fusedlasso function takes either a penalty matrix
or a graph object from the igraph package. The
fusedlasso1d and fusedlasso2d functions are convenience
functions that construct the penalty matrix over a 1d or 2d grid.fusedlasso(y, X, D, graph, gamma = 0, approx = FALSE, maxsteps = 2000,
minlam = 0, tol = 1e-11, verbose = FALSE, fileback = FALSE)
fusedlasso1d(y, X, z, gamma = 0, approx = FALSE, maxsteps = 2000,
minlam = 0, tol = 1e-11, verbose = FALSE)
fusedlasso2d(y, X, dim1, dim2, gamma = 0, approx = FALSE,
maxsteps = 2000, minlam = 0, tol = 1e-11, verbose = FALSE,
fileback = FALSE)fusedlasso2d
with no matrix X passed, y can be a matrix
(its dimensions corresponding to the underlying 2d grid). Note that
when y is given as a fusedlasso, this is the penalty matrix, i.e., the
oriented incidence matrix over the underlying graph (the orientation
of each edge being arbitrary). Only one of D or graph
needs to be specified.fusedlasso, this is the underlying graph as an
igraph object from the igraph package. Only one of
D or graph needs to be specified.fusedlasso1d, these are the optional positions of
the gridpoints in the 1d grid. If missing, the 1d grid is assumed to
have unit spacing. Note that arbitrary positions z cannot be
used in the presence of a fusedlasso2d, this is the number of rows in the
underlying 2d grid. If missing and y is given as a matrix, it
is assumed to be the number of rows of y.fusedlasso2d, this is the number of columns in the
underlying 2d grid. If missing and y is given as a matrix, it
is assumed to be the number of columns of y.FALSE. Note
that for the 1d fused lasso, with identity predicor matrix and
evenly spacefusedlasso or fusedlasso2d, this is
a logical variable indicating if file backing should be used. It
can also be a character string indicating the file name to use for
file backing. See "Details" below for mofileback is TRUE, a special list is silently returned
which should be processed via filebackout. Otherwise the
function returns an object of class "fusedlasso", and subclass
"genlasso". This is a list with at least following components:FALSE
indicates a variable leaving the boundary.maxsteps or
minlam options results in a value of FALSE).NULL when completepath is FALSE.fusedlasso2d function begins at the fully regularized end
and works its way down to the dense end. For a problem with many
edges (dual variables), if a solution at the dense is desired, then it
must usually pass through a huge number knots in the path. Hence it is
not advisable to run fusedlasso2d on image denoising problems of
large scale, as the dual solution path is computationally
infeasible. It should be noted that a faster algorithm for the 2d
fused lasso solution path (when the predictor matrix is the identity),
which begins at the dense end of the path, is available in the
flsa package. If the predictor matrix is the identity, and the primal solution path
$\beta$ is desired at several levels of the ratio parameter
$\gamma$, it is much more efficient to compute the solution path
once with $\gamma=0$, and then use soft-thresholding via the
softthresh function.
For large runs a potentially substantial increase in speed can be
achieved by storing the solution path on disk rather than in memory,
which is achieved by setting fileback equal to TRUE. The
output can be read via the filebackout function. For
very large problems, where the path object cannot be read safely into
memory, the user can use a customized call to the readlines
function.
Tibshirani, R., Saunders, M., Rosset, S., Zhu, J. and Knight, K. (2005), "Sparsity and smoothness via the fused lasso", Journal of the Royal Statistics Society: Series B 67(1), 91--108.
softthresh, filebackout,
genlasso# The 2d fused lasso with a predictor matrix X
set.seed(0)
dim1 = dim2 = 16
p = dim1*dim2
n = 300
X = matrix(rnorm(n*p),nrow=n)
beta0 = matrix(0,dim1,dim2)
beta0[(row(beta0)-dim1/2)^2 + (col(beta0)-dim2/2)^2 <=
(min(dim1,dim2)/3)^2] = 1
y = X %*% as.numeric(beta0) + rnorm(n)
# Takes about 30 seconds for the full solution path
out = fusedlasso2d(y,X,dim1=dim1,dim2=dim2)
# Grab the solution at 8 values of lambda over the path
a = coef(out,nlam=8)
# Plot these against the true coefficients
par(mar=c(1,1,2,1),mfrow=c(3,3))
cols = terrain.colors(30)
zlim = range(c(range(beta0),range(a$beta)))
image(beta0,col=cols,zlim=zlim,axes=FALSE)
for (i in 1:8) {
image(matrix(a$beta[,i],nrow=dim1),col=cols,zlim=zlim,
axes=FALSE)
mtext(bquote(lambda==.(sprintf("%.3f",a$lambda[i]))))
}Run the code above in your browser using DataLab