root/bdm/math/chmat.h @ 262

Revision 262, 2.8 kB (checked in by smidl, 15 years ago)

cleanup of include files

  • Property svn:eol-style set to native
Line 
1/*!
2 * \file
3 * \brief Matrices in decomposed forms (LDL', LU, UDU', etc).
4 * \author Vaclav Smidl.
5 *
6 * -----------------------------------
7 * BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8 *
9 * Using IT++ for numerical operations
10 * -----------------------------------
11 */
12
13#ifndef CHMAT_H
14#define CHMAT_H
15
16
17#include "libDC.h"
18
19/*! \brief Symmetric matrix stored in square root decomposition using upper cholesky
20
21This matrix represent \f$A=Ch' Ch\f$ where only the upper triangle \f$Ch\f$ is stored;
22
23*/
24class chmat : public sqmat {
25protected:
26//! Upper triangle of the cholesky matrix
27        mat Ch;
28public:
29
30        void opupdt ( const vec &v, double w );
31        mat to_mat() const;
32        void mult_sym ( const mat &C );
33        void mult_sym ( const mat &C , chmat &U ) const;
34        void mult_sym_t ( const mat &C );
35        void mult_sym_t ( const mat &C, chmat &U ) const;
36        double logdet() const;
37        vec sqrt_mult ( const vec &v ) const;
38        double qform ( const vec &v ) const;
39        double invqform ( const vec &v ) const;
40        void clear();
41        //! add another chmat \c A2 with weight \c w.
42        void add ( const chmat &A2, double w=1.0 ) {};
43        //!Inversion in the same form, i.e. cholesky
44        void inv ( chmat &Inv ) const   { ( Inv.Ch ) = itpp::inv ( Ch ).T();}; //Fixme: can be more efficient
45        ;
46//      void inv ( mat &Inv );
47
48        //! Destructor for future use;
49        virtual ~chmat() {};
50        //! Default constructor
51        chmat ( const int dim0 ) : sqmat ( dim0 ),Ch ( dim0,dim0 ) {};
52        //! Default constructor
53        chmat ( const vec &v) : sqmat ( v.length() ),Ch ( diag(sqrt(v)) ) {};
54        //! Copy constructor
55        chmat ( const chmat &Ch0) : sqmat ( Ch0.dim),Ch ( Ch0.dim,Ch0.dim ) {Ch=Ch0.Ch;};
56        //! Default constructor (m3k:cholform)
57        chmat ( const mat &M ) : sqmat ( M.rows() ),Ch ( M.rows(),M.cols() ) {
58                mat Q;
59                it_assert_debug ( M.rows() ==M.cols(),"chmat:: input matrix must be square!" );
60                Ch=chol ( M );
61        };
62        //! Constructor
63        chmat ( const chmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
64        //! Access function
65        mat & _Ch() {return Ch;}
66        //! Access functions
67        void setD ( const vec &nD ) {Ch=diag ( sqrt(nD) );}
68        //! Access functions
69        void setD ( const vec &nD, int i ) {for ( int j=i;j<nD.length();j++ ) {Ch( j,j ) =sqrt(nD ( j-i ));}} //Fixme can be more general
70
71        //! Operators
72        chmat& operator += ( const chmat &A2 );
73        chmat& operator -= ( const chmat &A2 ) ;
74        chmat& operator * ( const chmat &A2 );
75        chmat& operator * ( const double &d ){Ch*d; return *this;};
76        chmat& operator = ( const chmat &A2 ){Ch=A2.Ch;dim=A2.dim;return *this;}
77};
78
79
80//////// Operations:
81//!mapping of add operation to operators
82inline chmat& chmat::operator += ( const chmat &A2 )  {this->add ( A2 );return *this;}
83//!mapping of negative add operation to operators
84inline chmat& chmat::operator -= ( const chmat &A2 )  {this->add ( A2,-1.0 );return *this;}
85
86#endif // CHMAT_H
Note: See TracBrowser for help on using the browser.