root/library/mex/estimator.cpp @ 313

Revision 313, 1.8 kB (checked in by smidl, 15 years ago)

mexds

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