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