﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
338	multiple robust statistics prevent use	Paul Price	gusciora@…	"These were found during a walk through of the current CVS version of the code.
Sorry for filing bugs on code that is not officially released, but I'm finding
them and would prefer to note and track them.

--------------------------------------------------------------------------------
1. In several cases, ""stats"" is used where ""tmpStats"" should be:

    if (fabs(binSize) <= FLT_EPSILON) {
        if (stats->options & PS_STAT_ROBUST_MEAN) {
            stats->robustMean = stats->clippedMean;
        }

Should be: stats->robustMean = tmpStats->clippedMean;
(Similarly with following lines; 5 occurences total.)

Also:
    // Determine minimum and maximum values in the data vector.
    if (isnan(stats->min)) {
and
    if (isnan(stats->max)) {

should refer to ""tmpStats"" instead of ""stats"".

--------------------------------------------------------------------------------

2. The result of the minimisation is not checked.  In the event that the
minimisation fails, a warning should be generated.  This is a better check to
make than the difference from ""myMean"", since it is the result of the
minimisation that is the robust mean (not ""myMean"").  Similarly with the
standard deviation.

--------------------------------------------------------------------------------

3. The fitting should only be over the range: mode - dL --> mode + dL
but the current implementation attempts to fit the entire histogram.  This can
cause the minimisation to fail to converge (and take a long time doing so).

Current:
    p_psNormalizeVectorRangeF32(robustHistogramVector, 0.0, 1.0);
    for (i=0;i<robustHistogramVector->n;i++) {
        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
        ((psVector *) (myCoords->data[i]))->data.F32[0] = (psF32) i;
        y->data.F32[i] = robustHistogramVector->data.F32[i];
    }

I suggest: 

    psMinimization *min = psMinimizationAlloc(100, 0.01);
    psVector *myParams = psVectorAlloc(2, PS_TYPE_F32);
    psArray *myCoords = psArrayAlloc(2 * dL + 1);
    psVector *y = psVectorAlloc(2 * dL + 1, PS_TYPE_F32);

    p_psNormalizeVectorRangeF32(robustHistogramVector, 0.0, 1.0);
    for (i = modeBinNum - dL; i <= modeBinNum + dL; i++) {
	int index = i - modeBinNum + dL;
        myCoords->data[index] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
        ((psVector *) (myCoords->data[index]))->data.F32[0] =
PS_BIN_MIDPOINT(robustHistogram, i);
        y->data.F32[index] = robustHistogramVector->data.F32[i];
    }

--------------------------------------------------------------------------------

4. The ""myParams"" vector is freed immediately after the minimisation, but then
later used.

--------------------------------------------------------------------------------

5. Operations should only be performed if requested by the user.  For example,
if the user wants only the robust median, there is no need to do the
minimization to obtain the robust mean."	defect	closed	high		types	unspecified	major	duplicate		
