Mercurial > hg > octave-lyh
annotate scripts/optimization/optimget.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 3f0ed69d21c6 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2008-2012 Jaroslav Hajek |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
2 ## Copyright (C) 2009 VZLU Prague |
8304
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 ## |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 ## This file is part of Octave. |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 ## |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 ## Octave is free software; you can redistribute it and/or modify it |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 ## your option) any later version. |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 ## |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 ## Octave is distributed in the hope that it will be useful, but |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 ## General Public License for more details. |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 ## |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public License |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 ## along with Octave; see the file COPYING. If not, see |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10319
diff
changeset
|
21 ## @deftypefn {Function File} {} optimget (@var{options}, @var{parname}) |
8715 | 22 ## @deftypefnx {Function File} {} optimget (@var{options}, @var{parname}, @var{default}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
23 ## Return a specific option from a structure created by |
8715 | 24 ## @code{optimset}. If @var{parname} is not a field of the @var{options} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
25 ## structure, return @var{default} if supplied, otherwise return an |
8304
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 ## empty matrix. |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 ## @end deftypefn |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 function retval = optimget (options, parname, default) |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
31 if (nargin < 2 || nargin > 4 || ! isstruct (options) || ! ischar (parname)) |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
32 print_usage (); |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
33 endif |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
34 |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
35 opts = __all_opts__ (); |
17413
3f0ed69d21c6
Replace unnecessary instances of strncmp with strcmp.
Rik <rik@octave.org>
parents:
17346
diff
changeset
|
36 idx = strncmpi (opts, parname, length (parname)); |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
37 |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
38 nmatch = sum (idx); |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
39 |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
40 if (nmatch == 1) |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
41 parname = opts{idx}; |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
42 elseif (nmatch == 0) |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
43 warning ("unrecognized option: %s", parname); |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
44 else |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
45 fmt = sprintf ("ambiguous option: %%s (%s%%s)", |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
46 repmat ("%s, ", 1, nmatch-1)); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
47 warning (fmt, parname, opts{idx}); |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
48 endif |
8304
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 if (isfield (options, parname)) |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 retval = options.(parname); |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 elseif (nargin > 2) |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 retval = default; |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 else |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 retval = []; |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 endif |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 endfunction |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16674
diff
changeset
|
59 |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
60 %!error optimget () |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
61 |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
62 %!shared opts |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
63 %! opts = optimset ("tolx", 0.1, "maxit", 100); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
64 %!assert (optimget (opts, "TolX"), 0.1); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
65 %!assert (optimget (opts, "maxit"), 100); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
66 %!assert (optimget (opts, "MaxITer"), 100); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
67 %!warning (optimget (opts, "Max")); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
68 %!warning (optimget (opts, "foobar")); |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16674
diff
changeset
|
69 |