IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 1, 2004, 1:57:08 PM (22 years ago)
Author:
gusciora
Message:

Fixed the robust stats routines for stdev/mean. Fixed minimization routines
for fitting gaussians. CVS:


Enter Log. Lines beginning with `CVS:' are removed automatically CVS: CVS:
Committing in . CVS: CVS: Modified Files: CVS:
src/dataManip/psMinimize.c src/dataManip/psMinimize.h CVS:
src/dataManip/psStats.c src/dataManip/makedir/psMinimize.d CVS:
src/dataManip/makedir/psStats.d CVS: test/dataManip/tst_psMinimize07.c


File:
1 edited

Legend:

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

    r2228 r2250  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.80 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-28 22:46:57 $
     11 *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-11-01 23:57:08 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    790790    psFree(tmpMask);
    791791}
     792
     793void p_psNormalizeVectorF32_0(psVector* myData)
     794{
     795    float min = (float)HUGE;
     796    float max = (float)-HUGE;
     797    psS32 i = 0;
     798
     799    for (i = 0; i < myData->n; i++) {
     800        if (myData->data.F32[i] < min) {
     801            min = myData->data.F32[i];
     802        }
     803        if (myData->data.F32[i] > max) {
     804            max = myData->data.F32[i];
     805        }
     806    }
     807
     808    //  float range = max - min;
     809    //    for (i = 0; i < myData->n; i++) {
     810    //        myData->data.F32[i] = (myData->data.F32[i] - min) / range;
     811    //    }
     812    for (i = 0; i < myData->n; i++) {
     813        myData->data.F32[i] = (myData->data.F32[i] - min) / (max - min);
     814    }
     815}
     816
     817
    792818
    793819/*****************************************************************************
     
    11621188    myStdev = sqrt((sumSquares - (sumDiffs * sumDiffs / countFloat)) / (countFloat - 1));
    11631189
     1190
     1191    // Using the above (myMean, myStdev) as initial estimates, we fit a
     1192    // Gaussian to the robustHistogramVector.
     1193    psMinimization *min = psMinimizationAlloc(100, 0.1);
     1194    psVector *myParams = psVectorAlloc(2, PS_TYPE_F32);
     1195    psArray *myCoords = psArrayAlloc(robustHistogramVector->n);
     1196    psVector *y = psVectorAlloc(robustHistogramVector->n, PS_TYPE_F32);
     1197
     1198    p_psNormalizeVectorF32_0(robustHistogramVector);
     1199    for (i=0;i<robustHistogramVector->n;i++) {
     1200        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
     1201        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) i;
     1202        y->data.F32[i] = robustHistogramVector->data.F32[i];
     1203    }
     1204
     1205    myParams->data.F32[0] = myMean;
     1206    myParams->data.F32[1] = myStdev;
     1207    psMinimizeLMChi2(min,
     1208                     NULL,
     1209                     myParams,
     1210                     NULL,
     1211                     myCoords,
     1212                     y,
     1213                     NULL,
     1214                     (psMinimizeLMChi2Func) psMinimizeLMChi2Gauss1D);
     1215    psFree(min);
     1216    psFree(myParams);
     1217    psFree(myCoords);
     1218    psFree(y);
    11641219    /**************************************************************************
    11651220    Set the appropriate members in the output stats struct.
    11661221    **************************************************************************/
    11671222    if (stats->options & PS_STAT_ROBUST_MEAN) {
    1168         stats->robustMean = myMean;
     1223        if (fabs((myParams->data.F32[0] - myMean)/myMean) > 0.1) {
     1224            printf("WARNING: the fitted Gaussian has more than 10% error for the mean.\n");
     1225            printf("Using the calculated mean (calc, fit) is (%f, %f)\n", myMean, myParams->data.F32[0]);
     1226            stats->robustMean = myMean;
     1227        } else {
     1228            stats->robustMean = myParams->data.F32[0];
     1229        }
    11691230    }
    11701231
     
    11741235
    11751236    if (stats->options & PS_STAT_ROBUST_STDEV) {
    1176         stats->robustStdev = myStdev;
     1237        if (fabs((myParams->data.F32[1] - myStdev)/myStdev) > 0.1) {
     1238            printf("WARNING: the fitted Gaussian has more than 10% error for the stdev.\n");
     1239            printf("Using the calculated stdev (calc, fit) is (%f, %f)\n", myStdev, myParams->data.F32[1]);
     1240            stats->robustStdev = myStdev;
     1241        } else {
     1242            stats->robustStdev = myParams->data.F32[1];
     1243        }
    11771244    }
    11781245
Note: See TracChangeset for help on using the changeset viewer.