| 1 | /*! |
|---|
| 2 | \file |
|---|
| 3 | \brief wrapper function for BM.bayes_batch() |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | #include <stat/emix.h> |
|---|
| 9 | |
|---|
| 10 | using 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 | |
|---|
| 19 | void 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_batch(BM_struct, Yt, Cond)\n" |
|---|
| 24 | " BM_struct = struct('class','BM_offspring',...); % description of Bayesian Model (BM)\n" |
|---|
| 25 | " Yt = [...]; % matrix of observed data - columns are data\n" |
|---|
| 26 | " Cond = [...]; % Mector of conditioning variables - columns are conditions\n" |
|---|
| 27 | "output:\n" |
|---|
| 28 | " bm_struct = struct('class','BM_offsprin',...); % description of BM after 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 | mat yt; |
|---|
| 43 | mat cond; |
|---|
| 44 | if (n_input<2){ |
|---|
| 45 | } else { |
|---|
| 46 | yt=mxArray2mat(input[1]); |
|---|
| 47 | if (n_input>2){ |
|---|
| 48 | cond =mxArray2mat(input[2]); |
|---|
| 49 | } else{ |
|---|
| 50 | cond.set_size(0,yt.cols()); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | //if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" ); |
|---|
| 54 | double logev=bm->bayes_batch(yt,cond); |
|---|
| 55 | UImxArray Out; |
|---|
| 56 | UI::save(bm.get(), Out); |
|---|
| 57 | output[0]=UImxArray::create_mxArray(Out); |
|---|
| 58 | if (n_output>1){ |
|---|
| 59 | mxArray *le=mxCreateDoubleScalar(mxREAL); |
|---|
| 60 | double2mxArray(logev, le); |
|---|
| 61 | output[1]=le; |
|---|
| 62 | } |
|---|
| 63 | } else { |
|---|
| 64 | mexErrMsgTxt ( "Given object is not BM" ); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | #endif |
|---|