1
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2
// Copyright (C) 2008-2009 - INRIA - Michael Baudin
3
// Copyright (C) 2010 - DIGITEO - Allan CORNET
4
// Copyright (C) 2011 - DIGITEO - Michael Baudin
6
// This file must be used under the terms of the CeCILL.
7
// This source file is licensed as described in the file COPYING, which
8
// you should have received as part of this distribution. The terms
9
// are also available at
10
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12
function demo_nmplot_qvariable()
14
filename = 'nmplot_quadratic.variable.sce';
15
dname = get_absolute_file_path(filename);
17
mprintf(_("Illustrates that the variable-shape Nelder-Mead algorithm performs well on a quadratic test case.\n"));
18
mprintf(_("Defining quadratic function ...\n"));
19
function [ y , index ] = quadratic ( x , index )
20
y = x(1)^2 + x(2)^2 - x(1) * x(2);
22
function y = quadraticC ( x1 , x2 )
23
y = quadratic ( [x1 , x2] , 2 )
26
mprintf(_("Creating nmplot object...\n"));
28
nm = nmplot_configure(nm, "-numberofvariables",2);
29
nm = nmplot_configure(nm, "-function",quadratic);
30
nm = nmplot_configure(nm, "-x0",[2.0 2.0]');
31
nm = nmplot_configure(nm, "-maxiter",100);
32
nm = nmplot_configure(nm, "-maxfunevals",300);
33
nm = nmplot_configure(nm, "-tolxmethod",%f);
34
nm = nmplot_configure(nm, "-tolsimplexizerelative",1.e-8);
35
nm = nmplot_configure(nm, "-simplex0method","spendley");
40
simplexfn = TMPDIR + filesep() + "history.simplex.txt";
41
nm = nmplot_configure(nm, "-simplexfn",simplexfn);
44
// Perform optimization
46
mprintf(_("Searching (please wait) ...\n"));
47
nm = nmplot_search(nm);
51
exec(fullfile(dname,"nmplot_summary.sci"),-1);
54
// Plot the contours of the cost function and the simplex history
55
mprintf(_("Plotting contour (please wait) ...\n"));
56
nm = nmplot_configure(nm, "-verbose", 0);
63
xdata=linspace(xmin,xmax,nx);
64
ydata=linspace(ymin,ymax,ny);
67
contour ( xdata , ydata , quadraticC , [0.1 1.0 2.0 5.0 10.0 15.0 20.0] )
68
nmplot_simplexhistory ( nm );
72
deletefile(simplexfn);
73
nm = nmplot_destroy(nm);
74
mprintf(_("End of demo.\n"));
77
// Load this script into the editor
79
editor ( dname + filename, "readonly" );
83
demo_nmplot_qvariable();
84
clear demo_nmplot_qvariable;
1
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2
// Copyright (C) 2008-2009 - INRIA - Michael Baudin
3
// Copyright (C) 2010 - DIGITEO - Allan CORNET
4
// Copyright (C) 2011 - DIGITEO - Michael Baudin
5
// Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS
7
// This file must be used under the terms of the CeCILL.
8
// This source file is licensed as described in the file COPYING, which
9
// you should have received as part of this distribution. The terms
10
// are also available at
11
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13
function demo_nmplot_qvariable()
15
filename = 'nmplot_quadratic.variable.sce';
16
dname = get_absolute_file_path(filename);
18
mprintf(_("Illustrates that the variable-shape Nelder-Mead algorithm performs well on a quadratic test case.\n"));
19
mprintf(_("Defining quadratic function ...\n"));
20
function [ y , index ] = quadratic ( x , index )
21
y = x(1)^2 + x(2)^2 - x(1) * x(2);
23
function y = quadraticC ( x1 , x2 )
24
y = quadratic ( [x1 , x2] , 2 )
27
mprintf(_("Creating nmplot object...\n"));
29
nm = nmplot_configure(nm, "-numberofvariables",2);
30
nm = nmplot_configure(nm, "-function",quadratic);
31
nm = nmplot_configure(nm, "-x0",[2.0 2.0]');
32
nm = nmplot_configure(nm, "-maxiter",100);
33
nm = nmplot_configure(nm, "-maxfunevals",300);
34
nm = nmplot_configure(nm, "-tolxmethod",%f);
35
nm = nmplot_configure(nm, "-tolsimplexizerelative",1.e-8);
36
nm = nmplot_configure(nm, "-simplex0method","spendley");
41
simplexfn = TMPDIR + filesep() + "history.simplex.txt";
42
nm = nmplot_configure(nm, "-simplexfn",simplexfn);
45
// Perform optimization
47
mprintf(_("Searching (please wait) ...\n"));
48
nm = nmplot_search(nm);
52
exec(fullfile(dname,"nmplot_summary.sci"),-1);
55
// Plot the contours of the cost function and the simplex history
56
mprintf(_("Plotting contour (please wait) ...\n"));
57
nm = nmplot_configure(nm, "-verbose", 0);
64
xdata=linspace(xmin,xmax,nx);
65
ydata=linspace(ymin,ymax,ny);
68
contour ( xdata , ydata , quadraticC , [0.1 1.0 2.0 5.0 10.0 15.0 20.0] )
69
nmplot_simplexhistory ( nm );
71
demo_viewCode(filename);
74
deletefile(simplexfn);
75
nm = nmplot_destroy(nm);
76
mprintf(_("End of demo.\n"));
79
demo_nmplot_qvariable();
80
clear demo_nmplot_qvariable;