Skip to main content

calcNormalizedFiberLengthGroupedSimilarityCost.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% (Array of number, struct) -> (Array of number)
% returns the cost for all rounds of the Muscle Tendon optimization


function cost = calcNormalizedFiberLengthGroupedSimilarityCost( ...
modeledValues, experimentalData, costTerm)
errorCenter = valueOrAlternate(costTerm, "errorCenter", 0);
maximumAllowableError = valueOrAlternate(costTerm, "maxAllowableError", 0.05);
index = 1;
for i = 1:length(experimentalData.normalizedFiberLengthGroups)
muscleGroup = experimentalData.normalizedFiberLengthGroups{i};
normalizedFiberLengthMagnitudeDeviation(:, index : index + size(...
muscleGroup, 2) - 1) = calcMeanDeviations( ...
modeledValues.normalizedFiberLength(:, muscleGroup, :), ...
experimentalData.normalizedFiberLength(:, muscleGroup, :));
normalizedFiberLengthShapeDeviation(:, index : index + size(...
muscleGroup, 2) - 1, :) = calcMeanShapeDeviations( ...
modeledValues.normalizedFiberLength(:, muscleGroup, :));
index = index + size(muscleGroup, 2);
end
normalizedFiberLengthMagnitudeDeviationCost = calcDeviationCostTerm( ...
normalizedFiberLengthMagnitudeDeviation, errorCenter, ...
maximumAllowableError);
normalizedFiberLengthShapeDeviationCost = calcDeviationCostTerm( ...
normalizedFiberLengthShapeDeviation, errorCenter, ...
maximumAllowableError);
cost = (normalizedFiberLengthMagnitudeDeviationCost + ...
normalizedFiberLengthShapeDeviationCost);
end