// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) 2008-2009 - INRIA - Michael Baudin // // This file must be used under the terms of the CeCILL. // This source file is licensed as described in the file COPYING, which // you should have received as part of this distribution. The terms // are also available at // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt // References // Han, Lixing and Neumann, Michael(2006) // 'Effect of dimensionality on the Nelder-Mead simplex method', // Optimization Methods and Software,21:1,1 — 16 mprintf("Defining quadratic function...\n"); function y = quadratic (x) y = x(:).' * x(:); endfunction // // myoutputcmd -- // This command is called back by the Nelder-Mead // algorithm. // Arguments // state : the current state of the algorithm // "init", "iter", "done" // data : the data at the current state // This is a tlist with the following entries: // * x : the optimal vector of parameters // * fval : the minimum function value // * simplex : the simplex, as a simplex object // * iteration : the number of iterations performed // * funccount : the number of function evaluations // * step : the type of step in the previous iteration // function myoutputcmd ( state , data , step ) global STEP_COUNTER STEP_COUNTER(step) = STEP_COUNTER(step) + 1 endfunction // OptimizeHanNeumann -- // Perform the optimization and returns the object // Arguments // N : the dimension function nm = OptimizeHanNeumann ( N ) global STEP_COUNTER STEP_COUNTER("init") = 0; STEP_COUNTER("done") = 0; STEP_COUNTER("reflection") = 0; STEP_COUNTER("expansion") = 0; STEP_COUNTER("insidecontraction") = 0; STEP_COUNTER("outsidecontraction") = 0; STEP_COUNTER("expansion") = 0; STEP_COUNTER("shrink") = 0; STEP_COUNTER("reflectionnext") = 0; x0 = zeros(N,1); nm = neldermead_new (); nm = neldermead_configure(nm,"-numberofvariables",N); nm = neldermead_configure(nm,"-function",quadratic); nm = neldermead_configure(nm,"-x0",x0); nm = neldermead_configure(nm,"-maxiter",10000); nm = neldermead_configure(nm,"-maxfunevals",10000); nm = neldermead_configure(nm,"-tolxmethod","disabled"); nm = neldermead_configure(nm,"-tolsimplexizeabsolute",1.e-8); nm = neldermead_configure(nm,"-tolsimplexizerelative",0); nm = neldermead_configure(nm,"-simplex0method","given"); coords0(1,1:N) = zeros(1,N); coords0(2:N+1,1:N) = 2 * rand(N,N) - 1; nm = neldermead_configure(nm,"-coords0",coords0); nm = neldermead_configure(nm,"-method","fixed"); nm = neldermead_configure(nm,"-verbose",0); nm = neldermead_configure(nm,"-verbosetermination",0); nm = neldermead_configure(nm,"-outputcommand",myoutputcmd); // // Perform optimization // nm = neldermead_search(nm); endfunction for N = 1:20 nm = OptimizeHanNeumann ( N ); niter = neldermead_get ( nm , "-iterations" ); funevals = neldermead_get ( nm , "-funevals" ); simplex0 = neldermead_get ( nm , "-simplex0" ); sigma0 = optimsimplex_size ( simplex0 , "sigmaplus" ); simplexopt = neldermead_get ( nm , "-simplexopt" ); sigmaopt = optimsimplex_size ( simplexopt , "sigmaplus" ); rho = ( sigmaopt / sigma0 ) ^ ( 1 / niter ); funevaltable(N) = funevals; rhotable(N) = rho; mprintf ( "%d %d %d %e\n" , N , funevals , niter , rho ); //mprintf("%d %s\n",N, strcat(string(STEP_COUNTER)," ")) // LaTeX formatting : //mprintf("%d & %d & %d & %d & %d\\\\\n",N, niter , STEP_COUNTER("reflection"), STEP_COUNTER("reflectionnext"), STEP_COUNTER("shrink")) // LaTeX formatting : //mprintf ( "%d & %d & %d & %f \\\\\n" , N , funevals , niter , rho ); nm = neldermead_destroy(nm); end f = scf() plot(1:20,funevaltable) f.children.x_label.text = "Number of Variables" f.children.y_label.text = "Number of Function Evaluations" f.children.title.text = "Sensitivity of Spendley'"s et al. algorithm to the number of variables" f.children.children.children.mark_size = 5 f.children.children.children.mark_style = 9