root/applications/bdmtoolbox/mex/mixef_init.cpp @ 735

Revision 735, 1.5 kB (checked in by smidl, 14 years ago)

Initial implementation of mixef.init() -- does not work due to missing to_setting

Line 
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
11using namespace bdm;
12
13#ifdef MEX
14#include <mex/mex_parser.h>
15
16void 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        shared_ptr<BMEF> com1=UI::build<BMEF>(Cfg.getRoot());
41        MixEF mix;
42        mix.init(&(*com1),Data,10);
43        mix.bayes_batch(Data,zeros(0,Data.rows()),ones(Data.rows()));
44       
45        mxArray* tmp= mxCreateStructMatrix(1,1,0, NULL);
46        UImxArray out(tmp);
47        mix.to_setting(out);
48        output[0]=tmp;
49}
50#endif
Note: See TracBrowser for help on using the browser.