Changeset 412 for applications/bdmtoolbox
- Timestamp:
- 07/02/09 22:16:23 (16 years ago)
- Location:
- applications/bdmtoolbox
- Files:
-
- 1 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/CMakeLists.txt
r407 r412 1 IF(MEX_COMPILER)2 1 3 2 MEX(merger) 4 3 EXEC(merger) 4 5 MEX(estimator) 6 EXEC(estimator) 7 5 8 MEX(config2mxstruct) 6 9 MEX(mxstruct2config) 7 8 ENDIF(MEX_COMPILER) -
applications/bdmtoolbox/mex/estimator.cpp
r394 r412 1 #include <itpp/itmex.h> 1 /*! 2 \file 3 \brief Application Estimator 4 5 The general task of estimation is defined on the following scheme: 6 \dot 7 digraph estimation{ 8 node [shape=box]; 9 {rank="same"; "Data Source"; "Bayesian Model"} 10 "Data Source" -> "Bayesian Model" [label="data"]; 11 "Bayesian Model" -> "Result Logger" [label="estimated\n statistics"]; 12 "Data Source" -> "Result Logger" [label="Simulated\n data"]; 13 } 14 \enddot 15 16 Here, 17 \li Data Source is an object (class DS) providing sequential data, \f$ [d_1, d_2, \ldots d_t] \f$. 18 \li Bayesian Model is an object (class BM) performing Bayesian filtering, 19 \li Result Logger is an object (class logger) dedicated to storing important data from the experiment. 20 21 \section cmd Command-line usage 22 Execute command: 23 \code 24 $> estimator config_file.cfg 25 \endcode 26 27 Full description of the experiment is in the file config_file.cfg which is expected to have the following structure: 28 \code 29 system = {type = "DS_offspring", ...}; // definition of a data source 30 estimator = {type = "BM_offspring", ...}; // definition of an estimator 31 logger = {type = "logger_type",...}; // definition of a logger 32 experiment = {ndat = 11000; }; // definition of number of data records 33 \endcode 34 35 The above description must be specialized to specific classes. See, \subpage arx_ui how to do it for estimation of an ARX model. 36 37 \section ex Matlab usage 38 Execute command: 39 \code 40 >> estimator('config_file.cfg'); 41 \endcode 42 when using loggers storing results on hard drives, and 43 \code 44 >> Res=estimator('config_file.cfg'); 45 \endcode 46 when using logger of the type \c "mex_logger". The results will be stored in structure \c M. 47 48 */ 2 49 3 50 #include "estim/arx.h" 4 #include "stat/datasources.h" 5 #include "stat/loggers.h" 6 #include "mex_logger.h" 51 #include "base/datasources.h" 52 #include "base/loggers.h" 7 53 8 54 //#include "mex_datasource.h" … … 10 56 using namespace bdm; 11 57 58 #ifdef MEX 59 #include <itpp/itmex.h> 60 #include "mex/mex_logger.h" 61 #include "mex/mex_parser.h" 62 12 63 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 13 64 // Check the number of inputs and output arguments 14 string fname; 15 if (n_input>0){ 16 fname=mxArray2string(input[0]); 65 if(n_input<3) mexErrMsgTxt("Usage:\n" 66 "result=estimator(system, estimators, experiment, logger)\n" 67 " system = struct('class','datasource',...); % Estimated system\n" 68 " estimators = {struct('class','estimator',...), % Estimators\n" 69 " struct('class','estimator',...),...} \n" 70 " experiment = struct('ndat',100); % number of data in experiment \n" 71 " === optional ===" 72 " logger = struct('class','mexlogger'); % How to store results, default=mexlog, i.e. matlab structure\n\n" 73 "see documentation of classes datasource, BM, and mexlogger and their offsprings in BDM."); 74 75 UImxArray Cfg; 76 try{ 77 Cfg.addGroup(input[0],"system"); 78 Cfg.addList(input[1],"estimators"); 79 Cfg.addGroup(input[2],"experiment"); 80 if (n_input>3){ 81 Cfg.addGroup(input[3],"logger"); 82 }else{ 83 // define logger as mexlog 84 Setting &S=Cfg.getRoot(); 85 S.add("logger",Setting::TypeGroup); 86 S["logger"].add("class",Setting::TypeString); 87 S["logger"]["class"]="mexlog"; 88 S["logger"].add("maxlen",Setting::TypeInt); 89 int maxlen; 90 S["experiment"].lookupValue("ndat",maxlen); 91 S["logger"]["maxlen"]=maxlen; 92 } 93 } catch(SettingException e){it_error("error: "+string(e.getPath()));} 94 95 //DBG 96 Cfg.writeFile("estimator.cfg"); 97 98 #else 99 int main ( int argc, char* argv[] ) { 100 const char *fname; 101 if ( argc>1 ) { 102 fname = argv[1]; 17 103 } else { 18 fname = "UIArxDS_test.cfg";104 fname="estimator.cfg"; 19 105 } 20 // ------------------ 106 UIFile Cfg ( fname ); 107 #endif 21 108 22 printf("name: %s", fname.c_str()); 23 UIFile F ( fname.c_str()); 24 25 logger* L = UI::build<logger>( F, "logger"); 26 ArxDS * DS = UI::build<ArxDS>( F, "system" ); 27 BM* E = UI::build<BM>( F, "estimator" ); 28 int Ndat = F.lookupValue ( "experiment.ndat",Ndat ); 109 logger* L = UI::build<logger>( Cfg, "logger"); 110 ArxDS * DS = UI::build<ArxDS>( Cfg, "system" ); 111 Array<BM*> Es; UI::get(Es,Cfg, "estimators" ); 112 int Ndat; 113 Cfg.lookupValue ( "experiment.ndat",Ndat ); 29 114 30 115 DS->log_add ( *L ); 31 int L_est= L->add ( E->posterior()._rv(), "est" ); // estimate 32 int L_lb = L->add ( E->posterior()._rv(), "lb" ); // lower bound 33 int L_ub = L->add ( E->posterior()._rv(), "ub" ); // upper bound 116 string Ename; 117 Setting &S=Cfg; 118 for (int i=0; i<Es.length(); i++){ 119 try{ 120 UI::get(Ename, S["estimators"][i], "name"); 121 } catch (UIException e){ 122 Ename="Est"+num2str(i); 123 } 124 125 Es(i)->log_add(*L,Ename); // estimate 126 } 34 127 L->init(); 35 128 36 129 vec dt=zeros ( DS->_drv()._dsize() ); //data variable 37 datalink dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator 38 130 Array<datalink*> Dls(Es.length()); 131 for (int i=0; i<Es.length(); i++){ 132 Dls(i)=new datalink( Es(i)->_drv(),DS->_drv() ); //datalink between a datasource and estimator 133 } 134 39 135 for ( int tK=1;tK<Ndat;tK++ ) { 40 136 DS->step(); // simulator step 41 137 DS->getdata ( dt ); // read data 42 E->bayes ( dl.pushdown ( dt ) ); // update estimates43 44 138 DS->logit ( *L ); 45 L->logit ( L_est, E->posterior().mean() ); 46 L->logit ( L_lb, E->posterior().mean()-2*sqrt ( E->posterior().variance() ) ); 47 L->logit ( L_ub, E->posterior().mean() +2*sqrt ( E->posterior().variance() ) ); 48 139 140 for (int i=0; i<Es.length(); i++){ 141 Es(i)->bayes ( Dls(i)->pushdown ( dt ) ); // update estimates 142 Es(i)->logit (*L); 143 } 49 144 L->step(); 50 145 } 51 146 52 147 L->finalize(); 148 // ------------------ End of routine ----------------------------- 53 149 54 // ------------------ End of routine ----------------------------- 55 56 mex_logger* mL=dynamic_cast<mex_logger*>(L); 150 #ifdef MEX 151 mexlog* mL=dynamic_cast<mexlog*>(L); 57 152 58 153 if (mL) { // user wants output!! … … 60 155 output[0] = mL->toCell(); 61 156 } 62 157 #endif 63 158 /////// 64 159 delete L; 65 160 delete DS; 66 delete E;161 for (int i;i<Es.length();i++){delete Es(i);delete Dls(i);} 67 162 } -
applications/bdmtoolbox/tutorial/exp/arx_ui/kst.kst
r273 r412 9 9 <kstfile> 10 10 <tag>DS-arx_ui</tag> 11 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>11 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 12 12 <type>Directory of Binary Files</type> 13 13 </kstfile> … … 115 115 <tag>DS-arx_ui/INDEX</tag> 116 116 <provider>DS-arx_ui</provider> 117 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>117 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 118 118 <field>INDEX</field> 119 119 <start>-1</start> … … 123 123 <tag>DS-arx_ui/t_th_0</tag> 124 124 <provider>DS-arx_ui</provider> 125 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>125 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 126 126 <field>t_th_0</field> 127 127 <start>-1</start> … … 131 131 <tag>DS-arx_ui/t_th_2</tag> 132 132 <provider>DS-arx_ui</provider> 133 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>133 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 134 134 <field>t_th_2</field> 135 135 <start>-1</start> … … 139 139 <tag>DS-arx_ui/t_th_4</tag> 140 140 <provider>DS-arx_ui</provider> 141 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>141 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 142 142 <field>t_th_4</field> 143 143 <start>-1</start> … … 147 147 <tag>DS-arx_ui/t_th_6</tag> 148 148 <provider>DS-arx_ui</provider> 149 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>149 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 150 150 <field>t_th_6</field> 151 151 <start>-1</start> … … 155 155 <tag>DS-arx_ui/r_R_0</tag> 156 156 <provider>DS-arx_ui</provider> 157 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>157 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 158 158 <field>r_R_0</field> 159 159 <start>-1</start> … … 163 163 <tag>DS-arx_ui/est_theta_0</tag> 164 164 <provider>DS-arx_ui</provider> 165 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>165 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 166 166 <field>est_theta_0</field> 167 167 <start>-1</start> … … 171 171 <tag>DS-arx_ui/est_theta_1</tag> 172 172 <provider>DS-arx_ui</provider> 173 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>173 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 174 174 <field>est_theta_1</field> 175 175 <start>-1</start> … … 179 179 <tag>DS-arx_ui/est_theta_2</tag> 180 180 <provider>DS-arx_ui</provider> 181 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>181 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 182 182 <field>est_theta_2</field> 183 183 <start>-1</start> … … 187 187 <tag>DS-arx_ui/est_theta_3</tag> 188 188 <provider>DS-arx_ui</provider> 189 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>189 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 190 190 <field>est_theta_3</field> 191 191 <start>-1</start> … … 195 195 <tag>DS-arx_ui/est_r</tag> 196 196 <provider>DS-arx_ui</provider> 197 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>197 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 198 198 <field>est_r</field> 199 199 <start>-1</start> … … 203 203 <tag>DS-arx_ui/lb_theta_0</tag> 204 204 <provider>DS-arx_ui</provider> 205 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>205 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 206 206 <field>lb_theta_0</field> 207 207 <start>-1</start> … … 211 211 <tag>DS-arx_ui/lb_theta_1</tag> 212 212 <provider>DS-arx_ui</provider> 213 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>213 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 214 214 <field>lb_theta_1</field> 215 215 <start>-1</start> … … 219 219 <tag>DS-arx_ui/lb_theta_2</tag> 220 220 <provider>DS-arx_ui</provider> 221 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>221 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 222 222 <field>lb_theta_2</field> 223 223 <start>-1</start> … … 227 227 <tag>DS-arx_ui/lb_theta_3</tag> 228 228 <provider>DS-arx_ui</provider> 229 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>229 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 230 230 <field>lb_theta_3</field> 231 231 <start>-1</start> … … 235 235 <tag>DS-arx_ui/lb_r</tag> 236 236 <provider>DS-arx_ui</provider> 237 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>237 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 238 238 <field>lb_r</field> 239 239 <start>-1</start> … … 243 243 <tag>DS-arx_ui/ub_theta_0</tag> 244 244 <provider>DS-arx_ui</provider> 245 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>245 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 246 246 <field>ub_theta_0</field> 247 247 <start>-1</start> … … 251 251 <tag>DS-arx_ui/ub_theta_1</tag> 252 252 <provider>DS-arx_ui</provider> 253 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>253 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 254 254 <field>ub_theta_1</field> 255 255 <start>-1</start> … … 259 259 <tag>DS-arx_ui/ub_theta_2</tag> 260 260 <provider>DS-arx_ui</provider> 261 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>261 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 262 262 <field>ub_theta_2</field> 263 263 <start>-1</start> … … 267 267 <tag>DS-arx_ui/ub_theta_3</tag> 268 268 <provider>DS-arx_ui</provider> 269 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>269 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 270 270 <field>ub_theta_3</field> 271 271 <start>-1</start> … … 275 275 <tag>DS-arx_ui/ub_r</tag> 276 276 <provider>DS-arx_ui</provider> 277 <filename>/home/smidl/work/git/mixpp/ library/tutorial/exp/arx_ui/</filename>277 <filename>/home/smidl/work/git/mixpp/applications/bdmtoolbox/tutorial/exp/arx_ui/</filename> 278 278 <field>ub_r</field> 279 279 <start>-1</start>