Mercurial > hg > octave-nkf
annotate scripts/optimization/optimget.m @ 20076:781adfc2958c draft obsolete nkf
Build qt graphics toolkit menus with uimenu
* libgui/graphics/Figure.cc, libgui/graphics/Figure.h: Revert cset 7335cc071ab0
and remove all menu items.
* scripts/gui/private/__get_funcname__.m: Fix typo
* scripts/plot/util/private/__add_default_menu__.m: Enable uimenu for qt
graphics toolkit and fix setting pan/rotate/zoom for qt and fltk
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 18:36:05 +0100 |
parents | 9fc020886ae9 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18750
diff
changeset
|
1 ## Copyright (C) 2008-2015 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}) |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
23 ## Return the specific option @var{parname} from the optimization options |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 ## structure @var{options} created by @code{optimset}. |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
25 ## |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
26 ## If @var{parname} is not defined then return @var{default} if supplied, |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
27 ## otherwise return an empty matrix. |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
28 ## @seealso{optimset} |
8304
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 ## @end deftypefn |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 function retval = optimget (options, parname, default) |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
33 if (nargin < 2 || nargin > 4 || ! isstruct (options) || ! ischar (parname)) |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
34 print_usage (); |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
35 endif |
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
36 |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
37 ## Expand partial-length names into full names |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
38 opts = __all_opts__ (); |
17405
3f0ed69d21c6
Replace unnecessary instances of strncmp with strcmp.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
39 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
|
40 nmatch = sum (idx); |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
41 |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
42 if (nmatch == 1) |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
43 parname = opts{idx}; |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
44 elseif (nmatch == 0) |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
45 warning ("optimget: unrecognized option: %s", parname); |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
46 else |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
47 fmt = sprintf ("optimget: ambiguous option: %%s (%s%%s)", |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
48 repmat ("%s, ", 1, nmatch-1)); |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
49 warning (fmt, parname, opts{idx}); |
8647
06f5dd901f30
implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents:
8304
diff
changeset
|
50 endif |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
51 |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 if (isfield (options, parname) && ! isempty (options.(parname))) |
8304
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 retval = options.(parname); |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 elseif (nargin > 2) |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 retval = default; |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 else |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 retval = []; |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 endif |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 endfunction |
eeaee297c0da
modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16674
diff
changeset
|
62 |
16674
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
63 %!shared opts |
bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
64 %! opts = optimset ("tolx", 0.1, "maxit", 100); |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 %!assert (optimget (opts, "TolX"), 0.1) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 %!assert (optimget (opts, "maxit"), 100) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 %!assert (optimget (opts, "MaxITer"), 100) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 %!assert (optimget (opts, "TolFun"), []) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 %!assert (optimget (opts, "TolFun", 1e-3), 1e-3) |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16674
diff
changeset
|
70 |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
71 ## Test input validation |
18750
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 %!error optimget () |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 %!error optimget (1) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 %!error optimget (1,2,3,4,5) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 %!error optimget (1, "name") |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 %!error optimget (struct (), 2) |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 %!warning <unrecognized option: foobar> (optimget (opts, "foobar")); |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 %!warning <ambiguous option: Max> (optimget (opts, "Max")); |
8d4d78285c8e
Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 |