- 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
    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 );
    00036         void mult_sym ( const mat &C , chmat &U ) const;
    00037         void mult_sym_t ( const mat &C );
    00038         void mult_sym_t ( const mat &C, chmat &U ) const;
    00039         double logdet() const;
    00040         vec sqrt_mult ( const vec &v ) const;
    00041         double qform ( const vec &v ) const;
    00042         double invqform ( const vec &v ) const;
    00043         void clear();
    00045         void add ( const chmat &A2, double w = 1.0 ) {
    00046                 it_assert_debug ( dim == A2.dim, "Matrices of unequal dimension" );
    00047                 mat pre = concat_vertical ( Ch, sqrt ( w ) * A2.Ch );
    00048                 mat post = zeros ( pre.rows(), pre.cols() );
    00049                 if ( !qr ( pre, post ) ) {
    00050                         it_warning ( "Unstable QR in chmat add" );
    00051                 }
    00052                 Ch = post ( 0, dim - 1, 0, dim - 1 );
    00053         };
    00055         void inv ( chmat &Inv ) const   {
    00056                 ( Inv.Ch ) = itpp::inv ( Ch ).T();
    00057         }; //Fixme: can be more efficient
    00058         ;
    00059 //      void inv ( mat &Inv );
    00060
    00062         virtual ~chmat() {};
    00064         chmat ( ) : sqmat (), Ch ( ) {};
    00066         chmat ( const int dim0 ) : sqmat ( dim0 ), Ch ( dim0, dim0 ) {};
    00068         chmat ( const vec &v ) : sqmat ( v.length() ), Ch ( diag ( sqrt ( v ) ) ) {};
    00070         chmat ( const chmat &Ch0 ) : sqmat ( Ch0.dim ), Ch ( Ch0.dim, Ch0.dim ) {
    00071                 Ch = Ch0.Ch;
    00072         };
    00074         chmat ( const mat &M ) : sqmat ( M.rows() ), Ch ( M.rows(), M.cols() ) {
    00075                 mat Q;
    00076                 it_assert_debug ( M.rows() == M.cols(), "chmat:: input matrix must be square!" );
    00077                 Ch = chol ( M );
    00078         };
    00080         chmat ( const chmat &M, const ivec &perm ) : sqmat ( M.rows() ) {
    00081                 it_error ( "not implemneted" );
    00082         };
    00084         mat & _Ch() {
    00085                 return Ch;
    00086         }
    00088         const mat & _Ch() const {
    00089                 return Ch;
    00090         }
    00092         void setD ( const vec &nD ) {
    00093                 Ch = diag ( sqrt ( nD ) );
    00094         }
    00096         void setCh ( const vec &chQ ) {
    00097                 it_assert_debug ( chQ.length() == dim*dim, "" );
    00098                 copy_vector ( dim*dim, chQ._data(), Ch._data() );
    00099         }
    00101         void setD ( const vec &nD, int i ) {
    00102                 for ( int j = i; j < nD.length(); j++ ) {
    00103                         Ch ( j, j ) = sqrt ( nD ( j - i ) );    //Fixme can be more general
    00104                 }
    00105         }
    00106
    00108         chmat& operator += ( const chmat &A2 );
    00109         chmat& operator -= ( const chmat &A2 );
    00110         chmat& operator * ( const double &d ) {
    00111                 Ch*sqrt ( d );
    00112                 return *this;
    00113         };
    00114         chmat& operator = ( const chmat &A2 ) {
    00115                 Ch = A2.Ch;
    00116                 dim = A2.dim;
    00117                 return *this;
    00118         }
    00119         chmat& operator *= ( double x ) {
    00120                 Ch *= sqrt ( x );
    00121                 return *this;
    00122         };
    00123 };
    00124
    00125
    00128 inline chmat& chmat::operator += ( const chmat & A2 )  {
    00129         this->add ( A2 );
    00130         return *this;
    00131 }
    00133 inline chmat& chmat::operator -= ( const chmat & A2 )  {
    00134         this->add ( A2, -1.0 );
    00135         return *this;
    00136 }
    00137
    00138 }
    00139
    00140 #endif // CHMAT_H