root/library/bdm/mex/mex_BM.h @ 597

Revision 597, 2.5 kB (checked in by smidl, 15 years ago)

missing file

Line 
1#include <estim/arx.h>
2#include <itpp/itmex.h>
3#include <mex/config2mxstruct.h>
4#include "mex_parser.h"
5
6namespace bdm {
7/*!
8* \brief Wrapper of BM mapping BM's methods to matlab functions
9
10The data are stored in an internal matrix \c Data . Each column of Data corresponds to one discrete time observation \f$t\f$. Access to this matrix is via indices \c rowid and \c delays.
11
12The data can be loaded from a file.
13*/
14
15using namespace bdm;
16
17class mexEpdf: public epdf{
18        protected:
19                string name;
20                mxArray *data;
21        public:
22                mexEpdf() {};
23                void from_setting(const Setting &S)  {
24                        name = (const char *) S["name"];
25                        UImxConfig conf(S);
26                        data = mxDuplicateArray(conf.mxconfig);
27                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
28                        //TODO (future...):
29                        //mxArray * init_data = setting2mxarray S["init_data"];
30                        //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting");
31                        //delete init_data;
32                } 
33                vec mean() const {
34                        mxArray *tmp;
35                        string fname = name+"_mean";
36                        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, fname.c_str());
37                        return mxArray2vec(tmp);
38                } 
39};
40UIREGISTER(mexEpdf);
41
42class mexBM: public BM{
43        protected :
44                string name;
45                mexEpdf est;
46                mxArray *data;
47        public:
48                mexBM() {}
49
50                mxArray *get_data() {
51                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
52                        return mxDuplicateArray(data);
53                }
54
55                void from_setting(const Setting &S)  {
56                        name = (const char *) S["name"];
57                        UImxConfig conf(S);
58                        data = mxDuplicateArray(conf.mxconfig);
59                        //string fname = name+"_new";
60                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
61                        //the following works as long as the posterior is the
62                        //only member object there could be a structure of
63                        //member objects in the setting and a for cycle over
64                        //all of them right here in the code
65                        Setting &posterior = S["posterior"]; 
66                        est.from_setting(posterior);
67                }
68                void bayes(const vec &dt)  {
69                //void bayes()  {
70                        mxArray *tmp, *old;
71                        mxArray *in[2];
72                        in[0] = data;
73                        in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL);
74                        vec2mxArray(dt, in[1]);
75                        mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str());
76                        old = data;
77                        data = mxDuplicateArray(tmp);
78                        if (old) mxDestroyArray(old);
79                        if (tmp) mxDestroyArray(tmp);
80                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
81                } 
82                const mexEpdf& posterior() const  {
83                        return est;
84                } //tohle by melo zustat!!
85                const mexEpdf* _e() const  {
86                        return &est;
87                } //tohle by melo zustat!!
88};
89UIREGISTER(mexBM);
90
91}
Note: See TracBrowser for help on using the browser.