Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psMinimize.h

Go to the documentation of this file.
00001 /** @file  psMinimize.c
00002  *  \brief basic minimization functions
00003  *  @ingroup Math
00004  *
00005  *  This file will contain function prototypes for various minimization,
00006  *  chi-squared minimization, and 1-D polynomial fitting routines.
00007  *
00008  *  @author GLG, MHPCC
00009  *
00010  *  @version $Revision: 1.60 $ $Name: rel9_0 $
00011  *  @date $Date: 2005/11/16 23:06:19 $
00012  *
00013  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00014  *
00015  */
00016 
00017 #ifndef PS_MINIMIZE_H
00018 #define PS_MINIMIZE_H
00019 
00020 /** \file psMinimize.h
00021  *  \brief minimization operations
00022  *  \ingroup Stats
00023  */
00024 /** \addtogroup Stats
00025  *  \{
00026  */
00027 
00028 #include "psVector.h"
00029 #include "psMemory.h"
00030 #include "psArray.h"
00031 #include "psImage.h"
00032 #include "psMatrix.h"
00033 #include "psPolynomial.h"
00034 #include "psSpline.h"
00035 #include "psStats.h"
00036 #include "psTrace.h"
00037 #include "psError.h"
00038 #include "psConstants.h"
00039 
00040 /** A data structure for minimization routines.
00041  *
00042  *  Contains numerical analysis parameters/values
00043  */
00044 typedef struct
00045 {
00046     const int maxIter;                 ///< Convergence limit
00047     const float tol;                   ///< Error Tolerance
00048     float value;                       ///< Value of function at minimum
00049     int iter;                          ///< Number of iterations to date
00050     float lastDelta;                   ///< The last difference for the fit
00051 }
00052 psMinimization;
00053 
00054 #define P_PSMINIMIZATION_SET_MAXITER(m,val) *(int*)&m->maxIter = val
00055         #define P_PSMINIMIZATION_SET_TOL(m,val) *(float*)&m->tol = val
00056 
00057 
00058                 /** Allocates a psMinimization structure.
00059                  *
00060                  *  @return psMinimization* :   a new psMinimization struct
00061                 */
00062                 psMinimization *psMinimizationAlloc(
00063                     int maxIter,                       ///< Number of minimization iterations to perform.
00064                     float tol                          ///< Requested error tolerance
00065                 );
00066 
00067 /** Checks the type of a particular pointer.
00068  *
00069  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00070  *
00071  *  @return bool:       True if the pointer matches a psMinimization structure, false otherwise.
00072  */
00073 bool psMemCheckMinimization(
00074     psPtr ptr                          ///< the pointer whose type to check
00075 );
00076 
00077 
00078 /** Derive a polynomial fit.
00079  *
00080  *  psVectorFitPolynomial1d returns the polynomial that best fits the
00081  *  observations. The input parameters are a polynomial that specifies the
00082  *  fit order, myPoly, which will be altered and returned with the best-fit
00083  *  coefficients; and the observations, x, y and yErr. The independent
00084  *  variable list, x may be NULL, in which case the vector index is used.
00085  *  The dependent variable error, yErr may be null, in which case the solution
00086  *  is determined in the assumption that all data errors are equal. This
00087  *  function must be valid only for types psF32, psF64.
00088  *
00089  *  @return psPolynomial1D*    polynomial fit
00090  */
00091 
00092 psPolynomial1D *psVectorFitPolynomial1D(
00093     psPolynomial1D *poly,
00094     const psVector *mask,
00095     psMaskType maskValue,
00096     const psVector *f,
00097     const psVector *fErr,
00098     const psVector *x
00099 );
00100 
00101 psPolynomial2D *psVectorFitPolynomial2D(
00102     psPolynomial2D *poly,
00103     const psVector *mask,
00104     psMaskType maskValue,
00105     const psVector *f,
00106     const psVector *fErr,
00107     const psVector *x,
00108     const psVector *y
00109 );
00110 
00111 psPolynomial3D *psVectorFitPolynomial3D(
00112     psPolynomial3D *poly,
00113     const psVector *mask,
00114     psMaskType maskValue,
00115     const psVector *f,
00116     const psVector *fErr,
00117     const psVector *x,
00118     const psVector *y,
00119     const psVector *z
00120 );
00121 
00122 psPolynomial4D *psVectorFitPolynomial4D(
00123     psPolynomial4D *poly,
00124     const psVector *mask,
00125     psMaskType maskValue,
00126     const psVector *f,
00127     const psVector *fErr,
00128     const psVector *x,
00129     const psVector *y,
00130     const psVector *z,
00131     const psVector *t
00132 );
00133 
00134 
00135 psPolynomial1D *psVectorClipFitPolynomial1D(
00136     psPolynomial1D *poly,
00137     psStats *stats,
00138     const psVector *mask,
00139     psMaskType maskValue,
00140     const psVector *f,
00141     const psVector *fErr,
00142     const psVector *x
00143 );
00144 
00145 psPolynomial2D *psVectorClipFitPolynomial2D(
00146     psPolynomial2D *poly,
00147     psStats *stats,
00148     const psVector *mask,
00149     psMaskType maskValue,
00150     const psVector *f,
00151     const psVector *fErr,
00152     const psVector *x,
00153     const psVector *y
00154 );
00155 
00156 psPolynomial3D *psVectorClipFitPolynomial3D(
00157     psPolynomial3D *poly,
00158     psStats *stats,
00159     const psVector *mask,
00160     psMaskType maskValue,
00161     const psVector *f,
00162     const psVector *fErr,
00163     const psVector *x,
00164     const psVector *y,
00165     const psVector *z
00166 );
00167 
00168 psPolynomial4D *psVectorClipFitPolynomial4D(
00169     psPolynomial4D *poly,
00170     psStats *stats,
00171     const psVector *mask,
00172     psMaskType maskValue,
00173     const psVector *f,
00174     const psVector *fErr,
00175     const psVector *x,
00176     const psVector *y,
00177     const psVector *z,
00178     const psVector *t
00179 );
00180 
00181 /** Specifies the format of a user-defined function that the general Levenberg-
00182  *  Marquardt minimizer routine will accept.
00183  *
00184  *  @return float:   the single float value of the function given the parameters,
00185  *       positions, and derivatives.
00186  */
00187 typedef
00188 float (*psMinimizeLMChi2Func)(
00189     psVector *deriv,                   ///< derivatives of the function
00190     const psVector *params,            ///< the parameters used to evaluate the function
00191     const psVector *x                  ///< positions for evaluation
00192 );
00193 
00194 /** Minimizes a specified function based on the Levenberg-Marquardt method.
00195  *
00196  *  @return bool:   True if successful.
00197  */
00198 bool psMinimizeLMChi2(
00199     psMinimization *min,               ///< Minimization specification
00200     psImage *covar,                    ///< Covariance matrix
00201     psVector *params,                  ///< "Best Guess" for the parameters that minimize func
00202     const psVector *paramMask,         ///< Parameters to be held fixed by the minimizer
00203     const psArray *x,                  ///< Measurement ordinates of multiple vectors
00204     const psVector *y,                 ///< Measurement coordinates
00205     const psVector *yErr,              ///< Errors in the measurement coordinates
00206     psMinimizeLMChi2Func func          ///< Specified function
00207 );
00208 
00209 bool psMinimizeGaussNewtonDelta (
00210     psVector *delta,
00211     const psVector *params,
00212     const psVector *paramMask,
00213     const psArray  *x,
00214     const psVector *y,
00215     const psVector *yErr,
00216     psMinimizeLMChi2Func func
00217 );
00218 
00219 /** Function used to set parameters for generating "best guess" in minimizing Chi-Squared value.
00220  *
00221  *  @return psF64:    Chi-squared value for new guess
00222  */
00223 psF64 p_psMinLM_SetABX (
00224     psImage  *alpha,                   ///< alpha guess
00225     psVector *beta,                    ///< beta guess
00226     const psVector *params,            ///< params guess
00227     const psVector *paramMask,         ///< param mask
00228     const psArray  *x,                 ///< Measurement ordinates
00229     const psVector *y,                 ///< Measurement coordinates
00230     const psVector *dy,                ///< Weights calculated from y-errors
00231     psMinimizeLMChi2Func func          ///< Specified function
00232 );
00233 
00234 
00235 /** Specifies the format of a user-defined function that the general Powell
00236  *  minimizer routine will accept.
00237  *
00238  *  @return float:   the single float value of the function given the parameters
00239  *      and coordinate vectors.
00240 */
00241 typedef
00242 float (*psMinimizePowellFunc)(
00243     const psVector *params,            ///< Parameters used to evaluate the function
00244     const psArray *coords              ///< Coordinates at which to evaluate
00245 );
00246 
00247 /** Minimizes a specified function based on the Powell method.
00248  *
00249  *  @return bool:   True if successful.
00250  */
00251 bool psMinimizePowell(
00252     psMinimization *min,               ///< Minimization specification
00253     psVector *params,                  ///< "Best guess" for parameters that minimize func
00254     const psVector *paramMask,         ///< Parameters to be held fixed by minimizer
00255     const psArray *coords,             ///< Measurement coordinates
00256     psMinimizePowellFunc func          ///< Specified function
00257 );
00258 
00259 /** Specifies the format of a user-defined function that the general Powell chi-
00260  *  squared minimizer routine will accept.
00261  *
00262  *  @return psVector*:    Calculated values given the parameters and coordinates.
00263 */
00264 typedef
00265 psVector *(*psMinimizeChi2PowellFunc)(
00266     const psVector *params,            ///< Parameters used to evaluate the function
00267     const psArray *coords              ///< Coordinates at which to evaluate
00268 );
00269 
00270 /** Minimizes a specified function based on the Powell chi-squared method.
00271  *
00272  *  @return bool:   True is successful.
00273  */
00274 bool psMinimizeChi2Powell(
00275     psMinimization *min,               ///< Minimization specification
00276     psVector *params,                  ///< "Best guess" for parameters that minimize func
00277     const psVector *paramMask,         ///< Parameters to be held fixed by minimizer
00278     const psArray *coords,             ///< Measurement coordinates
00279     const psVector *value,             ///< Measured values at the coordinates
00280     const psVector *error,             ///< Errors in the measure values (or NULL)
00281     psMinimizeChi2PowellFunc model     ///< Specified function
00282 );
00283 
00284 /** Gauss-Jordan numerical solver.
00285  *
00286  *  @return bool:   True if successful.
00287  */
00288 bool psGaussJordan(
00289     psImage *a,                        ///< Matrix to be solved
00290     psVector *b                        ///< Vector of values
00291 );
00292 
00293 /* \} */// End of MathGroup Functions
00294 
00295 
00296 
00297 
00298 #endif // #ifndef PS_MINIMIZE_H
00299 

Generated on Tue Dec 6 17:18:42 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2