]> Creatis software - CreaPhase.git/blob - octave_packages/optim-1.2.0/optimset_compat.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / optim-1.2.0 / optimset_compat.m
1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## opt = optimset_compat (...)         - manipulate m*tlab-style options structure
17 ## 
18 ## This function returns a m*tlab-style options structure that can be used
19 ## with the fminunc() function. 'optimset_compat' has been deprecated in
20 ## favor of 'optimset', which is now part of core Octave. This function
21 ## will possibly be removed from future versions of the 'optim' package.
22 ##
23 ## INPUT : Input consist in one or more structs followed by option-value
24 ## pairs. The option that can be passed are those of m*tlab's 'optimset'.
25 ## Whether fminunc() accepts them is another question (see fminunc()).
26 ## 
27 ## Two extra options are supported which indicate how to use directly octave
28 ## optimization tools (such as minimize() and other backends):
29 ##
30 ## "MinEquiv", [on|off] : Tell 'fminunc()' not to minimize 'fun', but
31 ##                        instead return the option passed to minimize().
32 ##
33 ## "Backend", [on|off] : Tell 'fminunc()' not to minimize 'fun', but
34 ##                       instead return the [backend, opt], the name of the
35 ##                       backend optimization function that is used and the
36 ##                       optional arguments that will be passed to it. See
37 ##                       the 'backend' option of minimize().
38
39 function opt = optimset_compat (varargin)
40
41 ## Diagnostics  , ["on"|{"off"}] : 
42 ## DiffMaxChange, [scalar>0]     : N/A (I don't know what it does)
43 ## DiffMinChange, [scalar>0]     : N/A (I don't know what it does)
44 ## Display      , ["off","iter","notify","final"] 
45 ##                               : N/A
46
47   persistent warned = false;
48   if (! warned)
49     warned = true;
50     warning ("Octave:deprecated-function",
51              "`optimset_compat' has been deprecated, and will be removed in the future. Use `optimset' from Octave core instead.");
52   endif
53
54 args = varargin;
55
56 opt = struct ();
57
58                                 # Integrate all leading structs
59
60 while length (args) && isstruct (o = args{1})
61
62   args = args(2:length(args));  # Remove 1st element of args
63                                 # Add key/value pairs
64   for [v,k] = o, opt = setfield (opt,k,v); end    
65 end
66
67 ## All the option
68 op1 = [" DerivativeCheck Diagnostics DiffMaxChange DiffMinChange",\
69        " Display GoalsExactAchieve GradConstr GradObj Hessian HessMult",\
70        " HessPattern HessUpdate Jacobian JacobMult JacobPattern",\
71        " LargeScale LevenbergMarquardt LineSearchType MaxFunEvals MaxIter",\
72        " MaxPCGIter MeritFunction MinAbsMax PrecondBandWidth TolCon",\
73        " TolFun TolPCG TolX TypicalX ",\
74        " MinEquiv Backend "];
75
76 opt = read_options (args, "op1",op1, "default",opt,"prefix",1,"nocase",1);