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