Changeset 6304 for trunk/psLib/test/math/tst_psStats07.c
- Timestamp:
- Feb 2, 2006, 11:06:10 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tst_psStats07.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psStats07.c
r6215 r6304 13 13 #include <math.h> 14 14 15 #define N 9015 #define NUM_DATA 10000 16 16 #define MEAN 32.0 17 17 #define STDEV 2.0 18 18 #define ERROR_TOLERANCE 0.15 19 #define PERCENT_OUTLIERS 10 19 20 20 21 psS32 t00() … … 27 28 psVector *myVector = NULL; 28 29 psVector *maskVector = NULL; 29 // NOTE: These values were calculated by running the function on the data.30 // They must be changed if we adjust the number of data points.31 // We don't really know that they are correct.32 30 psS32 count = 0; 33 31 psS32 currentId = psMemGetId(); … … 35 33 float realMeanNoMask = MEAN; 36 34 float realMedianNoMask = MEAN; 37 // float realModeNoMask = MEAN;38 35 float realStdevNoMask = STDEV; 39 36 float realLQNoMask = MEAN - ( 0.6 * STDEV ); 40 37 float realUQNoMask = MEAN + ( 0.6 * STDEV ); 41 psS32 realN50NoMask = N / 4;38 psS32 realN50NoMask = NUM_DATA / 4; 42 39 43 40 /*************************************************************************/ 44 41 /* Allocate and initialize data structures */ 45 42 /*************************************************************************/ 46 maskVector = psVectorAlloc( N , PS_TYPE_U8 );47 maskVector->n = N ;48 myVector = p_psGaussianDev( MEAN, STDEV, N );43 maskVector = psVectorAlloc( NUM_DATA, PS_TYPE_U8 ); 44 maskVector->n = NUM_DATA; 45 myVector = p_psGaussianDev( MEAN, STDEV, NUM_DATA ); 49 46 // Set the mask vector and calculate the expected maximum. 50 for ( i = 0;i < N ;i++ ) {51 if ( i < ( N / 2 ) ) {47 for ( i = 0;i < NUM_DATA;i++ ) { 48 if ( i < ( NUM_DATA / 2 ) ) { 52 49 maskVector->data.U8[ i ] = 0; 53 50 count++; … … 56 53 } 57 54 } 55 56 // 57 // We calculate the exact mean, median, stdev and quartiles with no mask. 58 // 58 59 psStats *mySampleStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN | 59 60 PS_STAT_SAMPLE_MEDIAN | … … 67 68 psFree(mySampleStats); 68 69 70 // 71 // We calculate the exact mean, median, stdev and quartiles with mask. 72 // 69 73 psStats *mySampleStatsWithMask = psStatsAlloc( PS_STAT_SAMPLE_MEAN | 70 74 PS_STAT_SAMPLE_MEDIAN | … … 84 88 PS_STAT_FITTED_STDEV); 85 89 // Create a full outliers: 86 myVector->data.F32[N/4] = -1000.0 * MEAN; 87 myVector->data.F32[N/2] = 1000.0 * MEAN; 90 for (psS32 i = 0 ; i < NUM_DATA ; i++) { 91 if (PERCENT_OUTLIERS > (random() % 100)) { 92 myVector->data.F32[i] = 1000.0 * MEAN; 93 } 94 } 88 95 /*************************************************************************/ 89 96 /* Call psVectorStats() with no vector mask. */ … … 130 137 "PS_STAT_ROBUST_STATS: robust Median: no vector mask", 131 138 testStatus ); 132 133 /* XXX: Should we test mode?134 printPositiveTestHeader( stdout,135 "psStats functions",136 "PS_STAT_ROBUST_STATS: robust Mode: no vector mask" );137 138 139 printf( "The expected Mode was %.2f; the calculated Mode was %.2f\n",140 realModeNoMask, myStats->robustMode );141 if ( fabs( myStats->robustMode - realModeNoMask ) < ( ERROR_TOLERANCE * realModeNoMask ) ) {142 testStatus = true;143 } else {144 testStatus = false;145 globalTestStatus = false;146 }147 printFooter( stdout,148 "psVector functions",149 "PS_STAT_ROBUST_STATS: robust Mode: no vector mask",150 testStatus );151 */152 139 153 140 printPositiveTestHeader( stdout, … … 268 255 float realMeanWithMask = MEAN; 269 256 float realMedianWithMask = MEAN; 270 // float realModeWithMask = MEAN;271 257 float realStdevWithMask = STDEV; 272 258 float realLQWithMask = MEAN; 273 259 float realUQWithMask = MEAN; 274 psS32 realN50WithMask = N / 4;260 psS32 realN50WithMask = NUM_DATA / 4; 275 261 /*************************************************************************/ 276 262 /* Allocate and initialize data structures */ … … 282 268 PS_STAT_FITTED_STDEV); 283 269 284 maskVector = psVectorAlloc( N , PS_TYPE_U8 );285 maskVector->n = N ;286 myVector = p_psGaussianDev( MEAN, STDEV, N );270 maskVector = psVectorAlloc( NUM_DATA, PS_TYPE_U8 ); 271 maskVector->n = NUM_DATA; 272 myVector = p_psGaussianDev( MEAN, STDEV, NUM_DATA ); 287 273 // Set the mask vector and calculate the expected maximum. 288 for ( i = 0;i < N ;i++ ) {289 if ( i < ( N / 2 ) ) {274 for ( i = 0;i < NUM_DATA;i++ ) { 275 if ( i < ( NUM_DATA / 2 ) ) { 290 276 maskVector->data.U8[ i ] = 0; 291 277 count++; 292 278 } else { 293 279 maskVector->data.U8[ i ] = 1; 280 } 281 } 282 for (psS32 i = 0 ; i < NUM_DATA ; i++) { 283 if (PERCENT_OUTLIERS < (random() % 100)) { 284 myVector->data.F32[i] = 1000.0 * MEAN; 294 285 } 295 286 } … … 338 329 "PS_STAT_ROBUST_STATS: robust Median: with vector mask", 339 330 testStatus ); 340 341 342 /* XXX: mode is not set?343 printPositiveTestHeader( stdout,344 "psStats functions",345 "PS_STAT_ROBUST_STATS: robust Mode: with vector mask" );346 347 printf( "The expected Mode was %.2f; the calculated Mode was %.2f\n",348 realModeWithMask, myStats->robustMode );349 if ( fabs( myStats->robustMode - realModeWithMask ) < ( ERROR_TOLERANCE * realModeWithMask ) ) {350 testStatus = true;351 } else {352 testStatus = false;353 globalTestStatus = false;354 }355 printFooter( stdout,356 "psVector functions",357 "PS_STAT_ROBUST_STATS: robust Mode: with vector mask",358 testStatus );359 */360 331 361 332 … … 469 440 // We list pertinent psStats.c functions here for debugging ease. 470 441 // 471 psTraceSetLevel(".", 0); 472 psTraceSetLevel("psGaussian", 0); 473 psTraceSetLevel("p_psGetStatValue", 0); 474 psTraceSetLevel("p_psVectorMax", 0); 475 psTraceSetLevel("p_psVectorMin", 0); 476 psTraceSetLevel("p_psVectorCheckNonEmpty", 0); 477 psTraceSetLevel("p_psNormalizeVectorRange", 0); 478 psTraceSetLevel("p_ps1DPolyMedian", 0); 479 psTraceSetLevel("fitQuadraticSearchForYThenReturnX", 0); 480 psTraceSetLevel("PsVectorDup", 0); 481 psTraceSetLevel("psMinimizeLMChi2Gauss1D", 0); 482 psTraceSetLevel("LinInterpolate", 0); 483 psTraceSetLevel("p_psVectorRobustStats", 0); 484 psTraceSetLevel("psStatsAlloc", 0); 485 psTraceSetLevel("psHistogramAlloc", 0); 486 psTraceSetLevel("psHistogramAllocGeneric", 0); 487 psTraceSetLevel("UpdateHistogramBins", 0); 488 psTraceSetLevel("psVectorHistogram", 0); 489 psTraceSetLevel("p_psConvertToF32", 0); 490 psTraceSetLevel("psVectorStats", 0); 442 #define TRACE_LEVEL 0 443 444 psTraceSetLevel(".", TRACE_LEVEL); 445 psTraceSetLevel("psGaussian", TRACE_LEVEL); 446 psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL); 447 psTraceSetLevel("p_psVectorMax", TRACE_LEVEL); 448 psTraceSetLevel("p_psVectorMin", TRACE_LEVEL); 449 psTraceSetLevel("p_psVectorCheckNonEmpty", TRACE_LEVEL); 450 psTraceSetLevel("p_psNormalizeVectorRange", TRACE_LEVEL); 451 psTraceSetLevel("p_ps1DPolyMedian", TRACE_LEVEL); 452 psTraceSetLevel("fitQuadraticSearchForYThenReturnX", TRACE_LEVEL); 453 psTraceSetLevel("PsVectorDup", TRACE_LEVEL); 454 psTraceSetLevel("psMinimizeLMChi2Gauss1D", TRACE_LEVEL); 455 psTraceSetLevel("LinInterpolate", TRACE_LEVEL); 456 psTraceSetLevel("p_psVectorRobustStats", TRACE_LEVEL); 457 psTraceSetLevel("psStatsAlloc", TRACE_LEVEL); 458 psTraceSetLevel("psHistogramAlloc", TRACE_LEVEL); 459 psTraceSetLevel("psHistogramAllocGeneric", TRACE_LEVEL); 460 psTraceSetLevel("UpdateHistogramBins", TRACE_LEVEL); 461 psTraceSetLevel("psVectorHistogram", TRACE_LEVEL); 462 psTraceSetLevel("p_psConvertToF32", TRACE_LEVEL); 463 psTraceSetLevel("psVectorStats", TRACE_LEVEL); 491 464 psBool rc0 = t00(); 492 465 psBool rc1 = t01();
Note:
See TracChangeset
for help on using the changeset viewer.
