IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30075


Ignore:
Timestamp:
Dec 16, 2010, 6:10:00 PM (15 years ago)
Author:
eugene
Message:

handle bad data case when (eg) almost all data points are in a single bin (was failing on the edge case of the first bin)

File:
1 edited

Legend:

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

    r28998 r30075  
    827827        // values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
    828828        // bins of that excess bin:
    829         int nMaxBin = 0;
     829        int nMaxBin = histogram->nums->data.F32[0];
    830830        int iMaxBin = 0;
    831831        for (long i = 1; i < histogram->nums->n; i++) {
     
    843843                if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
    844844                bool invalid = false;
    845                 invalid |= (myVector->data.F32[i] <= minKeep);
    846                 invalid |= (myVector->data.F32[i] >= maxKeep);
     845                invalid |= (myVector->data.F32[i] < minKeep);
     846                invalid |= (myVector->data.F32[i] > maxKeep);
    847847                invalid |= (!isfinite(myVector->data.F32[i]));
    848848                if (!invalid) continue;
     
    852852
    853853            if (nInvalid) {
    854               psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
     854              psTrace(TRACE, 6, "data is concentrated in a single bin (%d = %f - %f), masking %d extreme outliers and retrying\n",
     855                      iMaxBin, histogram->bounds->data.F32[iMaxBin], histogram->bounds->data.F32[iMaxBin+1], nInvalid);
    855856              psFree(histogram);
    856857              psFree(cumulative);
     
    11081109    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    11091110    if (isnan(stats->robustMedian)) {
    1110         stats->fittedStdev = NAN;
    1111         stats->fittedStdev = NAN;
     1111        stats->fittedMean = NAN;
     1112        stats->fittedStdev = NAN;
     1113        stats->results |= PS_STAT_FITTED_MEAN;
     1114        stats->results |= PS_STAT_FITTED_STDEV;
     1115        return true;
     1116    }
     1117
     1118    if (stats->robustStdev <= FLT_EPSILON) {
     1119        stats->fittedMean = stats->robustMedian;
     1120        stats->fittedStdev = stats->robustStdev;
     1121        stats->results |= PS_STAT_FITTED_MEAN;
     1122        stats->results |= PS_STAT_FITTED_STDEV;
    11121123        return true;
    11131124    }
     
    12891300    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    12901301    if (isnan(stats->robustMedian)) {
    1291         stats->fittedStdev = NAN;
    1292         stats->fittedStdev = NAN;
    1293         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
     1302        stats->fittedMean = NAN;
     1303        stats->fittedStdev = NAN;
     1304        stats->results |= PS_STAT_FITTED_MEAN_V2;
     1305        stats->results |= PS_STAT_FITTED_STDEV_V2;
     1306        return true;
     1307    }
     1308
     1309    if (stats->robustStdev <= FLT_EPSILON) {
     1310        stats->fittedMean = stats->robustMedian;
     1311        stats->fittedStdev = stats->robustStdev;
     1312        stats->results |= PS_STAT_FITTED_MEAN_V2;
     1313        stats->results |= PS_STAT_FITTED_STDEV_V2;
    12941314        return true;
    12951315    }
     
    14861506    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    14871507    if (isnan(stats->robustMedian)) {
    1488         stats->fittedStdev = NAN;
    1489         stats->fittedStdev = NAN;
    1490         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
     1508        stats->fittedMean = NAN;
     1509        stats->fittedStdev = NAN;
     1510        stats->results |= PS_STAT_FITTED_MEAN_V3;
     1511        stats->results |= PS_STAT_FITTED_STDEV_V3;
     1512        return true;
     1513    }
     1514
     1515    if (stats->robustStdev <= FLT_EPSILON) {
     1516        stats->fittedMean = stats->robustMedian;
     1517        stats->fittedStdev = stats->robustStdev;
     1518        stats->results |= PS_STAT_FITTED_MEAN_V3;
     1519        stats->results |= PS_STAT_FITTED_STDEV_V3;
    14911520        return true;
    14921521    }
     
    17821811
    17831812    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    1784     if (isnan(stats->robustMedian)) goto escape;
     1813    if (isnan(stats->robustMedian)) {
     1814        stats->fittedMean = NAN;
     1815        stats->fittedStdev = NAN;
     1816        stats->results |= PS_STAT_FITTED_MEAN_V4;
     1817        stats->results |= PS_STAT_FITTED_STDEV_V4;
     1818        return true;
     1819    }
     1820
     1821    if (stats->robustStdev <= FLT_EPSILON) {
     1822        stats->fittedMean = stats->robustMedian;
     1823        stats->fittedStdev = stats->robustStdev;
     1824        stats->results |= PS_STAT_FITTED_MEAN_V4;
     1825        stats->results |= PS_STAT_FITTED_STDEV_V4;
     1826        return true;
     1827    }
    17851828
    17861829    float guessStdev = stats->robustStdev;  // pass the guess sigma
Note: See TracChangeset for help on using the changeset viewer.