MixedHMCSampler¶
The Mixed Hamiltonian Monte-Carlo sampler for use with MCMC inference.
This sampler is suitable for models with both continuous and discrete variables where there are potentially many unique discrete states, and will sample stochastically from those variables. The sampler uses an underlying HMC sampler whose main parameter, the trajectory length, will likely need to be tuned by the user; this may require some experimentation. For this reason it is strongly recommended to compare also with the DiscreteHMC sampler which is compatible with the relatively tuning-free underlying NUTS sampler (the default), but which may in contrast explore the discrete variables less efficiently. More Info... Version 1.0.0
Ports/Properties¶
trajectory_length¶
The length of the particle trajectory to simulate. This value may need to be chosen carefully to avoid either too short (non-converging) or too long (wasteful) trajectories. The default is 2*pi (a full circle). See tips in the MCMC Inference node for how to tune this parameter using a combination of diagnostics and optionally trace plots of the sampler state history.
- verbose name: Trajectory Length
- default value: 6.283185
- port type: FloatPort
- value type: float (can be None)
mass_matrix_shape¶
The shape of the inverse mass matrix. This determines the efficiency with which the sampler can explore the posterior parameter space in case one or more variables may have highly correlated posterior distributions. The 'uncorrelated' form uses a simplifying diagonal approximation that is computationally cheap per update but will not handle strong correlations very well so may require more updates, while 'all-to-all' uses a full-rank ("dense") mass matrix. The latter can in principle handle correlated posterior variables more efficiently and require fewer updates, but at increased computational cost per update, especially if the parameter space is high dimensional.
An in-between is the blockwise form: this allows one to express that one or more individual variables in the model that are multivariate may each have a correlated posterior distribution, without also assuming that the variables are necessarily correlated with each other. This is written as in blockwise(myvar1,myvar2) where myvar1 and myvar2 are the names of the random variables in question; all other variables will have diagonal entries in the (overall block-diagonal) mass matrix. The final form is one in which one may denote sets of variables that could have strong mutual correlations (in addition to their own internal correlations), which is written as in blockwise(myvar1/myvar2,myvar3) where myvar1 and myvar2 are assumed to be correlated with each other but not with myvar3, but myvar3 may have its own correlation structure. Any unlisted variables again receive diagonal entries in the mass matrix.
- verbose name: Mass Matrix Shape
- default value: uncorrelated
- port type: ComboPort
- value type: str (can be None)
num_discrete_updates¶
The number of discrete updates to perform. The default is the number of discrete variables.
- verbose name: Num Discrete Updates
- default value: None
- port type: IntPort
- value type: int (can be None)
modified¶
Use the modified Gibbs sampler aka Metropolised Gibbs sampler.
- verbose name: Use Modified Gibbs Sampler
- default value: False
- port type: BoolPort
- value type: bool (can be None)
random_walk¶
If enabled, samples are drawn uniformly from the support of the discrete variables. Otherwise the draw is conditioned on the other variables, which tends to be more efficient if the discrete variables are correlated with the continuous variables.
- verbose name: Random Walk
- default value: False
- port type: BoolPort
- value type: bool (can be None)
desired_accept_prob¶
The desired acceptance probability for step-size adaptation. This will adjust the step size such that on average a step is accepted (within the posterior distribution) with this probability. Increasing this value will lead to a smaller step size, thus the sampling will be slower but more robust.
- verbose name: Desired Accept Prob
- default value: 0.8
- port type: FloatPort
- value type: float (can be None)
num_steps¶
Optionally a fixed number of steps to take.
- verbose name: Num Steps
- default value: None
- port type: IntPort
- value type: int (can be None)
step_size¶
The initial step size used by the underlying HMC sampler. This normally does not need to be touched unless step size adaptation is disabled, or the adaptation diverges immediately even when using conservative choices for the init strategy in the inference node, and having tried the step size heuristic option in the sampler. The step size is often tuned based on the acceptance rate of the sampler, where 0.8 is usually a good target (if greater than 0.8, the step size could be decreased and if less than 0.8, the step size could be increased).
- verbose name: Step Size
- default value: 1.0
- port type: FloatPort
- value type: float (can be None)
adapt_step_size¶
Whether to adapt the step size during warmup. This uses the dual-averaging scheme.
- verbose name: Adapt Step Size
- default value: True
- port type: BoolPort
- value type: bool (can be None)
adapt_mass_matrix¶
Whether to adapt the mass matrix during warmup. This uses the Welford scheme.
- verbose name: Adapt Mass Matrix
- default value: True
- port type: BoolPort
- value type: bool (can be None)
step_size_heuristic¶
Whether to use a heuristic to adjust the step size at the beginning of each adaptation. This uses the doubling/halving strategy proposed in "The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo" (2014). This heuristic can speed up initial convergence but introduces its own computational cost. Another use case is that it can help with instant divergence due to a bad choice of initial step size, if the model has steep gradients or other pathological features.
- verbose name: Pretune Step Size
- default value: False
- port type: BoolPort
- value type: bool (can be None)
regularize_mass_matrix¶
Wether to apply regularization to the mass matrix. This is generally recommended, particularly for higher-dimensional posterior distribution, since otherwise sampling may become unstable.
- verbose name: Regularize Mass Matrix
- default value: True
- port type: BoolPort
- value type: bool (can be None)
set_breakpoint¶
Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.
- verbose name: Set Breakpoint (Debug Only)
- default value: False
- port type: BoolPort
- value type: bool (can be None)
metadata¶
User-definable meta-data associated with the node. Usually reserved for technical purposes.
- verbose name: Metadata
- default value: {}
- port type: DictPort
- value type: dict (can be None)