IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 28, 2004, 12:47:00 PM (22 years ago)
Author:
gusciora
Message:

Modifying the minimization algorithms.

File:
1 edited

Legend:

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

    r2227 r2228  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.79 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-28 00:46:04 $
    13 n *
     11 *  @version $Revision: 1.80 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-28 22:46:57 $
     13 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1515 */
     
    123123    default:
    124124        return false;
    125     }
    126 }
    127 
    128 /*****************************************************************************
    129 p_psVectorPrint(myVector, maskVector, maskVal, stats): a private internal
    130 function that simply prints a vector to STDOUT.  Used primarily for
    131 debugging.
    132  *****************************************************************************/
    133 
    134 void p_psVectorPrint(psVector* myVector, psVector* maskVector, psU32 maskVal, psStats* stats)
    135 {
    136     psS32 i = 0;                  // Loop index variable.
    137 
    138     for (i = 0; i < myVector->n; i++) {
    139         if (maskVector != NULL)
    140             printf("Element %d is %f (mask is %d)\n", i, myVector->data.F32[i], maskVector->data.U8[i]);
    141         else
    142             printf("Element %d is %f\n", i, myVector->data.F32[i]);
    143125    }
    144126}
     
    428410    // Allocate temporary vectors for the data.
    429411    unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
    430     unsortedVector->n = unsortedVector->nalloc;
    431 
    432412    sortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
    433     sortedVector->n = sortedVector->nalloc;
    434413
    435414    // Determine if we must only use data points within a min/max range.
     
    579558    // Allocate temporary vectors for the data.
    580559    unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
    581     unsortedVector->n = unsortedVector->nalloc;
    582560    sortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
    583     sortedVector->n = sortedVector->nalloc;
    584561
    585562    // Determine if we must only use data points within a min/max range.
     
    817794p_psNormalizeVectorF32(myData): this is a private function which normalizes the
    818795elements of a vector to a range between 0.0 and 1.0.
     796 
     797XXX: how about an arbitrary p_psNormalizeVectorF32(myData, min, max)?
    819798 *****************************************************************************/
    820799void p_psNormalizeVectorF32(psVector* myData)
     
    847826elements of a vector to a range between -1.0 and 1.0.
    848827XXX: 0-1 or -1:1?
     828 
     829XXX: how about an arbitrary p_psNormalizeVectorF64(myData, min, max)?
    849830 *****************************************************************************/
    850831void p_psNormalizeVectorF64(psVector* myData)
     
    876857}
    877858
     859// XXX: how about an arbitrary p_psNormalizeVector(myData, min, max)?
    878860void p_psNormalizeVector(psVector* myData)
    879861{
     
    885867        psError(__func__, "Unalowable data type.\n");
    886868    }
    887 }
    888 
    889 /*****************************************************************************
    890 p_psGaussian(myData, myParams): an internal function, used by robust stats,
    891 intended to compute the Gaussian with a specified sigma/mean, at the
    892 specified data point.
    893  *****************************************************************************/
    894 float p_psGaussian(const psVector* restrict myData,
    895                    const psVector* restrict myParams)
    896 {
    897     float x = myData->data.F32[0];
    898     float mean = myParams->data.F32[0];
    899     float stdev = myParams->data.F32[1];
    900     float tmp = exp(-((x - mean) * (x - mean)) / (2.0 * stdev * stdev));
    901 
    902     tmp /= ((float)sqrt(2.0 * M_PI * (stdev * stdev)));
    903 
    904     // printf("p_psGaussian((%.2f), %.2f, %.2f) is %.2f\n", x, mean, stdev, tmp);
    905     return (tmp);
    906 }
    907 
    908 /*****************************************************************************
    909 p_psGaussianDeriv(myData, myParams, whichParam): an internal function, which
    910 calculates the specified partial derivative of the above Gaussian function.
    911  *****************************************************************************/
    912 float p_psGaussianDeriv(const psVector* restrict myData,
    913                         const psVector* restrict myParams, psS32 whichParam)
    914 {
    915     float x = myData->data.F32[0];
    916     float mean = myParams->data.F32[0];
    917     float stdev = myParams->data.F32[1];
    918     float tmp = 0.0;
    919 
    920     if (whichParam == 0) {
    921         // Return the derivative w.r.t. the mean.
    922         tmp = (x - mean) * p_psGaussian(myData, myParams);
    923         tmp /= (stdev * stdev);
    924     } else if (whichParam == 1) {
    925         // Return the derivative w.r.t. the stdev.
    926         tmp = (x - mean) * (x - mean) * p_psGaussian(myData, myParams);
    927         tmp /= (stdev * stdev * stdev);
    928     }
    929     printf("p_psGaussianDeriv((%.2f), %.2f, %.2f, (%d)) is %.2f\n", x, mean, stdev, whichParam, tmp);
    930 
    931     return (tmp);
    932 }
    933 
    934 /*****************************************************************************
    935 p_psQuadratic(myData, myParams): an internal function, used by robust stats,
    936 intended to compute a quadratic, with the specified parameters, at the
    937 specified data point.
    938  *****************************************************************************/
    939 float p_psQuadratic(const psVector* restrict myParams, const psVector* restrict myCoords)
    940 {
    941     float x = myCoords->data.F32[0];
    942     float A = myParams->data.F32[0];
    943     float B = myParams->data.F32[1];
    944     float C = myParams->data.F32[2];
    945     float tmp = 0.0;
    946 
    947     tmp = (A * x * x) + (B * x) + C;
    948     return (tmp);
    949 }
    950 
    951 /*****************************************************************************
    952 p_psQuadraticDeriv(myData, myParams, whichParam): an internal function, which
    953 calculates the specified partial derivative of the above quadratic function.
    954  *****************************************************************************/
    955 float p_psQuadraticDeriv(const psVector* restrict myParams,
    956                          const psVector* restrict myCoords, psS32 whichParamDeriv)
    957 {
    958     float x = myCoords->data.F32[0];
    959     float tmp = 0.0;
    960 
    961     if (whichParamDeriv == 0) {
    962         tmp = x * x;
    963     } else if (whichParamDeriv == 1) {
    964         tmp = x;
    965     } else if (whichParamDeriv == 2) {
    966         tmp = 1.0;
    967     }
    968 
    969     return (tmp);
    970869}
    971870
     
    1022921and i+1 is used for x[i]).  It then determines for what value x does that
    1023922quadratic f(x) = yVal (the input parameter).
    1024  
    1025 // XXX: Use static variables.
    1026923*****************************************************************************/
    1027924float fitQuadraticSearchForYThenReturnX(psVector *xVec,
     
    1030927                                        float yVal)
    1031928{
    1032     //    static psVector* x = NULL;
    1033     //    static psVector* y = NULL;
    1034     //    static psVector* yErr = NULL;
    1035     psVector* x = psVectorAlloc(3, PS_TYPE_F64);
    1036     psVector* y = psVectorAlloc(3, PS_TYPE_F64);
    1037     psVector* yErr = psVectorAlloc(3, PS_TYPE_F64);
    1038 
    1039     /*
    1040         if (x == NULL) {
    1041             x = psVectorAlloc(3, PS_TYPE_F64);
    1042             p_psMemSetPersistent(x, true);
    1043         }
    1044         if (y == NULL) {
    1045             y = psVectorAlloc(3, PS_TYPE_F64);
    1046             p_psMemSetPersistent(y, true);
    1047         }
    1048         if (yErr == NULL) {
    1049             yErr = psVectorAlloc(3, PS_TYPE_F64);
    1050             p_psMemSetPersistent(yErr, true);
    1051         }
    1052     */
    1053     psPolynomial1D* myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
     929    PS_VECTOR_DECLARE_ALLOC_STATIC(x, 3, PS_TYPE_F64);
     930    PS_VECTOR_DECLARE_ALLOC_STATIC(y, 3, PS_TYPE_F64);
     931    PS_VECTOR_DECLARE_ALLOC_STATIC(yErr, 3, PS_TYPE_F64);
     932    static psPolynomial1D* myPoly = NULL;
     933
     934    if (myPoly == NULL) {
     935        myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
     936        p_psMemSetPersistent(myPoly, true);
     937    }
    1054938    float tmpFloat;
    1055939
     
    1090974    }
    1091975
    1092     psFree(x);
    1093     psFree(y);
    1094     psFree(yErr);
    1095     psFree(myPoly);
    1096976    return(tmpFloat);
    1097977}
     
    14751355
    14761356/******************************************************************************
    1477 psHistogramAllocGenric(bounds): allocate a non-uniform histogram structure
     1357psHistogramAllocGeneric(bounds): allocate a non-uniform histogram structure
    14781358with the specifed bounds.
    14791359 
Note: See TracChangeset for help on using the changeset viewer.