- Main Page
- Related Pages
- Classes
- Files

# work/mixpp/bdm/stat/libBM.h

Go to the documentation of this file.

    00001
    00013 #ifndef BM_H
    00014 #define BM_H
    00015
    00016 #include <itpp/itbase.h>
    00017 //#include <std>
    00018
    00019 using namespace itpp;
    00020
    00027 class RV {
    00028 protected:
    00030         int tsize;
    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 tsize;} ;
    00059         int length() const {return len;} ;
    00060
    00061         //TODO why not inline and later??
    00062
    00064         ivec find ( RV rv2 );
    00066         bool equal ( RV rv2 ) const;
    00068         void add (const RV &rv2 );
    00070         friend RV concat (const RV &rv1, const RV &rv2 );
    00072         RV subt ( RV rv2 );
    00074         RV subselect ( ivec ind );
    00076         RV operator() ( ivec ind );
    00078         void t ( int delta );
    00080         ivec indexlist();
    00081
    00083         Array<std::string>& _names(){return names;};
    00084
    00086         int id(int at){return ids(at);};
    00088         int size(int at){return sizes(at);};
    00090         int time(int at){return times(at);};
    00092         std::string name(int at){return names(at);};
    00093 };
    00094
    00095
    00097
    00098 class fnc {
    00099 protected:
    00101         int dimy;
    00102 public:
    00104         fnc(int dy):dimy(dy){};
    00106         virtual vec eval ( const vec &cond ) {
    00107                 return vec ( 0 );
    00108         };
    00109
    00111         int _dimy() const{return dimy;}
    00112
    00114         virtual ~fnc() {};
    00115 };
    00116
    00117
    00119
    00120 class epdf {
    00121 protected:
    00123         RV rv;
    00124 public:
    00126         epdf() :rv ( ivec ( 0 ) ) {};
    00127
    00129         epdf ( const RV &rv0 ) :rv ( rv0 ) {};
    00130
    00132 //      virtual vec moment ( const int order = 1 );
    00134         virtual vec sample () const =0;
    00136         virtual mat sample (int N) const;
    00138         virtual double eval ( const vec &val ) const {return exp(this->evalpdflog(val));};
    00139
    00141         virtual double evalpdflog ( const vec &val ) const =0;
    00142
    00144         virtual vec mean() const =0;
    00145
    00147         virtual ~epdf() {};
    00149         RV _rv() const {return rv;}
    00150 };
    00151
    00152
    00154 //TODO Samplecond can be generalized
    00155
    00156 class mpdf {
    00157 protected:
    00159         RV rv;
    00161         RV rvc;
    00163         epdf* ep;
    00164 public:
    00165
    00167 //      virtual fnc moment ( const int order = 1 );
    00169         virtual vec samplecond ( vec &cond, double &ll ) {this->condition(cond);vec temp= ep->sample();ll=ep->evalpdflog(temp);return temp;};
    00171         virtual void condition ( const vec &cond ) {};
    00172
    00174         virtual double evalcond (const vec &dt, const vec &cond ) {this->condition(cond);return ep->eval(dt);};
    00175
    00177         virtual ~mpdf() {};
    00178
    00180         mpdf ( const RV &rv0, const RV &rvc0 ) :rv ( rv0 ),rvc ( rvc0 ) {};
    00182         RV _rvc(){return rvc;}
    00184         epdf& _epdf(){return *ep;}
    00185 };
    00186
    00194 class DS {
    00195 protected:
    00197         RV Drv;
    00199         RV Urv; //
    00200 public:
    00202         void getdata ( vec &dt );
    00204         void getdata ( vec &dt, ivec &indeces );
    00206         void write ( vec &ut );
    00208         void write ( vec &ut, ivec &indeces );
    00214         void linkrvs ( RV &drv, RV &urv );
    00215
    00217         void step();
    00218
    00219 };
    00220
    00225 class BM {
    00226 protected:
    00228         RV rv;
    00230         double ll;
    00232         bool evalll;
    00233 public:
    00234
    00236         BM(const RV &rv0) :rv(rv0), ll ( 0 ),evalll ( true ) {//Fixme: test rv
    00237         };
    00238
    00242         virtual void bayes ( const vec &dt ) = 0;
    00244         void bayes ( mat Dt );
    00246         virtual epdf& _epdf()=0;
    00247
    00249         virtual ~BM() {};
    00251         const RV& _rv() const {return rv;}
    00253         double _ll() const {return ll;}
    00254 };
    00255
    00265 class BMcond {
    00266 protected:
    00268         RV rvc;
    00269 public:
    00271         virtual void condition ( const vec &val ) =0;
    00273         BMcond(RV &rv0):rvc(rv0){};
    00275         virtual ~BMcond(){};
    00277         const RV& _rvc() const {return rvc;}
    00278 };
    00279
    00280 #endif // BM_H