]> Creatis software - CreaPhase.git/blob - octave_packages/optim-1.2.0/curvefit_stat.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / optim-1.2.0 / curvefit_stat.m
1 ## Copyright (C) 2011 Olaf Till <olaf.till@uni-jena.de>
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 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{info} =} residmin_stat (@var{f}, @var{p}, @var{x}, @var{y}, @var{settings})
18 ##
19 ## Frontend for computation of statistics for fitting of values,
20 ## computed by a model function, to observed values.
21 ##
22 ## Please refer to the description of @code{residmin_stat}. The only
23 ## differences to @code{residmin_stat} are the additional arguments
24 ## @var{x} (independent values) and @var{y} (observations), that the
25 ## model function @var{f}, if provided, has a second obligatory argument
26 ## which will be set to @var{x} and is supposed to return guesses for
27 ## the observations (with the same dimensions), and that the possibly
28 ## user-supplied function for the jacobian of the model function has
29 ## also a second obligatory argument which will be set to @var{x}.
30 ##
31 ## @seealso {residmin_stat}
32 ## @end deftypefn
33
34 function ret = curvefit_stat (f, pfin, x, y, settings)
35
36   if (nargin == 1)
37     ret = __residmin_stat__ (f);
38     return;
39   endif
40
41   if (nargin != 5)
42     print_usage ()
43   endif
44
45   if (compare_versions (version (), "3.3.55", "<"))
46     ## optimset mechanism was fixed for option names with underscores
47     ## sometime in 3.3.54+, if I remember right
48     optimget = @ __optimget__;
49   endif
50   if (! isempty (dfdp = optimget (settings, "dfdp")) && \
51       ! (ismatrix (dfdp) && ! ischar (dfdp)))
52     if (ischar (dfdp))
53       dfdp = str2func (dfdp);
54     endif
55     settings.dfdp = @ (p, varargin) dfdp (p, x, varargin{:});
56   endif
57   if (! isempty (f))
58     f = @ (p) f (p, x);
59   endif
60
61   ret = __residmin_stat__ \
62       (f, pfin, settings, struct ("observations", y));
63
64 endfunction
65
66 function ret = __optimget__ (s, name, default)
67
68   if (isfield (s, name))
69     ret = s.(name);
70   elseif (nargin > 2)
71     ret = default;
72   else
73     ret = [];
74   endif
75
76 endfunction