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

Revision 660, 2.8 kB (checked in by smidl, 15 years ago)

doc - doxygen warnings

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
17//! epdf with functions implemented in matlab
18class mexEpdf: public epdf{
19        protected:
20                //! prefix of matlab functions
21                string name;
22                //! pointer to storage structure
23                mxArray *data;
24        public:
25                mexEpdf() {};
26                void from_setting(const Setting &S)  {
27                        name = (const char *) S["name"];
28                        UImxConfig conf(S);
29                        data = mxDuplicateArray(conf.mxconfig);
30                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
31                        //TODO (future...):
32                        //mxArray * init_data = setting2mxarray S["init_data"];
33                        //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting");
34                        //delete init_data;
35                } 
36                vec mean() const {
37                        mxArray *tmp;
38                        string fname = name+"_mean";
39                        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, fname.c_str());
40                        return mxArray2vec(tmp);
41                } 
42};
43UIREGISTER(mexEpdf);
44
45//! BM with functions implemented in matlab
46class mexBM: public BM{
47        protected :
48                //! prefix of matlab functions
49                string name;
50                //! internal estimator
51                mexEpdf est;
52                //! mxArray with attributes of this object
53                mxArray *data;
54        public:
55                mexBM() {}
56
57                //! duplicate internal data pointer?
58                mxArray *get_data() {
59                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
60                        return mxDuplicateArray(data);
61                }
62
63                void from_setting(const Setting &S)  {
64                        BM::from_setting(S);
65                        name = (const char *) S["name"];
66                        UImxConfig conf(S);
67                        data = mxDuplicateArray(conf.mxconfig);
68                        //string fname = name+"_new";
69                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
70                        //the following works as long as the posterior is the
71                        //only member object there could be a structure of
72                        //member objects in the setting and a for cycle over
73                        //all of them right here in the code
74                        Setting &posterior = S["posterior"]; 
75                        est.from_setting(posterior);
76                }
77                void bayes(const vec &dt)  {
78                //void bayes()  {
79                        mxArray *tmp, *old;
80                        mxArray *in[2];
81                        in[0] = data;
82                        in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL);
83                        vec2mxArray(dt, in[1]);
84                        mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str());
85                        old = data;
86                        data = mxDuplicateArray(tmp);
87                        if (old) mxDestroyArray(old);
88                        if (tmp) mxDestroyArray(tmp);
89                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
90                } 
91                //! return correctly typed posterior (covariant return)
92                const mexEpdf& posterior() const  {
93                        return est;
94                } //tohle by melo zustat!!
95};
96UIREGISTER(mexBM);
97
98}
Note: See TracBrowser for help on using the browser.