IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6437


Ignore:
Timestamp:
Feb 16, 2006, 2:56:48 PM (20 years ago)
Author:
gusciora
Message:

* empty log message *

Location:
trunk/psLib/src/math
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psConstants.h

    r6204 r6437  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-01-26 21:10:22 $
     8 *  @version $Revision: 1.85 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-02-17 00:56:48 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    169169}
    170170
    171 // Return an error if the arg is lies outside the supplied range.
     171// Return an error if the arg lies outside the supplied range.
    172172#define PS_ASSERT_FLOAT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
    173173if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
     
    186186}
    187187
    188 // Return an error if the arg lies outside the supplied range
    189188#define PS_ASSERT_LONG_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
    190189if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
     
    519518} \
    520519
    521 /* XXX: This is not correct
    522     #define PS_POLY_2D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    523     static psPolynomial2D *(NAME) = NULL; \
    524     if ((NAME) == NULL) { \
    525         (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
    526         p_psMemSetPersistent((NAME), true); \
    527     } \
    528  
    529     #define PS_POLY_3D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    530     static psPolynomial3D *(NAME) = NULL; \
    531     if ((NAME) == NULL) { \
    532         (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
    533         p_psMemSetPersistent((NAME), true); \
    534     } \
    535  
    536     #define PS_POLY_4D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    537     static psPolynomial4D *(NAME) = NULL; \
    538     if ((NAME) == NULL) { \
    539         (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
    540         p_psMemSetPersistent((NAME), true); \
    541     } \
    542 */
    543 
    544520#define PS_POLY_1D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    545521static psPolynomial1D *(NAME) = NULL; \
     
    548524    p_psMemSetPersistent((NAME), true); \
    549525} \
    550 
    551 /* XXX: This is not correct
    552     #define PS_POLY_2D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    553     static psPolynomial2D *(NAME) = NULL; \
    554     if ((NAME) == NULL) { \
    555         (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
    556         p_psMemSetPersistent((NAME), true); \
    557     } \
    558  
    559     #define PS_POLY_3D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    560     static psPolynomial3D *(NAME) = NULL; \
    561     if ((NAME) == NULL) { \
    562         (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
    563         p_psMemSetPersistent((NAME), true); \
    564     } \
    565  
    566     #define PS_POLY_4D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
    567     static psPolynomial4D *(NAME) = NULL; \
    568     if ((NAME) == NULL) { \
    569         (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
    570         p_psMemSetPersistent((NAME), true); \
    571     } \
    572 */
    573526
    574527#define PS_POLY_PRINT_1D(NAME) \
  • trunk/psLib/src/math/psMathUtils.h

    r6305 r6437  
    77 *  @author GLG, MHPCC
    88 *
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-02-02 21:09:07 $
     9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-02-17 00:56:48 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5151);
    5252
    53 // XXX: Create a single, generic, version of the vector normalize function.
    54 // XXX: Ask IfA for a public psLib function.
    55 
    5653psS32 p_psNormalizeVectorRange(psVector* myData,
    5754                               psF64 outLow,
  • trunk/psLib/src/math/psMinimizeLMM.h

    r6226 r6437  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-01-27 20:08:58 $
     10 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-02-17 00:56:48 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    115115    const psArray *x,                  ///< Measurement ordinates of multiple vectors
    116116    const psVector *y,                 ///< Measurement coordinates
    117     const psVector *yErr,              ///< Errors in the measurement coordinates
     117    const psVector *yWt,               ///< Errors in the measurement coordinates
    118118    psMinimizeLMChi2Func func          ///< Specified function
    119119);
  • trunk/psLib/src/math/psPolynomial.c

    r6348 r6437  
    44*         routines.
    55*
    6 *  This file will hold the functions for allocated, freeing, and evaluating
     6*  This file will hold the routiness for allocating, freeing, and evaluating
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.142 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-02-07 23:36:15 $
     9*  @version $Revision: 1.143 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-02-17 00:56:48 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    159159used frequently and the data structure created here does not contain the
    160160outer coefficients of the Chebyshev polynomials.
    161  
    162161 *****************************************************************************/
    163162psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys)
     
    165164    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL);
    166165
    167     if (0) {
    168         psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
    169         for (psS32 i = 0; i < numPolys; i++) {
    170             chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
    171             chebPolys[i]->coeff[i] = 1;
    172         }
    173         return (chebPolys);
    174     } else {
    175         psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
    176         for (psS32 i = 0; i < numPolys; i++) {
    177             chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
    178         }
    179 
    180         // Create the Chebyshev polynomials.
    181         // Polynomial i has i-th order.
    182         chebPolys[0]->coeff[0] = 1.0;
    183         if (numPolys >= 2) {
    184             chebPolys[1]->coeff[1] = 1.0;
    185 
    186             for (psS32 i = 2; i < numPolys; i++) {
    187                 for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) {
    188                     chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j];
    189                 }
    190                 for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) {
    191                     chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    192                 }
    193             }
    194         }
    195 
    196         if (psTraceGetLevel(__func__) >= 6) {
    197             for (psS32 j = 0; j < numPolys; j++) {
    198                 PS_POLY_PRINT_1D(chebPolys[j]);
    199             }
    200         }
    201         return (chebPolys);
    202     }
     166    psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
     167    for (psS32 i = 0; i < numPolys; i++) {
     168        chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i);
     169    }
     170
     171    // Create the Chebyshev polynomials.
     172    // Polynomial i has i-th order.
     173    chebPolys[0]->coeff[0] = 1.0;
     174    if (numPolys >= 2) {
     175        chebPolys[1]->coeff[1] = 1.0;
     176
     177        for (psS32 i = 2; i < numPolys; i++) {
     178            for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) {
     179                chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j];
     180            }
     181            for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) {
     182                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     183            }
     184        }
     185    }
     186
     187    if (psTraceGetLevel(__func__) >= 6) {
     188        for (psS32 j = 0; j < numPolys; j++) {
     189            PS_POLY_PRINT_1D(chebPolys[j]);
     190        }
     191    }
     192    return (chebPolys);
    203193}
    204194
     
    223213    for (loop_x = 0; loop_x < poly->nX+1; loop_x++) {
    224214        if (poly->mask[loop_x] == 0) {
    225             // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to
    226             // 2 or higher in the test code, you get seg faults.
    227215            psTrace(__func__, 8,
    228216                    "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]);
     
    238226// XXX: You can do this without having to psAlloc() vector d.
    239227// XXX: How does the mask vector effect Crenshaw's formula?
    240 // XXX: We assume that x is scaled between -1.0 and 1.0;
     228// NOTE: We assume that x is scaled between -1.0 and 1.0;
    241229// XXX: Create a faster version for low-order Chebyshevs.
    242230static psF64 chebPolynomial1DEval(
     
    298286        psFree(d);
    299287    } else {
    300         // This is old code that does not use Clenshaw's formula.  Get rid of it.
     288        // XXX: This is old code that does not use Clenshaw's formula.  Get rid of it.
    301289        psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX);
    302290
  • trunk/psLib/src/math/psSpline.c

    r6305 r6437  
    66*  This file contains the routines that allocate, free, and evaluate splines.
    77*
    8 *  @version $Revision: 1.135 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2006-02-02 21:09:08 $
     8*  @version $Revision: 1.136 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2006-02-17 00:56:48 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    101101 
    102102The first and second derivatives at the endpoints were previously undefined in
    103 the SDR.  From bugzilla #???, they are required to be 0.0, impementing natural
     103the SDR.  From bugzilla #???, they are required to be 0.0, implementing natural
    104104splines.
    105105 
     
    228228    // The following code ensures that xPtr and yPtr points to a psF32 psVector.
    229229    //
    230     // XXX: When you debug, use the vector copy and create routines here:
     230    // XXX: Use the vector copy and create routines here:
    231231    //
    232232
     
    345345/*****************************************************************************
    346346psSpline1DEval(): this routine takes an existing spline of arbitrary order
    347 and an independent x value.  Each determines which spline that x corresponds
     347and an independent x value.  It determines which spline that x corresponds
    348348to by doing a bracket disection on the knots of the spline data structure
    349349(vectorBinDisectF32()).  Then it evaluates the spline at that x location
     
    360360    float x)
    361361{
    362     psTrace(__func__, 3, "---- %s(%f) begin ----\n", __func__, x);
     362    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
    363363    PS_ASSERT_PTR_NON_NULL(spline, NAN);
    364364    PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN);
     
    366366
    367367    psS32 n = spline->n;
     368    if ((x < spline->knots->data.F32[0]) || (x > spline->knots->data.F32[n-1])) {
     369        // If x is outside the range of spline->knots, generate a warning
     370        // message, then return the left, or right, endpoint.
     371        psLogMsg(__func__, PS_LOG_WARN,
     372                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
     373                 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
     374
     375        psS32 binNum = (x < spline->knots->data.F32[0]) ? 0 : n-1;
     376        psTrace(__func__, 3, "---- %s() end ----\n", __func__);
     377        return(psPolynomial1DEval(spline->spline[binNum], x));
     378    }
     379
    368380    psScalar tmpScalar;
    369381    tmpScalar.type.type = PS_TYPE_F32;
    370382    tmpScalar.data.F32 = x;
    371383    psS32 binNum = p_psVectorBinDisect(spline->knots, &tmpScalar);
    372 
    373384    if (binNum < 0) {
    374         //
    375         // If x is outside the range of spline->knots, generate a warning
    376         // message, then return the left, or right, endpoint.
    377         //
    378         psLogMsg(__func__, PS_LOG_WARN,
    379                  "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
    380                  x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
    381 
    382         if (x < spline->knots->data.F32[0]) {
    383             psF32 rcF32 = psPolynomial1DEval(spline->spline[0], x);
    384             psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
    385             return(rcF32);
    386         } else if (x > spline->knots->data.F32[n-1]) {
    387             psF32 rcF32 = psPolynomial1DEval(spline->spline[n-1], x);
    388             psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
    389             return(rcF32);
    390         }
    391     }
    392 
    393     psF32 rcF32 = psPolynomial1DEval(spline->spline[binNum], x);
    394     psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
    395     return(rcF32);
     385        psError(PS_ERR_UNKNOWN, false, "Could not perform bin dissection on spline->knots.\n");
     386        return(NAN);
     387    }
     388
     389    psTrace(__func__, 3, "---- %s() end ----\n", __func__);
     390    return(psPolynomial1DEval(spline->spline[binNum], x));
    396391}
    397392
  • trunk/psLib/src/math/psStats.c

    r6322 r6437  
    1616 * use ->min and ->max (PS_STAT_USE_RANGE)
    1717 *
    18  *  @version $Revision: 1.167 $ $Name: not supported by cvs2svn $
    19  *  @date $Date: 2006-02-03 22:05:22 $
     18 *  @version $Revision: 1.168 $ $Name: not supported by cvs2svn $
     19 *  @date $Date: 2006-02-17 00:56:48 $
    2020 *
    2121 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    440440unmasked element within the specified min/max range).  Otherwise, return
    441441"false".
    442  
    443 XXX: Can you use psVectorCountPixelMask here?
    444442 *****************************************************************************/
    445 bool p_psVectorCheckNonEmpty(const psVector* myVector,
    446                              const psVector* maskVector,
    447                              psU32 maskVal,
    448                              psStats* stats)
     443bool p_psVectorCheckNonEmpty(
     444    const psVector* myVector,
     445    const psVector* maskVector,
     446    psU32 maskVal,
     447    psStats* stats)
    449448{
    450449    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
     
    496495number of non-masked pixels in the vector that fall within the min/max
    497496range, if specified.
    498  
    499 XXX: Can you use psVectorCountPixelMask here?
    500497 *****************************************************************************/
    501498psS32 p_psVectorNValues(const psVector* myVector,
     
    644641robustHistogram with a Gaussian of width sigma.  It returns a psVector of the
    645642smoothed data.
    646  
    647 XXX: Only PS_TYPE_F32 is supported.
    648  
    649 XXX: Write a general routine which smoothes a psVector.  This routine should
    650 call that.  Is that possible?
    651643 *****************************************************************************/
    652644psVector *p_psVectorSmoothHistGaussian(
     
    985977    -1: error
    986978    -2: warning
    987  
    988 XXX: Use static vectors for tmpMask.
    989979 *****************************************************************************/
    990980psS32 p_psVectorClippedStats(const psVector* myVector,
     
    12241214
    12251215        //
    1226         // Ensure that the y values are monotonic.
    1227         //
    1228         // XXX: This routine should probably be rewritten in a more general fashion
    1229         // so that the following checks are not necessary.
     1216        // Ensure that the y value lies within range of the y values.
    12301217        //
    12311218        if (! (((y->data.F64[0] <= yVal) && (yVal <= y->data.F64[2])) ||
     
    12361223        }
    12371224
     1225        //
     1226        // Ensure that the y values are monotonic.
     1227        //
    12381228        if (((y->data.F64[0] < y->data.F64[1]) && !(y->data.F64[1] <= y->data.F64[2])) ||
    12391229                ((y->data.F64[0] > y->data.F64[1]) && !(y->data.F64[1] >= y->data.F64[2]))) {
     
    12891279        } else if (binNum == (xVec->n - 2)) {
    12901280            // XXX: Is this right?
    1291             tmpFloat = 0.5 * (xVec->data.F32[binNum] +
    1292                               xVec->data.F32[binNum + 1]);
     1281            tmpFloat = 0.5 * (xVec->data.F32[binNum] + xVec->data.F32[binNum + 1]);
    12931282        }
    12941283    }
     
    16771666    tmpScalar.data.F32 = totalDataPoints * 0.25f;
    16781667    if (tmpScalar.data.F32 <= cumulativeRobustHistogram->nums->data.F32[0]) {
    1679         // XXX: Special case where its in first bin.  Must code last bin.
     1668        // Special case where its in first bin.  The last bin should be handled automatically.
    16801669        binLo25 = 0;
    16811670    } else {
     
    16841673    tmpScalar.data.F32 = totalDataPoints * 0.75f;
    16851674    if (tmpScalar.data.F32 <= cumulativeRobustHistogram->nums->data.F32[0]) {
    1686         // XXX: Special case where its in first bin.  Must code last bin.
     1675        // Special case where its in first bin.  The last bin should be handled automatically.
    16871676        binHi25 = 0;
    16881677    } else {
     
    17041693    // Interpolate to find these two positions exactly: these are the upper
    17051694    // and lower quartile positions.
    1706     // XXX: Check for errors.
    17071695    //
    17081696    psF32 binLo25F32 = fitQuadraticSearchForYThenReturnX(
     
    17111699                           binLo25,
    17121700                           totalDataPoints * 0.25f);
     1701
    17131702    psF32 binHi25F32 = fitQuadraticSearchForYThenReturnX(
    17141703                           *(psVector* *)&cumulativeRobustHistogram->bounds,
     
    17161705                           binHi25,
    17171706                           totalDataPoints * 0.75f);
     1707
     1708    if (isnan(binLo25F32) || isnan(binHi25F32)) {
     1709        psError(PS_ERR_UNKNOWN, false, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnX() returned a NAN.\n");
     1710        psFree(tmpStatsMinMax);
     1711        psFree(robustHistogram);
     1712        psFree(cumulativeRobustHistogram);
     1713        psFree(tmpMaskVec);
     1714        psTrace(__func__, 4, "---- %s(1) end  ----\n", __func__);
     1715        return(1);
     1716    }
     1717
    17181718    stats->robustLQ = binLo25F32;
    17191719    stats->robustUQ = binHi25F32;
    17201720    psTrace(__func__, 6, "The 25 and 75 percent data point exact positions are (%f, %f).\n", binLo25F32, binHi25F32);
    1721 
    17221721    psS32 N50 = 0;
    17231722    for (psS32 i = 0 ; i < myVector->n ; i++) {
     
    18631862        }
    18641863
    1865         // XXX: Use the min/max routines for this
    1866         psF32 minY = FLT_MAX;
    1867         psF32 maxY = -FLT_MAX;
    1868         for (psS32 i = 0 ; i < y->n ; i++) {
    1869             if (y->data.F32[i] > maxY) {
    1870                 maxY = y->data.F32[i];
    1871             }
    1872             if (y->data.F32[i] < minY) {
    1873                 minY = y->data.F32[i];
    1874             }
    1875         }
     1864        rc = p_psVectorMin(y, NULL, 0, tmpStatsMinMax);
     1865        rc|= p_psVectorMax(y, NULL, 0, tmpStatsMinMax);
     1866        if ((rc != 0) || isnan(tmpStatsMinMax->min) || isnan(tmpStatsMinMax->max)) {
     1867            psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1868            psFree(tmpMaskVec);
     1869            psFree(robustHistogram);
     1870            psFree(cumulativeRobustHistogram);
     1871            psFree(tmpStatsMinMax);
     1872            psTrace(__func__, 4, "---- %s(1) end  ----\n", __func__);
     1873            return(1);
     1874        }
     1875
    18761876        //
    18771877        // Normalize y to [0.0:1.0] (since the psMinimizeLMChi2Gauss1D() functions is [0.0:1.0])
     
    18791879        //
    18801880        for (psS32 i = 0 ; i < y->n ; i++) {
    1881             y->data.F32[i]= (y->data.F32[i] - minY) / (maxY - minY);
     1881            y->data.F32[i]= (y->data.F32[i] - tmpStatsMinMax->min) / (tmpStatsMinMax->max - tmpStatsMinMax->min);
    18821882        }
    18831883
     
    22952295                        }
    22962296                    } else {
    2297                         // XXX: This if-statement really shouldn't be necessary.
     2297                        // This if-statement really shouldn't be necessary.
    22982298                        // However, due to numerical lack of precision, we
    22992299                        // occasionally produce a binNum outside the range.
     
    24352435XXX: Should we free stats if the asserts fail?
    24362436 *****************************************************************************/
    2437 psStats* psVectorStats(psStats* stats,
    2438                        const psVector* in,
    2439                        const psVector* errors,
    2440                        const psVector* mask,
    2441                        psMaskType maskVal)
     2437psStats* psVectorStats(
     2438    psStats* stats,
     2439    const psVector* in,
     2440    const psVector* errors,
     2441    const psVector* mask,
     2442    psMaskType maskVal)
    24422443{
    24432444    psTrace(__func__, 3,"---- %s() begin  ----\n", __func__);
Note: See TracChangeset for help on using the changeset viewer.