Mercurial > hg > octave-terminal
changeset 6226:984d85191d0d
[project @ 2007-01-05 18:41:24 by jwe]
author | jwe |
---|---|
date | Fri, 05 Jan 2007 18:41:24 +0000 |
parents | 62f482479cb5 |
children | 4c252a611d47 |
files | scripts/ChangeLog scripts/optimization/__fsolve_defopts__.m scripts/optimization/optimset.m |
diffstat | 3 files changed, 144 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2007-01-05 John W. Eaton <jwe@octave.org> + + * optimization/optimset.m, optimization/__fsolve_defopts__.m: + New files. + 2006-12-30 John W. Eaton <jwe@octave.org> * sparse/spfun.m: Check for "function_handle" not "function handle".
new file mode 100644 --- /dev/null +++ b/scripts/optimization/__fsolve_defopts__.m @@ -0,0 +1,53 @@ +## Copyright (C) 2007 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __fsolve_defopts__ () +## @end deftypefn + +function retval = __fsolve_defopts__ () + + if (nargin == 0) + retval = struct ("DerivativeCheck", "off", + "Diagnostics", "off", + "DiffMaxChange", 0.1, + "DiffMinChange", 1e-8, + "Display", "final", + "FunValCheck", "off", + "JacobMult", [], + "JacobPattern", "sparse (ones (jrows, jcols))", + "Jacobian", "off", + "LargeScale", "off", + "LineSearchtype", "quadcubic", + "MaxFunEvals", "100*numberofvariables", + "MaxIter", 400, + "MaxPCGIter", "max (1, floor (numberofvariables/2))", + "NonlEqnAlgorithm", "dogleg", + "OutputFcn", [], + "PlotFcns", [], + "PrecondBandWidth", 0, + "TolFun", 1e-6, + "TolPCG", 0.1, + "TolX", 1e-6, + "TypicalX", "ones (numberofvariables, 1)"); + else + print_usage (); + endif + +endfunction
new file mode 100644 --- /dev/null +++ b/scripts/optimization/optimset.m @@ -0,0 +1,86 @@ +## Copyright (C) 2007 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} optimset () +## @deftypefnx {Function File} {} optimset (@var{par}, @var{val}, @dots{}) +## @deftypefnx {Function File} {} optimset (@var{old}, @var{par}, @var{val}, @dots{}) +## @deftypefnx {Function File} {} optimset (@var{old}, @var{new}) +## Create options struct for optimization functions. +## @end deftypefn + +function retval = optimset (varargin) + + nargs = nargin (); + + ## Add more as needed. + persistent opts = { + "Display", "\"off\"|\"iter\"|{\"final\"}|\"notify\""; + "FunValCheck", "{\"off\"}|\"on\""; + "MaxFunEvals", "positive integer"; + "MaxIter", "positive integer"; + "OutputFun", "function|{[]}"; + "TolFun", "positive scalar"; + "TolX", "positive scalar" + }; + + if (nargs == 0) + if (nargout == 0) + ## Display possibilities. + tmp = opts'; + disp (struct (tmp{:})); + else + ## Return structure with empty values. + t1 = opts(:,1)'; + t2 = cell (size (t1)); + tmp = [t1; t2]; + retval = struct (tmp{:}); + endif + elseif (nargs == 1 && ischar (varargin{1})) + ## Return defaults for named function. + fcn = varargin{1}; + optfcn = sprintf ("__%s_defopts__", fcn); + if (exist (optfcn)) + retval = optimset (optimset (), feval (optfcn)); + else + error ("no defaults for function `%s'", fcn); + endif + elseif (nargs == 2 && isstruct (varargin{1}) && isstruct (varargin{2})) + ## Set slots in old from nonempties in new. Should we be checking + ## to ensure that the field names are expected? + old = varargin{1}; + new = varargin{2}; + for [val, key] = new + if (! isempty (val)) + old.(key) = val; + endif + endfor + retval = old; + elseif (rem (nargs, 2) && isstruct (varargin{1})) + ## Set values in old from name/value pairs. + retval = optimset (varargin{1}, struct (varargin{2:end})); + elseif (rem (nargs, 2) == 0) + ## Create struct. Default values are replaced by those specified by + ## name/value pairs. + retval = optimset (optimset (), struct (varargin{:})); + else + print_usage (); + endif + +endfunction