IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1455


Ignore:
Timestamp:
Aug 10, 2004, 1:08:40 PM (22 years ago)
Author:
Paul Price
Message:

Major changes to minimization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r1437 r1455  
    1 %%% $Id: psLibSDRS.tex,v 1.64 2004-08-09 23:22:58 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.65 2004-08-10 23:08:40 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    323201 & 2004 May 19 & Extensive modifications, see appendix \\ \hline
    333302 & 2004 Jun 22 & Incorporation of Bugzilla PRs (up to 69) \\ \hline
    34 03 & 2004 Aug 09 & Adding convolution, splines, chebyshevs \\
    35    &             & (modified polynomials), ImageTrim for Phase 2 \\ \hline
     3403 & 2004 Aug 10 & Adding convolution, splines, chebyshevs \\
     35   &             & (modified polynomials), ImageTrim for Phase 2. \\
     36   &             & Changed minimization. \\ \hline
    3637\RevisionsEnd
    3738
     
    20842085We require a general minimization routine, a routine that will
    20852086specifically minimize $\chi^2$ given a list of data with associated
    2086 errors, and a function that will analytically determine the best
    2087 polynomial fit by minimizing $\chi^2$. 
    2088 
    2089 Consider a function \code{myFunction} which is a function of a
    2090 collection of parameters \code{params} and coordiate vector
    2091 \code{coord}, and returns a single floating point value.  We define
    2092 \code{psMinimize}, which determines the parameters of
    2093 \code{myFunction} which minimize the function for the coordinate
    2094 \code{coord}.  The returned vector must be the same length as the
    2095 vector argument to the input function.
    2096 \begin{verbatim}
    2097 float myFunction (psVector *params, psVector *coord);
    2098 float myFuncDeriv (psVector *params, psVector *coord);
    2099 psVector *psMinimize(psVector *restrict initialGuess,
    2100                      float (*myFunction)(psVector *, psVector *),
    2101                      float (*myFuncDeriv)(psVector *, psVector *),
    2102                      const psVector *restrict coord,
    2103                      const psVector *restrict paramMask);
    2104 \end{verbatim}
    2105 \code{psMinimize} determines and returns the vector that minimizes the
    2106 specified function.  It takes as input a function, \code{myFunction},
    2107 an initial guess for the vector that minimizes the function,
    2108 \code{initialGuess}, the current coordiate \code{coord}, and an
    2109 optional mask for the vector elements (function parameters) to
    2110 minimize, \code{paramMask} (all parameters are fit if \code{NULL}).
    2111 Note that \code{paramMask} must be of type \code{psU8}, while
    2112 \code{params} must be of type \code{psF32}.  The optional function,
    2113 \code{myFuncDeriv} returns the derivative of the function.  This
    2114 function must be valid only for types \code{psF32}, \code{psF64}.
    2115 
    2116 \begin{verbatim}
    2117 psVector *psMinimizeChi2(psVector *restrict initialGuess,
    2118                          float (*evalModel)(psVector *, psVector *),
    2119                          const psVector *restrict domain,
    2120                          const psVector *restrict data,
    2121                          const psVector *restrict errors,
    2122                          const psVector *restrict paramMask,
    2123                          float *ChiSq);
    2124 \end{verbatim}
    2125 \code{psMinimizeChi2} fits a model to observations by minimizing
    2126 $\chi^2$, returning the best-fit parameters.  The input parameters are
    2127 a function that evaluates the model for a specified domain, given the
    2128 parameters, \code{evalModel}; a list of observations, (\code{domain},
    2129 \code{data}, and \code{errors}); an initial guess at the best-fit
    2130 parameters, \code{initialGuess} which is returned with the best-fit
    2131 parameters, and an optional mask specifying which parameters are to be
    2132 fit, \code{paramMask}, which must be of type \code{psU8}.  All
    2133 parameters are fit if this vector is \code{NULL}.  This
    2134 function must be valid only for types \code{psF32}, \code{psF64}.
     2087errors, and functions that will analytically determine the best
     2088polynomial and spline fits by minimizing $\chi^2$.
     2089
     2090We specify two minimization engines, Levenberg-Marquardt and Powell,
     2091since the former is relatively robust, but requires derivatives to be
     2092known, while the latter does not always obtain the best fit but does
     2093not require derivatives to be known.
     2094
     2095In both cases, we need to be able to set the maximum number of
     2096iterations (\code{maxIter}) and the maximum tolerance (\code{tol}) for
     2097convergence, in addition to having some basic information on the
     2098results and quality of the minimization: the value of the function at
     2099the minimum (\code{value}), the number of iterations performed
     2100(\code{iter}) and last change in tolerance before returning
     2101(\code{lastDelta}).
     2102
     2103\begin{verbatim}
     2104typedef struct {
     2105    const int maxIter;                  ///< Maximum number of iterations
     2106    const float tol;                    ///< Tolerance to reach
     2107    float value;                        ///< Value after minimization
     2108    int iter;                           ///< Actual number of iterations performed
     2109    float lastDelta;                    ///< Last change before quitting
     2110} psMinimization;
     2111\end{verbatim}
     2112
     2113The corresponding allocator is:
     2114\begin{verbatim}
     2115psMinimization *psMinimizationAlloc(int maxIter, float tol);
     2116\end{verbatim}
     2117
     2118\subsubsection{Levenberg-Marquardt}
     2119
     2120Consider a function of a collection of parameters, \code{params}, and
     2121(possibly several) coordinate vectors (which we represent as an array
     2122of vectors), \code{coord}, which returns a single floating point value
     2123which is the value of the function given the parameters and coordinate
     2124vectors, along with the derivatives of the function with respect to
     2125each of the parameters:
     2126\begin{verbatim}
     2127typedef float (*psMinimizeLMFunc)(psVector *deriv, const psVector *params, const psArray *coords);
     2128\end{verbatim}
     2129
     2130Then \code{psMinimizeLM} shall mimimize the specified function,
     2131\code{func}, using the Levenberg-Marquardt method:
     2132
     2133\begin{verbatim}
     2134bool psMinimizeLM(psMinimization *min, psMatrix *covar, psVector *params, const psVector *paramMask,
     2135                  const psArray *coords, psMinimizeLMFunc func);
     2136\end{verbatim}
     2137
     2138The function shall return \code{false} in the event that there was an
     2139error (bad input, too many iterations), and also call \code{psError}.
     2140
     2141The minimization specification, \code{min}, shall be modified with the
     2142\code{value}, \code{iter} and \code{lastDelta} members updated with
     2143the values appropriate from the minimization.
     2144
     2145On calling the minimizer, \code{params} shall consist of a ``best
     2146guess'' for the parameters that minimize the input function,
     2147\code{func}.  On successful completion, the input parameters,
     2148\code{params}, shall be updated with the values that minimize the
     2149input function.  The function shall also update the covariance matrix,
     2150\code{covar}, in the event that it is non-\code{NULL}.  The function
     2151shall generate in error in the event that \code{covar} is not a square
     2152matrix with size matching that of \code{params}.
     2153
     2154Parameters that have a corresponding \code{paramMask} entry of
     2155\code{0} are to be held fixed by the minimizer.  It shall be an error
     2156for \code{paramMask} not to be of the same dimension as \code{params}.
     2157
     2158The \code{coords} are not handled by the minimizer, except to be
     2159passed to the function as additional input, and it is the
     2160responsibility of the function to interpret these.
     2161
     2162\code{paramMask} must be of type \code{psU8}, while \code{params} must
     2163be of type \code{psF32}.  The \code{func} function must be valid only
     2164for types \code{psF32}, \code{psF64}.
     2165
     2166\subsubsubsection{Pre-defined Functions for LM}
     2167
     2168We define some commonly used functions for use with the LM
     2169minimization, used for the purpose of performing $\chi^2$ fitting:
     2170
     2171\begin{verbatim}
     2172psMinimizeLMFunc psMinimizeLMChi2Gauss1D;
     2173psMinimizeLMFunc psMinimizeLMChi2Gauss2D;
     2174\end{verbatim}
     2175
     2176\code{psMinimizeChi2LMGauss1D} shall take, as \code{params}, the
     2177normalization, center, and standard deviation of a Gaussian to be fit
     2178to the data.  The data in the \code{coords} shall consist of vectors
     2179for each of \code{x}, \code{y}, and \code{yErr}.  If the \code{yErr}
     2180is missing, or \code{NULL}, then the errors shall be taken to be
     2181unity, for the purpose of fitting where the errors are all identical
     2182(and possibly unknown).  If the \code{x}, \code{y} or \code{yErr} (if
     2183supplied) vectors are of differing lengths, the function shall
     2184generate a warning and truncate the lengths to match the shortest.
     2185
     2186\code{psMinimizeLMChi2Gauss1D} shall return the $\chi^2$ value for the
     2187specified Gaussian as a model for the supplied data, along with the
     2188derivatives of the $\chi^2$ with respect to each of the parameters.
     2189
     2190\code{psMinimizeChi2LMGauss2D} shall take, as \code{params}, the
     2191normalization, center (two values), standard deviation (two values)
     2192and position angle of a 2-dimensional Gaussian to be fit to the data.
     2193The data in the \code{coords} shall consist of vectors for each of
     2194\code{x}, \code{y}, \code{z} and \code{zErr}.  If the \code{zErr} is
     2195missing, or \code{NULL}, then the errors shall be taken to be unity,
     2196for the purpose of fitting where the errors are all identical (and
     2197possibly unknown).  If the \code{x}, \code{y}, \code{z} or \code{zErr}
     2198(if supplied) vectors are of differing lengths, the function shall
     2199generate a warning and truncate the lengths to match the shortest.
     2200
     2201\code{psMinimizeLMChi2Gauss2D} shall return the $\chi^2$ value for the
     2202specified Gaussian as a model for the supplied data, along with the
     2203derivatives of the $\chi^2$ with respect to each of the parameters.
     2204
     2205\subsubsection{Powell}
     2206
     2207As for the LM minimizer, consider a function of a collection of
     2208parameters, \code{params}, and (possibly several) coordinate vectors
     2209(which we represent as an array of vectors), \code{coord}, and returns
     2210a single floating point value which is the value of the function given
     2211the parameters and coordinate vectors, but now the derivatives are not
     2212known:
     2213\begin{verbatim}
     2214typedef float (*psMinimizePowellFunc)(const psVector *params, const psArray *coords);
     2215\end{verbatim}
     2216
     2217Then \code{psMinimizePowell} shall mimimize the specified function,
     2218\code{func}, using the Powell method:
     2219
     2220\begin{verbatim}
     2221bool psMinimizePowell(psMinimization *min, psVector *params, const psVector *paramMask,
     2222                      const psArray *coords, psMinimizePowellFunc func);
     2223\end{verbatim}
     2224
     2225The inputs and general behavior of this function is the same as for
     2226\code{psMinimizeLM}, except for the absence of the covariance matrix,
     2227\code{covar}.
     2228
     2229\subsubsubsection{Minimizing $\chi^2$ with Powell}
     2230
     2231We require a front-end to the Powell minimizer to allow fitting
     2232general functions to data.
     2233
     2234\begin{verbatim}
     2235typedef psVector* (*psMinimizeChi2PowellFunc)(const psVector *params, const psArray *coords);
     2236
     2237bool psMinimizeChi2Powell(psMinimization *min, psVector *params, const psVector *paramMask,
     2238                          const psArray *coords, const psVector *value, const psVector *error,
     2239                          psMinimizeChi2PowellFunc model);
     2240\end{verbatim}
     2241
     2242The inputs and general behavior of \code{psMinimizeChi2Powell} is
     2243similar as for \code{psMinimizePowell}, with the exception that
     2244instead of being provided the function to be minimized, it is provided
     2245a model to fit and must calculate the $\chi^2$ to be minimized itself.
     2246
     2247For this purpose, \code{value} shall contain measured values at the
     2248coordinates, and \code{error} may either be non-\code{NULL}, in which
     2249case it contains the errors in the measured values; otherwise the
     2250errors shall assumed to be unity for the purpose of fitting where the
     2251errors are all identical (and possibly unknown).
     2252
     2253Furthermore, the \code{model} function provided by the user shall
     2254return a vector of values (instead of a single value, as was the case
     2255for \code{psMinimizePowell}), corresponding to the model predictions
     2256to be compared against the measured values.  If the lengths of the
     2257\code{value}, \code{error} (if provided) vectors and the vector
     2258returned by the \code{model} function differ, then
     2259\code{psMinimizeChi2Powell} shall generate a warning, truncate the
     2260vectors to the length of the shortest and proceed (only one error
     2261should be generated per call).
     2262
     2263\subsubsection{Analytical fits}
    21352264
    21362265\begin{verbatim}
Note: See TracChangeset for help on using the changeset viewer.