00001
00013 #ifndef DC_H
00014 #define DC_H
00015
00016 #include <itpp/itbase.h>
00017
00018 using namespace itpp;
00019
00024 class sqmat {
00025 public:
00033 virtual void opupdt( const vec &v, double w ) =0;
00034
00038 virtual mat to_mat() =0;
00039
00044 virtual void mult_sym( const mat &C, bool trans=true ) =0;
00045
00046
00051 virtual double logdet() =0;
00052
00058 virtual vec sqrt_mult(vec &v) =0;
00059
00064 virtual double qform(vec &v) =0;
00065
00066
00067
00068
00070 virtual void clear() =0;
00071
00073 int cols() const {return dim;};
00074
00076 int rows() const {return dim;};
00077
00078 protected:
00079 int dim;
00080 };
00081
00082
00087 class fsqmat: public sqmat {
00088 protected:
00089 mat M;
00090 public:
00091 void opupdt( const vec &v, double w );
00092 mat to_mat();
00093 void mult_sym( const mat &C, bool trans=false );
00094 void mult_sym( const mat &C, fsqmat &U, bool trans=false );
00095 void inv(fsqmat &Inv);
00096 void clear();
00097
00098
00099 fsqmat(){};
00101 fsqmat(const mat &M);
00102
00108 virtual void inv(fsqmat* Inv);
00109
00110 double logdet(){return log(det(M));};
00111 double qform(vec &v){return (v*(M*v));};
00112 vec sqrt_mult(vec &v){it_error("not implemented");return v;};
00113
00114 fsqmat& operator += (const fsqmat &A){M+=A.M;return *this;};
00115 fsqmat& operator -= (const fsqmat &A){M-=A.M;return *this;};
00116 fsqmat& operator *= (double x){M*=x;return *this;};
00117 };
00118
00119 class ldmat: sqmat {
00120 public:
00121
00123 ldmat( const mat &L, const vec &D );
00125 ldmat( mat V );
00127 ldmat( vec D0 );
00128 ldmat ();
00129
00130
00131
00132 void opupdt( const vec &v, double w );
00133 mat to_mat();
00134 void mult_sym( const mat &C, bool trans=false );
00135 void add ( const ldmat &ld2, double w=1.0 );
00136 double logdet();
00137 double qform(vec &v);
00138
00139 void clear();
00140 int cols();
00141 int rows();
00142 vec sqrt_mult(vec &v);
00143
00149 virtual void inv(ldmat &Inv);
00150
00156 void mult_sym( const mat &C, ldmat &U, bool trans=false );
00157
00166 void ldform( mat &A, vec &D0 );
00167
00168 ldmat& operator += (const ldmat &ldA);
00169 ldmat& operator -= (const ldmat &ldA);
00170 ldmat& operator *= (double x);
00171
00172 friend std::ostream &operator<< ( std::ostream &os, ldmat &sq );
00173
00174 protected:
00175 vec D;
00176 mat L;
00177
00178 };
00179
00181
00182 inline ldmat& ldmat::operator += (const ldmat &ldA) {this->add(ldA);return *this;}
00183 inline ldmat& ldmat::operator -= (const ldmat &ldA) {this->add(ldA,-1.0);return *this;}
00184 inline int ldmat::cols(){return dim;}
00185 inline int ldmat::rows(){return dim;}
00186
00187 #endif // DC_H