root/library/bdm/mex/mex_BM.h @ 863

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

Correction to new log_level -- FIXME - wrong parsing of array<string> in LOG_LEVEL

  • Property svn:eol-style set to native
Line 
1#include <estim/arx.h>
2#include <itpp/itmex.h>
3#include "mex_parser.h"
4
5namespace bdm {
6/*!
7* \brief Wrapper of BM mapping BM's methods to matlab functions
8
9The data are stored in an internal matrix \c Data . Each column of Data corresponds to one discrete time observation \f$t\f$. Access to this matrix is via indices \c rowid and \c delays.
10
11The data can be loaded from a file.
12*/
13
14using namespace bdm;
15
16//! epdf with functions implemented in matlab
17class mexEpdf: public epdf {
18protected:
19        //! prefix of matlab functions
20        string name;
21        //! pointer to storage structure
22        mxArray *data;
23public:
24        mexEpdf() {};
25        void from_setting ( const Setting &S )  {
26                UIFile conf( ( const char * ) S["name"] );
27                data = UImxArray::create_mxArray( conf );
28                //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
29                //TODO (future...):
30                //mxArray * init_data = setting2mxarray S["init_data"];
31                //mexCallMATLAB(1, &data, 1, &init_data, name+"_from_setting");
32                //delete init_data;
33        }
34        vec mean() const {
35                mxArray *tmp;
36                string fname = name + "_mean";
37                mexCallMATLAB ( 1, &tmp, 1, ( mxArray ** ) &data, fname.c_str() );
38                return mxArray2vec ( tmp );
39        }
40
41        virtual vec sample() const NOT_IMPLEMENTED(0);
42
43        virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0);
44       
45        virtual vec variance() const NOT_IMPLEMENTED(0);
46};
47UIREGISTER ( mexEpdf );
48
49//! BM with functions implemented in matlab
50class mexBM: public BM {
51protected :
52        //! prefix of matlab functions
53        string name;
54        //! internal estimator
55        mexEpdf est;
56        //! mxArray with attributes of this object
57        mxArray *data;
58public:
59        mexBM() {}
60
61        //! duplicate internal data pointer?
62        mxArray *get_data() {
63                //mexCallMATLAB(0, NULL, 1, &data, "dump");
64                return mxDuplicateArray ( data );
65        }
66
67        void from_setting ( const Setting &S )  {
68                BM::from_setting ( S );
69
70                UIFile conf( ( const char * ) S["name"] );
71                data = UImxArray::create_mxArray( conf );
72
73                //string fname = name+"_new";
74                //mexCallMATLAB(1, &data, 0, 0, (name+"_new").c_str());
75                //the following works as long as the posterior is the
76                //only member object there could be a structure of
77                //member objects in the setting and a for cycle over
78                //all of them right here in the code
79                Setting &posterior = S["posterior"];
80                est.from_setting ( posterior );
81        }
82        void bayes ( const vec &yt, const vec &cond )  {
83                //void bayes()  {
84                mxArray *tmp, *old;
85                mxArray *in[2];
86                in[0] = data;
87                in[1] = mxCreateDoubleMatrix ( yt.size(), 1, mxREAL );
88                vec2mxArray ( yt, in[1] );
89                mexCallMATLAB ( 1, &tmp, 2, in, ( name + "_bayes" ).c_str() );
90                old = data;
91                data = mxDuplicateArray ( tmp );
92                if ( old ) mxDestroyArray ( old );
93                if ( tmp ) mxDestroyArray ( tmp );
94                //mexCallMATLAB(0, NULL, 1, &data, "dump");
95        }
96        //! return correctly typed posterior (covariant return)
97        const mexEpdf& posterior() const  {
98                return est;
99        } //tohle by melo zustat!!
100
101};
102UIREGISTER ( mexBM );
103
104}
Note: See TracBrowser for help on using the browser.