- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

# libDC.h

Go to the documentation of this file.

    00001
    00013 #ifndef DC_H
    00014 #define DC_H
    00015
    00016
    00017 #include "../itpp_ext.h"
    00018
    00024 using namespace itpp;
    00025
    00027 void dydr( double * r, double *f, double *Dr, double *Df, double *R, int jl, int jh, double *kr, int m, int mx );
    00028
    00030 //TODO can be done via: dtrtri.f from lapack
    00031 mat ltuinv( const mat &L );
    00032
    00037 class sqmat
    00038 {
    00039         public:
    00047                 virtual void opupdt ( const vec &v, double w ) =0;
    00048
    00052                 virtual mat to_mat() const =0;
    00053
    00057                 virtual void mult_sym ( const mat &C ) =0;
    00058
    00062                 virtual void mult_sym_t ( const mat &C ) =0;
    00063
    00064
    00069                 virtual double logdet() const =0;
    00070
    00076                 virtual vec sqrt_mult (const vec &v ) const =0;
    00077
    00082                 virtual double qform (const vec &v ) const =0;
    00083
    00088                 virtual double invqform (const vec &v ) const =0;
    00089
    00090 //      //! easy version of the
    00091 //      sqmat inv();
    00092
    00094                 virtual void clear() =0;
    00095
    00097                 int cols() const {return dim;};
    00098
    00100                 int rows() const {return dim;};
    00101
    00103                 virtual ~sqmat(){};
    00105                 sqmat(const int dim0): dim(dim0){};
    00107                 sqmat(): dim(0){};
    00108         protected:
    00110                 int dim;
    00111 };
    00112
    00113
    00118 class fsqmat: public sqmat
    00119 {
    00120         protected:
    00122                 mat M;
    00123         public:
    00124                 void opupdt ( const vec &v, double w );
    00125                 mat to_mat() const;
    00126                 void mult_sym ( const mat &C);
    00127                 void mult_sym_t ( const mat &C);
    00129                 void mult_sym ( const mat &C, fsqmat &U) const;
    00131                 void mult_sym_t ( const mat &C, fsqmat &U) const;
    00132                 void clear();
    00133
    00135                 fsqmat(){}; // mat will be initialized OK
    00137                 fsqmat(const int dim0); // mat will be initialized OK
    00139                 fsqmat ( const mat &M );
    00141                 fsqmat ( const fsqmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
    00143                 fsqmat ( const vec &d ):sqmat(d.length()){M=diag(d);};
    00144
    00146                 virtual ~fsqmat(){};
    00147
    00148
    00154                 virtual void inv ( fsqmat &Inv );
    00155
    00156                 double logdet() const {return log ( det ( M ) );};
    00157                 double qform (const  vec &v ) const {return ( v* ( M*v ) );};
    00158                 double invqform (const  vec &v ) const {return ( v* ( itpp::inv(M)*v ) );};
    00159                 vec sqrt_mult (const vec &v ) const {mat Ch=chol(M); return Ch*v;};
    00160
    00162                 void add ( const fsqmat &fsq2, double w=1.0 ){M+=fsq2.M;};
    00163
    00165                 void setD (const vec &nD){M=diag(nD);}
    00167                 vec getD (){return diag(M);}
    00169                 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
    00170
    00171
    00173                 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
    00175                 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
    00177                 fsqmat& operator *= ( double x ) {M*=x;return *this;};
    00178 //              fsqmat& operator = ( const fsqmat &A) {M=A.M; return *this;};
    00180                 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
    00181
    00182 };
    00183
    00189 class ldmat: sqmat
    00190 {
    00191         public:
    00193                 ldmat ( const mat &L, const vec &D );
    00195                 ldmat (const mat &V );
    00197                 ldmat (const ldmat &V0, const ivec &perm):sqmat(V0.rows()){     ldform(V0.L.get_cols(perm), V0.D);};
    00199                 ldmat ( vec D0 );
    00201                 ldmat ();
    00203                 ldmat(const int dim0);
    00204
    00206                 virtual ~ldmat(){};
    00207
    00208                 // Reimplementation of compulsory operatios
    00209
    00210                 void opupdt ( const vec &v, double w );
    00211                 mat to_mat() const;
    00212                 void mult_sym ( const mat &C);
    00213                 void mult_sym_t ( const mat &C);
    00215                 void add ( const ldmat &ld2, double w=1.0 );
    00216                 double logdet() const;
    00217                 double qform (const vec &v ) const;
    00218                 double invqform (const vec &v ) const;
    00219                 void clear();
    00220                 int cols() const;
    00221                 int rows() const;
    00222                 vec sqrt_mult ( const vec &v ) const;
    00223
    00224
    00228                 virtual void inv ( ldmat &Inv ) const;
    00229
    00234                 void mult_sym ( const mat &C, ldmat &U) const;
    00235
    00240                 void mult_sym_t ( const mat &C, ldmat &U) const;
    00241
    00242
    00249                 void ldform (const mat &A,const vec &D0 );
    00250
    00252                 void setD (const vec &nD){D=nD;}
    00254                 void setD (const vec &nD, int i){D.replace_mid(i,nD);} //Fixme can be more general
    00256                 void setL (const vec &nL){L=nL;}
    00257
    00259                 const vec& _D() const {return D;}
    00261                 const mat& _L() const {return L;}
    00262
    00264                 ldmat& operator += ( const ldmat &ldA );
    00266                 ldmat& operator -= ( const ldmat &ldA );
    00268                 ldmat& operator *= ( double x );
    00269
    00271                 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq );
    00272
    00273         protected:
    00275                 vec D;
    00277                 mat L;
    00278
    00279 };
    00280
    00283 inline ldmat& ldmat::operator += ( const ldmat &ldA )  {this->add ( ldA );return *this;}
    00285 inline ldmat& ldmat::operator -= ( const ldmat &ldA )  {this->add ( ldA,-1.0 );return *this;}
    00287 inline int ldmat::cols() const {return dim;}
    00289 inline int ldmat::rows() const {return dim;}
    00290
    00293 #endif // DC_H