1 | #include <estim/arx.h> |
---|
2 | #include <itpp/itmex.h> |
---|
3 | #include <mex/config2mxstruct.h> |
---|
4 | #include "mex_parser.h" |
---|
5 | |
---|
6 | namespace bdm { |
---|
7 | /*! |
---|
8 | * \brief Wrapper of BM mapping BM's methods to matlab functions |
---|
9 | |
---|
10 | The 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 | |
---|
12 | The data can be loaded from a file. |
---|
13 | */ |
---|
14 | |
---|
15 | using namespace bdm; |
---|
16 | |
---|
17 | class 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 | }; |
---|
40 | UIREGISTER(mexEpdf); |
---|
41 | |
---|
42 | class 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 | BM::from_setting(S); |
---|
57 | name = (const char *) S["name"]; |
---|
58 | UImxConfig conf(S); |
---|
59 | data = mxDuplicateArray(conf.mxconfig); |
---|
60 | //string fname = name+"_new"; |
---|
61 | //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str()); |
---|
62 | //the following works as long as the posterior is the |
---|
63 | //only member object there could be a structure of |
---|
64 | //member objects in the setting and a for cycle over |
---|
65 | //all of them right here in the code |
---|
66 | Setting &posterior = S["posterior"]; |
---|
67 | est.from_setting(posterior); |
---|
68 | } |
---|
69 | void bayes(const vec &dt) { |
---|
70 | //void bayes() { |
---|
71 | mxArray *tmp, *old; |
---|
72 | mxArray *in[2]; |
---|
73 | in[0] = data; |
---|
74 | in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL); |
---|
75 | vec2mxArray(dt, in[1]); |
---|
76 | mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str()); |
---|
77 | old = data; |
---|
78 | data = mxDuplicateArray(tmp); |
---|
79 | if (old) mxDestroyArray(old); |
---|
80 | if (tmp) mxDestroyArray(tmp); |
---|
81 | //mexCallMATLAB(0, NULL, 1, &data, "dump"); |
---|
82 | } |
---|
83 | const mexEpdf& posterior() const { |
---|
84 | return est; |
---|
85 | } //tohle by melo zustat!! |
---|
86 | const mexEpdf* _e() const { |
---|
87 | return &est; |
---|
88 | } //tohle by melo zustat!! |
---|
89 | }; |
---|
90 | UIREGISTER(mexBM); |
---|
91 | |
---|
92 | } |
---|