Description Usage Arguments Author(s) References Examples
To implement interface to calculate SGL using C++
1 |
data |
list of input data x and y |
index |
group index |
thresh |
threshold |
nlam |
number of lambdas long the regularization path |
lambdas |
list of values of lambdas set by user |
beta.naught |
beta.naught |
inner.iter |
innter.iter |
outer.iter |
outer.iter |
outer.thresh |
threshold of outer loop |
gamma |
gamma |
step |
step |
reset |
reset |
alpha |
alpha |
min.frac |
min.frac |
verbose |
verbose |
Noah Simon, Jerome Friedman, Trevor Hastie, and Rob Tibshirani
Simon, N., Friedman, J., Hastie T., and Tibshirani, R. (2011) A Sparse-Group Lasso, http://www-stat.stanford.edu/~nsimon/SGL.pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (data, index, thresh = 0.01, nlam = 20, lambdas = NULL,
beta.naught = rep(0, ncol(data$x)), inner.iter = 100, outer.iter = 100,
outer.thresh = 0.01, gamma = 0.8, step = 1, reset = 10, alpha = 0.95,
min.frac = 0.05, verbose = FALSE)
{
if (is.null(lambdas)) {
lambdas <- betterPathCalc(data = data, index = index,
alpha = alpha, min.frac = min.frac, nlam = nlam,
type = "linear")
}
dyn.load("F://R files//PackageTest03//PackageTest//src//PackageTest.dll")
X <- data$x
y <- data$y
n <- nrow(X)
p <- ncol(X)
ord <- order(index)
index <- index[ord]
X <- X[, ord]
unOrd <- match(1:length(ord), ord)
groups <- unique(index)
num.groups <- length(groups)
range.group.ind <- rep(0, (num.groups + 1))
for (i in 1:num.groups) {
range.group.ind[i] <- min(which(index == groups[i])) -
1
}
range.group.ind[num.groups + 1] <- ncol(X)
group.length <- diff(range.group.ind)
nlam = length(lambdas)
beta.old <- rep(0, ncol(X))
beta.is.zero <- rep(1, num.groups)
beta <- array(0, c(ncol(X), nlam))
eta <- rep(0, n)
for (k in 1:nlam) {
beta.is.zero <- rep(1, num.groups)
beta.old <- rep(0, ncol(X))
eta <- rep(0, n)
junk <- .C("linNest", X = as.double(as.vector(X)), y = as.double(y),
index = as.integer(index), nrow = as.integer(nrow(X)),
ncol = as.integer(ncol(X)), numGroup = as.integer(num.groups),
rangeGroupInd = as.integer(range.group.ind), groupLen = as.integer(group.length),
lambda1 = as.double(lambdas[k] * alpha), lambda2 = as.double(lambdas[k] *
(1 - alpha)), beta = as.double(beta.old), innerIter = as.integer(inner.iter),
outerIter = as.integer(outer.iter), thresh = as.double(thresh),
outerThresh = as.double(outer.thresh), eta = as.double(eta),
gamma = as.double(gamma), betaIsZero = as.integer(beta.is.zero),
step = as.double(step), reset = as.integer(reset),
PACKAGE = "PackageTest")
beta.new <- junk$beta
beta[, k] <- beta.new
beta.is.zero <- junk$betaIsZero
eta <- junk$eta
beta.old <- beta.new
if (verbose == TRUE) {
write(paste("***Lambda", k, "***"), "")
}
}
return(list(beta = beta[unOrd, ], lambdas = lambdas))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.