- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

# libDS.h

Go to the documentation of this file.

    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 {
    00030         protected:
    00032         mat Data;
    00034         int time;
    00036         ivec rowid;
    00038         ivec delays;
    00039
    00040 public:
    00041         void getdata ( vec &dt );
    00042         void getdata ( vec &dt, const ivec &indeces );
    00043         void set_rvs ( RV &drv, RV &urv );
    00044         void write ( vec &ut ) {it_error ( "MemDS::write is not supported" );}
    00045         void write ( vec &ut,ivec &indices ) {it_error ( "MemDS::write is not supported" );}
    00046         void step();
    00048         MemDS () {};
    00049         MemDS ( mat &Dat, ivec &rowid, ivec &delays );
    00050 };
    00051
    00055 class FileDS: public MemDS {
    00056
    00057 public:
    00058         FileDS ( const string &fname, const string &varname ) :MemDS() {
    00059                 it_file it ( fname );
    00060                 it << Name ( varname );
    00061                 it >> Data;
    00062                 time =0;
    00063                 //rowid and delays are ignored
    00064         }
    00065         void getdata ( vec &dt ) {
    00066                 it_assert_debug ( dt.length() ==Data.rows(),"" );
    00067                 dt = Data.get_col(time);
    00068         };
    00069         void getdata ( vec &dt, const ivec &indeces ){
    00070                 it_assert_debug ( dt.length() ==indeces.length(),"" );
    00071                 vec tmp(indeces.length());
    00072                 tmp = Data.get_col(time);
    00073                 dt = tmp(indeces);
    00074         };
    00076         int ndat(){return Data.cols();}
    00077 };
    00078
    00083 class ArxDS : public DS {
    00084 protected:
    00086         RV Rrv;
    00088         vec H;
    00090         vec U;
    00092         vec rgr;
    00094         datalink rgrlnk;
    00096         mlnorm<chmat> model;
    00098         bool opt_L_theta;
    00100         int L_theta;
    00101         int L_R;
    00102         int dt_size;
    00103 public:
    00104         void getdata ( vec &dt ) {
    00105                 //it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" );
    00106                 dt=H;
    00107         };
    00108         void getdata ( vec &dt, const ivec &indices ) {
    00109                 it_assert_debug ( dt.length() ==indices.length(),"ArxDS" );
    00110                 dt=H ( indices );
    00111         };
    00112         void write ( vec &ut ) {
    00113                 //it_assert_debug ( ut.length() ==Urv.count(),"ArxDS" );
    00114                 U=ut;
    00115         };
    00116         void write ( vec &ut, const ivec &indices ) {
    00117                 it_assert_debug ( ut.length() ==indices.length(),"ArxDS" );
    00118                 set_subvector ( U, indices,ut );
    00119         };
    00120         void step();
    00122         ArxDS ( ) {};
    00124         void set_parameters ( const mat &Th0, const vec mu0, const chmat &sqR0 )
    00125         { model.set_parameters ( Th0, mu0, sqR0 );};
    00127         void set_drv ( RV &yrv, RV &urv, RV &rrv ) {
    00128                 Rrv = rrv;
    00129                 Urv = urv;
    00130                 dt_size = yrv._dsize() +urv._dsize();
    00131
    00132                 RV drv = concat ( yrv,urv );
    00133                 Drv = drv;
    00134                 int td = rrv.mint();
    00135                 H.set_size ( drv._dsize() * ( -td+1 ) );
    00136                 U.set_size ( Urv._dsize() );
    00137                 for ( int i=-1;i>=td;i-- ) {
    00138                         drv.t ( -1 );
    00139                         Drv.add ( drv ); //shift u1
    00140                 }
    00141                 rgrlnk.set_connection ( rrv,Drv );
    00142
    00143                 dtsize = Drv._dsize();
    00144                 utsize = Urv._dsize();
    00145         }
    00147         void set_options ( const string &s ) {
    00148                 opt_L_theta= ( s.find ( "L_theta" ) !=string::npos );
    00149         };
    00150         virtual void log_add ( logger &L ) {
    00151                 //DS::log_add ( L ); too long!!
    00152                 L_dt=L.add ( Drv ( 0,dt_size ),"" );
    00153                 L_ut=L.add ( Urv,"" );
    00154
    00155                 mat &A =model._A();
    00156                 mat R =model._R();
    00157                 if ( opt_L_theta ) {L_theta=L.add ( RV ( "{th }", vec_1 ( A.rows() *A.cols() ) ),"t" );}
    00158                 if ( opt_L_theta ) {L_R=L.add ( RV ( "{R }", vec_1 ( R.rows() *R.cols() ) ),"r" );}
    00159         }
    00160         virtual void logit ( logger &L ) {
    00161                 //DS::logit ( L );
    00162                 L.logit ( L_dt, H.left ( dt_size ) );
    00163                 L.logit ( L_ut, U );
    00164
    00165                 mat &A =model._A();
    00166                 mat R =model._R();
    00167                 if ( opt_L_theta ) {L.logit ( L_theta,vec ( A._data(), A.rows() *A.cols() ) );};
    00168                 if ( opt_L_theta ) {L.logit ( L_R, vec ( R._data(), R.rows() *R.rows() ) );};
    00169         }
    00170
    00171 };
    00172
    00173 class stateDS : public DS {
    00174 protected:
    00176         mpdf* IM;
    00178         mpdf* OM;
    00180         vec dt;
    00182         vec xt;
    00184         vec ut;
    00186         int L_xt;
    00187 public:
    00188         void getdata ( vec &dt0 ) {dt0=dt;}
    00189         void getdata ( vec &dt0, const ivec &indeces ) {dt0=dt ( indeces );}
    00190
    00191         stateDS ( mpdf* IM0, mpdf* OM0, int usize ) :DS ( ),IM ( IM0 ),OM ( OM0 ),
    00192                         dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {}
    00193         ~stateDS() {delete IM; delete OM;}
    00194         virtual void step() {
    00195                 xt=IM->samplecond ( concat ( xt,ut ) );
    00196                 dt=OM->samplecond ( concat ( xt,ut ) );
    00197         };
    00198
    00199         virtual void log_add ( logger &L ) {
    00200                 DS::log_add ( L );
    00201                 L_xt=L.add ( IM->_rv(),"true" );
    00202         }
    00203         virtual void logit ( logger &L ) {
    00204                 DS::logit ( L );
    00205                 L.logit ( L_xt,xt );
    00206         }
    00207
    00208 };
    00209
    00210 }; //namespace
    00211
    00212 #endif // DS_H