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.1.1.1 $ $Name:  $
00011  *  @date $Date: 2005/09/14 20:42:48 $
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 /** Allocates a psMinimization structure.
00055  *
00056  *  @return psMinimization* :   a new psMinimization struct
00057 */
00058 psMinimization *psMinimizationAlloc(
00059     int maxIter,                       ///< Number of minimization iterations to perform.
00060     float tol                          ///< Requested error tolerance
00061 );
00062 
00063 /** Checks the type of a particular pointer.
00064  *
00065  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00066  *
00067  *  @return bool:       True if the pointer matches a psMinimization structure, false otherwise.
00068  */
00069 bool psMemCheckMinimization(
00070     psPtr ptr                          ///< the pointer whose type to check
00071 );
00072 
00073 
00074 /** Derive a polynomial fit.
00075  *
00076  *  psVectorFitPolynomial1d returns the polynomial that best fits the
00077  *  observations. The input parameters are a polynomial that specifies the
00078  *  fit order, myPoly, which will be altered and returned with the best-fit
00079  *  coefficients; and the observations, x, y and yErr. The independent
00080  *  variable list, x may be NULL, in which case the vector index is used.
00081  *  The dependent variable error, yErr may be null, in which case the solution
00082  *  is determined in the assumption that all data errors are equal. This
00083  *  function must be valid only for types psF32, psF64.
00084  *
00085  *  @return psPolynomial1D*    polynomial fit
00086  */
00087 
00088 psPolynomial1D *psVectorFitPolynomial1D(
00089     psPolynomial1D *poly,
00090     const psVector *mask,
00091     psMaskType maskValue,
00092     const psVector *f,
00093     const psVector *fErr,
00094     const psVector *x
00095 );
00096 
00097 psPolynomial2D *psVectorFitPolynomial2D(
00098     psPolynomial2D *poly,
00099     const psVector *mask,
00100     psMaskType maskValue,
00101     const psVector *f,
00102     const psVector *fErr,
00103     const psVector *x,
00104     const psVector *y
00105 );
00106 
00107 psPolynomial3D *psVectorFitPolynomial3D(
00108     psPolynomial3D *poly,
00109     const psVector *mask,
00110     psMaskType maskValue,
00111     const psVector *f,
00112     const psVector *fErr,
00113     const psVector *x,
00114     const psVector *y,
00115     const psVector *z
00116 );
00117 
00118 psPolynomial4D *psVectorFitPolynomial4D(
00119     psPolynomial4D *poly,
00120     const psVector *mask,
00121     psMaskType maskValue,
00122     const psVector *f,
00123     const psVector *fErr,
00124     const psVector *x,
00125     const psVector *y,
00126     const psVector *z,
00127     const psVector *t
00128 );
00129 
00130 
00131 psPolynomial1D *psVectorClipFitPolynomial1D(
00132     psPolynomial1D *poly,
00133     psStats *stats,
00134     const psVector *mask,
00135     psMaskType maskValue,
00136     const psVector *f,
00137     const psVector *fErr,
00138     const psVector *x
00139 );
00140 
00141 psPolynomial2D *psVectorClipFitPolynomial2D(
00142     psPolynomial2D *poly,
00143     psStats *stats,
00144     const psVector *mask,
00145     psMaskType maskValue,
00146     const psVector *f,
00147     const psVector *fErr,
00148     const psVector *x,
00149     const psVector *y
00150 );
00151 
00152 psPolynomial3D *psVectorClipFitPolynomial3D(
00153     psPolynomial3D *poly,
00154     psStats *stats,
00155     const psVector *mask,
00156     psMaskType maskValue,
00157     const psVector *f,
00158     const psVector *fErr,
00159     const psVector *x,
00160     const psVector *y,
00161     const psVector *z
00162 );
00163 
00164 psPolynomial4D *psVectorClipFitPolynomial4D(
00165     psPolynomial4D *poly,
00166     psStats *stats,
00167     const psVector *mask,
00168     psMaskType maskValue,
00169     const psVector *f,
00170     const psVector *fErr,
00171     const psVector *x,
00172     const psVector *y,
00173     const psVector *z,
00174     const psVector *t
00175 );
00176 
00177 /** Specifies the format of a user-defined function that the general Levenberg-
00178  *  Marquardt minimizer routine will accept.
00179  *
00180  *  @return float:   the single float value of the function given the parameters,
00181  *       positions, and derivatives.
00182  */
00183 typedef
00184 float (*psMinimizeLMChi2Func)(
00185     psVector *deriv,                   ///< derivatives of the function
00186     const psVector *params,            ///< the parameters used to evaluate the function
00187     const psVector *x                  ///< positions for evaluation
00188 );
00189 
00190 /** Minimizes a specified function based on the Levenberg-Marquardt method.
00191  *
00192  *  @return bool:   True if successful.
00193  */
00194 bool psMinimizeLMChi2(
00195     psMinimization *min,               ///< Minimization specification
00196     psImage *covar,                    ///< Covariance matrix
00197     psVector *params,                  ///< "Best Guess" for the parameters that minimize func
00198     const psVector *paramMask,         ///< Parameters to be held fixed by the minimizer
00199     const psArray *x,                  ///< Measurement ordinates of multiple vectors
00200     const psVector *y,                 ///< Measurement coordinates
00201     const psVector *yErr,              ///< Errors in the measurement coordinates
00202     psMinimizeLMChi2Func func          ///< Specified function
00203 );
00204 
00205 bool psMinimizeGaussNewtonDelta (
00206     psVector *delta,
00207     const psVector *params,
00208     const psVector *paramMask,
00209     const psArray  *x,
00210     const psVector *y,
00211     const psVector *yErr,
00212     psMinimizeLMChi2Func func
00213 );
00214 
00215 /** Use specified alpha, beta, params to generate a new guess for Alpha, Beta, Params
00216  *
00217  *  @return psBool:   True if successful.
00218  */
00219 psBool p_psMinLM_GuessABP(
00220     psImage  *Alpha,                   ///< New Alpha guess
00221     psVector *Beta,                    ///< New Beta guess
00222     psVector *Params,                  ///< New Params guess
00223     const psImage  *alpha,             ///< Old Alpha guess
00224     const psVector *beta,              ///< Old Beta guess
00225     const psVector *params,            ///< Old Params guess
00226     const psVector *paramMask,         ///< Param Mask
00227     psF64 lambda                       ///< Factor used in update
00228     //XXX Got Better Desc?
00229 );
00230 
00231 /** Function used to set parameters for generating "best guess" in minimizing Chi-Squared value.
00232  *
00233  *  @return psF64:    Chi-squared value for new guess
00234  */
00235 psF64 p_psMinLM_SetABX (
00236     psImage  *alpha,                   ///< alpha guess
00237     psVector *beta,                    ///< beta guess
00238     const psVector *params,            ///< params guess
00239     const psVector *paramMask,         ///< param mask
00240     const psArray  *x,                 ///< Measurement ordinates
00241     const psVector *y,                 ///< Measurement coordinates
00242     const psVector *dy,                ///< Weights calculated from y-errors
00243     psMinimizeLMChi2Func func          ///< Specified function
00244 );
00245 
00246 
00247 /** Specifies the format of a user-defined function that the general Powell
00248  *  minimizer routine will accept.
00249  *
00250  *  @return float:   the single float value of the function given the parameters
00251  *      and coordinate vectors.
00252 */
00253 typedef
00254 float (*psMinimizePowellFunc)(
00255     const psVector *params,            ///< Parameters used to evaluate the function
00256     const psArray *coords              ///< Coordinates at which to evaluate
00257 );
00258 
00259 /** Minimizes a specified function based on the Powell method.
00260  *
00261  *  @return bool:   True if successful.
00262  */
00263 bool psMinimizePowell(
00264     psMinimization *min,               ///< Minimization specification
00265     psVector *params,                  ///< "Best guess" for parameters that minimize func
00266     const psVector *paramMask,         ///< Parameters to be held fixed by minimizer
00267     const psArray *coords,             ///< Measurement coordinates
00268     psMinimizePowellFunc func          ///< Specified function
00269 );
00270 
00271 /** Specifies the format of a user-defined function that the general Powell chi-
00272  *  squared minimizer routine will accept.
00273  *
00274  *  @return psVector*:    Calculated values given the parameters and coordinates.
00275 */
00276 typedef
00277 psVector *(*psMinimizeChi2PowellFunc)(
00278     const psVector *params,            ///< Parameters used to evaluate the function
00279     const psArray *coords              ///< Coordinates at which to evaluate
00280 );
00281 
00282 /** Minimizes a specified function based on the Powell chi-squared method.
00283  *
00284  *  @return bool:   True is successful.
00285  */
00286 bool psMinimizeChi2Powell(
00287     psMinimization *min,               ///< Minimization specification
00288     psVector *params,                  ///< "Best guess" for parameters that minimize func
00289     const psVector *paramMask,         ///< Parameters to be held fixed by minimizer
00290     const psArray *coords,             ///< Measurement coordinates
00291     const psVector *value,             ///< Measured values at the coordinates
00292     const psVector *error,             ///< Errors in the measure values (or NULL)
00293     psMinimizeChi2PowellFunc model     ///< Specified function
00294 );
00295 
00296 /** Gauss-Jordan numerical solver.
00297  *
00298  *  @return bool:   True if successful.
00299  */
00300 bool psGaussJordan(
00301     psImage *a,                        ///< Matrix to be solved
00302     psVector *b                        ///< Vector of values
00303 );
00304 
00305 /* \} */// End of MathGroup Functions
00306 
00307 
00308 
00309 
00310 #endif // #ifndef PS_MINIMIZE_H
00311 

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2