[735] | 1 | /*! |
---|
| 2 | \file |
---|
| 3 | \brief wrapper function for MixEF.init() + MixEF.bayes_batch() |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include <estim/mixtures.h> |
---|
| 9 | #include <estim/arx.h> |
---|
| 10 | |
---|
| 11 | using namespace bdm; |
---|
| 12 | |
---|
| 13 | #ifdef MEX |
---|
| 14 | #include <mex/mex_parser.h> |
---|
[797] | 15 | #include <mex/mex_function.h> |
---|
[735] | 16 | |
---|
| 17 | void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { |
---|
| 18 | // Check the number of inputs and output arguments |
---|
| 19 | if ( n_input<1 ) mexErrMsgTxt ( "Usage:\n" |
---|
| 20 | "Mix=mixef_init(Data, Com1)\n" |
---|
| 21 | " Data = []; % matrix of data \n" |
---|
| 22 | " Com1 = struct('class','BMEF_offspring'); % A typical component \n" |
---|
[1002] | 23 | " no_com = [10]; % requested numbebr of component \n" |
---|
[735] | 24 | "output:\n" |
---|
| 25 | " structure with description of mixture." ); |
---|
| 26 | |
---|
| 27 | //input check |
---|
| 28 | if (!mxIsNumeric(input[0])) mexErrMsgTxt("Given input #1 is not a data matrix."); |
---|
[756] | 29 | if (n_input<2) mexErrMsgTxt("No initial component, dont know what type of mixture to fit."); |
---|
[735] | 30 | if (!mxIsStruct(input[1])) mexErrMsgTxt("Given input #2 is not a struct."); |
---|
| 31 | //output check |
---|
| 32 | if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" ); |
---|
| 33 | |
---|
| 34 | // act |
---|
| 35 | RV::clear_all(); |
---|
| 36 | |
---|
| 37 | mat Data=mxArray2mat(input[0]); |
---|
| 38 | |
---|
| 39 | UImxArray Cfg(input[1]); |
---|
[1002] | 40 | Cfg.writeFile("mixef_init.cfg"); |
---|
[735] | 41 | |
---|
[1002] | 42 | int no_com=10; |
---|
| 43 | if (n_input>2){ |
---|
| 44 | no_com = mxArray2double(input[2]); |
---|
| 45 | } |
---|
[742] | 46 | #else |
---|
| 47 | int main() { |
---|
| 48 | UIFile Cfg ( "mixef_init.cfg" ); |
---|
| 49 | mat Data=randn(2,100); // <<<<<<<<< ============== beware!!! |
---|
[1002] | 50 | int no_com =10; |
---|
[742] | 51 | #endif |
---|
| 52 | |
---|
[735] | 53 | shared_ptr<BMEF> com1=UI::build<BMEF>(Cfg.getRoot()); |
---|
| 54 | MixEF mix; |
---|
[1002] | 55 | mix.init(&(*com1),Data,no_com); |
---|
[1013] | 56 | // mix.bayes_batch(Data,zeros(0,Data.cols())); |
---|
[1002] | 57 | shared_ptr<epdf> p=mix.epredictor(vec(0)); |
---|
| 58 | UIFile prf; |
---|
| 59 | UI::save(p.get(), prf.getRoot(),"predictor"); |
---|
| 60 | prf.writeFile("mix_pred.cfg"); |
---|
| 61 | |
---|
[742] | 62 | #ifdef MEX |
---|
[756] | 63 | UImxArray out; |
---|
| 64 | UI::save( &mix, out ); |
---|
| 65 | output[0]= out.create_mxArray(); |
---|
[1002] | 66 | if (n_output>1){ |
---|
| 67 | UImxArray ep; |
---|
| 68 | shared_ptr<epdf> p=mix.epredictor(vec(0)); |
---|
| 69 | UI::save( p.get(), ep ); |
---|
| 70 | output[1] = ep.create_mxArray(); |
---|
| 71 | } |
---|
| 72 | |
---|
[742] | 73 | #else |
---|
[797] | 74 | UIFile out; |
---|
| 75 | UI::save ( &mix, out, "test" ); |
---|
| 76 | out.save ( "mixef_init.out" ); |
---|
[742] | 77 | #endif |
---|
[735] | 78 | } |
---|