- 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         void add (const RV &rv2 );
    00068         friend RV concat (const RV &rv1, const RV &rv2 );
    00070         RV subt ( RV rv2 );
    00072         RV subselect ( ivec ind );
    00074         RV operator() ( ivec ind );
    00076         void t ( int delta );
    00078         ivec indexlist();
    00079
    00081         Array<std::string>& _names(){return names;};
    00082
    00084         int id(int at){return ids(at);};
    00086         int size(int at){return sizes(at);};
    00088         int time(int at){return times(at);};
    00090         std::string name(int at){return names(at);};
    00091 };
    00092
    00093
    00095
    00096 class fnc {
    00097 protected:
    00099         int dimy;
    00100 public:
    00102         fnc(int dy):dimy(dy){};
    00104         virtual vec eval ( const vec &cond ) {
    00105                 return vec ( 0 );
    00106         };
    00107
    00109         int _dimy() const{return dimy;}
    00110
    00112         virtual ~fnc() {};
    00113 };
    00114
    00115
    00117
    00118 class epdf {
    00119 protected:
    00121         RV rv;
    00122 public:
    00124         epdf() :rv ( ivec ( 0 ) ) {};
    00125
    00127         epdf ( const RV &rv0 ) :rv ( rv0 ) {};
    00128
    00130 //      virtual vec moment ( const int order = 1 );
    00132         virtual vec sample () const =0;
    00134         virtual double eval ( const vec &val ) const {return exp(this->evalpdflog(val));};
    00135
    00137         virtual double evalpdflog ( const vec &val ) const =0;
    00138
    00140         virtual vec mean() const =0;
    00141
    00143         virtual ~epdf() {};
    00145         RV _rv() const {return rv;}
    00146 };
    00147
    00148
    00150 //TODO Samplecond can be generalized
    00151
    00152 class mpdf {
    00153 protected:
    00155         RV rv;
    00157         RV rvc;
    00159         epdf* ep;
    00160 public:
    00161
    00163 //      virtual fnc moment ( const int order = 1 );
    00165         virtual vec samplecond ( vec &cond, double &ll ) {this->condition(cond);vec temp= ep->sample();ll=ep->evalpdflog(temp);return temp;};
    00167         virtual void condition ( const vec &cond ) {};
    00168
    00170         virtual double evalcond (const vec &dt, const vec &cond ) {this->condition(cond);return ep->eval(dt);};
    00171
    00173         virtual ~mpdf() {};
    00174
    00176         mpdf ( const RV &rv0, const RV &rvc0 ) :rv ( rv0 ),rvc ( rvc0 ) {};
    00178         RV _rvc(){return rvc;}
    00180         epdf& _epdf(){return *ep;}
    00181 };
    00182
    00190 class DS {
    00191 protected:
    00193         RV Drv;
    00195         RV Urv; //
    00196 public:
    00198         void getdata ( vec &dt );
    00200         void getdata ( vec &dt, ivec &indeces );
    00202         void write ( vec &ut );
    00204         void write ( vec &ut, ivec &indeces );
    00210         void linkrvs ( RV &drv, RV &urv );
    00211
    00213         void step();
    00214
    00215 };
    00216
    00221 class BM {
    00222 protected:
    00224         RV rv;
    00226         double ll;
    00228         bool evalll;
    00229 public:
    00230
    00232         BM(const RV &rv0) :rv(rv0), ll ( 0 ),evalll ( true ) {//Fixme: test rv
    00233         };
    00234
    00238         virtual void bayes ( const vec &dt ) = 0;
    00240         void bayes ( mat Dt );
    00242         virtual epdf& _epdf()=0;
    00243
    00245         virtual ~BM() {};
    00247         const RV& _rv() const {return rv;}
    00249         double _ll() const {return ll;}
    00250 };
    00251
    00261 class BMcond {
    00262 protected:
    00264         RV rvc;
    00265 public:
    00267         virtual void condition ( const vec &val ) =0;
    00269         BMcond(RV &rv0):rvc(rv0){};
    00271         virtual ~BMcond(){};
    00273         const RV& _rvc() const {return rvc;}
    00274 };
    00275
    00276 #endif // BM_H