correction emgrank.R
[valse.git] / src / test / generate_test_data / helpers / constructionModelesLassoRank.R
1 constructionModelesLassoRank = function(Pi,Rho,mini,maxi,X,Y,tau,A1,rangmin,rangmax){
2 #get matrix sizes
3 n = dim(X)[1]
4 p = dim(X)[2]
5 m = dim(rho)[2]
6 k = dim(rho)[3]
7 L = dim(A1)[2]
8
9 deltaRank = rangmax - rangmin + 1
10 Size = deltaRank^k
11 Rank = matrix(0, Size, k)
12 for(r in 1:k){
13 Rank[,r] = rangmin +
14 }
15
16 phi = array(0, dim=c(p,m,k,L*Size))
17 lvraisemblance = matrix(0, L*Size, 2)
18 for(lambdaIndex in 1:L){
19 #on ne garde que les colonnes actives
20 #active sera l'ensemble des variables informatives
21 active = A1[, lambdaIndex]
22 active[active==0] = c()
23 if(length(active)>0){
24 for(j in 1:Size){
25 EMG_rank = EMGrank(Pi[,lambdaIndex], Rho[,,,lambdaIndex], mini, maxi, X[, active], Y, tau, Rank[j,])
26 phiLambda = EMG_rank$phi
27 LLF = EMG_rank$LLF
28 lvraisemblance[(lambdaIndex-1)*Size+j,] = c(LLF, sum(Rank[j,]^(length(active)- Rank[j,]+m)))
29 phi[active,,,(lambdaIndex-1)*Size+j] = phiLambda
30 }
31 }
32 }
33 return(list(phi=phi, lvraisemblance = lvraisemblance))
34 }