IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 22, 2006, 7:27:06 PM (19 years ago)
Author:
magnier
Message:

added test for non-normal matrix equation

File:
1 edited

Legend:

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

    r10015 r10170  
    88int main (void)
    99{
    10     plan_tests(23);
     10    plan_tests(26);
    1111
    1212    diag("psSparse() tests");
    1313
    14     // test psSparseSolve for a simple example matrix
     14    // test psSparseSolve for a simple normal example matrix
    1515    {
    1616        psMemId id = psMemGetId();
    1717
    18         diag ("solve a simple, small matrix equation ");
     18        diag ("solve a normalized matrix equation with psSparseSolve");
    1919
    2020        // the basic equation is Ax = b
     
    3131        {
    3232            psSparseMatrixElement (matrix, i, i, 1.0);
     33            if (i + 1 < 100) {
     34                psSparseMatrixElement (matrix, i + 1, i, 0.1);
     35            }
     36        }
     37
     38        // incoming matrix elements do not need to be in order; sort before
     39        // applying sparse matrix
     40        psSparseResort (matrix);
     41
     42        psVector *xRef = psVectorAlloc (100, PS_TYPE_F32);
     43        for (int i = 0; i < 100; i++)
     44        {
     45            xRef->data.F32[i] = 1.0;
     46        }
     47
     48        psVector *bVec = psSparseMatrixTimesVector (NULL, matrix, xRef);
     49
     50        for (int i = 0; i < 100; i++)
     51        {
     52            psSparseVectorElement (matrix, i, bVec->data.F32[i]);
     53        }
     54
     55        psSparseConstraint constraint;
     56        constraint.paramMin   = 0.0;
     57        constraint.paramMax   = 1e8;
     58        constraint.paramDelta = 1e8;
     59
     60        // solve for normalization terms (need include local sky?)
     61        psVector *xFit = psSparseSolve (NULL, constraint, matrix, 4);
     62
     63        // measure stdev between xFit and xRes
     64        float dS = 0;
     65        float dS2 = 0;
     66        for (int i = 0; i < 100; i++)
     67        {
     68            float dX = xRef->data.F32[i] - xFit->data.F32[i];
     69            // fprintf (stderr, "%5.3f %5.3f %5.3f %5.3f\n", bVec->data.F32[i], xRef->data.F32[i], xFit->data.F32[i], dX);
     70            dS2 += PS_SQR(dX);
     71            dS += dX;
     72        }
     73        dS /= 100.0;
     74        dS2 = sqrt (dS2/100.0 - dS*dS);
     75
     76        ok_float_tol (dS2, 0.0, 1e-4, "scatter: %.20f", dS2);
     77
     78        psFree (matrix);
     79        psFree (xRef);
     80        psFree (bVec);
     81        psFree (xFit);
     82
     83        skip_end();
     84        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     85    }
     86
     87    // test psSparseSolve for a simple non-normal example matrix
     88    {
     89        psMemId id = psMemGetId();
     90
     91        diag ("solve a non-normalized matrix equation with psSparseSolve");
     92
     93        // the basic equation is Ax = b
     94
     95        // create a matrix A with diagonals of 1 and a small number of off diagonal elements.
     96        // construct a vector x, construct the corresponding vector b by multiplication. solve
     97        // Ax = b for x using psSparseSolve.  compare with the input values for x.
     98
     99        psSparse *matrix = psSparseAlloc (100, 100);
     100        ok(matrix != NULL, "psSparse successfully allocated");
     101        skip_start(matrix == NULL, 5, "Skipping tests because psSparseAlloc() failed");
     102
     103        for (int i = 0; i < 100; i++)
     104        {
     105            psSparseMatrixElement (matrix, i, i, 5.0);
    33106            if (i + 1 < 100) {
    34107                psSparseMatrixElement (matrix, i + 1, i, 0.1);
Note: See TracChangeset for help on using the changeset viewer.