Changeset 18331 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Jun 26, 2008, 11:47:01 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r18312 r18331 7 7 * on those data structures. 8 8 * 9 * @author GLG (MHPCC), EAM (IfA) , PAP (IfA)9 * @author GLG (MHPCC), EAM (IfA) 10 10 * 11 11 * XXX: Must do … … 13 13 * use ->min and ->max (PS_STAT_USE_RANGE) 14 14 * 15 * @version $Revision: 1.22 5$ $Name: not supported by cvs2svn $16 * @date $Date: 2008-06-2 4 21:58:57$15 * @version $Revision: 1.226 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2008-06-26 21:47:01 $ 17 17 * 18 18 * Copyright 2006 IfA, University of Hawaii … … 340 340 } 341 341 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) 345 344 psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data.")); 346 345 stats->sampleUQ = NAN; … … 350 349 return false; 351 350 } 352 double median = output[count/2]; // Median value 353 351 352 // Calculate the median. Use the average if the number of samples if even. 354 353 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]); 364 355 } 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 367 363 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 386 364 stats->results |= PS_STAT_SAMPLE_QUARTILE; 387 365
Note:
See TracChangeset
for help on using the changeset viewer.
