1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008-2009 - INRIA - Michael Baudin
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
11 //dirname = get_absolute_file_path('nmplot_mckinnon.sce');
12 //% MCKINNON computes the McKinnon function.
16 // This function has a global minimizer:
18 // X* = ( 0.0, -0.5 ), F(X*) = -0.25
20 // There are three parameters, TAU, THETA and PHI.
22 // 1 < TAU, then F is strictly convex.
23 // and F has continuous first derivatives.
24 // 2 < TAU, then F has continuous second derivatives.
25 // 3 < TAU, then F has continuous third derivatives.
27 // However, this function can cause the Nelder-Mead optimization
28 // algorithm to "converge" to a point which is not the minimizer
31 // Sample parameter values which cause problems for Nelder-Mead
34 // TAU = 1, THETA = 15, PHI = 10;
35 // TAU = 2, THETA = 6, PHI = 60;
36 // TAU = 3, THETA = 6, PHI = 400;
38 // To get the bad behavior, we also assume the initial simplex has the form
46 // A = (1+sqrt(33))/8 = 0.84307...
47 // B = (1-sqrt(33))/8 = -0.59307...
51 // This code is distributed under the GNU LGPL license.
64 // Convergence of the Nelder-Mead simplex method to a nonstationary point,
65 // SIAM Journal on Optimization,
66 // Volume 9, Number 1, 1998, pages 148-158.
70 // Input, real X(2), the argument of the function.
72 // Output, real F, the value of the function at X.
74 // Copyright (C) 2009 - INRIA - Michael Baudin, Scilab port
76 function f = mckinnon3 ( x )
78 if ( length ( x ) ~= 2 )
79 error ( 'Error: function expects a two dimensional input\n' );
87 f = theta * phi * abs ( x(1) ).^tau + x(2) * ( 1.0 + x(2) );
89 f = theta * x(1).^tau + x(2) * ( 1.0 + x(2) );
94 lambda1 = (1.0 + sqrt(33.0))/8.0
95 lambda2 = (1.0 - sqrt(33.0))/8.0
103 nm = nmplot_configure(nm,"-numberofvariables",2);
104 nm = nmplot_configure(nm,"-function",mckinnon3);
105 nm = nmplot_configure(nm,"-x0",[1.0 1.0]');
106 nm = nmplot_configure(nm,"-maxiter",200);
107 nm = nmplot_configure(nm,"-maxfunevals",300);
108 nm = nmplot_configure(nm,"-tolfunrelative",10*%eps);
109 nm = nmplot_configure(nm,"-tolxrelative",10*%eps);
110 nm = nmplot_configure(nm,"-simplex0method","given");
111 nm = nmplot_configure(nm,"-coords0",coords0);
112 nm = nmplot_configure(nm,"-simplex0length",1.0);
113 nm = nmplot_configure(nm,"-method","variable");
114 //nm = nmplot_configure(nm,"-verbose",1);
115 nm = nmplot_configure(nm,"-verbosetermination",1);
117 // Setup output files
119 nm = nmplot_configure(nm,"-simplexfn","mckinnon.history.simplex.txt");
120 nm = nmplot_configure(nm,"-fbarfn","mckinnon.history.fbar.txt");
121 nm = nmplot_configure(nm,"-foptfn","mckinnon.history.fopt.txt");
122 nm = nmplot_configure(nm,"-sigmafn","mckinnon.history.sigma.txt");
124 // Perform optimization
126 nm = nmplot_search(nm);
130 [nm , xdata , ydata , zdata ] = nmplot_contour ( nm , xmin = -0.2 , xmax = 1.2 , ymin = -2.0 , ymax = 2.0 , nx = 50 , ny = 50 );
133 contour ( xdata , ydata , zdata , 40 )
134 nmplot_simplexhistory ( nm );
135 xs2png(0,"mckinnon.history.simplex.png");
137 nmplot_historyplot ( nm , "mckinnon.history.fbar.txt" , ...
138 mytitle = "Function Value Average" , myxlabel = "Iterations" );
139 xs2png(1,"mckinnon.history.fbar.png");
141 nmplot_historyplot ( nm , "mckinnon.history.fopt.txt" , ...
142 mytitle = "Minimum Function Value" , myxlabel = "Iterations" );
143 xs2png(2,"mckinnon.history.fopt.png");
145 nmplot_historyplot ( nm , "mckinnon.history.sigma.txt" , ...
146 mytitle = "Maximum Oriented length" , myxlabel = "Iterations" );
147 xs2png(3,"mckinnon.history.sigma.png");
148 deletefile("mckinnon.history.simplex.txt");
149 deletefile("mckinnon.history.fbar.txt");
150 deletefile("mckinnon.history.fopt.txt");
151 deletefile("mckinnon.history.sigma.txt");
152 nm = nmplot_destroy(nm);