Diagnostics¶
Convergence diagnostics for MCMC chains. All functions operate on raw
np.ndarray sample arrays (shape (n_samples, n_params)) and are also
exposed as methods on :class:~mcmckit.core.result.Result.
Tip
For multi-chain workflows use :class:~mcmckit.core.multichain.MultiChainResult
which calls these functions internally and formats the results as a table.
ess¶
ess ¶
Effective sample size (ESS) per parameter.
Uses Geyer's (1992) initial positive sequence estimator: accumulate pairs of autocorrelations as long as their sum is positive. This avoids the noise blow-up of naively summing all lags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
(ndarray, shape(n_samples, n_params))
|
|
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(n_params))
|
ESS for each parameter, capped at n_samples. |
References
Geyer, C. J. (1992). Practical Markov Chain Monte Carlo. Statistical Science, 7(4), 473–483.
Source code in mcmckit/core/diagnostics.py
autocorr¶
autocorr ¶
Normalised autocorrelation function for each parameter.
Computed via FFT for efficiency (O(N log N) per parameter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
(ndarray, shape(n_samples, n_params))
|
|
required |
max_lag
|
int
|
Maximum lag to return. Clipped to n_samples - 1. |
100
|
Returns:
| Type | Description |
|---|---|
(ndarray, shape(max_lag + 1, n_params))
|
|
Source code in mcmckit/core/diagnostics.py
gelman_rubin¶
gelman_rubin ¶
Split-chain Gelman-Rubin :math:\hat{R} statistic.
Each chain is split in half before computing :math:\hat{R}, which
allows detection of non-stationarity within a single chain.
Values close to 1.0 indicate convergence; a common threshold is
:math:\hat{R} < 1.01 (strict) or :math:< 1.1 (permissive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chains
|
list of np.ndarray, each shape (n_samples, n_params)
|
Or a list of :class: |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(n_params))
|
:math: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 2 chains are provided or chains are too short to split. |
References
Gelman, A., & Rubin, D. B. (1992). Inference from iterative simulation using multiple sequences. Statistical Science, 7(4), 457–472.
Vehtari, A., et al. (2021). Rank-normalization, folding, and localization: An improved Rhat for assessing convergence of MCMC. Bayesian Analysis, 16(2), 667–718.
Source code in mcmckit/core/diagnostics.py
convergence_summary¶
convergence_summary ¶
Compute R-hat and per-chain ESS, return a summary dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chains
|
list of Result or np.ndarray
|
|
required |
threshold_rhat
|
float
|
Warn if any R-hat exceeds this value. Default 1.01. |
1.01
|
Returns:
| Type | Description |
|---|---|
dict with keys ``rhat`` (array), ``ess`` (list of arrays),
|
|
``converged`` (bool), ``warnings`` (list of str).
|
|