datasources.h
Go to the documentation of this file.00001 00013 #ifndef DATASOURCE_H 00014 #define DATASOURCE_H 00015 00016 #include "../base/bdmbase.h" 00017 #include "../stat/exp_family.h" 00018 #include "../base/user_info.h" 00019 00020 namespace bdm { 00028 class MemDS : public DS { 00029 protected: 00031 mat Data; 00033 int time; 00034 00035 public: 00037 MemDS () {}; 00038 00040 MemDS ( mat &Dat ); 00041 00043 int max_length() { 00044 return Data.cols(); 00045 } 00046 00047 void getdata ( vec &dt ) const; 00048 00049 void getdata ( vec &dt, const ivec &indices ); 00050 00051 void write ( const vec &ut ) { 00052 if (ut.size()>0) { 00053 bdm_error ( "MemDS::write is not supported" ); 00054 } 00055 } 00056 00057 void write ( const vec &ut, const ivec &indices ) { 00058 if (ut.size()>0) { 00059 bdm_error ( "MemDS::write is not supported" ); 00060 } 00061 } 00062 00063 void step(); 00064 00083 void from_setting ( const Setting &set ); 00084 00085 void validate(); 00086 }; 00087 UIREGISTER ( MemDS ); 00088 00093 class FileDS: public MemDS { 00094 protected: 00095 string filename; 00096 public: 00104 void from_setting ( const Setting & set ); 00105 }; 00106 00113 class ITppFileDS: public FileDS { 00114 00115 public: 00117 ITppFileDS ( const string &fname, const string &varname ) : FileDS() { 00118 it_file it ( fname ); 00119 it << Name ( varname ); 00120 it >> Data; 00121 time = 0; 00122 //delays are ignored 00123 }; 00124 00125 ITppFileDS () : FileDS() { 00126 }; 00127 00137 void from_setting ( const Setting &set ); 00138 00139 // TODO dodelat void to_setting( Setting &set ) const; 00140 }; 00141 UIREGISTER ( ITppFileDS ); 00142 SHAREDPTR ( ITppFileDS ); 00143 00152 class CsvFileDS: public FileDS { 00153 public: 00163 void from_setting ( const Setting & set ); 00164 }; 00165 00166 00167 00168 // ARXDs - DELETED 00169 00175 class EpdfDS: public DS { 00176 protected: 00178 shared_ptr<epdf> iepdf; 00180 vec dt; 00181 public: 00182 void step() { 00183 dt = iepdf->sample(); 00184 } 00185 void getdata ( vec &dt_out ) const { 00186 dt_out = dt; 00187 } 00188 void getdata ( vec &dt_out, const ivec &ids ) { 00189 dt_out = dt ( ids ); 00190 } 00191 const RV& _drv() const { 00192 return iepdf->_rv(); 00193 } 00194 00196 virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 00197 00199 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 00200 00208 void from_setting ( const Setting &set ) { 00209 iepdf = UI::build<epdf> ( set, "epdf", UI::compulsory ); 00210 bdm_assert ( iepdf->isnamed(), "Input epdf must be named, check if RV is given correctly" ); 00211 dt = zeros ( iepdf->dimension() ); 00212 dtsize = dt.length(); 00213 Drv = iepdf->_rv(); 00214 utsize = 0; 00215 } 00216 00217 void validate() { 00218 DS::validate(); 00219 00220 dt = iepdf->sample(); 00221 } 00222 }; 00223 UIREGISTER ( EpdfDS ); 00224 00235 class PdfDS : public DS { 00236 public: 00238 shared_ptr<pdf> ipdf; 00239 protected: 00241 vec yt; 00243 vec ut; 00245 datalink_buffered ut2rgr; 00247 datalink_buffered yt2rgr; 00249 vec rgr; 00250 00252 RV init_rv; 00254 vec init_values; 00255 00256 public: 00257 void step(); 00258 00259 void getdata ( vec &dt_out ) const; 00260 00261 void write ( const vec &ut0 ) { 00262 ut = ut0; 00263 } 00264 void write ( const vec &ut0, const ivec &ind ) { 00265 set_subvector ( ut, ind, ut0 ); 00266 } 00267 00268 00270 virtual void getdata ( vec &dt, const ivec &indices ) NOT_IMPLEMENTED_VOID; 00271 00272 00285 void from_setting ( const Setting &set ) { 00286 ipdf = UI::build<pdf> ( set, "pdf", UI::compulsory ); 00287 UI::get ( init_rv, set, "init_rv", UI::optional); 00288 UI::get ( init_values, set, "init_values", UI::optional); 00289 } 00290 00291 void validate() { 00292 RV Yrv = ipdf->_rv(); 00293 // get unique rvs form rvc 00294 RV rgrv0 = ipdf->_rvc().remove_time(); 00295 // input is what in not in Yrv 00296 Urv = rgrv0.subt ( Yrv ); 00297 Drv= concat(Yrv,Urv); 00298 // connect input and output to rvc 00299 ut2rgr.set_connection ( ipdf->_rvc(), Urv ); 00300 yt2rgr.set_connection ( ipdf->_rvc(), Yrv ); 00301 00302 if ( init_rv._dsize()>0 ) { // check if 00303 if ( init_values.length() != init_rv._dsize() ) { 00304 bdm_error ( "init_rv and init_values fields have incompatible sizes" ); 00305 } else { 00306 ut2rgr.set_history ( init_rv, init_values ); 00307 yt2rgr.set_history ( init_rv, init_values ); 00308 } 00309 } 00310 00311 yt = zeros ( ipdf->dimension() ); 00312 rgr = zeros ( ipdf->dimensionc() ); 00313 ut = zeros ( Urv._dsize() ); 00314 00315 utsize = ut.length(); 00316 dtsize = yt.length() + utsize; 00317 00318 DS::validate(); 00319 00320 //taken from sample() - shift of history is not done here 00321 ut2rgr.filldown ( ut, rgr ); 00322 yt2rgr.filldown ( yt, rgr ); 00323 yt = ipdf->samplecond ( rgr ); 00324 } 00325 }; 00326 UIREGISTER ( PdfDS ); 00327 00328 }; //namespace 00329 00330 #endif // DS_H
Generated on 2 Dec 2013 for mixpp by 1.4.7