2 #include "constructionModelesLassoMLE.h"
7 // nlhs, nrhs: resp. numbers of out and in parameters.
8 // plhs: array of out parameters, each being a mxArray
9 // plhs: array of in parameters (immutable), each being a mxArray
11 // MATLAB translates a call [A,B] = fun(C,D) into mexFunction(2,{A,B},2,{C,D}).
12 // Then mxArrayS are adapted to be passed to a regular C function,
13 // and the results are translated back to mxArrayS into plhs.
18 const mxArray
* prhs
[])
20 // Basic sanity checks
22 mexErrMsgIdAndTxt("select:constructionModelesLassoMLE:nrhs","14 inputs required.");
24 mexErrMsgIdAndTxt("select:constructionModelesLassoMLE:nlhs","4 outputs required.");
26 // Get matrices dimensions
27 const mwSize n
= mxGetDimensions(prhs
[8])[0];
28 const mwSize p
= mxGetDimensions(prhs
[0])[0];
29 const mwSize m
= mxGetDimensions(prhs
[0])[1];
30 const mwSize k
= mxGetDimensions(prhs
[0])[2];
31 const mwSize L
= mxGetNumberOfElements(prhs
[7]);
38 const mwSize
* dimPhiInit
= mxGetDimensions(prhs
[0]);
39 Real
* brPhiInit
= matlabToBrArray_real(mxGetPr(prhs
[0]), dimPhiInit
, 3);
42 const mwSize
* dimRhoInit
= mxGetDimensions(prhs
[1]);
43 Real
* brRhoInit
= matlabToBrArray_real(mxGetPr(prhs
[1]), dimRhoInit
, 3);
46 Real
* piInit
= mxGetPr(prhs
[2]);
49 const mwSize
* dimGamInit
= mxGetDimensions(prhs
[3]);
50 Real
* brGamInit
= matlabToBrArray_real(mxGetPr(prhs
[3]), dimGamInit
, 2);
52 // min number of iterations
53 Int mini
= ((Int
*)mxGetData(prhs
[4]))[0];
55 // max number of iterations
56 Int maxi
= ((Int
*)mxGetData(prhs
[5]))[0];
59 Real gamma
= mxGetScalar(prhs
[6]);
62 Real
* glambda
= mxGetPr(prhs
[7]);
65 const mwSize
* dimX
= mxGetDimensions(prhs
[8]);
66 Real
* brX
= matlabToBrArray_real(mxGetPr(prhs
[8]), dimX
, 2);
69 const mwSize
* dimY
= mxGetDimensions(prhs
[9]);
70 Real
* brY
= matlabToBrArray_real(mxGetPr(prhs
[9]), dimY
, 2);
73 Real seuil
= mxGetScalar(prhs
[10]);
76 Real tau
= mxGetScalar(prhs
[11]);
79 const mwSize
* dimA
= mxGetDimensions(prhs
[12]);
80 Int
* brA1
= matlabToBrArray_int(mxGetData(prhs
[12]), dimA
, 3);
83 Int
* brA2
= matlabToBrArray_int(mxGetData(prhs
[13]), dimA
, 3);
90 const mwSize dimPhi
[] = {dimPhiInit
[0], dimPhiInit
[1], dimPhiInit
[2], L
};
91 plhs
[0] = mxCreateNumericArray(4,dimPhi
,mxDOUBLE_CLASS
,mxREAL
);
92 Real
* phi
= mxGetPr(plhs
[0]);
95 const mwSize dimRho
[] = {dimRhoInit
[0], dimRhoInit
[1], dimRhoInit
[2], L
};
96 plhs
[1] = mxCreateNumericArray(4,dimRho
,mxDOUBLE_CLASS
,mxREAL
);
97 Real
* rho
= mxGetPr(plhs
[1]);
100 const mwSize dimPi
[] = {k
, L
};
101 plhs
[2] = mxCreateNumericMatrix(dimPi
[0],dimPi
[1],mxDOUBLE_CLASS
,mxREAL
);
102 Real
* pi
= mxGetPr(plhs
[2]);
105 const mwSize dimLvraisemblance
[] = {L
, 2};
106 plhs
[3] = mxCreateNumericMatrix(L
, 2, mxDOUBLE_CLASS
,mxREAL
);
107 Real
* lvraisemblance
= mxGetPr(plhs
[3]);
109 /////////////////////////////////////////
110 // Call to constructionModelesLassoMLE //
111 /////////////////////////////////////////
113 constructionModelesLassoMLE(
114 brPhiInit
,brRhoInit
,piInit
,brGamInit
,mini
,maxi
,gamma
,glambda
,brX
,brY
,seuil
,tau
,brA1
,brA2
,
115 phi
,rho
,pi
,lvraisemblance
,
126 //post-processing: convert by-rows outputs to MATLAB matrices
127 Real
* mlPhi
= brToMatlabArray_real(phi
, dimPhi
, 4);
128 copyArray(mlPhi
, phi
, dimPhi
[0]*dimPhi
[1]*dimPhi
[2]*dimPhi
[3]);
131 Real
* mlRho
= brToMatlabArray_real(rho
, dimRho
, 4);
132 copyArray(mlRho
, rho
, dimRho
[0]*dimRho
[1]*dimRho
[2]*dimRho
[3]);
135 Real
* mlPi
= brToMatlabArray_real(pi
, dimPi
, 2);
136 copyArray(mlPi
, pi
, dimPi
[0]*dimPi
[1]);
139 Real
* mlLvraisemblance
= brToMatlabArray_real(lvraisemblance
, dimLvraisemblance
, 2);
140 copyArray(mlLvraisemblance
, lvraisemblance
, dimLvraisemblance
[0]*dimLvraisemblance
[1]);
141 free(mlLvraisemblance
);