Gibbs couplings: the pump-failure model

A Gibbs sampler updates blocks of coordinates in turn, each by a draw from its full conditional distribution given the others. telescopic.kernels.Gibbs couples two such samplers block by block. This tutorial runs it on the pump-failure model of Jacob, O’Leary & Atchadé (2020, §5.2), whose exact posterior moments telescopic.examples.pumps() provides.

The model

Pump \(i\) of 10 failed \(s_i\) times in \(t_i\) thousand hours, with

\[s_i \sim \mathrm{Poisson}(\lambda_i t_i), \qquad \lambda_i \sim \mathrm{Gamma}(1.802, \text{rate } \beta), \qquad \beta \sim \mathrm{Gamma}(0.01, \text{rate } 1).\]

The point is \((\lambda_1, \dots, \lambda_{10}, \beta)\), and each full conditional is a gamma distribution:

\[\lambda_i \mid \beta \sim \mathrm{Gamma}(1.802 + s_i, \text{rate } \beta + t_i), \qquad \beta \mid \lambda \sim \mathrm{Gamma}\Big(0.01 + 10 \times 1.802, \text{rate } 1 + \sum_i \lambda_i\Big).\]

pumps.conditional(x, b) returns the conditional of block b given the other coordinates of the point x, as a small object with rvs, logpdf and ppf, quicker to build than a frozen SciPy distribution (Kernels). pumps.blocks lists the 11 blocks, one coordinate each. A Gibbs kernel never evaluates the log-density, so the sampler gets log_prob=None. The pairs start from pumps.initial, uniform on \((0.001, 5)\) in each coordinate.

Three couplings

The kernels guide defines the three couplings of Gibbs:

  • "maximal", the default: the rejection maximal coupling of each block’s two conditionals;

  • "crn": common random numbers, here one uniform through both conditionals’ ppf;

  • "two-scale": common random numbers while the chains are farther apart than threshold, the maximal coupling after; here threshold is the square root of the trace of the exact covariance pumps.cov.

telescopic.CoupledSampler.meeting_times() runs pilot pairs with lag 1 and returns their meeting times, counted in sweeps. With one seed for the three couplings, their pairs start from the same points:

import numpy as np

import telescopic
from telescopic import examples
from telescopic.kernels import Gibbs

pumps = examples.pumps()
kernels = {
    "maximal": Gibbs(pumps.conditional, pumps.blocks),
    "crn": Gibbs(pumps.conditional, pumps.blocks, coupling="crn"),
    "two-scale": Gibbs(
        pumps.conditional,
        pumps.blocks,
        coupling="two-scale",
        threshold=np.sqrt(np.trace(pumps.cov)),
    ),
}
tau = {}
for coupling, kernel in kernels.items():
    sampler = telescopic.CoupledSampler(None, pumps.initial, kernel=kernel, rng=1)
    tau[coupling] = sampler.meeting_times(200)
    median, slowest = np.median(tau[coupling]), np.max(tau[coupling])
    print(f"{coupling:9}  median {median:3.0f}  max {slowest:3.0f}")
maximal    median   3  max   7
crn        median  34  max  38
two-scale  median   3  max   9

The maximal coupling makes the pairs meet within a few sweeps. Common random numbers make them meet too, but later: the distance between the chains shrinks at every sweep until it reaches the rounding error of float64, where the two chains’ arithmetic gives the same numbers. The two-scale coupling meets about as fast as the maximal one: on this model the maximal coupling succeeds even from distant starts, which leaves the switch little to gain. The two-scale coupling is meant for targets where maximal couplings of distant chains rarely succeed.

Estimates against the exact posterior

A run of 1000 replicates with the maximal coupling:

names = [f"lambda{i}" for i in range(1, 11)] + ["beta"]
result = telescopic.sample(
    None, pumps.initial, 1000, kernel=kernels["maximal"], names=names, rng=2
)
result.summary()
meanstandard_errorstdq16q50q84
lambda10.07013180.0001260160.02695530.04397590.06673070.0961724
lambda20.1542820.0004368540.09250070.06798920.1360650.241116
lambda30.1042450.0001869690.03995310.06521470.09920820.143217
lambda40.1231940.0001415020.03106360.09271510.1205080.15364
lambda50.6288280.001413230.2934490.3482010.5849960.907743
lambda60.6141840.0006363320.1352590.4802990.6040810.747443
lambda70.8297990.002826570.5295090.3496820.7115031.31106
lambda80.8310080.002746070.5316550.3477220.716171.30874
lambda91.302030.003090950.5792590.7557431.211231.85263
lambda101.844570.001938930.3908011.459781.81652.22993
beta2.461820.004598450.7065481.780642.377263.13625
  • R = 1000, k = 5, m = 50, lag = 5, thin = 1
  • kernel: Gibbs(_pump_conditional, 11 blocks, coupling='maximal', eta=1.0, threshold=None)
  • meeting times: median 7, 90% 8, 99% 11, max 12; censored 0
  • tail index of the meeting times: 4.17
  • cost per replicate: 52.01 kernel applications, 0.00141 s; relative cost 1.13
  • pairs meeting after k + lag: 1.2% (at most 1.9% at 95%)
  • largest share of one replicate in a variance: 5%, for the variance of lambda5

The estimated posterior means against the exact ones, and their differences in standard errors:

mean = result.mean()
z = (mean.value - pumps.mean) / mean.standard_error
print("            exact  estimate  standard error      z")
for name, exact, value, error, score in zip(
    names, pumps.mean, mean.value, mean.standard_error, z
):
    print(f"{name:9}  {exact:7.4g}  {value:8.4g}  {error:14.2g}  {score:5.2f}")
            exact  estimate  standard error      z
lambda1    0.07028   0.07013         0.00013  -1.16
lambda2     0.1543    0.1543         0.00044   0.06
lambda3     0.1041    0.1042         0.00019   0.80
lambda4     0.1232    0.1232         0.00014  -0.28
lambda5     0.6278    0.6288          0.0014   0.73
lambda6     0.6137    0.6142         0.00064   0.79
lambda7     0.8275    0.8298          0.0028   0.80
lambda8     0.8275     0.831          0.0027   1.26
lambda9      1.299     1.302          0.0031   1.04
lambda10     1.843     1.845          0.0019   0.74
beta         2.472     2.462          0.0046  -2.21

The differences are of the size of their standard errors. The number beyond 2 is 1 of 11, where about one in twenty is expected.