IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Fixed bugs reported in 316. Not tested yet.

File:
1 edited

Legend:

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

    r3349 r3350  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.115 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-03-01 21:03:25 $
     11 *  @version $Revision: 1.116 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-03-01 21:20:51 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    10031003    -2: warning
    10041004 
    1005 XXX: Create a new psStats object for the sample mean and sample stdev.
    1006  
    10071005XXX: Do we really need to calculate median and mean?
    10081006 
     
    10151013                             psStats* stats)
    10161014{
    1017     psS32 i = 0;                  // Loop index variable
    1018     psS32 j = 0;                  // Loop index variable
    10191015    psF32 clippedMean = 0.0;    // self-explanatory
    10201016    psF32 clippedStdev = 0.0;   // self-explanatory
    1021     psVector* tmpMask = NULL;   // Temporary vector
    1022     psStats *statsTmp = NULL;
     1017    psVector* tmpMask = NULL;   // Temporary vector for masks during iterations.
     1018    psStats *statsTmp = NULL;   // Temporary psStats struct.
     1019    psS32 rc = 0;               // Return code.
    10231020
    10241021    // Ensure that stats->clipIter is within the proper range.
     
    10321029                       PS_CLIPPED_SIGMA_UB, -1);
    10331030
     1031    // Allocate a psStats structure for calculating the mean, median, and
     1032    // stdev.
    10341033    if (statsTmp == NULL) {
    10351034        statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     
    10451044    // mask vector with those values.
    10461045    if (maskVector != NULL) {
    1047         for (i = 0; i < tmpMask->n; i++) {
     1046        for (psS32 i = 0; i < tmpMask->n; i++) {
    10481047            tmpMask->data.U8[i] = maskVector->data.U8[i];
    10491048        }
    10501049    }
     1050
    10511051    // 1. Compute the sample median.
    10521052    p_psVectorSampleMedian(myVector, maskVector, maskVal, statsTmp);
     
    10691069    // 3. Use the sample median as the first estimator of the mean X.
    10701070    clippedMean = statsTmp->sampleMean;
     1071
    10711072    // 4. Use the sample stdev as the first estimator of the mean stdev.
    10721073    clippedStdev = statsTmp->sampleStdev;
    10731074
    1074     // 5. Repeat N times:
    1075     for (i = 0; i < stats->clipIter; i++) {
     1075    // 5. Repeat N (stats->clipIter) times:
     1076    for (psS32 iter = 0; iter < stats->clipIter; iter++) {
    10761077        // a) Exclude all values x_i for which |x_i - x| > K * stdev
    10771078        if (errors != NULL) {
    1078             for (j = 0; j < myVector->n; j++) {
     1079            for (psS32 j = 0; j < myVector->n; j++) {
    10791080                if (fabs(myVector->data.F32[j] - clippedMean) >
    10801081                        (stats->clipSigma * errors->data.F32[j])) {
     
    10831084            }
    10841085        } else {
    1085             for (j = 0; j < myVector->n; j++) {
     1086            for (psS32 j = 0; j < myVector->n; j++) {
    10861087                if (fabs(myVector->data.F32[j] - clippedMean) >
    10871088                        (stats->clipSigma * clippedStdev)) {
     
    10951096        p_psVectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp);
    10961097
    1097         // If the new mean and stdev are not NAN, then we use them.
    1098         // Otherwise, keep the old ones, and exit the loop.
    1099         if (! (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev))) {
     1098        // If the new mean and stdev are NAN, we must exit the loop.
     1099        // Otherwise, use the new results and continue.
     1100        if (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev)) {
     1101            // Exit loop.  XXX: Should we throw an error or warning here?
     1102            iter = stats->clipIter;
     1103            rc = -1;
     1104        } else {
    11001105            clippedMean = statsTmp->sampleMean;
    11011106            clippedStdev = statsTmp->sampleStdev;
    1102         } else {
    1103             // Exit loop
    1104             // Should we throw an error or warning here?
    1105             i = stats->clipIter;
    11061107        }
    11071108    }
     
    11171118
    11181119    psFree(tmpMask);
    1119     return(0);
     1120    return(rc);
    11201121}
    11211122
Note: See TracChangeset for help on using the changeset viewer.