root/applications/bdmtoolbox/mex/mexBM.cpp @ 661

Revision 661, 3.0 kB (checked in by smidl, 15 years ago)

doc

Line 
1#include <itpp/itmex.h>
2#include <estim/arx.h>
3#include "config2mxstruct.h"
4
5using namespace bdm;
6
7class mexEpdf: public epdf{
8        protected:
9                string name;
10                mxArray *data;
11        public:
12                mexEpdf() {};
13                void from_setting(const Setting &S)  {
14                        name = (const char *) S["name"];
15                        UImxConfig conf(S);
16                        data = mxDuplicateArray(conf.mxconfig);
17                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
18                        //TODO (future...):
19                        //mxArray * init_data = setting2mxarray S["init_data"];
20                        //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting");
21                        //delete init_data;
22                } 
23                vec mean() const {
24                        mxArray *tmp;
25                        string fname = name+"_mean";
26                        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, fname.c_str());
27                        return mxArray2vec(tmp);
28                } 
29};
30UIREGISTER(mexEpdf);
31
32class mexBM: public BM{
33        protected :
34                string name;
35                mexEpdf est;
36                mxArray *data;
37        public:
38                mexBM() {}
39
40                mxArray *get_data() {
41                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
42                        return mxDuplicateArray(data);
43                }
44
45                void from_setting(const Setting &S)  {
46                        name = (const char *) S["name"];
47                        UImxConfig conf(S);
48                        data = mxDuplicateArray(conf.mxconfig);
49                        //string fname = name+"_new";
50                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
51                        //the following works as long as the posterior is the
52                        //only member object there could be a structure of
53                        //member objects in the setting and a for cycle over
54                        //all of them right here in the code
55                        Setting &posterior = S["posterior"]; 
56                        est.from_setting(posterior);
57                }
58                void bayes(const vec &dt)  {
59                //void bayes()  {
60                        mxArray *tmp, *old;
61                        mxArray *in[2];
62                        in[0] = data;
63                        in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL);
64                        vec2mxArray(dt, in[1]);
65                        mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str());
66                        old = data;
67                        data = mxDuplicateArray(tmp);
68                        if (old) mxDestroyArray(old);
69                        if (tmp) mxDestroyArray(tmp);
70                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
71                } 
72                //! return correctly typed posterior (covariant return)
73                const mexEpdf& posterior() const  {
74                        return est;
75                } //tohle by melo zustat!!
76                const mexEpdf* _e() const  {
77                        return &est;
78                } //tohle by melo zustat!!
79};
80UIREGISTER(mexBM);
81
82void mexFunction(int n_output, mxArray *output[], int n_input, const mxArray *input[])
83{
84    // Check the number of inputs and output arguments
85        if(n_input!=1) mexErrMsgTxt("Wrong number of input variables - expected parameter 'filename'!");
86
87        // ------------------ Start of routine ---------------------------
88
89        //mexBM mB(mxArray2string(input[0])); // naplni
90        //mB.bayes(vec_1(1.3));
91        string filename = mxArray2string(input[0]);
92        Config config;
93        config.readFile(filename.c_str());
94        mexBM mb;
95        Setting &root = config.getRoot();
96        mb.from_setting(root);
97        vec dt = "18.0";
98        mb.bayes(dt);
99        if(n_output>0) output[0] = mb.get_data();
100       
101
102        // ------------------ End of routine -----------------------------
103
104    // Create output vectors
105        //output[0] = mxCreateDoubleMatrix(1,1, mxREAL);
106
107    // Convert the IT++ format to Matlab format for output
108        //vec2mxArray(mB.posterior().mean(), output[0]);
109}
Note: See TracBrowser for help on using the browser.