- print('Model selection')
- tableauRecap = tableauRecap[rowSums(tableauRecap[, 2:4])!=0,]
- tableauRecap = tableauRecap[(tableauRecap[,1])!=Inf,]
- data = cbind(1:dim(tableauRecap)[1], tableauRecap[,2], tableauRecap[,2], tableauRecap[,1])
- require(capushe)
- modSel = capushe(data, n)
+
+ # List (index k) of lists (index lambda) of models
+ models_list <-
+ if (ncores_outer > 1)
+ parLapply(cl, kmin:kmax, computeModels)
+ else
+ lapply(kmin:kmax, computeModels)
+ if (ncores_outer > 1)
+ parallel::stopCluster(cl)
+
+ if (! requireNamespace("capushe", quietly=TRUE))
+ {
+ warning("'capushe' not available: returning all models")
+ return (models_list)
+ }
+
+ # Get summary "tableauRecap" from models
+ tableauRecap = do.call( rbind, lapply( seq_along(models_list), function(i) {
+ models <- models_list[[i]]
+ #Pour un groupe de modeles (même k, différents lambda):
+ LLH <- sapply( models, function(model) model$llh )
+ k == length(models[[1]]$pi)
+ # TODO: chuis pas sûr du tout des lignes suivantes...
+ # J'ai l'impression qu'il manque des infos
+ sumPen = sapply( models, function(model)
+ sum( model$pi^gamma * sapply(1:k, function(r) sum(abs(model$phi[,,r]))) ) )
+ data.frame(model=paste(i,".",seq_along(models),sep=""),
+ pen=sumPen/1000, complexity=sumPen, contrast=LLH)
+ } ) )
+
+ modSel = capushe::capushe(data, n)