- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# chmat.h

Go to the documentation of this file.

    00001
    00013 #ifndef CHMAT_H
    00014 #define CHMAT_H
    00015
    00016 #include "../bdmerror.h"
    00017 #include "square_mat.h"
    00018
    00019 namespace bdm
    00020 {
    00021
    00027 class chmat : public sqmat {
    00028 protected:
    00030         mat Ch;
    00031 public:
    00032
    00033         void opupdt ( const vec &v, double w );
    00034         mat to_mat() const;
    00035         void mult_sym ( const mat &C );
    00037         void mult_sym ( const mat &C , chmat &U ) const;
    00038         void mult_sym_t ( const mat &C );
    00040         void mult_sym_t ( const mat &C, chmat &U ) const;
    00041         double logdet() const;
    00042         vec sqrt_mult ( const vec &v ) const;
    00043         double qform ( const vec &v ) const;
    00044         double invqform ( const vec &v ) const;
    00045         void clear();
    00047         void add ( const chmat &A2, double w = 1.0 ) {
    00048                 bdm_assert_debug ( dim == A2.dim, "Matrices of unequal dimension" );
    00049                 mat pre = concat_vertical ( Ch, sqrt ( w ) * A2.Ch );
    00050                 mat post = zeros ( pre.rows(), pre.cols() );
    00051                 if ( !qr ( pre, post ) ) {
    00052                         bdm_warning ( "Unstable QR in chmat add" );
    00053                 }
    00054                 Ch = post ( 0, dim - 1, 0, dim - 1 );
    00055         };
    00057         void inv ( chmat &Inv ) const   {
    00058                 ( Inv.Ch ) = itpp::inv ( Ch ).T();
    00059         }; //Fixme: can be more efficient
    00060         ;
    00061 //      void inv ( mat &Inv );
    00062
    00064         virtual ~chmat() {};
    00066         chmat ( ) : sqmat (), Ch ( ) {};
    00068         chmat ( const int dim0 ) : sqmat ( dim0 ), Ch ( dim0, dim0 ) {};
    00070         chmat ( const vec &v ) : sqmat ( v.length() ), Ch ( diag ( sqrt ( v ) ) ) {};
    00072         chmat ( const chmat &Ch0 ) : sqmat ( Ch0.dim ), Ch ( Ch0.dim, Ch0.dim ) {
    00073                 Ch = Ch0.Ch;
    00074         }
    00075
    00077         chmat ( const mat &M ) : sqmat ( M.rows() ), Ch ( M.rows(), M.cols() ) {
    00078                 mat Q;
    00079                 bdm_assert_debug ( M.rows() == M.cols(), "chmat:: input matrix must be square!" );
    00080                 Ch = chol ( M );
    00081         }
    00082
    00087         chmat ( const chmat &M, const ivec &perm ) {
    00088                 bdm_error ( "not implemented" );
    00089         }
    00090
    00092         mat & _Ch() {
    00093                 return Ch;
    00094         }
    00096         const mat & _Ch() const {
    00097                 return Ch;
    00098         }
    00100         void setD ( const vec &nD ) {
    00101                 Ch = diag ( sqrt ( nD ) );
    00102         }
    00104         void setCh ( const vec &chQ ) {
    00105                 bdm_assert_debug ( chQ.length() == dim * dim, "wrong length" );
    00106                 copy_vector ( dim*dim, chQ._data(), Ch._data() );
    00107         }
    00108
    00110         void setD ( const vec &nD, int i ) {
    00111                 for ( int j = i; j < nD.length(); j++ ) {
    00112                         Ch ( j, j ) = sqrt ( nD ( j - i ) );    //Fixme can be more general
    00113                 }
    00114         }
    00115
    00117         chmat& operator += ( const chmat &A2 );
    00119         chmat& operator -= ( const chmat &A2 );
    00121         chmat& operator * ( const double &d ) {
    00122                 Ch*sqrt ( d );
    00123                 return *this;
    00124         };
    00126         chmat& operator = ( const chmat &A2 ) {
    00127                 Ch = A2.Ch;
    00128                 dim = A2.dim;
    00129                 return *this;
    00130         }
    00132         chmat& operator *= ( double x ) {
    00133                 Ch *= sqrt ( x );
    00134                 return *this;
    00135         };
    00136 };
    00137
    00138
    00141 inline chmat& chmat::operator += ( const chmat & A2 )  {
    00142         this->add ( A2 );
    00143         return *this;
    00144 }
    00146 inline chmat& chmat::operator -= ( const chmat & A2 )  {
    00147         this->add ( A2, -1.0 );
    00148         return *this;
    00149 }
    00150
    00151 }
    00152
    00153 #endif // CHMAT_H