Changeset 7102
- Timestamp:
- May 9, 2006, 2:49:38 PM (20 years ago)
- Location:
- trunk/psLib/src/math
- Files:
-
- 3 edited
-
psMatrix.h (modified) (2 diffs)
-
psMinimizeLMM.c (modified) (3 diffs)
-
psMinimizeLMM.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.h
r4589 r7102 21 21 * @author Ross Harman, MHPCC 22 22 * 23 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $24 * @date $Date: 200 5-07-21 01:40:10$23 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2006-05-10 00:49:38 $ 25 25 * 26 26 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 62 62 const psVector* RHS, ///< Vector right-hand-side of equation. 63 63 const psVector* perm ///< Permutation vector resulting from psMatrixLUD function. 64 ); 65 66 /** Gauss-Jordan numerical solver. 67 * 68 * @return bool: True if successful. 69 */ 70 bool psMatrixGJSolve( 71 psImage *a, ///< Matrix to be solved 72 psVector *b ///< Vector of values 64 73 ); 65 74 -
trunk/psLib/src/math/psMinimizeLMM.c
r6942 r7102 10 10 * @author EAM, IfA 11 11 * 12 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-0 4-21 21:18:44$12 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-05-10 00:49:38 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 114 114 } 115 115 116 if (false == ps GaussJordan(Alpha, Beta)) {116 if (false == psMatrixGJSolve(Alpha, Beta)) { 117 117 psTrace (__func__, 4, "singular matrix in Guess ABP\n"); 118 118 return(false); … … 514 514 } 515 515 516 // This is a temporary gauss-jordan solver based on gene's517 // version based on the Numerical Recipes version518 bool psGaussJordan(519 psImage *a,520 psVector *b)521 {522 int *indxc,*indxr,*ipiv;523 int Nx, icol, irow;524 int i, j, k, l, ll;525 float big, dum, pivinv;526 psF64 *vector;527 psF64 **matrix;528 529 Nx = a->numCols;530 matrix = a->data.F64;531 vector = b->data.F64;532 533 indxc = psAlloc(Nx*sizeof(int));534 indxr = psAlloc(Nx*sizeof(int));535 ipiv = psAlloc(Nx*sizeof(int));536 for (j = 0; j < Nx; j++) {537 ipiv[j] = 0;538 }539 540 irow = icol = 0;541 big = fabs(matrix[0][0]);542 543 for (i = 0; i < Nx; i++) {544 big = 0.0;545 for (j = 0; j < Nx; j++) {546 if (!isfinite(matrix[i][j])) {547 psTrace (__func__, 3, "Input matrix contains NaNs: matrix[%d][%d] is %.2f\n", i, j, matrix[i][j]);548 goto fescape;549 }550 if (ipiv[j] != 1) {551 for (k = 0; k < Nx; k++) {552 if (ipiv[k] == 0) {553 if (fabs (matrix[j][k]) >= big) {554 big = fabs(matrix[j][k]);555 irow = j;556 icol = k;557 }558 } else {559 if (ipiv[k] > 1) {560 psTrace (__func__, 3, "Singular Matrix (1).\n");561 goto fescape;562 }563 }564 }565 }566 }567 ipiv[icol]++;568 if (irow != icol) {569 for (l = 0; l < Nx; l++) {570 PS_SWAP(matrix[irow][l], matrix[icol][l]);571 }572 PS_SWAP(vector[irow], vector[icol]);573 }574 indxr[i] = irow;575 indxc[i] = icol;576 if (matrix[icol][icol] == 0.0) {577 psTrace (__func__, 3, "Singular Matrix (2).\n");578 goto fescape;579 }580 pivinv = 1.0 / matrix[icol][icol];581 matrix[icol][icol] = 1.0;582 for (l = 0; l < Nx; l++) {583 matrix[icol][l] *= pivinv;584 }585 vector[icol] *= pivinv;586 587 for (ll = 0; ll < Nx; ll++) {588 if (ll != icol) {589 dum = matrix[ll][icol];590 matrix[ll][icol] = 0.0;591 for (l = 0; l < Nx; l++) {592 matrix[ll][l] -= matrix[icol][l]*dum;593 }594 vector[ll] -= vector[icol]*dum;595 }596 }597 }598 599 for (l = Nx - 1; l >= 0; l--) {600 if (indxr[l] != indxc[l]) {601 for (k = 0; k < Nx; k++) {602 PS_SWAP(matrix[k][indxr[l]], matrix[k][indxc[l]]);603 }604 }605 }606 psFree(ipiv);607 psFree(indxr);608 psFree(indxc);609 return(true);610 611 fescape:612 psFree(ipiv);613 psFree(indxr);614 psFree(indxc);615 return(false);616 }617 618 516 static void minimizationFree(psMinimization *min) 619 517 { -
trunk/psLib/src/math/psMinimizeLMM.h
r6437 r7102 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 2-17 00:56:48 $10 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-05-10 00:49:38 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 55 55 /** A data structure for minimization routines. 56 56 * 57 * 57 * 58 58 */ 59 59 typedef struct … … 145 145 146 146 147 /** Gauss-Jordan numerical solver.148 *149 * @return bool: True if successful.150 */151 bool psGaussJordan(152 psImage *a, ///< Matrix to be solved153 psVector *b ///< Vector of values154 );155 156 147 /* \} */// End of MathGroup Functions 157 148
Note:
See TracChangeset
for help on using the changeset viewer.
