MetropolisHastings

class telescopic.kernels.MetropolisHastings(proposal, coupling)

A Metropolis-Hastings kernel from a proposal, coupled by a coupling of that proposal.

A step draws \(x' \sim q(\cdot \mid x)\) and accepts it when \(\log u < \log\pi(x') - \log\pi(x) + \log q(x \mid x') - \log q(x' \mid x)\). A coupled step draws both chains’ proposals from coupling, evaluates identical proposals once, and accepts each with the same uniform. When the coupling returns one array for both chains, as Shared does, the step evaluates it once and gives both chains its state.

Parameters:
proposalProposal or None

The proposal of every chain. None leaves the kernel untuned, for a subclass that sets its proposal by tuning, as RandomWalk does.

couplingCoupling

A coupling whose supports(proposal) is true; otherwise ValueError.

coupled_step(target, state_x, state_y, draws)

One coupled transition of each pair.

Parameters:
targetTarget

The target that the chains sample.

state_x, state_yState

The first and the second chains of the n pairs.

drawsDraws

Random numbers for the n pairs.

Returns:
state_x, state_yState
init_extra(state)

The initial values of the kernel’s own fields at the chains of state.

init_state() attaches them; none by default.

Parameters:
stateState

The chains, n of them, without fields of their own.

Returns:
dict of str to ndarray, each of shape (n, …)
property is_tuned

Whether every parameter is set, so the kernel can run.

Returns:
bool
property ndim

The dimension that the kernel’s parameters fix, or None.

Returns:
int or None
property needs_grad

Whether the kernel evaluates the gradient of the log-density.

Returns:
bool
step(target, state, draws)

One transition of each chain.

Parameters:
targetTarget

The target that the chains sample.

stateState

The chains, n of them.

drawsDraws

Random numbers for the n chains.

Returns:
stateState
acceptancendarray, shape (n,)

Each chain’s probability of accepting its proposal, 1 for a kernel that always moves; dual averaging adapts step sizes to its mean.