pybird.module module
- class pybird.module.InterpolatedUnivariateSpline(x, y, k=3, endpoints='not-a-knot', coefficients=None)[source]
Bases:
object
JAX-compatible interpolation up to cubic order. Taken from https://jax-cosmo.readthedocs.io/en/latest/_modules/jax_cosmo/scipy/interpolate.html
JAX implementation of kth-order spline interpolation.
This class aims to reproduce scipy’s InterpolatedUnivariateSpline functionality using JAX. Not all of the original class’s features have been implemented yet, notably -
w
: no weights are used in the spline fitting. -bbox
: we assume the boundary to always be [x[0], x[-1]]. -ext
: extrapolation is always active, i.e.,ext
= 0. -k
: ordersk
> 3 are not available. -check_finite
: no such check is performed.(The relevant lines from the original docstring have been included in the following.)
Fits a spline y = spl(x) of degree
k
to the providedx
,y
data. Spline function passes through all provided points. Equivalent toUnivariateSpline
with s = 0.- Parameters:
x ((N,) array_like) – Input dimension of data points – must be strictly increasing
y ((N,) array_like) – input dimension of data points
k (int, optional) – Degree of the smoothing spline. Must be 1 <=
k
<= 3.endpoints (str, optional, one of {'natural', 'not-a-knot'}) – Endpoint condition for cubic splines, i.e.,
k
= 3. ‘natural’ endpoints enforce a vanishing second derivative of the spline at the two endpoints, while ‘not-a-knot’ ensures that the third derivatives are equal for the two left-mostx
of the domain, as well as for the two right-mostx
. The original scipy implementation uses ‘not-a-knot’.coefficients (list, optional) – Precomputed parameters for spline interpolation. Shouldn’t be set manually.
See also
UnivariateSpline
Superclass – allows knots to be selected by a smoothing condition
LSQUnivariateSpline
spline for which knots are user-selected
splrep
An older, non object-oriented wrapping of FITPACK
splev
,sproot
,splint
,spalde
BivariateSpline
A similar class for two-dimensional spline interpolation
Notes
The number of data points must be larger than the spline degree
k
.- The general form of the spline can be written as
f[i](x) = a[i] + b[i](x - x[i]) + c[i](x - x[i])^2 + d[i](x - x[i])^3, i = 0, …, n-1,
where d = 0 for
k
= 2, and c = d = 0 fork
= 1.The unknown coefficients (a, b, c, d) define a symmetric, diagonal linear system of equations, Az = s, where z = b for
k
= 1 andk
= 2, and z = c fork
= 3. In each case, the coefficients defining each spline piece can be expressed in terms of only z[i], z[i+1], y[i], and y[i+1]. The coefficients are solved for usingnumpy.linalg.solve
whenk
= 2 andk
= 3.