-
Notifications
You must be signed in to change notification settings - Fork 0
/
uo_BLSNW32.m
128 lines (124 loc) · 2.49 KB
/
uo_BLSNW32.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function [alphas,iout] = uo_BLSNW32(f,g0,x0,d,alpham,c1,c2,maxiter,eps)
% function alphas = strongwolfe(f,d,x0,alpham)
% Line search algorithm satisfying strong Wolfe conditions
% Algorithms 3.5 on pages 60-61 in Nocedal and Wright
% MATLAB code by Kartik Sivaramakrishnan
% Last modified: January 27, 2008
%
% F.-Javier Heredia, September 2018 <fjh...>
% g,c1,c2,maxiter, eps
% iout = 1 : too many iterations
% iout = 2 : stacked, alpha_[i]=alpha^[i-1]
alpha0 = 0;
alphap = alpha0;
g = @(x) g0(x)';
%<fjh
iout = 0;
if c1 == 0
c1 = 1e-4;
end
if c2==0
c2 = 0.5;
end
%alphax = alpham*rand(1);
alphax = alpham;
%[fx0,gx0] = feval(f,x0,d);
fx0 = f(x0);
gx0 = g(x0)*d;
%>
fxp = fx0;
gxp = gx0;
i=1;
% alphap is alpha_{i-1}
% alphax is alpha_i
while (1 ~= 2 && i < maxiter)
%<fjh
if abs(alphap-alphax) < eps
iout = 2;
alphas = alphax;
return
end
%>
xx = x0 + alphax*d;
%<fjh
%[fxx,gxx] = feval(f,xx,d);
fxx = f(xx);
gxx = g(xx)*d;
%>
if (fxx > fx0 + c1*alphax*gx0) || ((i > 1) && (fxx >= fxp)),
[alphas,iout_zoom] = zoom(f,g,x0,d,alphap,alphax,c1,c2,eps);
%<fjh
if iout_zoom == 2
iout = 2;
end
%>
return;
end
if abs(gxx) <= -c2*gx0,
alphas = alphax;
return;
end
if gxx >= 0,
[alphas,iout_zoom] = zoom(f,g,x0,d,alphax,alphap,c1,c2,eps);
%<fjh
if iout_zoom == 2
iout = 2;
end
%>
return;
end
alphap = alphax;
fxp = fxx;
gxp = gxx;
alphax = alphax + (alpham-alphax)*rand(1);
i = i+1;
end
if i==maxiter
iout = 1;
alphas = alphax;
end
function [alphas,iout] = zoom(f,g,x0,d,alphal,alphah,c1,c2,eps)
% function alphas = zoom(f,g,x0,d,alphal,alphah)
% Algorithm 3.6 on page 61 in Nocedal and Wright
% MATLAB code by Kartik Sivaramakrishnan
% Last modified: January 27, 2008
% F.-Javier Heredia, September 2018 <fjh...>
%<fjh
%[fx0,gx0] = feval(f,x0,d);
fx0 = f(x0);
gx0 = g(x0)*d;
iout = 0;
%>
while (1~=2),
%<fjh
if abs(alphal-alphah) < eps
iout = 2;
alphas = alphax;
return
end
%>
alphax = 1/2*(alphal+alphah);
xx = x0 + alphax*d;
%<fjh
%[fxx,gxx] = feval(f,xx,d);
fxx = f(xx);
gxx = g(xx)*d;
%>
xl = x0 + alphal*d;
%<fjh
%fxl = feval(f,xl,d);
fxl = f(xl);
%>
if ((fxx > fx0 + c1*alphax*gx0) || (fxx >= fxl)),
alphah = alphax;
else
if abs(gxx) <= -c2*gx0,
alphas = alphax;
return;
end
if gxx*(alphah-alphal) >= 0,
alphah = alphal;
end
alphal = alphax;
end
end