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
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){};
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();
00130 fsqmat(const int dim0);
00132 fsqmat ( const mat &M );
00134 fsqmat ( const vec &d ):sqmat(d.length()){M=diag(d);};
00135
00137 virtual ~fsqmat(){};
00138
00139
00145 virtual void inv ( fsqmat &Inv );
00146
00147 double logdet() const {return log ( det ( M ) );};
00148 double qform (const vec &v ) const {return ( v* ( M*v ) );};
00149 double invqform (const vec &v ) const {return ( v* ( itpp::inv(M)*v ) );};
00150 vec sqrt_mult (const vec &v ) const {mat Ch=chol(M); return Ch*v;};
00151
00153 void add ( const fsqmat &fsq2, double w=1.0 ){M+=fsq2.M;};
00154
00156 void setD (const vec &nD){M=diag(nD);}
00158 vec getD (){return diag(M);}
00160 void setD (const vec &nD, int i){for(int j=i;j<nD.length();j++){M(j,j)=nD(j-i);}}
00161
00162
00164 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
00166 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
00168 fsqmat& operator *= ( double x ) {M*=x;return *this;};
00169
00171 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
00172
00173 };
00174
00180 class ldmat: sqmat
00181 {
00182 public:
00184 ldmat ( const mat &L, const vec &D );
00186 ldmat (const mat &V );
00188 ldmat (const ldmat &V0, const ivec &perm):sqmat(V0.rows()){ ldform(V0.L.get_cols(perm), V0.D);};
00190 ldmat ( vec D0 );
00192 ldmat ();
00194 ldmat(const int dim0);
00195
00197 virtual ~ldmat(){};
00198
00199
00200
00201 void opupdt ( const vec &v, double w );
00202 mat to_mat() const;
00203 void mult_sym ( const mat &C);
00204 void mult_sym_t ( const mat &C);
00206 void add ( const ldmat &ld2, double w=1.0 );
00207 double logdet() const;
00208 double qform (const vec &v ) const;
00209 double invqform (const vec &v ) const;
00210 void clear();
00211 int cols() const;
00212 int rows() const;
00213 vec sqrt_mult ( const vec &v ) const;
00214
00215
00219 virtual void inv ( ldmat &Inv ) const;
00220
00225 void mult_sym ( const mat &C, ldmat &U) const;
00226
00231 void mult_sym_t ( const mat &C, ldmat &U) const;
00232
00233
00240 void ldform (const mat &A,const vec &D0 );
00241
00243 void setD (const vec &nD){D=nD;}
00245 void setD (const vec &nD, int i){D.replace_mid(i,nD);}
00247 void setL (const vec &nL){L=nL;}
00248
00250 const vec& _D() const {return D;}
00252 const mat& _L() const {return L;}
00253
00255 ldmat& operator += ( const ldmat &ldA );
00257 ldmat& operator -= ( const ldmat &ldA );
00259 ldmat& operator *= ( double x );
00260
00262 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq );
00263
00264 protected:
00266 vec D;
00268 mat L;
00269
00270 };
00271
00274 inline ldmat& ldmat::operator += ( const ldmat &ldA ) {this->add ( ldA );return *this;}
00276 inline ldmat& ldmat::operator -= ( const ldmat &ldA ) {this->add ( ldA,-1.0 );return *this;}
00278 inline int ldmat::cols() const {return dim;}
00280 inline int ldmat::rows() const {return dim;}
00281
00282 #endif // DC_H