BSplineApprox#
- class liesel_gam.experimental.BSplineApprox(knots, degree=3, ngrid=1000, Z=None, subscripts='...ij,...j->...i')[source]#
Bases:
objectApproximate B-spline evaluations on a fixed grid.
- Parameters:
knots (
Array) – Knot positions.degree (
int, default:3) – Degree of the spline, withdegree=3indicating a cubic spline.ngrid (
int, default:1000) – Number of grid points used to precompute the basis (default 1000).Z (
Array|None, default:None) – Optional matrix to post-multiply the basis. InB(x) @ Z,B(x)is the basis matrix andZis the postmultiplication matrix. Can be used to apply linear constraints via reparameterization matrices such as those returned byLinearConstraintEVD.
See also
LinearConstraintEVDCompute reparameterization matrices for linear constraints.
Examples
Basic example.
>>> import jax >>> from liesel.contrib.splines import equidistant_knots >>> import liesel_gam as gam
>>> nbases = 20 >>> x = jax.random.uniform(jax.random.key(1234), shape=(40,)) >>> coef = jax.random.normal(jax.random.key(4321), shape=(nbases,)) >>> knots = equidistant_knots(x, n_param=nbases)
>>> bspline = gam.experimental.BSplineApprox(knots) >>> bspline.dot(x, coef).shape (40,)
Applying a linear constraint matrix.
>>> import jax >>> from liesel.contrib.splines import basis_matrix, equidistant_knots >>> import liesel_gam as gam
>>> nbases = 20 >>> x = jax.random.uniform(jax.random.key(1234), shape=(40,)) >>> coef = jax.random.normal(jax.random.key(4321), shape=((nbases - 1),)) >>> knots = equidistant_knots(x, n_param=nbases)
>>> basis = basis_matrix(x, knots) >>> Z = gam.LinearConstraintEVD.sumzero_term(basis)
>>> bspline = gam.experimental.BSplineApprox(knots, Z=Z) >>> bspline.dot(x, coef).shape (40,)
Methods
Approximates B-spline basis for input data.
Approximates basis and matrix of first derivatives.
Approximates basis matrix and matrices of first and second derivatives.
Computes the basis matrix.
Computes the matrix of basis function derivatives with respect to x.
Computes the matrix of basis function second derivatives with respect to x.
Evaluate spline at given points.
Evaluate spline and its derivative.