- Main Page
- Related Pages
- Classes
- Files

# work/git/mixpp/bdm/math/libDC.h

Go to the documentation of this file.

    00001
    00013 #ifndef DC_H
    00014 #define DC_H
    00015
    00016 #include <itpp/itbase.h>
    00017 #include "../itpp_ext.h"
    00018
    00019 using namespace itpp;
    00020
    00022 void dydr( double * r, double *f, double *Dr, double *Df, double *R, int jl, int jh, double *kr, int m, int mx );
    00023
    00025 //TODO can be done via: dtrtri.f from lapack
    00026 mat ltuinv( const mat &L );
    00027
    00032 class sqmat
    00033 {
    00034         public:
    00042                 virtual void opupdt ( const vec &v, double w ) =0;
    00043
    00047                 virtual mat to_mat() const =0;
    00048
    00052                 virtual void mult_sym ( const mat &C ) =0;
    00053
    00057                 virtual void mult_sym_t ( const mat &C ) =0;
    00058
    00059
    00064                 virtual double logdet() const =0;
    00065
    00071                 virtual vec sqrt_mult (const vec &v ) const =0;
    00072
    00077                 virtual double qform (const vec &v ) const =0;
    00078
    00083                 virtual double invqform (const vec &v ) const =0;
    00084
    00085 //      //! easy version of the
    00086 //      sqmat inv();
    00087
    00089                 virtual void clear() =0;
    00090
    00092                 int cols() const {return dim;};
    00093
    00095                 int rows() const {return dim;};
    00096
    00098                 virtual ~sqmat(){};
    00100                 sqmat(const int dim0): dim(dim0){};
    00101         protected:
    00103                 int dim;
    00104 };
    00105
    00106
    00111 class fsqmat: public sqmat
    00112 {
    00113         protected:
    00115                 mat M;
    00116         public:
    00117                 void opupdt ( const vec &v, double w );
    00118                 mat to_mat() const;
    00119                 void mult_sym ( const mat &C);
    00120                 void mult_sym_t ( const mat &C);
    00122                 void mult_sym ( const mat &C, fsqmat &U) const;
    00124                 void mult_sym_t ( const mat &C, fsqmat &U) const;
    00125                 void clear();
    00126
    00128                 fsqmat(); // mat will be initialized OK
    00130                 fsqmat(const int dim0); // mat will be initialized OK
    00132                 fsqmat ( const mat &M );
    00134                 fsqmat ( const fsqmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
    00136                 fsqmat ( const vec &d ):sqmat(d.length()){M=diag(d);};
    00137
    00139                 virtual ~fsqmat(){};
    00140
    00141
    00147                 virtual void inv ( fsqmat &Inv );
    00148
    00149                 double logdet() const {return log ( det ( M ) );};
    00150                 double qform (const  vec &v ) const {return ( v* ( M*v ) );};
    00151                 double invqform (const  vec &v ) const {return ( v* ( itpp::inv(M)*v ) );};
    00152                 vec sqrt_mult (const vec &v ) const {mat Ch=chol(M); return Ch*v;};
    00153
    00155                 void add ( const fsqmat &fsq2, double w=1.0 ){M+=fsq2.M;};
    00156
    00158                 void setD (const vec &nD){M=diag(nD);}
    00160                 vec getD (){return diag(M);}
    00162                 void setD (const vec &nD, int i){for(int j=i;j<nD.length();j++){M(j,j)=nD(j-i);}} //Fixme can be more general
    00163
    00164
    00166                 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
    00168                 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
    00170                 fsqmat& operator *= ( double x ) {M*=x;return *this;};
    00171 //              fsqmat& operator = ( const fsqmat &A) {M=A.M; return *this;};
    00173                 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
    00174
    00175 };
    00176
    00182 class ldmat: sqmat
    00183 {
    00184         public:
    00186                 ldmat ( const mat &L, const vec &D );
    00188                 ldmat (const mat &V );
    00190                 ldmat (const ldmat &V0, const ivec &perm):sqmat(V0.rows()){     ldform(V0.L.get_cols(perm), V0.D);};
    00192                 ldmat ( vec D0 );
    00194                 ldmat ();
    00196                 ldmat(const int dim0);
    00197
    00199                 virtual ~ldmat(){};
    00200
    00201                 // Reimplementation of compulsory operatios
    00202
    00203                 void opupdt ( const vec &v, double w );
    00204                 mat to_mat() const;
    00205                 void mult_sym ( const mat &C);
    00206                 void mult_sym_t ( const mat &C);
    00208                 void add ( const ldmat &ld2, double w=1.0 );
    00209                 double logdet() const;
    00210                 double qform (const vec &v ) const;
    00211                 double invqform (const vec &v ) const;
    00212                 void clear();
    00213                 int cols() const;
    00214                 int rows() const;
    00215                 vec sqrt_mult ( const vec &v ) const;
    00216
    00217
    00221                 virtual void inv ( ldmat &Inv ) const;
    00222
    00227                 void mult_sym ( const mat &C, ldmat &U) const;
    00228
    00233                 void mult_sym_t ( const mat &C, ldmat &U) const;
    00234
    00235
    00242                 void ldform (const mat &A,const vec &D0 );
    00243
    00245                 void setD (const vec &nD){D=nD;}
    00247                 void setD (const vec &nD, int i){D.replace_mid(i,nD);} //Fixme can be more general
    00249                 void setL (const vec &nL){L=nL;}
    00250
    00252                 const vec& _D() const {return D;}
    00254                 const mat& _L() const {return L;}
    00255
    00257                 ldmat& operator += ( const ldmat &ldA );
    00259                 ldmat& operator -= ( const ldmat &ldA );
    00261                 ldmat& operator *= ( double x );
    00262
    00264                 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq );
    00265
    00266         protected:
    00268                 vec D;
    00270                 mat L;
    00271
    00272 };
    00273
    00276 inline ldmat& ldmat::operator += ( const ldmat &ldA )  {this->add ( ldA );return *this;}
    00278 inline ldmat& ldmat::operator -= ( const ldmat &ldA )  {this->add ( ldA,-1.0 );return *this;}
    00280 inline int ldmat::cols() const {return dim;}
    00282 inline int ldmat::rows() const {return dim;}
    00283
    00284 #endif // DC_H