Page 186 - Compact Numerical Methods For Computers
P. 186

Direct search methods                     175
                     Algorithm 19. A Nelder-Mead minimisation procedure (cont.)

                             for i := 1 to n do if 0.1*abs(Bvec[i])>step then step := 0.1*abs(Bvec[i]);
                             writeln(‘Stepsize computed  as ‘,step);
                             for j := 2 to n1 do {main loop to build polytope} {STEP 5}
                             begin {STEP 6}
                                action := ‘BUILD‘;
                                for i := 1 to n do P[i,j] := Bvec[i]; {set the parameters}
                                {alternative strategy -- variable step size -- in the build phase}
                                { step := 0.1*abs(Bvec[j-l])+0.001; }
                                {Note the scaling and avoidance of zero stepsize.}
                                trystep := step; {trial step -- STEP 7}
                                while P[j-1,j]=Bvecu[j-1] do
                                begin
                                   P[j-1,j] := Bvec[j-1]+trystep; trystep := trystep*10;
                                end; (while]
                                size := size+trystep; {to compute a size measure for polytope -- STEP 8}
                             end; {loop on j for parameters}
                             oldsize := size; {to save the size measure -- STEP 9}
                             calcvert := true; {must calculate vertices when polytope is new}
                             shrinkfail := false; {initialize shrink failure flag so we don’t have
                                        false convergence}
                             repeat {main loop for Nelder-Mead operations -- STEP 10}
                                if calcvert then
                                begin
                                   for j := 1 to nl do {compute the function at each vertex}
                                   begin
                                      if j<>L then {We already have function value for L(owest) vertex.}
                                      begin
                                         for i := 1 to n do Bvec[i] := P[i,j]; {get the parameter values}
                                         f := fininfn(n,Bvec,Workdata,notcomp); {function calculation}
                                         if notcomp then f := big; funcount := funcount+1; P[nl,j] := f;
                                      end; {if j<>L clause}
                                   end; {loop on j to compute polytope vertices}
                                   calcvert := false; {remember to reset flag so we don’t calculate
                                         vertices every cycle of algorithm}
                                end; {calculation of vertices}
                                {STEP 11: find the highest and lowest vertices in current polytope}
                                VL := P[nl,L]; {supposedly lowest value}
                                VH := VL; {highest value must hopefully be higher}
                                H := L; {pointer to highest vertex initialized to L}
                                {Now perform the search}
                                for j := 1 to nl do
                                begin
                                   if j<>L then
                                   begin
                                      f := P[nl,j]; {function value at vertex j}
                                      if f<VL then
                                      begin
                                         L := j; VL := f; {save new ‘low’}
                                      end;
                                      if f>VH then
                                      begin
   181   182   183   184   185   186   187   188   189   190   191