| 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> |
|---|
| 15 | |
|---|
| 16 | void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { |
|---|
| 17 | // Check the number of inputs and output arguments |
|---|
| 18 | if ( n_input<1 ) mexErrMsgTxt ( "Usage:\n" |
|---|
| 19 | "Mix=mixef_init(Data, Com1)\n" |
|---|
| 20 | " Data = []; % matrix of data \n" |
|---|
| 21 | " Com1 = struct('class','BMEF_offspring'); % A typical component \n" |
|---|
| 22 | "output:\n" |
|---|
| 23 | " structure with description of mixture." ); |
|---|
| 24 | |
|---|
| 25 | //input check |
|---|
| 26 | if (!mxIsNumeric(input[0])) mexErrMsgTxt("Given input #1 is not a data matrix."); |
|---|
| 27 | if (n_input<2) mexErrMsgTxt("No initial component, dont what type of mixture to fit."); |
|---|
| 28 | if (!mxIsStruct(input[1])) mexErrMsgTxt("Given input #2 is not a struct."); |
|---|
| 29 | //output check |
|---|
| 30 | if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" ); |
|---|
| 31 | |
|---|
| 32 | // act |
|---|
| 33 | RV::clear_all(); |
|---|
| 34 | |
|---|
| 35 | mat Data=mxArray2mat(input[0]); |
|---|
| 36 | |
|---|
| 37 | UImxArray Cfg(input[1]); |
|---|
| 38 | Cfg.writeFile("mixef_init.cfg"); |
|---|
| 39 | |
|---|
| 40 | #else |
|---|
| 41 | int main() { |
|---|
| 42 | UIFile Cfg ( "mixef_init.cfg" ); |
|---|
| 43 | mat Data=randn(2,100); // <<<<<<<<< ============== beware!!! |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | shared_ptr<BMEF> com1=UI::build<BMEF>(Cfg.getRoot()); |
|---|
| 47 | MixEF mix; |
|---|
| 48 | mix.init(&(*com1),Data,10); |
|---|
| 49 | mix.bayes_batch(Data,zeros(0,Data.cols()),ones(Data.cols())); |
|---|
| 50 | |
|---|
| 51 | #ifdef MEX |
|---|
| 52 | mxArray* tmp= mxCreateStructMatrix(1,1,0, NULL); |
|---|
| 53 | UImxArray out(tmp); |
|---|
| 54 | mix.to_setting(out); |
|---|
| 55 | output[0]=tmp; |
|---|
| 56 | #else |
|---|
| 57 | UIFile out; |
|---|
| 58 | UI::save ( &mix, out, "test" ); |
|---|
| 59 | out.save ( "mixef_init.out" ); |
|---|
| 60 | #endif |
|---|
| 61 | } |
|---|