Skip to content

MCMC Inference

MCMCInference is the high-level inference wrapper for filter-based parameter inference. It wraps your model in an inference context and dispatches to the configured backend (numpyro or blackjax). run() keeps its samples-only return value; call get_diagnostics() afterward for compact sampler-specific diagnostics when supported.

For joint Gaussian random-walk proposals, use AdaptiveMetropolisConfig. Its mean, full covariance, and global multiplier adapt only during warmup. get_diagnostics() reports observed acceptance over retained transitions, the final global multiplier, and the effective proposal covariance in flattened unconstrained coordinates (including numerical diagonal regularization). The coordinate-wise alternative is AdaptiveMWGConfig, whose diagnostics retain one acceptance rate and final proposal scale per coordinate.

MCMCInference

Provides a high-level interface for MCMC inference, consistent between NumPyro and BlackJAX backends.

Models must take in obs_times, obs_values, ctrl_times, ctrl_values as arguments (and optionally, *model_args, **model_kwargs).

Attributes:

Name Type Description
mcmc_config

Sampler configuration dataclass (NUTSConfig, HMCConfig, AdaptiveMetropolisConfig, AdaptiveMWGConfig, SGLDConfig, or MALAConfig).

model

Callable probabilistic model with signature model(obs_times=..., obs_values=..., ctrl_times=..., ctrl_values=..., *model_args, **model_kwargs).

get_diagnostics() -> dict[str, jax.Array]

Return compact diagnostics from the most recent successful run.

NUTS reports mean_acceptance_rate and num_divergences per chain. Adaptive MWG reports mean_acceptance_rate and final_proposal_scale per chain and unconstrained coordinate. Joint Adaptive Metropolis reports observed mean_acceptance_rate and final_global_scale per chain, plus final_proposal_covariance with shape (num_chains, d, d) in unconstrained coordinates. Adaptive sampler acceptance rates exclude warmup; the joint covariance includes the global multiplier and numerical diagonal regularization.

Raises:

Type Description
RuntimeError

If inference has not completed successfully.

run(rng_key: jnp.ndarray, obs_times: jnp.ndarray, obs_values: jnp.ndarray, ctrl_times: jnp.ndarray | None = None, ctrl_values: jnp.ndarray | None = None, *model_args, **model_kwargs) -> dict

Run inference and return posterior samples.

Parameters:

Name Type Description Default
rng_key ndarray

JAX PRNG key.

required
obs_times ndarray

Observation times.

required
obs_values ndarray

Observation values.

required
ctrl_times ndarray | None

Control times.

None
ctrl_values ndarray | None

Control values.

None
*model_args

Additional positional arguments passed to model.

()
**model_kwargs

Additional keyword arguments passed to model.

{}

Returns:

Type Description
dict

Dict-like pytree of posterior samples.