telescopic.tuning¶
Tuning on pilot runs: adaptive Metropolis chains, and the choice of k.
Classes
The second halves of the pilot chains of |
|
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). Chainistarts from the first of its 25 draws, and draws from replicateiof the tuning namespace.- Parameters:
- target
Target The target to sample.
- initial
An object with
rvs(random_state=generator), a callableinitial(rng)or an array of points of shape(n, d), as fortelescopic.initial.as_initial().- rng
None,int,numpy.random.SeedSequenceornumpy.random.Generator The root of the chains’ random streams.
- n_steps
int, optional Steps per chain, at least 3; \(\max(2000, 200d, 10d^2)\) by default.
- target
- Returns:
PilotRunThe 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 aboutn_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
kfrom 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;
inffor a censored pair, which sorts above every finite one.- quantile
float The level \(\beta\), at most \(1 - 1/R_0\) so that the quantile is not the sample maximum.
- Returns:
- 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). Chainidraws from replicate4 + iof the tuning namespace, after the streams ofadaptive_metropolis().- Parameters:
- kernel_at
callable() Maps a step size to a kernel, cheaply: it is called at every step.
- target
Target The target to sample.
- pilot
PilotRun The pilot chains, whose last states start the chains.
- rng
None,int,numpy.random.SeedSequenceornumpy.random.Generator The root of the chains’ random streams.
- target_acceptance
float In (0, 1).
- step_size
float The first step size \(\epsilon_0\), positive and finite.
- kernel_at
- Returns: