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

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

doc

RevLine 
[336]1#include <itpp/itmex.h>
2#include <estim/arx.h>
[374]3#include "config2mxstruct.h"
[336]4
5using namespace bdm;
6
7class mexEpdf: public epdf{
8        protected:
9                string name;
[371]10                mxArray *data;
[336]11        public:
[371]12                mexEpdf() {};
13                void from_setting(const Setting &S)  {
14                        name = (const char *) S["name"];
[374]15                        UImxConfig conf(S);
16                        data = mxDuplicateArray(conf.mxconfig);
17                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
[371]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                } 
[336]29};
[575]30UIREGISTER(mexEpdf);
[371]31
[336]32class mexBM: public BM{
33        protected :
34                string name;
35                mexEpdf est;
[371]36                mxArray *data;
[336]37        public:
[371]38                mexBM() {}
39
[374]40                mxArray *get_data() {
41                        //mexCallMATLAB(0, NULL, 1, &data, "dump");
42                        return mxDuplicateArray(data);
43                }
44
[371]45                void from_setting(const Setting &S)  {
46                        name = (const char *) S["name"];
[374]47                        UImxConfig conf(S);
48                        data = mxDuplicateArray(conf.mxconfig);
49                        //string fname = name+"_new";
50                        //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
[371]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()  {
[374]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");
[371]71                } 
[661]72                //! return correctly typed posterior (covariant return)
[371]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!!
[336]79};
[575]80UIREGISTER(mexBM);
[336]81
82void mexFunction(int n_output, mxArray *output[], int n_input, const mxArray *input[])
83{
84    // Check the number of inputs and output arguments
[371]85        if(n_input!=1) mexErrMsgTxt("Wrong number of input variables - expected parameter 'filename'!");
[336]86
87        // ------------------ Start of routine ---------------------------
88
[371]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;
[374]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();
[371]100       
[336]101
102        // ------------------ End of routine -----------------------------
103
104    // Create output vectors
[374]105        //output[0] = mxCreateDoubleMatrix(1,1, mxREAL);
[336]106
107    // Convert the IT++ format to Matlab format for output
[371]108        //vec2mxArray(mB.posterior().mean(), output[0]);
[336]109}
Note: See TracBrowser for help on using the browser.