dynamirt package¶
Subpackages¶
Submodules¶
dynamirt.api module¶
- dynamirt.api.dynamirt(model_type: Literal['1PL', '2PL', '3PL', '4PL', 'GRM', 'PCM', 'GPCM'] = '2PL', n_latent: int = 1, loadings: Callable | None = None, latent_fn: Sequence[Callable] | None = None, DIF: Sequence[Callable] | None = None, include_residuals: bool | None = None, corr: bool = True, model_type_kwargs: dict | None = None) Callable¶
Build a MIRT model with optionally time evolving latent traits.
- Parameters:
model_type – IRT response family. Dichotomous options:
"1PL","2PL","3PL","4PL". Polytomous options:"GRM"(graded response model),"PCM"(partial credit model),"GPCM"(generalised partial credit model). Defaults to"2PL".n_latent – Dimensionality of the latent trait space. Defaults to 1.
loadings – Loading-matrix factory (e.g.
Fixed(),Full(),Confirmatory(Q)). Defaults toFull()(unconstrained), except for"1PL"and"PCM"where it is forced toFixed().latent_fn – Sequence of latent-regression term callables (e.g. time-series terms, covariate effects on theta). If None and
include_residualsis not explicitly False, an i.i.d. residual term is added automatically.DIF – Sequence of full-rank regression term callables added alongside the item intercepts to model differential item functioning. Defaults to None.
include_residuals – Whether to append an i.i.d. residual latent term. Defaults to True when
latent_fnis None, False otherwise.corr – If True and residuals are included, an LKJ-Cholesky correlation structure is estimated across latent dimensions. Defaults to True.
model_type_kwargs – Extra keyword arguments forwarded to the IRT family constructor for model_type.
- Returns:
A numpyro function with signature
model(responses, covariates, ...)ready for use withfit_mcmcorfit_svi.- Raises:
ValueError – If
loadingsis provided for"1PL"or"PCM"(these fix all loadings to 1).ValueError – If no latent terms would be active (both
latent_fnandinclude_residualsare empty/False).ValueError – If
model_typeis not recognised.
dynamirt.fit module¶
- dynamirt.fit.fit_mcmc(model: ~typing.Callable, responses: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex, covariates: ~typing.Mapping[str, ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex], kernel_class: type[~numpyro.infer.mcmc.MCMCKernel] = <class 'numpyro.infer.hmc.NUTS'>, kernel_kwargs: dict | None = None, mcmc_kwargs: dict | None = None, rng_key: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex | None = None) tuple[DataTree, MCMC]¶
Run MCMC inference on a NumPyro model and return an xarray.DataTree.
- Parameters:
model – A NumPyro model function with signature
model(responses, covariates, ...).responses – Observation matrix passed to the model.
covariates – Covariate mapping passed to the model.
kernel_class – MCMC kernel class. Defaults to
NUTS.kernel_kwargs – Extra keyword arguments forwarded to the kernel constructor. Defaults to an empty dict.
mcmc_kwargs – Keyword arguments forwarded to
MCMC. Defaults to{"num_warmup": 1500, "num_samples": 500, "num_chains": 4}.rng_key – JAX PRNG key. Defaults to
PRNGKey(0).
- Returns:
A tuple (idata, mcmc) where idata is an
arviz.InferenceDataobject and mcmc is the fittednumpyro.infer.MCMCinstance.
- dynamirt.fit.fit_svi(model: ~typing.Callable, responses: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex, covariates: ~typing.Mapping[str, ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex], guide_class: type[~numpyro.infer.autoguide.AutoGuide] = <class 'numpyro.infer.autoguide.AutoNormal'>, guide_kwargs: dict | None = None, optim_kwargs: dict | None = None, run_kwargs: dict | None = None, rng_key: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex | None = None, num_samples: int = 500) tuple[DataTree, AutoGuide, SVIRunResult]¶
Run stochastic variational inference (SVI) on a NumPyro model.
After optimisation, draws posterior samples from the fitted guide and packages them into an xarray.DataTree.
- Parameters:
model – A NumPyro model function with signature
model(responses, covariates, ...).responses – Observation matrix passed to the model.
covariates – Covariate mapping passed to the model.
guide_class – Autoguide class used to construct the variational family. Defaults to
AutoNormal.guide_kwargs – Extra keyword arguments forwarded to the guide constructor. Defaults to an empty dict.
optim_kwargs – Keyword arguments forwarded to the
Adamoptimiser. Defaults to{"step_size": 1e-4}.run_kwargs – Keyword arguments controlling the SVI run. Must contain
"num_steps". Defaults to{"num_steps": 5000}.rng_key – JAX PRNG key. Defaults to
jax.random.key(0).num_samples – Number of posterior samples drawn from the fitted guide for the returned InferenceData. Defaults to 500.
- Returns:
A tuple (idata, guide, svi_result) where idata is an
arviz.InferenceDataobject, guide is the fitted autoguide instance, and svi_result is theSVIRunResultreturned bysvi.run.
dynamirt.loadings module¶
dynamirt.terms module¶
Module contents¶
- class dynamirt.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¶
- dynamirt.Confirmatory(Q: Array | ndarray | bool | number | bool | int | float | complex, positive_anchors: Array | ndarray | bool | number | bool | int | float | complex = None, free_prior: Distribution | None = None, positive_prior: Distribution | None = None) Callable¶
Loading matrix factory for confirmatory factor analysis.
- Parameters:
Q – Binary (n_var, n_latent) array. Q[i, j] = 1 means item i is allowed to load on factor j; 0 means the loading is fixed at 0.
positive_anchors – Optional binary array of the same shape as Q. Marks a subset of Q’s nonzero entries as positive-only anchor loadings. If None, all free loadings are unconstrained in sign. Defaults to None.
free_prior – Prior distribution for the unconstrained loadings. Defaults to Normal(0, 1) if None.
positive_prior – Prior distribution for the positive anchor loadings. Defaults to LogNormal(0, 0.5) if None.
- Returns:
A loadings(ctx) function that returns the (n_var, n_latent) loading matrix
- class dynamirt.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¶
- dynamirt.Fixed() Callable¶
Loading matrix factory that fixes all loadings to 1 so every item loads equally on every latent factor.
- Returns:
A loadings(ctx) function that returns a (n_var, n_latent) array of ones.
- dynamirt.Full(prior: Distribution | None = None) Callable¶
Loading matrix factory with all loadings drawn from prior. For the default Normal(0, 1) this results in an unconstrained loading matrix and is equivalent to Confirmatory with Q of all ones and no positive anchors and will lead to rotational and signed-permutation invariances in most cases.
- Parameters:
prior – Prior distribution for each loading. Defaults to Normal(0, 1).
- Returns:
A loadings(ctx) function that returns a (n_var, n_latent) array sampled entrywise from prior.
- class dynamirt.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¶
- class dynamirt.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¶
- class dynamirt.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]¶
- class dynamirt.Param(prior: Distribution | float, by_group: Literal['shared', 'free'] | Pool = 'shared', by_variable: Literal['shared', 'free'] | Pool = 'shared')¶
Bases:
objectBroadcastable parameter with optional non-centered partial pooling.
Wraps a scalar constant or a prior distribution and manages its expansion along the group and variable/latent axes of a term. When either axis is set to a
Poolinstance, a non-centered parameterisation is used: a shared hyper-mean and hyper-scale are sampled, and the raw draw is shifted and scaled accordingly.- Variables:
prior (numpyro.distributions.distribution.Distribution | float) – Either a fixed scalar value (no sampling) or a
numpyro.distributions.Distributionused as the prior.by_group (Literal['shared', 'free'] | dynamirt.gllvm.parameters.Pool) –
"shared"broadcasts a single value across groups,"free"samples independently per group, and aPoolinstance applies non-centered partial pooling across groups. Defaults to"shared".by_variable (Literal['shared', 'free'] | dynamirt.gllvm.parameters.Pool) – Same as by_group but along the variable/latent axis. Defaults to
"shared".
- apply_partial_pooling(name, raw, n_groups, n_target, trailing=())¶
- prior: Distribution | float¶
- sample_raw(name, n_groups, n_target, trailing=())¶
- class dynamirt.Pool(loc: Param = Param(prior=<numpyro.distributions.continuous.Normal object at 0x7c32059c9af0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared'), scale: Param = Param(prior=<numpyro.distributions.continuous.HalfNormal object at 0x7c32059c9eb0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared'), transform: Transform = <factory>)¶
Bases:
objectHyperparameters for non-centered partial pooling in
Param.- Variables:
loc (dynamirt.gllvm.parameters.Param) –
Paramfor the hyper-mean. Defaults to Normal(0, 1).scale (dynamirt.gllvm.parameters.Param) –
Paramfor the hyper-scale. Defaults to HalfNormal(0.5).transform (numpyro.distributions.transforms.Transform) – Bijective transform applied after the affine
loc + scale * rawstep (e.g.ExpTransformto constrain the result to be positive). Defaults to the identity transform.
- loc: Param = Param(prior=<numpyro.distributions.continuous.Normal object at 0x7c32059c9af0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared')¶
- scale: Param = Param(prior=<numpyro.distributions.continuous.HalfNormal object at 0x7c32059c9eb0 with batch shape () and event shape ()>, by_group='shared', by_variable='shared')¶
- transform: Transform¶
- dynamirt.Sparsity(tau0=1.0, slab_scale: float = 1.0, slab_df: float = 4.0) Callable¶
Loading matrix factory with regularized horseshoe sparsity prior.
Applies the regularised horseshoe prior of Piironen & Vehtari (2017) to the loading matrix, encouraging most loadings toward zero while allowing a sparse subset to remain large.
- Reference:
Juho Piironen. Aki Vehtari (2017). Electron. J. Statist. 11 (2) 5018 - 5051 https://doi.org/10.1214/17-EJS1337SI
- Parameters:
tau0 – Global shrinkage scale. A sensible default follows Eq. 3.12:
p0 / (D - p0) * sigma / sqrt(n)where p0 is the expected number of non-zero loadings and D is the total number of loadings. Defaults to 1.0.slab_scale – Typical magnitude of a loading that escapes shrinkage. Controls the width of the regularising slab. Defaults to 1.0.
slab_df – Degrees of freedom of the Student-t slab controlling how heavy-tailed the non-zero loadings may be. Defaults to 4.0.
- Returns:
A loadings(ctx) function that returns the (n_var, n_latent) loading matrix
- dynamirt.dynamirt(model_type: Literal['1PL', '2PL', '3PL', '4PL', 'GRM', 'PCM', 'GPCM'] = '2PL', n_latent: int = 1, loadings: Callable | None = None, latent_fn: Sequence[Callable] | None = None, DIF: Sequence[Callable] | None = None, include_residuals: bool | None = None, corr: bool = True, model_type_kwargs: dict | None = None) Callable¶
Build a MIRT model with optionally time evolving latent traits.
- Parameters:
model_type – IRT response family. Dichotomous options:
"1PL","2PL","3PL","4PL". Polytomous options:"GRM"(graded response model),"PCM"(partial credit model),"GPCM"(generalised partial credit model). Defaults to"2PL".n_latent – Dimensionality of the latent trait space. Defaults to 1.
loadings – Loading-matrix factory (e.g.
Fixed(),Full(),Confirmatory(Q)). Defaults toFull()(unconstrained), except for"1PL"and"PCM"where it is forced toFixed().latent_fn – Sequence of latent-regression term callables (e.g. time-series terms, covariate effects on theta). If None and
include_residualsis not explicitly False, an i.i.d. residual term is added automatically.DIF – Sequence of full-rank regression term callables added alongside the item intercepts to model differential item functioning. Defaults to None.
include_residuals – Whether to append an i.i.d. residual latent term. Defaults to True when
latent_fnis None, False otherwise.corr – If True and residuals are included, an LKJ-Cholesky correlation structure is estimated across latent dimensions. Defaults to True.
model_type_kwargs – Extra keyword arguments forwarded to the IRT family constructor for model_type.
- Returns:
A numpyro function with signature
model(responses, covariates, ...)ready for use withfit_mcmcorfit_svi.- Raises:
ValueError – If
loadingsis provided for"1PL"or"PCM"(these fix all loadings to 1).ValueError – If no latent terms would be active (both
latent_fnandinclude_residualsare empty/False).ValueError – If
model_typeis not recognised.
- dynamirt.fit_mcmc(model: ~typing.Callable, responses: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex, covariates: ~typing.Mapping[str, ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex], kernel_class: type[~numpyro.infer.mcmc.MCMCKernel] = <class 'numpyro.infer.hmc.NUTS'>, kernel_kwargs: dict | None = None, mcmc_kwargs: dict | None = None, rng_key: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex | None = None) tuple[DataTree, MCMC]¶
Run MCMC inference on a NumPyro model and return an xarray.DataTree.
- Parameters:
model – A NumPyro model function with signature
model(responses, covariates, ...).responses – Observation matrix passed to the model.
covariates – Covariate mapping passed to the model.
kernel_class – MCMC kernel class. Defaults to
NUTS.kernel_kwargs – Extra keyword arguments forwarded to the kernel constructor. Defaults to an empty dict.
mcmc_kwargs – Keyword arguments forwarded to
MCMC. Defaults to{"num_warmup": 1500, "num_samples": 500, "num_chains": 4}.rng_key – JAX PRNG key. Defaults to
PRNGKey(0).
- Returns:
A tuple (idata, mcmc) where idata is an
arviz.InferenceDataobject and mcmc is the fittednumpyro.infer.MCMCinstance.
- dynamirt.fit_svi(model: ~typing.Callable, responses: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex, covariates: ~typing.Mapping[str, ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex], guide_class: type[~numpyro.infer.autoguide.AutoGuide] = <class 'numpyro.infer.autoguide.AutoNormal'>, guide_kwargs: dict | None = None, optim_kwargs: dict | None = None, run_kwargs: dict | None = None, rng_key: ~jax.Array | ~numpy.ndarray | ~numpy.bool | ~numpy.number | bool | int | float | complex | None = None, num_samples: int = 500) tuple[DataTree, AutoGuide, SVIRunResult]¶
Run stochastic variational inference (SVI) on a NumPyro model.
After optimisation, draws posterior samples from the fitted guide and packages them into an xarray.DataTree.
- Parameters:
model – A NumPyro model function with signature
model(responses, covariates, ...).responses – Observation matrix passed to the model.
covariates – Covariate mapping passed to the model.
guide_class – Autoguide class used to construct the variational family. Defaults to
AutoNormal.guide_kwargs – Extra keyword arguments forwarded to the guide constructor. Defaults to an empty dict.
optim_kwargs – Keyword arguments forwarded to the
Adamoptimiser. Defaults to{"step_size": 1e-4}.run_kwargs – Keyword arguments controlling the SVI run. Must contain
"num_steps". Defaults to{"num_steps": 5000}.rng_key – JAX PRNG key. Defaults to
jax.random.key(0).num_samples – Number of posterior samples drawn from the fitted guide for the returned InferenceData. Defaults to 500.
- Returns:
A tuple (idata, guide, svi_result) where idata is an
arviz.InferenceDataobject, guide is the fitted autoguide instance, and svi_result is theSVIRunResultreturned bysvi.run.