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 | #include <mex/mex_function.h> |
---|
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" |
---|
23 | " no_com = [10]; % requested numbebr of component \n" |
---|
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."); |
---|
29 | if (n_input<2) mexErrMsgTxt("No initial component, dont know what type of mixture to fit."); |
---|
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]); |
---|
40 | Cfg.writeFile("mixef_init.cfg"); |
---|
41 | |
---|
42 | int no_com=10; |
---|
43 | if (n_input>2){ |
---|
44 | no_com = mxArray2double(input[2]); |
---|
45 | } |
---|
46 | #else |
---|
47 | int main() { |
---|
48 | UIFile Cfg ( "mixef_init.cfg" ); |
---|
49 | mat Data=randn(2,100); // <<<<<<<<< ============== beware!!! |
---|
50 | int no_com =10; |
---|
51 | #endif |
---|
52 | |
---|
53 | shared_ptr<BMEF> com1=UI::build<BMEF>(Cfg.getRoot()); |
---|
54 | MixEF mix; |
---|
55 | mix.init(&(*com1),Data,no_com); |
---|
56 | // mix.bayes_batch(Data,zeros(0,Data.cols())); |
---|
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 | |
---|
62 | #ifdef MEX |
---|
63 | UImxArray out; |
---|
64 | UI::save( &mix, out ); |
---|
65 | output[0]= out.create_mxArray(); |
---|
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 | |
---|
73 | #else |
---|
74 | UIFile out; |
---|
75 | UI::save ( &mix, out, "test" ); |
---|
76 | out.save ( "mixef_init.out" ); |
---|
77 | #endif |
---|
78 | } |
---|