root/bdm/math/chmat.h @ 230

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

mpf_delta - estimation of covariance weight

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