Proposal

class telescopic.kernels.Proposal

A Metropolis-Hastings proposal for a batch of chains: its draw, its evaluation and its log acceptance ratio.

A subclass implements sample() and log_alpha(), and evaluate() when its proposals’ states need other fields than the current states’. A coupled step calls log_alpha() once for each chain. A proposal with fields of its own in a State’s extra gives their initial values in init_extra(), and evaluate() can fill them at the proposals.

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
init_extra(state)

The initial values of the proposal’s own fields; none by default.

As for telescopic.kernels.Kernel.init_extra().

Parameters:
stateState

The chains, n of them.

Returns:
dict of str to ndarray, each of shape (n, …)
abstractmethod 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 ndim

The dimension that the proposal fixes, or None.

Returns:
int or None
property needs_grad

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

Returns:
bool
abstractmethod 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.