SplineCategorical#
- class superglm.SplineCategorical(spline_name: str, cat_name: str)#
Bases:
objectVarying-coefficient interaction: spline curve per categorical level.
For each non-base level of the categorical, produces one group of K B-spline columns masked by the level indicator. The base level’s effect is absorbed into the main spline term.
- build_discrete(
- x_spline: NDArray,
- x_cat: NDArray,
- parent_specs: dict,
- n_bins: int,
- sample_weight: NDArray | None = None,
- separation: tuple | None = None,
Build spline-by-category groups from compressed spline support.
- score(
- x_spline: NDArray,
- x_cat: NDArray,
- beta: NDArray,
Score the interaction directly from its public runtime blocks.
- level_design_rows(
- x: NDArray,
Each non-base level with the matrix taking its fitted coefficients to its curve at
x.Shape
(len(x), width):rows @ beta_levelis that level’s column oflevel_log_deviations(), held-range clip included, so a covariance of the fitted coefficients gives the curve’s variance asrows @ cov @ rows.T.
- level_log_deviations(
- x: NDArray,
- beta: NDArray,
Every non-base level’s log deviation from the base curve at
x.Shape
(len(x), len(non_base)), columns in_non_baseorder, and the same numbersscoregives a row of that level at thatx: it goes through the same coefficients and the same held-range clip. One basis evaluation serves every level, so the cost is linear in the number of levels, which a loop overscoreorreconstructis not.
- level_index(
- x_cat: NDArray,
Each row’s position
jin_non_base, or -1 for a row of the base level.The labels are routed as
scoreroutes them – grouping, unseen policy and all – so this is the level a row’s curve is read for.
- banded_deviation(
- band: NDArray,
- x_cat: NDArray,
- cells: NDArray,
Each row’s cell:
cells[band, j]for a row of non-base levelj, 0 for any other.cellsis(bands, len(non_base))in_non_baseorder andbandgives each row’s band; the row’s level islevel_index(), so a table of cells rates a row on the level its curve would have been read for.