fix memory leaks on EMGLLF, test OK for EMGrank
[valse.git] / src / test / test.ConstructionModelesLassoMLE.c
1 #include "constructionModelesLassoMLE.h"
2 #include "test_utils.h"
3
4 int main(int argc, char** argv)
5 {
6 int* dimensions = readArray_int("dimensions");
7 int n = dimensions[0];
8 int p = dimensions[1];
9 int m = dimensions[2];
10 int k = dimensions[3];
11 int L = dimensions[4];
12 free(dimensions);
13
14 ////////////
15 // INPUTS //
16 Real* phiInit = readArray_real("phiInit");
17 Real* rhoInit = readArray_real("rhoInit");
18 Real* piInit = readArray_real("piInit");
19 Real* gamInit = readArray_real("gamInit");
20 int mini = read_int("mini");
21 int maxi = read_int("maxi");
22 Real gamma = read_real("gamma");
23 Real* glambda = readArray_real("glambda");
24 Real* X = readArray_real("X");
25 Real* Y = readArray_real("Y");
26 Real seuil = read_real("seuil");
27 Real tau = read_real("tau");
28 int* A1 = readArray_int("A1");
29 int* A2 = readArray_int("A2");
30 ////////////
31
32 /////////////
33 // OUTPUTS //
34 Real* phi = (Real*)malloc(p*m*k*L*sizeof(Real));
35 Real* rho = (Real*)malloc(m*m*k*L*sizeof(Real));
36 Real* pi = (Real*)malloc(k*L*sizeof(Real));
37 Real* llh = (Real*)malloc(L*2*sizeof(Real));
38 /////////////
39
40 /////////////////////////////////////////
41 // Call to constructionModelesLassoMLE //
42 constructionModelesLassoMLE(
43 phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau,A1,A2,
44 phi,rho,pi,llh,
45 n,p,m,k,L);
46 /////////////////////////////////////////
47
48 free(phiInit);
49 free(rhoInit);
50 free(piInit);
51 free(gamInit);
52 free(X);
53 free(Y);
54 free(A1);
55 free(A2);
56 free(glambda);
57
58 // Compare to reference outputs
59 Real* ref_phi = readArray_real("phi",dimPhi,4);
60 compareArray_real("phi", phi, ref_phi, p*m*k*L);
61 free(phi);
62 free(ref_phi);
63
64 Real* ref_rho = readArray_real("rho",dimRho,4);
65 compareArray_real("rho", rho, ref_rho, m*m*k*L);
66 free(rho);
67 free(ref_rho);
68
69 Real* ref_pi = readArray_real("pi",dimPi,2);
70 compareArray_real("pi", pi, ref_pi, k*L);
71 free(pi);
72 free(ref_pi);
73
74 Real* ref_llh = readArray_real("llh",dimllh,2);
75 compareArray_real("llh", llh, ref_llh, L*2);
76 free(llh);
77 free(ref_llh);
78
79 return 0;
80 }