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

Revision 925, 2.8 kB (checked in by smidl, 14 years ago)

new mexpdf

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