Changeset 76
Legend:
- Unmodified
- Added
- Removed
-
bdm/math/chmat.cpp
r39 r76 11 11 mat Z; 12 12 mat R; 13 mat Q; 14 Z = concat_vertical ( Ch,mat(w*v) ); 15 qr ( Z,Q,R ); 13 mat V(1,v.length()); 14 V.set_row(0,v*w); 15 Z = concat_vertical ( Ch,V ); 16 qr ( Z,R ); 16 17 Ch = R ( 0, Ch.rows()-1, 0, Ch.cols()-1 ); 17 18 }; 18 inline mat chmat::to_mat() {mat F=Ch.T()*Ch;return F;};19 inline mat chmat::to_mat() {mat F=Ch.T() *Ch;return F;}; 19 20 void chmat::mult_sym ( const mat &C ) { 20 it_error("not implemented");21 it_error ( "not implemented" ); 21 22 }; 22 void chmat::mult_sym ( const mat &C , chmat &U ) const {23 it_error("not implemented");23 void chmat::mult_sym ( const mat &C , chmat &U ) const { 24 it_error ( "not implemented" ); 24 25 }; 25 26 void chmat::mult_sym_t ( const mat &C ) { 26 it_error("not implemented");27 it_error ( "not implemented" ); 27 28 }; 28 29 void chmat::mult_sym_t ( const mat &C, chmat &U ) const { 29 it_error("not implemented");30 it_error ( "not implemented" ); 30 31 }; 31 32 double chmat::logdet() const { 32 33 double ldet=0.0; int i; 33 34 //sum of logs of (possibly negative!) diagonal entries 34 for ( i=0;i<Ch.rows();i++ ) {ldet+=log ( std::fabs(Ch ( i,i )) );}35 for ( i=0;i<Ch.rows();i++ ) {ldet+=log ( std::fabs ( Ch ( i,i ) ) );} 35 36 return 2*ldet; //compensate for Ch being sqrt() 36 37 }; … … 38 39 inline vec chmat::sqrt_mult ( const vec &v ) const {vec pom; pom = Ch*v; return pom;}; 39 40 inline double chmat::qform ( const vec &v ) const {vec pom; pom = Ch*v; return pom*pom;}; 41 inline double chmat::invqform ( const vec &v ) const { 42 vec pom(v.length()); 43 forward_substitution(Ch.T(),v,pom); 44 return pom*pom; 45 }; 40 46 inline void chmat::clear() {Ch.clear();}; -
bdm/math/chmat.h
r39 r76 21 21 /*! \brief Symmetric matrix stored in square root decomposition using upper cholesky 22 22 23 This matrix represent $A=Ch Ch'$ where only the upper triangleis stored;23 This matrix represent \f$A=Ch' Ch\f$ where only the upper triangle \f$Ch\f$ is stored; 24 24 25 25 */ … … 39 39 vec sqrt_mult ( const vec &v ) const; 40 40 double qform ( const vec &v ) const; 41 double invqform ( const vec &v ) const; 41 42 void clear(); 42 43 void add ( const chmat &A2, double w=1.0 ) {}; 43 44 //!Inversion in the same form, i.e. cholesky 44 void inv ( chmat &Inv ) const { ( Inv.Ch ) = itpp::inv ( Ch ) ;}; //ltuinv is wrong?45 void inv ( chmat &Inv ) const { ( Inv.Ch ) = itpp::inv ( Ch ).T();}; //Fixme: can be more efficient 45 46 ; 46 47 // void inv ( mat &Inv ); … … 52 53 //! Default constructor 53 54 chmat ( const vec &v) : sqmat ( v.length() ),Ch ( diag(sqrt(v)) ) {}; 55 //! Copy constructor 56 chmat ( const chmat &Ch0) : sqmat ( Ch0.dim),Ch ( Ch0.dim,Ch0.dim ) {Ch=Ch0.Ch;}; 54 57 //! Default constructor (m3k:cholform) 55 58 chmat ( const mat &M ) : sqmat ( M.rows() ),Ch ( M.rows(),M.cols() ) {