1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## Checks wether the function 'nelder_mead_min' accepts options properly
21 if ! exist ("verbose"), verbose = 0; end
22 if ! exist ("inspect"), inspect = 0; end
25 printf (["test_nelder_mead_2\n",\
26 " Check whether nelder_mead_min accepts options properly\n\n"]);
32 vol = (small^N) / factorial (N);
34 ## Define simple 2D function : [x,y] -> x^2, start from [0,0]
37 function c = my_func (x)
41 ######################################################################
42 ## Test using volume #################################################
44 ## Choose vtol and initial simplex so that algo should stop immediately.
45 ctl = struct ("verbose",verbose, "isz",small, "vtol",vol*1.01, "rst",0);
47 [x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
50 if verbose || inspect, printf ("not ok %i\n",cnt); end
51 if inspect, keyboard; end
55 printf ("ok %i\n",cnt);
60 ## Choose vtol and initial simplex so that algo should stop after one
61 ## iteration (should be a reflexion and a tentative extension). Total is 5
63 ctl = struct ("verbose",verbose, "isz",small, "vtol",vol*0.99, "rst",0);
67 [x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
70 if verbose || inspect, printf ("not ok %i\n",cnt); end
71 if inspect, keyboard; end
75 printf ("ok %i\n",cnt);
80 ######################################################################
81 ## Test using radius #################################################
83 ## Choose rtol and initial simplex so that algo stops immediately.
84 ctl = struct ("verbose",verbose, "isz",small, "rtol",small*2.01, "rst",0);
86 [x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
89 if verbose || inspect, printf ("not ok %i\n",cnt); end
90 if inspect, keyboard; end
94 printf ("ok %i\n",cnt);
99 ## Choose rtol and initial simplex so that algo does not stop immediately.
100 ctl = struct ("verbose",verbose, "isz",small, "rtol",small*1.99, "rst",0);
102 [x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
105 if verbose || inspect, printf ("not ok %i\n",cnt); end
106 if inspect, keyboard; end
110 printf ("ok %i\n",cnt);
115 ######################################################################
116 ## Test using values #################################################
118 ## Choose rtol and initial simplex so that algo should stop immediately.
119 ctl = struct ("verbose",verbose, "isz",small, "ftol",1.01*small^2, "rst",0);
121 [x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
124 if verbose || inspect, printf ("not ok %i\n",cnt); end
125 if inspect, keyboard; end
129 printf ("ok %i\n",cnt);
134 ## Choose rtol and initial simplex so that algo does not stop immediately.
135 ctl = struct ("verbose",verbose, "isz",small, "ftol",0.99*small^2, "rst",0);
137 [x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
140 if verbose || inspect, printf ("not ok %i\n",cnt); end
141 if inspect, keyboard; end
145 printf ("ok %i\n",cnt);
152 printf ("All %i tests ok\n", cnt);