1 #' constructionModelesLassoMLE
10 constructionModelesLassoMLE = function(phiInit, rhoInit, piInit, gamInit, mini, maxi,
11 gamma, X, Y, seuil, tau, selected, ncores=3, verbose=FALSE)
15 cl = parallel::makeCluster(ncores)
16 parallel::clusterExport( cl, envir=environment(),
17 varlist=c("phiInit","rhoInit","gamInit","mini","maxi","gamma","X","Y","seuil",
18 "tau","selected","ncores","verbose") )
21 # Individual model computation
22 computeAtLambda <- function(lambda)
25 require("valse") #// nodes start with an ampty environment
28 print(paste("Computations for lambda=",lambda))
35 sel.lambda = selected[[lambda]]
36 # col.sel = which(colSums(sel.lambda)!=0) #if boolean matrix
37 col.sel <- which( sapply(sel.lambda,length) > 0 ) #if list of selected vars
39 if (length(col.sel) == 0)
42 # lambda == 0 because we compute the EMV: no penalization here
43 res = EMGLLF(phiInit[col.sel,,],rhoInit,piInit,gamInit,mini,maxi,gamma,0,
46 # Eval dimension from the result + selected
47 phiLambda2 = res_EM$phi
48 rhoLambda = res_EM$rho
50 phiLambda = array(0, dim = c(p,m,k))
51 for (j in seq_along(col.sel))
52 phiLambda[col.sel[j],,] = phiLambda2[j,,]
57 b = setdiff(1:m, sel.lambda[,j])
60 dimension = dimension + sum(sel.lambda[,j]!=0)
63 # on veut calculer la vraisemblance avec toutes nos estimations
64 densite = vector("double",n)
67 delta = Y%*%rhoLambda[,,r] - (X[, col.sel]%*%phiLambda[col.sel,,r])
68 densite = densite + piLambda[r] *
69 det(rhoLambda[,,r])/(sqrt(2*base::pi))^m * exp(-tcrossprod(delta)/2.0)
71 llhLambda = c( sum(log(densite)), (dimension+m+1)*k-1 )
72 list("phi"= phiLambda, "rho"= rhoLambda, "pi"= piLambda, "llh" = llhLambda)
75 #Pour chaque lambda de la grille, on calcule les coefficients
78 parLapply(cl, seq_along(glambda), computeAtLambda)
80 lapply(seq_along(glambda), computeAtLambda)
83 parallel::stopCluster(cl)