Changeset 7131
- Timestamp:
- May 17, 2006, 3:20:10 PM (20 years ago)
- Location:
- trunk/psLib/test/math
- Files:
-
- 2 edited
-
tst_psStats00.c (modified) (3 diffs)
-
tst_psStats09.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psStats00.c
r6317 r7131 3 3 * @brief Contains tests for psVectorStats with sample mean calculations 4 4 * 5 * We extensively test the code with data type PS_TYPE_F32. If these pass, we 5 * We extensively test the code with data type PS_TYPE_F32. If these pass, we 6 6 * do a much simpler test with data type PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64. 7 7 * … … 10 10 * 11 11 * @author GLG, MHPCC 12 * 13 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-0 2-03 01:34:11$12 * 13 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-05-18 01:20:10 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 85 85 psS32 testStatsSampleMeanF32(void) 86 86 { 87 psStats* myStats = NULL;88 psVector* myVector = NULL;89 psVector* maskVector = NULL;90 psVector* myErrors = NULL;91 psF64 mean = 0.0;92 93 87 /*************************************************************************/ 94 88 /* Allocate and initialize data structures */ 95 89 /*************************************************************************/ 96 myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);97 myVector = psVectorAlloc(N, PS_TYPE_F32);90 psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 91 psVector *myVector = psVectorAlloc(N, PS_TYPE_F32); 98 92 myVector->n = N; 99 myErrors = psVectorAlloc(N, PS_TYPE_F32);93 psVector *myErrors = psVectorAlloc(N, PS_TYPE_F32); 100 94 myErrors->n = N; 101 maskVector = psVectorAlloc(N, PS_TYPE_U8);95 psVector *maskVector = psVectorAlloc(N, PS_TYPE_U8); 102 96 maskVector->n = N; 103 97 104 mean = 0.0;98 psF64 mean = 0.0; 105 99 // Set the appropriate values for the vector data. 106 for ( psS32i = 0; i < N; i++) {100 for (long i = 0; i < N; i++) { 107 101 myVector->data.F32[i] = samplesF32[i]; 108 102 myErrors->data.F32[i] = errorsF32[i]; -
trunk/psLib/test/math/tst_psStats09.c
r6484 r7131 14 14 15 15 #define NUM_DATA 1000 16 #define VERBOSE 016 #define VERBOSE 1 17 17 #define PERCENT_OUTLIERS 2 18 18 #define ERROR_TOLERANCE .10 19 #define ERRORS 1 000.019 #define ERRORS 1.0 20 20 #define SEED 1995 21 21 … … 52 52 printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine"); 53 53 54 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed 55 psVector *truth = psVectorAlloc(numData, PS_TYPE_F64); 56 truth->n = numData; 57 for (long i = 0; i < numData; i++) { 58 truth->data.F64[i] = psRandomGaussian(rng); 59 } 60 psFree(rng); 61 54 62 if (expectedRC == true) { 55 63 printf("This test should not generate any errors.\n"); … … 65 73 if (flags & TST_IN_F32) { 66 74 printf(" using a psF32 in vector\n"); 67 in = psVectorAlloc(numData, PS_TYPE_F32); 68 for (psS32 i=0;i<numData;i++) { 69 in->data.F32[i] = (psF32) i; 70 in->n++; 71 } 72 75 in = psVectorCopy(in, truth, PS_TYPE_F32); 73 76 if (VERBOSE) { 74 77 for (psS32 i=0;i<numData;i++) { … … 80 83 if (flags & TST_IN_F64) { 81 84 printf(" using a psF64 in vector\n"); 82 in = psVectorAlloc(numData, PS_TYPE_F64); 83 for (psS32 i=0;i<numData;i++) { 84 in->data.F64[i] = (psF64) i; 85 in->n++; 86 } 85 in = psVectorCopy(in, truth, PS_TYPE_F64); 87 86 88 87 if (VERBOSE) { … … 95 94 if (flags & TST_IN_S8) { 96 95 printf(" using a psS8 in vector\n"); 97 in = psVectorAlloc(numData, PS_TYPE_S8); 98 for (psS32 i=0;i<numData;i++) { 99 in->data.S8[i] = (psS8) i; 100 in->n++; 101 } 96 in = psVectorCopy(in, truth, PS_TYPE_S8); 102 97 103 98 if (VERBOSE) { … … 110 105 if (flags & TST_IN_U16) { 111 106 printf(" using a psU16 in vector\n"); 112 in = psVectorAlloc(numData, PS_TYPE_U16); 113 for (psS32 i=0;i<numData;i++) { 114 in->data.U16[i] = (psU16) i; 115 in->n++; 116 } 107 in = psVectorCopy(in, truth, PS_TYPE_U16); 117 108 118 109 if (VERBOSE) { … … 125 116 if (flags & TST_IN_S32) { 126 117 printf(" using a psS32 in vector\n"); 127 in = psVectorAlloc(numData, PS_TYPE_S32); 128 for (psS32 i=0;i<numData;i++) { 129 in->data.S32[i] = (psS32) i; 130 in->n++; 131 } 118 in = psVectorCopy(in, truth, PS_TYPE_S32); 132 119 133 120 if (VERBOSE) { … … 252 239 } 253 240 241 242 // 243 // We add a few outliers to the input data. 244 // 245 psVector *outliers = psVectorAlloc(numData, PS_TYPE_U8); 246 outliers->n = numData; 247 psVectorInit(outliers, 0); 248 if (flags & TST_IN_F32) { 249 for (psS32 i=0;i<numData;i++) { 250 if (PERCENT_OUTLIERS > (random() % 100)) { 251 in->data.F32[i] = 100.0; 252 outliers->data.U8[i] = 1; 253 } 254 } 255 256 if (VERBOSE) { 257 for (psS32 i=0;i<numData;i++) { 258 printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]); 259 } 260 } 261 } 262 if (flags & TST_IN_F64) { 263 for (psS32 i=0;i<numData;i++) { 264 if (PERCENT_OUTLIERS > (random() % 100)) { 265 in->data.F64[i] = 100.0; 266 outliers->data.U8[i] = 1; 267 } 268 } 269 270 if (VERBOSE) { 271 for (psS32 i=0;i<numData;i++) { 272 printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]); 273 } 274 } 275 } 276 if (flags & TST_IN_S8) { 277 for (psS32 i=0;i<numData;i++) { 278 if (PERCENT_OUTLIERS > (random() % 100)) { 279 in->data.S8[i] = 100; 280 outliers->data.U8[i] = 1; 281 } 282 } 283 284 if (VERBOSE) { 285 for (psS32 i=0;i<numData;i++) { 286 printf("Original in data %d: (%d)\n", i, in->data.S8[i]); 287 } 288 } 289 } 290 if (flags & TST_IN_U16) { 291 for (psS32 i=0;i<numData;i++) { 292 if (PERCENT_OUTLIERS > (random() % 100)) { 293 in->data.U16[i] = 100; 294 outliers->data.U8[i] = 1; 295 } 296 } 297 298 if (VERBOSE) { 299 for (psS32 i=0;i<numData;i++) { 300 printf("Original in data %d: (%d)\n", i, in->data.U16[i]); 301 } 302 } 303 } 304 if (flags & TST_IN_S32) { 305 for (psS32 i=0;i<numData;i++) { 306 if (PERCENT_OUTLIERS > (random() % 100)) { 307 in->data.S32[i] = 100; 308 outliers->data.U8[i] = 1; 309 } 310 } 311 312 if (VERBOSE) { 313 for (psS32 i=0;i<numData;i++) { 314 printf("Original in data %d: (%d)\n", i, in->data.S32[i]); 315 } 316 } 317 } 254 318 255 319 // … … 261 325 if (expectedRC == true) { 262 326 psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 263 psStats *rc = psVectorStats(myStats, in, NULL, NULL, maskValue);327 psStats *rc = psVectorStats(myStats, in, errors, outliers, 1); 264 328 if (rc == NULL) { 265 329 printf("TEST ERROR: the psVectorStats() function returned NULL.\n"); … … 271 335 psFree(myStats); 272 336 } 273 274 // 275 // We add a few outliers to the input data. 276 // 277 if (flags & TST_IN_F32) { 278 for (psS32 i=0;i<numData;i++) { 279 if (PERCENT_OUTLIERS > (random() % 100)) { 280 in->data.F32[i] = (psF32) (10 * numData); 281 } 282 } 283 284 if (VERBOSE) { 285 for (psS32 i=0;i<numData;i++) { 286 printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]); 287 } 288 } 289 } 290 if (flags & TST_IN_F64) { 291 for (psS32 i=0;i<numData;i++) { 292 if (PERCENT_OUTLIERS > (random() % 100)) { 293 in->data.F64[i] = (psF64) (10 * numData); 294 } 295 } 296 297 if (VERBOSE) { 298 for (psS32 i=0;i<numData;i++) { 299 printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]); 300 } 301 } 302 } 303 if (flags & TST_IN_S8) { 304 for (psS32 i=0;i<numData;i++) { 305 if (PERCENT_OUTLIERS > (random() % 100)) { 306 in->data.S8[i] = (psS8) (10 * numData); 307 } 308 } 309 310 if (VERBOSE) { 311 for (psS32 i=0;i<numData;i++) { 312 printf("Original in data %d: (%d)\n", i, in->data.S8[i]); 313 } 314 } 315 } 316 if (flags & TST_IN_U16) { 317 for (psS32 i=0;i<numData;i++) { 318 if (PERCENT_OUTLIERS > (random() % 100)) { 319 in->data.U16[i] = (psU16) (10 * numData); 320 } 321 } 322 323 if (VERBOSE) { 324 for (psS32 i=0;i<numData;i++) { 325 printf("Original in data %d: (%d)\n", i, in->data.U16[i]); 326 } 327 } 328 } 329 if (flags & TST_IN_S32) { 330 for (psS32 i=0;i<numData;i++) { 331 if (PERCENT_OUTLIERS > (random() % 100)) { 332 in->data.S32[i] = (psS32) (10 * numData); 333 } 334 } 335 336 if (VERBOSE) { 337 for (psS32 i=0;i<numData;i++) { 338 printf("Original in data %d: (%d)\n", i, in->data.S32[i]); 339 } 340 } 341 } 337 psFree(outliers); 342 338 343 339 // … … 345 341 // 346 342 psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 343 myStats->clipSigma = 5.0; 347 344 psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue); 348 345 if (rc == NULL) { … … 358 355 359 356 if (fabs(myStats->clippedMean - sampleMean) > (ERROR_TOLERANCE * sampleMean)) { 360 printf("TEST ERROR: the clipped mean was % .2f, should have been %.2f\n", myStats->clippedMean, sampleMean);357 printf("TEST ERROR: the clipped mean was %f, should have been %f\n", myStats->clippedMean, sampleMean); 361 358 testStatus = false; 362 359 } else if (VERBOSE) { 363 printf("GOOD: the clipped mean was % .2f, should have been %.2f\n", myStats->clippedMean, sampleMean);360 printf("GOOD: the clipped mean was %f, should have been %f\n", myStats->clippedMean, sampleMean); 364 361 } 365 362 366 363 if (fabs(myStats->clippedStdev - sampleStdev) > (ERROR_TOLERANCE * sampleStdev)) { 367 printf("TEST ERROR: the clipped stdev was % .2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);364 printf("TEST ERROR: the clipped stdev was %f, should have been %f\n", myStats->clippedStdev, sampleStdev); 368 365 testStatus = false; 369 366 } else if (VERBOSE) { 370 printf("GOOD: the clipped stdev was % .2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);367 printf("GOOD: the clipped stdev was %f, should have been %f\n", myStats->clippedStdev, sampleStdev); 371 368 } 372 369 … … 374 371 375 372 psFree(myStats); 373 psFree(truth); 376 374 psFree(in); 377 375 psFree(errors);
Note:
See TracChangeset
for help on using the changeset viewer.
