Changeset 10017 for trunk/psLib/src/math/psSparse.c
- Timestamp:
- Nov 16, 2006, 8:09:44 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psSparse.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psSparse.c
r10009 r10017 266 266 267 267 // check i,j against border->Tjj->nX,nY 268 border->Tjj->data.F32[ i][j] = value;268 border->Tjj->data.F32[j][i] = value; 269 269 return true; 270 270 } … … 278 278 PS_ASSERT_INT_NONNEGATIVE(j, false); 279 279 280 border->Bij->data.F32[ i][j] = value;280 border->Bij->data.F32[j][i] = value; 281 281 return true; 282 282 } … … 307 307 double value = 0; 308 308 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]; 310 310 } 311 311 dG->data.F32[j] = value; … … 329 329 double value = 0; 330 330 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]; 332 332 } 333 333 dF->data.F32[i] = value; … … 350 350 double value = 0; 351 351 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]; 353 353 } 354 354 dG->data.F32[i] = value; … … 372 372 373 373 // perform the operation dF = B^T*y 374 bool psSparseBorderLowerDelta (psSparseBorder *border, psVector *dG) 375 { 376 374 psVector *psSparseBorderLowerDelta (psVector *Go, psSparseBorder *border, psVector *dG) 375 { 377 376 int Nborder = border->Nborder; 378 377 378 Go = psVectorRecycle (Go, Nborder, PS_TYPE_F64); 379 psVectorInit (Go, 0.0); 380 379 381 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; 384 385 } 385 386 … … 417 418 psVector *yVec = *yFit; 418 419 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 419 428 for (int j = 0; j < Niter; j++) { 420 429 421 430 // 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); 434 449 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); 439 457 440 458 *xFit = xVec;
Note:
See TracChangeset
for help on using the changeset viewer.
