Skip to main content

prepareNonNegativeMatrixFactorizationInitialValues.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function uses nnmf to calculate an initial guess for synergy
% weights if an intial guess is not loaded
%
% (struct, struct) -> (Array of number)
% Returns synergy weights initial guess


function values = ...
prepareNonNegativeMatrixFactorizationInitialValues(inputs, params)
values = [];
controls = {};
for i = 1:length(inputs.synergyGroups)
groupMtpActivationsIndices = ismember( ...
inputs.mtpActivationsColumnNames, ...
inputs.synergyGroups{1}.muscleNames);
groupMtpActivations = inputs.mtpActivations(:, ...
groupMtpActivationsIndices, :);
[groupWeights, controls{i}] = nnmf(...
squeeze(groupMtpActivations(1, :, :)), ...
inputs.synergyGroups{i}.numSynergies);

values = [values; reshape(groupWeights, [], 1); 0.1 * ...
ones(length(inputs.synergyGroups{i}.muscleNames) - ...
sum(groupMtpActivationsIndices), 1)];
end
end