| 1 | /*! |
|---|
| 2 | \file |
|---|
| 3 | \brief Test of UI builders for ARX |
|---|
| 4 | |
|---|
| 5 | See file \ref arx for mathematical background. |
|---|
| 6 | |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #include <stat/libDS_ui.h> |
|---|
| 11 | #include <estim/arx_ui.h> |
|---|
| 12 | |
|---|
| 13 | using namespace bdm; |
|---|
| 14 | int main(int argc, char* argv[]) { |
|---|
| 15 | const char *fname; |
|---|
| 16 | if (argc>0) { |
|---|
| 17 | fname = argv[0]; |
|---|
| 18 | } else { |
|---|
| 19 | fname = "UIArxDS_test.cfg"; |
|---|
| 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()._dsize() ); //data variable |
|---|
| 40 | datalink dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator |
|---|
| 41 | |
|---|
| 42 | for ( int tK=1;tK<Ndat;tK++ ) { |
|---|
| 43 | DS->step(); // simulator step |
|---|
| 44 | DS->getdata ( dt ); // read data |
|---|
| 45 | E->bayes ( dl.pushdown ( 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 | delete L; |
|---|
| 58 | delete DS; |
|---|
| 59 | delete E; |
|---|
| 60 | return 0; |
|---|
| 61 | } |
|---|