1 | #include <itpp/itcomm.h> |
---|
2 | #include <itpp/itmex.h> |
---|
3 | |
---|
4 | #include <stat/libDS_ui.h> |
---|
5 | #include <estim/arx_ui.h> |
---|
6 | |
---|
7 | #include "mexlog.h" |
---|
8 | |
---|
9 | using namespace bdm; |
---|
10 | |
---|
11 | void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { |
---|
12 | // Check the number of inputs and output arguments |
---|
13 | const char *fname; |
---|
14 | if (n_input>0){ |
---|
15 | fname=mxArray2string(input[0]).c_str(); |
---|
16 | } else { |
---|
17 | fname = "UIArxDS_test.cfg"; |
---|
18 | } |
---|
19 | // ------------------ |
---|
20 | |
---|
21 | UIFile F ( fname); |
---|
22 | |
---|
23 | logger* L; |
---|
24 | UIbuild ( F.lookup ( "logger" ),L ); |
---|
25 | ArxDS * DS; |
---|
26 | UIbuild ( F.lookup ( "system" ),DS ); |
---|
27 | int Ndat; |
---|
28 | F.lookupValue ( "experiment.ndat",Ndat ); |
---|
29 | // SET SIMULATOR |
---|
30 | BM* E; |
---|
31 | UIbuild ( F.lookup ( "estimator" ),E ); |
---|
32 | |
---|
33 | DS->log_add ( *L ); |
---|
34 | int L_est= L->add ( E->_epdf()._rv(), "est" ); // estimate |
---|
35 | int L_lb = L->add ( E->_epdf()._rv(), "lb" ); // lower bound |
---|
36 | int L_ub = L->add ( E->_epdf()._rv(), "ub" ); // upper bound |
---|
37 | L->init(); |
---|
38 | |
---|
39 | vec dt=zeros ( DS->_drv().count() ); //data variable |
---|
40 | datalink_e2e dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator |
---|
41 | |
---|
42 | for ( int tK=0;tK<Ndat;tK++ ) { |
---|
43 | DS->step(); // simulator step |
---|
44 | DS->getdata ( dt ); // read data |
---|
45 | E->bayes ( dl.get_val ( dt ) ); // update estimates |
---|
46 | |
---|
47 | DS->logit ( *L ); |
---|
48 | L->logit ( L_est, E->_epdf().mean() ); |
---|
49 | L->logit ( L_lb, E->_epdf().mean()-2*sqrt ( E->_epdf().variance() ) ); |
---|
50 | L->logit ( L_ub, E->_epdf().mean() +2*sqrt ( E->_epdf().variance() ) ); |
---|
51 | |
---|
52 | L->step(); |
---|
53 | } |
---|
54 | |
---|
55 | L->finalize(); |
---|
56 | |
---|
57 | |
---|
58 | // ------------------ End of routine ----------------------------- |
---|
59 | |
---|
60 | mexlog* mL=dynamic_cast<mexlog*>(L); |
---|
61 | |
---|
62 | if (mL) { // user wants output!! |
---|
63 | if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); |
---|
64 | output[0] = mL->toCell(); |
---|
65 | } |
---|
66 | |
---|
67 | /////// |
---|
68 | delete L; |
---|
69 | delete DS; |
---|
70 | delete E; |
---|
71 | |
---|
72 | } |
---|