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
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
00085
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();
00129 fsqmat(const int dim0);
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 add ( const fsqmat &fsq2, double w=1.0 ){M+=fsq2.M;};
00153
00155 void setD (const vec &nD){M=diag(nD);}
00157 vec getD (){return diag(M);}
00159 void setD (const vec &nD, int i){for(int j=i;j<nD.length();j++){M(j,j)=nD(j-i);}}
00160
00161
00163 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;};
00165 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;};
00167 fsqmat& operator *= ( double x ) {M*=x;return *this;};
00168
00170 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq );
00171
00172 };
00173
00179 class ldmat: sqmat
00180 {
00181 public:
00182
00184 ldmat ( const mat &L, const vec &D );
00186 ldmat (const mat &V );
00188 ldmat ( vec D0 );
00190 ldmat ();
00192 ldmat(const int dim0);
00193
00195 virtual ~ldmat(){};
00196
00197
00198
00199 void opupdt ( const vec &v, double w );
00200 mat to_mat();
00201 void mult_sym ( const mat &C);
00202 void mult_sym_t ( const mat &C);
00204 void add ( const ldmat &ld2, double w=1.0 );
00205 double logdet() const;
00206 double qform (const vec &v ) const;
00207 double invqform (const vec &v ) const;
00208
00209 void clear();
00210 int cols() const;
00211 int rows() const;
00212 vec sqrt_mult ( const vec &v ) const;
00213
00217 virtual void inv ( ldmat &Inv ) const;
00218
00223 void mult_sym ( const mat &C, ldmat &U) const;
00224
00229 void mult_sym_t ( const mat &C, ldmat &U) const;
00230
00231
00238 void ldform (const mat &A,const vec &D0 );
00239
00241 void setD (const vec &nD){D=nD;}
00243 void setD (const vec &nD, int i){D.replace_mid(i,nD);}
00245 void setL (const vec &nL){L=nL;}
00246
00248 ldmat& operator += ( const ldmat &ldA );
00250 ldmat& operator -= ( const ldmat &ldA );
00252 ldmat& operator *= ( double x );
00253
00255 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq );
00256
00257
00258 protected:
00260 vec D;
00262 mat L;
00263
00264 };
00265
00266
00269 inline ldmat& ldmat::operator += ( const ldmat &ldA ) {this->add ( ldA );return *this;}
00271 inline ldmat& ldmat::operator -= ( const ldmat &ldA ) {this->add ( ldA,-1.0 );return *this;}
00273 inline int ldmat::cols() const {return dim;}
00275 inline int ldmat::rows() const {return dim;}
00276
00277 #endif // DC_H