These are utility functions for creating penalty matrices for the
fused lasso and trend filtering problems. Most users will not need to
explicitly construct these as they are created internally by the
fusedlasso
or trendfilter
functions. The sparse
variants output sparse matrices, which should be used whenever
possible because of a significant savings in both construction speed
and memory usage.
The function getGraph is an inverse function for fused lasso problems,
returning an igraph
object (from the igraph
package), the
graph corresponding to the passed penalty matrix.
getD1d(n)
getD1dSparse(n)
getD2d(dim1, dim2)
getD2dSparse(dim1, dim2)
getDg(graph)
getDgSparse(graph)
getDtf(n, ord)
getDtfSparse(n, ord)
getDtfPos(n, ord, pos)
getDtfPosSparse(n, ord, pos)
getGraph(D)
All functions except getGraph
return a penalty matrix, either
in standard R matrix format or as a sparse matrix of class
dgCMatrix
via the Matrix
package. The function
getGraph
returns an igraph
object from the igraph
package.
The arguments for the sparse variants are identical to those for the regular variants, which are described below.
for getD1d
, getDtf
, and getDtfPos
,
the number of points in the 1d sequence.
for getD2d
, the number of rows and columns in the 2d grid,
respectively.
for getDg
, an igraph
object from the igraph
package, upon which the penalty matrix should be based (the penalty
matrix is the oriented incidence matrix of the graph, with arbitrary
orientations assigned to each edge).
for getDtf
, and getDtfPos
, the order of the
polynomial. E.g., ord=0 is the 1d fused lasso and ord=1 is linear
trend filtering. Hence the returned matrix is the discrete (ord+1)st
derivative operator.
for getDtfPos
, a numeric vector giving the positions of
points in the 1d sequence. Must have length n
.
for getGraph
, a fused lasso penalty matrix, the incidence
matrix of an undirected graph, with arbitrary edge orientations.
fusedlasso
, trendfilter
getD1d(9)
getDtfSparse(10,2)
graph = getGraph(getD2dSparse(4,4))
plot(graph)
Run the code above in your browser using DataLab