sumzero_term()

Contents

sumzero_term()#

liesel_ptm.sumzero_term(basis)[source]#

Matrix Z for reparameterization for sum-to-zero-constraint of a structured additive term.

The reparameterization matrix returned by this function applies a sum-to-zero constraint on the evaluations of a spline.

Parameters:

basis (Any) – Basis matrix to work on.

Return type:

Any

See also

sumzero_coef

Matrix Z for reparameterization for sum-to-zero-constraint of coefficients.

Examples

Example usage:

import numpy as np
import tensorflow_probability.substrates.jax.distributions as tfd
import liesel.model as lsl
import liesel_ptm as ptm

np.random.seed(2407)
x = np.random.uniform(low=-1.0, high=1.0, size=300)
nparam = 10
knots = ptm.kn(x, n_params=nparam)

Z = ptm.sumzero_term(ptm.bspline_basis(x, knots, 3))
K = Z.T @ ptm.diffpen(nparam, diff=2) @ Z

def basis_fn(x):
    return ptm.bspline_basis(x, knots, 3) @ Z

tau2 = ptm.VarWeibull(10.0, scale=0.05, name="tau2")

term = ptm.StructuredAdditiveTerm(
    x=x, basis_fn=basis_fn, K=K, tau2=tau2, name="my_term"
)