Changeset 896
- Timestamp:
- 04/09/10 09:31:37 (15 years ago)
- Files:
-
- 14 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/CMakeLists.txt
r653 r896 14 14 link_directories (${BDM_SOURCE_DIR}/bdm) 15 15 16 #EXEC(estimator) 17 18 IF(MATLAB_FOUND) 19 add_subdirectory (mex) 20 ENDIF(MATLAB_FOUND) 16 add_subdirectory (mex) -
library/bdm/base/bdmbase.cpp
r889 r896 522 522 // decide if we need to copy val to history 523 523 if ( Hrv._dsize() > 0 ) { 524 v2h_up = rv_hist0.dataind ( rv_up ); // ind eces of elements of rv_up to be copied524 v2h_up = rv_hist0.dataind ( rv_up ); // indices of elements of rv_up to be copied 525 525 } // else v2h_up is empty 526 526 … … 535 535 ivec ind_H; 536 536 ivec ind_h0; 537 Hrv.dataind ( rv1, ind_H, ind_h0 ); // find ind eces of rv in537 Hrv.dataind ( rv1, ind_H, ind_h0 ); // find indices of rv in 538 538 set_subvector ( history, ind_H, hist0 ( ind_h0 ) ); // copy given hist to appropriate places 539 539 } -
library/bdm/base/bdmbase.h
r895 r896 594 594 //!@} 595 595 void from_setting ( const Setting &set ) { 596 root::from_setting( set ); 596 597 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 597 598 if ( r ) { … … 740 741 class datalink_part : public datalink { 741 742 protected: 742 //! ind eces of values in vector downsize743 //! indices of values in vector downsize 743 744 ivec v2v_down; 744 745 public: … … 760 761 //! rv of the history 761 762 RV Hrv; 762 //! h2v : ind eces in down763 //! h2v : indices in down 763 764 ivec h2v_down; 764 //! h2v : ind eces in history765 //! h2v : indices in history 765 766 ivec h2v_hist; 766 //! v2h: ind eces of up too be pushed to h767 //! v2h: indices of up too be pushed to h 767 768 ivec v2h_up; 768 769 public: … … 932 933 virtual void getdata ( vec &dt ) const = 0; 933 934 934 //! Returns data records at ind eces. Default is inefficent.935 virtual void getdata ( vec &dt, const ivec &ind eces ) {935 //! Returns data records at indices. Default is inefficent. 936 virtual void getdata ( vec &dt, const ivec &indices ) { 936 937 vec tmp(dtsize); 937 938 getdata(tmp); 938 dt = tmp(ind eces);939 dt = tmp(indices); 939 940 }; 940 941 … … 942 943 virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 943 944 944 //! Accepts action variables at specific ind eces945 virtual void write ( const vec &ut, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;945 //! Accepts action variables at specific indices 946 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 946 947 947 948 //! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system. … … 960 961 return Urv; 961 962 } 963 962 964 //! set random variables 963 965 virtual void set_drv ( const RV &drv, const RV &urv) { -
library/bdm/base/datasources.cpp
r895 r896 1 2 1 #include "datasources.h" 3 2 4 3 using namespace bdm; 5 4 6 void MemDS::getdata ( vec &dt ) const { 7 int i; 8 9 bdm_assert_debug ( dt.length() == rowid.length(), "MemDS:getdata incompatible dt" ); 10 for ( i = 0; i < rowid.length(); i++ ) { 11 dt ( i ) = Data ( rowid ( i ), time ); 12 } 5 MemDS::MemDS ( mat &Dat ) : Data( Dat ) { 13 6 } 14 7 15 void MemDS::getdata ( vec &dt, const ivec &indeces ) { 16 int j, i; 17 bdm_assert_debug ( dt.length() == indeces.length(), "MemDS:getdata incompatible dt" ); 18 for ( i = 0; i < indeces.length(); i++ ) { 19 j = indeces ( i ); 20 dt ( i ) = Data ( rowid ( j ), time ); 21 } 22 } 23 24 void MemDS::step() { 25 if ( time < Data.cols() ) { 8 void MemDS::step( ) { 9 if ( time < max_length() ) { 26 10 time++; 27 11 } 28 12 } 29 13 30 void MemDS::set_drv ( const RV &drv, const RV &urv ) { 31 bdm_assert_debug ( drv._dsize() == rowid.length(), "MemDS::set_rvs incompatible drv" ); 32 bdm_assert_debug ( urv._dsize() == 0, "MemDS does not support urv." ); 33 34 DS::set_drv ( drv, urv ); 14 void MemDS::getdata ( vec &dt ) const { 15 bdm_assert_debug ( dt.length() == Data.rows(), "MemDS:getdata incompatible dt" ); 16 dt = Data.get_col ( time ); 35 17 } 36 18 37 MemDS::MemDS ( mat &Dat, ivec &rowid0 ) : rowid ( rowid0 ) { 38 bdm_assert_debug ( max ( rowid ) <= Dat.rows(), "MemDS rowid is too high for given Dat." ); 19 void MemDS::getdata ( vec &dt, const ivec &indices ) { 20 bdm_assert_debug ( dt.length() == indices.length(), "MemDS:getdata incompatible dt" ); 21 vec tmp = Data.get_col ( time ); 22 dt = tmp ( indices ); 23 } 24 25 void MemDS::set_drv ( const RV &drv ) { 26 bdm_assert_debug ( drv._dsize() == Data.rows(), "MemDS::set_rvs incompatible drv" ); 27 DS::set_drv ( drv, RV() ); 28 } 29 30 void MemDS::from_setting ( const Setting &set ) { 31 DS::from_setting ( set ); 32 33 UI::get ( Data, set, "Data", UI::compulsory ); 34 35 if ( !UI::get ( time, set, "time", UI::optional ) ) { 36 time = 0; 37 } 38 39 shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional ); 40 if ( !r ) { 41 r = new RV(); 42 for ( int i = 0; i < Data.rows(); i++ ) { 43 r->add ( RV ( "ch" + num2str ( i ), 1, 0 ) ); 44 } 45 } 46 47 set_drv ( *r ); 48 dtsize = r->_dsize(); 49 utsize = 0; 50 } 51 52 void FileDS::from_setting ( const Setting & set ) { 53 // here we do not call MemDS::from_setting intentionally as we can not load any Data matrix directly 54 DS::from_setting ( set ); 55 56 string filename; 57 UI::get ( filename, set, "filename", UI::compulsory ); 39 58 40 59 time = 0; 41 Data = Dat; 60 61 shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional ); 62 if ( !r ) { 63 r = new RV(); 64 for ( int i = 0; i < Data.rows(); i++ ) { 65 r->add ( RV ( "ch" + num2str ( i ), 1, 0 ) ); 66 } 67 } 68 69 set_drv ( *r ); 70 dtsize = r->_dsize(); 71 utsize = 0; 42 72 } 43 73 44 void ITppFileDS::from_setting ( const Setting &set ) {45 shared_ptr<RV> rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory);74 void CsvFileDS::from_setting ( const Setting & set ) { 75 FileDS::from_setting ( set ); 46 76 47 it_file it ( set["filename"] ); 48 it << Name ( set["varname"] ); 77 vec data_line; 78 string line; 79 80 ifstream fs; 81 fs.open ( filename.c_str() ); 82 if ( fs.is_open() ) { 83 while ( getline ( fs, line ) ) { 84 data_line.set ( line ); 85 Data.append_row ( data_line ); 86 } 87 } 88 89 string orientation; 90 if( UI::get ( orientation, set, "orientation", UI::optional ) & orientation == "BY_ROW" ) 91 transpose ( Data, Data ); 92 } 93 94 void ITppFileDS::from_setting ( const Setting & set ) { 95 FileDS::from_setting ( set ); 96 97 string varname; 98 UI::get ( varname, set, "varname", UI::compulsory ); 99 100 it_file it ( filename ); 101 it << Name ( varname ); 49 102 it >> Data; 50 time = 0;51 //rowid and delays are ignored52 rowid = linspace ( 0, Data.rows() - 1 );53 set_drv ( *rvtmp, RV() );54 103 } 55 104 … … 62 111 } 63 112 64 void PdfDS::getdata ( vec & dt_out ) const {113 void PdfDS::getdata ( vec & dt_out ) const { 65 114 bdm_assert_debug ( dt_out.length() >= dtsize, "Short output vector" ); 66 115 dt_out.set_subvector ( 0, yt ); … … 85 134 } 86 135 87 void StateDS::from_setting ( const Setting & set ) {136 void StateDS::from_setting ( const Setting & set ) { 88 137 IM = UI::build<pdf> ( set, "IM", UI::compulsory ); 89 138 OM = UI::build<pdf> ( set, "OM", UI::compulsory ); -
library/bdm/base/datasources.h
r895 r896 32 32 //! active column in the Data matrix 33 33 int time; 34 //! vector of rows that are presented in Dt 35 ivec rowid; 36 37 public: 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; 38 43 int max_length() { 39 44 return Data.cols(); 40 45 } 46 41 47 void getdata ( vec &dt ) const; 42 void getdata ( vec &dt, const ivec &indeces ); 43 void set_drv ( const RV &drv, const RV &urv ); 48 49 void getdata ( vec &dt, const ivec &indices ); 50 51 void set_drv ( const RV &drv ); 52 53 void set_drv ( const RV &drv, const RV &urv ) 54 { 55 bdm_error ( "MemDS::urv is not supported" ); 56 } 44 57 45 58 void write ( const vec &ut ) { … … 52 65 53 66 void step(); 54 //!Default constructor 55 MemDS () {}; 56 //! Convenience constructor 57 MemDS ( mat &Dat, ivec &rowid0 ); 67 58 68 /*! Create object from the following structure 59 69 \code … … 63 73 drv = {class="RV"; ...} // Identification how rows of the matrix Data will be known to others 64 74 time = 0; // Index of the first column to user_info, 65 rowid = [1,2,3...]; // ids of rows to be used66 75 } 67 76 \endcode … … 69 78 If the optional fields are not given, they will be filled as follows: 70 79 \code 71 rowid= [0, 1, 2, ...number_of_rows_of_Data];72 80 drv = {names=("ch0", "ch1", "ch2", ..."number_of_rows_of_Data"); 73 81 sizes=( 1 1 1 ...); … … 76 84 time = 0; 77 85 \endcode 78 If \c rowid is given, \c drv will be named after ind eces in rowids.86 If \c rowid is given, \c drv will be named after indices in rowids. 79 87 80 88 Hence the data provided by method \c getdata() will be full column of matrix Data starting from the first record. 81 89 */ 82 void from_setting ( const Setting &set ) { 83 UI::get ( Data, set, "Data", UI::compulsory ); 84 if ( !UI::get ( time, set, "time", UI::optional ) ) { 85 time = 0; 86 } 87 if ( !UI::get ( rowid, set, "rowid", UI::optional ) ) { 88 rowid = linspace ( 0, Data.rows() - 1 ); 89 } 90 shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional ); 91 if ( !r ) { 92 r = new RV(); 93 for ( int i = 0; i < rowid.length(); i++ ) { 94 r->add ( RV ( "ch" + num2str ( rowid ( i ) ), 1, 0 ) ); 95 } 96 } 97 set_drv ( *r, RV() ); //empty urv 98 dtsize = r->_dsize(); 99 utsize = 0; 100 } 90 void from_setting ( const Setting &set ); 101 91 }; 102 92 UIREGISTER ( MemDS ); … … 106 96 */ 107 97 class FileDS: public MemDS { 108 109 public: 110 void getdata ( vec &dt ) { 111 dt = Data.get_col ( time ); 112 } 113 114 void getdata ( vec &dt, const ivec &indices ) { 115 vec tmp = Data.get_col ( time ); 116 dt = tmp ( indices ); 117 } 118 119 //! returns number of data in the file; 120 int ndat() { 121 return Data.cols(); 122 } 123 //! no sense to log this type 124 void log_register ( logger &L, const string &prefix ) {}; 125 //! no sense to log this type 126 void log_write ( ) const {}; 98 protected: 99 string filename; 100 public: 101 void from_setting ( const Setting & set ); 127 102 }; 128 103 … … 142 117 it >> Data; 143 118 time = 0; 144 // rowid anddelays are ignored119 //delays are ignored 145 120 }; 146 121 … … 165 140 */ 166 141 class CsvFileDS: public FileDS { 167 168 public: 169 //! Constructor - create DS from a CSV file. 170 CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 142 public: 143 void from_setting ( const Setting & set ); 171 144 }; 172 145 … … 203 176 virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 204 177 205 //! Accepts action variables at specific ind eces206 virtual void write ( const vec &ut, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;178 //! Accepts action variables at specific indices 179 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 207 180 208 181 /*! … … 261 234 262 235 263 //! Returns data records at ind eces.264 virtual void getdata ( vec &dt, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;236 //! Returns data records at indices. 237 virtual void getdata ( vec &dt, const ivec &indices ) NOT_IMPLEMENTED_VOID; 265 238 266 239 … … 364 337 } 365 338 366 virtual void write ( const vec &ut, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;339 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 367 340 368 341 /*! UI for stateDS -
library/bdm/design/arx_ctrl.h
r883 r896 67 67 } 68 68 vec tmp=lq.ctrlaction ( state, cond.right ( Stsp->_B().cols() ) ); 69 if (! isfinite(sum(tmp))) {69 if (!std::isfinite(sum(tmp))) { 70 70 cout << "infinite ctrl action"; 71 71 } -
library/bdm/estim/arx.cpp
r883 r896 148 148 @param Eg0 a copy of prior GiW density before estimation 149 149 @param Egll likelihood of the current Eg 150 @param ind eces current indeces150 @param indices current indices 151 151 \return best likelihood in the structure below the given one 152 152 */ 153 double egiw_bestbelow ( egiw Eg, egiw Eg0, double Egll, ivec &ind eces ) { //parameter Eg is a copy!153 double egiw_bestbelow ( egiw Eg, egiw Eg0, double Egll, ivec &indices ) { //parameter Eg is a copy! 154 154 ldmat Vo = Eg._V(); //copy 155 155 ldmat Vo0 = Eg._V(); //copy … … 164 164 double belll = Egll; 165 165 166 ivec tmpind eces;167 ivec maxind eces = indeces;168 169 170 cout << "bb:(" << ind eces << ") ll=" << Egll << endl;166 ivec tmpindices; 167 ivec maxindices = indices; 168 169 170 cout << "bb:(" << indices << ") ll=" << Egll << endl; 171 171 172 172 //try to remove only one rv … … 186 186 // 187 187 if ( tmpll > Egll ) { //increase of the likelihood 188 tmpind eces = indeces;189 tmpind eces.del ( i );188 tmpindices = indices; 189 tmpindices.del ( i ); 190 190 //search for a better match in this substructure 191 belll = egiw_bestbelow ( Eg, Eg0, tmpll, tmpind eces );191 belll = egiw_bestbelow ( Eg, Eg0, tmpll, tmpindices ); 192 192 if ( belll > maxll ) { //better match found 193 193 maxll = belll; 194 maxind eces = tmpindeces;194 maxindices = tmpindices; 195 195 } 196 196 } 197 197 } 198 ind eces = maxindeces;198 indices = maxindices; 199 199 return maxll; 200 200 } -
library/bdm/estim/arx.h
r878 r896 97 97 void ml_predictor_update ( mlnorm<sq_T> &pred ) const; 98 98 mlstudent* predictor_student() const; 99 //! Brute force structure estimation.\return ind eces of accepted regressors.99 //! Brute force structure estimation.\return indices of accepted regressors. 100 100 ivec structure_est ( egiw Eg0 ); 101 //! Smarter structure estimation by Ludvik Tesar.\return ind eces of accepted regressors.101 //! Smarter structure estimation by Ludvik Tesar.\return indices of accepted regressors. 102 102 ivec structure_est_LT ( egiw Eg0 ); 103 103 //!@} -
library/bdm/estim/kalman.h
r889 r896 432 432 Using Frobenius form, see []. 433 433 434 For easier use in the future, ind eces theta_in_A and theta_in_C are set. TODO - explain434 For easier use in the future, indices theta_in_A and theta_in_C are set. TODO - explain 435 435 */ 436 436 //template<class sq_T> -
library/bdm/mex/mex_datasource.h
r895 r896 115 115 } 116 116 117 virtual void getdata ( vec &dt, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;117 virtual void getdata ( vec &dt, const ivec &indices ) NOT_IMPLEMENTED_VOID; 118 118 119 virtual void write ( const vec &ut, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;119 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 120 120 121 121 -
library/bdm/stat/discrete.cpp
r766 r896 41 41 for ( int j = 0; j < dim; j++ ) { 42 42 ind += dim_skips * ( inds ( j ) ); // add shift in linear index caused by this dimension 43 dim_skips *= gridsizes ( j ); // ind eces in the next dimension are repeated with period gridsizes(j) times greater that in this dimesion43 dim_skips *= gridsizes ( j ); // indices in the next dimension are repeated with period gridsizes(j) times greater that in this dimesion 44 44 } 45 45 return ind; -
library/bdm/stat/discrete.h
r737 r896 36 36 //! active vector for first_vec and next_vec 37 37 vec actvec; 38 //! ind eces of active vector38 //! indices of active vector 39 39 vec actvec_ind; 40 40 //! length of steps in each dimension … … 51 51 void initialize(); 52 52 53 //! return vector at position given by vector of ind eces53 //! return vector at position given by vector of indices 54 54 vec get_vec ( const ivec &inds ); 55 55 56 //! convert dimension ind eces into linear index, the indexing is in the same way as in \c next_vec()56 //! convert dimension indices into linear index, the indexing is in the same way as in \c next_vec() 57 57 long linear_index ( const ivec inds ); 58 58 -
library/bdm/stat/emix.h
r886 r896 275 275 class eprod_base: public epdf { 276 276 protected: 277 //! Array of ind eces277 //! Array of indices 278 278 Array<datalink*> dls; 279 279 //! interface for a factor -
library/bdm/stat/exp_family.h
r889 r896 294 294 } 295 295 void marginal (const RV &rvm, estudent<sq_T> &marg) const { 296 ivec ind = rvm.findself_ids(rv); // ind eces of rvm in rv296 ivec ind = rvm.findself_ids(rv); // indices of rvm in rv 297 297 marg._mu() = mu(ind); 298 298 marg._H() = sq_T(H,ind);