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 15 16function [ y , index ] = rosenbrock ( x , index ) 17 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2; 18endfunction 19 20// Use 20 points in X and 20 points in Y 21NP = 20; 22 23// 24// Check behaviour with default settings. 25// 26nm = nmplot_new (); 27nm = nmplot_configure(nm,"-numberofvariables",2); 28nm = nmplot_configure(nm,"-function",rosenbrock); 29nm = nmplot_configure(nm,"-x0",[-1.2 1.0].'); 30nm = nmplot_configure(nm,"-maxiter",10); 31nm = nmplot_configure(nm,"-maxfunevals",300); 32nm = nmplot_configure(nm,"-tolfunrelative",10*%eps); 33nm = nmplot_configure(nm,"-tolxrelative",10*%eps); 34nm = nmplot_configure(nm,"-simplex0method","axes"); 35nm = nmplot_configure(nm,"-simplex0length",1.0); 36nm = nmplot_configure(nm,"-method","variable"); 37// 38// Setup output files 39// 40simplexfn = fullfile(TMPDIR,"simplex.txt"); 41fbarfn = fullfile(TMPDIR,"fbar.txt"); 42foptfn = fullfile(TMPDIR,"fopt.txt"); 43sigmafn = fullfile(TMPDIR,"sigma.txt"); 44nm = nmplot_configure(nm,"-simplexfn",simplexfn); 45nm = nmplot_configure(nm,"-fbarfn",fbarfn); 46nm = nmplot_configure(nm,"-foptfn",foptfn); 47nm = nmplot_configure(nm,"-sigmafn",sigmafn); 48// 49// Perform optimization 50// 51nm = nmplot_search(nm); 52// Plot the contours of the cost function and the simplex history 53xmin = -2.0; 54xmax = 2.0 ; 55ymin = -2.0 ; 56ymax = 2.0 ; 57nx = NP ; 58ny = NP; 59[nm , xdata , ydata , zdata ] = nmplot_contour ( nm , ... 60 xmin , xmax , ymin , ymax , nx , ny ); 61f = scf(); 62drawlater(); 63contour ( xdata , ydata , zdata , 20 ) 64nmplot_simplexhistory ( nm ); 65drawnow(); 66close(f); 67f = scf(); 68mytitle = "Function Value Average" ; 69myxlabel = "Iterations"; 70nmplot_historyplot ( nm , fbarfn , mytitle , myxlabel); 71close(f); 72f = scf(); 73mytitle = "Minimum Function Value" ; 74myxlabel = "Iterations"; 75nmplot_historyplot ( nm , foptfn , mytitle , myxlabel); 76close(f); 77f = scf(); 78mytitle = "Maximum Oriented length" ; 79myxlabel = "Iterations"; 80nmplot_historyplot ( nm , sigmafn , mytitle , myxlabel); 81close(f); 82deletefile(simplexfn); 83deletefile(fbarfn); 84deletefile(foptfn); 85deletefile(sigmafn); 86nm = nmplot_destroy(nm); 87 88 89 90