IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 16, 2006, 8:09:44 AM (19 years ago)
Author:
magnier
Message:

finished psSparseBorder, runs tests ok

File:
1 edited

Legend:

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

    r10009 r10017  
    266266
    267267    // check i,j against border->Tjj->nX,nY
    268     border->Tjj->data.F32[i][j] = value;
     268    border->Tjj->data.F32[j][i] = value;
    269269    return true;
    270270}
     
    278278    PS_ASSERT_INT_NONNEGATIVE(j, false);
    279279
    280     border->Bij->data.F32[i][j] = value;
     280    border->Bij->data.F32[j][i] = value;
    281281    return true;
    282282}
     
    307307        double value = 0;
    308308        for (int i = 0; i < Nrows; i++) {
    309             value += border->Bij->data.F32[i][j] * xVec->data.F32[i];
     309            value += border->Bij->data.F32[j][i] * xVec->data.F32[i];
    310310        }
    311311        dG->data.F32[j] = value;
     
    329329        double value = 0;
    330330        for (int j = 0; j < Nborder; j++) {
    331             value += border->Bij->data.F32[i][j] * yVec->data.F32[j];
     331            value += border->Bij->data.F32[j][i] * yVec->data.F32[j];
    332332        }
    333333        dF->data.F32[i] = value;
     
    350350        double value = 0;
    351351        for (int j = 0; j < Nborder; j++) {
    352             value += border->Tjj->data.F32[j][i] * yVec->data.F32[j];
     352            value += border->Tjj->data.F32[i][j] * yVec->data.F32[j];
    353353        }
    354354        dG->data.F32[i] = value;
     
    372372
    373373// perform the operation dF = B^T*y
    374 bool psSparseBorderLowerDelta (psSparseBorder *border, psVector *dG)
    375 {
    376 
     374psVector *psSparseBorderLowerDelta (psVector *Go, psSparseBorder *border, psVector *dG)
     375{
    377376    int Nborder = border->Nborder;
    378377
     378    Go = psVectorRecycle (Go, Nborder, PS_TYPE_F64);
     379    psVectorInit (Go, 0.0);
     380
    379381    for (int i = 0; i < Nborder; i++) {
    380         border->Gj->data.F32[i] -= dG->data.F32[i];
    381     }
    382 
    383     return true;
     382        Go->data.F64[i] = border->Gj->data.F32[i] - dG->data.F32[i];
     383    }
     384    return Go;
    384385}
    385386
     
    417418    psVector *yVec = *yFit;
    418419
     420    // save the original value of Bfj, alloc other temp vectors
     421    // XXX be careful about TYPE requirements of support functions...
     422    psVector *Fo = psVectorCopy (NULL, border->sparse->Bfj, PS_TYPE_F32);
     423    psVector *dF = psVectorAlloc (border->Nrows, PS_TYPE_F32);
     424    psVector *Go = psVectorAlloc (border->Nborder, PS_TYPE_F64);
     425    psVector *dG = psVectorAlloc (border->Nborder, PS_TYPE_F32);
     426    psImage *square = psImageAlloc (border->Nborder, border->Nborder, PS_TYPE_F64);
     427
    419428    for (int j = 0; j < Niter; j++) {
    420429
    421430        // solve Sx = f
    422         xVec = psSparseSolve(xVec, constraint, border->sparse, Niter);
    423 
    424         psVector *dG = psSparseBorderLowerProduct (NULL, border, xVec);
    425         psSparseBorderLowerDelta (border, dG);
    426 
    427         // XXX not defined
    428         psImage *square = psImageCopy (NULL, border->Tjj, PS_TYPE_F32);
    429         psVectorCopy (yVec, border->Gj, PS_TYPE_F32);
    430         psMatrixGJSolve (square, yVec);
    431         psFree (square);
    432 
    433         psVector *dF = psSparseBorderUpperProduct (NULL, border, yVec);
     431        xVec = psSparseSolve(xVec, constraint, border->sparse, 4);
     432
     433        dG = psSparseBorderLowerProduct (dG, border, xVec);
     434
     435        // XXX i have an error here: i'm not
     436        // I need to reset to the original value of g before subtracting
     437        // XXX this function returns an psVector:F64 so we can us it in GJ
     438        Go = psSparseBorderLowerDelta (Go, border, dG);
     439
     440        // use gauss-jordan to solve the lower square
     441        // square is modified by GJSolve, so re-copy each time
     442        square = psImageCopy (square, border->Tjj, PS_TYPE_F64);
     443        psMatrixGJSolve (square, Go);
     444        yVec = psVectorCopy (yVec, Go, PS_TYPE_F32);
     445
     446        // calculate the delta relative to the original Bfj:
     447        border->sparse->Bfj = psVectorCopy (border->sparse->Bfj, Fo, PS_TYPE_F32);
     448        dF = psSparseBorderUpperProduct (dF, border, yVec);
    434449        psSparseBorderUpperDelta (border, dF);
    435 
    436         psFree (dF);
    437         psFree (dG);
    438     }
     450    }
     451
     452    psFree (dG);
     453    psFree (Go);
     454    psFree (dF);
     455    psFree (Fo);
     456    psFree (square);
    439457
    440458    *xFit = xVec;
Note: See TracChangeset for help on using the changeset viewer.