- Timestamp:
- 09/04/09 00:45:40 (15 years ago)
- Location:
- library
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r600 r603 242 242 //! Minimum time-offset 243 243 int mint() const { 244 return min ( times );244 return times.length()>0 ? min (times) : 0; 245 245 } 246 246 //!@} … … 676 676 //! h2v : indeces in history 677 677 ivec h2v_hist; 678 //! v2h: indeces of up too be pushed to h 679 ivec v2h_up; 678 680 public: 679 681 … … 683 685 if ( Hrv._dsize() > 0 ) { 684 686 history.shift_right ( 0, Hrv._dsize() ); 685 history.set_subvector ( 0, val_up); // write U after Drv687 history.set_subvector ( 0, val_up(v2h_up) ); // write U after Drv 686 688 } 687 689 } … … 708 710 ivec valid_ids = rv.findself_ids ( rv_up ); 709 711 RV rv_hist = rv.subselect ( find ( valid_ids >= 0 ) ); // select only rvs that are in rv_up 712 RV rv_hist0 =rv_hist.remove_time(); // these RVs will form history at time =0 713 v2h_up = rv_hist0.dataind(rv_up); // indeces of elements of rv_up to be copied 714 // now we need to know what is needed from Up 710 715 rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0 711 Hrv = rv_hist.subt ( rv.remove_time()); // remove time 0716 Hrv=rv_hist.subt(rv_hist0); // remove time 0 712 717 history = zeros ( Hrv._dsize() ); 713 718 … … 893 898 /*! \brief Abstract class for discrete-time sources of data. 894 899 895 The class abstracts operations of: (i) data aquisition, (ii) data-preprocessing, (iii) scaling of data, and (iv) data resampling from the task of estimation and control. 900 The class abstracts operations of: 901 \li data aquisition, 902 \li data-preprocessing, such as scaling of data, 903 \li data resampling from the task of estimation and control. 896 904 Moreover, for controlled systems, it is able to receive the desired control action and perform it in the next step. (Or as soon as possible). 897 905 906 The DataSource has three main data interaction structures: 907 \li input, \f$ u_t \f$, 908 \li output \f$ y_t \f$, 909 \li data, \f$ d_t=[y_t,u_t, \ldots ]\f$ a collection of all inputs and outputs and possibly some internal variables too. 910 898 911 */ 899 912 900 913 class DS : public root { 901 914 protected: 915 //! size of data returned by \c getdata() 902 916 int dtsize; 917 //! size of data 903 918 int utsize; 919 //!size of output 920 int ytsize; 904 921 //!Description of data returned by \c getdata(). 905 922 RV Drv; 906 923 //!Description of data witten by by \c write(). 907 924 RV Urv; // 925 //!Description of output data 926 RV Yrv; // 908 927 //! Remember its own index in Logger L 909 928 int L_dt, L_ut; 910 929 public: 911 930 //! default constructors 912 DS() : Drv(), Urv() {};931 DS() : Drv(), Urv(),Yrv() {}; 913 932 914 933 //! Returns full vector of observed data=[output, input] … … 961 980 return Urv; 962 981 } 982 //!access function 983 const RV& _yrv() const { 984 return Yrv; 985 } 963 986 //! set random variables 964 virtual void set_drv ( const RV &drv, const RV &urv ) { 965 Drv = drv; 987 virtual void set_drv (const RV &yrv, const RV &urv) { 988 Yrv = yrv; 989 Drv = concat(yrv,urv); 966 990 Urv = urv; 967 991 } -
library/bdm/base/datasources.h
r598 r603 103 103 shared_ptr<mpdf> impdf; 104 104 //! internal storage of data sample 105 vec dt;105 vec yt; 106 106 //! input vector 107 107 vec ut; 108 //! datalink between dt and ut and regressor 109 datalink_2to1_buffered rgrlink; 108 //! datalink between ut and regressor 109 datalink_buffered ut2rgr; 110 //! datalink between yt and regressor 111 datalink_buffered yt2rgr; 110 112 //! numeric values of regressor 111 113 vec rgr; … … 113 115 public: 114 116 void step() { 115 rgrlink.filldown ( dt,ut,rgr ); 116 rgrlink.step(dt,ut);//whist history 117 dt=impdf->samplecond ( rgr ); 117 yt2rgr.step(yt); // y is now history 118 ut2rgr.filldown ( ut,rgr ); 119 yt2rgr.filldown ( yt,rgr ); 120 yt=impdf->samplecond ( rgr ); 121 ut2rgr.step(ut); //u is now history 118 122 } 119 123 void getdata ( vec &dt_out ) { 120 dt_out = dt; 121 } 122 void getdata ( vec &dt_out, const ivec &ids ) { 123 dt_out = dt ( ids ); 124 } 125 const RV& _drv() const { 126 return impdf->_rv(); 124 bdm_assert_debug(dt_out.length()>=utsize+ytsize,"Short output vector"); 125 dt_out.set_subvector(0, yt); 126 dt_out.set_subvector(ytsize, ut); 127 127 } 128 128 void write(const vec &ut0){ut=ut0;} … … 131 131 \code 132 132 class = "MpdfDS"; 133 mpdf = {class=" epdf_offspring", ...}// list of points133 mpdf = {class="mpdf_offspring", ...}// mpdf to simulate 134 134 \endcode 135 135 … … 138 138 impdf=UI::build<mpdf> ( set,"mpdf",UI::compulsory ); 139 139 140 Yrv = impdf->_rv(); 140 141 // get unique rvs form rvc 141 142 RV rgrv0=impdf->_rvc().remove_time(); 142 // input is what in not in _rv()143 RV urv=rgrv0.subt(impdf->_rv());144 set_drv( impdf->_rv(), urv);143 // input is what in not in Yrv 144 Urv=rgrv0.subt(Yrv); 145 set_drv(Yrv, Urv); 145 146 // connect input and output to rvc 146 rgrlink.set_connection(impdf->_rvc(), Drv,Urv); 147 148 dt = zeros ( impdf->dimension() ); 147 ut2rgr.set_connection(impdf->_rvc(), Urv); 148 yt2rgr.set_connection(impdf->_rvc(), Yrv); 149 150 yt = zeros ( impdf->dimension() ); 149 151 rgr = zeros ( impdf->dimensionc() ); 150 ut = zeros(urv._dsize()); 152 ut = zeros(Urv._dsize()); 153 154 ytsize=yt.length(); 155 utsize=ut.length(); 156 dtsize = ytsize+utsize; 151 157 } 152 158 }; -
library/tests/datasource_test.cpp
r598 r603 25 25 shared_ptr<MpdfDS> ds=UI::build<MpdfDS>(uif, "ds", UI::compulsory); 26 26 27 vec dt = zeros( 1);27 vec dt = zeros(2); 28 28 vec ut="1.0"; 29 29 ds->write(ut); … … 32 32 } 33 33 ds->getdata(dt); 34 CHECK_CLOSE ( -0.2 , dt(0), 1e- 5);34 CHECK_CLOSE ( -0.2 , dt(0), 1e-4); 35 35 36 36 ut="2.0"; … … 40 40 } 41 41 ds->getdata(dt); 42 CHECK_CLOSE ( -0.4 , dt(0), 1e- 5);42 CHECK_CLOSE ( -0.4 , dt(0), 1e-4); 43 43 }