IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 2, 2006, 11:06:10 AM (20 years ago)
Author:
gusciora
Message:

....

File:
1 edited

Legend:

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

    r6215 r6304  
    1313#include <math.h>
    1414
    15 #define N 90
     15#define NUM_DATA 10000
    1616#define MEAN 32.0
    1717#define STDEV 2.0
    1818#define ERROR_TOLERANCE 0.15
     19#define PERCENT_OUTLIERS 10
    1920
    2021psS32 t00()
     
    2728    psVector *myVector = NULL;
    2829    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.
    3230    psS32 count = 0;
    3331    psS32 currentId = psMemGetId();
     
    3533    float realMeanNoMask = MEAN;
    3634    float realMedianNoMask = MEAN;
    37     //    float realModeNoMask = MEAN;
    3835    float realStdevNoMask = STDEV;
    3936    float realLQNoMask = MEAN - ( 0.6 * STDEV );
    4037    float realUQNoMask = MEAN + ( 0.6 * STDEV );
    41     psS32 realN50NoMask = N / 4;
     38    psS32 realN50NoMask = NUM_DATA / 4;
    4239
    4340    /*************************************************************************/
    4441    /*  Allocate and initialize data structures                              */
    4542    /*************************************************************************/
    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 );
    4946    // 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 ) ) {
    5249            maskVector->data.U8[ i ] = 0;
    5350            count++;
     
    5653        }
    5754    }
     55
     56    //
     57    // We calculate the exact mean, median, stdev and quartiles with no mask.
     58    //
    5859    psStats *mySampleStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN |
    5960                                           PS_STAT_SAMPLE_MEDIAN |
     
    6768    psFree(mySampleStats);
    6869
     70    //
     71    // We calculate the exact mean, median, stdev and quartiles with mask.
     72    //
    6973    psStats *mySampleStatsWithMask = psStatsAlloc( PS_STAT_SAMPLE_MEAN |
    7074                                     PS_STAT_SAMPLE_MEDIAN |
     
    8488                           PS_STAT_FITTED_STDEV);
    8589    // 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    }
    8895    /*************************************************************************/
    8996    /*  Call psVectorStats() with no vector mask.                            */
     
    130137                 "PS_STAT_ROBUST_STATS: robust Median: no vector mask",
    131138                 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     */
    152139
    153140    printPositiveTestHeader( stdout,
     
    268255    float realMeanWithMask = MEAN;
    269256    float realMedianWithMask = MEAN;
    270     //    float realModeWithMask = MEAN;
    271257    float realStdevWithMask = STDEV;
    272258    float realLQWithMask = MEAN;
    273259    float realUQWithMask = MEAN;
    274     psS32 realN50WithMask = N / 4;
     260    psS32 realN50WithMask = NUM_DATA / 4;
    275261    /*************************************************************************/
    276262    /*  Allocate and initialize data structures                              */
     
    282268                           PS_STAT_FITTED_STDEV);
    283269
    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 );
    287273    // 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 ) ) {
    290276            maskVector->data.U8[ i ] = 0;
    291277            count++;
    292278        } else {
    293279            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;
    294285        }
    295286    }
     
    338329                 "PS_STAT_ROBUST_STATS: robust Median: with vector mask",
    339330                 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     */
    360331
    361332
     
    469440    // We list pertinent psStats.c functions here for debugging ease.
    470441    //
    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);
    491464    psBool rc0 = t00();
    492465    psBool rc1 = t01();
Note: See TracChangeset for help on using the changeset viewer.