telescopic.tuning

Tuning on pilot runs: adaptive Metropolis chains, and the choice of k.

Classes

PilotRun

The second halves of the pilot chains of adaptive_metropolis().

TuningReport

What a tuning pilot found.

telescopic.tuning.adaptive_metropolis(target, initial, rng=None, *, n_steps=None)

Four adaptive Metropolis chains that pool their adaptation.

Chain \(c\) proposes \(x' \sim \mathcal N(x_c, \lambda_c\Sigma)\). After step \(t = 1, 2, \dots\) its scale moves toward an acceptance rate of 0.234, and the mean and covariance become running averages of every chain’s states:

\[\log\lambda_c \mathrel{+}= \frac{\alpha_{c,t} - 0.234}{(t + 1)^{0.6}}, \quad \mu \mathrel{+}= \frac{\bar\delta}{t + 1}, \quad \Sigma \mathrel{+}= \frac{1}{t + 1}\Big(\frac14\sum_c \delta_c\delta_c^\top - \Sigma\Big),\]

with \(\delta_c = x_c - \mu\), from \(\lambda_c = 2.38^2/d\), the mean of the starting points and the diagonal of the variances of 100 draws from initial (Haario, Saksman & Tamminen 2001, with the global scales of Andrieu & Thoms 2008, section 5, pooled across chains as in Craiu, Rosenthal & Yang 2009). Chain i starts from the first of its 25 draws, and draws from replicate i of the tuning namespace.

Parameters:
targetTarget

The target to sample.

initial

An object with rvs(random_state=generator), a callable initial(rng) or an array of points of shape (n, d), as for telescopic.initial.as_initial().

rngNone, int, numpy.random.SeedSequence or numpy.random.Generator

The root of the chains’ random streams.

n_stepsint, optional

Steps per chain, at least 3; \(\max(2000, 200d, 10d^2)\) by default.

Returns:
PilotRun

The second halves of the chains, and the variances of the draws from the initial distribution.

Notes

Cost: 4 (n_steps + 1) log-density evaluations and about n_steps / ceil(d/20) Cholesky factorizations: beyond 20 dimensions the chains refactor the covariance and keep their states every \(\lceil d/20\rceil\) steps, or fewer for a short pilot.

telescopic.tuning.choose_k(meeting_times, quantile=0.99)

Choose k from lag-1 pilot meeting times.

\(k = \max(1, \hat q_\beta(\tau - 1))\), with \(\hat q_\beta\) the inverted-CDF sample quantile (Atchadé & Jacob 2024). The recipe then sets \(L = k\) and \(m = 10k\).

Parameters:
meeting_timesarray_like, shape (R0,)

Pilot meeting times with lag 1, positive integers; inf for a censored pair, which sorts above every finite one.

quantilefloat

The level \(\beta\), at most \(1 - 1/R_0\) so that the quantile is not the sample maximum.

Returns:
int
telescopic.tuning.dual_averaging(kernel_at, target, pilot, rng, target_acceptance, step_size)

A step size whose mean acceptance probability is target_acceptance.

One chain per pilot chain runs kernel_at(step_size) from that chain’s last state, where a gradient that is not finite where the log-density is counts as 0. After step \(t\) the step size becomes \(\epsilon_t = \exp(\mu - \sqrt t\,\bar H_t/\gamma)\), where \(\bar H_t\) averages the target acceptance minus the chains’ mean acceptance probability with offset \(t_0\); the result is \(\bar\epsilon\), the average of \(\log\epsilon_t\) with weights \(t^{-\kappa}\) (Hoffman & Gelman 2014, section 3.2.1, with \(\gamma = 0.05\), \(t_0 = 10\), \(\kappa = 0.75\), \(\mu = \log(10\epsilon_0)\) and 1000 steps). Chain i draws from replicate 4 + i of the tuning namespace, after the streams of adaptive_metropolis().

Parameters:
kernel_atcallable()

Maps a step size to a kernel, cheaply: it is called at every step.

targetTarget

The target to sample.

pilotPilotRun

The pilot chains, whose last states start the chains.

rngNone, int, numpy.random.SeedSequence or numpy.random.Generator

The root of the chains’ random streams.

target_acceptancefloat

In (0, 1).

step_sizefloat

The first step size \(\epsilon_0\), positive and finite.

Returns:
float