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