Changeset 18876 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Aug 3, 2008, 10:55:09 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r18493 r18876 13 13 * use ->min and ->max (PS_STAT_USE_RANGE) 14 14 * 15 * @version $Revision: 1.22 7$ $Name: not supported by cvs2svn $16 * @date $Date: 2008-0 7-12 21:08:14$15 * @version $Revision: 1.228 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2008-08-03 20:54:43 $ 17 17 * 18 18 * Copyright 2006 IfA, University of Hawaii … … 310 310 psF32 *input = inVector->data.F32; // Dereference the vector 311 311 312 // Allocate temporary vectors for the data. 313 psVector *outVector = psVectorAllocEmpty(inVector->n, PS_TYPE_F32); // Vector containing unmasked values 312 // use the temporary vector for the sorted output 313 stats->tmpData = psVectorRecycle (stats->tmpData, inVector->n, PS_TYPE_F32); 314 psVector *outVector = stats->tmpData; 314 315 psF32 *output = outVector->data.F32; // Dereference the vector 315 316 … … 333 334 if (count == 0) { 334 335 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "No valid data in input vector.\n"); 335 psFree(outVector);336 336 stats->sampleUQ = NAN; 337 337 stats->sampleLQ = NAN; … … 346 346 stats->sampleLQ = NAN; 347 347 stats->sampleMedian = NAN; 348 psFree(outVector);349 348 return false; 350 349 } … … 363 362 stats->results |= PS_STAT_SAMPLE_MEDIAN; 364 363 stats->results |= PS_STAT_SAMPLE_QUARTILE; 365 366 // Free the temporary data structures.367 psFree(outVector);368 364 369 365 // Return "true" on success. … … 584 580 // We copy the mask vector, to preserve the original 585 581 psMaskType maskVal = MASK_MARK | maskValInput; 586 psVector *tmpMask = psVectorAlloc(myVector->n, PS_TYPE_U8); 582 583 // use the temporary vector for local temporary mask 584 stats->tmpMask = psVectorRecycle (stats->tmpMask, myVector->n, PS_TYPE_U8); 585 psVector *tmpMask = stats->tmpMask; 587 586 psVectorInit(tmpMask, 0); 588 587 if (maskInput) { … … 599 598 psTrace(TRACE, 5, "Call to vectorSampleMedian returned NAN\n"); 600 599 psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__); 601 psFree(tmpMask);602 600 return false; 603 601 } … … 609 607 psTrace(TRACE, 5, "Call to vectorSampleStdev returned NAN\n"); 610 608 psTrace(TRACE, 4, "---- %s(false) end ----\n", __func__); 611 psFree(tmpMask);612 609 return false; 613 610 } … … 654 651 // b) compute new mean and stdev 655 652 // Allocate a psStats structure for calculating the mean and stdev. 656 psStats *statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 657 vectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp); 658 vectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp); 659 psTrace(TRACE, 6, "The new sample mean is %f\n", statsTmp->sampleMean); 660 psTrace(TRACE, 6, "The new sample stdev is %f\n", statsTmp->sampleStdev); 653 // XXX Can we just use this psStats structure to calculate the SAMPLE MEAN and STDEV? 654 // psStats *statsTmp = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 655 // vectorSampleMean(myVector, errors, tmpMask, maskVal, statsTmp); 656 // vectorSampleStdev(myVector, errors, tmpMask, maskVal, statsTmp); 657 vectorSampleMean(myVector, errors, tmpMask, maskVal, stats); 658 vectorSampleStdev(myVector, errors, tmpMask, maskVal, stats); 659 psTrace(TRACE, 6, "The new sample mean is %f\n", stats->sampleMean); 660 psTrace(TRACE, 6, "The new sample stdev is %f\n", stats->sampleStdev); 661 661 662 662 // If the new mean and stdev are NAN, we must exit the loop. 663 663 // Otherwise, use the new results and continue. 664 if (isnan(statsTmp->sampleMean) || isnan(statsTmp->sampleStdev)) { 665 // Exit loop. 664 if (isnan(stats->sampleMean) || isnan(stats->sampleStdev)) { 666 665 iter = stats->clipIter; 667 666 psError(PS_ERR_UNKNOWN, true, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n"); 668 psFree(tmpMask);669 667 return false; 670 668 } else { 671 clippedMean = stats Tmp->sampleMean;672 clippedStdev = stats Tmp->sampleStdev;673 } 674 psFree(statsTmp);669 clippedMean = stats->sampleMean; 670 clippedStdev = stats->sampleStdev; 671 } 672 // psFree(statsTmp); 675 673 } 676 674 … … 690 688 psTrace(TRACE, 6, "The final clipped stdev is %f\n", clippedStdev); 691 689 692 psFree(tmpMask);693 690 psTrace(TRACE, 4, "---- %s(true) end ----\n", __func__); 694 691 return true; … … 2139 2136 /*****************************************************************************/ 2140 2137 2141 // We keep statsFree so that we can identify statistics pointers from the memblock2138 // free function 2142 2139 static void statsFree(psStats *stats) 2143 2140 { 2144 // There are non dynamic allocated items 2141 if (!stats) return; 2142 psFree (stats->tmpData); 2143 psFree (stats->tmpMask); 2145 2144 return; 2146 2145 } … … 2165 2164 stats->nSubsample = 100000; 2166 2165 stats->options = options; 2166 stats->tmpData = NULL; 2167 stats->tmpMask = NULL; 2167 2168 2168 2169 psTrace(TRACE, 3, "---- %s() end ----\n", __func__);
Note:
See TracChangeset
for help on using the changeset viewer.
