- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# mex_BM.h

    00001 #include <estim/arx.h>
    00002 #include <itpp/itmex.h>
    00003 #include <mex/config2mxstruct.h>
    00004 #include "mex_parser.h"
    00005
    00006 namespace bdm {
    00015 using namespace bdm;
    00016
    00018 class mexEpdf: public epdf{
    00019         protected:
    00021                 string name;
    00023                 mxArray *data;
    00024         public:
    00025                 mexEpdf() {};
    00026                 void from_setting(const Setting &S)  {
    00027                         name = (const char *) S["name"];
    00028                         UImxConfig conf(S);
    00029                         data = mxDuplicateArray(conf.mxconfig);
    00030                         //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
    00031                         //TODO (future...):
    00032                         //mxArray * init_data = setting2mxarray S["init_data"];
    00033                         //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting");
    00034                         //delete init_data;
    00035                 }
    00036                 vec mean() const {
    00037                         mxArray *tmp;
    00038                         string fname = name+"_mean";
    00039                         mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, fname.c_str());
    00040                         return mxArray2vec(tmp);
    00041                 }
    00042 };
    00043 UIREGISTER(mexEpdf);
    00044
    00046 class mexBM: public BM{
    00047         protected :
    00049                 string name;
    00051                 mexEpdf est;
    00053                 mxArray *data;
    00054         public:
    00055                 mexBM() {}
    00056
    00058                 mxArray *get_data() {
    00059                         //mexCallMATLAB(0, NULL, 1, &data, "dump");
    00060                         return mxDuplicateArray(data);
    00061                 }
    00062
    00063                 void from_setting(const Setting &S)  {
    00064                         BM::from_setting(S);
    00065                         name = (const char *) S["name"];
    00066                         UImxConfig conf(S);
    00067                         data = mxDuplicateArray(conf.mxconfig);
    00068                         //string fname = name+"_new";
    00069                         //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
    00070                         //the following works as long as the posterior is the
    00071                         //only member object there could be a structure of
    00072                         //member objects in the setting and a for cycle over
    00073                         //all of them right here in the code
    00074                         Setting &posterior = S["posterior"];
    00075                         est.from_setting(posterior);
    00076                 }
    00077                 void bayes(const vec &dt)  {
    00078                 //void bayes()  {
    00079                         mxArray *tmp, *old;
    00080                         mxArray *in[2];
    00081                         in[0] = data;
    00082                         in[1] = mxCreateDoubleMatrix(dt.size(), 1, mxREAL);
    00083                         vec2mxArray(dt, in[1]);
    00084                         mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str());
    00085                         old = data;
    00086                         data = mxDuplicateArray(tmp);
    00087                         if (old) mxDestroyArray(old);
    00088                         if (tmp) mxDestroyArray(tmp);
    00089                         //mexCallMATLAB(0, NULL, 1, &data, "dump");
    00090                 }
    00092                 const mexEpdf& posterior() const  {
    00093                         return est;
    00094                 } //tohle by melo zustat!!
    00095 };
    00096 UIREGISTER(mexBM);
    00097
    00098 }