From 95dc88bfe8495527cebe7f64db4e75a69773f2e5 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Fri, 14 Apr 2017 17:36:10 +0200 Subject: [PATCH 1/1] test auto-indenter --- pkg/R/constructionModelesLassoRank.R | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 } -- 2.44.0