rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
stepsize_armijo.m
1 function [model, t_opt,nr_fct,output, data_return] = stepsize_armijo(model, model_data, output, x, d)
2 %function [model, t_opt,nr_fct,output] = stepsize_armijo(model, model_data, output, x, d)
3 %
4 % Function calculating a stepsize following the Armijo-rule
5 %
6 %Required fields of model:
7 % model.optimization.get_Jacobian: gradient function
8 % model.optimization.objective_function: function to be optimized
9 %
10 %Inputs:
11 % output : vector with the sequence of the values of the functional during optimization
12 % x : vector with the current values of mu, that means parameters to
13 % optimize
14 % d : search direction, i.e. negative gradient in gradient-method
15 %
16 %Output variables
17 % t_opt: optimal value for stepsize t
18 % nr_fct: number of function calls needed during process
19 % ouput: vector with the sequence of the values of the functional during
20 % optimization, value of the new setting of mu given by the armijo rule
21 % was added at the end of the vector
22 %
23 %
24 % Oliver Zeeb 20.05.2010
25 data_return = [];
26 data=[];
27 if(model.verbose>=8)
28  disp('entered stepsize_armijo')
29 end
30 
31 if model.optimization.min_or_max == 'min'
32  min_or_max=1;
33 elseif model.optimization.min_or_max == 'max'
34  min_or_max=-1;
35 else disp('maximize or minimize? model.optimization.min_or_max not properly defined')
36  return
37 end
38 
39 if isfield(model.optimization,'sigma')
40  sigma = model.optimization.sigma;
41 else
42  sigma=0.8; % 0 < sigma < 1
43 end
44 if isfield(model.optimization,'stepsize_factor')
45  stepsize_factor = model.optimization.stepsize_factor;
46 else
47  stepsize_factor=0.5; % 0 < stepsize < 1
48 end
49 if isfield(model.optimization,'initial_stepsize')
50  t = model.optimization.initial_stepsize;
51 else
52  t = 1;
53 end
54 
55 
56 %initializing
57 nr_fct = 0;
58 if isfield(model,'armijo_t_min')
59  t_tol = model.optimization.armijo_t_min; %controls, that the stepsize does not become too small to avoid infinite loops
60 else
61  t_tol = 0.01;
62 end
63 
64 grad_f_x=-d;
65 
66 [func_f_x,data] = model.optimization.objective_function(model,model_data); nr_fct = nr_fct+1;
67 func_f_x = func_f_x * min_or_max;
68 if ~isempty(data)&&isfield(data,'nRB')
69  nRB = data.nRB;
70 else
71  nRB = [];
72 end
73 
74 if isempty(output) %first component, before mu is changed. i.e. value of the functional with init_params, saves one simulation in gradient_opt
75  output=[output,func_f_x];
76 end
77 
78 %calculate func(x+t*d)
79 x_td_model=[];
80 x_td_model=set_mu_to_optimize(model,x,t,d);
81 [func_f_x_td,data] = model.optimization.objective_function(x_td_model,model_data); nr_fct = nr_fct+1;
82 func_f_x_td=func_f_x_td*min_or_max;
83 if ~isempty(data)&&isfield(data,'nRB')
84  nRB = [nRB,data.nRB];
85 end
86 
87 
88 %Armijo-Algorithm
89 while (func_f_x_td > func_f_x + sigma*t*grad_f_x(:)'*d) && (t >= t_tol)
90  %debug
91  disp('while-Schleife in Armijo')
92  %end debug
93  t=stepsize_factor*t;
94  x_td_model=set_mu_to_optimize(model,x,t,d);
95  [func_f_x_td,data] = model.optimization.objective_function(x_td_model, model_data);
96  func_f_x_td = func_f_x_td*min_or_max;
97  if ~isempty(data)&&isfield(data,'nRB')
98  nRB = [nRB,data.nRB];
99  end
100 
101  nr_fct = nr_fct+1;
102 end
103 
104 %setting output data
105 model=x_td_model;
106 t_opt=t;
107 output=[output;func_f_x_td];
108 data_return.nRB = nRB;
109 
110 if(model.verbose>=8)
111  disp('leaving stepsize_armijo')
112  t
113  nr_fct
114 end
115 
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
function model = set_mu_to_optimize(model, x, varargin)
Funcion sets the parameters that are to be optimized to the values given by x Also usable for optimiz...
function [ opt_data , model ] = optimize(model, model_data, detailed_data, reduced_data)
opt_data = optimize(model, model_data, detailed_data, reduced_data)
Definition: optimize.m:17