blackjax.adaptation.mclmc_adaptation#

Algorithms to adapt the MCLMC kernel parameters, namely step size and L.

Classes#

MCLMCAdaptationState

Represents the tunable parameters for MCLMC adaptation.

Functions#

mclmc_find_L_and_step_size(mclmc_kernel, num_steps, ...)

Finds the optimal value of the parameters for the MCLMC algorithm.

make_L_step_size_adaptation(kernel, dim, frac_tune1, ...)

Adapts the stepsize and L of the MCLMC kernel. Designed for the unadjusted MCLMC

make_adaptation_L(kernel, frac, Lfactor)

determine L by the autocorrelations (around 10 effective samples are needed for this to be accurate)

handle_nans(previous_state, next_state, step_size, ...)

if there are nans, let's reduce the stepsize, and not update the state. The

Module Contents#

class MCLMCAdaptationState[source]#

Represents the tunable parameters for MCLMC adaptation.

L

The momentum decoherent rate for the MCLMC algorithm.

step_size

The step size used for the MCLMC algorithm.

sqrt_diag_cov

A matrix used for preconditioning.

L: float[source]#
step_size: float[source]#
sqrt_diag_cov: float[source]#
mclmc_find_L_and_step_size(mclmc_kernel, num_steps, state, rng_key, frac_tune1=0.1, frac_tune2=0.1, frac_tune3=0.1, desired_energy_var=0.0005, trust_in_estimate=1.5, num_effective_samples=150, diagonal_preconditioning=True)[source]#

Finds the optimal value of the parameters for the MCLMC algorithm.

Parameters:
  • mclmc_kernel – The kernel function used for the MCMC algorithm.

  • num_steps – The number of MCMC steps that will subsequently be run, after tuning.

  • state – The initial state of the MCMC algorithm.

  • rng_key – The random number generator key.

  • frac_tune1 – The fraction of tuning for the first step of the adaptation.

  • frac_tune2 – The fraction of tuning for the second step of the adaptation.

  • frac_tune3 – The fraction of tuning for the third step of the adaptation.

  • desired_energy_va – The desired energy variance for the MCMC algorithm.

  • trust_in_estimate – The trust in the estimate of optimal stepsize.

  • num_effective_samples – The number of effective samples for the MCMC algorithm.

Return type:

A tuple containing the final state of the MCMC algorithm and the final hyperparameters.

Example

make_L_step_size_adaptation(kernel, dim, frac_tune1, frac_tune2, diagonal_preconditioning, desired_energy_var=0.001, trust_in_estimate=1.5, num_effective_samples=150)[source]#

Adapts the stepsize and L of the MCLMC kernel. Designed for the unadjusted MCLMC

make_adaptation_L(kernel, frac, Lfactor)[source]#

determine L by the autocorrelations (around 10 effective samples are needed for this to be accurate)

handle_nans(previous_state, next_state, step_size, step_size_max, kinetic_change, key)[source]#

if there are nans, let’s reduce the stepsize, and not update the state. The function returns the old state in this case.