/usr/share/octave/packages/optim-1.4.0/samin_example.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 | ## Copyright (C) 2004 Michael Creel <michael.creel@uab.es>
##
## 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/>.
# samin_example: example script that contains examples of how to call
# samin for minimization using simulated annealing.
# Edit the script to see how samin may be used.
#
# usage: samin_example
1; # this is a script file
# Example objective function
# remember that cos(0)=1, so
# "a" has a local minimum at 0 (each dimension)
# "b" makes the function value 0 at min
# "c" adds some curvature to make the min
# at (0,0,...,0) global.
# the closer is "curvature" to zero the more alike are
# the local mins, so the harder the global min is to find
function f = obj(theta, curvature);
dim = rows(theta);
a = sum(exp(-cos(theta)));
b = - dim*exp(-1);
c = sum(curvature*theta .^ 2);
f = a + b + c;
endfunction
k = 5; # dimensionality
theta = rand(k,1)*10 - 5; # random start value
# if you set "curvature" very small,
# you will need to increase nt, ns, and rt
# to minimize sucessfully
curvature = 0.01;
# SA controls
ub = 10*ones(rows(theta),1);
lb = -ub;
# setting ub and lb to same value restricts that parameter, and the algorithm does not search
ub(1,:) = 0;
lb(1,:) = 0;
theta(1,:) = 0; # must satisfy restriction
nt = 20;
ns = 5;
rt = 0.5; # careful - this is too low for many problems
maxevals = 1e10;
neps = 5;
functol = 1e-10;
paramtol = 1e-3;
verbosity = 1; # only final results. Inc
minarg = 1;
control = { lb, ub, nt, ns, rt, maxevals, neps, functol, paramtol, verbosity, 1};
# do sa
t=cputime();
[theta, obj_value, convergence] = samin("obj", {theta, curvature}, control);
t = cputime() - t;
printf("Elapsed time = %f\n\n\n",t);
|