dynamirt.gllvm.terms package¶
Submodules¶
dynamirt.gllvm.terms.continuous module¶
- class dynamirt.gllvm.terms.continuous.ExactGP(name: str, predictors: str | Sequence[str], kernel: Callable[[dict], Kernel], params: Mapping[str, Param], group_by: str | None = None, varies_over_variables: bool = True, jitter: float = 1e-06)¶
Bases:
objectExact Gaussian process term for a gllvm regression.
Computes
f = L @ zwhere L is the Cholesky factor of the kernel matrix and z are standard-normal draws. Observations are padded into a dense (n_groups, n_max_points, dim) tensor so that group-wise covariance matrices can be computed in a single vmap pass.Might need manual jax.config.update(“jax_enable_x64”, True) to prevent underflow.
- Variables:
name (str) – Sample-site prefix. The GP realisation is stored under a deterministic site with this name.
predictors (str | Sequence[str]) – Covariate name(s) used as GP inputs.
kernel (Callable[[dict], tinygp.kernels.base.Kernel]) – A callable
kernel(params) -> tinygp.kernels.Kernelthat builds the kernel from a dict of sampled parameters.params (Mapping[str, dynamirt.gllvm.parameters.Param]) – Mapping from parameter name to
Paraminstance. Each entry is sampled and passed to kernel.group_by (str | None) – Optional covariate name giving a grouping factor. A separate GP is drawn per level. None means one shared GP. Defaults to None.
varies_over_variables (bool) – If True, an independent GP realisation is drawn for each response variable; if False, a single realisation is broadcast. Defaults to True.
jitter (float) – Small constant added to the kernel diagonal before Cholesky decomposition for numerical stability. Defaults to 1e-6.
- group_by: str | None = None¶
- jitter: float = 1e-06¶
- kernel: Callable[[dict], Kernel]¶
- name: str¶
- predictors: str | Sequence[str]¶
- varies_over_variables: bool = True¶
- class dynamirt.gllvm.terms.continuous.HSGP(name: str, predictors: str | ~typing.Sequence[str], kernel: ~typing.Literal['Matern', 'ExpSquared'], ell: float | ~typing.Sequence[float], m: int | ~typing.Sequence[int], nu: float = 1.5, group_by: str | None = None, varies_over_variables: bool = True, amplitude: ~dynamirt.gllvm.parameters.Param = Param(prior=1.0, by_group='shared', by_variable='shared'), length: ~dynamirt.gllvm.parameters.Param = Param(prior=<numpyro.distributions.continuous.InverseGamma object at 0x7c31e035f170 with batch shape () and event shape ()>, by_group='shared', by_variable='free'))¶
Bases:
objectHilbert-space approximate Gaussian process term for a gllvm regression.
Replaces the exact kernel matrix with a truncated basis-function expansion following the HSGP method, trading a small approximation error for O(n * m) rather than O(n^3) cost. Supports Matérn and squared-exponential kernels.
- Variables:
name (str) – Sample-site prefix. The GP realisation is stored under a deterministic site with this name.
predictors (str | Sequence[str]) – Covariate name(s) used as GP inputs.
kernel (Literal['Matern', 'ExpSquared']) – Kernel family, either
"Matern"or"ExpSquared".ell (float | Sequence[float]) – Boundary factor(s) for the Laplacian eigenfunctions. A scalar applies to all input dimensions; a sequence specifies per-dimension values.
m (int | Sequence[int]) – Number of basis functions. A scalar applies to all input dimensions; a sequence specifies per-dimension counts.
nu (float) – Smoothness parameter for the Matérn kernel. Ignored when kernel is
"ExpSquared". Defaults to 1.5.group_by (str | None) – Optional covariate name giving a grouping factor. Defaults to None.
varies_over_variables (bool) – If True, an independent GP realisation is drawn for each response variable. Defaults to True.
amplitude (dynamirt.gllvm.parameters.Param) –
Paramfor the kernel amplitude (marginal standard deviation). Defaults to a fixed value of 1.0.length (dynamirt.gllvm.parameters.Param) –
Paramfor the kernel lengthscale. Defaults to InverseGamma(5, 5) sampled independently per variable.
- ell: float | Sequence[float]¶
- group_by: str | None = None¶
- kernel: Literal['Matern', 'ExpSquared']¶
- length: Param = Param(prior=<numpyro.distributions.continuous.InverseGamma object at 0x7c31e035f170 with batch shape () and event shape ()>, by_group='shared', by_variable='free')¶
- m: int | Sequence[int]¶
- name: str¶
- nu: float = 1.5¶
- predictors: str | Sequence[str]¶
- varies_over_variables: bool = True¶
dynamirt.gllvm.terms.discrete module¶
- class dynamirt.gllvm.terms.discrete.AR1(name: str, order_by: str, group_by: str | None = None, varies_over_variables: bool = True, scale: Param = Param(prior=<numpyro.distributions.continuous.HalfNormal object at 0x7c31fbc5dc10 with batch shape () and event shape ()>, by_group='shared', by_variable='shared'), phi: Param = Param(prior=<numpyro.distributions.continuous.Beta object at 0x7c31fbc5cef0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared'))¶
Bases:
objectStationary first-order autoregressive term for a gllvm regression.
The process is initialised at its stationary marginal standard deviation
sigma / sqrt(1 - phi^2)so that variance is constant across time rather than warming up from zero. Assumes equally spaced, fully observed time steps within each group.- Variables:
name (str) – Sample-site prefix. The AR(1) trajectory is stored under a deterministic site with this name.
order_by (str) – Covariate name whose unique sorted values define the time axis.
group_by (str | None) – Optional covariate name giving a grouping factor. An independent process is drawn per level. Defaults to None.
varies_over_variables (bool) – If True, an independent process is drawn for each response variable. Defaults to True.
scale (dynamirt.gllvm.parameters.Param) –
Paramfor the innovation standard deviation sigma. Defaults to HalfNormal(1).phi (dynamirt.gllvm.parameters.Param) –
Paramfor the autoregressive persistence coefficient (correlation between consecutive steps). Defaults to Beta(3, 3), which is symmetric on (0, 1).
- group_by: str | None = None¶
- name: str¶
- order_by: str¶
- phi: Param = Param(prior=<numpyro.distributions.continuous.Beta object at 0x7c31fbc5cef0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared')¶
- scale: Param = Param(prior=<numpyro.distributions.continuous.HalfNormal object at 0x7c31fbc5dc10 with batch shape () and event shape ()>, by_group='shared', by_variable='shared')¶
- varies_over_variables: bool = True¶
- class dynamirt.gllvm.terms.discrete.GRW(name: str, order_by: str, group_by: str | None = None, varies_over_variables: bool = True, scale: Param = Param(prior=<numpyro.distributions.continuous.HalfNormal object at 0x7c31fbc5d0a0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared'))¶
Bases:
objectGaussian random walk term for a gllvm regression.
At each time step the process increments by a Normal(0, sigma) draw. Assumes equally spaced, fully observed time steps within each group.
- Variables:
name (str) – Sample-site prefix. The cumulative walk is stored under a deterministic site with this name.
order_by (str) – Covariate name whose unique sorted values define the time axis.
group_by (str | None) – Optional covariate name giving a grouping factor. An independent walk is drawn per level. Defaults to None.
varies_over_variables (bool) – If True, an independent walk is drawn for each response variable. Defaults to True.
scale (dynamirt.gllvm.parameters.Param) –
Paramfor the innovation standard deviation sigma. Defaults to HalfNormal(1).
- group_by: str | None = None¶
- name: str¶
- order_by: str¶
- scale: Param = Param(prior=<numpyro.distributions.continuous.HalfNormal object at 0x7c31fbc5d0a0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared')¶
- varies_over_variables: bool = True¶
dynamirt.gllvm.terms.linear module¶
- class dynamirt.gllvm.terms.linear.Linear(name: str, predictors: str | ~typing.Sequence[str], group_by: str | None = None, constraint: ~typing.Literal[None, 'reference_coding'] = None, corr: ~typing.Literal[None, 'predictors', 'variables', 'both'] = None, coef: ~dynamirt.gllvm.parameters.Param = Param(prior=<numpyro.distributions.continuous.Normal object at 0x7c32059ca3c0 with batch shape () and event shape ()>, by_group='free', by_variable='free'))¶
Bases:
objectLinear term
X @ coeffor a gllvm regression.Contributes an array of shape (n_obs, n_target) where n_target is the number of response variables (full-rank predictor), the number of latent dimensions (reduced-rank predictor).
- Variables:
name (str) – Sample-site prefix. The assembled coefficient tensor is stored as a deterministic site under this name.
predictors (str | Sequence[str]) – Covariate name or sequence of names to regress on.
group_by (str | None) – Optional covariate name giving a grouping factor. A separate coefficient vector is drawn per level. Defaults to None (single level).
constraint (Literal[None, 'reference_coding']) –
"reference_coding"fixes the first group level’s coefficients to zero. Defaults to None.corr (Literal[None, 'predictors', 'variables', 'both']) – Axis along which to introduce LKJ-Cholesky correlations among coefficients.
"predictors"correlates across covariates,"variables"across response variables or latent dimensions,"both"across both jointly. Defaults to None.coef (dynamirt.gllvm.parameters.Param) –
Paramcontrolling the prior and pooling behaviour of the raw coefficients. Defaults to Normal(0, 1) sampled independently per group and per variable.
- coef: Param = Param(prior=<numpyro.distributions.continuous.Normal object at 0x7c32059ca3c0 with batch shape () and event shape ()>, by_group='free', by_variable='free')¶
- constraint: Literal[None, 'reference_coding'] = None¶
- corr: Literal[None, 'predictors', 'variables', 'both'] = None¶
- group_by: str | None = None¶
- name: str¶
- predictors: str | Sequence[str]¶