IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1177


Ignore:
Timestamp:
Jul 1, 2004, 12:30:43 PM (22 years ago)
Author:
gusciora
Message:

...

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

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psMinimize00.c

    r1123 r1177  
    1616#define NUM_PARAMS 4
    1717
    18 // The function is f(x) = (A * e^(lambda x)) + b
    19 
    20 float myFunc2(const psVector *restrict myData,
    21               const psVector *restrict myParams)
    22 {
    23     float x = myData->data.F32[0];
    24     float A = myParams->data.F32[0];
    25     float lambda = myParams->data.F32[1];
    26     float b = myParams->data.F32[2];
    27 
    28     return(A * exp(-lambda * x) + b);
    29 }
    30 
    31 float myFunc2Deriv(const psVector *restrict myData,
    32                    const psVector *restrict myParams,
    33                    int whichParamDeriv)
    34 {
    35     float x = myData->data.F32[0];
    36     float A = myParams->data.F32[0];
    37     float lambda = myParams->data.F32[1];
    38     float tmp = 0.0;
    39 
    40     if (whichParamDeriv == 0) {
    41         tmp = exp(-lambda * x);
    42     } else if (whichParamDeriv == 1) {
    43         tmp = -x * A * exp(-lambda * x);
    44     } else if (whichParamDeriv == 2) {
    45         tmp = 1.0;
    46     }
    47     return(tmp);
    48 }
    49 
    50 
    51 
    5218float myFunc(const psVector *restrict myData,
    5319             const psVector *restrict myParams)
     
    6127    float tmp = 0.0;
    6228
    63     tmp = A + (B*x) + (C*y) + (D*x*y);
    64     printf("--------- myFunc((%.1f %.1f) %.1f %.1f %.1f %.1f) is %.1f ---------\n",
    65            x, y, A, B, C, D, tmp);
     29    tmp = (A * x) + (B*x*x) + (C*y*y) + (D*x*x*y);
     30    //    printf("--------- myFunc((%.1f %.1f) %.1f %.1f %.1f %.1f) is %.1f ---------\n",
     31    //           x, y, A, B, C, D, tmp);
    6632
    6733    return(tmp);
     
    7844    if (whichParamDeriv == 0) {
    7945        tmp = 1.0;
     46        tmp = x;
    8047    } else if (whichParamDeriv == 1) {
    8148        tmp = x;
     49        tmp = x*x;
    8250    } else if (whichParamDeriv == 2) {
    8351        tmp = y;
     52        tmp = y*y;
    8453    } else if (whichParamDeriv == 3) {
    85         tmp = x * y;
     54        tmp = x * x * y;
    8655    }
    8756
    88     printf("--------- myFuncDeriv((%.1f %.1f) %.1f %.1f %.1f %.1f (%d)) is %.1f ---------\n",
    89            x, y, myParams->data.F32[0], myParams->data.F32[1],
    90            myParams->data.F32[2], myParams->data.F32[3], whichParamDeriv, tmp);
     57    //    printf("--------- myFuncDeriv((%.1f %.1f) %.1f %.1f %.1f %.1f (%d)) is %.1f ---------\n",
     58    //            x, y, myParams->data.F32[0], myParams->data.F32[1],
     59    //            myParams->data.F32[2], myParams->data.F32[3], whichParamDeriv, tmp);
    9160    return(tmp);
    9261}
     
    10574    int j = 0;
    10675    int currentId = psMemGetId();
    107     int testStatus = 0;
     76    int testStatus = true;
    10877    int memLeaks = 0;
    10978    psVector *theParams = NULL;
     
    11685    tmpVecPtr = psVectorAlloc(DATA_WIDTH, PS_TYPE_F32);
    11786
     87
     88    //--------- myFunc((0.0 1.0) -8.6 -7.6 14.6 5.0) is 6.0 ---------
     89
     90    initialGuess->data.F32[0] = -8.6;
     91    initialGuess->data.F32[1] = -7.6;
     92    initialGuess->data.F32[2] = 14.6;
     93    initialGuess->data.F32[3] = 5.0;
     94
    11895    // Build the data.
    11996    initialGuess->data.F32[0] = 2.0;
     
    12198    initialGuess->data.F32[2] = 4.0;
    12299    initialGuess->data.F32[3] = 5.0;
     100
    123101
    124102    for (i = 0; i<NUM_DATA; i++) {
     
    128106    }
    129107    for (i = 0; i<NUM_DATA; i++) {
    130         errors->data.F32[i] = 1.0;
     108        errors->data.F32[i] = 0.1;
    131109    }
    132110
    133     printf("========== Setting Data Values ==========\n");
     111    //    printf("========== Setting Data Values ==========\n");
    134112    for (i = 0; i<NUM_DATA; i++) {
    135113        for (j=0; j<DATA_WIDTH; j++) {
     
    138116        data->data.F32[i] = myFunc(tmpVecPtr, initialGuess);
    139117    }
     118    //    printf("=========================================\n");
    140119
    141120    for (i=0;i<NUM_PARAMS;i++) {
    142         initialGuess->data.F32[i] = 1.0;
    143         initialGuess->data.F32[i]+= 10.0;
     121        initialGuess->data.F32[i]+= 1.0;
    144122    }
    145123
    146124    printPositiveTestHeader(stdout,
    147125                            "psMinimize functions",
    148                             "Calculate Histogram, no mask");
     126                            "psMinimizeChi2(): no masks");
    149127
    150     theParams = psMinimizeChi2(myFunc2,
    151                                myFunc2Deriv,
     128    theParams = psMinimizeChi2(myFunc,
     129                               myFuncDeriv,
    152130                               domain,
    153131                               data,
     
    160138    }
    161139
    162 
    163 
    164140    printf("chiSq is %f\n", chiSq);
    165141    psMemCheckCorruption(1);
    166142    printFooter(stdout,
    167143                "psMinimize functions",
    168                 "Calculate Histogram, no mask",
     144                "psMinimizeChi2(): no masks",
    169145                testStatus);
    170146
  • trunk/psLib/test/dataManip/tst_psMinimize01.c

    r1123 r1177  
    6767    int i = 0;
    6868    psVector *theParams = NULL;
     69    int currentId = psMemGetId();
     70    int testStatus = true;
     71    int memLeaks = 0;
    6972
    7073    domain = psImageAlloc(DATA_WIDTH, NUM_DATA, PS_TYPE_F32);
     
    127130    data->data.F32[39] = 1.061982;
    128131
     132    printPositiveTestHeader(stdout,
     133                            "psMinimize functions",
     134                            "psMinimizeChi2(): no masks");
     135
    129136    theParams = psMinimizeChi2(myFunc,
    130137                               myFuncDeriv,
     
    139146        printf("theParams[%d] is %.1f\n", i, theParams->data.F32[i]);
    140147    }
     148    printf("chiSq is %f\n", chiSq);
    141149
    142     printf("chiSq is %f\n", chiSq);
     150    psMemCheckCorruption(1);
     151    printFooter(stdout,
     152                "psMinimize functions",
     153                "psMinimizeChi2(): no masks",
     154                testStatus);
     155    psMemCheckCorruption(1);
     156    psFree(domain);
     157    psFree(data);
     158    psFree(errors);
     159    psFree(initialGuess);
     160    psFree(paramMask);
     161    psFree(tmpVecPtr);
     162
     163    psMemCheckCorruption(1);
     164    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
     165    if (0 != memLeaks) {
     166        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     167    }
     168
     169    return (!testStatus);
    143170}
Note: See TracChangeset for help on using the changeset viewer.