1 | #include <itpp/itmex.h> |
---|
2 | |
---|
3 | #include "estim/arx.h" |
---|
4 | #include "stat/datasources.h" |
---|
5 | #include "stat/loggers.h" |
---|
6 | #include "mex_logger.h" |
---|
7 | |
---|
8 | //#include "mex_datasource.h" |
---|
9 | |
---|
10 | using namespace bdm; |
---|
11 | |
---|
12 | void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { |
---|
13 | // Check the number of inputs and output arguments |
---|
14 | string fname; |
---|
15 | if (n_input>0){ |
---|
16 | fname=mxArray2string(input[0]); |
---|
17 | } else { |
---|
18 | fname = "UIArxDS_test.cfg"; |
---|
19 | } |
---|
20 | // ------------------ |
---|
21 | |
---|
22 | printf("name: %s", fname.c_str()); |
---|
23 | UI_File 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 ); |
---|
29 | |
---|
30 | 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 |
---|
34 | L->init(); |
---|
35 | |
---|
36 | vec dt=zeros ( DS->_drv()._dsize() ); //data variable |
---|
37 | datalink dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator |
---|
38 | |
---|
39 | for ( int tK=1;tK<Ndat;tK++ ) { |
---|
40 | DS->step(); // simulator step |
---|
41 | DS->getdata ( dt ); // read data |
---|
42 | E->bayes ( dl.pushdown ( dt ) ); // update estimates |
---|
43 | |
---|
44 | 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 | |
---|
49 | L->step(); |
---|
50 | } |
---|
51 | |
---|
52 | L->finalize(); |
---|
53 | |
---|
54 | // ------------------ End of routine ----------------------------- |
---|
55 | |
---|
56 | mex_logger* mL=dynamic_cast<mex_logger*>(L); |
---|
57 | |
---|
58 | if (mL) { // user wants output!! |
---|
59 | if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); |
---|
60 | output[0] = mL->toCell(); |
---|
61 | } |
---|
62 | |
---|
63 | /////// |
---|
64 | delete L; |
---|
65 | delete DS; |
---|
66 | delete E; |
---|
67 | } |
---|