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 : orders k > 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 provided x, y data. Spline function passes through all provided points. Equivalent to UnivariateSpline 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-most x of the domain, as well as for the two right-most x. 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 for k = 1.

The unknown coefficients (a, b, c, d) define a symmetric, diagonal linear system of equations, Az = s, where z = b for k = 1 and k = 2, and z = c for k = 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 using numpy.linalg.solve when k = 2 and k = 3.

tree_flatten()[source]
classmethod tree_unflatten(aux_data, children)[source]
derivative(x, n=1)[source]

Analytic nth derivative of the spline.

The spline has derivatives up to its order k.

antiderivative(xs)[source]

Computes the antiderivative of first order of this spline

integral(a, b)[source]

Compute a definite integral over a piecewise polynomial. :param a: Lower integration bound :type a: float :param b: Upper integration bound :type b: float

Returns:

ig – Definite integral of the piecewise polynomial over [a, b]

Return type:

array_like