root/library/mex/mexBM.cpp @ 372

Revision 371, 2.3 kB (checked in by miro, 15 years ago)

conversion from config to matlab structure
changed expected interpretation of matrix in mexparse.h

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