add test folder
[valse.git] / src / test / test.selectiontotale.c
CommitLineData
7b272073
BA
1#include "selectiontotale.h"
2#include "ioutils.h"
3
4mwSize main(mwSize argc, char** argv)
5{
6 // read dimensions
7 const Int nbDims = 5;
8 Int* dimensions = readArray_int("dimensions",&nbDims,1);
9 mwSize n = dimensions[0];
10 mwSize p = dimensions[1];
11 mwSize m = dimensions[2];
12 mwSize k = dimensions[3];
13 mwSize L = dimensions[4];
14 free(dimensions);
15 mwSize lengthOne = 1;
16
17 ////////////
18 // INPUTS //
19 ////////////
20
21 // phiInit
22 const mwSize dimPhiInit[] = {p, m, k};
23 Real* phiInit = readArray_real("phiInit",dimPhiInit,3);
24
25 // rhoInit
26 const mwSize dimRhoInit[] = {m, m, k};
27 Real* rhoInit = readArray_real("rhoInit",dimRhoInit,3);
28
29 // piInit
30 Real* piInit = readArray_real("piInit",&k,1);
31
32 // gamInit
33 const mwSize dimGamInit[] = {n, k};
34 Real* gamInit = readArray_real("gamInit",dimGamInit, 2);
35
36 // min number of iterations
37 Int* pmini = readArray_int("mini",&lengthOne,1);
38 Int mini = *pmini;
39 free(pmini);
40
41 // max number of iterations
42 Int* pmaxi = readArray_int("maxi",&lengthOne,1);
43 Int maxi = *pmaxi;
44 free(pmaxi);
45
46 // gamma
47 Real* pgamma = readArray_real("gamma",&lengthOne,1);
48 Real gamma = *pgamma;
49 free(pgamma);
50
51 // lambda
52 Real* glambda = readArray_real("glambda",&L,1);
53
54 // X
55 const mwSize dimX[] = {n, p};
56 Real* X = readArray_real("X",dimX,2);
57
58 // Y
59 const mwSize dimY[] = {n, m};
60 Real* Y = readArray_real("Y",dimY,2);
61
62 // seuil
63 Real* pseuil = readArray_real("seuil",&lengthOne,1);
64 Real seuil = *pseuil;
65 free(pseuil);
66
67 // tau
68 Real* ptau = readArray_real("tau",&lengthOne,1);
69 Real tau = *ptau;
70 free(ptau);
71
72 /////////////
73 // OUTPUTS //
74 /////////////
75
76 // A1
77 const mwSize dimA[] = {p, m+1, L};
78 Int* A1 = (Int*)malloc(dimA[0]*dimA[1]*dimA[2]*sizeof(Int));
79
80 // A2
81 Int* A2 = (Int*)malloc(dimA[0]*dimA[1]*dimA[2]*sizeof(Int));
82
83 // rho
84 const mwSize dimRho[] = {m, m, k, L};
85 Real* Rho = (Real*)malloc(dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]*sizeof(Real));
86
87 // pi
88 const mwSize dimPi[] = {k, L};
89 Real* Pi = (Real*)malloc(dimPi[0]*dimPi[1]*sizeof(Real));
90
91 //////////////////////////////////////////////
92 // Main call to constructionModelesLassoMLE //
93 //////////////////////////////////////////////
94
95 selectiontotale(
96 phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau,
97 A1,A2,Rho,Pi,
98 n,p,m,k,L);
99
100 // free input pointers
101 free(phiInit);
102 free(rhoInit);
103 free(piInit);
104 free(gamInit);
105 free(glambda);
106 free(X);
107 free(Y);
108
109 // Compare to reference outputs
110 Int* ref_A1 = readArray_int("A1",dimA, 3);
111 compareArray_int("A1", A1, ref_A1, dimA[0]*dimA[1]*dimA[2]);
112 free(A1);
113 free(ref_A1);
114
115 // A2
116 Int* ref_A2 = readArray_int("A2",dimA, 3);
117 compareArray_int("A2", A2, ref_A2, dimA[0]*dimA[1]*dimA[2]);
118 free(A2);
119 free(ref_A2);
120
121 // Rho
122 Real* ref_Rho = readArray_real("Rho",dimRho, 4);
123 compareArray_real("Rho", Rho, ref_Rho, dimRho[0]*dimRho[1]*dimRho[2]*dimRho[3]);
124 free(Rho);
125 free(ref_Rho);
126
127 // Pi
128 Real* ref_Pi = readArray_real("Pi",dimPi, 2);
129 compareArray_real("Pi", Pi, ref_Pi, dimPi[0]*dimPi[1]);
130 free(Pi);
131 free(ref_Pi);
132
133 return 0;
134}