root/applications/bdmtoolbox/mex/bm_bayesweighted.cpp @ 1002

Revision 1002, 1.9 kB (checked in by smidl, 14 years ago)

new mexes + cleanup

Line 
1/*!
2\file
3\brief wrapper function for BM.bayes()
4
5
6 */
7
8#include <stat/emix.h>
9
10using namespace bdm;
11
12#ifdef MEX
13#include <estim/arx_ext.h>
14#include <estim/kalman.h>
15#include <estim/particles.h>
16#include <estim/mixtures.h>
17#include <mex/mex_BM.h>
18
19void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) {
20        // Check the number of inputs and output arguments
21        if ( n_input<1 ) mexErrMsgTxt ( 
22                "Usage:\n"
23                "[bmef_struct,logevidence]=bm_bayesweighted(BMEF_struct, yt, cond, weight)\n"
24                "  BMEF_struct = struct('class','BMEF_offspring',...);% description of Bayesian Model (BM) form exp. family\n"
25                "  yt = [...];                                        % vector of observed data\n"
26                "  cond = [...];                                      % vector of conditioning variables\n"
27                "  weight = [1.0];                                    % weight of the date vector\n"
28                "output:\n"
29                "  bmef_struct = struct('class','BMEF_offsprin',...); % description of BM afret update.\n"
30                "  logevidence  = 0.0;                                % logarithm of normalizing constant f(yt|cond)"
31                );
32
33        RV::clear_all();
34        //CONFIG
35        if (n_input<2){                 bdm_error("no observed data entered"); }
36       
37        UImxArray Cfg(input[0]);
38        Cfg.writeFile("BM_bayes.cfg");
39
40        shared_ptr<BMEF> bm=UI::build<BMEF>(Cfg);
41       
42        if (bm){       
43                vec yt;
44                vec cond;
45                double weight;
46                if (n_input<2){
47                } else {
48                        yt=mxArray2vec(input[1]);
49                        if (n_input>2){
50                                cond =mxArray2vec(input[2]);
51                        }
52                        if (n_input>3){
53                                weight = mxArray2double(input[3]);
54                        }
55                }
56                //if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" );
57                bm->bayes_weighted(yt,cond,weight);
58                UImxArray Out;
59                UI::save(bm.get(), Out);
60                output[0]=UImxArray::create_mxArray(Out);
61                if (n_output>1){
62                        mxArray *le=mxCreateDoubleScalar(mxREAL);
63                        double2mxArray(bm->_ll(), le);
64                        output[1]=le;
65                }
66        } else { 
67                mexErrMsgTxt ( "Given object is not BM" );
68        }
69}
70#endif
Note: See TracBrowser for help on using the browser.