-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoom.m
43 lines (30 loc) · 1.06 KB
/
zoom.m
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
function alpha = zoom(f,gradf,gradphi_0,c1,c2,x,phi_0,phi_prev,pk,alpha_lo,alpha_hi)
% Zoom function - each iteration generates alpha between alpha_lo and
% alpha_hi, and then replaces one of these endpoints by alpha, in such a
% way that Wolfe condition is satisfied in the interval!
while true
% Choose an alpha in (alpha_lo, alpha_hi). There are many ways to
% select the alpha (a) interpolation or (b) just select a midpoint or (c)
alpha = (alpha_lo+alpha_hi)/2;
xi = x + alpha*pk;
phi_xi = f(xi);
gradphi_xi = gradf(xi)'*pk;
if phi_xi > phi_0 + c1*alpha*gradphi_0 || phi_xi >= phi_prev
alpha_hi = alpha;
else
gradphi_xi = gradf(xi)'*pk;
% Check strong Wolfe condition
if abs(gradphi_xi) <= -c2*gradphi_0
return;
end
if gradphi_xi*(alpha_hi-alpha_lo) >= 0
alpha_hi = alpha_lo;
alpha_lo = alpha;
phi_prev = phi_xi;
end
end
if alpha < 1e-5
return
end
end
end