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, parallel = FALSE){
5 cl = parallel::makeCluster( parallel::detectCores() / 4) # <-- ça devrait être un argument
6 parallel::clusterExport(cl=cl,
7 varlist=c("phiInit","rhoInit","gamInit","mini","maxi","glambda","X","Y","thresh","tau"),
9 #Pour chaque lambda de la grille, on calcule les coefficients
10 out = parLapply(cl, 1:length(glambda), function(lambdaIndex)
13 EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda[lambdaIndex],X,Y,tau)
17 #selectedVariables: list where element j contains vector of selected variables in [1,m]
18 selectedVariables = lapply(1:p, function(j) {
19 #from boolean matrix mxk of selected variables obtain the corresponding boolean m-vector,
20 #and finally return the corresponding indices
21 seq_len(m)[ apply( abs(params$phi[j,,]) > thresh, 1, any ) ]
24 list("selected"=selectedVariables,"Rho"=params$Rho,"Pi"=params$Pi)
26 parallel::stopCluster(cl)
29 selectedVariables = list()
32 #Pour chaque lambda de la grille, on calcule les coefficients
33 for (lambdaIndex in 1:length(glambda)){
36 EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda[lambdaIndex],X,Y,tau)
39 #selectedVariables: list where element j contains vector of selected variables in [1,m]
40 selectedVariables[[lambdaIndex]] = sapply(1:p, function(j) {
41 #from boolean matrix mxk of selected variables obtain the corresponding boolean m-vector,
42 #and finally return the corresponding indices
43 seq_len(m)[ apply( abs(params$phi[j,,]) > thresh, 1, any ) ]
45 Rho[[lambdaIndex]] = params$Rho
46 Pi[[lambdaIndex]] = params$Pi
48 list("selected"=selectedVariables,"Rho"=Rho,"Pi"=Pi)