GradientCheck¶
- class telescopic.diagnostics.GradientCheck(draw, gap, tolerance, predicted, n_skipped, n_unusable)¶
What the gradient check of a sampler built with a gradient compared.
At each of 8 draws \(x\) of \(\pi_0\) the check compares, along the direction \(u\) between two further draws, the change of \(\log\pi\) that the gradient predicts with central differences of the log-density at steps \(h u\), \(h = \epsilon^{1/3}\) for the epsilon \(\epsilon\) of the dtype of the log-density’s values:
\[\Delta = \big|\nabla\log\pi(x)\cdot u - D_u\big|, \qquad D_u = \frac{\log\pi(x + hu) - \log\pi(x - hu)}{2h},\]and a line disagrees when \(\Delta\) exceeds its tolerance, 10 times the estimated error of the comparison: the truncation of the differences, from a second difference at \(2hu\), and the rounding of the log-density and of the gradient. All the figures are in nats along \(u\), across the spread of \(\pi_0\). The gradient and the log-density are
gradandlog_prob, or the two parts oflog_prob_and_grad.- Attributes:
- draw
ndarrayofint, shape (n,) Which of the 8 draws, numbered from 1, each compared line starts from.
- gap
ndarray, shape (n,) \(\Delta\) of each line.
- tolerance
ndarray, shape (n,) The tolerance of each line.
- predicted
ndarray, shape (n,) The change \(\nabla\log\pi(x)\cdot u\) that the gradient predicts on each line.
- n_skipped
int Draws skipped because the density is zero or the gradient is not finite there.
- n_unusable
int Lines not compared because they reach zero density, or because their steps round away in the dtype of
log_prob, as with a float32log_proband a start whose spread is tiny beside its distance from 0.
- draw