Changeset 603

Show
Ignore:
Timestamp:
09/04/09 00:45:40 (15 years ago)
Author:
smidl
Message:

datasources revisited...

Location:
library
Files:
3 modified

Legend:

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

    r600 r603  
    242242        //! Minimum time-offset 
    243243        int mint() const { 
    244                 return min ( times ); 
     244                        return times.length()>0 ? min (times) : 0; 
    245245        } 
    246246        //!@} 
     
    676676        //! h2v : indeces in history 
    677677        ivec h2v_hist; 
     678        //! v2h: indeces of up too be pushed to h 
     679        ivec v2h_up; 
    678680public: 
    679681 
     
    683685                if ( Hrv._dsize() > 0 ) { 
    684686                        history.shift_right ( 0, Hrv._dsize() ); 
    685                         history.set_subvector ( 0, val_up ); // write U after Drv 
     687                  history.set_subvector ( 0, val_up(v2h_up) ); // write U after Drv 
    686688                } 
    687689        } 
     
    708710                ivec valid_ids = rv.findself_ids ( rv_up ); 
    709711                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 
    710715                rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0 
    711                 Hrv = rv_hist.subt ( rv.remove_time() );   // remove time 0 
     716          Hrv=rv_hist.subt(rv_hist0);   // remove time 0 
    712717                history = zeros ( Hrv._dsize() ); 
    713718 
     
    893898/*! \brief Abstract class for discrete-time sources of data. 
    894899 
    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. 
     900The 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. 
    896904Moreover, for controlled systems, it is able to receive the desired control action and perform it in the next step. (Or as soon as possible). 
    897905 
     906The 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 
    898911*/ 
    899912 
    900913class DS : public root { 
    901914protected: 
     915                //! size of data returned by \c getdata() 
    902916        int dtsize; 
     917                //! size of data 
    903918        int utsize; 
     919                //!size of output 
     920                int ytsize; 
    904921        //!Description of data returned by \c getdata(). 
    905922        RV Drv; 
    906923        //!Description of data witten by by \c write(). 
    907924        RV Urv; // 
     925                //!Description of output data 
     926                RV Yrv; // 
    908927        //! Remember its own index in Logger L 
    909928        int L_dt, L_ut; 
    910929public: 
    911930        //! default constructors 
    912         DS() : Drv(), Urv() {}; 
     931                DS() : Drv(), Urv(),Yrv() {}; 
    913932 
    914933        //! Returns full vector of observed data=[output, input] 
     
    961980                return Urv; 
    962981        } 
     982                //!access function 
     983                const RV& _yrv() const { 
     984                        return Yrv; 
     985                } 
    963986        //! 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); 
    966990                Urv = urv; 
    967991        } 
  • library/bdm/base/datasources.h

    r598 r603  
    103103                shared_ptr<mpdf> impdf; 
    104104                //! internal storage of data sample 
    105                 vec dt; 
     105                vec yt; 
    106106                //! input vector 
    107107                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; 
    110112                //! numeric values of regressor 
    111113                vec rgr; 
     
    113115        public: 
    114116                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 
    118122                } 
    119123                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); 
    127127                } 
    128128                void write(const vec &ut0){ut=ut0;} 
     
    131131                \code 
    132132                class = "MpdfDS"; 
    133                 mpdf = {class="epdf_offspring", ...}// list of points 
     133                mpdf = {class="mpdf_offspring", ...}// mpdf to simulate 
    134134                \endcode 
    135135 
     
    138138                        impdf=UI::build<mpdf> ( set,"mpdf",UI::compulsory ); 
    139139                         
     140                        Yrv = impdf->_rv(); 
    140141                        // get unique rvs form rvc 
    141142                        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); 
    145146                        // 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() ); 
    149151                        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; 
    151157                } 
    152158}; 
  • library/tests/datasource_test.cpp

    r598 r603  
    2525        shared_ptr<MpdfDS> ds=UI::build<MpdfDS>(uif, "ds", UI::compulsory); 
    2626         
    27         vec dt = zeros(1); 
     27        vec dt = zeros(2); 
    2828        vec ut="1.0"; 
    2929        ds->write(ut); 
     
    3232        } 
    3333        ds->getdata(dt); 
    34         CHECK_CLOSE ( -0.2 , dt(0), 1e-5); 
     34        CHECK_CLOSE ( -0.2 , dt(0), 1e-4); 
    3535 
    3636        ut="2.0"; 
     
    4040        } 
    4141        ds->getdata(dt); 
    42         CHECK_CLOSE ( -0.4 , dt(0), 1e-5); 
     42        CHECK_CLOSE ( -0.4 , dt(0), 1e-4); 
    4343}