/usr/share/octave/packages/optim-1.4.0/test_nelder_mead_min_2.m is in octave-optim 1.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
## Checks wether the function 'nelder_mead_min' accepts options properly
ok = 1;
cnt = 1;
if ! exist ("verbose"), verbose = 0; end
if ! exist ("inspect"), inspect = 0; end
if verbose,
printf (["test_nelder_mead_2\n",...
" Check whether nelder_mead_min accepts options properly\n\n"]);
end
N = 2;
x1 = zeros (1,N);
small = 1e-3;
vol = (small^N) / factorial (N);
## Define simple 2D function : [x,y] -> x^2, start from [0,0]
##
function c = my_func (x)
c = x(1)^2;
end
######################################################################
## Test using volume #################################################
## Choose vtol and initial simplex so that algo should stop immediately.
ctl = struct ("verbose",verbose, "isz",small, "vtol",vol*1.01, "rst",0);
[x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
if nev != N+1
if verbose || inspect, printf ("not ok %i\n",cnt); end
if inspect, keyboard; end
ok = 0 ;
else
if verbose,
printf ("ok %i\n",cnt);
end
end
cnt++;
## Choose vtol and initial simplex so that algo should stop after one
## iteration (should be a reflexion and a tentative extension). Total is 5
## evaluations.
ctl = struct ("verbose",verbose, "isz",small, "vtol",vol*0.99, "rst",0);
x1 = [0,0];
[x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
if nev != N+3
if verbose || inspect, printf ("not ok %i\n",cnt); end
if inspect, keyboard; end
ok = 0 ;
else
if verbose,
printf ("ok %i\n",cnt);
end
end
cnt++;
######################################################################
## Test using radius #################################################
## Choose rtol and initial simplex so that algo stops immediately.
ctl = struct ("verbose",verbose, "isz",small, "rtol",small*2.01, "rst",0);
[x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
if nev != N+1
if verbose || inspect, printf ("not ok %i\n",cnt); end
if inspect, keyboard; end
ok = 0 ;
else
if verbose,
printf ("ok %i\n",cnt);
end
end
cnt++;
## Choose rtol and initial simplex so that algo does not stop immediately.
ctl = struct ("verbose",verbose, "isz",small, "rtol",small*1.99, "rst",0);
[x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
if nev <= N+1
if verbose || inspect, printf ("not ok %i\n",cnt); end
if inspect, keyboard; end
ok = 0 ;
else
if verbose,
printf ("ok %i\n",cnt);
end
end
cnt++;
######################################################################
## Test using values #################################################
## Choose rtol and initial simplex so that algo should stop immediately.
ctl = struct ("verbose",verbose, "isz",small, "ftol",1.01*small^2, "rst",0);
[x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
if nev != N+1
if verbose || inspect, printf ("not ok %i\n",cnt); end
if inspect, keyboard; end
ok = 0 ;
else
if verbose,
printf ("ok %i\n",cnt);
end
end
cnt++;
## Choose rtol and initial simplex so that algo does not stop immediately.
ctl = struct ("verbose",verbose, "isz",small, "ftol",0.99*small^2, "rst",0);
[x2,v,nev] = nelder_mead_min ("my_func", x1, ctl);
if nev <= N+1
if verbose || inspect, printf ("not ok %i\n",cnt); end
if inspect, keyboard; end
ok = 0 ;
else
if verbose
printf ("ok %i\n",cnt);
end
end
cnt++;
cnt--;
if verbose && ok
printf ("All %i tests ok\n", cnt);
end
|