Changeset 609 for applications
- Timestamp:
- 09/13/09 23:14:23 (15 years ago)
- Files:
-
- 1 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