Changeset 609
- Timestamp:
- 09/13/09 23:14:23 (15 years ago)
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/estimator.cpp
r602 r609 65 65 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 66 66 // Check the number of inputs and output arguments 67 if(n_input< 3) mexErrMsgTxt("Usage:\n"67 if(n_input<2) mexErrMsgTxt("Usage:\n" 68 68 "result=estimator(system, estimators, experiment, logger)\n" 69 69 " system = struct('class','datasource',...); % Estimated system\n" 70 70 " estimators = {struct('class','estimator',...), % Estimators\n" 71 71 " struct('class','estimator',...),...} \n" 72 " experiment = struct('ndat',100); % number of data in experiment \n"73 72 " === optional ===" 73 " experiment = struct('ndat',10); % number of data in experiment, full length of finite datasources, 10 otherwise \n" 74 74 " logger = struct('class','mexlogger'); % How to store results, default=mexlog, i.e. matlab structure\n\n" 75 75 "see documentation of classes datasource, BM, and mexlogger and their offsprings in BDM."); … … 81 81 Cfg.addGroup(input[0],"system"); 82 82 Cfg.addList(input[1],"estimators"); 83 Cfg.addGroup(input[2],"experiment"); 83 if (n_input>2){ 84 Cfg.addGroup(input[2],"experiment"); 85 } 84 86 if (n_input>3){ 85 87 Cfg.addGroup(input[3],"logger"); 86 } else{88 }/*else{ 87 89 // define logger as mexlog 88 90 Setting &S=Cfg.getRoot(); … … 94 96 S["experiment"].lookupValue("ndat",maxlen); 95 97 S["logger"]["maxlen"]=maxlen; 96 } 98 }*/ 97 99 } catch(SettingException e){it_error("error: "+string(e.getPath()));} 98 100 … … 111 113 #endif 112 114 113 shared_ptr<logger> L = UI::build<logger>( Cfg, "logger");114 115 shared_ptr<DS> Ds = UI::build<DS>( Cfg, "system" ); 115 116 Array<shared_ptr<BM> > Es; UI::get(Es,Cfg, "estimators" ); 116 int Ndat; 117 Cfg.lookupValue ( "experiment.ndat",Ndat ); 118 117 long Ndat=10; 118 if (Cfg.exists("experiment")) { 119 if (Cfg.lookupValue ( "experiment.ndat",Ndat )) { 120 bdm_assert(Ndat<=Ds->max_length(), "Data source has less data then required"); 121 }; 122 } else { 123 if (Ds->max_length() < inf) { 124 Ndat=Ds->max_length(); 125 };// else Ndat=10; 126 } 127 shared_ptr<logger> L = UI::build<logger>( Cfg, "logger",UI::optional); 128 if (!L) { 129 #ifdef MEX 130 //mex logger has only from_setting constructor - we have to fill it... 131 L=new mexlog(Ndat); 132 #else 133 L=new memlog(Ndat, "estimator_logger.it"); 134 #endif 135 } 136 119 137 Ds->log_add ( *L ); 120 138 string Ename; … … 137 155 } 138 156 139 for ( int tK=1;tK<Ndat;tK++ ) { 140 Ds->step(); // simulator step 157 for ( int tK=0;tK<Ndat;tK++ ) { 141 158 Ds->getdata ( dt ); // read data 142 159 Ds->logit ( *L ); … … 147 164 } 148 165 L->step(); 166 Ds->step(); // simulator step 149 167 } 150 168 -
library/bdm/base/bdmbase.h
r604 r609 945 945 DS() : Drv(), Urv(),Yrv() {}; 946 946 947 //! Returns maximum number of provided data, by default it is set to maximum allowed length, shorter DS should overload this method! See, MemDS.max_length(). 948 virtual int max_length() {return std::numeric_limits< int >::max();} 947 949 //! Returns full vector of observed data=[output, input] 948 950 virtual void getdata ( vec &dt ) { -
library/bdm/base/datasources.cpp
r604 r609 9 9 bdm_assert_debug ( dt.length() == rowid.length(), "MemDS:getdata incompatible dt" ); 10 10 for ( i = 0; i < rowid.length(); i++ ) { 11 dt ( i ) = Data ( rowid ( i ), time - delays ( i ));11 dt ( i ) = Data ( rowid ( i ), time ); 12 12 } 13 13 } … … 18 18 for ( i = 0; i < indeces.length(); i++ ) { 19 19 j = indeces ( i ); 20 dt ( i ) = Data ( rowid ( j ), time - delays ( j ));20 dt ( i ) = Data ( rowid ( j ), time ); 21 21 } 22 22 } … … 35 35 } 36 36 37 MemDS::MemDS ( mat &Dat, ivec &rowid0 , ivec &delays0 ) : rowid ( rowid0 ), delays ( delays0 ) {37 MemDS::MemDS ( mat &Dat, ivec &rowid0) : rowid ( rowid0 ) { 38 38 bdm_assert_debug ( max ( rowid ) <= Dat.rows(), "MemDS rowid is too high for given Dat." ); 39 bdm_assert_debug ( max ( delays ) < Dat.cols(), "MemDS delays are too high." );40 39 41 time = max ( delays );40 time = 0; 42 41 Data = Dat; 43 42 } -
library/bdm/base/datasources.h
r604 r609 35 35 //! vector of rows that are presented in Dt 36 36 ivec rowid; 37 //! vector of delays that are presented in Dt 38 ivec delays; 39 40 public: 37 38 public: 39 int max_length() {return Data.cols();} 41 40 void getdata ( vec &dt ); 42 41 void getdata ( vec &dt, const ivec &indeces ); … … 54 53 //!Default constructor 55 54 MemDS () {}; 56 MemDS ( mat &Dat, ivec &rowid0, ivec &delays0 ); 57 }; 55 MemDS ( mat &Dat, ivec &rowid0); 56 /*! Create object from the following structure 57 \code 58 { class = 'MemDS'; 59 Data = (...); // Data matrix or data vector 60 --- optional --- 61 drv = {class='RV'; ...} // Identification how rows of the matrix Data will be known to others 62 time = 0; // Index of the first column to user_info, 63 rowid = [1,2,3...]; // ids of rows to be used 64 } 65 \endcode 66 67 If the optional fields are not given, they will be filled as follows: 68 \code 69 rowid= [0, 1, 2, ...number_of_rows_of_Data]; 70 drv = {names=("0", "1", "2", ..."number_of_rows_of_Data"); 71 sizes=( 1 1 1 ...); 72 times=( 0 0 0 ...); 73 }; 74 time = 0; 75 \endcode 76 If \c rowid is given, \c drv will be named after indeces in rowids. 77 78 Hence the data provided by method \c getdata() will be full column of matrix Data starting from the first record. 79 */ 80 void from_setting(const Setting &set){ 81 UI::get(Data, set, "Data", UI::compulsory); 82 if(!UI::get(time, set,"time", UI::optional)) {time =0;} 83 if(!UI::get(rowid, set, "rowid",UI::optional)) {rowid =linspace(0,Data.rows()-1);} 84 shared_ptr<RV> r=UI::build<RV>(set,"drv",UI::optional); 85 if (!r) {r=new RV(); 86 for (int i=0; i<rowid.length(); i++){ r->add(RV("ch"+num2str(rowid(i)), 1, 0));} 87 } 88 set_drv(*r,RV()); //empty urv 89 dtsize=r->_dsize(); 90 utsize=0; 91 } 92 }; 93 UIREGISTER(MemDS); 58 94 59 95 /*! \brief Simulate data from a static pdf -
library/bdm/mex/mex_datasource.h
r596 r609 44 44 //set MemDS 45 45 rowid = linspace(0,Data.rows()-1); 46 delays = zeros_i(Data.rows());47 46 dtsize=rowid.length(); 48 47 utsize=0; -
library/bdm/mex/mex_logger.h
r593 r609 47 47 //! constructor 48 48 mexlog() : memlog ( 0, "" ) {}; 49 //! constructor 50 mexlog(long maxlen0) : memlog ( maxlen0, "" ) {}; 49 51 //! 50 52 mxArray* toCell() {