View source: R/matrix_construction.R
n_mat | R Documentation |
Constructs the discrete B-spline basis matrix of a given order, with respect to given design points and given knot points.
n_mat(k, xd, normalized = TRUE, knot_idx = NULL)
k |
Order for the discrete B-spline basis matrix. Must be >= 0. |
xd |
Design points. Must be sorted in increasing order, and have length
at least |
normalized |
Should the discrete B-spline basis vectors be normalized to
attain a maximum value of 1 over the design points? The default is |
knot_idx |
Vector of indices, a subset of |
The discrete B-spline basis matrix of order k
, with respect to
design points x_1 < \ldots < x_n
, and knot set T \subseteq
x_{(k+1):(n-1)}
is denoted N^k_T
. It has dimension (|T|+k+1)
\times n
, and its entries are given by:
(N^k_T)_{ij} = \eta^k_j(x_i),
where \eta^k_1, \ldots, \eta^k_m
are discrete B-spline (DB-spline)
basis functions and m = |T|+k+1
. As is suggested by their name, the
DB-spline functions are linearly independent and span the space of
discrete splines with knots at T
. Each DB-spline \eta^k_j
has a
key local support property: it is supported on an interval containing at
most k+2
adjacent knots.
The functions \eta^k_1, \ldots, \eta^k_m
are, in general, not available
in closed-form, and are defined by setting up and solving a sequence of
locally-defined linear systems. For any knot set T
, computation of
the evaluations of all DB-splines at the design points can be done in
O(nk^2)
operations; see Sections 7, 8.2, and 8.3 of Tibshirani (2020)
for details. The current function uses a sparse QR decomposition from the
Eigen::SparseQR
module in C++ in order to solve the local linear systems.
When T = x_{(k+1):(n-1)}
, the knot set corresponding to the "canonical"
discrete spline space (spanned by the falling factorial basis functions
h^k_1, \ldots, h^k_n
whose evaluations make up H^k_n
; see the
help file for h_mat()
), the DB-spline basis matrix, which we denote by
N^k_n
, is trivial: it equals the n \times n
identity matrix,
N^k_n = I_n
. Therefore DB-splines are really only useful for knot
sets T
that are proper subsets of x_{(k+1):(n-1)}
.
Specification of the knot set T
is done via the argument knot_idx
.
Sparse matrix of dimension length(xd)
by length(knot_idx) + k + 1
.
Tibshirani (2020), "Divided differences, falling factorials, and discrete splines: Another look at trend filtering and related problems", Sections 7, 8.2, and 8.3.
h_eval()
for constructing evaluations of the discrete B-spline
basis at arbitrary query points.
n_mat(2, 1:10, knot_idx = c(3, 5, 7))
n_mat(2, 1:10, knot_idx = c(4, 6, 8))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.