2 %> Algorithm 15.1: Nelder-Mead algorithm. Implementation of algorithm 15.1 of \cite Bier15-book
4 %> @note Tested with \ref run1502nelderMead.m
5 %> @note Tested with \ref run1503nelderMead.m
7 %> @author Michel Bierlaire
8 %> @date Sat Mar 21 18:23:57 2015
12 %> Applies the Nelder-Mead algorithm to solve \f$\min_x f(x)\f$ where \f$f:\mathbb{R}^n\to\mathbb{R}\f$.
13 %> @param obj the name of the Octave
function defining f(x)
14 %> @param x0 matrix nx(n+1) containnig the initial
simplex 15 %> @param eps algorithm stops if \f$\|d_k\| \leq \varepsilon \f$.
16 %> @param maxiter maximum number of iterations (Default: 100)
22 error("Incorrect size") ;
30 f = [ f ; feval(obj,x(:,k)) ] ;
34 [worst,worstindex] = max(f) ;
36 [best,bestindex] = min(f) ;
38 tmp(worstindex) = best - 10.0 ;
39 xworst = x(:,worstindex) ;
40 [secondworst,secondworstindex] = max(tmp) ;
42 xc = (sum(x,2) - xworst) / n;
43 d = xc - x(:,worstindex) ;
44 xr = 2 * xc - xworst ;
55 if (secondworst > fxr)
59 xnew = 0.5 * (xworst + xc) ;
61 xnew = 0.5 * (xr + xc) ;
65 fxnew = feval(obj,xnew) ;
70 printf(
"%e\t",xr(1)) ;
71 printf(
"%e\n",xnew(1)) ;
76 printf(
"%e\t",xr(2)) ;
77 printf(
"%e\n",xnew(2)) ;
78 printf(
"---------------------\n") ;
84 printf(
"%e\n",fxnew) ;
85 printf(
"---------------------\n") ;
86 x(:,worstindex) = xnew ;
88 until (norm(d) < eps || iter >= maxiter)
89 solution = x(:,bestindex) ;
function nelderMead(in obj, in x0, in eps, in maxiter)
Applies the Nelder-Mead algorithm to solve where .
function simplex(in A, in b, in c, in basis)
Applies the simplex method to solve subject to and , where , , and .