IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7131


Ignore:
Timestamp:
May 17, 2006, 3:20:10 PM (20 years ago)
Author:
Paul Price
Message:

Updating stats tests, following update to psStats.c

Location:
trunk/psLib/test/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/math/tst_psStats00.c

    r6317 r7131  
    33*  @brief Contains tests for psVectorStats with sample mean calculations
    44*
    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
    66*  do a much simpler test with data type PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64.
    77*
     
    1010*
    1111*  @author GLG, MHPCC
    12 * 
    13 *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
    14 *  @date $Date: 2006-02-03 01:34:11 $
     12*
     13*  @version $Revision: 1.7 $  $Name: not supported by cvs2svn $
     14*  @date $Date: 2006-05-18 01:20:10 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    8585psS32 testStatsSampleMeanF32(void)
    8686{
    87     psStats*  myStats    = NULL;
    88     psVector* myVector   = NULL;
    89     psVector* maskVector = NULL;
    90     psVector* myErrors   = NULL;
    91     psF64     mean       = 0.0;
    92 
    9387    /*************************************************************************/
    9488    /*  Allocate and initialize data structures                      */
    9589    /*************************************************************************/
    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);
    9892    myVector->n = N;
    99     myErrors = psVectorAlloc(N, PS_TYPE_F32);
     93    psVector *myErrors = psVectorAlloc(N, PS_TYPE_F32);
    10094    myErrors->n = N;
    101     maskVector = psVectorAlloc(N, PS_TYPE_U8);
     95    psVector *maskVector = psVectorAlloc(N, PS_TYPE_U8);
    10296    maskVector->n = N;
    10397
    104     mean = 0.0;
     98    psF64 mean = 0.0;
    10599    // Set the appropriate values for the vector data.
    106     for (psS32 i = 0; i < N; i++) {
     100    for (long i = 0; i < N; i++) {
    107101        myVector->data.F32[i] =  samplesF32[i];
    108102        myErrors->data.F32[i] =  errorsF32[i];
  • trunk/psLib/test/math/tst_psStats09.c

    r6484 r7131  
    1414
    1515#define NUM_DATA 1000
    16 #define VERBOSE 0
     16#define VERBOSE 1
    1717#define PERCENT_OUTLIERS 2
    1818#define ERROR_TOLERANCE .10
    19 #define ERRORS 1000.0
     19#define ERRORS 1.0
    2020#define SEED 1995
    2121
     
    5252    printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
    5353
     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
    5462    if (expectedRC == true) {
    5563        printf("This test should not generate any errors.\n");
     
    6573    if (flags & TST_IN_F32) {
    6674        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);
    7376        if (VERBOSE) {
    7477            for (psS32 i=0;i<numData;i++) {
     
    8083    if (flags & TST_IN_F64) {
    8184        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);
    8786
    8887        if (VERBOSE) {
     
    9594    if (flags & TST_IN_S8) {
    9695        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);
    10297
    10398        if (VERBOSE) {
     
    110105    if (flags & TST_IN_U16) {
    111106        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);
    117108
    118109        if (VERBOSE) {
     
    125116    if (flags & TST_IN_S32) {
    126117        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);
    132119
    133120        if (VERBOSE) {
     
    252239    }
    253240
     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    }
    254318
    255319    //
     
    261325    if (expectedRC == true) {
    262326        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);
    264328        if (rc == NULL) {
    265329            printf("TEST ERROR: the psVectorStats() function returned NULL.\n");
     
    271335        psFree(myStats);
    272336    }
    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);
    342338
    343339    //
     
    345341    //
    346342    psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     343    myStats->clipSigma = 5.0;
    347344    psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);
    348345    if (rc == NULL) {
     
    358355
    359356        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);
    361358            testStatus = false;
    362359        } 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);
    364361        }
    365362
    366363        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);
    368365            testStatus = false;
    369366        } 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);
    371368        }
    372369
     
    374371
    375372    psFree(myStats);
     373    psFree(truth);
    376374    psFree(in);
    377375    psFree(errors);
Note: See TracChangeset for help on using the changeset viewer.