Adjustments for CRAN upload
[valse.git] / test / test.constructionModelesLassoRank.c
1 #include "constructionModelesLassoRank.h"
2 #include "test_utils.h"
3
4 int main(int argc, char** argv)
5 {
6 // read dimensions
7 const int nbDims = 5;
8 int* dimensions = readArray_int("dimensions",&nbDims,1);
9 int n = dimensions[0];
10 int p = dimensions[1];
11 int m = dimensions[2];
12 int k = dimensions[3];
13 int L = dimensions[4];
14 free(dimensions);
15 int lengthOne = 1;
16
17 ////////////
18 // INPUTS //
19 ////////////
20
21 // piInit
22 const int dimPi[] = {k, L};
23 float* Pi = readArray_real("Pi",dimPi,2);
24
25 // rhoInit
26 const int dimRho[] = {m, m, k, L};
27 float* Rho = readArray_real("Rho",dimRho,4);
28
29 // min number of iterations
30 int* pmini = readArray_int("mini",&lengthOne,1);
31 int mini = *pmini;
32 free(pmini);
33
34 // max number of iterations
35 int* pmaxi = readArray_int("maxi",&lengthOne,1);
36 int maxi = *pmaxi;
37 free(pmaxi);
38
39 // X
40 const int dimX[] = {n, p};
41 float* X = readArray_real("X",dimX,2);
42
43 // Y
44 const int dimY[] = {n, m};
45 float* Y = readArray_real("Y",dimY,2);
46
47 // tau
48 float* ptau = readArray_real("tau",&lengthOne,1);
49 float tau = *ptau;
50 free(ptau);
51
52 // A1
53 const int dimA[] = {p, L};
54 int* A1 = readArray_int("A1",dimA,2);
55
56 // rangmin
57 int* prangmin = readArray_int("rangmin",&lengthOne,1);
58 int rangmin = *prangmin;
59 free(prangmin);
60
61 // rangmax
62 int* prangmax = readArray_int("rangmax",&lengthOne,1);
63 int rangmax = *prangmax;
64 free(prangmax);
65
66 /////////////
67 // OUTPUTS //
68 /////////////
69
70 // phi
71 int Size = (int)pow(rangmax-rangmin+1, k);
72 const int dimPhi[] = {p, m, k, L*Size};
73 float* phi = (float*)malloc(dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]*sizeof(float));
74
75 // lvraisemblance
76 const int dimLvraisemblance[] = {L*Size, 2};
77 float* lvraisemblance = (float*)malloc(dimLvraisemblance[0]*dimLvraisemblance[1]*sizeof(float));
78
79 //////////////////////////////////////////////
80 // Main call to constructionModelesLassoMLE //
81 //////////////////////////////////////////////
82
83 constructionModelesLassoRank(
84 Pi,Rho,mini,maxi,X,Y,tau,A1,rangmin,rangmax,
85 phi,lvraisemblance,
86 n,p,m,k,L);
87
88 free(Rho);
89 free(Pi);
90 free(X);
91 free(Y);
92 free(A1);
93
94 // Compare to reference outputs
95 float* ref_phi = readArray_real("phi",dimPhi, 4);
96 compareArray_real("phi", phi, ref_phi, dimPhi[0]*dimPhi[1]*dimPhi[2]*dimPhi[3]);
97 free(phi);
98 free(ref_phi);
99
100 // lvraisemblance
101 float* ref_lvraisemblance = readArray_real("lvraisemblance",dimLvraisemblance,2);
102 compareArray_real("lvraisemblance", lvraisemblance, ref_lvraisemblance, dimLvraisemblance[0]*dimLvraisemblance[1]);
103 free(lvraisemblance);
104 free(ref_lvraisemblance);
105
106 return 0;
107 }