root/bdm/math/chmat.h @ 39

Revision 39, 2.3 kB (checked in by smidl, 16 years ago)

Choleski DC matrix

  • 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#include <itpp/itbase.h>
17#include "libDC.h"
18
19using namespace itpp;
20
21/*! \brief Symmetric matrix stored in square root decomposition using upper cholesky
22
23This matrix represent $A=Ch Ch'$ where only the upper triangle is stored;
24
25*/
26class chmat : public sqmat {
27protected:
28//! Upper triangle of the cholesky matrix
29        mat Ch;
30public:
31
32        void opupdt ( const vec &v, double w );
33        mat to_mat();
34        void mult_sym ( const mat &C );
35        void mult_sym ( const mat &C , chmat &U ) const;
36        void mult_sym_t ( const mat &C );
37        void mult_sym_t ( const mat &C, chmat &U ) const;
38        double logdet() const;
39        vec sqrt_mult ( const vec &v ) const;
40        double qform ( const vec &v ) const;
41        void clear();
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 );}; //ltuinv is wrong?
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        //! Default constructor (m3k:cholform)
55        chmat ( const mat &M ) : sqmat ( M.rows() ),Ch ( M.rows(),M.cols() ) {
56                mat Q;
57                it_assert_debug ( M.rows() ==M.cols(),"chmat:: input matrix must be square!" );
58                Ch=chol ( M );
59        };
60        //! Access function
61        mat & _Ch() {return Ch;}
62        //! Access functions
63        void setD ( const vec &nD ) {Ch=diag ( sqrt(nD) );}
64        //! Access functions
65        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
66
67        //! Operators
68        chmat& operator += ( const chmat &A2 );
69        chmat& operator -= ( const chmat &A2 ) ;
70};
71
72
73//////// Operations:
74//!mapping of add operation to operators
75inline chmat& chmat::operator += ( const chmat &A2 )  {this->add ( A2 );return *this;}
76//!mapping of negative add operation to operators
77inline chmat& chmat::operator -= ( const chmat &A2 )  {this->add ( A2,-1.0 );return *this;}
78#endif // CHMAT_H
Note: See TracBrowser for help on using the browser.