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// <-- ENGLISH IMPOSED --> 16 17 18 19 20 21function stop = myoutputcmd ( state , data ) 22 simplex = data.simplex 23 ssize = optimsimplex_size ( simplex , "sigmaplus" ); 24 if ( ssize < 1.e-2 ) then 25 stop = %t; 26 status = "mysize"; 27 else 28 stop = %f 29 end 30endfunction 31 32function [ y , index ] = rosenbrock ( x , index ) 33 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; 34endfunction 35 36 37 38 39// 40// Test with my own termination criteria 41// 42nm = neldermead_new (); 43nm = neldermead_configure(nm,"-numberofvariables",2); 44nm = neldermead_configure(nm,"-function",rosenbrock); 45nm = neldermead_configure(nm,"-x0",[1.1 1.1]'); 46nm = neldermead_configure(nm,"-maxiter",%inf); 47nm = neldermead_configure(nm,"-maxfunevals",%inf); 48nm = neldermead_configure(nm,"-method","variable"); 49// Disable default terminations 50nm = neldermead_configure(nm,"-tolxmethod",%f); 51nm = neldermead_configure(nm,"-tolsimplexizemethod",%f); 52nm = neldermead_configure(nm,"-outputcommand",myoutputcmd); 53nm = neldermead_search(nm); 54// Check optimum point 55xopt = neldermead_get(nm,"-xopt"); 56assert_checkalmostequal ( xopt , [1.0 1.0]', 1e-2 ); 57// Check optimum point value 58fopt = neldermead_get(nm,"-fopt"); 59assert_checkalmostequal ( fopt , 0.0 , [] , 1e-4 ); 60// Check status 61status = neldermead_get(nm,"-status"); 62assert_checkequal ( status , "userstop" ); 63// Check simplex size 64simplex = neldermead_get(nm,"-simplexopt"); 65ssize = optimsimplex_size ( simplex , "sigmaplus" ); 66assert_checkequal ( ssize<1.e-1 , %t ); 67// Check function evaluations 68funevals = neldermead_get(nm,"-funevals"); 69assert_checkequal ( funevals<200 , %t ); 70nm = neldermead_destroy(nm); 71 72 73