Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

MEADS: Ensemble Adaptation for GHMC

MEADS (Maximum-Eigenvalue Adaptation of Damping and Stepsize; Hoffman & Sountsov, 2022) is an adaptation scheme for Generalized HMC (GHMC). Unlike standard HMC tuners that rely on a single chain’s history, MEADS uses an ensemble of parallel chains to estimate the posterior’s gradient covariance at each adaptation step, and from it automatically sets the step size ε\varepsilon, the per-parameter momentum scale Σ−1/2\Sigma^{-1/2}, and the momentum persistence α\alpha.

The key formula: ε∝λmax⁡−1/2\varepsilon \propto \lambda_{\max}^{-1/2} where λmax⁡\lambda_{\max} is estimated from the matrix of scaled gradients across all chains. MEADS uses a k-fold update (Algorithm 3 of the paper) — chains are split into KK groups, and each group’s parameters are estimated from the other K−1K-1 groups to avoid information leakage.

Initialization. MEADS estimates geometry from the current spread of chains. When chains start far from the posterior (e.g. initialised from the prior of a model with many observations), the scaled gradients are enormous and λmax⁡≈105\lambda_{\max} \approx 10^5, giving a near-zero step size that freezes all chains. We address this with a lightweight two-step approach: (1) run a single NUTS chain for a brief warmup to reach the typical set, then collect 100–200 samples; (2) sample the last few positions from this trajectory and add small Uniform(−1,1)\mathrm{Uniform}(-1, 1) jitter in unconstrained space to generate the ensemble starting positions. This requires only a single short NUTS run — no per-chain warmup — and gives the ensemble the diversity MEADS needs to estimate geometry.

Notebook Cell

Item Response Theory

The 2-parameter logistic (2PL) IRT model describes the probability that student ii answers item jj correctly as

P(correctij)=σ ⁣(aj (θi−bj)),P(\text{correct}_{ij}) = \sigma\!\left(a_j\,(\theta_i - b_j)\right),

where θi\theta_i is student ability, bjb_j is item difficulty, and aj>0a_j > 0 is item discrimination. Priors:

θi∼N(0,1),bj∼N(0,1),aj∼N+(0,1).\theta_i \sim \mathcal{N}(0,1), \qquad b_j \sim \mathcal{N}(0,1), \qquad a_j \sim \mathcal{N}^+(0,1).

With 100 students and 30 items this is a 230-dimensional posterior — a good showcase for ensemble-based adaptation where per-parameter mass-matrix tuning matters.

Synthetic data

Response matrix (100, 30),  mean correct: 0.56

Model

Why naive initialization fails

Before running the full pipeline, it is instructive to check what step size MEADS would choose from a naive prior-based initialization versus one obtained via the trajectory-spread approach.

Prior init:   λ_max = 178,924   →  step_size ≈ 0.00118
Spread init:  λ_max = 9787.34   →  step_size ≈ 0.0051

The contrast is stark: prior init gives λmax⁡≈105\lambda_{\max} \approx 10^5 and ε≈0.001\varepsilon \approx 0.001; after the trajectory spread λmax⁡≈1–10\lambda_{\max} \approx 1\text{–}10 and ε≈0.2–0.5\varepsilon \approx 0.2\text{–}0.5 — near-optimal for a unit-scale posterior. MEADS then adapts the full diagonal mass matrix and momentum persistence automatically from there.

Sampling

Runtime: 0 days 00:00:15.742630
MEADS step_size: 0.231   alpha: 0.292

                  mean       std    median      5.0%     95.0%     n_eff     r_hat
theta[:5][0]     -1.30      0.41     -1.29     -2.00     -0.65   2370.06      1.03
theta[:5][1]     -0.07      0.36     -0.07     -0.67      0.53   2767.83      1.02
theta[:5][2]     -0.92      0.38     -0.91     -1.55     -0.30   3028.82      1.03
theta[:5][3]      1.21      0.47      1.19      0.43      1.95   3691.18      1.01
theta[:5][4]     -0.14      0.36     -0.14     -0.75      0.42   2960.24      1.02
    b[:5][0]     -1.05      0.53     -1.01     -1.91     -0.22   2928.72      1.02
    b[:5][1]      0.42      0.21      0.42      0.09      0.76   1257.38      1.05
    b[:5][2]     -0.41      0.52     -0.38     -1.25      0.41   1838.77      1.03
    b[:5][3]      0.11      0.85      0.12     -1.30      1.47   3238.31      1.02
    b[:5][4]      1.60      0.31      1.56      1.12      2.09   1678.04      1.04
    a[:5][0]     -0.93      0.50     -0.85     -1.60     -0.20   1774.23      1.04
    a[:5][1]      0.33      0.25      0.35     -0.07      0.75   2408.66      1.02
    a[:5][2]     -0.96      0.62     -0.85     -1.80     -0.10    635.60      1.06
    a[:5][3]     -2.50      1.12     -2.28     -4.15     -0.83   3328.53      1.02
    a[:5][4]      0.37      0.27      0.38     -0.06      0.80   1845.25      1.03

<Figure size 1200x400 with 3 Axes>

Radon hierarchical model

The radon dataset (Gelman & Hill, 2007) records basement and first-floor radon measurements in homes grouped by county. We fit a partial-pooling model:

μα∼N(0,1),σα∼C+(1)αc∼N(μα, σα),c=1,…,Cβ∼N(0,1),σy∼C+(1)log⁡ri∼N(αci+β floori,  σy)\begin{split} \mu_\alpha &\sim \mathcal{N}(0, 1), \qquad \sigma_\alpha \sim \mathcal{C}^+(1) \\ \alpha_c &\sim \mathcal{N}(\mu_\alpha,\, \sigma_\alpha), \quad c = 1,\ldots,C \\ \beta &\sim \mathcal{N}(0, 1), \qquad \sigma_y \sim \mathcal{C}^+(1) \\ \log r_i &\sim \mathcal{N}(\alpha_{c_i} + \beta\,\text{floor}_i,\; \sigma_y) \end{split}

Synthetic data

874 observations, 85 counties

Model

Sampling

Runtime: 0 days 00:00:19.900053
MEADS step_size: 0.362   alpha: 0.478

                   mean       std    median      5.0%     95.0%     n_eff     r_hat
         beta     -0.71      0.04     -0.71     -0.77     -0.64   4080.58      1.01
     mu_alpha      1.27      0.05      1.27      1.18      1.35   3789.67      1.02
  sigma_alpha     -0.84      0.09     -0.85     -0.99     -0.70   3659.72      1.02
      sigma_y     -0.71      0.03     -0.71     -0.75     -0.67   4530.16      1.01

<Figure size 1000x400 with 2 Axes>
<Figure size 1200x400 with 1 Axes>