1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Copyright (C) 2011 - DIGITEO - Michael Baudin 3// 4// Copyright (C) 2012 - 2016 - Scilab Enterprises 5// 6// This file is hereby licensed under the terms of the GNU GPL v2.0, 7// pursuant to article 5.3.4 of the CeCILL v.2.1. 8// This file was originally licensed under the terms of the CeCILL v2.1, 9// and continues to be available under such terms. 10// For more information, see the COPYING file which you should have received 11// along with this program. 12 13// <-- CLI SHELL MODE --> 14// <-- ENGLISH IMPOSED --> 15// <-- NO CHECK REF --> 16 17// This test is designed to produce a warning: 18// this warning is localized. 19// This is why we do not check the ref. 20// Checking the ref file under Linux fails, because 21// <-- ENGLISH IMPOSED --> has no effect there. 22// See : http://bugzilla.scilab.org/show_bug.cgi?id=9284 23 24 25function [ y , index ] = rosenbrock ( x , index ) 26 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; 27endfunction 28 29// 30// Check backward compatibility: 31// check obsolete options "-myterminateflag" and "-myterminate". 32// 33function [ this , terminate , status ] = mystoppingrule2 ( this , simplex ) 34 ssize = optimsimplex_size ( simplex , "sigmaplus" ); 35 if ( ssize < 1.e-2 ) then 36 terminate = %t; 37 status = "mysize"; 38 else 39 terminate = %f 40 end 41 42endfunction 43 44 45 46// 47// Test with my own termination criteria 48// 49nm = neldermead_new (); 50nm = neldermead_configure(nm,"-numberofvariables",2); 51nm = neldermead_configure(nm,"-function",rosenbrock); 52nm = neldermead_configure(nm,"-x0",[1.1 1.1]'); 53nm = neldermead_configure(nm,"-maxiter",%inf); 54nm = neldermead_configure(nm,"-maxfunevals",%inf); 55nm = neldermead_configure(nm,"-method","variable"); 56// Disable default terminations 57nm = neldermead_configure(nm,"-tolxmethod",%f); 58nm = neldermead_configure(nm,"-tolsimplexizemethod",%f); 59nm = neldermead_configure(nm,"-myterminateflag",%t); 60nm = neldermead_configure(nm,"-myterminate",mystoppingrule2); 61// 62// Check cget 63value = neldermead_cget(nm,"-myterminateflag"); 64assert_checktrue ( value ); 65// 66value = neldermead_cget(nm,"-myterminate"); 67assert_checkequal ( typeof(value) , "function" ); 68// 69nm = neldermead_search(nm); 70// Check optimum point 71xopt = neldermead_get(nm,"-xopt"); 72assert_checkalmostequal ( xopt , [1.0 1.0]', 1e-2 ); 73// Check optimum point value 74fopt = neldermead_get(nm,"-fopt"); 75assert_checkalmostequal ( fopt , 0.0 , [] , 1e-4 ); 76// Check status 77status = neldermead_get(nm,"-status"); 78assert_checkequal ( status , "mysize" ); 79nm = neldermead_destroy(nm); 80 81