annotate scripts/optimization/optimset.m @ 19833:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1 ## Copyright (C) 2007-2015 John W. Eaton
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
2 ## Copyright (C) 2009 VZLU Prague
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
3 ##
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
5 ##
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6227
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6227
diff changeset
9 ## your option) any later version.
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
10 ##
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
15 ##
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6227
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6227
diff changeset
18 ## <http://www.gnu.org/licenses/>.
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
19
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
21 ## @deftypefn {Function File} {} optimset ()
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
22 ## @deftypefnx {Function File} {@var{options} =} optimset ()
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
23 ## @deftypefnx {Function File} {@var{options} =} optimset (@var{par}, @var{val}, @dots{})
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
24 ## @deftypefnx {Function File} {@var{options} =} optimset (@var{old}, @var{par}, @var{val}, @dots{})
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
25 ## @deftypefnx {Function File} {@var{options} =} optimset (@var{old}, @var{new})
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
26 ## Create options structure for optimization functions.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ##
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ## When called without any input or output arguments, @code{optimset} prints
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## a list of all valid optimization parameters.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ##
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## When called with one output and no inputs, return an options structure with
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ## all valid option parameters initialized to @code{[]}.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
33 ##
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
34 ## When called with a list of parameter/value pairs, return an options
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
35 ## structure with only the named parameters initialized.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
36 ##
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## When the first input is an existing options structure @var{old}, the values
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
38 ## are updated from either the @var{par}/@var{val} list or from the options
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
39 ## structure @var{new}.
13797
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
40 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
41 ## Valid parameters are:
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
42 ##
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
43 ## @table @asis
13797
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
44 ## @item AutoScaling
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
45 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
46 ## @item ComplexEqn
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
47 ##
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
48 ## @item Display
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
49 ## Request verbose display of results from optimizations. Values are:
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
50 ##
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
51 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
52 ## @item @qcode{"off"} [default]
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
53 ## No display.
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
54 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
55 ## @item @qcode{"iter"}
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
56 ## Display intermediate results for every loop iteration.
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
57 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
58 ## @item @qcode{"final"}
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
59 ## Display the result of the final loop iteration.
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
60 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
61 ## @item @qcode{"notify"}
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
62 ## Display the result of the final loop iteration if the function has
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
63 ## failed to converge.
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
64 ## @end table
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
65 ##
13797
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
66 ## @item FinDiffType
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
67 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
68 ## @item FunValCheck
14387
966ec84e7858 doc: Update optimset docstring with details of FunValCheck option.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
69 ## When enabled, display an error if the objective function returns an invalid
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
70 ## value (a complex number, NaN, or Inf). Must be set to @qcode{"on"} or
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
71 ## @qcode{"off"} [default]. Note: the functions @code{fzero} and
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
72 ## @code{fminbnd} correctly handle Inf values and only complex values or NaN
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
73 ## will cause an error in this case.
13797
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
74 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
75 ## @item GradObj
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
76 ## When set to @qcode{"on"}, the function to be minimized must return a
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
77 ## second argument which is the gradient, or first derivative, of the
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
78 ## function at the point @var{x}. If set to @qcode{"off"} [default], the
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
79 ## gradient is computed via finite differences.
13797
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
80 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
81 ## @item Jacobian
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
82 ## When set to @qcode{"on"}, the function to be minimized must return a
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
83 ## second argument which is the Jacobian, or first derivative, of the
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
84 ## function at the point @var{x}. If set to @qcode{"off"} [default], the
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16674
diff changeset
85 ## Jacobian is computed via finite differences.
13797
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
86 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
87 ## @item MaxFunEvals
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
88 ## Maximum number of function evaluations before optimization stops.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
89 ## Must be a positive integer.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
90 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
91 ## @item MaxIter
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
92 ## Maximum number of algorithm iterations before optimization stops.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
93 ## Must be a positive integer.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
94 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
95 ## @item OutputFcn
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
96 ## A user-defined function executed once per algorithm iteration.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
97 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
98 ## @item TolFun
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
99 ## Termination criterion for the function output. If the difference in the
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
100 ## calculated objective function between one algorithm iteration and the next
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
101 ## is less than @code{TolFun} the optimization stops. Must be a positive
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
102 ## scalar.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
103 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
104 ## @item TolX
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
105 ## Termination criterion for the function input. If the difference in @var{x},
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
106 ## the current search point, between one algorithm iteration and the next is
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
107 ## less than @code{TolX} the optimization stops. Must be a positive scalar.
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
108 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
109 ## @item TypicalX
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
110 ##
5289d7c2460d optimset.m: Document valid parameters for optimization functions.
Carnë Draug <carandraug+dev@gmail.com>
parents: 11523
diff changeset
111 ## @item Updating
14898
f8bb15f6a19b doc: Add "Display" option to optimset documentation.
Andy Adler <andy@analyti.ca>
parents: 14387
diff changeset
112 ## @end table
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
113 ## @seealso{optimget}
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
114 ## @end deftypefn
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
115
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
116 function retval = optimset (varargin)
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
117
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
118 nargs = nargin ();
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
119
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
120 opts = __all_opts__ ();
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
121
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
122 if (nargs == 0)
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
123 if (nargout == 0)
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
124 ## Display possibilities.
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
125 puts ("\nAll possible optimization options:\n\n");
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
126 printf (" %s\n", opts{:});
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
127 puts ("\n");
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
128 else
13183
cc1fd6a58151 optimset.m: When called with 1 output argument, return a struct with all possible options initialized to [].
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
129 ## Return struct with all options initialized to []
cc1fd6a58151 optimset.m: When called with 1 output argument, return a struct with all possible options initialized to [].
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
130 retval = cell2struct (repmat ({[]}, size (opts)), opts, 2);
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
131 endif
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
132 elseif (nargs == 1 && ischar (varargin{1}))
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
133 ## Return defaults for named function.
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
134 fcn = varargin{1};
8596
8833c0b18eb2 enable default settings queries in optim funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
135 try
11407
ed827ffa5a43 optimset, optimget, __all_opts__: consistently use lower case for storing and searching options
John W. Eaton <jwe@octave.org>
parents: 11346
diff changeset
136 retval = feval (fcn, "defaults");
8596
8833c0b18eb2 enable default settings queries in optim funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
137 catch
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
138 error ("optimset: no defaults for function '%s'", fcn);
8598
11cf7bc4a871 fix invalid block end
Jaroslav Hajek <highegg@gmail.com>
parents: 8596
diff changeset
139 end_try_catch
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
140 elseif (nargs == 2 && isstruct (varargin{1}) && isstruct (varargin{2}))
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
141 ## Set slots in old from non-empties in new.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
142 ## Should we be checking to ensure that the field names are expected?
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
143 old = varargin{1};
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
144 new = varargin{2};
6227
4c252a611d47 [project @ 2007-01-05 20:23:59 by jwe]
jwe
parents: 6226
diff changeset
145 fnames = fieldnames (old);
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
146 ## skip validation if we're in the internal query
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
147 validation = ! isempty (opts);
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
148 for [val, key] = new
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
149 if (validation)
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
150 ## Case insensitive lookup in all options.
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
151 i = strncmpi (opts, key, length (key));
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
152 nmatch = sum (i);
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
153 ## Validate option.
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
154 if (nmatch == 1)
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
155 key = opts{find (i)};
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
156 elseif (nmatch == 0)
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
157 warning ("optimset: unrecognized option: %s", key);
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
158 else
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
159 fmt = sprintf ("optimset: ambiguous option: %%s (%s%%s)",
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
160 repmat ("%s, ", 1, nmatch-1));
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
161 warning (fmt, key, opts{i});
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
162 endif
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
163 endif
6227
4c252a611d47 [project @ 2007-01-05 20:23:59 by jwe]
jwe
parents: 6226
diff changeset
164 old.(key) = val;
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
165 endfor
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
166 retval = old;
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
167 elseif (rem (nargs, 2) && isstruct (varargin{1}))
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
168 ## Set values in old from name/value pairs.
11121
134d357e1c03 optimization/optimset.m: Use cell2struct instead of struct to handle cell arrays as options
Olaf Till <olaf.till@uni-jena.de>
parents: 10793
diff changeset
169 pairs = reshape (varargin(2:end), 2, []);
134d357e1c03 optimization/optimset.m: Use cell2struct instead of struct to handle cell arrays as options
Olaf Till <olaf.till@uni-jena.de>
parents: 10793
diff changeset
170 retval = optimset (varargin{1}, cell2struct (pairs(2, :), pairs(1, :), 2));
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
171 elseif (rem (nargs, 2) == 0)
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
172 ## Create struct.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
173 ## Default values are replaced by those specified by name/value pairs.
11121
134d357e1c03 optimization/optimset.m: Use cell2struct instead of struct to handle cell arrays as options
Olaf Till <olaf.till@uni-jena.de>
parents: 10793
diff changeset
174 pairs = reshape (varargin, 2, []);
134d357e1c03 optimization/optimset.m: Use cell2struct instead of struct to handle cell arrays as options
Olaf Till <olaf.till@uni-jena.de>
parents: 10793
diff changeset
175 retval = optimset (struct (), cell2struct (pairs(2, :), pairs(1, :), 2));
6226
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
176 else
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
177 print_usage ();
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
178 endif
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
179
984d85191d0d [project @ 2007-01-05 18:41:24 by jwe]
jwe
parents:
diff changeset
180 endfunction
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8598
diff changeset
181
13183
cc1fd6a58151 optimset.m: When called with 1 output argument, return a struct with all possible options initialized to [].
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
182
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
183 %!assert (isfield (optimset (), "TolFun"))
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
184 %!assert (isfield (optimset ("tolFun", 1e-3), "TolFun"))
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
185 %!assert (optimget (optimset ("tolx", 1e-2), "tOLx"), 1e-2)
13183
cc1fd6a58151 optimset.m: When called with 1 output argument, return a struct with all possible options initialized to [].
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
186
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
187 ## Test input validation
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
188 %!error optimset ("1_Parameter")
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
189 %!error <no defaults for function> optimset ("%NOT_A_REAL_FUNCTION_NAME%")
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
190 %!warning <unrecognized option: foobar> optimset ("foobar", 13);
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
191 %!warning <ambiguous option: Max> optimset ("Max", 10);
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17281
diff changeset
192