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

Revision 1002, 1.7 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                "[bm_struct,logevidence]=bm_bayes(BM_struct, yt, cond)\n"
24                "  BM_struct = struct('class','BM_offspring',...);    % description of Bayesian Model (BM)\n"
25                "  yt = [...];                                        % vector of observed data\n"
26                "  cond = [...];                                      % vector of conditioning variables\n"
27                "output:\n"
28                "  bm_struct = struct('class','BM_offsprin',...);     % description of BM afret update.\n"
29                "  logevidence  = 0.0;                                % logarithm of normalizing constant f(yt|cond)"
30                );
31
32        RV::clear_all();
33        //CONFIG
34        if (n_input<2){                 bdm_error("no observed data entered"); }
35       
36        UImxArray Cfg(input[0]);
37        Cfg.writeFile("BM_bayes.cfg");
38
39        shared_ptr<BM> bm=UI::build<BM>(Cfg);
40       
41        if (bm){       
42                vec yt;
43                vec cond;
44                if (n_input<2){
45                } else {
46                        yt=mxArray2vec(input[1]);
47                        if (n_input>2){
48                                cond =mxArray2vec(input[2]);
49                        }
50                }
51                //if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" );
52                bm->bayes(yt,cond);
53                UImxArray Out;
54                UI::save(bm.get(), Out);
55                output[0]=UImxArray::create_mxArray(Out);
56                if (n_output>1){
57                        mxArray *le=mxCreateDoubleScalar(mxREAL);
58                        double2mxArray(bm->_ll(), le);
59                        output[1]=le;
60                }
61        } else { 
62                mexErrMsgTxt ( "Given object is not BM" );
63        }
64}
65#endif
Note: See TracBrowser for help on using the browser.