IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 1, 2005, 11:03:25 AM (21 years ago)
Author:
gusciora
Message:

Fixing bugs from 316. Not tested yet.

File:
1 edited

Legend:

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

    r3348 r3349  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.114 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-03-01 21:02:21 $
     11 *  @version $Revision: 1.115 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-03-01 21:03:25 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    10021002    -1: error
    10031003    -2: warning
     1004 
     1005XXX: Create a new psStats object for the sample mean and sample stdev.
     1006 
     1007XXX: Do we really need to calculate median and mean?
     1008 
     1009XXX: Use static vectors for tmpMask.
    10041010 *****************************************************************************/
    10051011psS32 p_psVectorClippedStats(const psVector* myVector,
     
    10131019    psF32 clippedMean = 0.0;    // self-explanatory
    10141020    psF32 clippedStdev = 0.0;   // self-explanatory
    1015     psF32 oldStanMean = 0.0;    // Temporary variable
    1016     psF32 oldStanStdev = 0.0;   // Temporary variable
    10171021    psVector* tmpMask = NULL;   // Temporary vector
     1022    psStats *statsTmp = NULL;
    10181023
    10191024    // Ensure that stats->clipIter is within the proper range.
     
    10261031                       PS_CLIPPED_SIGMA_LB,
    10271032                       PS_CLIPPED_SIGMA_UB, -1);
     1033
     1034    if (statsTmp == NULL) {
     1035        statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     1036        p_psMemSetPersistent(statsTmp, true);
     1037    }
    10281038
    10291039    // We allocate a temporary mask vector since during the iterative
     
    10401050    }
    10411051    // 1. Compute the sample median.
    1042     p_psVectorSampleMedian(myVector, maskVector, maskVal, stats);
    1043     if (isnan(stats->sampleMedian)) {
     1052    p_psVectorSampleMedian(myVector, maskVector, maskVal, statsTmp);
     1053    if (isnan(statsTmp->sampleMedian)) {
    10441054        psLogMsg(__func__, PS_LOG_WARN, "Call to p_psVectorSampleMedian returned NAN\n");
    10451055        stats->clippedMean = NAN;
     
    10491059
    10501060    // 2. Compute the sample standard deviation.
    1051     p_psVectorSampleStdev(myVector, errors, maskVector, maskVal, stats);
    1052     if (isnan(stats->sampleStdev)) {
     1061    p_psVectorSampleStdev(myVector, errors, maskVector, maskVal, statsTmp);
     1062    if (isnan(statsTmp->sampleStdev)) {
    10531063        psLogMsg(__func__, PS_LOG_WARN, "Call to p_psVectorSampleStdev returned NAN\n");
    10541064        stats->clippedMean = NAN;
     
    10581068
    10591069    // 3. Use the sample median as the first estimator of the mean X.
    1060     clippedMean = stats->sampleMean;
    1061 
     1070    clippedMean = statsTmp->sampleMean;
    10621071    // 4. Use the sample stdev as the first estimator of the mean stdev.
    1063     clippedStdev = stats->sampleStdev;
    1064 
    1065     // Must save the old sampleMean and sampleStdev since the following code
    1066     // block overwrites them.
    1067     oldStanMean = stats->sampleMean;
    1068     oldStanStdev = stats->sampleStdev;
     1072    clippedStdev = statsTmp->sampleStdev;
    10691073
    10701074    // 5. Repeat N times:
     
    10731077        if (errors != NULL) {
    10741078            for (j = 0; j < myVector->n; j++) {
    1075                 if (fabs(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * errors->data.F32[j])) {
    1076                     tmpMask->data.U8[i] = 0xff;
     1079                if (fabs(myVector->data.F32[j] - clippedMean) >
     1080                        (stats->clipSigma * errors->data.F32[j])) {
     1081                    tmpMask->data.U8[j] = 0xff;
    10771082                }
    10781083            }
    10791084        } else {
    10801085            for (j = 0; j < myVector->n; j++) {
    1081                 if (fabs(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * clippedStdev)) {
    1082                     tmpMask->data.U8[i] = 0xff;
     1086                if (fabs(myVector->data.F32[j] - clippedMean) >
     1087                        (stats->clipSigma * clippedStdev)) {
     1088                    tmpMask->data.U8[j] = 0xff;
    10831089                }
    10841090            }
     
    10861092
    10871093        // b) compute new mean and stdev
    1088         p_psVectorSampleMean(myVector, errors, tmpMask, maskVal, stats);
    1089         p_psVectorSampleStdev(myVector, errors, tmpMask, maskVal, stats);
     1094        p_psVectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp);
     1095        p_psVectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp);
    10901096
    10911097        // If the new mean and stdev are not NAN, then we use them.
    10921098        // Otherwise, keep the old ones, and exit the loop.
    1093         if (! (isnan(stats->sampleMean) || isnan(stats->sampleStdev))) {
    1094             clippedMean = stats->sampleMean;
    1095             clippedStdev = stats->sampleStdev;
    1096 
     1099        if (! (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev))) {
     1100            clippedMean = statsTmp->sampleMean;
     1101            clippedStdev = statsTmp->sampleStdev;
     1102        } else {
    10971103            // Exit loop
     1104            // Should we throw an error or warning here?
    10981105            i = stats->clipIter;
    10991106        }
    11001107    }
    1101 
    1102     stats->sampleMean = oldStanMean;
    1103     stats->sampleStdev = oldStanStdev;
    11041108
    11051109    // 7. The last calcuated value of x is the cliped mean.
     
    22402244    // XXX: Different conditions for return -1 and -2?
    22412245    if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) {
    2242         if (-1 >  p_psVectorClippedStats(inF32, errorsF32, mask, maskVal, stats)) {
     2246        psS32 rc = p_psVectorClippedStats(inF32, errorsF32, mask, maskVal, stats);
     2247        if (-1 == rc) {
    22432248            psError(PS_ERR_UNKNOWN, false,
    22442249                    "Failed to calculate clipped statistics for input psVector.\n");
    22452250            stats->clippedMean = NAN;
    22462251            stats->clippedStdev = NAN;
    2247         } else if (-2 == p_psVectorClippedStats(inF32, errorsF32, mask, maskVal, stats)) {
     2252        } else if (-2 == rc) {
    22482253            psLogMsg(__func__, PS_LOG_WARN, "Failed to calculate clipped statistics for input psVector.");
    22492254            stats->clippedMean = NAN;
Note: See TracChangeset for help on using the changeset viewer.