Page 195 - Compact Numerical Methods For Computers
P. 195
184 Compact numerical methods for computers
Algorithm 27. Hooke and Jeeves minimiser (cont.)
end {safety stop for non-computable function}
else {initial function computed -- proceed}
begin {main portion of routine}
writeln(‘Initial function value=‘,fval);
for i := l to n do
begin
write(B[i]:10:5,’’);
if (7 * (i div 7) = i) and (i<n) then writeln;
end;
writeln;
fold := fval; Fmin := fval; {to save function value at ‘old’ base which
is also current best function value}
while stepsize>intol do {STEP HJ9 is now here}
begin {STEP HJ5 == Axial Search}
{write( ‘A’);} {Indicator output }
for i := 1 to n do {STEP AS1}
begin {STEP AS2}
temp := B[i]; B[i] := temp+stepsize; {save parameter, step ‘forward’}
fval := fmi.nfn(n, B,Workdata,notcomp); ifn := ifn+l; {STEP AS3}
if notcomp then fval := big; {to allow for non-computable function}
if fval<Fmin then
Fmin := fval {STEP AS4}
else
begin {STEP AS5}
B[i] := temp-stepsize; {to step ‘backward’ if forward step
unsuccessful in reducing function value}
fval := fminfn(n, B,Workdata,notcomp); ifn := ifn+l; {STEP AS6}
if notcomp then fval := big; {for non-computable function}
if fval<Fmin then {STEP AS7}
Fmin := fval {STEP AS9 -- re-ordering of original algorithm}
else {STEP AS8}
B[i] := temp; {to reset the parameter value to original value}
end; {else fval>=Fmin}
end; {loop on i over parameters and end of Axial Search}
if Fmin<fold then {STEP HJ6}
begin {Pattern Move} {STEP PM1}
{write( ‘P’);} {Indicator output}
for i := 1 to n do {loop over parameters}
begin {STEP PM2}
temp := 2.0*B[i]-X[i]; {compute new base point component}
X[i] := B[i]; B[i] := temp; {save current point and new base point}
end; {loop on i -- STEP PM3}
fold := Fmin; {to save new base point value}
end {of Pattern Move -- try a new Axial Search}
else
begin
samepoint := true; {initially assume points are the same}
i := l;{set loop counter start}
repeat
if B[i]<>X[i] then samepoint := false;
i := i+l;
until (not samepoint) or (i>n); {test for equality of points}