00001 
00013 #ifndef DS_H
00014 #define DS_H
00015 
00016 
00017 #include "libBM.h"
00018 #include "libEF.h"
00019 
00020 
00021 namespace bdm {
00029         class MemDS : public DS {
00031                 mat Data;
00033                 int time;
00035                 ivec rowid;
00037                 ivec delays;
00038 
00039         public:
00040                 void getdata ( vec &dt );
00041                 void getdata ( vec &dt, const ivec &indeces );
00042                 void linkrvs ( RV &drv, RV &urv );
00043                 void write ( vec &ut ) {it_error ( "MemDS::write is not supported" );}
00044                 void write ( vec &ut,ivec &indexes ) {it_error ( "MemDS::write is not supported" );}
00045                 void step();
00047                 MemDS ( mat &Dat, ivec &rowid, ivec &delays );
00048         };
00049 
00054         class ArxDS : public DS {
00055         protected:
00057                 RV Rrv;
00059                 RV Hrv;
00061                 vec H;
00063                 vec U;
00065                 vec rgr;
00067                 datalink_e2e rgrlnk;
00069                 mlnorm<chmat> model;
00071                 bool opt_L_theta;
00073                 int L_theta;
00074                 int L_R;
00075         public:
00076                 void getdata ( vec &dt ) {
00077                         it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" );
00078                         dt=H.left ( Urv.count() +Drv.count() );
00079                 };
00080                 void getdata ( vec &dt, const ivec &indexes ) {
00081                         it_assert_debug ( dt.length() ==indeces.length(),"ArxDS" );
00082                         dt=H ( indexes );
00083                 };
00084                 void write ( vec &ut ) {
00085                         it_assert_debug ( ut.length() ==Urv.count(),"ArxDS" );
00086                         U=ut;
00087                 };
00088                 void write ( vec &ut, const ivec &indexes ) {
00089                         it_assert_debug ( ut.length() ==indeces.length(),"ArxDS" );
00090                         set_subvector ( U, indexes,ut );
00091                 };
00092                 void step();
00094                 ArxDS ( RV &drv, RV &urv, RV &rrv );
00096                 void set_parameters ( const mat &Th0, const vec mu0, const chmat &sqR0 )
00097                 { model.set_parameters ( Th0, mu0, sqR0 ); };
00099                 void set_options ( const string &s ) {
00100                         opt_L_theta= ( s.find ( "L_theta" ) !=string::npos );
00101                 };
00102                 virtual void log_add ( logger &L ) {
00103                         DS::log_add ( L );
00104                         mat &A =model._A();
00105                         mat R =model._R();
00106                         if ( opt_L_theta ) {L_theta=L.add ( RV ( "{theta }", vec_1 ( A.rows() *A.cols() ) ),"t" );}
00107                         if ( opt_L_theta ) {L_R=L.add ( RV ( "{R }", vec_1 ( R.rows() *R.cols() ) ),"r" );}
00108                 }
00109                 virtual void logit ( logger &L ) {
00110                         DS::logit ( L );
00111                         mat &A =model._A();
00112                         mat R =model._R();
00113                         if ( opt_L_theta ) {L.logit ( L_theta,vec ( A._data(), A.rows() *A.cols() ) );};
00114                         if ( opt_L_theta ) {L.logit ( L_R, vec ( R._data(), R.rows() *R.rows() ) );};
00115                 }
00116 
00117         };
00118 
00119         class ARXDS : public ArxDS {
00120         public:
00121                 ARXDS ( RV &drv, RV &urv, RV &rrv ) : ArxDS ( drv,urv,rrv ) {}
00122 
00123                 void getdata ( vec &dt ) {dt=H;}
00124                 void getdata ( vec &dt, const ivec &indeces ) {dt=H ( indeces );}
00125                 virtual RV _drv() const {return Hrv;}
00126 
00127         };
00128 
00129         class stateDS : public DS {
00130         protected:
00132                 mpdf* IM;
00134                 mpdf* OM;
00136                 vec dt;
00138                 vec xt;
00140                 vec ut;
00142                 int L_xt;
00143         public:
00144                 void getdata ( vec &dt0 ) {dt0=dt;}
00145                 void getdata ( vec &dt0, const ivec &indeces ) {dt0=dt ( indeces );}
00146 
00147                 stateDS ( mpdf* IM0, mpdf* OM0, RV &Urv0 ) :DS ( OM0->_rv(),Urv0 ),IM ( IM0 ),OM ( OM0 ),
00148                                 dt ( OM0->_rv().count() ), xt ( IM0->_rv().count() ), ut ( Urv0.count() ) {}
00149                 ~stateDS() {delete IM; delete OM;}
00150                 virtual void step() {
00151                         double tmp;
00152                         xt=IM->samplecond(concat ( xt,ut ));
00153                         dt=OM->samplecond(concat ( xt,ut ));
00154                 };
00155                 
00156                 virtual void log_add ( logger &L ) {
00157                         DS::log_add ( L );
00158                         L_xt=L.add(IM->_rv(),"true");
00159                 }
00160                 virtual void logit ( logger &L ) {
00161                         DS::logit ( L );
00162                         L.logit ( L_xt,xt);
00163                 }
00164 
00165         };
00166 
00167 }; 
00168 
00169 #endif // DS_H