Page 205 - Compact Numerical Methods For Computers
P. 205
194 Compact numerical methods for computers
Algorithm 21. Variable metric minimiser (cont.)
writeln;
for i:=1 to n do
begin
X[i]:=Bvec[i];{save best parameters}
c[i]:=g[i]; {save gradient}
end; {loop on i}
{STEP 5 -- set t:=-B*g and gradproj=tT*g}
gradproj:=0.0; {to save tT*g inner product}
for i:=1 to n do
begin
s:=0.0; {to accumulate element of B*g}
for j:=l to n do s:=s-B[i, j]*g[j];
t[i]:=s; gradproj:=gradproj+s*g[i];
end; {loop on i for STEP 5}
{STEP 6} {test for descent direction}
if gradproj<0 then {if gradproj<0 then STEP 7 to perform linear
search; other parts of this step follow the ‘else’ below}
begin {STEP 7 -- begin linear search}
steplength:=1.0; {always try full step first}
{STEP 8 -- step along search direction and test for a change}
accpoint:=false; {don’t have a good point yet}
repeat {line search loop}
count:=0; {to count unchanged parameters}
for i:=1 to n do
begin
Bvec[i]:=X[i]+steplength*t[i];
if (reltest+X[i])=(reltest+Bvec[i]) then count:=count+1;
end; {loop on i}
if count<n then {STEP 9 -- main convergence test}
begin {STEP 10 -- can proceed with linear search}
f:=fminfn(n, Bvec, Workdata, notcomp); {function calculation}
funcount:=funcount+1;
accpoint:=(not notcomp) and
(f<=Fmin+gradproj*steplength*acctol);
{STEP 11 -- a point is acceptable only if function is computable
(not notcomp) and it satisfies the acceptable point criterion}
if not accpoint then
begin
steplength:=steplength*stepredn; write(‘*’);
end;
end; {compute and test for linear search}
until (count=n) or accpoint; {end of loop for line search}
if count<n then
begin
Fmin:=f; {save funcion value}
fmingr(n, Bvec, Workdata, g); {STEP 12}
gradcount:=gradcount+1;
D1:=0.0; {STEP 13 -- prepare for matrix update}
for i:=1 to n do
begin
t[i]:=steplength*t[i]; c[i]:=g[i]-c[i]; {to compute vector y}
D1:=D1+t[i]*c[i]; {to compute inner product t*y}