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

Revision 943, 1.3 kB (checked in by smidl, 14 years ago)

syntax of epredictor

  • Property svn:eol-style set to native
Line 
1#include <mex/mex_parser.h>
2#include <mex/mex_pdf.h>
3class mexBM: public BM{
4        protected:
5                mxArray *data;
6                mexEpdf est;
7        public:
8                mexBM() {};
9                void from_setting(const Setting &S)  {
10                        Setting &So=S["object"];
11                        data = (mxArray*)long(So);
12                } 
13                void validate() {
14                        mexCallMATLAB(0, 0, 1, &data,  "validate");
15                        mxArray *tmp;
16                        mexCallMATLAB(1, &tmp, 1, &data, "dimensions");
17                        vec v=mxArray2vec(tmp);
18                        if (v.length()<3) {bdm_error("Three dimensions are expected in mexBM.dimensions");}
19                        set_dim(v(0));
20                        dimy = v(1);
21                        dimc = v(2);
22                }
23                void bayes(const vec &dt, const vec &cond) {
24                        mxArray *tmp;
25                        mxArray *in[3];
26                        in[0]=data;
27                        in[1]=mxCreateDoubleMatrix(dt.length(),1,mxREAL);
28                        vec2mxArray(dt,in[1]);
29                        in[2]=mxCreateDoubleMatrix(cond.length(),1,mxREAL);
30                        vec2mxArray(cond,in[2]);
31                       
32                        mexCallMATLAB(1, &tmp, 3, in, "bayes");
33                        if (data!=tmp){
34                                mxDestroyArray ( data );
35                                data = mxDuplicateArray ( tmp );
36                        }                       //
37                }
38                epdf* predictor(const vec &cond) const {
39                        mxArray *tmp;
40                        mxArray *in[3];
41                        in[0]=data;
42                        in[1]=mxCreateDoubleMatrix(cond.length(),1,mxREAL);
43                        vec2mxArray(cond,in[1]);
44                       
45                        mexCallMATLAB(1, &tmp, 3, in, "predictor");
46                       
47                        UImxArray uitmp(tmp);
48                        shared_ptr<epdf> pred = UI::build<epdf>(uitmp);
49                        return pred.get();
50                        //
51                }
52                const epdf& posterior() const {
53                        return est;
54                }
55};
56UIREGISTER(mexBM);
Note: See TracBrowser for help on using the browser.