No-U-Turn MCMC Sampler¶
- class pints.NoUTurnMCMC(x0, sigma0=None)[source]¶
Implements the No U-Turn Sampler (NUTS) with dual averaging, as described in Algorithm 6 in [1].
Implements the multinomial sampling suggested in [2]. Implements a mass matrix for the dynamics, which is detailed in [2]. Both the step size and the mass matrix is adapted using a combination of the dual averaging detailed in [1], and the windowed adaption for the mass matrix and step size implemented in the Stan library (https://github.com/stan-dev/stan).
Like Hamiltonian Monte Carlo, NUTS imagines a particle moving over negative log-posterior (NLP) space to generate proposals. Naturally, the particle tends to move to locations of low NLP – meaning high posterior density. Unlike HMC, NUTS allows the number of steps taken through parameter space to depend on position, allowing local adaptation.
Note: This sampler is only supported on Python versions 3.3 and newer.
Extends
SingleChainMCMC
.References
- hamiltonian_threshold()[source]¶
Returns threshold difference in Hamiltonian value from one iteration to next which determines whether an iteration is divergent.
- in_initial_phase()¶
For methods that need an initial phase (see
needs_initial_phase()
), this method returnsTrue
if the method is currently configured to be in its initial phase. For other methods aNotImplementedError
is returned.
- load_state(file)[source]¶
Loads sampler state from a .pickle file and returns sampler.
- Parameters:
file (str) – Path to file.
- max_tree_depth()[source]¶
Returns the maximum tree depth
D
for the algorithm. For each iteration, the number of leapfrog steps will not be greater than2^D
.
- needs_initial_phase()¶
Returns
True
if this method needs an initial phase, for example an adaptation-free period for adaptive covariance methods, or a warm-up phase for DREAM.
- replace(current, current_log_pdf, proposed=None)¶
Replaces the internal current position, current LogPDF, and proposed point (if any) by the user-specified values.
This method can only be used once the initial position and LogPDF have been set (so after at least 1 round of ask-and-tell).
This is an optional method, and some samplers may not support it.
- save_state(file)[source]¶
Saves sampler state to pickle file.
- Parameters:
file (str) – Path to file.
- set_delta(delta)[source]¶
Sets delta for the nuts algorithm. This is the goal acceptance probability for the algorithm. Used to set the scalar magnitude of the leapfrog step size.
- set_hamiltonian_threshold(hamiltonian_threshold)[source]¶
Sets threshold difference in Hamiltonian value from one iteration to next which determines whether an iteration is divergent.
- set_initial_phase(in_initial_phase)¶
For methods that need an initial phase (see
needs_initial_phase()
), this method toggles the initial phase algorithm. For other methods aNotImplementedError
is returned.
- set_max_tree_depth(max_tree_depth)[source]¶
Sets the maximum tree depth
D
for the algorithm. For each iteration, the number of leapfrog steps will not be greater than2^D
- set_number_adaption_steps(n)[source]¶
Sets number of adaptions steps in the nuts algorithm. This is the number of mcmc steps that are used to determin the best value for epsilon, the scalar magnitude of the leafrog step size.
- set_use_dense_mass_matrix(use_dense_mass_matrix)[source]¶
If
use_dense_mass_matrix
is False then algorithm uses a diagonal matrix for the mass matrix. If True then a fully dense mass matrix is used.