IndexingTerm#
- class liesel_gam.IndexingTerm(basis, penalty, scale, name='', inference=None, coef_name=None, _update_on_init=True, validate_scalar_scale=True)[source]#
Bases:
StrctTermTerm object for memory-efficient representation of sparse bases.
Derived from
StrctTerm. If the basis matrix of a term is a dummy matrix, where each column consists only of binary (0/1) entries, and each row has only one non-zero entry, then it is not necessary to store the full matrix in memory and evaluate the term as a dot productbasis @ coef.Instead, we can simply store a 1-D array of indices, identifying the nonzero column for each row of the basis matrix, and use this index to access the corresponding coefficient. This scenario is common for independent random intercepts.
This class implements such a sparse representation.
In case you do need to materialize the full, sparse basis of such a term, you can use
IndexingTerm.init_full_basis().Examples
>>> basis = Basis(jnp.array([0, 1, 0, 1]), xname="group", penalty=None) >>> term = IndexingTerm(basis, penalty=jnp.eye(2), scale=1.0) >>> term.value.shape, term.nclusters ((4,), 2)
Methods
Materializes a
Basisobject that holds the full basis matrix corresponding to this term.Attributes