00001
00013 #ifndef BM_H
00014 #define BM_H
00015
00016 #include <itpp/itbase.h>
00017
00018
00019 using namespace itpp;
00020
00027 class RV {
00028 protected:
00030 int size;
00032 int len;
00034 ivec ids;
00036 ivec sizes;
00038 ivec times;
00040 Array<std::string> names;
00041
00042 private:
00044 void init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times);
00045 public:
00047 RV ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times);
00049 RV ( ivec ids );
00051 RV ();
00052
00054 friend std::ostream &operator<< ( std::ostream &os, const RV &rv );
00055
00057 int count() const {return size;} ;
00058
00059
00060
00062 ivec find ( RV rv2 );
00064 void add (const RV &rv2 );
00066 friend RV concat (const RV &rv1, const RV &rv2 );
00068 RV subt ( RV rv2 );
00070 RV subselect ( ivec ind );
00072 RV operator() ( ivec ind );
00074 void t ( int delta );
00076 ivec indexlist();
00077 };
00078
00079
00081
00082 class fnc {
00083 protected:
00085 int dimy;
00086 public:
00088 virtual vec eval ( const vec &cond ) {
00089 return vec ( 0 );
00090 };
00091
00093 int _dimy() const{return dimy;}
00094
00096 virtual ~fnc() {};
00097 };
00098
00099
00101
00102 class epdf {
00103 protected:
00105 RV rv;
00106 public:
00108 epdf() :rv ( ivec ( 0 ) ) {};
00109
00111 epdf ( const RV &rv0 ) :rv ( rv0 ) {};
00112
00114
00116 virtual vec sample () const =0;
00118 virtual double eval ( const vec &val ) const {return exp(this->evalpdflog(val));};
00119
00121 virtual double evalpdflog ( const vec &val ) const =0;
00122
00124 virtual vec mean() const =0;
00125
00127 virtual ~epdf() {};
00129 RV _rv() const {return rv;}
00130 };
00131
00132
00134
00135
00136 class mpdf {
00137 protected:
00139 RV rv;
00141 RV rvc;
00143 epdf* ep;
00144 public:
00145
00147
00149 virtual vec samplecond ( vec &cond, double &ll ) {this->condition(cond);vec temp= ep->sample();ll=ep->evalpdflog(temp);return temp;};
00151 virtual void condition ( const vec &cond ) {};
00152
00154 virtual double evalcond (const vec &dt, const vec &cond ) {this->condition(cond);return ep->eval(dt);};
00155
00157 virtual ~mpdf() {};
00158
00160 mpdf ( const RV &rv0, const RV &rvc0 ) :rv ( rv0 ),rvc ( rvc0 ) {};
00162 RV _rvc(){return rvc;}
00164 epdf& _epdf(){return *ep;}
00165 };
00166
00174 class DS {
00175 protected:
00177 RV Drv;
00179 RV Urv;
00180 public:
00182 void getdata ( vec &dt );
00184 void getdata ( vec &dt, ivec &indeces );
00186 void write ( vec &ut );
00188 void write ( vec &ut, ivec &indeces );
00194 void linkrvs ( RV &drv, RV &urv );
00195
00197 void step();
00198
00199 };
00200
00205 class BM {
00206 protected:
00208 RV rv;
00210 double ll;
00212 bool evalll;
00213 public:
00214
00216 BM(const RV &rv0) :rv(rv0), ll ( 0 ),evalll ( true ) {
00217 };
00218
00222 virtual void bayes ( const vec &dt ) = 0;
00224 void bayes ( mat Dt );
00226 virtual epdf& _epdf()=0;
00227
00229 virtual ~BM() {};
00231 const RV& _rv() const {return rv;}
00233 double _ll() const {return ll;}
00234 };
00235
00245 class BMcond {
00246 protected:
00248 RV rvc;
00249 public:
00251 virtual void condition ( const vec &val ) =0;
00253 BMcond(RV &rv0):rvc(rv0){};
00255 virtual ~BMcond(){};
00257 const RV& _rvc() const {return rvc;}
00258 };
00259
00260 #endif // BM_H