gwinferno.interpolation.BasisSpline#

class BasisSpline(n_df, knots=None, interior_knots=None, xrange=(0, 1), k=4, normalize=True)[source]#

Bases: object

Methods

bases(xs)

bases form the basis spline design matrix evaluated at xs.

eval(xs, coefs)

eval Evaluate basis spline at xs given coefficients

get_coefficients(xs, ys)

computes the coefficients of the basis components given data 1-D data (xs, ys)

norm(coefs)

norm numerically normalizes the spline

project(bases, coefs)

project given a design matrix (or bases) and coefficients, project the coefficients onto the spline

__call__(xs, coefs)[source]#

__call__ Evaluate basis spline at xs given coefficients

Args:

xs (array_like): input values to evaluate the basis spline at coefs (array_like): coefficients for the basis components

Returns:

array_like: The linear combination of the basis components evaluated at xs given the coefficients

__init__(n_df, knots=None, interior_knots=None, xrange=(0, 1), k=4, normalize=True)[source]#

Class to construct a basis spline (with the M-Spline basis)

Args:

n_df (int): number of degrees of freedom for the spline knots (array_like, optional): array of knots, if non-uniform knot placing is preferred.

Defaults to None.

interior_knots (array_like, optional): array of interior knots,

if non-uniform knot placing is preferred. Defaults to None.

xrange (tuple, optional): domain of spline. Defaults to (0, 1). k (int, optional): order of the spline +1, i.e. cubic splines->k=4. Defaults to 4 (cubic spline). normalize (bool, optional): flag whether or not to numerically normalize the spline. Defaults to True.

bases(xs)[source]#

bases form the basis spline design matrix evaluated at xs. All basis values outside the range of the spline are set to zero.

Args:

xs (array_like): input values to evaluate the basis spline at

Returns:

array_like: the design matrix evaluated at xs. shape (N, *xs.shape)

eval(xs, coefs)[source]#

eval Evaluate basis spline at xs given coefficients

Args:

xs (array_like): input values to evaluate the basis spline at coefs (array_like): coefficients for the basis components

Returns:

array_like: The linear combination of the basis components evaluated at xs given the coefficients

get_coefficients(xs, ys)[source]#

computes the coefficients of the basis components given data 1-D data (xs, ys)

Args:

xs (array_like): The x values of data ys (array_like): The y values of data

Returns:

the coefficients (array_like), interpolated y-values evaluated at xs (array_like), the design matrix evaluated at xs with shape (N, *xs.shape)

norm(coefs)[source]#

norm numerically normalizes the spline

Args:

coefs (array_like): coefficients for the basis components

Returns:

float: the normalization factor given the coefficients

project(bases, coefs)[source]#

project given a design matrix (or bases) and coefficients, project the coefficients onto the spline

Args:

bases (array_like): The set of basis components or design matrix to project onto coefs (array_like): coefficients for the basis components

Returns:

array_like: The linear combination of the basis components given the coefficients