Renamed mtlb_fminsearch into fminsearch. Added demos.
[scilab.git] / scilab / modules / optimization / demos / neldermead / nmplot_rosenbrock.fixed.sce
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008-2009 - INRIA - Michael Baudin
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10
11 function y = rosenbrock (x)
12   y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
13 endfunction
14
15 nm = nmplot_new ();
16 nm = nmplot_configure(nm,"-numberofvariables",2);
17 nm = nmplot_configure(nm,"-function",rosenbrock);
18 nm = nmplot_configure(nm,"-x0",[-1.2 1.0]');
19 nm = nmplot_configure(nm,"-maxiter",200);
20 nm = nmplot_configure(nm,"-maxfunevals",300);
21 nm = nmplot_configure(nm,"-tolfunrelative",10*%eps);
22 nm = nmplot_configure(nm,"-tolxrelative",10*%eps);
23 nm = nmplot_configure(nm,"-simplex0method","axes");
24 nm = nmplot_configure(nm,"-simplex0length",1.0);
25 nm = nmplot_configure(nm,"-method","fixed");
26 nm = nmplot_configure(nm,"-verbose",1);
27 nm = nmplot_configure(nm,"-verbosetermination",0);
28 //
29 // Setup output files
30 //
31 nm = nmplot_configure(nm,"-simplexfn","rosenbrock.fixed.history.simplex.txt");
32 nm = nmplot_configure(nm,"-fbarfn","rosenbrock.fixed.history.fbar.txt");
33 nm = nmplot_configure(nm,"-foptfn","rosenbrock.fixed.history.fopt.txt");
34 nm = nmplot_configure(nm,"-sigmafn","rosenbrock.fixed.history.sigma.txt");
35 //
36 // Perform optimization
37 //
38 nm = nmplot_search(nm);
39 // Plot the contours of the cost function and the simplex history
40 [nm , xdata , ydata , zdata ] = nmplot_contour ( nm , xmin = -2.0 , xmax = 2.0 , ymin = -2.0 , ymax = 2.0 , nx = 100 , ny = 100 );
41 f = scf();
42 contour ( xdata , ydata , zdata , 20 )
43 nmplot_simplexhistory ( nm );
44 xs2png(0,"rosenbrock.fixed.history.simplex.png");
45 f = scf();
46 nmplot_historyplot ( nm , "rosenbrock.fixed.history.fbar.txt" , ...
47   mytitle = "Function Value Average" , myxlabel = "Iterations" );
48 xs2png(1,"rosenbrock.fixed.history.fbar.png");
49 f = scf();
50 nmplot_historyplot ( nm , "rosenbrock.fixed.history.fopt.txt" , ...
51   mytitle = "Minimum Function Value" , myxlabel = "Iterations" );
52 xs2png(2,"rosenbrock.fixed.history.fopt.png");
53 f = scf();
54 nmplot_historyplot ( nm , "rosenbrock.fixed.history.sigma.txt" , ...
55   mytitle = "Maximum Oriented length" , myxlabel = "Iterations" );
56 xs2png(3,"rosenbrock.fixed.history.sigma.png");
57 deletefile("rosenbrock.fixed.history.simplex.txt");
58 deletefile("rosenbrock.fixed.history.fbar.txt");
59 deletefile("rosenbrock.fixed.history.fopt.txt");
60 deletefile("rosenbrock.fixed.history.sigma.txt");
61 nm = nmplot_destroy(nm);
62
63