Fix numerical problems in EMGLLF (R version)
[valse.git] / pkg / R / computeGridLambda.R
index 8ec4d66..c2e9c8c 100644 (file)
@@ -1,10 +1,10 @@
-#' computeGridLambda
+#' computeGridLambda 
 #'
 #' Construct the data-driven grid for the regularization parameters used for the Lasso estimator
 #'
 #' @param phiInit value for phi
-#' @param rhoInit      value for rho
-#' @param piInit       value for pi
+#' @param rhoInit\tvalue for rho
+#' @param piInit\tvalue for pi
 #' @param gamInit value for gamma
 #' @param X matrix of covariates (of size n*p)
 #' @param Y matrix of responses (of size n*m)
 #' @return the grid of regularization parameters
 #'
 #' @export
-computeGridLambda = function(phiInit, rhoInit, piInit, gamInit, X, Y,
-       gamma, mini, maxi, tau, fast=TRUE)
+computeGridLambda <- function(phiInit, rhoInit, piInit, gamInit, X, Y, gamma, mini, 
+  maxi, tau, fast)
 {
-       n = nrow(X)
-       p = dim(phiInit)[1]
-       m = dim(phiInit)[2]
-       k = dim(phiInit)[3]
+  n <- nrow(X)
+  p <- dim(phiInit)[1]
+  m <- dim(phiInit)[2]
+  k <- dim(phiInit)[3]
 
-       list_EMG = EMGLLF(phiInit, rhoInit, piInit, gamInit, mini, maxi,
-               gamma, lambda=0, X, Y, tau, fast)
-       grid = array(0, dim=c(p,m,k))
-       for (i in 1:p)
-       {
-               for (j in 1:m)
-                       grid[i,j,] = abs(list_EMG$S[i,j,]) / (n*list_EMG$pi^gamma)
-       }
-       grid = unique(grid)
-       grid
+  list_EMG <- EMGLLF(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda = 0, 
+    X, Y, tau, fast)
+  grid <- array(0, dim = c(p, m, k))
+  for (i in 1:p)
+  {
+    for (j in 1:m)
+      grid[i, j, ] <- abs(list_EMG$S[i, j, ])/(n * list_EMG$pi^gamma)
+  }
+  sort(unique(grid))
 }