- Main Page
- Classes
- Files
- Related Pages

# work/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
    00018 using namespace itpp;
    00019
    00021 void dydr( double * r, double *f, double *Dr, double *Df, double *R, int jl, int jh, double *kr, int m, int mx );
    00022
    00024 //TODO can be done via: dtrtri.f from lapack
    00025 mat ltuinv( const mat &L );
    00026
    00031 class sqmat
    00032 {
    00033         public:
    00041                 virtual void opupdt ( const vec &v, double w ) =0;
    00042
    00046                 virtual mat to_mat() =0;
    00047
    00051                 virtual void mult_sym ( const mat &C ) =0;
    00052
    00056                 virtual void mult_sym_t ( const mat &C ) =0;
    00057
    00058
    00063                 virtual double logdet() const =0;
    00064
    00070                 virtual vec sqrt_mult (const vec &v ) const =0;
    00071
    00076                 virtual double qform (const vec &v ) const =0;
    00077
    00082                 virtual double invqform (const vec &v ) const =0;
    00083
    00084 //      //! easy version of the
    00085 //      sqmat inv();
    00086
    00088                 virtual void clear() =0;
    00089
    00091                 int cols() const {return dim;};
    00092
    00094                 int rows() const {return dim;};
    00095
    00097                 virtual ~sqmat(){};
    00099                 sqmat(const int dim0): dim(dim0){};
    00100         protected:
    00102                 int dim;
    00103 };
    00104
    00105
    00110 class fsqmat: public sqmat
    00111 {
    00112         protected:
    00114                 mat M;
    00115         public:
    00116                 void opupdt ( const vec &v, double w );
    00117                 mat to_mat() ;
    00118                 void mult_sym ( const mat &C);
    00119                 void mult_sym_t ( const mat &C);
    00121                 void mult_sym ( const mat &C, fsqmat &U) const;
    00123                 void mult_sym_t ( const mat &C, fsqmat &U) const;
    00124                 void clear();
    00125
    00127                 fsqmat(); // mat will be initialized OK
    00129                 fsqmat(const int dim0); // mat will be initialized OK
    00131                 fsqmat ( const mat &M );
    00133                 fsqmat ( const vec &d ):sqmat(d.length()){M=diag(d);};
    00134
    00136                 virtual ~fsqmat(){};
    00137
    00138
    00144                 virtual void inv ( fsqmat &Inv );
    00145
    00146                 double logdet() const {return log ( det ( M ) );};
    00147                 double qform (const  vec &v ) const {return ( v* ( M*v ) );};
    00148                 double invqform (const  vec &v ) const {return ( v* ( itpp::inv(M)*v ) );};
    00149                 vec sqrt_mult (const vec &v ) const {mat Ch=chol(M); return Ch*v;};
    00150
    00152                 void setD (const vec &nD){M=diag(nD);}
    00154                 vec getD (){return diag(M);}
    00156                 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
    00157
    00159                 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
    00161                 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
    00163                 fsqmat& operator *= ( double x ) {M*=x;return *this;};
    00164 //              fsqmat& operator = ( const fsqmat &A) {M=A.M; return *this;};
    00166                 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
    00167
    00168 };
    00169
    00175 class ldmat: sqmat
    00176 {
    00177         public:
    00178
    00180                 ldmat ( const mat &L, const vec &D );
    00182                 ldmat (const mat &V );
    00184                 ldmat ( vec D0 );
    00186                 ldmat ();
    00188                 ldmat(const int dim0);
    00189
    00191                 virtual ~ldmat(){};
    00192
    00193                 // Reimplementation of compulsory operatios
    00194
    00195                 void opupdt ( const vec &v, double w );
    00196                 mat to_mat();
    00197                 void mult_sym ( const mat &C);
    00198                 void mult_sym_t ( const mat &C);
    00200                 void add ( const ldmat &ld2, double w=1.0 );
    00201                 double logdet() const;
    00202                 double qform (const vec &v ) const;
    00203                 double invqform (const vec &v ) const;
    00204 //      sqmat& operator -= ( const sqmat & ld2 );
    00205                 void clear();
    00206                 int cols() const;
    00207                 int rows() const;
    00208                 vec sqrt_mult ( const vec &v ) const;
    00209
    00213                 virtual void inv ( ldmat &Inv ) const;
    00214
    00219                 void mult_sym ( const mat &C, ldmat &U) const;
    00220
    00225                 void mult_sym_t ( const mat &C, ldmat &U) const;
    00226
    00227
    00234                 void ldform (const mat &A,const vec &D0 );
    00235
    00237                 void setD (const vec &nD){D=nD;}
    00239                 void setD (const vec &nD, int i){D.replace_mid(i,nD);} //Fixme can be more general
    00241                 void setL (const vec &nL){L=nL;}
    00242
    00244                 ldmat& operator += ( const ldmat &ldA );
    00246                 ldmat& operator -= ( const ldmat &ldA );
    00248                 ldmat& operator *= ( double x );
    00249
    00251                 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq );
    00252
    00253
    00254         protected:
    00256                 vec D;
    00258                 mat L;
    00259
    00260 };
    00261
    00262
    00265 inline ldmat& ldmat::operator += ( const ldmat &ldA )  {this->add ( ldA );return *this;}
    00267 inline ldmat& ldmat::operator -= ( const ldmat &ldA )  {this->add ( ldA,-1.0 );return *this;}
    00269 inline int ldmat::cols() const {return dim;}
    00271 inline int ldmat::rows() const {return dim;}
    00272
    00273 #endif // DC_H