00001
00013 #ifndef DC_H
00014 #define DC_H
00015
00016 #include <itpp/itbase.h>
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
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
00091
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){};
00106 protected:
00108 int dim;
00109 };
00110
00111
00116 class fsqmat: public sqmat
00117 {
00118 protected:
00120 mat M;
00121 public:
00122 void opupdt ( const vec &v, double w );
00123 mat to_mat() const;
00124 void mult_sym ( const mat &C);
00125 void mult_sym_t ( const mat &C);
00127 void mult_sym ( const mat &C, fsqmat &U) const;
00129 void mult_sym_t ( const mat &C, fsqmat &U) const;
00130 void clear();
00131
00133 fsqmat();
00135 fsqmat(const int dim0);
00137 fsqmat ( const mat &M );
00139 fsqmat ( const fsqmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
00141 fsqmat ( const vec &d ):sqmat(d.length()){M=diag(d);};
00142
00144 virtual ~fsqmat(){};
00145
00146
00152 virtual void inv ( fsqmat &Inv );
00153
00154 double logdet() const {return log ( det ( M ) );};
00155 double qform (const vec &v ) const {return ( v* ( M*v ) );};
00156 double invqform (const vec &v ) const {return ( v* ( itpp::inv(M)*v ) );};
00157 vec sqrt_mult (const vec &v ) const {mat Ch=chol(M); return Ch*v;};
00158
00160 void add ( const fsqmat &fsq2, double w=1.0 ){M+=fsq2.M;};
00161
00163 void setD (const vec &nD){M=diag(nD);}
00165 vec getD (){return diag(M);}
00167 void setD (const vec &nD, int i){for(int j=i;j<nD.length();j++){M(j,j)=nD(j-i);}}
00168
00169
00171 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
00173 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
00175 fsqmat& operator *= ( double x ) {M*=x;return *this;};
00176
00178 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
00179
00180 };
00181
00187 class ldmat: sqmat
00188 {
00189 public:
00191 ldmat ( const mat &L, const vec &D );
00193 ldmat (const mat &V );
00195 ldmat (const ldmat &V0, const ivec &perm):sqmat(V0.rows()){ ldform(V0.L.get_cols(perm), V0.D);};
00197 ldmat ( vec D0 );
00199 ldmat ();
00201 ldmat(const int dim0);
00202
00204 virtual ~ldmat(){};
00205
00206
00207
00208 void opupdt ( const vec &v, double w );
00209 mat to_mat() const;
00210 void mult_sym ( const mat &C);
00211 void mult_sym_t ( const mat &C);
00213 void add ( const ldmat &ld2, double w=1.0 );
00214 double logdet() const;
00215 double qform (const vec &v ) const;
00216 double invqform (const vec &v ) const;
00217 void clear();
00218 int cols() const;
00219 int rows() const;
00220 vec sqrt_mult ( const vec &v ) const;
00221
00222
00226 virtual void inv ( ldmat &Inv ) const;
00227
00232 void mult_sym ( const mat &C, ldmat &U) const;
00233
00238 void mult_sym_t ( const mat &C, ldmat &U) const;
00239
00240
00247 void ldform (const mat &A,const vec &D0 );
00248
00250 void setD (const vec &nD){D=nD;}
00252 void setD (const vec &nD, int i){D.replace_mid(i,nD);}
00254 void setL (const vec &nL){L=nL;}
00255
00257 const vec& _D() const {return D;}
00259 const mat& _L() const {return L;}
00260
00262 ldmat& operator += ( const ldmat &ldA );
00264 ldmat& operator -= ( const ldmat &ldA );
00266 ldmat& operator *= ( double x );
00267
00269 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq );
00270
00271 protected:
00273 vec D;
00275 mat L;
00276
00277 };
00278
00281 inline ldmat& ldmat::operator += ( const ldmat &ldA ) {this->add ( ldA );return *this;}
00283 inline ldmat& ldmat::operator -= ( const ldmat &ldA ) {this->add ( ldA,-1.0 );return *this;}
00285 inline int ldmat::cols() const {return dim;}
00287 inline int ldmat::rows() const {return dim;}
00288
00291 #endif // DC_H