draft of selectiontotale.R
[valse.git] / R / selectiontotale.R
CommitLineData
928d1c52
BA
1#Return a list of outputs, for each lambda in grid: selected,Rho,Pi
2selectiontotale = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau)
3{
4 cl = parallel::makeCluster( parallel::detectCores() / 4 )
5 parallel::clusterExport(cl=cl,
6 varlist=c("phiInit","rhoInit","gamInit","mini","maxi","glambda","X","Y","seuil","tau"),
7 envir=environment())
8 #Pour chaque lambda de la grille, on calcule les coefficients
9 out = parLapply( 1:L, function(lambdaindex)
10 {
11 params = EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda[lambdaIndex],X,Y,tau)
12
13 p = dim(phiInit)[1]
14 m = dim(phiInit)[2]
15 #selectedVariables: list where element j contains vector of selected variables in [1,m]
16 selectedVariables = lapply(1:p, function(j) {
17 #from boolean matrix mxk of selected variables obtain the corresponding boolean m-vector,
18 #and finally return the corresponding indices
19 seq_len(m)[ apply( abs(params$phi[j,,]) > seuil, 1, any ) ]
20 })
21
22 list("selected"=selectedVariables,"Rho"=params$Rho,"Pi"=params$Pi)
23 })
24 parallel::stopCluster(cl)
25}