telescopic.diagnostics

Diagnostics: bounds on the distance to stationarity, tail indices, warnings, gradient checks.

Classes

GradientCheck

What the gradient check of a sampler built with a gradient compared.

Issue

A condition that applies to a result and makes it warn.

telescopic.diagnostics.hill(values, n_tail)

Hill’s estimate of the tail index \(\alpha\) of positive values.

\[\hat\alpha = \Big[\frac{1}{k}\sum_{i=1}^{k} \log\frac{x_{(n-i+1)}}{x_{(n-k)}}\Big]^{-1}\]

from the \(k\) = n_tail largest of \(n\) values. A tail \(P(X > x) \propto x^{-\alpha}\) has finite moments below \(\alpha\) only. Where ties make the smallest value the threshold \(x_{(n-k)}\), as when most meeting times take their smallest possible value, the estimate is undefined: above such ties it reads a light tail as a heavy one. With n_tail \(= \lfloor n/10 \rfloor\), as in the tail warning of telescopic.Result.check(), this happens when nine values in ten or more share the smallest.

Parameters:
valuesarray_like, shape (n,)

Positive, finite values.

n_tailint

The number \(k\) of upper order statistics, \(1 \le k < n\).

Returns:
float

nan where ties make the smallest value the threshold, and otherwise inf when the \(k + 1\) largest values are equal.

telescopic.diagnostics.issues(result)

The warnings that apply to result (Warnings, in Warnings and errors).

Parameters:
resultResult

The result to check.

Returns:
list of Issue

Empty for a run that raises no warning.

telescopic.diagnostics.slow_pair_threshold(lag, m)

The time \(\max(10^4, 10\max(L, m))\) past which a pair is slow.

Parameters:
lagint

At least 1.

mint

At least 0.

Returns:
int
telescopic.diagnostics.tuning_disagreement(tuning)

The warning about tuning chains that disagree, or None.

The chains disagree when, in some coordinate, their means spread more widely than the chains themselves: \(\hat R > \sqrt 2\), a sign of several modes or of chains that have not converged. Chains that agree do not show that the target has one mode. The warning also names the coordinates whose \(\hat R\) is NaN, where all four chains sat at one value, so the pilot never moved in them.

Parameters:
tuningTuningReport or None

The report of the tuning pilot; None when nothing was tuned.

Returns:
str or None
telescopic.diagnostics.tv_bound(meeting_times, lag, t)

Estimated upper bound on the total variation distance to the target.

\[d_{TV}(\pi_t, \pi) \le \mathbb E\big[\max(0, \lceil (\tau - L - t)/L \rceil)\big]\]

(Biswas, Jacob & Vanetti 2019, Theorem 2.5), estimated by the average over replicates of \(N_r(t) = \max(0, \lceil (\tau_r - L - t)/L \rceil)\) and reported as \(\min(1, \cdot)\), with the standard error of that average.

Parameters:
meeting_timesarray_like of int, shape (R,)

The meeting times \(\tau\). A censored pair, given as its cap plus 1, the least meeting time it can have, makes the estimate a lower bound of the true average.

lagint

The lag \(L\) of the runs that produced the meeting times.

tarray_like of int

Times at which to bound the distance.

Returns:
bound, standard_errorndarray, shape of t

The standard error is the sample standard deviation of the \(N_r(t)\) divided by \(\sqrt R\), of the average before it is capped at 1; nan for \(R = 1\).

Notes

Computed as \(\sum_{j \ge 1} \hat S(t + jL)\) with the empirical survival function \(\hat S(u) = R^{-1}\#\{\tau > u\}\), and the second moment as \(\sum_{j \ge 1} (2j - 1)\hat S(t + jL)\), in \(O(R + \max\tau)\).

telescopic.diagnostics.variance_share(values)

The largest share of one replicate in the sample variance of each column.

Parameters:
valuesarray_like, shape (R,) or (R, p)

Replicate values.

Returns:
ndarray, shape () or (p,)

0 for a column without variance, or whose values differ only by rounding.

telescopic.diagnostics.w1_bound(distance_owner, distance_time, distance, n_replicates, lag, t)

Estimated upper bound on the 1-Wasserstein distance to the target.

\[d_{W_1}(\pi_t, \pi) \le \mathbb E\Big[\sum_{j=1}^{\lceil(\tau - L - t)/L\rceil} \lVert X_{t+jL} - Y_{t+(j-1)L}\rVert\Big]\]

(Biswas, Jacob & Vanetti 2019), estimated by the average over replicates of each replicate’s sum, with the standard error of that average. It depends on the parameterization of the target.

Parameters:
distance_owner, distance_time, distancearray_like, shape (M,)

The replicate, time \(s\) and distance \(\lVert X_s - Y_{s-L}\rVert\) of each record, for \(L \le s < \tau\), pooled over replicates, as telescopic.engine.Replicates holds them.

n_replicatesint

The number of replicates \(R\), including those with no recorded distance.

lagint

The lag \(L\) of the runs that recorded the distances.

tarray_like of int

Times at which to bound the distance.

Returns:
bound, standard_errorndarray, shape of t

The standard error is the sample standard deviation of the replicates’ sums divided by \(\sqrt R\), those without a record counting as 0; nan for \(R = 1\).

Notes

Costs \(O(M \log M + \max s)\).

telescopic.diagnostics.wide_start(tuning)

The warning about an initial distribution far wider than the target, or None.

The tuning pilot shows a start far wider than the target when the report’s initial_width, defined in telescopic.tuning.PilotRun.initial_width, exceeds 30. From such a start, k from the 99% quantile of the pilot’s meeting times can leave a few replicates still on their way to the target, and those can dominate the variance of the estimates. When the warning is emitted and listed is stated in Warnings and errors.

Parameters:
tuningTuningReport or None

The report of the tuning pilot; None when nothing was tuned.

Returns:
str or None