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 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         //TODO why not inline and later??
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 
00079         Array<std::string>& _names(){return names;};
00080 };
00081 
00082 
00084 
00085 class fnc {
00086 protected:
00088         int dimy;
00089 public:
00091         fnc(int dy):dimy(dy){};
00093         virtual vec eval ( const vec &cond ) {
00094                 return vec ( 0 );
00095         }; 
00096 
00098         int _dimy() const{return dimy;}
00099 
00101         virtual ~fnc() {};
00102 };
00103 
00104 
00106 
00107 class epdf {
00108 protected:
00110         RV rv;
00111 public:
00113         epdf() :rv ( ivec ( 0 ) ) {};
00114 
00116         epdf ( const RV &rv0 ) :rv ( rv0 ) {};
00117 
00119 //      virtual vec moment ( const int order = 1 );
00121         virtual vec sample () const =0;
00123         virtual double eval ( const vec &val ) const {return exp(this->evalpdflog(val));};
00124 
00126         virtual double evalpdflog ( const vec &val ) const =0;
00127 
00129         virtual vec mean() const =0;
00130         
00132         virtual ~epdf() {};
00134         RV _rv() const {return rv;}
00135 };
00136 
00137 
00139 //TODO Samplecond can be generalized
00140 
00141 class mpdf {
00142 protected:
00144         RV rv;
00146         RV rvc;
00148         epdf* ep;
00149 public:
00150 
00152 //      virtual fnc moment ( const int order = 1 );
00154         virtual vec samplecond ( vec &cond, double &ll ) {this->condition(cond);vec temp= ep->sample();ll=ep->evalpdflog(temp);return temp;};
00156         virtual void condition ( const vec &cond ) {};
00157         
00159         virtual double evalcond (const vec &dt, const vec &cond ) {this->condition(cond);return ep->eval(dt);};
00160 
00162         virtual ~mpdf() {};
00163 
00165         mpdf ( const RV &rv0, const RV &rvc0 ) :rv ( rv0 ),rvc ( rvc0 ) {};
00167         RV _rvc(){return rvc;}
00169         epdf& _epdf(){return *ep;}
00170 };
00171 
00179 class DS {
00180 protected:
00182         RV Drv;
00184         RV Urv; //
00185 public:
00187         void getdata ( vec &dt );
00189         void getdata ( vec &dt, ivec &indeces );
00191         void write ( vec &ut );
00193         void write ( vec &ut, ivec &indeces );
00199         void linkrvs ( RV &drv, RV &urv );
00200 
00202         void step();
00203 
00204 };
00205 
00210 class BM {
00211 protected:
00213         RV rv;
00215  double ll;
00217         bool evalll;
00218 public:
00219 
00221         BM(const RV &rv0) :rv(rv0), ll ( 0 ),evalll ( true ) {//Fixme: test rv 
00222         };
00223 
00227         virtual void bayes ( const vec &dt ) = 0;
00229         void bayes ( mat Dt );
00231         virtual epdf& _epdf()=0;
00232 
00234         virtual ~BM() {};
00236         const RV& _rv() const {return rv;}
00238         double _ll() const {return ll;}
00239 };
00240 
00250 class BMcond {
00251 protected:
00253         RV rvc;
00254 public:
00256         virtual void condition ( const vec &val ) =0;
00258         BMcond(RV &rv0):rvc(rv0){};
00260         virtual ~BMcond(){};
00262         const RV& _rvc() const {return rvc;}
00263 };
00264 
00265 #endif // BM_H

Generated on Fri Apr 18 11:15:15 2008 for mixpp by  doxygen 1.5.3