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

- File List
- File Members

# datasources.h

Go to the documentation of this file.

    00001
    00013 #ifndef DATASOURCE_H
    00014 #define DATASOURCE_H
    00015
    00016
    00017 #include "../base/bdmbase.h"
    00018 #include "../stat/exp_family.h"
    00019 #include "../base/user_info.h"
    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 &rowid0, ivec &delays0 );
    00050 };
    00051
    00055 class FileDS: public MemDS {
    00056
    00057 public:
    00058         void getdata ( vec &dt ) {
    00059                 it_assert_debug ( dt.length() ==Data.rows(),"" );
    00060                 dt = Data.get_col(time);
    00061         };
    00062         void getdata ( vec &dt, const ivec &indeces ){
    00063                 it_assert_debug ( dt.length() ==indeces.length(),"" );
    00064                 vec tmp(indeces.length());
    00065                 tmp = Data.get_col(time);
    00066                 dt = tmp(indeces);
    00067         };
    00069         int ndat(){return Data.cols();}
    00071         void log_add ( logger &L ) {};
    00073         void logit ( logger &L ) {};
    00074 };
    00075
    00082 class ITppFileDS: public FileDS {
    00083
    00084 public:
    00085         ITppFileDS ( const string &fname, const string &varname ) :FileDS() {
    00086                 it_file it ( fname );
    00087                 it << Name ( varname );
    00088                 it >> Data;
    00089                 time = 0;
    00090                 //rowid and delays are ignored
    00091         };
    00092
    00093         ITppFileDS () :FileDS() {
    00094         };
    00095
    00096         void from_setting( const Setting &set );
    00097
    00098         // TODO dodelat void to_setting( Setting &set ) const;
    00099
    00100 };
    00101
    00102 UIREGISTER(ITppFileDS);
    00103
    00111 class CsvFileDS: public FileDS {
    00112
    00113 public:
    00115         CsvFileDS ( const string& fname, const string& orientation = "BY_COL" );
    00116 };
    00117
    00118
    00119
    00124 class ArxDS : public DS {
    00125 protected:
    00127         RV Rrv;
    00129         vec H;
    00131         vec U;
    00133         vec rgr;
    00135         datalink rgrlnk;
    00137         mlnorm<chmat> model;
    00139         bool opt_L_theta;
    00141         int L_theta;
    00142         int L_R;
    00143         int dt_size;
    00144 public:
    00145         void getdata ( vec &dt ) {
    00146                 //it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" );
    00147                 dt=H;
    00148         };
    00149         void getdata ( vec &dt, const ivec &indices ) {
    00150                 it_assert_debug ( dt.length() ==indices.length(),"ArxDS" );
    00151                 dt=H ( indices );
    00152         };
    00153         void write ( vec &ut ) {
    00154                 //it_assert_debug ( ut.length() ==Urv.count(),"ArxDS" );
    00155                 U=ut;
    00156         };
    00157         void write ( vec &ut, const ivec &indices ) {
    00158                 it_assert_debug ( ut.length() ==indices.length(),"ArxDS" );
    00159                 set_subvector ( U, indices,ut );
    00160         };
    00161         void step();
    00163         ArxDS ( ) {};
    00165         void set_parameters ( const mat &Th0, const vec mu0, const chmat &sqR0 )
    00166         { model.set_parameters ( Th0, mu0, sqR0 );};
    00168         void set_drv ( RV &yrv, RV &urv, RV &rrv ) {
    00169                 Rrv = rrv;
    00170                 Urv = urv;
    00171                 dt_size = yrv._dsize() +urv._dsize();
    00172
    00173                 RV drv = concat ( yrv,urv );
    00174                 Drv = drv;
    00175                 int td = rrv.mint();
    00176                 H.set_size ( drv._dsize() * ( -td+1 ) );
    00177                 U.set_size ( Urv._dsize() );
    00178                 for ( int i=-1;i>=td;i-- ) {
    00179                         drv.t ( -1 );
    00180                         Drv.add ( drv ); //shift u1
    00181                 }
    00182                 rgrlnk.set_connection ( rrv,Drv );
    00183
    00184                 dtsize = Drv._dsize();
    00185                 utsize = Urv._dsize();
    00186         }
    00188         void set_options ( const string &s ) {
    00189                 opt_L_theta= ( s.find ( "L_theta" ) !=string::npos );
    00190         };
    00191         virtual void log_add ( logger &L ) {
    00192                 //DS::log_add ( L ); too long!!
    00193                 L_dt=L.add ( Drv ( 0,dt_size ),"" );
    00194                 L_ut=L.add ( Urv,"" );
    00195
    00196                 mat &A =model._A();
    00197                 mat R =model._R();
    00198                 if ( opt_L_theta ) {L_theta=L.add ( RV ( "{th }", vec_1 ( A.rows() *A.cols() ) ),"t" );}
    00199                 if ( opt_L_theta ) {L_R=L.add ( RV ( "{R }", vec_1 ( R.rows() *R.cols() ) ),"r" );}
    00200         }
    00201         virtual void logit ( logger &L ) {
    00202                 //DS::logit ( L );
    00203                 L.logit ( L_dt, H.left ( dt_size ) );
    00204                 L.logit ( L_ut, U );
    00205
    00206                 mat &A =model._A();
    00207                 mat R =model._R();
    00208                 if ( opt_L_theta ) {L.logit ( L_theta,vec ( A._data(), A.rows() *A.cols() ) );};
    00209                 if ( opt_L_theta ) {L.logit ( L_R, vec ( R._data(), R.rows() *R.rows() ) );};
    00210         }
    00211
    00212         // TODO dokumentace - aktualizovat
    00244         void from_setting( const Setting &set );
    00245
    00246         // TODO dodelat void to_setting( Setting &set ) const;
    00247 };
    00248
    00249 UIREGISTER( ArxDS );
    00250
    00251 class stateDS : public DS {
    00252 protected:
    00254         mpdf* IM;
    00256         mpdf* OM;
    00258         vec dt;
    00260         vec xt;
    00262         vec ut;
    00264         int L_xt;
    00265 public:
    00266         void getdata ( vec &dt0 ) {dt0=dt;}
    00267         void getdata ( vec &dt0, const ivec &indeces ) {dt0=dt ( indeces );}
    00268
    00269         stateDS ( mpdf* IM0, mpdf* OM0, int usize ) :DS ( ),IM ( IM0 ),OM ( OM0 ),
    00270                         dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {}
    00271
    00272         stateDS(){}
    00273
    00274         ~stateDS() {delete IM; delete OM;}
    00275         virtual void step() {
    00276                 xt=IM->samplecond ( concat ( xt,ut ) );
    00277                 dt=OM->samplecond ( concat ( xt,ut ) );
    00278         };
    00279
    00280         virtual void log_add ( logger &L ) {
    00281                 DS::log_add ( L );
    00282                 L_xt=L.add ( IM->_rv(),"true" );
    00283         }
    00284         virtual void logit ( logger &L ) {
    00285                 DS::logit ( L );
    00286                 L.logit ( L_xt,xt );
    00287         }
    00288
    00318         void from_setting( const Setting &set );
    00319
    00320         // TODO dodelat void to_setting( Setting &set ) const;
    00321
    00322 };
    00323
    00324 UIREGISTER(stateDS);
    00325
    00326 }; //namespace
    00327
    00328 #endif // DS_H