1 ## Copyright (C) 2004 Michael Creel <michael.creel@uab.es>
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 ## battery.m: repeatedly call bfgs using a battery of
17 ## start values, to attempt to find global min
18 ## of a nonconvex function
21 ## func: function to mimimize
22 ## args: args of function
23 ## minarg: argument to minimize w.r.t. (usually = 1)
24 ## startvals: kxp matrix of values to try for sure (don't include all zeros, that's automatic)
25 ## max iters per start value
26 ## number of additional random start values to try
28 # OUTPUT: theta - the best value found - NOT iterated to convergence
30 function theta = battery(func, args, minarg, startvals, maxiters)
33 [k,trials] = size(startvals);
35 besttheta = zeros(k,1);
36 bfgscontrol = {maxiters,0,0,1};
37 # now try the supplied start values, and optionally the random start values
39 args{minarg} = startvals(:,i);
40 [theta, obj_value, convergence] = bfgsmin (func, args, bfgscontrol);
42 if obj_value < bestobj