Monte Carlo methods for Bayesian inference: a from-scratch Metropolis–Hastings test of dark energy evolution.
A hand-written Metropolis–Hastings sampler is used to fit the cosmic expansion
rate
Fitting ΛCDM to 36 cosmic-chronometer + BAO
| Parameter | Posterior (mean ± 1σ) |
|---|---|
| 71.9 ± 1.4 km s⁻¹ Mpc⁻¹ | |
| 0.229 ± 0.010 | |
| 0.68 |
Sampling used 16 chains; all parameters converged (Gelman–Rubin
Comparing ΛCDM against the CPL (
| Model | k | χ²/dof | AIC | BIC | ΔBIC |
|---|---|---|---|---|---|
| ΛCDM | 2 | 0.68 | 26.98 | 30.15 | 0.00 |
| CPL | 4 | 0.63 | 28.11 | 34.44 | +4.29 |
CPL lowers
-
Data — 36 cosmic-chronometer and BAO
$H(z)$ points,data/hubble_cosmic_chronometers.txt. -
Sampler — random-walk Metropolis–Hastings written from scratch
(
src/mcmc/sampler.py), in log-likelihood space for numerical stability, with burn-in, acceptance tracking, and uniform-prior bounds. CPL's degenerate posterior is sampled with a preconditioned proposal (covariance estimated from a pilot run). -
Convergence — many-chain Gelman–Rubin
$\hat{R}$ (with running-$\hat{R}$ and trace diagnostics). -
Model selection — best-fit
$\chi^2$ , AIC and BIC (src/mcmc/inference.py).
src/mcmc/ # reusable package
├── models.py # ΛCDM, CPL (w0-wa) H(z) models
├── inference.py # chi², likelihood, best-fit, AIC/BIC
├── sampler.py # Metropolis–Hastings, multi-chain, Gelman–Rubin
└── plotting.py # traces, R-hat, H(z) band, credible-region marginals
data/ # H(z) measurements
figures/ # generated figures
tests/ # unit tests for the sampler and inference
main.ipynb # narrated end-to-end demonstration
pip install -r requirements.txt
python -m pytest tests/ # run the unit tests
jupyter notebook main.ipynbYu, H., Ratra, B., & Wang, F. Y. (2018). Hubble parameter and Baryon Acoustic Oscillation measurement constraints on the Hubble constant, the deviation from the spatially flat ΛCDM model, the deceleration–acceleration transition redshift, and spatial curvature. The Astrophysical Journal, 856(1), 3.
