1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Copyright (C) 2008-2009 - INRIA - Michael Baudin 3// Copyright (C) 2011 - DIGITEO - Michael Baudin 4// 5// Copyright (C) 2012 - 2016 - Scilab Enterprises 6// 7// This file is hereby licensed under the terms of the GNU GPL v2.0, 8// pursuant to article 5.3.4 of the CeCILL v.2.1. 9// This file was originally licensed under the terms of the CeCILL v2.1, 10// and continues to be available under such terms. 11// For more information, see the COPYING file which you should have received 12// along with this program. 13 14// <-- CLI SHELL MODE --> 15 16// 17// Check behaviour with default settings. 18// 19 20function [ y , index ] = rosenbrock ( x , index ) 21 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; 22endfunction 23 24nm = neldermead_new (); 25nm = neldermead_configure(nm,"-numberofvariables",2); 26nm = neldermead_configure(nm,"-x0",[1.1 1.1]'); 27nm = neldermead_configure(nm,"-function",rosenbrock); 28nm = neldermead_search(nm, "off"); 29// Check optimum point 30xopt = neldermead_get(nm,"-xopt"); 31assert_checkalmostequal ( xopt , [1.0;1.0], 1e-4 ); 32// Cleanup 33nm = neldermead_destroy(nm); 34clear nm; 35 36//% MCKINNON computes the McKinnon function. 37// 38// Discussion: 39// 40// This function has a global minimizer: 41// 42// X* = ( 0.0, -0.5 ), F(X*) = -0.25 43// 44// There are three parameters, TAU, THETA and PHI. 45// 46// 1 < TAU, then F is strictly convex. 47// and F has continuous first derivatives. 48// 2 < TAU, then F has continuous second derivatives. 49// 3 < TAU, then F has continuous third derivatives. 50// 51// However, this function can cause the Nelder-Mead optimization 52// algorithm to "converge" to a point which is not the minimizer 53// of the function F. 54// 55// Sample parameter values which cause problems for Nelder-Mead 56// include: 57// 58// TAU = 1, THETA = 15, PHI = 10; 59// TAU = 2, THETA = 6, PHI = 60; 60// TAU = 3, THETA = 6, PHI = 400; 61// 62// To get the bad behavior, we also assume the initial simplex has the form 63// 64// X1 = (0,0), 65// X2 = (1,1), 66// X3 = (A,B), 67// 68// where 69// 70// A = (1+sqrt(33))/8 = 0.84307... 71// B = (1-sqrt(33))/8 = -0.59307... 72// 73// Licensing: 74// 75// This code is distributed under the GNU LGPL license. 76// 77// Modified: 78// 79// 09 February 2008 80// 81// Author: 82// 83// John Burkardt 84// 85// Reference: 86// 87// Ken McKinnon, 88// Convergence of the Nelder-Mead simplex method to a nonstationary point, 89// SIAM Journal on Optimization, 90// Volume 9, Number 1, 1998, pages 148-158. 91// 92// Parameters: 93// 94// Input, real X(2), the argument of the function. 95// 96// Output, real F, the value of the function at X. 97// 98// Copyright (C) 2009 - INRIA - Michael Baudin, Scilab port 99 100function [ f , index ] = mckinnon3 ( x , index ) 101 102 if ( length ( x ) ~= 2 ) 103 error ( 'Error: function expects a two dimensional input\n' ); 104 end 105 106 tau = 3.0; 107 theta = 6.0; 108 phi = 400.0; 109 110 if ( x(1) <= 0.0 ) 111 f = theta * phi * abs ( x(1) ).^tau + x(2) * ( 1.0 + x(2) ); 112 else 113 f = theta * x(1).^tau + x(2) * ( 1.0 + x(2) ); 114 end 115endfunction 116 117lambda1 = (1.0 + sqrt(33.0))/8.0; 118lambda2 = (1.0 - sqrt(33.0))/8.0; 119coords0 = [ 1201.0 1.0 1210.0 0.0 122lambda1 lambda2 123]; 124 125// 126// Test wrong -restartdetection 127// 128nm = neldermead_new (); 129nm = neldermead_configure(nm,"-numberofvariables",2); 130nm = neldermead_configure(nm,"-function",mckinnon3); 131nm = neldermead_configure(nm,"-x0",[1.0 1.0]'); 132nm = neldermead_configure(nm,"-maxiter",300); 133nm = neldermead_configure(nm,"-maxfunevals",500); 134nm = neldermead_configure(nm,"-tolsimplexizerelative",1.e-6); 135nm = neldermead_configure(nm,"-simplex0method","given"); 136nm = neldermead_configure(nm,"-coords0",coords0); 137nm = neldermead_configure(nm,"-method","variable"); 138nm = neldermead_configure(nm,"-verbosetermination",0); 139nm = neldermead_configure(nm,"-kelleystagnationflag",%t); 140nm = neldermead_configure(nm,"-restartflag",%t); 141instr = "nm = neldermead_configure(nm,""-restartdetection"",""foo"");"; 142alloptions = """oneill"" or ""kelley"""; 143assert_checkerror(instr,"%s: Expected value [%s] for input argument %s at input #%d, but got ""%s"" instead.",[],.. 144 "neldermead_configure",alloptions,"value",3,"foo"); 145nm = neldermead_destroy(nm); 146