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