Show
Ignore:
Timestamp:
06/09/10 14:00:40 (14 years ago)
Author:
mido
Message:

astyle applied all over the library

Files:
1 modified

Legend:

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

    r1063 r1064  
    2222* \brief Memory storage of off-line data column-wise (used mostly in C++) 
    2323 
    24 The data are stored in an internal matrix \c Data .  
    25 Each column of Data corresponds to one discrete time observation \f$t\f$.  
     24The data are stored in an internal matrix \c Data . 
     25Each column of Data corresponds to one discrete time observation \f$t\f$. 
    2626 
    2727*/ 
    2828class MemDS : public DS { 
    2929protected: 
    30         //! internal matrix of data 
    31         mat Data; 
    32         //! active column in the Data matrix 
    33         int time; 
    34  
    35 public: 
    36         //!Default constructor 
    37         MemDS () {}; 
    38  
    39         //! Convenience constructor 
    40         MemDS ( mat &Dat ); 
    41  
    42         //! returns number of data in the file; 
    43         int max_length() { 
    44                 return Data.cols(); 
    45         } 
    46  
    47         void getdata ( vec &dt ) const; 
    48  
    49         void getdata ( vec &dt, const ivec &indices ); 
    50  
    51         void write ( const vec &ut ) { 
    52                 if (ut.size()>0){ 
    53                         bdm_error ( "MemDS::write is not supported" ); 
    54                 } 
    55         } 
    56  
    57         void write ( const vec &ut, const ivec &indices ) { 
    58                 if (ut.size()>0){ 
    59                         bdm_error ( "MemDS::write is not supported" ); 
    60                 } 
    61         } 
    62  
    63         void step(); 
    64  
    65         /*! Create object from the following structure 
    66         \code 
    67         class = 'MemDS'; 
    68         Data = [...];               % Data matrix with records stored in columns 
    69         --- optional fields --- 
    70         time = 0;                   % Index of the first column in the matrix Data 
    71         --- inherited fields --- 
    72         bdm::DS::from_setting 
    73         \endcode 
    74  
    75         If the optional fields are not given, they will be filled as follows: 
    76         \code 
    77         drv.names = { "" };                % empty name 
    78         drv.sizes = { no_rows_Data };      % full size of the record 
    79         time = 0; 
    80         \endcode 
    81  
    82         */ 
    83         void from_setting ( const Setting &set ); 
    84  
    85         void validate(); 
     30    //! internal matrix of data 
     31    mat Data; 
     32    //! active column in the Data matrix 
     33    int time; 
     34 
     35public: 
     36    //!Default constructor 
     37    MemDS () {}; 
     38 
     39    //! Convenience constructor 
     40    MemDS ( mat &Dat ); 
     41 
     42    //! returns number of data in the file; 
     43    int max_length() { 
     44        return Data.cols(); 
     45    } 
     46 
     47    void getdata ( vec &dt ) const; 
     48 
     49    void getdata ( vec &dt, const ivec &indices ); 
     50 
     51    void write ( const vec &ut ) { 
     52        if (ut.size()>0) { 
     53            bdm_error ( "MemDS::write is not supported" ); 
     54        } 
     55    } 
     56 
     57    void write ( const vec &ut, const ivec &indices ) { 
     58        if (ut.size()>0) { 
     59            bdm_error ( "MemDS::write is not supported" ); 
     60        } 
     61    } 
     62 
     63    void step(); 
     64 
     65    /*! Create object from the following structure 
     66    \code 
     67    class = 'MemDS'; 
     68    Data = [...];               % Data matrix with records stored in columns 
     69    --- optional fields --- 
     70    time = 0;                   % Index of the first column in the matrix Data 
     71    --- inherited fields --- 
     72    bdm::DS::from_setting 
     73    \endcode 
     74 
     75    If the optional fields are not given, they will be filled as follows: 
     76    \code 
     77    drv.names = { "" };                % empty name 
     78    drv.sizes = { no_rows_Data };      % full size of the record 
     79    time = 0; 
     80    \endcode 
     81 
     82    */ 
     83    void from_setting ( const Setting &set ); 
     84 
     85    void validate(); 
    8686}; 
    8787UIREGISTER ( MemDS ); 
     
    9393class FileDS: public MemDS { 
    9494protected: 
    95         string filename; 
    96 public: 
    97         /*! Create object from the following structure 
    98         \code 
    99         filename = 'data_file.ext';           % name of the file where the data sare stored 
    100         --- inherited fields --- 
    101         bdm::DS::from_setting 
    102         \endcode 
    103         */ 
    104         void from_setting ( const Setting & set ); 
     95    string filename; 
     96public: 
     97    /*! Create object from the following structure 
     98    \code 
     99    filename = 'data_file.ext';           % name of the file where the data sare stored 
     100    --- inherited fields --- 
     101    bdm::DS::from_setting 
     102    \endcode 
     103    */ 
     104    void from_setting ( const Setting & set ); 
    105105}; 
    106106 
     
    114114 
    115115public: 
    116         //! Convenience constructor 
    117         ITppFileDS ( const string &fname, const string &varname ) : FileDS() { 
    118                 it_file it ( fname ); 
    119                 it << Name ( varname ); 
    120                 it >> Data; 
    121                 time = 0; 
    122                 //delays are ignored 
    123         }; 
    124  
    125         ITppFileDS () : FileDS() { 
    126         }; 
    127  
    128         /*! Create object from the following structure 
    129         \code 
    130         class    = 'ITppFileDS';          
    131         filename = 'file_with_data.it'; 
    132         varname  = 'Data1';                  // Name of a variable in which the data are stored 
    133         --- inherited fields --- 
    134         bdm::DS::from_setting 
    135         \endcode 
    136         */ 
    137         void from_setting ( const Setting &set ); 
    138  
    139         // TODO dodelat void to_setting( Setting &set ) const; 
     116    //! Convenience constructor 
     117    ITppFileDS ( const string &fname, const string &varname ) : FileDS() { 
     118        it_file it ( fname ); 
     119        it << Name ( varname ); 
     120        it >> Data; 
     121        time = 0; 
     122        //delays are ignored 
     123    }; 
     124 
     125    ITppFileDS () : FileDS() { 
     126    }; 
     127 
     128    /*! Create object from the following structure 
     129    \code 
     130    class    = 'ITppFileDS'; 
     131    filename = 'file_with_data.it'; 
     132    varname  = 'Data1';                  // Name of a variable in which the data are stored 
     133    --- inherited fields --- 
     134    bdm::DS::from_setting 
     135    \endcode 
     136    */ 
     137    void from_setting ( const Setting &set ); 
     138 
     139    // TODO dodelat void to_setting( Setting &set ) const; 
    140140}; 
    141141UIREGISTER ( ITppFileDS ); 
     
    152152class CsvFileDS: public FileDS { 
    153153public: 
    154         /*! Create object from the following structure 
    155         \code  
    156         class = 'CsvFileDS'; 
    157         filename = 'file.csv'; 
    158         orientation = 'BY_ROW' or 'BY_COL';        % data records are stored in rows of columns (default). 
    159         --- inherited fields --- 
    160         bdm::DS::from_setting 
    161         \endcode 
    162         */ 
    163         void from_setting ( const Setting & set ); 
     154    /*! Create object from the following structure 
     155    \code 
     156    class = 'CsvFileDS'; 
     157    filename = 'file.csv'; 
     158    orientation = 'BY_ROW' or 'BY_COL';        % data records are stored in rows of columns (default). 
     159    --- inherited fields --- 
     160    bdm::DS::from_setting 
     161    \endcode 
     162    */ 
     163    void from_setting ( const Setting & set ); 
    164164}; 
    165165 
     
    175175class EpdfDS: public DS { 
    176176protected: 
    177         //! internal pointer to epdf from which we samplecond 
    178         shared_ptr<epdf> iepdf; 
    179         //! internal storage of data sample 
    180         vec dt; 
    181 public: 
    182         void step() { 
    183                 dt = iepdf->sample(); 
    184         } 
    185         void getdata ( vec &dt_out ) const { 
    186                 dt_out = dt; 
    187         } 
    188         void getdata ( vec &dt_out, const ivec &ids ) { 
    189                 dt_out = dt ( ids ); 
    190         } 
    191         const RV& _drv() const { 
    192                 return iepdf->_rv(); 
    193         } 
    194  
    195         //! Accepts action variable and schedule it for application. 
    196         virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 
    197  
    198         //! Accepts action variables at specific indices 
    199         virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 
    200  
    201         /*! Create object from the following structure 
    202         \code 
    203         class = 'EpdfDS'; 
    204         epdf = configuration of bdm::epdf        % unconditional density to sample from,  bdm::epdf::from_setting 
    205         \endcode 
    206         Does not inherit from bdm::DS::from_setting, names of data are taken from epdf.rv. 
    207         */ 
    208         void from_setting ( const Setting &set ) { 
    209                 iepdf = UI::build<epdf> ( set, "epdf", UI::compulsory ); 
    210                 bdm_assert ( iepdf->isnamed(), "Input epdf must be named, check if RV is given correctly" ); 
    211                 dt =  zeros ( iepdf->dimension() ); 
    212                 dtsize = dt.length(); 
    213                 Drv = iepdf->_rv(); 
    214                 utsize = 0; 
    215         } 
    216  
    217         void validate() { 
    218                 DS::validate(); 
    219  
    220                 dt = iepdf->sample(); 
    221         } 
     177    //! internal pointer to epdf from which we samplecond 
     178    shared_ptr<epdf> iepdf; 
     179    //! internal storage of data sample 
     180    vec dt; 
     181public: 
     182    void step() { 
     183        dt = iepdf->sample(); 
     184    } 
     185    void getdata ( vec &dt_out ) const { 
     186        dt_out = dt; 
     187    } 
     188    void getdata ( vec &dt_out, const ivec &ids ) { 
     189        dt_out = dt ( ids ); 
     190    } 
     191    const RV& _drv() const { 
     192        return iepdf->_rv(); 
     193    } 
     194 
     195    //! Accepts action variable and schedule it for application. 
     196    virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 
     197 
     198    //! Accepts action variables at specific indices 
     199    virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 
     200 
     201    /*! Create object from the following structure 
     202    \code 
     203    class = 'EpdfDS'; 
     204    epdf = configuration of bdm::epdf        % unconditional density to sample from,  bdm::epdf::from_setting 
     205    \endcode 
     206    Does not inherit from bdm::DS::from_setting, names of data are taken from epdf.rv. 
     207    */ 
     208    void from_setting ( const Setting &set ) { 
     209        iepdf = UI::build<epdf> ( set, "epdf", UI::compulsory ); 
     210        bdm_assert ( iepdf->isnamed(), "Input epdf must be named, check if RV is given correctly" ); 
     211        dt =  zeros ( iepdf->dimension() ); 
     212        dtsize = dt.length(); 
     213        Drv = iepdf->_rv(); 
     214        utsize = 0; 
     215    } 
     216 
     217    void validate() { 
     218        DS::validate(); 
     219 
     220        dt = iepdf->sample(); 
     221    } 
    222222}; 
    223223UIREGISTER ( EpdfDS ); 
     
    235235class PdfDS : public DS { 
    236236protected: 
    237         //! internal pointer to epdf from which we samplecond 
    238         shared_ptr<pdf> ipdf; 
    239         //! internal storage of data sample 
    240         vec yt; 
    241         //! input vector 
    242         vec ut; 
    243         //! datalink between ut and regressor 
    244         datalink_buffered ut2rgr; 
    245         //! datalink between yt and regressor 
    246         datalink_buffered yt2rgr; 
    247         //! numeric values of regressor 
    248         vec rgr; 
    249  
    250 public: 
    251         void step(); 
    252  
    253         void getdata ( vec &dt_out ) const; 
    254  
    255         void write ( const vec &ut0 ) { 
    256                 ut = ut0; 
    257         } 
    258         void write ( const vec &ut0, const ivec &ind ) { 
    259                 set_subvector ( ut, ind, ut0 ); 
    260         } 
    261  
    262  
    263         //! Returns data records at indices. 
    264         virtual void getdata ( vec &dt, const ivec &indices ) NOT_IMPLEMENTED_VOID; 
    265  
    266  
    267         /*! Create object from the following structure 
    268         \code 
    269         class = 'PdfDS'; 
    270         pdf = configuration of bdm::pdf;          % any offspring of pdf, bdm::pdf::from_setting 
    271         --- optional fields --- 
    272         init_rv = RV({'names',...},[sizes,...],[times,...]);   % define what rv to initialize - typically delayed values, time=-1, etc.! 
    273         init_values = [...];                      % vector of initial values corresponding to init_rv 
    274         \endcode 
    275         Class does not call from bdm::DS::from_setting, names of data are taken from pdf.rv and pdf.rvc. 
    276          
    277         If init_rv is not given, init_values are set to zero. 
    278         */ 
    279         void from_setting ( const Setting &set ) { 
    280                 ipdf = UI::build<pdf> ( set, "pdf", UI::compulsory ); 
    281  
    282                 RV Yrv = ipdf->_rv(); 
    283                 // get unique rvs form rvc 
    284                 RV rgrv0 = ipdf->_rvc().remove_time(); 
    285                 // input is what in not in Yrv 
    286                 Urv = rgrv0.subt ( Yrv ); 
    287                 Drv=  concat(Yrv,Urv); 
    288                 // connect input and output to rvc 
    289                 ut2rgr.set_connection ( ipdf->_rvc(), Urv ); 
    290                 yt2rgr.set_connection ( ipdf->_rvc(), Yrv ); 
    291  
    292                 //set history - if given 
    293                 shared_ptr<RV> rv_ini = UI::build<RV> ( set, "init_rv", UI::optional ); 
    294                 if ( rv_ini ) { // check if 
    295                         vec val; 
    296                         UI::get ( val, set, "init_values", UI::optional ); 
    297                         if ( val.length() != rv_ini->_dsize() ) { 
    298                                 bdm_error ( "init_rv and init_values fields have incompatible sizes" ); 
    299                         } else { 
    300                                 ut2rgr.set_history ( *rv_ini, val ); 
    301                                 yt2rgr.set_history ( *rv_ini, val ); 
    302                         } 
    303                 } 
    304  
    305                 yt = zeros ( ipdf->dimension() ); 
    306                 rgr = zeros ( ipdf->dimensionc() ); 
    307                 ut = zeros ( Urv._dsize() ); 
    308  
    309                 utsize = ut.length(); 
    310                 dtsize = yt.length() + utsize; 
    311         } 
    312  
    313         void validate() { 
    314                 DS::validate(); 
    315  
    316                 //taken from sample() - shift of history is not done here 
    317                 ut2rgr.filldown ( ut, rgr ); 
    318                 yt2rgr.filldown ( yt, rgr ); 
    319                 yt = ipdf->samplecond ( rgr ); 
    320         } 
     237    //! internal pointer to epdf from which we samplecond 
     238    shared_ptr<pdf> ipdf; 
     239    //! internal storage of data sample 
     240    vec yt; 
     241    //! input vector 
     242    vec ut; 
     243    //! datalink between ut and regressor 
     244    datalink_buffered ut2rgr; 
     245    //! datalink between yt and regressor 
     246    datalink_buffered yt2rgr; 
     247    //! numeric values of regressor 
     248    vec rgr; 
     249 
     250public: 
     251    void step(); 
     252 
     253    void getdata ( vec &dt_out ) const; 
     254 
     255    void write ( const vec &ut0 ) { 
     256        ut = ut0; 
     257    } 
     258    void write ( const vec &ut0, const ivec &ind ) { 
     259        set_subvector ( ut, ind, ut0 ); 
     260    } 
     261 
     262 
     263    //! Returns data records at indices. 
     264    virtual void getdata ( vec &dt, const ivec &indices ) NOT_IMPLEMENTED_VOID; 
     265 
     266 
     267    /*! Create object from the following structure 
     268    \code 
     269    class = 'PdfDS'; 
     270    pdf = configuration of bdm::pdf;          % any offspring of pdf, bdm::pdf::from_setting 
     271    --- optional fields --- 
     272    init_rv = RV({'names',...},[sizes,...],[times,...]);   % define what rv to initialize - typically delayed values, time=-1, etc.! 
     273    init_values = [...];                      % vector of initial values corresponding to init_rv 
     274    \endcode 
     275    Class does not call from bdm::DS::from_setting, names of data are taken from pdf.rv and pdf.rvc. 
     276 
     277    If init_rv is not given, init_values are set to zero. 
     278    */ 
     279    void from_setting ( const Setting &set ) { 
     280        ipdf = UI::build<pdf> ( set, "pdf", UI::compulsory ); 
     281 
     282        RV Yrv = ipdf->_rv(); 
     283        // get unique rvs form rvc 
     284        RV rgrv0 = ipdf->_rvc().remove_time(); 
     285        // input is what in not in Yrv 
     286        Urv = rgrv0.subt ( Yrv ); 
     287        Drv=  concat(Yrv,Urv); 
     288        // connect input and output to rvc 
     289        ut2rgr.set_connection ( ipdf->_rvc(), Urv ); 
     290        yt2rgr.set_connection ( ipdf->_rvc(), Yrv ); 
     291 
     292        //set history - if given 
     293        shared_ptr<RV> rv_ini = UI::build<RV> ( set, "init_rv", UI::optional ); 
     294        if ( rv_ini ) { // check if 
     295            vec val; 
     296            UI::get ( val, set, "init_values", UI::optional ); 
     297            if ( val.length() != rv_ini->_dsize() ) { 
     298                bdm_error ( "init_rv and init_values fields have incompatible sizes" ); 
     299            } else { 
     300                ut2rgr.set_history ( *rv_ini, val ); 
     301                yt2rgr.set_history ( *rv_ini, val ); 
     302            } 
     303        } 
     304 
     305        yt = zeros ( ipdf->dimension() ); 
     306        rgr = zeros ( ipdf->dimensionc() ); 
     307        ut = zeros ( Urv._dsize() ); 
     308 
     309        utsize = ut.length(); 
     310        dtsize = yt.length() + utsize; 
     311    } 
     312 
     313    void validate() { 
     314        DS::validate(); 
     315 
     316        //taken from sample() - shift of history is not done here 
     317        ut2rgr.filldown ( ut, rgr ); 
     318        yt2rgr.filldown ( yt, rgr ); 
     319        yt = ipdf->samplecond ( rgr ); 
     320    } 
    321321}; 
    322322UIREGISTER ( PdfDS );