Fix numerical problems in EMGLLF (R version)
[valse.git] / pkg / R / constructionModelesLassoRank.R
index 5c742d1..85685e9 100644 (file)
 #' @param ncores Number of cores, by default = 3
 #' @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
 #'
 #' @export
 constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min, rank.max, 
-  ncores, fast = TRUE, verbose = FALSE)
+  ncores, fast, verbose)
 {
   n <- dim(X)[1]
   p <- dim(X)[2]
@@ -64,9 +64,7 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min,
     for (j in 1:p)
     {
       if (length(selected[[j]]) > 0)
-      {
         relevant <- c(relevant, j)
-      }
     }
     if (max(rankIndex) < length(relevant))
     {
@@ -75,19 +73,20 @@ constructionModelesLassoRank <- function(S, k, mini, maxi, X, Y, eps, rank.min,
       {
         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)))
+        llh <- c(res$LLF, sum(rankIndex * (length(relevant) - rankIndex + m)))
         phi[relevant, , ] <- res$phi
       }
       list(llh = llh, phi = phi, pi = S[[lambdaIndex]]$Pi, rho = S[[lambdaIndex]]$Rho)
-      
     }
   }
 
   # 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)