IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 26, 2004, 1:14:04 PM (22 years ago)
Author:
gusciora
Message:

Modified the prototype for the LM minimization routines.

File:
1 edited

Legend:

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

    r2197 r2202  
    88#define NUM_ITERATIONS 10000
    99#define ERR_TOL 0.0
    10 #define N 5
     10#define N 20
    1111#define MIN_VALUE 5.0
    1212#define NUM_PARAMS 3
     
    2424 
    2525 *****************************************************************************/
    26 float myFunc(psVector *myDeriv,
    27              psVector *myParams,
    28              psVector *myCoords)
    29 {
    30     float sum = 0.0;
    31     //    float coordData = 0.0;
    32     //    float expData = 0.0;
    33     int i;
    34 
    35     if (myDeriv == NULL) {
    36         myDeriv = psVectorAlloc(myParams->n, PS_TYPE_F32);
    37         psError(__func__, "myDeriv is NULL.\n");
    38     }
    39 
    40     // Simply test that coords were passed in correctly.
    41     /*
    42         for (i=0;i<N;i++) {
    43             coordData = myCoords->data.F32[0];
    44             expData = (float) (i+10);
    45             if (fabs(coordData - expData) > FLT_EPSILON) {
    46                 printf("ERROR(1): coordinate data was incorrectly passed to myFunc()\n");
    47                 printf("ERROR(1): was (%f) should be (%f)\n", coordData, expData);
    48                 testStatus = false;
    49             }
    50             coordData = myCoords->data.F32[1];
    51             expData = (float) (i+3);
    52             if (fabs(coordData - expData) > FLT_EPSILON) {
    53                 printf("ERROR(2): coordinate data was incorrectly passed to myFunc()\n");
    54                 printf("ERROR(2): was (%f) should be (%f)\n", coordData, expData);
    55                 testStatus = false;
    56             }
    57         }
    58     */
    59 
    60     sum = 0.0;
    61     for (i=0;i<NUM_PARAMS;i++) {
    62         sum+= (myParams->data.F32[i] - expectedParm[i]) *
    63               (myParams->data.F32[i] - expectedParm[i]);
    64         myDeriv->data.F32[i] = (2.0 * myParams->data.F32[i]) -
    65                                (2.0 * expectedParm[i]);
    66     }
    67     //    for (i=0;i<NUM_PARAMS;i++)
    68     //        printf("HMMM: myParams->data.F32[%d] is %f\n", i, myParams->data.F32[i]);
    69     //    for (i=0;i<NUM_PARAMS;i++)
    70     //        printf("HMMM: myDeriv->data.F32[%d] is %f\n", i, myDeriv->data.F32[i]);
    71 
    72     sum+= MIN_VALUE;
    73     return(sum);
    74 }
    75 
    76 psVector *myFunc2(psImage *myDeriv,
    77                   psVector *myParams,
    78                   psArray *myCoords)
     26psVector *myFunc(psImage *myDeriv,
     27                 psVector *myParams,
     28                 psArray *myCoords)
    7929{
    8030    psVector *sum = psVectorAlloc(myCoords->n, PS_TYPE_F32);
     
    13686    }
    13787
    138     psMyMinimizeLMChi2(min,
    139                        myCovar,
    140                        myParams,
    141                        NULL,
    142                        myCoords,
    143                        y,
    144                        NULL,
    145                        (psMyMinimizeLMChi2Func) myFunc2);
     88    psMinimizeLMChi2(min,
     89                     myCovar,
     90                     myParams,
     91                     NULL,
     92                     myCoords,
     93                     y,
     94                     NULL,
     95                     (psMinimizeLMChi2Func) myFunc);
    14696
    14797    printf("\nThe chi-squared is %f\n", min->value);
     
    165115}
    166116
    167 int t02()
    168 {
    169     int currentId = psMemGetId();
    170     int memLeaks = 0;
    171     int i = 0;
    172     psArray *myCoords;
    173     psVector *myParams;
    174     psVector *myParamMask;
    175     psImage *myCovar;
    176     psMinimization *min;
    177     psVector *y = psVectorAlloc(N, PS_TYPE_F32);
    178 
    179     psTraceSetLevel(".psLib", 0);
    180     t02();
    181     /**************************************************************************
    182      *************************************************************************/
    183     myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
    184     myParamMask = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
    185     min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
    186     myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32);
    187 
    188     myCoords = psArrayAlloc(N);
    189     for (i=0;i<N;i++) {
    190         myCoords->data[i] = (psPTR *) psVectorAlloc(2, PS_TYPE_F32);
    191         ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
    192         ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
    193         y->data.F32[i] = (float) i;
    194     }
    195     for (i=0;i<NUM_PARAMS;i++) {
    196         expectedParm[i] = 2.42 + (float) (2 * i);
    197         myParams->data.F32[i] = (float) i;
    198         myParams->data.F32[i] = expectedParm[i] * 1.3;
    199         myParams->data.F32[i] = (float) (5 + i);
    200         myParams->data.F32[i] = 0.0;
    201         myParamMask->data.U8[i] = 0;
    202     }
    203 
    204     psMinimizeLMChi2(min,
    205                      myParams,
    206                      NULL,
    207                      myCovar,
    208                      myCoords,
    209                      y,
    210                      (psMinimizeLMChi2Func) myFunc);
    211 
    212     printf("\nThe chi-squared is %f\n", min->value);
    213     for (i=0;i<NUM_PARAMS;i++) {
    214         printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
    215                myParams->data.F32[i], expectedParm[i]);
    216     }
    217 
    218     psFree(myCoords);
    219     psFree(myParams);
    220     psFree(myParamMask);
    221     psFree(min);
    222     psFree(y);
    223     psFree(myCovar);
    224 
    225     psMemCheckCorruption(1);
    226     memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
    227     if (0 != memLeaks) {
    228         psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    229     }
    230     return (!testStatus);
    231 }
    232 
    233117int main()
    234118{
    235119    t01();
    236     //    t02();
    237120}
Note: See TracChangeset for help on using the changeset viewer.