Adjustments for CRAN upload
[valse.git] / pkg / R / constructionModelesLassoRank.R
index dc88f67..a37a7a6 100644 (file)
 #' @param fast TRUE to use compiled C code, FALSE for R code only
 #' @param verbose TRUE to show some execution traces
 #'
-#' @return a list with several models, defined by phi, rho, pi, llh
+#' @return a list with several models, defined by phi (the regression parameter reparametrized),
+#' rho (the covariance parameter reparametrized), pi (the proportion parameter is the mixture model), llh
+#' (the value of the loglikelihood function for this estimator on the training dataset). The list is given
+#' for several levels of sparsity, given by several regularization parameters computed automatically,
+#' and several ranks (between rank.min and rank.max).
 #'
 #' @export
-constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, rank.max, 
+constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, rank.max,
   ncores, fast, verbose)
 {
   n <- nrow(X)
@@ -33,12 +37,12 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min,
   for (r in 1:k)
   {
     # On veut le tableau de toutes les combinaisons de rangs possibles, et des
-    # lambdas Dans la première colonne : on répète (rank.max-rank.min)^(k-1) chaque
-    # chiffre : ça remplit la colonne Dans la deuxieme : on répète
-    # (rank.max-rank.min)^(k-2) chaque chiffre, et on fait ça (rank.max-rank.min)^2
-    # fois ...  Dans la dernière, on répète chaque chiffre une fois, et on fait ça
+    # lambdas Dans la premiere colonne : on repete (rank.max-rank.min)^(k-1) chaque
+    # chiffre : ca remplit la colonne Dans la deuxieme : on repete
+    # (rank.max-rank.min)^(k-2) chaque chiffre, et on fait ca (rank.max-rank.min)^2
+    # fois ...  Dans la derniere, on repete chaque chiffre une fois, et on fait ca
     # (rank.min-rank.max)^(k-1) fois.
-    RankLambda[, r] <- rep(rank.min + rep(0:(deltaRank - 1), deltaRank^(r - 1), 
+    RankLambda[, r] <- rep(rank.min + rep(0:(deltaRank - 1), deltaRank^(r - 1),
       each = deltaRank^(k - r)), each = L)
   }
   RankLambda[, k + 1] <- rep(1:L, times = Size)
@@ -46,8 +50,8 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min,
   if (ncores > 1)
   {
     cl <- parallel::makeCluster(ncores, outfile = "")
-    parallel::clusterExport(cl, envir = environment(), varlist = c("A1", "Size", 
-      "Pi", "Rho", "mini", "maxi", "X", "Y", "eps", "Rank", "m", "phi", "ncores", 
+    parallel::clusterExport(cl, envir = environment(), varlist = c("A1", "Size",
+      "Pi", "Rho", "mini", "maxi", "X", "Y", "eps", "Rank", "m", "phi", "ncores",
       "verbose"))
   }
 
@@ -55,7 +59,7 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min,
   {
     lambdaIndex <- RankLambda[index, k + 1]
     rankIndex <- RankLambda[index, 1:k]
-    if (ncores > 1) 
+    if (ncores > 1)
       require("valse")  #workers start with an empty environment
 
     # 'relevant' will be the set of relevant columns
@@ -71,7 +75,7 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min,
       phi <- array(0, dim = c(p, m, k))
       if (length(relevant) > 0)
       {
-        res <- EMGrank(S[[lambdaIndex]]$Pi, S[[lambdaIndex]]$Rho, mini, maxi, 
+        res <- EMGrank(S[[lambdaIndex]]$Pi, S[[lambdaIndex]]$Rho, mini, maxi,
           X[, relevant], Y, eps, rankIndex, fast)
         llh <- c(res$LLF, sum(rankIndex * (length(relevant) - rankIndex + m)))
         phi[relevant, , ] <- res$phi
@@ -83,12 +87,12 @@ 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)
+      parallel::parLapply(cl, seq_len(length(S) * Size), computeAtLambda)
     } else {
       lapply(seq_len(length(S) * Size), computeAtLambda)
     }
 
-  if (ncores > 1) 
+  if (ncores > 1)
     parallel::stopCluster(cl)
 
   out