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