Changeset 18312
- Timestamp:
- Jun 24, 2008, 11:58:57 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
r18155 r18312 7 7 * on those data structures. 8 8 * 9 * @author GLG (MHPCC), EAM (IfA) 9 * @author GLG (MHPCC), EAM (IfA), PAP (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 4$ $Name: not supported by cvs2svn $16 * @date $Date: 2008-06- 17 02:26:34$15 * @version $Revision: 1.225 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2008-06-24 21:58:57 $ 17 17 * 18 18 * Copyright 2006 IfA, University of Hawaii … … 340 340 } 341 341 342 // Sort the temporary vector. 343 if (!psVectorSort(outVector, outVector)) { // Sort in-place (since it's a copy, it's OK) 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)) { 344 345 psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data.")); 345 346 stats->sampleUQ = NAN; … … 347 348 stats->sampleMedian = NAN; 348 349 psFree(outVector); 349 return true;350 } 351 352 // Calculate the median. Use the average if the number of samples if even. 350 return false; 351 } 352 double median = output[count/2]; // Median value 353 353 354 if (count % 2 == 0) { 354 stats->sampleMedian = 0.5 * (output[(count/2) - 1] + output[count/2]); 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); 355 364 } else { 356 stats->sampleMedian = output[count/2]; 357 } 358 359 // Calculate the quartile points exactly. 365 stats->sampleMedian = median; 366 } 367 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 } 360 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 } 361 384 stats->sampleLQ = output[(int)(0.25*count)]; 362 385 363 stats->results |= PS_STAT_SAMPLE_MEDIAN;364 386 stats->results |= PS_STAT_SAMPLE_QUARTILE; 365 387
Note:
See TracChangeset
for help on using the changeset viewer.
