From: Benjamin Auder Date: Fri, 14 Apr 2017 15:36:10 +0000 (+0200) Subject: test auto-indenter X-Git-Url: https://git.auder.net/css/vendor/img/scripts/getGraph_%22%20%20%20this.image%20%20%20%22.php?a=commitdiff_plain;h=95dc88bfe8495527cebe7f64db4e75a69773f2e5;p=valse.git test auto-indenter --- diff --git a/pkg/R/constructionModelesLassoRank.R b/pkg/R/constructionModelesLassoRank.R index fe75d2c..dc6bcc1 100644 --- a/pkg/R/constructionModelesLassoRank.R +++ b/pkg/R/constructionModelesLassoRank.R @@ -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,13 +83,14 @@ 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 }