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 "mexlog". The results will be stored in structure \c M. |
---|
47 | |
---|
48 | */ |
---|
49 | |
---|
50 | #include <stat/libDS_ui.h> |
---|
51 | #include <estim/arx_ui.h> |
---|
52 | |
---|
53 | using namespace bdm; |
---|
54 | int main ( int argc, char* argv[] ) { |
---|
55 | const char *fname; |
---|
56 | if ( argc>1 ) { |
---|
57 | fname = argv[1]; |
---|
58 | } |
---|
59 | else { |
---|
60 | cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"; |
---|
61 | abort(); |
---|
62 | } |
---|
63 | UIFile F ( fname ); |
---|
64 | |
---|
65 | logger* L; |
---|
66 | ArxDS * DS; |
---|
67 | BM* E; |
---|
68 | int Ndat; |
---|
69 | |
---|
70 | try { |
---|
71 | UIbuild ( F.lookup ( "logger" ),L ); |
---|
72 | UIbuild ( F.lookup ( "system" ),DS ); |
---|
73 | F.lookupValue ( "experiment.ndat",Ndat ); |
---|
74 | UIbuild ( F.lookup ( "estimator" ),E ); |
---|
75 | } |
---|
76 | catch UICATCH; |
---|
77 | |
---|
78 | DS->log_add ( *L ); |
---|
79 | int L_est= L->add ( E->posterior()._rv(), "est" ); // estimate |
---|
80 | int L_lb = L->add ( E->posterior()._rv(), "lb" ); // lower bound |
---|
81 | int L_ub = L->add ( E->posterior()._rv(), "ub" ); // upper bound |
---|
82 | L->init(); |
---|
83 | |
---|
84 | vec dt=zeros ( DS->_drv()._dsize() ); //data variable |
---|
85 | datalink dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator |
---|
86 | |
---|
87 | for ( int tK=1;tK<Ndat;tK++ ) { |
---|
88 | DS->step(); // simulator step |
---|
89 | DS->getdata ( dt ); // read data |
---|
90 | E->bayes ( dl.pushdown ( dt ) ); // update estimates |
---|
91 | |
---|
92 | DS->logit ( *L ); |
---|
93 | L->logit ( L_est, E->posterior().mean() ); |
---|
94 | L->logit ( L_lb, E->posterior().mean()-2*sqrt ( E->posterior().variance() ) ); |
---|
95 | L->logit ( L_ub, E->posterior().mean() +2*sqrt ( E->posterior().variance() ) ); |
---|
96 | |
---|
97 | L->step(); |
---|
98 | } |
---|
99 | |
---|
100 | L->finalize(); |
---|
101 | |
---|
102 | delete L; |
---|
103 | delete DS; |
---|
104 | delete E; |
---|
105 | return 0; |
---|
106 | } |
---|