1 function [opt_data,model] = detailed_grid_search(model, model_data, detailed_data, reduced_data)
2 %
function opt_data = detailed_grid_search(model, model_data);
4 % Function performing an optimization by grid search
using the detailed
7 %Required fields of model:
8 %model.mu_names: names of the parameters to be optimized
9 %model.mu_ranges: value ranges
for optimization
10 %model.optimization.init_params: marks which parameters should be optimized
11 %model.optimization.opt_params.grid_density: Density of the search grid. F.Ex.
"3"
12 % means
using 3 parameters per dimension
13 %model.optimitzation.params_to_optimize: Flag vector indicating which
14 % variables to opimize
16 %used variables in Function:
17 % P : cell-array where the used parameters are stored.
18 % P{1} = Vector of values
for first parameter
19 % PM : Parameter matrix (each row defines a Parameter set
for a
20 % detailed simulation)
22 %Generated fields of opt_data:
23 % output: sequence of outputvalues obtained during optimization
24 % parameter_sets: sequence of corresponding parameter sets to output sequence
25 % max_output: maximal output value
26 % max_output_paramsets: paramset
for which the maximal parameter was
29 % Markus Dihlmann 03.02.2010
31 model.opt_method=
'detailed grid search';
33 %Check required fields:
34 if isempty(model_data)
35 model_data = gen_model_data(model);
38 if isempty(model.mu_names)
39 error('No parameter names specified!');
42 %Total number of parameters defined in model
43 nbrParams = length(model.mu_names);
45 %Continue check required fields
46 if (isempty(model.mu_ranges)||nbrParams~=length(model.mu_ranges))
47 error('not the right number of parameter ranges given!');
50 %if isempty(model.opt_method)
51 % error('No optimization method defined!');
54 if (isempty(model.optimization.params_to_optimize)||nbrParams~=length(model.optimization.params_to_optimize))
55 error('It is not properly defined which parameters are set for optimization and which not!');
59 % If no initial values are given, set them in the middle of the ranges
60 if isempty(model.optimization.init_params)
62 model.optimization.init_params(i) = (model.mu_ranges{i}(1)+model.mu_ranges{i}(2))/2;
67 if isempty(model.optimization.opt_params.grid_density)
68 model.optimization.opt_params.grid_density =3; %defautl value
71 nbrParams = length(model.mu_names);
72 nbrOptparams=0; %number of paramters to be optimized
74 if(size(model.optimization.opt_params.grid_density)==1)
75 %same density for all parameter dimensions
78 if model.optimization.params_to_optimize(i)
79 stepd = (model.mu_ranges{i}(2)-model.mu_ranges{i}(1))/(model.optimization.opt_params.grid_density-1);
80 P{ind} = model.mu_ranges{i}(1):stepd:model.mu_ranges{i}(2);
84 nbrOptParams = ind-1; %number of parameters to be optimized
86 %
for each parameter dimension another density
89 if model.optimization.params_to_optimize(i)
90 stepd = (model.mu_ranges{i}(2)-model.mu_ranges{i}(1))/(model.optimization.opt_params.grid_density(i)-1);
91 P{ind} = model.mu_ranges{i}(1):stepd:model.mu_ranges{i}(2);
99 %Construct ParameterGrid-Matrix
100 limits=zeros(length(P),1);
101 for i=1:length(limits)
102 limits(i)=length(P{i});
105 for i=1:length(limits)
106 nbrCombinations=nbrCombinations * limits(i);
109 PM=zeros(nbrCombinations,nbrParams);
110 counter=ones(1,length(limits)+1);
116 if(model.optimization.params_to_optimize(i))
117 PM(j,i)=P{ind}(counter(ind));
120 PM(j,i)=model.optimization.init_params(i);
123 counter(1)=counter(1)+1;
124 for h=1:(length(counter)-1)
125 if(counter(h)>limits(h))
127 counter(h+1)=counter(h+1)+1;
131 if counter(length(counter))~=1
137 %performing a detailed simulation of all parameter sets given by the lines
139 output=zeros(length(PM(:,1)),1);
140 for i=1:length(PM(:,1))
142 model = model.set_mu(model,PM(i,:));
145 disp(
'Actual parameter set:');
151 output(i) = model.optimization.objective_function(model,model_data);
157 opt_data.output = output;
158 opt_data.parameter_sets = PM;
159 opt_data.max_output = max(output);
161 %where to reach this maximum value:
164 ind=search_pos(opt_data.max_output, output,ind)
166 Pmax=[Pmax;PM(ind,:)];
167 ind=search_pos(opt_data.max_output, output,ind+1);
170 opt_data.max_output_paramsets=Pmax;
175 function ind=search_pos(value,vec,start)
178 while ((~found)&&(ind<=length(vec)))