[592feb]: / manuscript_material / a_sensitivityStudy_Example1.m

Download this file

99 lines (85 with data), 4.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
%-------------------------------------------------------------------------%
% Copyright (c) 2019 Modenese L., Ceseracciu, E., Reggiani M., Lloyd, D.G.%
% %
% Licensed under the Apache License, Version 2.0 (the "License"); %
% you may not use this file except in compliance with the License. %
% You may obtain a copy of the License at %
% http://www.apache.org/licenses/LICENSE-2.0. %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or %
% implied. See the License for the specific language governing %
% permissions and limitations under the License. %
% %
% Author: Luca Modenese, August 2014 %
% revised for paper May 2015 %
% email: l.modenese@imperial.ac.uk %
% ----------------------------------------------------------------------- %
%
% Script optimizing muscle parameters for the Example 1 described in
% Modenese L, Ceseracciu E, Reggiani M, Lloyd DG (2015). "Estimation of
% musculotendon parameters for scaled and subject specific musculoskeletal
% models using an optimization technique" Journal of Biomechanics (submitted)
% The script performes a sensitivity study from which the Figures of the
% papers are then produced.
% The script:
% 1) optimizes muscle parameters varying the number of points used in the
% optimization from 5 to 15 per degree of freedom. Optimized models and
% optimization log are saved in the folder "Example1>OptimModels"
% 2) evaluates the results of the optimization in terms of muscle
% parameters variation and muscle mapping metrics (and saves structures
% summarizing the results in the folder "Example1>Results"
clear;clc;close all
% importing OpenSim libraries
import org.opensim.modeling.*
% importing muscle optimizer's functions
addpath(genpath('./Functions_MusOptTool'))
%========= USERS SETTINGS =======
% select case to simulate: 1 or 2
example_nr = 1;
% evaluations
N_eval_set = 5:15;
%================================
%=========== INITIALIZING FOLDERS AND FILES =============
% getting example details
[case_id, osimModel_ref_file, osimModel_targ_file] = getExampleInfo(example_nr);
% folders used by the script
refModel_folder = ['./',case_id,'/MSK_Models'];
targModel_folder = refModel_folder;
OptimizedModel_folder = ['./',case_id,'/OptimModels'];% folder for storing optimized model
Results_folder = ['./',case_id,'/Results'];
log_folder = OptimizedModel_folder;
checkFolder(OptimizedModel_folder);% creates results folder is not existing
checkFolder(Results_folder);
% model files with paths
osimModel_ref_filepath = fullfile(refModel_folder,osimModel_ref_file);
osimModel_targ_filepath = fullfile(targModel_folder,osimModel_targ_file);
% reference model for calculating results metrics
osimModel_ref = Model(osimModel_ref_filepath);
for N_eval = N_eval_set;
%====== MUSCLE OPTIMIZER ========
% optimizing target model based on reference model fro N_eval points per
% degree of freedom
[osimModel_opt, SimsInfo{N_eval}] = optimMuscleParams(osimModel_ref_filepath, osimModel_targ_filepath, N_eval, log_folder);
%====== PRINTING OPT MODEL =======
% setting the output folder
if strcmp(OptimizedModel_folder,'') || isempty(OptimizedModel_folder)
OptimizedModel_folder = targModel_folder;
end
% printing the optimized model
osimModel_opt.print(fullfile(OptimizedModel_folder, char(osimModel_opt.getName())));
%====== SAVING RESULTS ===========
% variation in muscle parameters
Results_MusVarMetrics = assessMuscleParamVar(osimModel_ref, osimModel_opt, N_eval);
% assess muscle mapping (RMSE, max error, etc) at n_Metrics points
% between reference and optimized model
n_Metrics = 10;
Results_MusMapMetrics = assessMuscleMapping(osimModel_ref, osimModel_opt,N_eval, n_Metrics);
% move results mat file to result folder
movefile('./*.mat',Results_folder)
end
% save simulations infos
save([Results_folder,'./SimsInfo'],'SimsInfo');
% removing functions from path
rmpath(genpath('./Functions_MusOptTool'));