sumzero_coef()

Contents

sumzero_coef()#

liesel_ptm.sumzero_coef(nparam)[source]#

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

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

Parameters:

nparam (int) – Number of parameters.

Return type:

Any

See also

sumzero_term

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

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_coef(nparam)

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"
)