root/bdm/math/chmat.h @ 254

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

create namespace bdm

  • 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#include "../itpp_ext.h"
19
20/*! \brief Symmetric matrix stored in square root decomposition using upper cholesky
21
22This matrix represent \f$A=Ch' Ch\f$ where only the upper triangle \f$Ch\f$ is stored;
23
24*/
25class chmat : public sqmat {
26protected:
27//! Upper triangle of the cholesky matrix
28        mat Ch;
29public:
30
31        void opupdt ( const vec &v, double w );
32        mat to_mat() const;
33        void mult_sym ( const mat &C );
34        void mult_sym ( const mat &C , chmat &U ) const;
35        void mult_sym_t ( const mat &C );
36        void mult_sym_t ( const mat &C, chmat &U ) const;
37        double logdet() const;
38        vec sqrt_mult ( const vec &v ) const;
39        double qform ( const vec &v ) const;
40        double invqform ( const vec &v ) const;
41        void clear();
42        //! add another chmat \c A2 with weight \c w.
43        void add ( const chmat &A2, double w=1.0 ) {};
44        //!Inversion in the same form, i.e. cholesky
45        void inv ( chmat &Inv ) const   { ( Inv.Ch ) = itpp::inv ( Ch ).T();}; //Fixme: can be more efficient
46        ;
47//      void inv ( mat &Inv );
48
49        //! Destructor for future use;
50        virtual ~chmat() {};
51        //! Default constructor
52        chmat ( const int dim0 ) : sqmat ( dim0 ),Ch ( dim0,dim0 ) {};
53        //! Default constructor
54        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;};
57        //! Default constructor (m3k:cholform)
58        chmat ( const mat &M ) : sqmat ( M.rows() ),Ch ( M.rows(),M.cols() ) {
59                mat Q;
60                it_assert_debug ( M.rows() ==M.cols(),"chmat:: input matrix must be square!" );
61                Ch=chol ( M );
62        };
63        //! Constructor
64        chmat ( const chmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
65        //! Access function
66        mat & _Ch() {return Ch;}
67        //! Access functions
68        void setD ( const vec &nD ) {Ch=diag ( sqrt(nD) );}
69        //! Access functions
70        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
71
72        //! Operators
73        chmat& operator += ( const chmat &A2 );
74        chmat& operator -= ( const chmat &A2 ) ;
75        chmat& operator * ( const chmat &A2 );
76        chmat& operator * ( const double &d ){Ch*d; return *this;};
77        chmat& operator = ( const chmat &A2 ){Ch=A2.Ch;dim=A2.dim;return *this;}
78};
79
80
81//////// Operations:
82//!mapping of add operation to operators
83inline chmat& chmat::operator += ( const chmat &A2 )  {this->add ( A2 );return *this;}
84//!mapping of negative add operation to operators
85inline chmat& chmat::operator -= ( const chmat &A2 )  {this->add ( A2,-1.0 );return *this;}
86
87#endif // CHMAT_H
Note: See TracBrowser for help on using the browser.