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 - Michael Baudin
4
// Copyright (C) 2010 - DIGITEO - Allan CORNET
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
13
// nmplot_boxpost.sce --
14
// Show that the Box algorithm is able to reproduce the
15
// numerical experiment presented in Richardson and Kuester's paper.
16
// Rosenbrock's Post Office
19
function demo_boxpost()
21
filename = 'neldermead_boxpost.sce';
22
dname = get_absolute_file_path(filename);
24
mprintf(_("Illustrates Box'' algorithm on Rosenbrock''s Post Office Problem.\n"));
25
mprintf(_("Defining Rosenbrock Post Office function...\n"));
31
// The complex method for constrained
33
// Richardson, Kuester
36
// An automatic method for finding the
37
// greatest or least value of a function
41
// Richardson and Kuester Results :
52
// Computes the Post Office cost function and
53
// inequality constraints.
56
// x: the point where to compute the function
57
// index : the stuff to compute
60
function [ f , c , index ] = fpostoffice ( x , index )
63
if ( index==2 | index==6 ) then
64
f = -x(1) * x(2) * x(3)
67
if ( index==5 | index==6 ) then
68
c1 = x(1) + 2 * x(2) + 2 * x(3)
74
// Initialize the random number generator, so that the results are always the
80
// Compute f(x0) : should be close to -1
81
fx0 = fpostoffice ( x0 , 2 );
82
mprintf("Computed fx0 = %e (expected = %e)\n",fx0 , -1 );
83
[ fx0 , cx0, index ] = fpostoffice ( x0 , 6 );
84
mprintf("Computed Constraints(x0) = [%e %e]\n", ..
86
mprintf("Expected Constraints(x0) = [%e %e]\n", ..
90
// Compute f(xopt) : should be 3456
91
fopt = fpostoffice ( xopt );
92
mprintf("Computed fopt = %e (expected = %e)\n", fopt , -3456 );
94
nm = neldermead_new ();
95
nm = neldermead_configure(nm,"-numberofvariables",3);
96
nm = neldermead_configure(nm,"-function",fpostoffice);
97
nm = neldermead_configure(nm,"-x0",x0);
98
nm = neldermead_configure(nm,"-maxiter",300);
99
nm = neldermead_configure(nm,"-maxfunevals",300);
100
nm = neldermead_configure(nm,"-method","box");
101
nm = neldermead_configure(nm,"-verbose",1);
102
logfile = TMPDIR + "/postoffice.txt";
103
nm = neldermead_configure(nm,"-logfile" , logfile );
104
nm = neldermead_configure(nm,"-verbosetermination",1);
105
nm = neldermead_configure(nm,"-boundsmin",[0.0 0.0 0.0]);
106
nm = neldermead_configure(nm,"-boundsmax",[42.0 42.0 42.0]);
107
// Configure like Box
108
nm = neldermead_configure(nm,"-simplex0method","randbounds");
109
nm = neldermead_configure(nm,"-nbineqconst",2);
110
nm = neldermead_configure(nm,"-tolxmethod" , %f );
111
nm = neldermead_configure(nm,"-tolsimplexizemethod",%f);
112
nm = neldermead_configure(nm,"-boxtermination" , %t );
113
nm = neldermead_configure(nm,"-boxtolf" , 0.001 );
114
nm = neldermead_configure(nm,"-boxboundsalpha" , 0.0001 );
117
// Check that the cost function is correctly connected.
119
[ nm , result ] = neldermead_function ( nm , x0 );
122
// Perform optimization
124
mprintf(_("Searching (please wait) ...\n"));
125
nm = neldermead_search(nm);
129
exec(fullfile(dname,"neldermead_summary.sci"),-1);
130
neldermead_summary(nm)
131
mprintf("==========================\n");
132
xcomp = neldermead_get(nm,"-xopt");
133
mprintf("x expected = [%s]\n",strcat(string(xopt)," "));
134
shift = norm(xcomp-xopt)/norm(xopt);
135
mprintf("Shift = %f\n",shift);
136
fcomp = neldermead_get(nm,"-fopt");
137
mprintf("f expected = %f\n",fopt);
138
shift = abs(fcomp-fopt)/abs(fopt);
139
mprintf("Shift = %f\n",shift);
140
nm = neldermead_destroy(nm);
141
deletefile ( logfile )
142
mprintf(_("End of demo.\n"));
145
// Load this script into the editor
147
editor ( dname + filename, "readonly" );
b'\\ No newline at end of file'
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 - Michael Baudin
4
// Copyright (C) 2010 - DIGITEO - Allan CORNET
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
14
// nmplot_boxpost.sce --
15
// Show that the Box algorithm is able to reproduce the
16
// numerical experiment presented in Richardson and Kuester's paper.
17
// Rosenbrock's Post Office
20
function demo_boxpost()
22
filename = 'neldermead_boxpost.sce';
23
dname = get_absolute_file_path(filename);
25
mprintf(_("Illustrates Box'' algorithm on Rosenbrock''s Post Office Problem.\n"));
26
mprintf(_("Defining Rosenbrock Post Office function...\n"));
32
// The complex method for constrained
34
// Richardson, Kuester
37
// An automatic method for finding the
38
// greatest or least value of a function
42
// Richardson and Kuester Results :
53
// Computes the Post Office cost function and
54
// inequality constraints.
57
// x: the point where to compute the function
58
// index : the stuff to compute
61
function [ f , c , index ] = fpostoffice ( x , index )
64
if ( index==2 | index==6 ) then
65
f = -x(1) * x(2) * x(3)
68
if ( index==5 | index==6 ) then
69
c1 = x(1) + 2 * x(2) + 2 * x(3)
75
// Initialize the random number generator, so that the results are always the
81
// Compute f(x0) : should be close to -1
82
fx0 = fpostoffice ( x0 , 2 );
83
mprintf("Computed fx0 = %e (expected = %e)\n",fx0 , -1 );
84
[ fx0 , cx0, index ] = fpostoffice ( x0 , 6 );
85
mprintf("Computed Constraints(x0) = [%e %e]\n", ..
87
mprintf("Expected Constraints(x0) = [%e %e]\n", ..
91
// Compute f(xopt) : should be 3456
92
fopt = fpostoffice ( xopt );
93
mprintf("Computed fopt = %e (expected = %e)\n", fopt , -3456 );
95
nm = neldermead_new ();
96
nm = neldermead_configure(nm,"-numberofvariables",3);
97
nm = neldermead_configure(nm,"-function",fpostoffice);
98
nm = neldermead_configure(nm,"-x0",x0);
99
nm = neldermead_configure(nm,"-maxiter",300);
100
nm = neldermead_configure(nm,"-maxfunevals",300);
101
nm = neldermead_configure(nm,"-method","box");
102
nm = neldermead_configure(nm,"-verbose",1);
103
logfile = TMPDIR + "/postoffice.txt";
104
nm = neldermead_configure(nm,"-logfile" , logfile );
105
nm = neldermead_configure(nm,"-verbosetermination",1);
106
nm = neldermead_configure(nm,"-boundsmin",[0.0 0.0 0.0]);
107
nm = neldermead_configure(nm,"-boundsmax",[42.0 42.0 42.0]);
108
// Configure like Box
109
nm = neldermead_configure(nm,"-simplex0method","randbounds");
110
nm = neldermead_configure(nm,"-nbineqconst",2);
111
nm = neldermead_configure(nm,"-tolxmethod" , %f );
112
nm = neldermead_configure(nm,"-tolsimplexizemethod",%f);
113
nm = neldermead_configure(nm,"-boxtermination" , %t );
114
nm = neldermead_configure(nm,"-boxtolf" , 0.001 );
115
nm = neldermead_configure(nm,"-boxboundsalpha" , 0.0001 );
118
// Check that the cost function is correctly connected.
120
[ nm , result ] = neldermead_function ( nm , x0 );
123
// Perform optimization
125
mprintf(_("Searching (please wait) ...\n"));
126
nm = neldermead_search(nm);
130
exec(fullfile(dname,"neldermead_summary.sci"),-1);
131
neldermead_summary(nm)
132
mprintf("==========================\n");
133
xcomp = neldermead_get(nm,"-xopt");
134
mprintf("x expected = [%s]\n",strcat(string(xopt)," "));
135
shift = norm(xcomp-xopt)/norm(xopt);
136
mprintf("Shift = %f\n",shift);
137
fcomp = neldermead_get(nm,"-fopt");
138
mprintf("f expected = %f\n",fopt);
139
shift = abs(fcomp-fopt)/abs(fopt);
140
mprintf("Shift = %f\n",shift);
141
nm = neldermead_destroy(nm);
142
deletefile ( logfile )
143
mprintf(_("End of demo.\n"));
146
// Load this script into the editor
148
m = messagebox(_("View Code?"), "Question", "question", [_("Yes") _("No")], "modal")
150
editor ( dname + filename, "readonly" );