IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 6, 2006, 10:57:42 AM (20 years ago)
Author:
gusciora
Message:

This merges in rel10_ifa. However, I changed the matrix solving
routines from GaussJordan to LUD.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMinimizePolyFit.c

    r6484 r6527  
    1010 *  @author EAM, IfA
    1111 *
    12  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-02-24 23:43:15 $
     12 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-03-06 20:57:42 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4141#define PS_VECTOR_GEN_CHEBY_INDEX(VEC, SIZE, TYPE) \
    4242VEC = psVectorAlloc(SIZE, TYPE); \
     43VEC->n = VEC->nalloc; \
    4344if (TYPE == PS_TYPE_F64) { \
    4445    for (psS32 i = 0 ; i < SIZE ; i++) { \
    4546        VEC->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \
    46         VEC->n++; \
    4747    }\
    4848} else if (TYPE == PS_TYPE_F32){ \
    4949    for (psS32 i = 0 ; i < SIZE ; i++) { \
    5050        VEC->data.F32[i] = ((2.0 / ((psF32) (SIZE - 1))) * ((psF32) i)) - 1.0; \
    51         VEC->n++; \
    5251    }\
    5352}\
     
    309308    linear equations which can be easily solved.  The resulting vector is the
    310309    coefficients of the Chebyshev polys.
    311  
     310    
    312311    This method is significantly slower than the standard NR algorithm.  It
    313312    was explicitly requested that we not use the NR algorithm.
     
    370369    psImage *A = psImageAlloc(numPoly, numPoly, PS_TYPE_F64);
    371370    psVector *B = psVectorAlloc(numPoly, PS_TYPE_F64);
     371    B->n = B->nalloc;
    372372    for (psS32 i = 0 ; i < numPoly ; i++) {
    373373        for (psS32 j = 0 ; j < numPoly ; j++) {
     
    375375        }
    376376        B->data.F64[i] = ordPoly->coeff[i];
    377         B->n++;
    378377    }
    379378
     
    817816        }
    818817        for (psS32 i = 0; i < nTerm; i++) {
     818            if (myPoly->mask[i])
     819                continue;
    819820            B->data.F64[i] += f->data.F64[k] * xSums->data.F64[i] * wt;
    820821        }
     
    823824        // we must handle masked orders
    824825        for (psS32 i = 0; i < nTerm; i++) {
     826            if (myPoly->mask[i])
     827                continue;
    825828            for (psS32 j = 0; j < nTerm; j++) {
     829                if (myPoly->mask[j])
     830                    continue;
    826831                A->data.F64[i][j] += xSums->data.F64[i + j] * wt;
    827832            }
     
    829834    }
    830835
     836    // set masked elements in A,B appropriately
     837    for (int i = 0; i < nTerm; i++) {
     838        if (!myPoly->mask[i])
     839            continue;
     840        B->data.F64[i] = 0;
     841        for (int j = 0; j < nTerm; j++) {
     842            A->data.F64[i][j] = (i == j) ? 1 : 0;
     843        }
     844    }
     845
     846
     847    // XXX: rel10_ifa used psGaussJordan().  However, this failed tests.  So, I'm using psMatrixLUD().
    831848    if (0) {
    832849        // GaussJordan version
     
    840857            for (psS32 k = 0; k < nTerm; k++) {
    841858                myPoly->coeff[k] = B->data.F64[k];
     859                myPoly->coeffErr[k] = sqrt(A->data.F64[k][k]);
    842860            }
    843861        }
     
    864882                for (psS32 k = 0; k < nTerm; k++) {
    865883                    myPoly->coeff[k] = coeffs->data.F64[k];
     884                    // XXX LUD does not give inverse of A
    866885                }
    867886            }
     
    12451264        for (psS32 n = 0; n < nXterm; n++) {
    12461265            for (psS32 m = 0; m < nYterm; m++) {
     1266                if (myPoly->mask[n][m])
     1267                    continue;
    12471268                B->data.F64[n+m*nXterm] += f->data.F64[k] * Sums->data.F64[n][m] * wt;
    12481269            }
     
    12511272        for (psS32 i = 0; i < nXterm; i++) {
    12521273            for (psS32 j = 0; j < nYterm; j++) {
     1274                if (myPoly->mask[i][j])
     1275                    continue;
    12531276                for (psS32 n = 0; n < nXterm; n++) {
    12541277                    for (psS32 m = 0; m < nYterm; m++) {
     1278                        if (myPoly->mask[n][m])
     1279                            continue;
    12551280                        A->data.F64[i+j*nXterm][n+m*nXterm] += Sums->data.F64[i+n][j+m] * wt;
    12561281                    }
     1282                }
     1283            }
     1284        }
     1285    }
     1286
     1287    // set masked elements appropriately
     1288    for (int i = 0; i < nXterm; i++) {
     1289        for (int j = 0; j < nYterm; j++) {
     1290            if (!myPoly->mask[i][j])
     1291                continue;
     1292            int nx = i+j*nXterm;
     1293            B->data.F64[nx] = 0;
     1294            for (int n = 0; n < nXterm; n++) {
     1295                for (int m = 0; m < nYterm; m++) {
     1296                    int ny = n+m*nXterm;
     1297                    A->data.F64[nx][ny] = (nx == ny) ? 1 : 0;
    12571298                }
    12581299            }
     
    12691310            for (psS32 m = 0; m < nYterm; m++) {
    12701311                myPoly->coeff[n][m] = B->data.F64[n+m*nXterm];
     1312                myPoly->coeffErr[n][m] = sqrt(A->data.F64[n+m*nXterm][n+m*nXterm]);
    12711313            }
    12721314        }
     
    17231765    }
    17241766
     1767    // XXX: rel10_ifa used psGaussJordan().  However, this failed tests.  So, I'm using psMatrixLUD().
    17251768    if (0) {
    17261769        // does the solution in place
     
    17751818                            psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm;
    17761819                            myPoly->coeff[ix][iy][iz] = coeffs->data.F64[nx];
    1777                             myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]);
     1820                            // XXX myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]);
     1821                            // XXX this is wrong: A is not replaced with inverse(A), as for GaussJordan
    17781822                        }
    17791823                    }
     
    22782322
    22792323
     2324    // XXX: rel10_ifa used psGaussJordan().  However, this failed tests.  So, I'm using psMatrixLUD().
    22802325    if (0) {
    22812326        // does the solution in place
     
    23362381                                psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm;
    23372382                                myPoly->coeff[ix][iy][iz][it] = coeffs->data.F64[nx];
    2338                                 myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]);
     2383                                // myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]);
     2384                                // XXX this is wrong: LUD does not supply inverse(A)
    23392385                            }
    23402386                        }
Note: See TracChangeset for help on using the changeset viewer.