rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
stepsize_wolfe_powell.m
1 function [t_opt,nr_fct,nr_grad]=stepsize_wolfe_powell (model, x, d);
2 %function [t_opt,nr_fct,nr_grad]=stepsize_wolfe_powell (model, x, d)
3 %
4 % Function calculating a stepsize following the Wolfe-Powell-rule
5 %
6 %Required fields of model:
7 % model.optimization.get_Jacobian: gradient function
8 % model.optimization.objective_function: function to be optimized
9 % x: initial value
10 % d: search direction
11 %
12 %
13 %Output variables
14 % t_opt: optimal value for stepsize t
15 % nr_fct: number of function calls needed during process
16 % nr_grad: number of calculations of the gradient
17 %
18 %
19 % Oliver Zeeb 20.05.2010%
20 
21 
22 nr_fct = 0; %counter for number of function calls
23 nr_grad = 0; %counter for number of gradient calculations
24 
25 rho = 0.25; % 0 < rho < 0.5
26 sigma = 0.125; % 0 < sigma < 0.5
27 
28 grad_f = model.optimization.get_Jacobian;
29 func = model.optimization.objective_function;
30 
31 
32 
33 %needed functions for the algorithm
34 grad_phi_0 = grad_f(x)*d';
35 nr_grad=nr_grad+1;
36 
37 phi = @(t) func(x+t*d);
38 psi = @(t) phi(t) - phi(0) - sigma*t*grad_phi_0;
39 
40 grad_phi = @(t) grad_f(x+t*d)*d';
41 
42 t=1;
43 phi_test=func(x+t*d);
44 psi_test=phi(t) - phi(0) - sigma*t*grad_phi_0;
45 grad_ohi_test=grad_f(x+t*d)*d';
46 
47 
48 %
49 % Phase A
50 %
51 
52 kondition_a = 0; % condition, to enter the Phase-A-loop
53 
54 % (A.0)
55 t=1;
56 gamma=2;
57 
58 % (A.1)
59 while kondition_a == 0
60  nr_fct=nr_fct+1; % checking the next if-condition needs a function call
61  if psi(t) >= 0
62  a=0;
63  b=t;
64  kondition_a = 1;
65  break; % leaving this loop, continuing with Phase B
66  elseif grad_phi(t) >= rho*grad_phi_0 % psi(t) < 0 and phi_strich(t) >= rho * phi_strich(0) --> algorithm found an optimal stepsize t
67  nr_grad=nr_grad+1;
68  t_opt=t;
69  return % STOP 1
70  else % psi(t) < 0 an phi_strich(t) < rho * phi_strich(0)
71  nr_grad=nr_grad+1; %grad_phi in elseif condition needed calculation of the gradient
72  t=gamma*t;
73  end
74 end
75 
76 
77 %
78 % Phase B
79 %
80 
81 % (B.0)
82 tau1 = 0.2; % 0 < tau1 < 0.5
83 tau2 = 0.2; % 0 < tau2 < 0.5
84 
85 kondition_b=0; % condition to enter the Phase-B-loop
86 
87 % According to the Wolfe-Powell-Algorithm the following loop terminates
88 while kondition_b == 0
89  % (B.1)
90  t=0.5*(a*(1-tau1+tau2) + b*(1+tau1-tau2)); % choose t in [a+tau1(b-a), b-tau2(b-a)
91 
92  % (B.2)
93  nr_fct=nr_fct+1; %checking the next if-condition needs a function call
94  if psi(t) >= 0
95  b=t;
96  elseif grad_phi(t) >= rho * grad_phi_0 % psi(t) > 0 and phi_strich(t) >= rho* phi_strich(0) --> algorithm found an optimal stepsize t
97  nr_grad=nr_grad+1;
98  t_opt=t;
99  return % STOP 2 point where the algorithm terminates! --> leaves the function
100  else % psi(t) < 0 and phi_strich(t) < rho * phi_strich(0)
101  nr_grad=nr_grad+1; %grad_phi in elseif condition needed calculation of the gradient
102  a=t;
103  end
104 
105 end
106 
107 
108 
109