|
Docs
|
Neal's Algorithm 3 with ZDNAM for improved collapsed Gibbs sampling. More...
#include <neal_ZDNAM.hpp>
Public Member Functions | |
| Neal3ZDNAM (Data &d, Params &p, Likelihood &l, Process &pr) | |
| Constructor for Neal's Algorithm 3 with ZDNAM sampler. | |
| void | step () override |
| Perform one complete iteration of Neal's Algorithm 3 with ZDNAM. | |
| Public Member Functions inherited from Sampler | |
| Sampler (Data &d, const Params &p, const Likelihood &l, Process &pr) | |
| Constructor initializing sampler with required components. | |
| virtual | ~Sampler ()=default |
| Virtual destructor for proper cleanup of derived classes. | |
Private Member Functions | |
| void | step_1_observation (int index) |
| Update cluster assignment for a single observation using ZDNAM. | |
| int | sample_from_log_probs (const std::vector< double > &log_probs) |
| Sample from log probabilities using standard Gibbs sampling. | |
| std::vector< double > | compute_zdnam_probabilities (const std::vector< double > &log_probs, int current_k) |
| Compute ZDNAM transition probabilities from current state. | |
| int | sample_from_log_probs_zdnam (const std::vector< double > &log_probs, int current_k) |
| Sample from log probabilities using ZDNAM to avoid self-transitions. | |
Private Attributes | |
| std::mt19937 | gen |
| Mersenne Twister random number generator for sampling operations. | |
Additional Inherited Members | |
| Protected Attributes inherited from Sampler | |
| Data & | data |
| Reference to the data object containing observations and current allocations. | |
| const Params & | params |
| Reference to the parameters object containing model hyperparameters and MCMC settings. | |
| const Likelihood & | likelihood |
| Reference to the likelihood computation object for evaluating cluster assignments. | |
| Process & | process |
| Reference to the stochastic process object (DP, NGGP, DPW, NGGPW). | |
| std::random_device | rd |
| Random device for generating random numbers across sampling algorithms. | |
Neal's Algorithm 3 with ZDNAM for improved collapsed Gibbs sampling.
This class implements Neal's Algorithm 3 (collapsed Gibbs sampler) enhanced with the Zero-self Downward Nested Antithetic Modification (ZDNAM) from Neal's Algorithm 5. The ZDNAM modification eliminates self-transitions in the Gibbs sampler, which can significantly improve mixing and reduce autocorrelation in the MCMC chain.
Key Features:
ZDNAM Algorithm: The ZDNAM modification constructs transition probabilities P(new_state | current_state) such that P(current_state | current_state) = 0 when possible, while maintaining the correct stationary distribution. This is achieved through a careful construction involving nested antithetic coupling.
When to use:
|
inline |
Constructor for Neal's Algorithm 3 with ZDNAM sampler.
| d | Reference to Data object containing observations and cluster assignments |
| p | Reference to Params object with model hyperparameters |
| l | Reference to Likelihood object for computing conditional probabilities |
| pr | Reference to Process object (DP, NGGP, etc.) defining the prior distribution |
Initializes the ZDNAM-enhanced Gibbs sampler with all required components. The random number generator is seeded from the inherited random device to ensure reproducibility when the random device is seeded externally.
|
private |
Compute ZDNAM transition probabilities from current state.
| log_probs | Vector of unnormalized log probabilities (target distribution π) |
| current_k | Current state/cluster index (-1 if no current state) |
Implements Algorithm 5 from Neal (2019). The algorithm constructs transition probabilities that:
Algorithm Steps:
Special Cases:
Mathematical Guarantee: The returned transition matrix satisfies:
|
private |
Sample from log probabilities using standard Gibbs sampling.
| log_probs | Vector of unnormalized log probabilities |
Standard categorical sampling:
|
private |
Sample from log probabilities using ZDNAM to avoid self-transitions.
| log_probs | Vector of unnormalized log probabilities (target distribution) |
| current_k | Current state/cluster index (-1 for no current state) |
High-level ZDNAM sampling procedure:
Behavior:
Use Case: Called by step_1_observation() to sample new cluster assignments while avoiding the tendency to stay in the current cluster.
|
overridevirtual |
Perform one complete iteration of Neal's Algorithm 3 with ZDNAM.
Executes one full sweep of the ZDNAM-enhanced collapsed Gibbs sampler:
After each step:
Expected Behavior: Compared to standard Neal's Algorithm 3, this version should show:
Implements Sampler.
|
private |
Update cluster assignment for a single observation using ZDNAM.
| index | Index of the observation to update (0 to n-1) |
This method implements Neal's Algorithm 3 with ZDNAM enhancement:
The log probabilities combine:
The ZDNAM sampler uses the current cluster index to construct transition probabilities that avoid returning to the same cluster.
|
mutableprivate |
Mersenne Twister random number generator for sampling operations.