Changeset 477 for library/bdm/math/chmat.cpp
- Timestamp:
- 08/05/09 14:40:03 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/math/chmat.cpp
r455 r477 9 9 mat Z; 10 10 mat R; 11 mat V (1,v.length());12 V.set_row (0,v*sqrt(w));13 Z = concat_vertical ( Ch, V );14 qr ( Z, R );15 Ch = R ( 0, Ch.rows() -1, 0, Ch.cols()-1 );11 mat V ( 1, v.length() ); 12 V.set_row ( 0, v*sqrt ( w ) ); 13 Z = concat_vertical ( Ch, V ); 14 qr ( Z, R ); 15 Ch = R ( 0, Ch.rows() - 1, 0, Ch.cols() - 1 ); 16 16 }; 17 mat chmat::to_mat() const {mat F=Ch.T() *Ch;return F;}; 17 mat chmat::to_mat() const { 18 mat F = Ch.T() * Ch; 19 return F; 20 }; 18 21 void chmat::mult_sym ( const mat &C ) { 19 it_assert_debug(C.rows()==dim, "Wrong dimension of U"); 20 if(!qr(Ch*C.T(), Ch)) {it_warning("QR unstable in chmat mult_sym");} 22 it_assert_debug ( C.rows() == dim, "Wrong dimension of U" ); 23 if ( !qr ( Ch*C.T(), Ch ) ) { 24 it_warning ( "QR unstable in chmat mult_sym" ); 25 } 21 26 }; 22 27 void chmat::mult_sym ( const mat &C , chmat &U ) const { 23 it_assert_debug(C.rows()==U.dim, "Wrong dimension of U"); 24 if(!qr(Ch*C.T(), U.Ch)) {it_warning("QR unstable in chmat mult_sym");} 28 it_assert_debug ( C.rows() == U.dim, "Wrong dimension of U" ); 29 if ( !qr ( Ch*C.T(), U.Ch ) ) { 30 it_warning ( "QR unstable in chmat mult_sym" ); 31 } 25 32 }; 26 33 void chmat::mult_sym_t ( const mat &C ) { 27 it_assert_debug(C.cols()==dim, "Wrong dimension of U"); 28 if(!qr(Ch*C, Ch)) {it_warning("QR unstable in chmat mult_sym");} 34 it_assert_debug ( C.cols() == dim, "Wrong dimension of U" ); 35 if ( !qr ( Ch*C, Ch ) ) { 36 it_warning ( "QR unstable in chmat mult_sym" ); 37 } 29 38 }; 30 39 void chmat::mult_sym_t ( const mat &C, chmat &U ) const { 31 it_assert_debug(C.cols()==U.dim, "Wrong dimension of U"); 32 if(!qr(Ch*C, U.Ch)) {it_warning("QR unstable in chmat mult_sym");} 40 it_assert_debug ( C.cols() == U.dim, "Wrong dimension of U" ); 41 if ( !qr ( Ch*C, U.Ch ) ) { 42 it_warning ( "QR unstable in chmat mult_sym" ); 43 } 33 44 }; 34 45 double chmat::logdet() const { 35 double ldet=0.0; int i; 46 double ldet = 0.0; 47 int i; 36 48 //sum of logs of (possibly negative!) diagonal entries 37 for ( i=0;i<Ch.rows();i++ ) {ldet+=log ( std::fabs ( Ch ( i,i ) ) );} 49 for ( i = 0; i < Ch.rows(); i++ ) { 50 ldet += log ( std::fabs ( Ch ( i, i ) ) ); 51 } 38 52 return 2*ldet; //compensate for Ch being sqrt() 39 53 }; 40 54 //TODO can be done more efficiently using BLAS, see triangular matrices 41 vec chmat::sqrt_mult ( const vec &v ) const {vec pom; pom = Ch*v; return pom;}; 42 double chmat::qform ( const vec &v ) const {vec pom; pom = Ch*v; return pom*pom;}; 43 double chmat::invqform ( const vec &v ) const { 44 vec pom(v.length()); 45 forward_substitution(Ch.T(),v,pom); 55 vec chmat::sqrt_mult ( const vec &v ) const { 56 vec pom; 57 pom = Ch * v; 58 return pom; 59 }; 60 double chmat::qform ( const vec &v ) const { 61 vec pom; 62 pom = Ch * v; 46 63 return pom*pom; 47 64 }; 48 void chmat::clear() {Ch.clear();}; 65 double chmat::invqform ( const vec &v ) const { 66 vec pom ( v.length() ); 67 forward_substitution ( Ch.T(), v, pom ); 68 return pom*pom; 69 }; 70 void chmat::clear() { 71 Ch.clear(); 72 };