X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=pkg%2FR%2FconstructionModelesLassoRank.R;h=493783048398c87dad1e6905f1e8fda27e84c056;hb=7d0865a15f12e42f3df25a8a80d29e6cdf31c805;hp=dc6bcc1efe1331771dd4eb7d1555b29b35a8f797;hpb=95dc88bfe8495527cebe7f64db4e75a69773f2e5;p=valse.git diff --git a/pkg/R/constructionModelesLassoRank.R b/pkg/R/constructionModelesLassoRank.R index dc6bcc1..4937830 100644 --- a/pkg/R/constructionModelesLassoRank.R +++ b/pkg/R/constructionModelesLassoRank.R @@ -1,7 +1,7 @@ #' constructionModelesLassoRank #' #' Construct a collection of models with the Lasso-Rank procedure. -#' +#' #' @param S output of selectVariables.R #' @param k number of components #' @param mini integer, minimum number of iterations in the EM algorithm, by default = 10 @@ -20,12 +20,12 @@ #' @export constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, rank.max, ncores, fast = TRUE, verbose = FALSE) -{ + { n <- dim(X)[1] p <- dim(X)[2] m <- dim(Y)[2] L <- length(S) - + # Possible interesting ranks deltaRank <- rank.max - rank.min + 1 Size <- deltaRank^k @@ -42,7 +42,7 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, each = deltaRank^(k - r)), each = L) } RankLambda[, k + 1] <- rep(1:L, times = Size) - + if (ncores > 1) { cl <- parallel::makeCluster(ncores, outfile = "") @@ -50,14 +50,14 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, "Pi", "Rho", "mini", "maxi", "X", "Y", "eps", "Rank", "m", "phi", "ncores", "verbose")) } - + computeAtLambda <- function(index) { lambdaIndex <- RankLambda[index, k + 1] rankIndex <- RankLambda[index, 1:k] if (ncores > 1) require("valse") #workers start with an empty environment - + # 'relevant' will be the set of relevant columns selected <- S[[lambdaIndex]]$selected relevant <- c() @@ -83,14 +83,18 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, } } - + # For each lambda in the grid we compute the estimators - out <- if (ncores > 1) { - parLapply(cl, seq_len(length(S) * Size), computeAtLambda) } else { - lapply(seq_len(length(S) * Size), computeAtLambda) - + out <- if (ncores > 1) + { + parLapply(cl, seq_len(length(S) * Size), computeAtLambda) + } else + { + lapply(seq_len(length(S) * Size), computeAtLambda) + } + if (ncores > 1) parallel::stopCluster(cl) - + out }