Mixture¶
- class telescopic.kernels.Mixture(kernels, weights)¶
A mixture of kernels.
Each step draws one uniform and applies the component it selects. The coupled step gives both chains the same component and applies that component’s coupling. The choice never depends on the states, which keeps each marginal the mixture (Atchadé & Jacob 2024, section 4.2).
The field that component
inamesnamein aState’sextrais namedf"{i}/{name}"in the mixture’s states. Each component sees only its own fields, under their own names, and every other field is carried unchanged. A component with Markov fields (markov_fields) raisesValueError: the mixture leaves a joint law \(\pi(x)\psi(v)\) invariant only when \(\psi\) does not depend on \(x\), which cannot be checked.- Parameters:
- kernelssequence of
Kernel Kernel instances.
tune()tunes the untuned ones on one set of pilot chains; its report gives the largest weight ratio of any independence component.- weightsarray_like
Non-negative weights with a finite sum, normalized internally.
- kernelssequence of
Examples
The sampler tunes the untuned components of a mixture on the same pilot chains, whose report gives the largest weight ratio of the independence proposal:
>>> from telescopic import examples, kernels, sample >>> example = examples.gaussian(2) >>> kernel = kernels.Mixture( ... [kernels.RandomWalk(), kernels.Independence()], [0.8, 0.2] ... ) >>> result = sample( ... example.log_prob, example.initial, kernel=kernel, ... n_replicates=50, vectorize=True, rng=0, ... ) >>> result.kernel.is_tuned, result.tuning.max_weight_ratio is not None (True, True)
- check_ndim(ndim)¶
Raise
ValueErrorif the kernel works in another dimension thanndim.- Parameters:
- ndim
int The dimension of the initial points.
- ndim
- 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.
- property needs_log_prob¶
Whether the kernel evaluates the log-density; Gibbs kernels do not.
- Returns:
- step(target, state, draws)¶
One transition of each chain.
- Parameters:
- Returns: