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
The point is \((\lambda_1, \dots, \lambda_{10}, \beta)\), and each full conditional is a gamma distribution:
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 thanthreshold, the maximal coupling after; herethresholdis the square root of the trace of the exact covariancepumps.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()
| mean | standard_error | std | q16 | q50 | q84 | |
|---|---|---|---|---|---|---|
| lambda1 | 0.0701318 | 0.000126016 | 0.0269553 | 0.0439759 | 0.0667307 | 0.0961724 |
| lambda2 | 0.154282 | 0.000436854 | 0.0925007 | 0.0679892 | 0.136065 | 0.241116 |
| lambda3 | 0.104245 | 0.000186969 | 0.0399531 | 0.0652147 | 0.0992082 | 0.143217 |
| lambda4 | 0.123194 | 0.000141502 | 0.0310636 | 0.0927151 | 0.120508 | 0.15364 |
| lambda5 | 0.628828 | 0.00141323 | 0.293449 | 0.348201 | 0.584996 | 0.907743 |
| lambda6 | 0.614184 | 0.000636332 | 0.135259 | 0.480299 | 0.604081 | 0.747443 |
| lambda7 | 0.829799 | 0.00282657 | 0.529509 | 0.349682 | 0.711503 | 1.31106 |
| lambda8 | 0.831008 | 0.00274607 | 0.531655 | 0.347722 | 0.71617 | 1.30874 |
| lambda9 | 1.30203 | 0.00309095 | 0.579259 | 0.755743 | 1.21123 | 1.85263 |
| lambda10 | 1.84457 | 0.00193893 | 0.390801 | 1.45978 | 1.8165 | 2.22993 |
| beta | 2.46182 | 0.00459845 | 0.706548 | 1.78064 | 2.37726 | 3.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.