Changeset 1468
- Timestamp:
- Aug 10, 2004, 5:17:03 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
dataManip/psMinimize.c (modified) (9 diffs)
-
dataManip/psMinimize.h (modified) (1 diff)
-
math/psMinimize.c (modified) (9 diffs)
-
math/psMinimize.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMinimize.c
r1440 r1468 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08- 09 23:34:57$12 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-11 03:17:03 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 104 104 const psVector* restrict errors; 105 105 const psVector* restrict paramMask; 106 float (*evalModel) (const psVector* , const psVector* );107 float (*d_evalModel) (const psVector* , const psVector* , int);106 psMinimizeFunction evalModel; 107 psMinimizeFunctionDeriv d_evalModel; 108 108 } 109 109 psMinChi2Data; … … 115 115 const psVector* restrict coord; 116 116 const psVector* restrict paramMask; 117 float (*evalModel) (const psVector* , const psVector* );118 float (*d_evalModel) (const psVector* , const psVector* , int);117 psMinimizeFunction evalModel; 118 psMinimizeFunctionDeriv d_evalModel; 119 119 } 120 120 psMinimizeData; … … 165 165 const psVector* restrict mask = ((psMinimizeData* ) funcData)->paramMask; 166 166 psVector* restrict initialGuess = ((psMinimizeData* ) funcData)->initialGuess; 167 float (*evalModel) (const psVector* , const psVector* )= ((psMinimizeData* ) funcData)->evalModel;167 psMinimizeFunction evalModel = ((psMinimizeData* ) funcData)->evalModel; 168 168 psVector* inputParameterList = NULL; 169 169 … … 219 219 const psVector* restrict mask = ((psMinimizeData* ) funcData)->paramMask; 220 220 psVector* restrict initialGuess = ((psMinimizeData* ) funcData)->initialGuess; 221 float (*d_evalModel) (const psVector* , const psVector* , int) = 222 ((psMinimizeData* ) funcData)->d_evalModel; 221 psMinimizeFunctionDeriv d_evalModel = ((psMinimizeData* ) funcData)->d_evalModel; 223 222 psVector* inputParameterList = NULL; 224 223 … … 298 297 const psVector* restrict mask = ((psMinChi2Data* ) funcData)->paramMask; 299 298 psVector* restrict initialGuess = ((psMinChi2Data* ) funcData)->initialGuess; 300 float (*evalModel) (const psVector* , const psVector* )= ((psMinChi2Data* ) funcData)->evalModel;299 psMinimizeFunction evalModel = ((psMinChi2Data* ) funcData)->evalModel; 301 300 psVector* inputParameterList = NULL; 302 301 psVector* tmpVecPtr = NULL; … … 366 365 psVector* inputParameterList = NULL; 367 366 psVector* tmpVecPtr = NULL; 368 float (*d_evalModel) (const psVector* , const psVector* , int) = 369 ((psMinChi2Data* ) funcData)->d_evalModel; 367 psMinimizeFunctionDeriv d_evalModel = ((psMinChi2Data* ) funcData)->d_evalModel; 370 368 371 369 size_t i; … … 557 555 *****************************************************************************/ 558 556 psVector* psMinimize(psVector* restrict initialGuess, 559 float (*myFunction) (const psVector* restrict, const psVector* restrict), 560 float (*myFunctionDeriv) (const psVector* restrict, const psVector* restrict, int), 561 const psVector* restrict coord, const psVector* restrict paramMask) 557 psMinimizeFunction myFunction, 558 psMinimizeFunctionDeriv myFunctionDeriv, 559 const psVector* restrict coord, 560 const psVector* restrict paramMask) 562 561 { 563 562 int status; … … 664 663 such that they best fit the supplied data points. 665 664 *****************************************************************************/ 666 psVector* psMinimizeChi2( float (*evalModel) (const psVector* restrict, const psVector* restrict),667 float (*DevalModel) (const psVector* restrict, const psVector* restrict, int),665 psVector* psMinimizeChi2(psMinimizeFunction evalModel, 666 psMinimizeFunctionDeriv DevalModel, 668 667 const psImage* restrict domain, 669 668 const psVector* restrict data, 670 669 const psVector* restrict errors, 671 psVector* restrict initialGuess, const psVector* restrict paramMask, float *chiSq) 670 psVector* restrict initialGuess, 671 const psVector* restrict paramMask, 672 float *chiSq) 672 673 { 673 674 int numData = domain->numRows; // Number of data points -
trunk/psLib/src/dataManip/psMinimize.h
r1441 r1468 15 15 */ 16 16 17 /** This routine must minimize a non-linear function */ 18 psVector* psMinimize(psVector* restrict initialGuess, 19 float (*myFunction) (const psVector* restrict, const psVector* restrict), 20 float (*myFunctionDeriv) (const psVector* restrict, const psVector* restrict, int), 21 const psVector* restrict coord, const psVector* restrict paramMask); 17 /** function of a collection of parameters and coordinate vector. 18 * 19 * @return float value to minimize 20 */ 21 typedef float (*psMinimizeFunction)( 22 const psVector* restrict params, ///< collection of parameters 23 const psVector* restrict coord ///< coordinates 24 ); 22 25 23 /** Minimize chi^2 for input data */ 24 psVector* psMinimizeChi2(float (*evalModel) (const psVector* restrict, const psVector* restrict), ///< 25 // Model 26 // to 27 // fit; 28 // (domain 29 // and 30 // params) 31 float (*DevalModel) (const psVector* restrict, const psVector* restrict, int), ///< 32 // Derivative 33 // of 34 // model 35 // to 36 // fit; 37 // (domain 38 // and 39 // params) 40 const psImage* restrict domain, ///< The domain values for the corresponding 41 // measurements 42 const psVector* restrict data, ///< Data to fit 43 const psVector* restrict errors, ///< Errors in the data 44 psVector* restrict initialGuess, ///< Initial guess 45 const psVector* restrict paramMask, ///< 1 = fit for parameter, 0 = hold 46 // parameter constant 47 float *chiSq); 26 typedef float (*psMinimizeFunctionDeriv) ( 27 const psVector* restrict params, ///< collection of parameters 28 const psVector* restrict coord, ///< coordinates 29 int derivParam ///< index of parameter to calculate derivative of 30 ); 48 31 49 /** Derive a polynomial fit by chi^2 minimisation (analytically) */ 50 psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly, ///< Polynomial to fit 51 const psVector* restrict x, ///< Ordinates (or NULL to just use 52 // the indices) 53 const psVector* restrict y, ///< Coordinates 54 const psVector* restrict yErr ///< Errors in coordinates, or NULL 55 ); 32 /** Minimizes a non-linear function. 33 * 34 * psMinimize determines and returns the vector that minimizes the specified 35 * function. It takes as input a function, myFunction, an initial guess for 36 * the vector that minimizes the function, initialGuess, the current 37 * coordiate coord, and an optional mask for the vector elements (function 38 * parameters) to minimize, paramMask (all parameters are fit if PSLib SDRS 39 * 25 July 13, 2004 Pan-STARRS Image Processing Pipeline PSDC-430-007-04 40 * NULL). Note that paramMask must be of type psU8, while params must be of 41 * type psF32. The optional function, myFuncDeriv returns the derivative of 42 * the function. This function must be valid only for types psF32, psF64. 43 * 44 * @return psVector* minimized vector 45 */ 46 psVector* psMinimize( 47 psVector* restrict initialGuess, 48 psMinimizeFunction myFunction, 49 psMinimizeFunctionDeriv myFunctionDeriv, 50 const psVector* restrict coord, 51 const psVector* restrict paramMask 52 ); 53 54 /** Minimize chi^2 for input data. 55 * 56 * psMinimizeChi2 fits a model to observations by minimizing chi^2, returning 57 * the best-fit parameters. The input parameters are a function that 58 * evaluates the model for a specified domain, given the parameters, 59 * evalModel; a list of observations, (domain, data, and errors); an initial 60 * guess at the best-fit parameters, initialGuess which is returned with the 61 * best-fit parameters, and an optional mask specifying which parameters are 62 * to be fit, paramMask, which must be of type psU8. All parameters are fit 63 * if this vector is NULL. This function must be valid only for types psF32, 64 * psF64. 65 * 66 * @return psVector* minimized vector 67 */ 68 psVector* psMinimizeChi2( 69 psMinimizeFunction evalModel, ///< Model to fit; (domain and params) 70 psMinimizeFunctionDeriv DevalModel,///< Derivative of model to fit; (domain and params) 71 const psImage* restrict domain, ///< The domain values for the corresponding measurements 72 const psVector* restrict data, ///< Data to fit 73 const psVector* restrict errors, ///< Errors in the data 74 psVector* restrict initialGuess, ///< Initial guess 75 const psVector* restrict paramMask,///< 1 = fit for parameter, 0 = hold parameter constant 76 float *chiSq ///< chi squared 77 ); 78 79 /** Derive a polynomial fit by chi^2 minimisation (analytically) 80 * 81 * psVectorFitPolynomial1d returns the polynomial that best fits the 82 * observations. The input parameters are a polynomial that specifies the 83 * fit order, myPoly, which will be altered and returned with the best-fit 84 * coefficients; and the observations, x, y and yErr. The independent 85 * variable list, x may be NULL, in which case the vector index is used. 86 * The dependent variable error, yErr may be null, in which case the solution 87 * is determined in the assumption that all data errors are equal. This 88 * function must be valid only for types psF32, psF64. 89 * 90 * @return psPolynomial1D* polynomial fit 91 */ 92 psPolynomial1D* psVectorFitPolynomial1D( 93 psPolynomial1D* myPoly, ///< Polynomial to fit 94 const psVector* restrict x, ///< Ordinates (or NULL to just use the indices) 95 const psVector* restrict y, ///< Coordinates 96 const psVector* restrict yErr ///< Errors in coordinates, or NULL 97 ); 56 98 57 99 /* \} */// End of MathGroup Functions -
trunk/psLib/src/math/psMinimize.c
r1440 r1468 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08- 09 23:34:57$12 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-11 03:17:03 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 104 104 const psVector* restrict errors; 105 105 const psVector* restrict paramMask; 106 float (*evalModel) (const psVector* , const psVector* );107 float (*d_evalModel) (const psVector* , const psVector* , int);106 psMinimizeFunction evalModel; 107 psMinimizeFunctionDeriv d_evalModel; 108 108 } 109 109 psMinChi2Data; … … 115 115 const psVector* restrict coord; 116 116 const psVector* restrict paramMask; 117 float (*evalModel) (const psVector* , const psVector* );118 float (*d_evalModel) (const psVector* , const psVector* , int);117 psMinimizeFunction evalModel; 118 psMinimizeFunctionDeriv d_evalModel; 119 119 } 120 120 psMinimizeData; … … 165 165 const psVector* restrict mask = ((psMinimizeData* ) funcData)->paramMask; 166 166 psVector* restrict initialGuess = ((psMinimizeData* ) funcData)->initialGuess; 167 float (*evalModel) (const psVector* , const psVector* )= ((psMinimizeData* ) funcData)->evalModel;167 psMinimizeFunction evalModel = ((psMinimizeData* ) funcData)->evalModel; 168 168 psVector* inputParameterList = NULL; 169 169 … … 219 219 const psVector* restrict mask = ((psMinimizeData* ) funcData)->paramMask; 220 220 psVector* restrict initialGuess = ((psMinimizeData* ) funcData)->initialGuess; 221 float (*d_evalModel) (const psVector* , const psVector* , int) = 222 ((psMinimizeData* ) funcData)->d_evalModel; 221 psMinimizeFunctionDeriv d_evalModel = ((psMinimizeData* ) funcData)->d_evalModel; 223 222 psVector* inputParameterList = NULL; 224 223 … … 298 297 const psVector* restrict mask = ((psMinChi2Data* ) funcData)->paramMask; 299 298 psVector* restrict initialGuess = ((psMinChi2Data* ) funcData)->initialGuess; 300 float (*evalModel) (const psVector* , const psVector* )= ((psMinChi2Data* ) funcData)->evalModel;299 psMinimizeFunction evalModel = ((psMinChi2Data* ) funcData)->evalModel; 301 300 psVector* inputParameterList = NULL; 302 301 psVector* tmpVecPtr = NULL; … … 366 365 psVector* inputParameterList = NULL; 367 366 psVector* tmpVecPtr = NULL; 368 float (*d_evalModel) (const psVector* , const psVector* , int) = 369 ((psMinChi2Data* ) funcData)->d_evalModel; 367 psMinimizeFunctionDeriv d_evalModel = ((psMinChi2Data* ) funcData)->d_evalModel; 370 368 371 369 size_t i; … … 557 555 *****************************************************************************/ 558 556 psVector* psMinimize(psVector* restrict initialGuess, 559 float (*myFunction) (const psVector* restrict, const psVector* restrict), 560 float (*myFunctionDeriv) (const psVector* restrict, const psVector* restrict, int), 561 const psVector* restrict coord, const psVector* restrict paramMask) 557 psMinimizeFunction myFunction, 558 psMinimizeFunctionDeriv myFunctionDeriv, 559 const psVector* restrict coord, 560 const psVector* restrict paramMask) 562 561 { 563 562 int status; … … 664 663 such that they best fit the supplied data points. 665 664 *****************************************************************************/ 666 psVector* psMinimizeChi2( float (*evalModel) (const psVector* restrict, const psVector* restrict),667 float (*DevalModel) (const psVector* restrict, const psVector* restrict, int),665 psVector* psMinimizeChi2(psMinimizeFunction evalModel, 666 psMinimizeFunctionDeriv DevalModel, 668 667 const psImage* restrict domain, 669 668 const psVector* restrict data, 670 669 const psVector* restrict errors, 671 psVector* restrict initialGuess, const psVector* restrict paramMask, float *chiSq) 670 psVector* restrict initialGuess, 671 const psVector* restrict paramMask, 672 float *chiSq) 672 673 { 673 674 int numData = domain->numRows; // Number of data points -
trunk/psLib/src/math/psMinimize.h
r1441 r1468 15 15 */ 16 16 17 /** This routine must minimize a non-linear function */ 18 psVector* psMinimize(psVector* restrict initialGuess, 19 float (*myFunction) (const psVector* restrict, const psVector* restrict), 20 float (*myFunctionDeriv) (const psVector* restrict, const psVector* restrict, int), 21 const psVector* restrict coord, const psVector* restrict paramMask); 17 /** function of a collection of parameters and coordinate vector. 18 * 19 * @return float value to minimize 20 */ 21 typedef float (*psMinimizeFunction)( 22 const psVector* restrict params, ///< collection of parameters 23 const psVector* restrict coord ///< coordinates 24 ); 22 25 23 /** Minimize chi^2 for input data */ 24 psVector* psMinimizeChi2(float (*evalModel) (const psVector* restrict, const psVector* restrict), ///< 25 // Model 26 // to 27 // fit; 28 // (domain 29 // and 30 // params) 31 float (*DevalModel) (const psVector* restrict, const psVector* restrict, int), ///< 32 // Derivative 33 // of 34 // model 35 // to 36 // fit; 37 // (domain 38 // and 39 // params) 40 const psImage* restrict domain, ///< The domain values for the corresponding 41 // measurements 42 const psVector* restrict data, ///< Data to fit 43 const psVector* restrict errors, ///< Errors in the data 44 psVector* restrict initialGuess, ///< Initial guess 45 const psVector* restrict paramMask, ///< 1 = fit for parameter, 0 = hold 46 // parameter constant 47 float *chiSq); 26 typedef float (*psMinimizeFunctionDeriv) ( 27 const psVector* restrict params, ///< collection of parameters 28 const psVector* restrict coord, ///< coordinates 29 int derivParam ///< index of parameter to calculate derivative of 30 ); 48 31 49 /** Derive a polynomial fit by chi^2 minimisation (analytically) */ 50 psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly, ///< Polynomial to fit 51 const psVector* restrict x, ///< Ordinates (or NULL to just use 52 // the indices) 53 const psVector* restrict y, ///< Coordinates 54 const psVector* restrict yErr ///< Errors in coordinates, or NULL 55 ); 32 /** Minimizes a non-linear function. 33 * 34 * psMinimize determines and returns the vector that minimizes the specified 35 * function. It takes as input a function, myFunction, an initial guess for 36 * the vector that minimizes the function, initialGuess, the current 37 * coordiate coord, and an optional mask for the vector elements (function 38 * parameters) to minimize, paramMask (all parameters are fit if PSLib SDRS 39 * 25 July 13, 2004 Pan-STARRS Image Processing Pipeline PSDC-430-007-04 40 * NULL). Note that paramMask must be of type psU8, while params must be of 41 * type psF32. The optional function, myFuncDeriv returns the derivative of 42 * the function. This function must be valid only for types psF32, psF64. 43 * 44 * @return psVector* minimized vector 45 */ 46 psVector* psMinimize( 47 psVector* restrict initialGuess, 48 psMinimizeFunction myFunction, 49 psMinimizeFunctionDeriv myFunctionDeriv, 50 const psVector* restrict coord, 51 const psVector* restrict paramMask 52 ); 53 54 /** Minimize chi^2 for input data. 55 * 56 * psMinimizeChi2 fits a model to observations by minimizing chi^2, returning 57 * the best-fit parameters. The input parameters are a function that 58 * evaluates the model for a specified domain, given the parameters, 59 * evalModel; a list of observations, (domain, data, and errors); an initial 60 * guess at the best-fit parameters, initialGuess which is returned with the 61 * best-fit parameters, and an optional mask specifying which parameters are 62 * to be fit, paramMask, which must be of type psU8. All parameters are fit 63 * if this vector is NULL. This function must be valid only for types psF32, 64 * psF64. 65 * 66 * @return psVector* minimized vector 67 */ 68 psVector* psMinimizeChi2( 69 psMinimizeFunction evalModel, ///< Model to fit; (domain and params) 70 psMinimizeFunctionDeriv DevalModel,///< Derivative of model to fit; (domain and params) 71 const psImage* restrict domain, ///< The domain values for the corresponding measurements 72 const psVector* restrict data, ///< Data to fit 73 const psVector* restrict errors, ///< Errors in the data 74 psVector* restrict initialGuess, ///< Initial guess 75 const psVector* restrict paramMask,///< 1 = fit for parameter, 0 = hold parameter constant 76 float *chiSq ///< chi squared 77 ); 78 79 /** Derive a polynomial fit by chi^2 minimisation (analytically) 80 * 81 * psVectorFitPolynomial1d returns the polynomial that best fits the 82 * observations. The input parameters are a polynomial that specifies the 83 * fit order, myPoly, which will be altered and returned with the best-fit 84 * coefficients; and the observations, x, y and yErr. The independent 85 * variable list, x may be NULL, in which case the vector index is used. 86 * The dependent variable error, yErr may be null, in which case the solution 87 * is determined in the assumption that all data errors are equal. This 88 * function must be valid only for types psF32, psF64. 89 * 90 * @return psPolynomial1D* polynomial fit 91 */ 92 psPolynomial1D* psVectorFitPolynomial1D( 93 psPolynomial1D* myPoly, ///< Polynomial to fit 94 const psVector* restrict x, ///< Ordinates (or NULL to just use the indices) 95 const psVector* restrict y, ///< Coordinates 96 const psVector* restrict yErr ///< Errors in coordinates, or NULL 97 ); 56 98 57 99 /* \} */// End of MathGroup Functions
Note:
See TracChangeset
for help on using the changeset viewer.
