fusedlasso | R Documentation |
These functions produce the solution path for a general fused lasso
problem. The 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, rtol = 1e-07, btol = 1e-07, eps = 1e-4, verbose = FALSE) fusedlasso1d(y, pos, X, gamma = 0, approx = FALSE, maxsteps = 2000, minlam = 0, rtol = 1e-07, btol = 1e-07, eps = 1e-4, verbose = FALSE) fusedlasso2d(y, X, dim1, dim2, gamma = 0, approx = FALSE, maxsteps = 2000, minlam = 0, rtol = 1e-07, btol = 1e-07, eps = 1e-4, verbose = FALSE)
y |
a numeric response vector. Alternatively, for |
pos |
only for |
X |
an optional matrix of predictor variables, with observations along
the rows, and variables along the columns. If the passed |
D |
only for |
graph |
only for |
dim1 |
only for |
dim2 |
only for |
gamma |
a numeric variable greater than or equal to 0, indicating the ratio of the two tuning parameters, one for the fusion penalty, and the other for the pure \ell_1 penalty. Default is 0. See "Details" for more information. |
approx |
a logical variable indicating if the approximate solution path
should be used (with no dual coordinates leaving the boundary).
Default is |
maxsteps |
an integer specifying the maximum number of steps for the algorithm to take before termination. Default is 2000. |
minlam |
a numeric variable indicating the value of lambda at which the path should terminate. Default is 0. |
rtol |
a numeric variable giving the tolerance for determining the rank of a matrix: if a diagonal value in the R factor of a QR decomposition is less than R, in absolute value, then it is considered zero. Hence making rtol larger means being less stringent with determination of matrix rank. In general, do not change this unless you know what you are getting into! Default is 1e-7. |
btol |
a numeric variable giving the tolerance for accepting "late" hitting and leaving times: future hitting times and leaving times should always be less than the current knot in the path, but sometimes for numerical reasons they are larger; any computed hitting or leaving time larger than the current knot + btol is thrown away. Hence making btol larger means being less stringent withthe determination of hitting and leaving times. Again, in general, do not change this unless you know what you are getting into! Default is 1e-7. |
eps |
a numeric variable indicating the multiplier for the ridge penalty,
in the case that |
verbose |
a logical variable indicating if progress should be reported after each knot in the path. |
The fused lasso estimate minimizes the criterion
1/2 ∑_{i=1}^n (y_i - x_i^T β_i)^2 + λ ∑_{(i,j) \in E} |β_i - β_j| + γ \cdot λ ∑_{i=1}^p |β_i|,
where x_i is the ith row of the predictor matrix and E is the edge set of the underlying graph. The solution \hat{β} is computed as a function of the regularization parameter λ, for a fixed value of γ. The default is to set γ=0, which corresponds to pure fusion of the coefficient vector β. A choice γ>0 introduces both sparsity and fusion in the coefficient vector, with a higher value placing more priority on sparsity.
If the predictor matrix is the identity, and the primal solution path
β is desired at several levels of the ratio parameter
γ, it is much more efficient to compute the solution path
once with γ=0, and then use soft-thresholding via the
softthresh
function.
Finally, for the image denoising problem, i.e., the fused lasso over a 2d
grid with identity predictor matrix, it is easy to specify a huge graph
with a seemingly small amount of data. For instance, running the 2d
fused lasso (with identity predictor matrix) on an image at standard
1080p HD resolution yields a graph with over 2 million
edges. Moreover, in image denoising problems—somewhat unlike most
other applications of the fused lasso (and generalized lasso)—a
solution is often desired near the dense end of the path
(λ=0) as opposed to the regularized end
(λ=∞). The dual path algorithm implemented by the
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.
The function returns an object of class "fusedlasso", and subclass "genlasso". This is a list with at least following components:
lambda |
values of lambda at which the solution path changes slope, i.e., kinks or knots. |
beta |
a matrix of primal coefficients, each column corresponding to a knot in the solution path. |
fit |
a matrix of fitted values, each column corresponding to a knot in the solution path. |
u |
a matrix of dual coefficients, each column corresponding to a knot in the solution path. |
hit |
a vector of logical values indicating if a new variable in the dual
solution hit the box contraint boundary. A value of |
df |
a vector giving an unbiased estimate of the degrees of freedom of the fit at each knot in the solution path. |
y |
the observed response vector. Useful for plotting and other methods. |
completepath |
a logical variable indicating whether the complete path was
computed (terminating the path early with the |
bls |
the least squares solution, i.e., the solution at lambda = 0. This
can be |
gamma |
the value of the lambda ratio. |
call |
the matched call. |
Taylor B. Arnold and Ryan J. Tibshirani
Tibshirani, R. J. and Taylor, J. (2011), "The solution path of the generalized lasso", Annals of Statistics 39 (3) 1335–1371.
Arnold, T. B. and Tibshirani, R. J. (2014), "Efficient implementations of the generalized lasso dual path algorithm", arXiv: 1405.3222.
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
, genlasso
# Fused lasso on a custom graph set.seed(0) edges = c(1,2,1,3,1,5,2,4,2,5,3,6,3,7,3,8,6,7,6,8) gr = graph(edges=edges,directed=FALSE) plot(gr) y = c(1,1,0,1,1,0,0,0) + rnorm(8,0.1) # Can either pass the graph object directly, or # first construct the penalty matrix, and then # pass this a1 = fusedlasso(y,graph=gr) D = getDgSparse(gr) a2 = fusedlasso(y,D=D) plot(a1,numbers=TRUE) # 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 oldpar <- par(no.readonly = TRUE) on.exit(par(oldpar)) 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])))) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.