blackjax.ns.from_mcmc#
NS particle-update strategies that wrap a generic MCMC kernel under the likelihood constraint.
Classes#
Info for a constrained MCMC proposal. |
Functions#
|
An update strategy for NS that uses MCMC to update the particles. |
|
Constrained inner step wrapping a generic MCMC kernel (propose-then-reject). |
|
Build a Nested Sampling kernel from a constrained inner step. |
Module Contents#
- class ConstrainedMCMCInfo[source]#
Info for a constrained MCMC proposal.
- update_with_mcmc_take_last(constrained_mcmc_step_fn, num_mcmc_steps, num_delete)[source]#
An update strategy for NS that uses MCMC to update the particles. For now we will not keep the states as they will be too large to store. Similar to the update_and_take_last from SMC.
- Parameters:
constrained_mcmc_step_fn – Wrapped MCMC step function that enforces the NS likelihood constraint.
num_mcmc_steps – Number of MCMC proposals per particle.
num_delete – Number of particles to replace per step.
- Returns:
An update function that proposes new particles by running the constrained
MCMC kernel from survivor start points and returns the final states and
infos.
- reject_constrained_step(init_state_fn: Callable, logdensity_fn: Callable, mcmc_init_fn: Callable, mcmc_step_fn: Callable) Callable[source]#
Constrained inner step wrapping a generic MCMC kernel (propose-then-reject).
Proposes one
mcmc_step_fnmove and accepts it only if the MCMC step accepted AND the proposed point is above the likelihood threshold; otherwise the particle stays put. The complement toslice_constrained_step()for kernels that cannot gate the constraint inside their own proposal.- Parameters:
init_state_fn – Builds a particle state from a position and birth log-likelihood.
logdensity_fn – Log-density of the (unconstrained) target passed to the MCMC kernel.
mcmc_init_fn – Initializes the wrapped MCMC state from a position and
logdensity_fn.mcmc_step_fn – One step of the wrapped MCMC kernel,
(rng_key, mcmc_state, logdensity_fn, **params) -> (mcmc_state, info).
- Returns:
A constrained inner step ``(rng_key, state, loglikelihood_0, **params) ->
(new_state, ConstrainedMCMCInfo)``.
- build_kernel(constrained_step_fn: Callable, num_inner_steps: int, update_inner_kernel_params_fn: Callable, num_delete: int = 1, delete_fn: Callable = default_delete_fn, update_strategy: Callable = update_with_mcmc_take_last) Callable[source]#
Build a Nested Sampling kernel from a constrained inner step.
The generic NS engine: run
constrained_step_fn(a move that reports its in-contouris_accepted) fornum_inner_stepsfrom survivor start points, take the last, and accumulate the evidence via the adaptive kernel. Build the step withreject_constrained_step()(generic MCMC) or, for the slice family,slice_constrained_step().- Parameters:
constrained_step_fn – Constrained inner step
(rng_key, state, loglikelihood_0, **params) -> (new_state, info).num_inner_steps – Number of inner steps per particle replacement.
update_inner_kernel_params_fn – Recomputes the inner-kernel parameters from the live points each step.
num_delete – Number of particles replaced per NS iteration.
delete_fn – Selects which particles to delete (default: the lowest-likelihood ones).
update_strategy –
Inner-kernel factory
(constrained_step_fn, num_inner_steps, num_delete) -> update_fn(default:update_with_mcmc_take_last()). The returnedupdate_fnis called once per NS iteration as:update_fn(rng_key, state, loglikelihood_0, **step_parameters) -> (new_particles, update_info)
where
loglikelihood_0is the likelihood contour being replaced andstep_parametersis the currentstate.inner_kernel_params. It must return exactlynum_deleteparticle states whose pytree structure and dtypes matchstate.particles, since they are written back by index, and each must satisfyloglikelihood > loglikelihood_0withloglikelihood_birthset tologlikelihood_0. Driving the particles withconstrained_step_fngives the last two properties for free.update_infois passed through toNSInfo.update_infounchanged and may be any pytree.
- Return type:
A Nested Sampling kernel
kernel(rng_key, state) -> (new_state, info).