DiscreteHMCGibbsSampler¶
A hybrid discrete/continuous sampler that uses Gibbs updates to sample from discrete sites along with an underlying Hamiltonian Monte Carlo (HMC)-type sampler for the continuous variables.
Along with MixedHMC, which has a similar structure, DiscreteHMC (DHMC) is one of two options when dealing with models that have both continuous and discrete variables; of the two, DHMC is applicable to models with high-dimensional continuous variables without much tuning, since it is compatible with NUTS (which is relatively tuning-free), but compared to MixedHMC is relatively less efficient on high-dimensional discrete states (e.g., multiple discrete variables, each with several states, which multiply to yield the total state space size), since it uses a more "naive" (or brute-force) update scheme. In contrast, MixedHMC is likely more efficient in such settings, but likely requires careful tuning of the underlying HMC sampler in terms of its trajectory length in particular. Due to these tradeoffs, it is recommended to compare efficiency between these different sampler types for your specific model. More Info... Version 0.8.0
Ports/Properties¶
method¶
Sampler to use for the continuous variables. If NUTS is used, the max tree depth parameters apply, and if HMC is used, the trajectory length applies.
- verbose name: Method
- default value: NUTS
- port type: EnumPort
- value type: str (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)
max_tree_depth¶
The maximum depth of the doubling scheme used in this sampler. Models with especially complex parameter spaces or posterior geometry can benefit from a larger value here.
- verbose name: Max Tree Depth (If Nuts)
- default value: 10
- port type: IntPort
- value type: int (can be None)
max_tree_depth_postwarmup¶
The maximum depth during the post-warmup phase. If not provided, this is the same as max_tree_depth.
- verbose name: Max Tree Depth (Post-Warmup)
- default value: None
- port type: IntPort
- value type: int (can be None)
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 (If Hmc)
- default value: 6.283185
- port type: FloatPort
- value type: float (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 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)