Skip to content

Splines

splines

Spline bases for qlPCA (thesis section 3.1.1 and the MATLAB listings of 3.2).

The pseudo-indicator matrix of a variable is its I-spline basis. With B-splines B_1..B_{w+1} of degree v on the knot sequence, I_i = sum_{q>i} B_q (i = 1..w, w = v + r); the first B-spline is dropped, so the constant is not in the span (it is recovered by centring in the estimator).

matlab_prctile

matlab_prctile(x, q)

Percentiles as MATLAB prctile (Hazen definition).

Parameters:

Name Type Description Default
x array - like

Data.

required
q float or array - like

Percentiles, between 0 and 100.

required

Returns:

Type Description
float or ndarray

The percentiles of x.

interior_knots

interior_knots(x, n_knots)

Interior knots at the percentiles round(100 i / (r + 1)), i = 1..r.

Rounding is MATLAB's (half away from zero), not numpy's banker's rounding.

Parameters:

Name Type Description Default
x array - like

Data of one variable.

required
n_knots int

Number r of interior knots.

required

Returns:

Type Description
ndarray of shape (n_knots,)

Sorted interior knots, in the units of x.

knot_sequence

knot_sequence(x, degree, n_knots, interior=None)

Full knot sequence: min repeated degree+1 times, interior knots, max repeated degree+1 times.

Interior knots that coincide (ties in the data) or fall on or outside the boundary are merged or dropped, with a warning, which reduces the basis dimension (DESIGN D7).

Parameters:

Name Type Description Default
x array - like

Data of one variable.

required
degree int

Spline degree.

required
n_knots int

Number of interior knots at the percentiles (ignored if interior is given).

required
interior array - like

Explicit interior knots.

None

Returns:

Type Description
ndarray

The knot sequence.

bspline_basis

bspline_basis(x, degree, knots)

Dense B-spline design matrix.

Parameters:

Name Type Description Default
x array-like of shape (n,)

Points, within [knots[degree], knots[-degree-1]]; the right endpoint is included.

required
degree int

Spline degree.

required
knots array - like

Full knot sequence.

required

Returns:

Type Description
ndarray of shape (n, len(knots) - degree - 1)

B-spline basis functions evaluated at x.

ispline_basis

ispline_basis(x, degree, knots)

I-spline basis: reverse cumulative sum of the B-splines, the first column dropped.

Parameters:

Name Type Description Default
x array-like of shape (n,)

Points.

required
degree int

Spline degree.

required
knots array - like

Full knot sequence.

required

Returns:

Type Description
ndarray of shape (n, degree + r)

Monotone I-spline columns, from 0 to 1.

pseudo_indicator

pseudo_indicator(x, degree=1, n_knots=1, knots=None)

Pseudo-indicator matrix G of a continuous variable (its I-spline basis).

Parameters:

Name Type Description Default
x array-like of shape (n,)

Data of one variable.

required
degree int

Spline degree.

1
n_knots int

Number of interior knots at the percentiles.

1
knots array - like

Full knot sequence; pass it to evaluate the basis on other points.

None

Returns:

Name Type Description
G ndarray of shape (n, degree + n_knots)

Pseudo-indicator matrix.

knots ndarray

The knot sequence used.