| 1 | #include <itpp/itcomm.h> |
|---|
| 2 | #include <itpp/itmex.h> |
|---|
| 3 | |
|---|
| 4 | #include "../../bdm/estim/arx.h" |
|---|
| 5 | |
|---|
| 6 | using namespace itpp; |
|---|
| 7 | |
|---|
| 8 | void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { |
|---|
| 9 | // Check the number of inputs and output arguments |
|---|
| 10 | if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); |
|---|
| 11 | if ( n_input!=1 ) mexErrMsgTxt ( "Wrong number of input variables!" ); |
|---|
| 12 | |
|---|
| 13 | // Convert input variables to IT++ format |
|---|
| 14 | mat Data = mxArray2mat ( input[0] ); |
|---|
| 15 | |
|---|
| 16 | // ------------------ Start of routine --------------------------- |
|---|
| 17 | int ndat=Data.cols(); |
|---|
| 18 | int npsi=Data.rows(); |
|---|
| 19 | RV thr ( "1","{ theta_r }",vec_1 ( npsi ),vec_1 ( 0 ) ); |
|---|
| 20 | |
|---|
| 21 | mat V0=1e-8*eye ( npsi ); V0 ( 0,0 ) *=100.0; |
|---|
| 22 | double nu0=npsi; |
|---|
| 23 | ARX Ar ( thr,V0,nu0 ); |
|---|
| 24 | // estimate |
|---|
| 25 | for (int i=0;i<ndat;i++ ) {Ar.bayes ( Data.get_col ( i ) ); } |
|---|
| 26 | |
|---|
| 27 | vec th = Ar._epdf().mean(); |
|---|
| 28 | |
|---|
| 29 | // ------------------ End of routine ----------------------------- |
|---|
| 30 | |
|---|
| 31 | // Create output vectors |
|---|
| 32 | output[0] = mxCreateDoubleMatrix ( 1,th.length(), mxREAL ); |
|---|
| 33 | // Convert the IT++ format to Matlab format for output |
|---|
| 34 | vec2mxArray ( th, output[0] ); |
|---|
| 35 | |
|---|
| 36 | if ( n_output>1 ) { |
|---|
| 37 | double ll=Ar._tll(); |
|---|
| 38 | output[1] = mxCreateDoubleMatrix ( 1,1, mxREAL ); |
|---|
| 39 | double2mxArray ( ll, output[1] ); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if ( n_output>2 ) { |
|---|
| 43 | ivec str = Ar.structure_est ( egiw ( thr,V0,nu0 ) ); |
|---|
| 44 | output[2] = mxCreateDoubleMatrix ( 1,str.length(), mxREAL ); |
|---|
| 45 | ivec2mxArray ( str, output[2] ); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|