Page 204 - Compact Numerical Methods For Computers
P. 204

Descent to a minimum I: variable metric algorithms    193
                      Algorithm 21. Variable metric minimiser (cont.)

                           acctol = 0.0001; {acceptable point tolerance -- see STEP 11}
                           reltest = 10.0; {to check equality of parameters -- see STEP 8}
                        var
                           accpoint : boolean, {to indicate an acceptable point}
                           B : array[1..Maxparm, 1..Maxparm] of real;
                                         {approximation to inverse Hessian}
                           c : rvector; {to store last gradient}
                           count : integer; {to check for parameter equality}
                           D1, D2 : real; {temporary working storage}
                           f : real; {temporary function value}
                           funcount : integer; {count of function evaluations}
                           g : r-vector; {to hold gradient}
                           gradcount : integer; {count of gradient evaluations}
                           gradproj : real; {gradient projection on search vector}
                           i, j : integer; {working integers}
                           ilast : integer; {records last step at which B was
                                         initialized to a unit matrix}
                           notcomp : boolean; {non-computability flag}
                           s : real; {inner product accumulator}
                           steplength: real; {linear search steplength}
                           t : rvector; {to store working vector for line search}
                        begin
                           writeln(‘alg21.pas -- version 2 1988-03-24’);
                           writeln(‘Variable metric function minimiser’);
                           fail:=false; {method has yet to fail}
                           f:=fminfn(n, Bvec, Workdata, notcomp); {initial fn calculation -- STEP 1}
                           if notcomp then
                           begin
                              writeln(‘**** Function cannot be evaluated at initial parameters ****’);
                              fail := true; {method has failed}
                           end
                           else {proceed with minimisation}
                           begin
                              Fmin:=f;{save the best value so far}
                              funcount:=l; {function count initialized to 1}
                              gradcount:=l; {initialize gradient count to 1}
                              fmingr(n, Bvec, Workdata, g); {STEP 2}
                              ilast:=gradcount; {set count to force initialization of B}
                              {STEP 3 -- set B to unit matrix -- top of major cycle}
                              repeat {iteration for method -- terminates when no progress can be
                                         made, and B is a unit matrix so that search is a steepest
                                         descent direction.}
                                 if ilast=gradcount then
                                 begin
                                   for i:=1 to n do
                                   begin
                                      for j:=1 to n do B[i, j]:=0.0; B[i, i]:=1.0;
                                    end; {loop on i}
                                 end; {initialize B}
                                 writeln(gradcount,’ ‘, funcount,’ ’, Fmin); {STEP 4}
                                 write(‘parameters ’);
                                 for i:=1 to n do write(Bvec[i]:10:5,’ ’);
   199   200   201   202   203   204   205   206   207   208   209