-
Notifications
You must be signed in to change notification settings - Fork 188
/
polyline.m
51 lines (51 loc) · 1.48 KB
/
polyline.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
function [xp, idid, lambda]=polyline(xc, fc, gc, d, ft, f, maxarm)
%
% C. T. Kelley, Dec 29, 1997
%
% This code comes with no guarantee or warranty of any kind.
%
% function [xp, idid]=polyline(xc, fc, gc, d, ft, fobj, maxarm)
%
% polynomial line search, call after first point is rejected
%
% Input: xc = current point
% fc = current function value
% gc = current gradient value
% d = direction
% ft = trial function (rejected value)
% f = objective function
% the calling sequence for f should be
% [fout,gout]=f(x) where fout=f(x) is a scalar
% and gout = grad f(x) is a COLUMN vector
% maxarm = maximum number of step length reductions
%
% Output: xp = successful new point (if it exists)
% idid = number of calls to f (if line search succeeds) or
% -1 if line search fails.
%
% Requires: polymod.m
%
% line search parameters that everyone uses
%
alp=1.d-4; blow=.1; bhigh=.5;
%
% Set up the search
%
q0=fc; qp0=gc'*d; qc=ft; lamc=1; iarm=0; numf=0;
fgoal=fc+alp*lamc*qp0;
while ft > fgoal
iarm=iarm+1;
if iarm==1 % quadratic
lambda=polymod(q0, qp0, lamc, qc, blow, bhigh);
else
lambda=polymod(q0, qp0, lamc, qc, blow, bhigh, lamm, qm);
end
qm=qc; lamm=lamc; lamc=lambda;
xt=xc+lambda*d;
ft=feval(f,xt); numf = numf+1; qc=ft;
if(iarm > maxarm)
disp(' line search failure'); idid=-1; xp=xc;
return; end
fgoal=fc+alp*lamc*qp0;
end
xp=xt; idid=numf;