Kernel¶
- class telescopic.kernels.Kernel¶
A Markov kernel with its coupling.
Subclasses implement
step()andcoupled_step()on batches of chains. Each marginal ofcoupled_step()must have exactly the law ofstep(). The engine declares a meeting when a pair’s returned Markov states are equal under==: the positions and the fields thatmarkov_fieldsnames. So a coupling that makes the two proposals identical must give the second chain a copy of the first chain’s proposal, never a recomputation. For a target evaluated point by point, a row’s arithmetic must not depend on the other rows of the batch; for a vectorized one it may, as BLAS products do, if a coupled step computes each chain’s products in a call of its own, of the same shape, so that equal chains stay equal.- check_ndim(ndim)¶
Raise
ValueErrorif the kernel works in another dimension thanndim.- Parameters:
- ndim
int The dimension of the initial points.
- ndim
- check_target(target)¶
Raise
ValueErroriftargetlacks a function that the kernel evaluates.A
targetthat is not aTargetraisesTypeError.- Parameters:
- target
Target The target to check.
- target
- abstractmethod coupled_step(target, state_x, state_y, draws)¶
One coupled transition of each pair.
- init_extra(state)¶
The initial values of the kernel’s own fields at the chains of
state.init_state()attaches them; none by default.
- init_state(target, x)¶
The states at the rows of
x: the target’s values, and the kernel’s fields.Gradients are evaluated if the kernel needs them, and
init_extra()gives the fields, which must include every Markov field.A gradient that is not finite where the log-density is raises
ValueErrorhere, as chains cannot start there; elsewhere it is taken as 0.- Parameters:
- Returns:
StateWith the fields of
init_extra().
- property markov_fields¶
The fields of a
State’sextrathat are part of the kernel’s Markov state.A pair meets when its positions and these fields are equal; every other field of the kernel is a cache. None for every kernel of the package.
- property needs_log_prob¶
Whether the kernel evaluates the log-density; Gibbs kernels do not.
- Returns:
- abstractmethod step(target, state, draws)¶
One transition of each chain.
- Parameters:
- Returns:
- tune(target, initial, rng=None, *, pilot=None)¶
A copy with the unset parameters tuned on pilot chains.
Each kernel’s documentation says which parameters it tunes and how.
- Parameters:
- target
Target Checked with
check_target()before the pilot runs.- initial
An object with
rvs(random_state=generator), a callableinitial(rng)or an array of points of shape(n, d), as fortelescopic.initial.as_initial().- rng
None,int,numpy.random.SeedSequenceornumpy.random.Generator Seed of the tuning, in the tuning namespace: the pilot chains, unless
pilotis given, and dual averaging.- pilot
PilotRun, optional Adaptive Metropolis chains already run, from
telescopic.tuning.adaptive_metropolis(), so that several kernels can be tuned on one pilot.
- target
- Returns:
- kernel
Kernel - report
TuningReportorNone None, with the kernel itself, when there is nothing to tune.
- kernel