IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23988


Ignore:
Timestamp:
Apr 28, 2009, 11:19:59 AM (17 years ago)
Author:
eugene
Message:
  • converted a few critical traces to logs
  • removed the excessive -- start-- and -- end -- trace messages
  • remove psError and return 'true' for all cases where the stats can be calculated, even if the result is a NAN value.
  • convert error messages in NAN cases to log messages.
  • ensure all functions check for a valid result (not-NAN) from preceding stages, and handle NAN results.
File:
1 edited

Legend:

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

    r23416 r23988  
    2424// unity, even though the standard deviation is not defined in that case (NAN).
    2525
     26// reworking the return values and failure conditions: it should only be an error if the
     27// inputs imply a programming error: eg, NULL data vectors, non-sensical input
     28// parameters.  If the statistic cannot be calculated (0 length vector, 0 range, no
     29// unmasked data values), the statistic should be reported as NAN, but an error should not
     30// be raised.  (TBD: do we need to have a unique field in psStats or a return parameter
     31// that can be checked for an invalid result?)
     32
    2633#ifdef HAVE_CONFIG_H
    27 # include "config.h"
     34#include "config.h"
    2835#endif
    2936
     
    4249#include "psMemory.h"
    4350#include "psAbort.h"
    44 //#include "psImage.h"
    4551#include "psVector.h"
    4652#include "psTrace.h"
     
    6975#define PS_POLY_MEDIAN_MAX_ITERATIONS 30
    7076
     77#define TRACE "psLib.math"
     78
    7179#define MASK_MARK 0x80   // XXX : can we change this? bit to use internally to mark data as bad
    7280#define PS_ROBUST_MAX_ITERATIONS 20     // Maximum number of iterations for robust statistics
     
    8795            break; \
    8896          case PS_BINARY_DISECT_OUTSIDE_RANGE: \
    89             psTrace ("psLib.math", 6, "selected bin outside range"); \
     97            psTrace(TRACE, 6, "selected bin outside range"); \
    9098            if (USE_END == -1) { RESULT = 0; } \
    9199            if (USE_END == +1) { RESULT = VECTOR->n - 1; } \
     
    116124        } \
    117125        Xt = PS_MIN (BOUNDS->data.F32[BIN+1], PS_MAX(BOUNDS->data.F32[BIN], Xt)); \
    118         psTrace("psLib.math", 6, "(Xo, Yo, dX, dY, Xt, Yt) is (%.2f %.2f %.2f %.2f %.2f %.2f)\n", \
     126        psTrace(TRACE, 6, "(Xo, Yo, dX, dY, Xt, Yt) is (%.2f %.2f %.2f %.2f %.2f %.2f)\n", \
    119127                Xo, Yo, dX, dY, Xt, VALUE); \
    120128        RESULT = Xt; }
    121 
    122 #define TRACE "psLib.math"
    123129
    124130/*****************************************************************************/
     
    182188                                 psStats* stats)
    183189{
    184     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    185 
    186190    long count = 0;                     // Number of points contributing to this mean
    187191    psF32 mean = 0.0;                   // The mean
     
    222226    }
    223227    stats->sampleMean = mean;
    224     if (isnan(mean)) {
    225         // XXX raise an error here?
    226         psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__);
    227         return true;
    228     }
    229 
    230     stats->results |= PS_STAT_SAMPLE_MEAN;
    231     psTrace(TRACE, 4, "---- %s(true) end ----\n", __func__);
     228
     229    if (!isnan(mean)) {
     230        stats->results |= PS_STAT_SAMPLE_MEAN;
     231    }
    232232    return true;
    233233}
     
    252252        )
    253253{
    254     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    255254    psF32 max = -PS_MAX_F32;            // The calculated maximum
    256255    psF32 min = PS_MAX_F32;             // The calculated minimum
     
    289288        stats->results |= PS_STAT_MAX;
    290289    }
    291     psTrace(TRACE, 4, "---- %s(%d) end ----\n", __func__, numValid);
    292290    return numValid;
    293291}
     
    303301                               psStats* stats)
    304302{
    305     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    306 
    307303    bool useRange = stats->options & PS_STAT_USE_RANGE;
    308304    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA; // Dereference the vector
     
    334330
    335331    if (count == 0) {
    336         psError(PS_ERR_BAD_PARAMETER_SIZE, true, "No valid data in input vector.\n");
     332        psLogMsg(TRACE, PS_LOG_DETAIL, "No valid data in input vector.\n");
    337333        stats->sampleUQ = NAN;
    338334        stats->sampleLQ = NAN;
     
    343339    // Sort the temporary vector.
    344340    if (!psVectorSort(outVector, outVector)) { // Sort in-place (since it's a copy, it's OK)
     341        // an error in psVectorSort is a serious error
    345342        psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data."));
    346343        stats->sampleUQ = NAN;
     
    364361    stats->results |= PS_STAT_SAMPLE_QUARTILE;
    365362
    366     // Return "true" on success.
    367     psTrace(TRACE, 4, "---- %s(true) end ----\n", __func__);
    368363    return true;
    369364}
     
    390385                              psStats* stats)
    391386{
    392     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    393 
    394387    // This procedure requires the mean.  If it has not been already
    395388    // calculated, then call vectorSampleMean()
     
    400393    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    401394    if (isnan(stats->sampleMean)) {
    402         psTrace(TRACE, 5, "WARNING: vectorSampleStdev(): sample mean is NAN.  "
    403                 "Setting stats->sampleStdev = NAN.\n");
     395        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): sample mean is NAN. Setting stats->sampleStdev = NAN.\n");
    404396        stats->sampleStdev = NAN;
    405397        return true;
     
    445437        // Assume that the user knows what he's doing when he masks out everything --> no error.
    446438        stats->sampleStdev = NAN;
    447         psTrace(TRACE, 5, "WARNING: vectorSampleStdev(): no valid psVector elements (%ld).  "
    448                 "Setting stats->sampleStdev = NAN.\n", count);
     439        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): no valid psVector elements (%ld). Setting stats->sampleStdev = NAN.\n", count);
    449440        return true;
    450441    }
    451442    if (count == 1) {
    452443        stats->sampleStdev = 0.0;
    453         psTrace(TRACE, 5, "WARNING: vectorSampleStdev(): only one valid psVector elements (%ld).  "
     444        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): only one valid psVector elements (%ld).  "
    454445                "Setting stats->sampleStdev = 0.0.\n", count);
    455446        return true;
     
    462453    }
    463454    stats->results |= PS_STAT_SAMPLE_STDEV;
    464 
    465     psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
    466455
    467456    return true;
     
    473462                                psStats* stats)
    474463{
    475     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    476 
    477464    // This procedure requires the mean and standard deviation
    478465    if (!(stats->results & PS_STAT_SAMPLE_MEAN)) {
     
    480467    }
    481468    if (isnan(stats->sampleMean)) {
    482         psTrace(TRACE, 5, "WARNING: vectorSampleMoments(): sample mean is NAN.\n");
     469        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleMoments(): sample mean is NAN.\n");
    483470        goto SAMPLE_MOMENTS_BAD;
    484471    }
     
    487474    }
    488475    if (isnan(stats->sampleStdev) || stats->sampleStdev == 0.0) {
    489         psTrace(TRACE, 5, "WARNING: vectorSampleMoments(): sample stdev is NAN or 0.\n");
     476        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleMoments(): sample stdev is NAN or 0.\n");
    490477        goto SAMPLE_MOMENTS_BAD;
    491478    }
     
    534521    stats->results |= PS_STAT_SAMPLE_SKEWNESS | PS_STAT_SAMPLE_KURTOSIS;
    535522
    536     psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
    537 
    538523    return true;
    539524
     
    542527    stats->sampleSkewness = NAN;
    543528    stats->sampleKurtosis = NAN;
    544     stats->results |= PS_STAT_SAMPLE_SKEWNESS | PS_STAT_SAMPLE_KURTOSIS;
    545529    return true;
    546530}
     
    565549    )
    566550{
    567     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    568     psTrace(TRACE, 4, "Trace level is %d\n", psTraceGetLevel("psLib.math"));
    569 
    570551    // Ensure that stats->clipIter is within the proper range.
    571552    PS_ASSERT_INT_WITHIN_RANGE(stats->clipIter,
     
    601582    vectorSampleMedian(myVector, tmpMask, maskVal, stats);
    602583    if (isnan(stats->sampleMedian)) {
    603         psTrace(TRACE, 5, "Call to vectorSampleMedian returned NAN\n");
    604         psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__);
    605         return false;
     584        psLogMsg(TRACE, PS_LOG_DETAIL, "Call to vectorSampleMedian returned NAN\n");
     585        return true;
    606586    }
    607587    psTrace(TRACE, 6, "The initial sample median is %f\n", stats->sampleMedian);
     
    610590    vectorSampleStdev(myVector, errors, tmpMask, maskVal, stats);
    611591    if (isnan(stats->sampleStdev)) {
    612         psTrace(TRACE, 5, "Call to vectorSampleStdev returned NAN\n");
    613         psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__);
    614         return false;
     592        psLogMsg(TRACE, PS_LOG_DETAIL, "Call to vectorSampleStdev returned NAN\n");
     593        return true;
    615594    }
    616595    psTrace(TRACE, 6, "The initial sample stdev is %f\n", stats->sampleStdev);
     
    669648        if (isnan(stats->sampleMean) || isnan(stats->sampleStdev)) {
    670649            iter = stats->clipIter;
    671             psError(PS_ERR_UNKNOWN, true, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
    672             return false;
     650            psLogMsg(TRACE, PS_LOG_DETAIL, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
     651            clippedMean = NAN;
     652            clippedStdev = NAN;
     653            return true;
    673654        } else {
    674655            clippedMean = stats->sampleMean;
     
    693674    psTrace(TRACE, 6, "The final clipped stdev is %f\n", clippedStdev);
    694675
    695     psTrace(TRACE, 4, "---- %s(true) end ----\n", __func__);
    696676    return true;
    697677}
     
    722702                              psStats* stats)
    723703{
    724     psTrace(TRACE, 4, "---- %s() begin ----\n", __func__);
    725704    if (psTraceGetLevel("psLib.math") >= 8) {
    726705        PS_VECTOR_PRINT_F32(myVector);
     
    767746        if (numValid == 0 || isnan(min) || isnan(max)) {
    768747            // Data range calculation failed
    769             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     748            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
    770749            goto escape;
    771750        }
     
    779758            stats->robustLQ = min;
    780759            stats->robustN50 = numValid;
     760            // XXX this is sort of an invalid / out-of-bounds result: to set or not to set these bits:
    781761            stats->results |= PS_STAT_ROBUST_MEDIAN;
    782762            stats->results |= PS_STAT_ROBUST_STDEV;
    783763            stats->results |= PS_STAT_ROBUST_QUARTILE;
    784             psTrace(TRACE, 5, "All data points have the same value: %f.\n", min);
    785             psTrace(TRACE, 4, "---- %s(0) end  ----\n", __func__);
     764            psLogMsg(TRACE, PS_LOG_DETAIL, "All data points have the same value: %f.\n", min);
    786765            psFree(mask);
    787766            psFree(statsMinMax);
     
    809788        // XXXXX we need to consider this step if errors -> variance
    810789        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
     790            // if psVectorHistogram returns false, we have a programming error
    811791            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for robust statistics.\n");
    812             goto escape;
     792            psFree(histogram);
     793            psFree(cumulative);
     794            psFree(statsMinMax);
     795            psFree(mask);
     796
     797            return false;
    813798        }
    814799        if (psTraceGetLevel("psLib.math") >= 8) {
     
    843828        stats->robustMedian = fitQuadraticSearchForYThenReturnXusingValues(cumulative->bounds, cumulative->nums, binMedian, totalDataPoints/2.0);
    844829        if (isnan(stats->robustMedian)) {
    845             psError(PS_ERR_UNKNOWN, false,
    846                     "Failed to fit a quadratic and calculate the 50-percent position.\n");
     830            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a quadratic and calculate the 50-percent position.\n");
    847831            goto escape;
    848832        }
     
    866850
    867851        if ((binLo < 0) || (binHi < 0)) {
    868             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the 15.8655%% and 84.1345%% data points.\n");
     852            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the 15.8655%% and 84.1345%% data points.\n");
    869853            goto escape;
    870854        }
     
    962946                stats->results |= PS_STAT_ROBUST_STDEV;
    963947                stats->results |= PS_STAT_ROBUST_QUARTILE;
    964                 psTrace(TRACE, 5, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
    965                 psTrace(TRACE, 4, "---- %s(0) end  ----\n", __func__);
     948                psLogMsg(TRACE, PS_LOG_DETAIL, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
    966949                psFree(mask);
    967950                psFree(statsMinMax);
    968                 return false;
     951                return true;
    969952            }
    970953        } else {
     
    991974    psF32 binHi25F32 = fitQuadraticSearchForYThenReturnXusingValues(cumulative->bounds, cumulative->nums, binHi25, totalDataPoints * 0.75f);
    992975    if (isnan(binLo25F32) || isnan(binHi25F32)) {
    993         psError(PS_ERR_UNKNOWN, false,
    994                 "could not determine the robustUQ: fitQuadraticSearchForYThenReturnX() returned a NAN.\n");
     976        psLogMsg(TRACE, PS_LOG_DETAIL, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnX() returned a NAN.\n");
    995977        goto escape;
    996978    }
     
    10201002    stats->results |= PS_STAT_ROBUST_QUARTILE;
    10211003
    1022     psTrace(TRACE, 4, "---- %s(0) end  ----\n", __func__);
    10231004    return true;
    10241005
     
    10331014    stats->results |= PS_STAT_ROBUST_QUARTILE;
    10341015
    1035     psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1036 
    10371016    psFree(histogram);
    10381017    psFree(cumulative);
     
    10401019    psFree(mask);
    10411020
    1042     return false;
     1021    return true;
    10431022}
    10441023
     
    10571036    // calculated, then call vectorSampleMean()
    10581037    if (!(stats->results & PS_STAT_ROBUST_MEDIAN)) {
    1059         vectorRobustStats(myVector, errors, mask, maskVal, stats);
     1038        if (!vectorRobustStats(myVector, errors, mask, maskVal, stats)) {
     1039            psError(PS_ERR_UNKNOWN, false, "failure to measure robust stats\n");
     1040            return false;
     1041        }
    10601042    }
    10611043
     
    10641046        stats->fittedStdev = NAN;
    10651047        stats->fittedStdev = NAN;
    1066         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
    1067         return false;
     1048        return true;
    10681049    }
    10691050
     
    10961077        float max = statsMinMax->max;
    10971078        if (numValid == 0 || isnan(min) || isnan(max)) {
    1098             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1079            psTrace(TRACE, 5, "Failed to calculate the min/max of the input vector.\n");
    10991080            psFree(statsMinMax);
    1100             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1101             return false;
     1081            return true;
    11021082        }
    11031083
     
    11111091        psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
    11121092        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
     1093            // if psVectorHistogram returns false, we have a programming error
    11131094            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for fitted statistics.\n");
    11141095            psFree(histogram);
     
    11751156            PS_VECTOR_PRINT_F32(y);
    11761157        }
     1158       
     1159        // psMinimizeLMChi2 can return false for bad data as well as for serious failures
    11771160        if (!psMinimizeLMChi2(minimizer, NULL, params, NULL, x, y, NULL, minimizeLMChi2Gauss1D)) {
    11781161            psError(PS_ERR_UNKNOWN, false, "Failed to fit a gaussian to the robust histogram.\n");
     
    11831166            psFree(histogram);
    11841167            psFree(statsMinMax);
    1185             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1186             return false;
     1168            return true;
    11871169        }
    11881170        if (psTraceGetLevel("psLib.math") >= 8) {
     
    12351217    // calculated, then call vectorSampleMean()
    12361218    if (!(stats->results & PS_STAT_ROBUST_MEDIAN)) {
    1237         vectorRobustStats(myVector, errors, mask, maskVal, stats);
     1219        if (!vectorRobustStats(myVector, errors, mask, maskVal, stats)) {
     1220            psError(PS_ERR_UNKNOWN, false, "failure to measure robust stats\n");
     1221            return false;
     1222        }
    12381223    }
    12391224
     
    12431228        stats->fittedStdev = NAN;
    12441229        psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
    1245         return false;
     1230        return true;
    12461231    }
    12471232
     
    12741259        float max = statsMinMax->max;
    12751260        if (numValid == 0 || isnan(min) || isnan(max)) {
    1276             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1261            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
    12771262            psFree(statsMinMax);
    12781263            psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1279             return false;
     1264            return true;
    12801265        }
    12811266
     
    13541339        // psVectorInit (fitMask, 0);
    13551340
     1341        // XXX not sure if these should result in errors or not...
    13561342        if (!psVectorFitPolynomial1D (poly, NULL, 0, y, NULL, x)) {
    13571343            psError(PS_ERR_UNKNOWN, false, "Failed to fit a gaussian to the robust histogram.\n");
     
    13661352
    13671353        if (poly->coeff[2] >= 0.0) {
    1368             psTrace(TRACE, 6, "Parabolic fit results: %f + %f x + %f x^2\n",
    1369                     poly->coeff[0], poly->coeff[1], poly->coeff[2]);
     1354            psTrace(TRACE, 6, "Parabolic fit results: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
    13701355            psError(PS_ERR_UNKNOWN, false, "fit did not converge\n");
    13711356            psFree(x);
     
    14291414    // calculated, then call vectorSampleMean()
    14301415    if (!(stats->results & PS_STAT_ROBUST_MEDIAN)) {
    1431         vectorRobustStats(myVector, errors, mask, maskVal, stats);
     1416        if (!vectorRobustStats(myVector, errors, mask, maskVal, stats)) {
     1417            psError(PS_ERR_UNKNOWN, false, "failure to measure robust stats\n");
     1418            return false;
     1419        }
    14321420    }
    14331421
     
    14371425        stats->fittedStdev = NAN;
    14381426        psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
    1439         return false;
     1427        return true;
    14401428    }
    14411429
     
    14681456        float max = statsMinMax->max;
    14691457        if (numValid == 0 || isnan(min) || isnan(max)) {
    1470             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1458            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
    14711459            psFree(statsMinMax);
    14721460            psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1473             return false;
     1461            return true;
    14741462        }
    14751463
     
    15161504        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
    15171505        if (binMin == binMax) {
    1518             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1506            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
    15191507            psFree(statsMinMax);
    1520             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1521             return false;
     1508            return true;
    15221509        }
    15231510
     
    17241711    // calculated, then call vectorSampleMean()
    17251712    if (!(stats->results & PS_STAT_ROBUST_MEDIAN)) {
    1726         vectorRobustStats(myVector, errors, mask, maskVal, stats);
     1713        if (!vectorRobustStats(myVector, errors, mask, maskVal, stats)) {
     1714            psError(PS_ERR_UNKNOWN, false, "failure to measure robust stats\n");
     1715            return false;
     1716        }
    17271717    }
    17281718
     
    17311721        stats->fittedStdev = NAN;
    17321722        stats->fittedStdev = NAN;
    1733         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
    1734         return false;
     1723        return true;
    17351724    }
    17361725
     
    17631752        float max = statsMinMax->max;
    17641753        if (numValid == 0 || isnan(min) || isnan(max)) {
    1765             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1754            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
    17661755            psFree(statsMinMax);
    1767             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1768             return false;
     1756            stats->fittedStdev = NAN;
     1757            stats->fittedStdev = NAN;
     1758            return true;
    17691759        }
    17701760
     
    17801770        psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
    17811771        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
    1782             psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram for fitted statistics v4.\n");
     1772            psLogMsg(TRACE, PS_LOG_DETAIL, "Unable to generate histogram for fitted statistics v4.\n");
    17831773            psFree(histogram);
    17841774            psFree(statsMinMax);
    1785             return false;
     1775            stats->fittedStdev = NAN;
     1776            stats->fittedStdev = NAN;
     1777            return true;
    17861778        }
    17871779        if (psTraceGetLevel("psLib.math") >= 8) {
     
    18131805        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
    18141806        if (binMin == binMax) {
    1815             psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n");
     1807            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
    18161808            psFree(statsMinMax);
    1817             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1818             return false;
     1809            stats->fittedStdev = NAN;
     1810            stats->fittedStdev = NAN;
     1811            return true;
    18191812        }
    18201813
     
    18771870
    18781871            // fit 2nd order polynomial to ln(y) = -(x-xo)^2/2sigma^2
     1872            // XXX this fit may fail with an error for an ill-conditioned matrix (bad data)
     1873            // we probably should be able to handle the data errors gracefully
    18791874            psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 2);
    18801875            bool status = psVectorFitPolynomial1D (poly, NULL, 0, y, NULL, x);
     
    18831878
    18841879            if (!status) {
    1885                 psError(PS_ERR_UNKNOWN, false, "Failed to fit a gaussian to the robust histogram.\n");
     1880                psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a gaussian to the robust histogram.\n");
    18861881                psFree(poly);
    18871882                psFree(histogram);
    18881883                psFree(statsMinMax);
    1889                 psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1890                 return false;
     1884                stats->fittedStdev = NAN;
     1885                stats->fittedStdev = NAN;
     1886                return true;
    18911887            }
    18921888
    18931889            if (poly->coeff[2] >= 0.0) {
    1894                 psTrace(TRACE, 6, "Failed parabolic fit: %f + %f x + %f x^2\n",
    1895                         poly->coeff[0], poly->coeff[1], poly->coeff[2]);
     1890                psLogMsg(TRACE, PS_LOG_MINUTIA, "Failed parabolic fit: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
    18961891                psFree(poly);
    18971892                psFree(histogram);
     
    19071902                }
    19081903
    1909                 psError(PS_ERR_UNKNOWN, false, "fit did not converge\n");
    1910                 psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1911                 return false;
     1904                psLogMsg(TRACE, PS_LOG_DETAIL, "fit did not converge\n");
     1905                stats->fittedStdev = NAN;
     1906                stats->fittedStdev = NAN;
     1907                return true;
    19121908            }
    19131909
     
    19751971
    19761972            if (!status) {
    1977                 psError(PS_ERR_UNKNOWN, false, "Failed to fit a gaussian to the robust histogram.\n");
     1973                psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a gaussian to the robust histogram.\n");
    19781974                psFree(poly);
    19791975                psFree(histogram);
    19801976                psFree(statsMinMax);
    1981                 psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
    1982                 return false;
     1977                stats->fittedStdev = NAN;
     1978                stats->fittedStdev = NAN;
     1979                return true;
    19831980            }
    19841981
     
    21552152psStats* p_psStatsAlloc(const char *file, unsigned int lineno, const char *func, psStatsOptions options)
    21562153{
    2157     psTrace(TRACE, 3,"---- %s() begin  ----\n", __func__);
    2158 
    21592154    psStats *stats = p_psAlloc(file, lineno, func, sizeof(psStats));
    21602155    psMemSetDeallocator(stats, (psFreeFunc)statsFree);
     
    21722167    stats->tmpMask = NULL;
    21732168
    2174     psTrace(TRACE, 3, "---- %s() end  ----\n", __func__);
    21752169    return stats;
    21762170}
     
    22312225                   psVectorMaskType maskVal)
    22322226{
    2233     psTrace(TRACE, 3,"---- %s() begin  ----\n", __func__);
    22342227    PS_ASSERT_PTR_NON_NULL(stats, false);
    22352228    PS_ASSERT_VECTOR_NON_NULL(in, false);
     
    23802373    psFree(errorsF32);
    23812374    psFree(maskVector);
    2382     psTrace(TRACE, 3,"---- %s() end  ----\n", __func__);
    23832375    return status;
    23842376}
Note: See TracChangeset for help on using the changeset viewer.