BasisBuilder.bs()#
- BasisBuilder.bs(x, *, k, basis_degree=3, penalty_order=2, knots=None, absorb_cons=True, diagonal_penalty=True, scale_penalty=True, basis_name='B')[source]#
B-spline basis with integrated squared derivative penalties.
- Parameters:
k (
int) – Number of (unconstrained) bases.basis_degree (
int, default:3) – Degree of the polynomials used in the B-spline basis function. Default is 3 for cubic B-splines.penalty_order (
int|Sequence[int], default:2) – Order of the penalty. If this is a sequence of integers, a penalty of the integer’s order is added for each entry in the sequence.knots (
Array|ndarray|bool|number|bool|int|float|complex|None, default:None) – Knots used to set up the basis. IfNone(default), a set of equidistant knots will be set up automatically, with the domain boundaries inferred from the minimum and maximum of the observed values.absorb_cons (
bool, default:True) – Whether the default identification constraint should be applied by reparameterization and absorbing the reparameterization matrix into the basis and penalty matrices for computational efficiency. IfFalse, the basis is unconstrained, ifTrueit receives a sum to zero constrained. Also seeBasis.constrain().diagonal_penalty (
bool, default:True) – Whether the penalty matrix associated with this term should be reparameterized into a diagonal matrix. In this case, the basis matrix is reparameterized accordingly. This can be beneficial for posterior geometry, which is why it is the default. Also seeBasis.diagonalize_penalty().scale_penalty (
bool, default:True) – Whether the penalty matrix should be scaled such that its infinity norm is one. This can improve numerical stability, which is why it is done by default. Also seeBasis.scale_penalty().basis_name (
str, default:'B') – Function-name for the basis matrix. If"B", and the basis is a function of the variable"x", the full name of theBasisobject will be"B(x)". Names are made unique by appending a counter if necessary.
- Return type:
Notes
This basis is initialized with
use_callback=Trueandcache_basis=True. SeeBasisfor details.This method internally calls the R package mgcv to set up the basis and penalty. The mgcv documentation provides further details.
References
Wood, S.N. (2017) Generalized Additive Models: An Introduction with R (2nd edition). Chapman and Hall/CRC.
R package mgcv https://cran.r-project.org/web/packages/mgcv/index.html
Examples
>>> import liesel_gam as gam >>> df = gam.demo_data(n=100) >>> registry = gam.PandasRegistry(df) >>> bb = gam.BasisBuilder(registry) >>> bb.bs("x_nonlin", k=20) Basis(name="B(x_nonlin)")