IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 1, 2007, 6:20:06 PM (19 years ago)
Author:
gusciora
Message:

Added tabular file of all psLib functions in Chapter 6 of the SDRS (Data
Manipulation). Most of the test file changes in this check-in are fairly
cosmetic.

File:
1 edited

Legend:

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

    r10945 r13124  
    22    This routine must ensure that psMinimizeLM() works correctly.
    33 
    4     XXX: This code needs a lot of additional test case work.
    5          The minimization currently (always?) fails and we don't
    6          attempt to check the output values.
     4    XXX: This code needs a lot of additional test case work.  The minimization
     5         currently fails and we don't attempt to check the output values.
     6    XXX: Add tests for
     7        covar arg set to non-NULL
     8        constraint set to non-NULL
     9        Set x->vectors to NULL, or use wrong types
     10        yWt (errors) vector set to incorrect size, type.
    711 *****************************************************************************/
    812#include <stdio.h>
     
    1923float expectedParm[NUM_PARAMS];
    2024
    21 
     25// y = p2 + p0 * e^( x0^2 + x1^2 / (2 * p1^2) )
    2226float function(const psVector *params, const psVector *x)
    2327{
     
    3539
    3640
    37 /*****************************************************************************
    38 fitFunc():
    39     sum = param[0] * x[0] * x[1] +
    40           param[1] * x[0] +
    41           param[2] * x[0]^2 +
    42           param[3] * x[1] +
    43           param[4] * x[1]^2
    44  
    45  *****************************************************************************/
    4641psF32 fitFunc(psVector *deriv,
    4742              psVector *params,
     
    5651}
    5752
     53
    5854#define NUM_ITER 10
    5955#define TOL  20.0
     
    6258    psLogSetFormat("HLNM");
    6359    psLogSetLevel(PS_LOG_INFO);
    64     plan_tests(2);
     60    plan_tests(34);
     61
     62
    6563    // Test psMinimizationAlloc()
    6664    {
     
    7977    }
    8078
    81     /*
    82         // Test psMinConstrainAlloc()
    83         {
    84             psMemId id = psMemGetId();
    85             psMinConstrain *tmp = psMinConstrainAlloc(NUM_ITER, TOL);
    86             ok(tmp != NULL. "psMinConstrainAlloc() returned non-NULL");
    87             skip_start(tmp == NULL, 4, "Skipping tests because psMinConstrainAlloc() failed");
    88             ok(tmp->paramMask == NULL, "psMinConstrainAlloc() properly set ->paramMask");
    89             ok(tmp->paramMax == NULL, "psMinConstrainAlloc() properly set ->paramMax");
    90             ok(tmp->paramMin == NULL, "psMinConstrainAlloc() properly set ->paramMin");
    91             ok(tmp->paramDelta == NULL, "psMinConstrainAlloc() properly set ->paramDelta");
    92             psFree(tmp);
    93             skip_end();
    94             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    95         }
    96     */
    97 
    98     // Test psMinimizeLMChi2()
     79
     80    // Test psMinConstraintAlloc()
     81    {
     82        psMemId id = psMemGetId();
     83        psMinConstraint *tmp = psMinConstraintAlloc();
     84        ok(tmp != NULL, "psMinConstraintAlloc() returned non-NULL");
     85        skip_start(tmp == NULL, 2, "Skipping tests because psMinConstraintAlloc() failed");
     86        ok(tmp->paramMask == NULL, "psMinConstraintAlloc() properly set ->paramMask");
     87        ok(tmp->checkLimits == NULL, "psMinConstraintAlloc() properly set ->checkLimits");
     88        psFree(tmp);
     89        skip_end();
     90        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     91    }
     92
     93
     94    // Test psMinimizeLMChi2(): unallowed input parameters.
     95    {
     96        psMemId id = psMemGetId();
     97        psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
     98        psMinimization *min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
     99        psArray *ordinates = psArrayAlloc(NUM_DATA_POINTS);
     100        psVector *coordinates = psVectorAlloc(NUM_DATA_POINTS, PS_TYPE_F32);
     101        psVector *coordinatesF64 = psVectorAlloc(NUM_DATA_POINTS, PS_TYPE_F64);
     102        psVector *errors = psVectorAlloc(NUM_DATA_POINTS, PS_TYPE_F32);
     103        psVector *params = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     104        psVector *paramsF64 = psVectorAlloc(NUM_PARAMS, PS_TYPE_F64);
     105        psVector *trueParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     106
     107        // Test with psMinimization set to NULL
     108        {
     109            psMemId id = psMemGetId();
     110            bool tmpBool = psMinimizeLMChi2(NULL, NULL, params, NULL, ordinates,
     111                           coordinates, errors, (psMinimizeLMChi2Func)fitFunc);
     112            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL psMinimization");
     113            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     114        }
     115
     116
     117        // Test with params set to NULL
     118        {
     119            psMemId id = psMemGetId();
     120            bool tmpBool = psMinimizeLMChi2(min, NULL, NULL, NULL, ordinates,
     121                           coordinates, errors, (psMinimizeLMChi2Func)fitFunc);
     122            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL params");
     123            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     124        }
     125
     126
     127        // Test with params wrong type
     128        {
     129            psMemId id = psMemGetId();
     130            bool tmpBool = psMinimizeLMChi2(min, NULL, paramsF64, NULL, ordinates,
     131                           coordinates, errors, (psMinimizeLMChi2Func)fitFunc);
     132            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL params");
     133            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     134        }
     135
     136
     137        // Test with ordinates (x) set to NULL
     138        {
     139            psMemId id = psMemGetId();
     140            bool tmpBool = psMinimizeLMChi2(min, NULL, params, NULL, NULL,
     141                           coordinates, errors, (psMinimizeLMChi2Func)fitFunc);
     142            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL ordinates (x)");
     143            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     144        }
     145
     146
     147        // Test with coordinates (y) set to NULL
     148        {
     149            psMemId id = psMemGetId();
     150            bool tmpBool = psMinimizeLMChi2(min, NULL, params, NULL, ordinates,
     151                           NULL, errors, (psMinimizeLMChi2Func)fitFunc);
     152            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL coordinates (y)");
     153            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     154        }
     155
     156
     157        // Test with coordinates (y) wrong type (F64)
     158        {
     159            psMemId id = psMemGetId();
     160            bool tmpBool = psMinimizeLMChi2(min, NULL, params, NULL, ordinates,
     161                           coordinatesF64, errors, (psMinimizeLMChi2Func)fitFunc);
     162            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with coordinates (y) wrong type");
     163            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     164        }
     165
     166
     167        // Test with ordinates and coordinates wrong size
     168        {
     169            psMemId id = psMemGetId();
     170            coordinates->n--;
     171            bool tmpBool = psMinimizeLMChi2(min, NULL, params, NULL, ordinates,
     172                           coordinates, errors, (psMinimizeLMChi2Func)fitFunc);
     173            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL psMinimization");
     174            coordinates->n++;
     175            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     176        }
     177
     178
     179        // Test with function set to NULL
     180        {
     181            psMemId id = psMemGetId();
     182            bool tmpBool = psMinimizeLMChi2(min, NULL, params, NULL, ordinates,
     183                           coordinates, errors, NULL);
     184            ok(!tmpBool, "psMinimizeLMChi2() returned FALSE with NULL fit function");
     185            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     186        }
     187
     188        psFree(min);
     189        psFree(params);
     190        psFree(paramsF64);
     191        psFree(trueParams);
     192        psFree(ordinates);
     193        psFree(coordinates);
     194        psFree(coordinatesF64);
     195        psFree(errors);
     196        psFree(rng);
     197        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     198    }
     199
     200
     201    // Test psMinimizeLMChi2() with legitimate input values
     202    // Currently this fails, and we do not attempt to verify output
    99203    {
    100204        psMemId id = psMemGetId();
     
    158262        }
    159263        printf("Mean relative difference is %f\n", diff/(float)NUM_DATA_POINTS);
    160 
     264        skip_end();
    161265        psFree(min);
    162266        psFree(params);
     
    166270        psFree(errors);
    167271        psFree(rng);
    168         skip_end();
    169         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    170     }
    171 }
     272        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     273    }
     274}
Note: See TracChangeset for help on using the changeset viewer.