IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18331


Ignore:
Timestamp:
Jun 26, 2008, 11:47:01 AM (18 years ago)
Author:
eugene
Message:

revert to 1.224 until PS_SELECT bug is fixed; (fixed return value)

File:
1 edited

Legend:

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

    r18312 r18331  
    77 *  on those data structures.
    88 *
    9  *  @author GLG (MHPCC), EAM (IfA), PAP (IfA)
     9 *  @author GLG (MHPCC), EAM (IfA)
    1010 *
    1111 * XXX: Must do
     
    1313 * use ->min and ->max (PS_STAT_USE_RANGE)
    1414 *
    15  *  @version $Revision: 1.225 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2008-06-24 21:58:57 $
     15 *  @version $Revision: 1.226 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2008-06-26 21:47:01 $
    1717 *
    1818 *  Copyright 2006 IfA, University of Hawaii
     
    340340    }
    341341
    342     // Using selection instead of sorting, because it's faster.  It does make the code a bit longer here tho.
    343     // Select in-place (since it's a copy, it's OK)
    344     if (!psVectorSelectInPlace(outVector, count/2)) {
     342    // Sort the temporary vector.
     343    if (!psVectorSort(outVector, outVector)) { // Sort in-place (since it's a copy, it's OK)
    345344        psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data."));
    346345        stats->sampleUQ = NAN;
     
    350349        return false;
    351350    }
    352     double median = output[count/2]; // Median value
    353 
     351
     352    // Calculate the median.  Use the average if the number of samples if even.
    354353    if (count % 2 == 0) {
    355         if (!psVectorSelectInPlace(outVector, count/2 - 1)) {
    356             psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data."));
    357             stats->sampleUQ = NAN;
    358             stats->sampleLQ = NAN;
    359             stats->sampleMedian = NAN;
    360             psFree(outVector);
    361             return false;
    362         }
    363         stats->sampleMedian = 0.5 * (output[count/2 - 1] + median);
     354        stats->sampleMedian = 0.5 * (output[(count/2) - 1] + output[count/2]);
    364355    } else {
    365         stats->sampleMedian = median;
    366     }
     356        stats->sampleMedian = output[count/2];
     357    }
     358
     359    // Calculate the quartile points exactly.
     360    stats->sampleUQ = output[(int)(0.75*count)];
     361    stats->sampleLQ = output[(int)(0.25*count)];
     362
    367363    stats->results |= PS_STAT_SAMPLE_MEDIAN;
    368 
    369     if (!psVectorSelectInPlace(outVector, 0.75 * count)) {
    370         psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data."));
    371         stats->sampleUQ = NAN;
    372         stats->sampleLQ = NAN;
    373         psFree(outVector);
    374         return false;
    375     }
    376     stats->sampleUQ = output[(int)(0.75*count)];
    377 
    378     if (!psVectorSelectInPlace(outVector, 0.25 * count)) {
    379         psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data."));
    380         stats->sampleLQ = NAN;
    381         psFree(outVector);
    382         return false;
    383     }
    384     stats->sampleLQ = output[(int)(0.25*count)];
    385 
    386364    stats->results |= PS_STAT_SAMPLE_QUARTILE;
    387365
Note: See TracChangeset for help on using the changeset viewer.