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 | |
| 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(); |
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; |
| 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 | } |
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 | |
| 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 | } |