#include #include #include #include "mexlog.h" #include "mexds.h" using namespace bdm; void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { // Check the number of inputs and output arguments string fname; if (n_input>0){ fname=mxArray2string(input[0]); } else { fname = "UIArxDS_test.cfg"; } // ------------------ printf("name: %s", fname.c_str()); UIFile F ( fname.c_str()); logger* L; DS * DS; BM* E; int Ndat; try { UIbuild ( F.lookup ( "logger" ),L ); UIbuild ( F.lookup ( "system" ),DS ); F.lookupValue ( "experiment.ndat",Ndat ); UIbuild ( F.lookup ( "estimator" ),E ); } catch UICATCH; DS->log_add ( *L ); int L_est= L->add ( E->posterior()._rv(), "est" ); // estimate int L_lb = L->add ( E->posterior()._rv(), "lb" ); // lower bound int L_ub = L->add ( E->posterior()._rv(), "ub" ); // upper bound L->init(); vec dt=zeros ( DS->_drv()._dsize() ); //data variable datalink dl ( E->_drv(),DS->_drv() ); //datalink between a datasource and estimator for ( int tK=1;tKstep(); // simulator step DS->getdata ( dt ); // read data E->bayes ( dl.pushdown ( dt ) ); // update estimates DS->logit ( *L ); L->logit ( L_est, E->posterior().mean() ); L->logit ( L_lb, E->posterior().mean()-2*sqrt ( E->posterior().variance() ) ); L->logit ( L_ub, E->posterior().mean() +2*sqrt ( E->posterior().variance() ) ); L->step(); } L->finalize(); // ------------------ End of routine ----------------------------- mexlog* mL=dynamic_cast(L); if (mL) { // user wants output!! if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); output[0] = mL->toCell(); } /////// delete L; delete DS; delete E; }