root/applications/bdmtoolbox/estimator.cpp @ 384

Revision 384, 3.0 kB (checked in by mido, 15 years ago)

possibly broken?

  • Property svn:eol-style set to native
Line 
1/*!
2\file
3\brief Application Estimator
4
5The general task of estimation is defined on the following scheme:
6\dot
7digraph 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
16Here,
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
22Execute command:
23\code
24$> estimator config_file.cfg
25\endcode
26
27Full description of the experiment is in the file config_file.cfg which is expected to have the following structure:
28\code
29system = {type = "DS_offspring", ...};      // definition of a data source
30estimator = {type = "BM_offspring", ...};   // definition of an estimator
31logger = {type = "logger_type",...};        // definition of a logger
32experiment = {ndat = 11000; };              // definition of number of data records
33\endcode
34
35The 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
38Execute command:
39\code
40>> estimator('config_file.cfg');
41\endcode
42when using loggers storing results on hard drives, and
43\code
44>> Res=estimator('config_file.cfg');
45\endcode
46when using logger of the type \c "mex_logger". The results will be stored in structure \c M.
47
48 */
49
50#include "stat/datasources.h"
51#include "estim/arx.h"
52#include "user_info.h"
53#include "stat/loggers.h"
54
55using namespace bdm;
56int main ( int argc, char* argv[] ) {
57        const char *fname;
58        if ( argc>1 ) {
59                fname = argv[1];
60        }
61        else {
62                cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg";
63                //abort();
64        }
65        fname = "arx_test.cfg";
66        UI_File F ( fname );
67
68        logger* L = UI::build<logger>( F, "logger");
69        ArxDS * DS = UI::build<ArxDS>( F, "system" );
70        BM* E = UI::build<BM>( F, "estimator" );
71        int Ndat = F.lookupValue ( "experiment.ndat",Ndat );
72
73        DS->log_add ( *L );
74        int L_est= L->add ( E->posterior()._rv(), "est" ); // estimate
75        int L_lb = L->add ( E->posterior()._rv(), "lb" ); // lower bound
76        int L_ub = L->add ( E->posterior()._rv(), "ub" ); // upper bound
77        L->init();
78
79        vec dt=zeros ( DS->_drv()._dsize() );   //data variable
80        datalink dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator
81
82        for ( int tK=1;tK<Ndat;tK++ ) {
83                DS->step();                                                     // simulator step
84                DS->getdata ( dt );                                     // read data
85                E->bayes ( dl.pushdown ( dt ) );                // update estimates
86
87                DS->logit ( *L );
88                L->logit ( L_est, E->posterior().mean() );
89                L->logit ( L_lb,  E->posterior().mean()-2*sqrt ( E->posterior().variance() ) );
90                L->logit ( L_ub,  E->posterior().mean() +2*sqrt ( E->posterior().variance() ) );
91
92                L->step();
93        }
94
95        L->finalize();
96
97        delete L;
98        delete DS;
99        delete E;
100        return 0;
101}
Note: See TracBrowser for help on using the browser.