Merge branch 'master' of auder.net:valse
[valse.git] / pkg / R / gridLambda.R
1 #' Construct the data-driven grid for the regularization parameters used for the Lasso estimator
2 #' @param phiInit value for phi
3 #' @param rhoInit value for rho
4 #' @param piInit value for pi
5 #' @param gamInit value for gamma
6 #' @param X matrix of covariates (of size n*p)
7 #' @param Y matrix of responses (of size n*m)
8 #' @param gamma power of weights in the penalty
9 #' @param mini minimum number of iterations in EM algorithm
10 #' @param maxi maximum number of iterations in EM algorithm
11 #' @param tau threshold to stop EM algorithm
12 #' @return the grid of regularization parameters
13 #' @export
14 #-----------------------------------------------------------------------
15 gridLambda = function(phiInit, rhoInit, piInit, gamInit, X, Y, gamma, mini, maxi, tau)
16 {
17 n = nrow(X)
18 p = dim(phiInit)[1]
19 m = dim(phiInit)[2]
20 k = dim(phiInit)[3]
21
22 #list_EMG = .Call("EMGLLF_core",phiInit,rhoInit,piInit,gamInit,mini,maxi,1,0,X,Y,tau)
23 list_EMG = EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,1,0,X,Y,tau)
24 grid = array(0, dim=c(p,m,k))
25 for (i in 1:p)
26 {
27 for (j in 1:m)
28 grid[i,j,] = abs(list_EMG$S[i,j,]) / (n*list_EMG$pi^gamma)
29 }
30 grid = unique(grid)
31 grid = grid[grid <=1]
32
33 return(grid)
34 }