IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1454


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

Significant changes to minimization code: now use both LM and Powell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/pslib/include/psMinimize.h

    r1422 r1454  
    1212 */
    1313
    14 /** Find the minimum of a particular non-linear function */
    15 psVector *
    16 psMinimize(psVector *restrict initialGuess, ///< Initial guess and answer
    17            float (*myFunction)(const psVector *restrict, const psVector *restrict), ///< Function to minimize
    18            float (*myFuncDeriv)(const psVector *restrict, const psVector *restrict), ///< Derivatives of function, or NULL
    19            const psVector *restrict paramMask) ///< 1 = fit for parameter, 0 = hold parameter constant
    20 ;
     14
     15/** Specification and return structure for a minimization */
     16typedef struct {
     17    const int maxIter;                  ///< Maximum number of iterations
     18    const float tol;                    ///< Tolerance to reach
     19    float value;                        ///< Value after minimization
     20    int iter;                           ///< Actual number of iterations performed
     21    float lastDelta;                    ///< Last change before quitting
     22} psMinimization;
    2123
    2224
    23 /** Minimize chi^2 for input data */
    24 psVector *
    25 psMinimizeChi2(psVector *restrict initialGuess, ///< Initial guess and answer
    26                float (*evalModel)(const psVector *restrict, const psVector *restrict), ///< Model to fit; (domain and params)
    27                const psVector *restrict domain, ///< The domain values for the corresponding measurements
    28                const psVector *restrict data, ///< Data to fit
    29                const psVector *restrict errors, ///< Errors in the data
    30                const psVector *restrict paramMask, ///< 1 = fit for parameter, 0 = hold parameter constant
    31                float ChiSq)             ///< calculated chisq of fit
    32 ;
     25psMinimization *psMinimizationAlloc(int maxIter, ///< Maximum number of iterations
     26                                    float tol ///< Tolerance to reach
     27    );
     28
     29/** Function format for LM minimization: requires derivatives */
     30typedef float (*psMinimizeLMFunc)(
     31    psVector *deriv,                    ///< Derivatives to return
     32    const psVector *params,             ///< Parameters for which to evaluate
     33    const psArray *coords               ///< Array of vectors of coordinates at which to evaluate
     34    );
     35
     36/** Minimize a function using the LM method: requires derivatives.  Returns false if there were errors. */
     37bool
     38psMinimizeLM(psMinimization *min,       ///< Minimization specification, and output
     39             psMatrix *covar,           ///< Covariance matrix to return
     40             psVector *params,          ///< Best guess input parameters, and output
     41             const psVector *paramMask, ///< Parameter mask: 1 = fit for parameter, 0 = hold constant.
     42             const psArray *coords,     ///< Coordinates at which to evaluate function
     43             psMinimizeLMFunc func      ///< Function to minimize
     44    );
     45
     46/** Pre-defined functions for LM minimization */
     47psMinimizeLMFunc psMinimizeLMChi2Gauss1D;
     48psMinimizeLMFunc psMinimizeLMChi2Gauss2D;
     49
     50/** Function format for Powell minimization: does not require derivatives */
     51typedef float (*psMinimizePowellFunc)(
     52    const psVector *params,             ///< Parameters for which to evaluate
     53    const psArray *coords               ///< Array of vectors of coordinates at which to evaluate
     54    );
     55
     56/** Minimize a function using Powell: doesn't require derivatives.  Returns false if there were errors. */
     57bool
     58psMinimizePowell(psMinimization *min,   ///< Minimization specification, and output
     59                 psVector *params,      ///< Best guess input parameters, and output
     60                 const psVector *paramMask, ///< Parameter mask: 1 = fit for parameter, 0 = hold constant.
     61                 const psArray *coords, ///< Coordinates at which to evaluate function
     62                 psMinimizePowellFunc func ///< Function to minimize
     63    );
     64
     65/** Model function format for Powell Chi2 minimization */
     66typedef psVector* (*psMinimizeChi2PowellFunc)(
     67    const psVector *params,             ///< Parameters for which to evaluate
     68    const psArray *coords               ///< Array of vectors of coordinates at which to evaluate
     69    );
     70
     71/** Minimize Chi^2 for a data set given a model: using Powell method.  Returns false if there were errors. */
     72bool
     73psMinimizeChi2Powell(psMinimization *min,       ///< Minimization specification, and output
     74                     psVector *params,  ///< Best guess input parameters, and output
     75                     const psVector *paramMask, ///< Parameter mask: 1 = fit for parameter, 0 = hold constant.
     76                     const psArray *coords, ///< Coordinates at which to evaluate function
     77                     const psVector *value, ///< Measured values at coordinates
     78                     const psVector *error, ///< Errors in measured values at coordinates
     79                     psMinimizePowellChi2Func model ///< Model to fit
     80    );
     81
     82/************************************************************************************************************/
    3383
    3484/** Derive a polynomial fit by chi^2 minimisation --- can be done analytically */
Note: See TracChangeset for help on using the changeset viewer.