jwspecmcmc.diagnostics

MCMC convergence diagnostics.

Provides Gelman–Rubin R-hat and effective sample size (ESS) for assessing chain convergence.

Functions

effective_sample_size(chains)

Estimate effective sample size (ESS) per parameter via FFT autocorrelation.

gelman_rubin(chains)

Compute the Gelman--Rubin \(\hat{R}\) statistic per parameter.

summarise_convergence(chains)

Compute a convergence summary for MCMC chains.

jwspecmcmc.diagnostics.effective_sample_size(chains)[source]

Estimate effective sample size (ESS) per parameter via FFT autocorrelation.

Parameters:

chains (np.ndarray) – MCMC chains of shape (n_walkers, n_steps, n_dim).

Returns:

ESS per parameter (length n_dim).

Return type:

np.ndarray

jwspecmcmc.diagnostics.gelman_rubin(chains)[source]

Compute the Gelman–Rubin \(\hat{R}\) statistic per parameter.

Parameters:

chains (np.ndarray) – MCMC chains of shape (n_walkers, n_steps, n_dim).

Returns:

\(\hat{R}\) per parameter (length n_dim). Values near 1.0 indicate convergence; values above ~1.05 suggest the chains have not mixed.

Return type:

np.ndarray

jwspecmcmc.diagnostics.summarise_convergence(chains)[source]

Compute a convergence summary for MCMC chains.

Parameters:

chains (np.ndarray) – MCMC chains of shape (n_walkers, n_steps, n_dim).

Returns:

Keys: r_hat (array), ess (array), r_hat_max (float), ess_min (float), converged (bool, True if R-hat < 1.05 and ESS > 100 for all parameters).

Return type:

dict