1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
Copyright (C) 2010 Olaf Till <olaf.till@uni-jena.de>
License terms:
You can redistribute and/or modify this text under the terms of the
GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any
later version.
This text 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 this text; If not, see <http://www.gnu.org/licenses/>.
###################################################################
Optimization Interfaces
It is planned (at least by me) to have common front-ends for some
optimization backends. This document should describe some of the
interfaces. (While frontends are supposed to honour options set by
optimset, keeping Matlab compatibility with respect to option names,
but possibly using additional options (not present in Matlab), the
interface to the backend does not pass the options as returned by
optimset, but uses different variables.)
This document is possibly not up-to-date.
The interface of backends in fitting of residuals (e.g. curve fitting)
is (example implementation is in __nonlin_residmin__.m):
function [p, resid, cvg, outp] = __backend_name__ (f, pin, hook)
where in the arguments
'f' is a handle of the residual function, accepting as a single
argument the vector of optimized paramters, and returning a matrix of
residuals; (constant variables as, e.g., independents and observed
values in curve fitting, can be provided by the front-end if 'f' is an
anonymous function),
'pin' is the vector of initial parameters, and
'hook' is a structure with additional information; some fields of
'hook' may be not obligatory, and additional fields may be defined in
the future (the fields will be described below),
and in the returned values
'p' is the vector of computed parameters,
'resid' are the residuals for the result,
'cvg' is a flag (described below) characterizing the result, and
'outp' is a structure (described below) with additional information;
some fields of 'outp' may not always be present, and additional fields
may be defined in the future.
The structure 'hook' can have the following fields:
(Constraints are violated if constraint functions return vector
elements which belong to inequality constraints and are smaller than
zero or a small positive value, or vector elements which belong to
equality constraints and have an absolute value larger than or equal
to a small positive value.)
'mc' (required): matrix (possibly empty) of the function "mc.' *
parameters + vc" of linear constraints,
'vc' (required): vector (possibly empty) of the function "mc.' *
parameters + vc" of linear constraints,
If bounds have been specified, they are contained in 'mc' and 'vc'
_before_ all other linear constraints.
'n_gencstr' (required): number of general constraints (except the
linear constraints given by 'mc' and 'vc',
'f_cstr' (required): handle of function of all constraints, accepting
as arguments the vector of parameters and a logical index of
constraints, and returning a vector of constraint values, the linear
constraints being the first elements; if no second argument is given,
the function returnes the vector of all constraints; if a second
argument is given, only the values of the indicated constraints are
returned (possibly sparing computation of the others),
'eq_idx' (required): logical index of equality constraints (as opposed
to inequality constraints) within the vector of all constraints
returned by 'f_cstr' with an index of all true as second argument,
'df_cstr' (required): handle of function for jacobian of all
constraints, accepting as arguments the vector of parameters, a
logical index of constraints, and a structure 'dfdp_hook' (described
below) with additional information; the returned jacobian only
contains rows for those constraints indicated by the logical vector,
'bounds' (required): 2-column matrix with bounds, one row per
parameter, lacking bounds are indicated by -Inf or Inf, respectively;
each bound (except -Inf or Inf) is also contained in 'mc' and 'vc'
above; all (bounds(:, 1) <= bounds(:, 2)) is guaranteed, but any
(bounds(:, 1) == bounds(:, 2)) is possible,
'pin_cstr' (required): structure with values of constraints (possibly
empty vectors) for initial parameters, field
'inequ.lin_except_bounds': linear inequality constraints except
bounds, field 'inequ.gen': general inequality constraints, field
'equ.lin' linear equality constraints, field 'equ.gen' general
constraints, (so backend can decide what to do if initial parameters
violate constraints),
'f_pin' (required): returned value of f (pin),
'dfdp' (required): handle of function returning the jacobian of the
residual function, accepting as arguments the vector of parameters and
a structure 'dfdp_hook' (described below) with additional information,
'dfdp_pin' (optional): returned value of dfdp for initial parameters
and dfdp_hook with fields as settable by the front end; may be
different from what the backend would compute, but might be used by
the backend; could be useful if user requests checks of dfdp return
value, as suggested by some existing Matlab optimset option --- these
checks can be done better in the frontend,
'cpiv' (required): handle of function for complementary pivoting, the
interface is not yet documented here and might change, for an example
see "cpiv_bard.m" and its usage by "leasqr.m",
'max_fract_change' (required, elements possibly NA): column vector of
maximum fractional changes in parameters between iterations, Inf for
unlimited,
'fract_prec' (required, elements possibly NA): column vector of
desired fractional precisions in parameter estimates (0 for disabled);
typically, backends will abort optimization if fractional change is
less than this in two successive iterations,
'TolFun' (required): (as corresponding Matlab compatible optimset
option) scalar, minimum fractional improvement in sum of squared
residuals between iterations; criterion for aborting optimization,
'MaxIter' (required, but may be empty): (as corresponding Matlab
compatible optimset option) maximum number of iterations,
'weights' (required): weights for the residuals, same matrix size,
'fixed' (required): logical vector, indicates that parameters are not
optimized, but keep their values,
'Display' (required): as corresponding Matlab compatible optimset
option,
'plot_cmd': function for plotting (intermediate) results, accepting
current computed residuals as argument,
The returned value 'cvg' has the same meaning as 'exitflag' in Matlabs
'lsqcurvefit'.
The returned value 'outp' is a structure with --- possibly --- the
following fields:
'niter': number of iterations.
The fields 'diffp', 'diff_onesided', 'bounds', and 'plabels' in the
'dfdp_hook' structure are not set in the backend, but can be set
(e.g. by wrapping the jacobian function) in the frontend. The frontend
also must correctly adapt the field 'fixed' (considering the
parameters not seen by the backend). If _pstruct is set for the
respective jacobian function, these values are passed as structures
with each original row in a field with the name of a parameter.
The structure 'dfdp_hook' can have the following fields:
'diffp': positive column vector, relative parameter change (or
absolute, if a parameter is zero) in finite differencing for
derivatives,
'diff_onesided': logical vector, indicates usage of one-sided
intervals in finite differencing for derivatives,
'fixed' (required): logical vector, indicating which of the passed
parameters is not optimized, but fixed, so the respective derivatives
need not be computed but should be filled in with zero,
'bounds': as in structure 'hook' above, if given, bounds should not be
violated even in finite differencing
'f': returned value of the passed residual function for the current
parameters; can spare re-computation in finite differencing.
'plabels': a 2-dimensional cell array with parameter labels, one row
for each parameter.
|