Skip to main content

reportSurrogateModel.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% () -> ()
%


function reportSurrogateModel(inputs)

[newMuscleTendonLengths, newMomentArms] = ...
calcSurrogateModel(inputs, inputs.muscleSpecificJointAngles, ...
inputs.muscleSpecificJointAngles);
plotSurrogateModelFitting(inputs, newMuscleTendonLengths, ...
newMomentArms);
end
function plotSurrogateModelFitting(inputs, newMuscleTendonLengths, ...
newMomentArms)

nplots = ceil(sqrt(inputs.numMuscles));
% Plot muscle tendon lengths
figure('name', 'Muscle Tendon Lengths')
for i = 1 : inputs.numMuscles
subplot(nplots, nplots, i)
plotData(inputs.muscleTendonLengths(:, i), newMuscleTendonLengths(:, i), ...
inputs.muscleNames{i})
axis([1 size(inputs.muscleTendonLengths, 1) min(inputs.muscleTendonLengths, [], ...
'all') max(inputs.muscleTendonLengths, [], 'all')])
if i > inputs.numMuscles - nplots; xlabel('Data Points');
else xticklabels(''); end
if ismember(i, 1 : nplots : inputs.numMuscles)
ylabel({'Muscle','Tendon Lengths'});
else yticklabels(''); end
if i == inputs.numMuscles
legend('Original', 'Predicted');
end
end

% Plot moment arms
for j = 1 : length(inputs.surrogateModelCoordinateNames)
figure('name', 'Moment Arms')
for i = 1 : inputs.numMuscles
subplot(nplots, nplots, i)
for k = 1:length(inputs.coordinateNames)
if strcmp(inputs.surrogateModelCoordinateNames(j), inputs.coordinateNames(k))
plotData(inputs.momentArms(:,j,i), newMomentArms(:,k,i), inputs.muscleNames(i));
end
end
if i > inputs.numMuscles - nplots; xlabel('Data Points');
else xticklabels(''); end
if ismember(i, 1 : nplots : inputs.numMuscles)
ylabel({'Moment','Arms'}); end
if i == inputs.numMuscles
legend('Original', 'Predicted');
end
end
end
end
function plotData(original, predicted, muscleLabel)
plot(original, 'r', 'LineWidth', 2)
hold on; plot(predicted, 'k')
title(strrep(muscleLabel, '_', ' '))
end