00001
00013 #ifndef DC_H
00014 #define DC_H
00015
00016
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
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
00086
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){};
00102 sqmat(): dim(0){};
00103 protected:
00105 int dim;
00106 };
00107
00108
00113 class fsqmat: public sqmat
00114 {
00115 protected:
00117 mat M;
00118 public:
00119 void opupdt ( const vec &v, double w );
00120 mat to_mat() const;
00121 void mult_sym ( const mat &C);
00122 void mult_sym_t ( const mat &C);
00124 void mult_sym ( const mat &C, fsqmat &U) const;
00126 void mult_sym_t ( const mat &C, fsqmat &U) const;
00127 void clear();
00128
00130 fsqmat(){};
00132 fsqmat(const int dim0);
00134 fsqmat ( const mat &M );
00136 fsqmat ( const fsqmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
00138 fsqmat ( const vec &d ):sqmat(d.length()){M=diag(d);};
00139
00141 virtual ~fsqmat(){};
00142
00143
00149 void inv ( fsqmat &Inv ) const;
00150
00151 double logdet() const {return log ( det ( M ) );};
00152 double qform (const vec &v ) const {return ( v* ( M*v ) );};
00153 double invqform (const vec &v ) const {return ( v* ( itpp::inv(M)*v ) );};
00154 vec sqrt_mult (const vec &v ) const {mat Ch=chol(M); return Ch*v;};
00155
00157 void add ( const fsqmat &fsq2, double w=1.0 ){M+=fsq2.M;};
00158
00160 void setD (const vec &nD){M=diag(nD);}
00162 vec getD (){return diag(M);}
00164 void setD (const vec &nD, int i){for(int j=i;j<nD.length();j++){M(j,j)=nD(j-i);}}
00165
00166
00168 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
00170 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
00172 fsqmat& operator *= ( double x ) {M*=x;return *this;};
00173
00175 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
00176
00177 };
00178
00184 class ldmat: public sqmat
00185 {
00186 public:
00188 ldmat ( const mat &L, const vec &D );
00190 ldmat (const mat &V );
00192 ldmat (const ldmat &V0, const ivec &perm):sqmat(V0.rows()){ ldform(V0.L.get_cols(perm), V0.D);};
00194 ldmat ( vec D0 );
00196 ldmat ();
00198 ldmat(const int dim0);
00199
00201 virtual ~ldmat(){};
00202
00203
00204
00205 void opupdt ( const vec &v, double w );
00206 mat to_mat() const;
00207 void mult_sym ( const mat &C);
00208 void mult_sym_t ( const mat &C);
00210 void add ( const ldmat &ld2, double w=1.0 );
00211 double logdet() const;
00212 double qform (const vec &v ) const;
00213 double invqform (const vec &v ) const;
00214 void clear();
00215 vec sqrt_mult ( const vec &v ) const;
00216
00217
00221 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);}
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;}
00279
00280 #endif // DC_H