IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 8, 2004, 1:32:03 PM (22 years ago)
Author:
gusciora
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMinimize.c

    r1719 r1734  
    99 *  @author George Gusciora, MHPCC
    1010 *
    11  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-09-08 06:02:23 $
     11 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-09-08 23:32:03 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 *
     16 *  XXX: must follow coding name standards on local functions.
     17 *
    1518 */
    1619
    1720/*****************************************************************************/
    18 
    1921/* INCLUDE FILES                                                             */
    20 
    2122/*****************************************************************************/
    2223#include <stdlib.h>
     
    4647
    4748/*****************************************************************************/
    48 
    4949/* DEFINE STATEMENTS                                                         */
    50 
    5150/*****************************************************************************/
     51
    5252#define MAX_LMM_ITERATIONS 100
    5353#define MAX_MINIMIZE_ITERATIONS 100
     
    9191
    9292/*****************************************************************************/
    93 
    9493/* TYPE DEFINITIONS                                                          */
    95 
    9694/*****************************************************************************/
     95
    9796typedef struct
    9897{
     
    121120
    122121/*****************************************************************************/
    123 
    124122/* GLOBAL VARIABLES                                                          */
    125 
    126123/*****************************************************************************/
    127124
     125static psMinimizeChi2PowellFunc Chi2PowellFunc = NULL;
     126//static psMinimizePowellFunc PowellFunc = NULL;
     127static psVector *myValue;
     128static psVector *myError;
     129
     130/*****************************************************************************/
     131/* FILE STATIC VARIABLES                                                     */
     132/*****************************************************************************/
     133
    128134// None
    129135
    130136/*****************************************************************************/
    131 
    132 /* FILE STATIC VARIABLES                                                     */
    133 
    134 /*****************************************************************************/
    135 
    136 // None
    137 
    138 /*****************************************************************************/
    139 
    140137/* FUNCTION IMPLEMENTATION - LOCAL                                           */
    141 
    142138/*****************************************************************************/
    143139
     
    543539
    544540/*****************************************************************************/
    545 
    546541/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    547 
    548542/*****************************************************************************/
    549543
     
    850844    return (initialGuess);
    851845}
     846/******************************************************************************
     847GUS
     848 
     849XXX: bug report for the psMatrix covar argument.
     850 *****************************************************************************/
     851bool psMinimizeLM(psMinimization *min,
     852                  psImage *covar,
     853                  psVector *params,
     854                  const psVector *paramMask,
     855                  const psArray *coords,
     856                  psMinimizeLMFunc func)
     857{
     858    /*
     859        psVector *beta = psVectorAlloc(params->n, PS_TYPE_F32);
     860        psImage *alpha = psImageAlloc(params->n, params->n, PS_TYPE_F32);
     861        psVector *deriv;
     862        int i;
     863        int k;
     864        float tmp;
     865     
     866        tmp = func(deriv, params, coords);
     867        for (k=0;k<params->n;k++) {
     868            beta->data.F32[k] = 0.0;
     869            for (i=0;i<params->n;i++) {
     870                beta->data.F32[k]+= deriv
     871            }
     872    */
     873    return(false);
     874}
     875
    852876
    853877/******************************************************************************
     
    856880    error for each data point (yErr).
    857881 
    858 NOTE: yErr is currently ignored.
     882XXX: NOTE: yErr is currently ignored.
    859883 *****************************************************************************/
    860884psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly,
     
    15051529
    15061530/******************************************************************************
    1507     This routine must minimize a possibly multi-dimensional function.
     1531This routine must minimize a possibly multi-dimensional function.  The
     1532function to be minimized "func" is:
     1533    float func(psVector *params, psArray *coords)
     1534The "params" are the parameters of the function which are varied.  The data
     1535points at which the function is varied are in the argument "coords" which is
     1536a psArray of psVectors: each vector represents a different coordinate.
     1537 
     1538XXX: We do not use Brent's method.
     1539 
     1540XXX: We do not use the
    15081541 *****************************************************************************/
    15091542bool psMinimizePowell(psMinimization *min,
     
    16721705    return(false);
    16731706}
     1707
     1708/******************************************************************************
     1709This routine is to be used with the psMinimizeChi2Powell() function below.
     1710and the psMinimizePowell() function above.
     1711 
     1712The basic idea is calculate chi-squared for a set of params/coords/errors.
     1713This functions uses globale variables to receive the function pointer, the
     1714data values, and the data errors.
     1715 *****************************************************************************/
     1716float myPowellChi2Func(const psVector *params,
     1717                       const psArray *coords)
     1718{
     1719    float chi2 = 0.0;
     1720    float d;
     1721    int i;
     1722    psVector *tmp;
     1723
     1724    tmp = Chi2PowellFunc(params, coords);
     1725    for (i=0;i<coords->n;i++) {
     1726        d = (tmp->data.F32[i] - myValue->data.F32[i]) / myError->data.F32[i];
     1727        chi2+= d * d;
     1728    }
     1729    psFree(tmp);
     1730    return(chi2);
     1731}
     1732
     1733
     1734/******************************************************************************
     1735This routine must minimize the chi-squared match of a set of data points and
     1736values for a possibly multi-dimensional function.
     1737 
     1738The basic idea is to use the psMinimizePowell() function defined above.  In
     1739order to do so, we defined above a function myPowellChi2Func() which takes
     1740the "func" function and returns chi-squared over the params/coords/values.
     1741We then use that function myPowellChi2Func() in the call to
     1742psMinimizePowell().
     1743 *****************************************************************************/
     1744bool psMinimizeChi2Powell(psMinimization *min,
     1745                          psVector *params,
     1746                          const psVector *paramMask,
     1747                          const psArray *coords,
     1748                          const psVector *value,
     1749                          const psVector *error,
     1750                          psMinimizeChi2PowellFunc func)
     1751{
     1752    myValue = (psVector *) value;
     1753    myError = (psVector *) error;
     1754    Chi2PowellFunc = func;
     1755
     1756    return(psMinimizePowell(min, params, paramMask, coords, myPowellChi2Func));
     1757}
Note: See TracChangeset for help on using the changeset viewer.