Changeset 76

Show
Ignore:
Timestamp:
04/18/08 14:01:20 (16 years ago)
Author:
smidl
Message:

oprava chol + invqform

Location:
bdm/math
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • bdm/math/chmat.cpp

    r39 r76  
    1111        mat Z; 
    1212        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 ); 
    1617        Ch = R ( 0, Ch.rows()-1, 0, Ch.cols()-1 ); 
    1718}; 
    18 inline mat chmat::to_mat(){mat F=Ch.T()*Ch;return F;}; 
     19inline mat chmat::to_mat() {mat F=Ch.T() *Ch;return F;}; 
    1920void chmat::mult_sym ( const mat &C ) { 
    20 it_error("not implemented"); 
     21        it_error ( "not implemented" ); 
    2122}; 
    22 void chmat::mult_sym ( const mat &C , chmat &U) const { 
    23 it_error("not implemented"); 
     23void chmat::mult_sym ( const mat &C , chmat &U ) const { 
     24        it_error ( "not implemented" ); 
    2425}; 
    2526void chmat::mult_sym_t ( const mat &C ) { 
    26 it_error("not implemented"); 
     27        it_error ( "not implemented" ); 
    2728}; 
    2829void chmat::mult_sym_t ( const mat &C, chmat &U ) const { 
    29 it_error("not implemented"); 
     30        it_error ( "not implemented" ); 
    3031}; 
    3132double chmat::logdet() const { 
    3233        double ldet=0.0; int i; 
    3334        //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 ) ) );} 
    3536        return 2*ldet; //compensate for Ch being sqrt() 
    3637}; 
     
    3839inline vec chmat::sqrt_mult ( const vec &v ) const {vec pom; pom = Ch*v; return pom;}; 
    3940inline double chmat::qform ( const vec &v ) const {vec pom; pom = Ch*v; return pom*pom;}; 
     41inline double chmat::invqform ( const vec &v ) const { 
     42        vec pom(v.length()); 
     43        forward_substitution(Ch.T(),v,pom); 
     44        return pom*pom; 
     45}; 
    4046inline void chmat::clear() {Ch.clear();}; 
  • bdm/math/chmat.h

    r39 r76  
    2121/*! \brief Symmetric matrix stored in square root decomposition using upper cholesky 
    2222 
    23 This matrix represent $A=Ch Ch'$ where only the upper triangle is stored; 
     23This matrix represent \f$A=Ch' Ch\f$ where only the upper triangle \f$Ch\f$ is stored; 
    2424 
    2525*/ 
     
    3939        vec sqrt_mult ( const vec &v ) const; 
    4040        double qform ( const vec &v ) const; 
     41        double invqform ( const vec &v ) const; 
    4142        void clear(); 
    4243        void add ( const chmat &A2, double w=1.0 ) {}; 
    4344        //!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 
    4546        ; 
    4647//      void inv ( mat &Inv ); 
     
    5253        //! Default constructor 
    5354        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;}; 
    5457        //! Default constructor (m3k:cholform) 
    5558        chmat ( const mat &M ) : sqmat ( M.rows() ),Ch ( M.rows(),M.cols() ) {