MultivariateSpline#
- class splinebox.multivariate.MultivariateSpline(M, basis_functions, closed=False, control_points=None, padding_functions=<function padding_function>)#
Spline in multiple independent variables.
A multivariate spline is defined as a tensor product of univariate splines, one for each variable. It can be evaluated, fitted to data, and used to generate meshes for bivariate splines.
- Parameters:
- Miterable of int
Number of knots for each variable.
- basis_functions
splinebox.basis_functions.BasisFunctionor iterable The basis function(s) used to construct the spline. A single basis function is applied to all variables; otherwise an iterable with one basis function per variable must be provided.
- closedbool or iterable of bool
Whether each variable is closed. A single boolean is broadcast to all variables.
- control_pointsnumpy array, optional
The control points of the spline. The first
nvariateaxes correspond to the control point grid, and the last axis is the codomain dimension. Control points can be supplied directly as a NumPy array, or built with helpers such assplinebox.multivariate.tensor_product()for separable geometries. IfNone, the spline must be initialized later viaknotsorfit.- padding_functionscallable or iterable of callables
Function(s) used to pad knots for open splines. The default is
splinebox.spline_curves.padding_function().
- Attributes:
control_pointsThe control points \(c[k]\) as defined in equation (1).
half_supportHalf the support of each basis function.
- knots
ndimDimensionality of the codomain, i.e.
padNumber of additional control points used for padding each open end.
Methods
__call__(t[, derivatives])Evaluate the multivariate spline at the parameter values
t.fit(points[, t])Fit the multivariate spline to a set of points by least squares.
mesh([step_t])- Raises:
- ValueError
If
Mis not an iterable of integers, ifbasis_functionsorcloseddo not have the expected length, or ifpadding_functionsdoes not match the number of variables.- RuntimeError
If any entry of
Mis smaller than the support of the corresponding basis function.
Examples
Create a bivariate B-spline:
>>> import numpy as np >>> import splinebox >>> spline = splinebox.multivariate.MultivariateSpline( ... M=(4, 5), ... basis_functions=splinebox.B3(), ... closed=(False, False), ... )
Set the control points directly. For open splines the control points have to be padded along each open dimension (one extra point on each side for B3):
>>> spline.control_points = np.random.rand(6, 7, 3)
Alternatively, a separable control-point grid can be built with
splinebox.multivariate.tensor_product():>>> control_points = splinebox.multivariate.tensor_product( ... [np.sin(np.linspace(0, np.pi, m + 2)) for m in (4, 5)] ... ) >>> spline.control_points = control_points
Evaluate the spline on a grid of parameter values:
>>> t0 = np.linspace(0, 4, 5) >>> t1 = np.linspace(0, 5, 6) >>> t = np.stack(np.meshgrid(t0, t1, indexing="ij"), axis=-1) >>> values = spline(t)