Page 187 - Compact Numerical Methods For Computers
P. 187

176               Compact numerical methods for computers
                            Algorithm 19. A Nelder-Mead minimisation procedure (cont.)
                                               H := j; VH := f; {save new ‘high’}
                                            end;
                                         end; {if j<>L}
                                      end; {search for highest and lowest}
                                       {STEP 12: test and display current polytope information}
                                      if VH>VL+convtol then
                                      begin {major cycle of the method}
                                         str(funcount:5,tstr); {this is purely for orderly display of results
                                               in aligned columns}
                                         writeln(action,tstr,’‘,VH,’ ‘,VL);
                                         VN := beta*VL+(1.0-beta)*VH;
                                         {interpolate to get “next to highest” function value -- there are
                                            many options here, we have chosen a fairly conservative one.}
                                         for i := 1 to n do {compute centroid of all but point H -- STEP 13}
                                         begin
                                            temp := -P[i,H]; {leave out point H by subtraction}
                                            for j := 1 to nl do temp := temp+P[i,j];
                                            P[i,C] := temp/n; {centroid parameter i}
                                         end, {loop on i for centroid}
                                         for i := 1 to n do {compute reflection in Bvec[] -- STEP 14}
                                               Bvec[i] := (1.0+alpha)*P[i,C]-alpha*P[i,H];
                                         f := fminfn(n,Bvec,Workdata,notcomp); {function value at refln point}
                                         if notcomp then f := big; {When function is not computable, a very
                                               large value is assigned.}
                                         funcount := funcount+l; {increment function count}
                                         action := ‘REFLECTION ’; {label the action taken}
                                         VR := f; {STEP 15: test if extension should be tried}
                                         if VR<VL then
                                         begin {STEP 16: try extension}
                                            P[nl,C] := f; {save the function value at reflection point}
                                            for i := 1 to n do
                                            begin
                                               f := gamma*Bvec[i]+(1-gamma)*P[i,C];
                                               P[i,C] := Bvec[i]; {save the reflection point in case we need it}
                                               Bvec[i] := f;
                                            end; {loop on i for extension point}
                                            f := fminfn(n,Bvec,Workdata,notcomp); {function calculation}
                                            if notcomp then f := big; funcount := funcount+1;
                                            if f<VR then {STEP 17: test extension}
                                            begin {STEP 18: save extension point, replacing H}
                                               for i := 1 to n do P[i,H] := Bvec[i];
                                               P[n1,H]  := f; {and its function value}
                                               action := ‘EXTENSION’; {change the action label}
                                            end {replace H}
                                            else
                                            begin {STEP 19: save reflection point}
                                               for i := 1 to n do P[i,H] := P[i,C];
                                               P[n1,H] := VR; {save reflection function value}
                                            end {save reflection point in H; note action is still reflection}
                                         end {try extension}
                                         else {reflection point not lower than current lowest point}
                                         begin {reduction and shrink -- STEP 20}
   182   183   184   185   186   187   188   189   190   191   192