telescopic.couplings

Couplings of pairs of distributions: the primitives that coupled kernels build on.

Classes

CoupledProposals

The coupled proposals of n pairs of chains, with what each proposal's ratio needs.

Coupling

A coupling of the proposals of two chains under one proposal.

Maximal

The rejection maximal coupling of two random-walk proposals.

Reflection

The reflection-maximal coupling of two Gaussian proposals with a shared covariance.

Shared

The coupling of two independence proposals that gives both chains one proposal.

telescopic.couplings.discrete_maximal(log_p, log_q, draws)

Maximal coupling of two distributions on \(\{0, \dots, K-1\}\), row by row.

With probability \(\alpha = \sum_k \min(p_k, q_k)\) both indices are drawn from \(\min(p, q)/\alpha\); otherwise they are drawn independently from the normalized residuals \(p - \min(p, q)\) and \(q - \min(p, q)\), whose supports are disjoint (Jacob, O’Leary & Atchadé 2020, section 5.4). So \(P(i = j) = \alpha = 1 - \mathrm{TV}(p, q)\).

Parameters:
log_p, log_qndarray, shape (n, K)

Log-probabilities, normalized or not; each row needs a finite maximum and no NaN.

drawsDraws

Random numbers for the n rows; each row uses 3 uniforms.

Returns:
i, jndarray of int, shape (n,)

The coupled indices.

telescopic.couplings.maximal(p, q, draws, eta=1.0)

Rejection maximal coupling of the distributions p[i] and q[i] of each row.

Draw \(X \sim p\); the pair is identical with probability \(\min(\eta, q(X)/p(X))\). Otherwise draw \(Y \sim q\) until \(u > \eta\,p(Y)/q(Y)\) (Thorisson’s algorithm, Jacob, O’Leary & Atchadé 2020 Algorithm 2; with \(\eta < 1\), the bounded-variance version of Gerber & Lee 2020, Atchadé & Jacob 2024 Algorithm 2). The meeting probability is \(\int\min(\eta p, q)\) over the draws whose log-densities are finite, maximal at \(\eta = 1\); the number of draws from p and q has mean 2 and variance at most \(2\eta/(1-\eta)\).

Where either log-density of a draw is infinite, the pair is not identical and the loop accepts the draw. Such a draw, as one that underflowed to the edge of its support, stands for the mass of an interval whose ratio of densities is unknown, and each chain keeps its sampler’s law. Such draws can be frequent: a third of Beta(0.01, 0.01)’s are 1.0, its mass within \(2^{-53}\) of 1, where the pair is not identical even for \(p = q\), though its draws can be equal.

Parameters:
p, qlist of distributions, length n

Objects with rvs(random_state=...) and a normalized logpdf (or logpmf), such as frozen SciPy distributions. All draws have the same shape. Values of logpdf for the coordinates of a draw are summed, as the joint log-density of independent coordinates; NaN raises ValueError.

drawsDraws

Random numbers for the n rows; each row draws from its own generator.

etafloat

Cap on the meeting probability, in (0, 1].

Returns:
x, yndarray, shape (n, …)

The coupled draws; on identical rows y is a copy of x.

identicalndarray of bool, shape (n,)
n_drawsndarray of int, shape (n,)

Draws from p and q used by each row.

telescopic.couplings.reflection_maximal(mu_x, mu_y, chol, inverse, draws, *, blas=False)

Reflection-maximal coupling of \(\mathcal N(\mu_x, CC^\top)\) and \(\mathcal N(\mu_y, CC^\top)\).

With \(\delta = C^{-1}(\mu_x - \mu_y)\), \(z \sim \mathcal N(0, I)\) and \(x = \mu_x + Cz\), the pair is identical when \(\log u < -z\cdot\delta - \lVert\delta\rVert^2/2\); otherwise \(y = \mu_y + C(z - 2(e\cdot z)e)\) with \(e = \delta/\lVert\delta\rVert\), or \(e = 0\) where \(\lVert\delta\rVert^2\) is 0 or not finite (Jacob, O’Leary & Atchadé 2020, section 4.1). The coupling is maximal: \(P(x = y) = 2\Phi(-\lVert\delta\rVert/2)\).

Parameters:
mu_x, mu_yndarray, shape (n, d)

Means of the two Gaussians of each row.

cholndarray, shape (d, d)

Lower-triangular factor \(C\) of the shared covariance.

inversendarray, shape (d, d)

\(C^{-1}\), which whitens the difference of the means.

drawsDraws

Random numbers for the n rows; each row uses d normals and 1 uniform.

blasbool

Whether to compute the products with \(C\) and \(C^{-1}\) by BLAS (vectors @ matrix.T), which gives a row bits that can depend on the other rows and on the number of BLAS threads; kernels set it for vectorized targets. Otherwise a row’s arithmetic does not depend on the other rows.

Returns:
x, yndarray, shape (n, d)

The coupled draws. On identical rows y is a copy of x, so equality is exact.

identicalndarray of bool, shape (n,)

Whether each row’s draws are equal.