Changeset 892 for library/bdm

Show
Ignore:
Timestamp:
04/04/10 16:33:41 (14 years ago)
Author:
mido
Message:

trivial commit - sources of datasources reformatted and astylled without changing any functionality

Location:
library/bdm/base
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/datasources.cpp

    r795 r892  
    4242} 
    4343 
     44void ITppFileDS::from_setting ( const Setting &set ) { 
     45        shared_ptr<RV> rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory ); 
     46 
     47        it_file it ( set["filename"] ); 
     48        it << Name ( set["varname"] ); 
     49        it >> Data; 
     50        time = 0; 
     51        //rowid and delays are ignored 
     52        rowid = linspace ( 0, Data.rows() - 1 ); 
     53        set_drv ( *rvtmp, RV() ); 
     54} 
     55 
    4456void PdfDS::step() { 
    4557        yt2rgr.store_data ( yt ); // y is now history 
     
    7183        dt.set_subvector ( yt.length(), xt ); 
    7284        dt.set_subvector ( ytsize, ut ); 
    73 } 
    74  
    75 // void ArxDS::step() { 
    76 //      //shift history 
    77 //      H.shift_right ( 0, dt_size ); 
    78 // 
    79 //      H.set_subvector ( dt_size - utsize, U ); // write U after Drv 
    80 // 
    81 //      //get regressor 
    82 //      rgr = rgrlnk.pushdown ( H ); 
    83 //      // Eval Y 
    84 //      H.set_subvector ( 0, model.samplecond ( rgr ) ); 
    85 // 
    86 // } 
    87 // 
    88 // void ArxDS::from_setting ( const Setting &set ) { 
    89 //      shared_ptr<RV> yrv = UI::build<RV> ( set, "y" , UI::compulsory ); 
    90 //      shared_ptr<RV> urv = UI::build<RV> ( set, "u" , UI::compulsory ); 
    91 //      shared_ptr<RV> rrv = UI::build<RV> ( set, "rgr" , UI::compulsory ); 
    92 // 
    93 //      mat Th; 
    94 //      UI::get ( Th, set, "theta", UI::compulsory ); 
    95 // 
    96 //      vec mu0; 
    97 //      if ( !UI::get ( mu0, set, "offset" ) ) 
    98 //              mu0 = zeros ( yrv->_dsize() ); 
    99 // 
    100 //      mat sqR; 
    101 //      UI::get ( sqR, set, "r", UI::compulsory ); 
    102 //      set_parameters ( Th, mu0, sqR ); 
    103 //      set_drv ( *yrv, *urv, *rrv ); 
    104 // 
    105 //      if ( set.exists ( "opt" ) ) 
    106 //              set_options ( set["opt"] ); 
    107 // } 
    108  
    109 CsvFileDS::CsvFileDS ( const string& fname, const string& orientation ) : FileDS() { 
    110         time = 0; 
    111  
    112         vec data_line; 
    113         string line; 
    114  
    115         ifstream fs; 
    116         fs.open ( fname.c_str() ); 
    117         if ( fs.is_open() ) { 
    118                 while ( getline ( fs, line ) ) { 
    119                         data_line.set ( line ); 
    120                         Data.append_row ( data_line ); 
    121                 } 
    122         } 
    123  
    124         if ( orientation == "BY_ROW" ) { 
    125                 transpose ( Data, Data ); 
    126         } 
    127  
    128  
    129 } 
    130  
    131 //! Auxiliary function building full history of rv0 
    132 RV fullrgr ( const RV &drv0, const RV &urv0, const RV &rrv0 ) { 
    133         RV T ( urv0 ); 
    134         RV pom = concat ( drv0, urv0 ); 
    135         int mint = rrv0.mint(); 
    136         for ( int i = 0; i > mint; i-- ) { 
    137                 pom.t_plus ( -1 ); 
    138                 T.add ( pom ); 
    139         } 
    140         return T; 
    141 } 
    142  
    143 void ITppFileDS::from_setting ( const Setting &set ) { 
    144         shared_ptr<RV> rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory ); 
    145  
    146         it_file it ( set["filename"] ); 
    147         it << Name ( set["varname"] ); 
    148         it >> Data; 
    149         time = 0; 
    150         //rowid and delays are ignored 
    151         rowid = linspace ( 0, Data.rows() - 1 ); 
    152         set_drv ( *rvtmp, RV() ); 
    15385} 
    15486 
  • library/bdm/base/datasources.h

    r795 r892  
    1313#ifndef DATASOURCE_H 
    1414#define DATASOURCE_H 
    15  
    1615 
    1716#include "../base/bdmbase.h" 
     
    104103UIREGISTER ( MemDS ); 
    105104 
     105/*! Pseudovirtual class for reading data from files 
     106 
     107*/ 
     108class FileDS: public MemDS { 
     109 
     110public: 
     111        void getdata ( vec &dt ) { 
     112                dt = Data.get_col ( time ); 
     113        } 
     114 
     115        void getdata ( vec &dt, const ivec &indices ) { 
     116                vec tmp = Data.get_col ( time ); 
     117                dt = tmp ( indices ); 
     118        } 
     119 
     120        //! returns number of data in the file; 
     121        int ndat() { 
     122                return Data.cols(); 
     123        } 
     124        //! no sense to log this type 
     125        void log_register ( logger &L, const string &prefix ) {}; 
     126        //! no sense to log this type 
     127        void log_write ( ) const {}; 
     128}; 
     129 
     130/*! 
     131* \brief Read Data Matrix from an IT file 
     132 
     133The constructor creates an internal matrix \c Data from an IT++ file. The file is binary and can be made using the IT++ library or the Matlab/Octave function itsave. NB: the data are stored columnwise, i.e. each column contains the data for time \f$t\f$! 
     134 
     135*/ 
     136class ITppFileDS: public FileDS { 
     137 
     138public: 
     139        //! Convenience constructor 
     140        ITppFileDS ( const string &fname, const string &varname ) : FileDS() { 
     141                it_file it ( fname ); 
     142                it << Name ( varname ); 
     143                it >> Data; 
     144                time = 0; 
     145                //rowid and delays are ignored 
     146        }; 
     147 
     148        ITppFileDS () : FileDS() { 
     149        }; 
     150 
     151        void from_setting ( const Setting &set ); 
     152 
     153        // TODO dodelat void to_setting( Setting &set ) const; 
     154 
     155}; 
     156 
     157UIREGISTER ( ITppFileDS ); 
     158SHAREDPTR ( ITppFileDS ); 
     159 
     160/*! 
     161* \brief CSV file data storage 
     162The constructor creates \c Data matrix from the records in a CSV file \c fname. The orientation can be of two types: 
     1631. \c BY_COL which is default - the data are stored in columns; one column per time \f$t\f$, one row per data item. 
     1642. \c BY_ROW if the data are stored the classical CSV style. Then each column stores the values for data item, for ex. \f$[y_{t} y_{t-1} ...]\f$, one row for each discrete time instant. 
     165 
     166*/ 
     167class CsvFileDS: public FileDS { 
     168 
     169public: 
     170        //! Constructor - create DS from a CSV file. 
     171        CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 
     172}; 
     173 
     174 
     175 
     176// ARXDs - DELETED 
     177 
    106178/*!  \brief Simulate data from a static pdf (epdf) 
    107179 
     
    129201        } 
    130202 
    131         //! Accepts action variable and schedule it for application.     
     203        //! Accepts action variable and schedule it for application. 
    132204        virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 
    133                  
     205 
    134206        //! Accepts action variables at specific indeces 
    135207        virtual void write ( const vec &ut, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 
     
    252324UIREGISTER ( PdfDS ); 
    253325 
    254 /*! Pseudovirtual class for reading data from files 
    255  
    256 */ 
    257 class FileDS: public MemDS { 
    258  
    259 public: 
    260         void getdata ( vec &dt ) { 
    261                 dt = Data.get_col ( time ); 
    262         } 
    263  
    264         void getdata ( vec &dt, const ivec &indices ) { 
    265                 vec tmp = Data.get_col ( time ); 
    266                 dt = tmp ( indices ); 
    267         } 
    268  
    269         //! returns number of data in the file; 
    270         int ndat() { 
    271                 return Data.cols(); 
    272         } 
    273         //! no sense to log this type 
    274         void log_register ( logger &L, const string &prefix ) {}; 
    275         //! no sense to log this type 
    276         void log_write ( ) const {}; 
    277 }; 
    278  
    279 /*! 
    280 * \brief Read Data Matrix from an IT file 
    281  
    282 The constructor creates an internal matrix \c Data from an IT++ file. The file is binary and can be made using the IT++ library or the Matlab/Octave function itsave. NB: the data are stored columnwise, i.e. each column contains the data for time \f$t\f$! 
    283  
    284 */ 
    285 class ITppFileDS: public FileDS { 
    286  
    287 public: 
    288         //! Convenience constructor 
    289         ITppFileDS ( const string &fname, const string &varname ) : FileDS() { 
    290                 it_file it ( fname ); 
    291                 it << Name ( varname ); 
    292                 it >> Data; 
    293                 time = 0; 
    294                 //rowid and delays are ignored 
    295         }; 
    296  
    297         ITppFileDS () : FileDS() { 
    298         }; 
    299  
    300         void from_setting ( const Setting &set ); 
    301  
    302         // TODO dodelat void to_setting( Setting &set ) const; 
    303  
    304 }; 
    305  
    306 UIREGISTER ( ITppFileDS ); 
    307 SHAREDPTR ( ITppFileDS ); 
    308  
    309 /*! 
    310 * \brief CSV file data storage 
    311 The constructor creates \c Data matrix from the records in a CSV file \c fname. The orientation can be of two types: 
    312 1. \c BY_COL which is default - the data are stored in columns; one column per time \f$t\f$, one row per data item. 
    313 2. \c BY_ROW if the data are stored the classical CSV style. Then each column stores the values for data item, for ex. \f$[y_{t} y_{t-1} ...]\f$, one row for each discrete time instant. 
    314  
    315 */ 
    316 class CsvFileDS: public FileDS { 
    317  
    318 public: 
    319         //! Constructor - create DS from a CSV file. 
    320         CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 
    321 }; 
    322  
    323  
    324  
    325 // ARXDs - DELETED 
    326  
    327326//! State-space data source simulating two densities 
    328327class StateDS : public DS {