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_qfixed2()
14
filename = 'nmplot_quadratic.fixed2.sce';
15
dname = get_absolute_file_path(filename);
17
mprintf(_("Illustrates that the fixed-shape Spendley et al. algorithm performs badly on a badly quadratic test case.\n"));
18
mprintf(_("Defining quadratic function...\n"));
21
function [ y , index ] = quadratic ( x , index )
22
y = a * x(1)^2 + x(2)^2;
24
function y = quadraticC ( x1 , x2 )
25
y = quadratic ( [x1 , x2] , 2 )
28
mprintf(_("Creating nmplot object ...\n"));
30
nm = nmplot_configure(nm, "-numberofvariables",2);
31
nm = nmplot_configure(nm, "-function",quadratic);
32
nm = nmplot_configure(nm, "-x0",[10.0 10.0]');
33
nm = nmplot_configure(nm, "-maxiter",400);
34
nm = nmplot_configure(nm, "-maxfunevals",400);
35
nm = nmplot_configure(nm, "-tolxmethod",%f);
36
nm = nmplot_configure(nm, "-tolsimplexizerelative",1.e-8);
37
nm = nmplot_configure(nm, "-simplex0method","spendley");
38
nm = nmplot_configure(nm, "-method","fixed");
43
simplexfn = TMPDIR + filesep() + "history.simplex.txt";
44
nm = nmplot_configure(nm, "-simplexfn",simplexfn);
47
// Perform optimization
49
mprintf(_("Searching (please wait) ...\n"));
50
nm = nmplot_search(nm);
54
exec(fullfile(dname,"nmplot_summary.sci"),-1);
57
// Plot the contours of the cost function and the simplex history
58
mprintf(_("Plotting contour (please wait) ...\n"));
59
nm = nmplot_configure(nm, "-verbose", 0);
68
xdata=linspace(xmin,xmax,nx);
69
ydata=linspace(ymin,ymax,ny);
70
contour ( xdata , ydata , quadraticC , [10.0 50 100 1000 2000 5000 10000 20000] )
71
nmplot_simplexhistory ( nm );
75
deletefile(simplexfn);
76
nm = nmplot_destroy(nm);
77
mprintf("End of demo.\n");
80
// Load this script into the editor
82
editor ( dname + filename, "readonly" );
86
demo_nmplot_qfixed2();
87
clear demo_nmplot_qfixed2;
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_qfixed2()
15
filename = 'nmplot_quadratic.fixed2.sce';
16
dname = get_absolute_file_path(filename);
18
mprintf(_("Illustrates that the fixed-shape Spendley et al. algorithm performs badly on a badly quadratic test case.\n"));
19
mprintf(_("Defining quadratic function...\n"));
22
function [ y , index ] = quadratic ( x , index )
23
y = a * x(1)^2 + x(2)^2;
25
function y = quadraticC ( x1 , x2 )
26
y = quadratic ( [x1 , x2] , 2 )
29
mprintf(_("Creating nmplot object ...\n"));
31
nm = nmplot_configure(nm, "-numberofvariables",2);
32
nm = nmplot_configure(nm, "-function",quadratic);
33
nm = nmplot_configure(nm, "-x0",[10.0 10.0]');
34
nm = nmplot_configure(nm, "-maxiter",400);
35
nm = nmplot_configure(nm, "-maxfunevals",400);
36
nm = nmplot_configure(nm, "-tolxmethod",%f);
37
nm = nmplot_configure(nm, "-tolsimplexizerelative",1.e-8);
38
nm = nmplot_configure(nm, "-simplex0method","spendley");
39
nm = nmplot_configure(nm, "-method","fixed");
44
simplexfn = TMPDIR + filesep() + "history.simplex.txt";
45
nm = nmplot_configure(nm, "-simplexfn",simplexfn);
48
// Perform optimization
50
mprintf(_("Searching (please wait) ...\n"));
51
nm = nmplot_search(nm);
55
exec(fullfile(dname,"nmplot_summary.sci"),-1);
58
// Plot the contours of the cost function and the simplex history
59
mprintf(_("Plotting contour (please wait) ...\n"));
60
nm = nmplot_configure(nm, "-verbose", 0);
69
xdata=linspace(xmin,xmax,nx);
70
ydata=linspace(ymin,ymax,ny);
71
contour ( xdata , ydata , quadraticC , [10.0 50 100 1000 2000 5000 10000 20000] )
72
nmplot_simplexhistory ( nm );
74
demo_viewCode(filename);
77
deletefile(simplexfn);
78
nm = nmplot_destroy(nm);
79
mprintf("End of demo.\n");
82
demo_nmplot_qfixed2();
83
clear demo_nmplot_qfixed2;