LangevinProposal

class telescopic.kernels.LangevinProposal(factor, inverse)

The Langevin proposal \(x' = x + B(h/2 + z)\), with \(h = B^\top\nabla\log\pi(x)\).

With \(z \sim \mathcal N(0, I)\), it is a draw from \(q(\cdot \mid x) = \mathcal N(x + BB^\top\nabla\log\pi(x)/2, BB^\top)\), and the log ratio of the proposal densities is \((\lVert z\rVert^2 - \lVert z + (h + h')/2\rVert^2)/2\). A proposal with a non-finite position is not evaluated: its log-density is -inf, a rejection.

Parameters:
factorarray_like, shape (d, d)

\(B\), a factor of the proposal covariance \(BB^\top\), such as its Cholesky factor.

inversearray_like, shape (d, d)

\(B^{-1}\), checked against factor to within rounding; a matrix that is not its inverse raises ValueError.

evaluate(target, x, like)

The states at the proposals x, with the fields of like.

Parameters:
targetTarget

The target to evaluate.

xndarray, shape (n, d)

The proposals.

likeState

The current states, whose fields the proposals’ states carry: gradients if they carry them.

Returns:
State
log_alpha(target, current, proposed, forward)

The log acceptance ratios \(\log\pi(x') - \log\pi(x) + \log q(x \mid x') - \log q(x' \mid x)\).

Parameters:
targetTarget

The target that the chains sample.

current, proposedState

The current states and those at the proposals.

forward

What sample() returned with the proposals.

Returns:
ndarray, shape (n,)

NaN, from -inf - -inf, is a rejection.

property needs_grad

Whether the proposal needs the gradient of the log-density at the current states.

Returns:
bool
sample(target, state, draws)

Draw a proposal \(x' \sim q(\cdot \mid x)\) for each chain.

Parameters:
targetTarget

The target that the chains sample.

stateState

The n chains.

drawsDraws

Random numbers for the n chains.

Returns:
xndarray, shape (n, d)

The proposals.

forward

What log_alpha() needs of the draw, or None.