|
Docs
|
Implementation of Neal's Algorithm 3 for collapsed Gibbs sampling. More...
#include <neal.hpp>
Public Member Functions | |
| Neal3 (Data &d, Params &p, Likelihood &l, Process &pr) | |
| Constructor for Neal's Algorithm 3 sampler. | |
| void | step () override |
| Perform one complete iteration of Neal's Algorithm 3. | |
| 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) |
| Sample cluster assignment for a single observation. | |
| int | sample_from_log_probs (int num_clusters) |
| Sample an index from log-probabilities using the log-sum-exp trick. | |
Private Attributes | |
| std::mt19937 | gen |
| Mersenne Twister random number generator for sampling operations. | |
| std::vector< int > | indices |
| std::vector< double > | log_likelihoods |
| std::vector< double > | weights |
| int | n_data |
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. | |
Implementation of Neal's Algorithm 3 for collapsed Gibbs sampling.
This class implements Neal's Algorithm 3, a standard collapsed Gibbs sampler for Bayesian nonparametric mixture models. The algorithm sequentially updates cluster assignments by sampling from the full conditional distribution of each observation, integrating out the cluster parameters.
Algorithm 3 is characterized by:
The algorithm is particularly effective for models where the likelihood can be computed in closed form after integrating out cluster-specific parameters.
|
inline |
Constructor for Neal's Algorithm 3 sampler.
| d | Reference to Data object containing observations |
| p | Reference to Params object with hyperparameters |
| l | Reference to Likelihood object for probability computations |
| pr | Reference to Process object (DP, NGGP, etc.) defining the prior |
Initializes the Gibbs sampler with all required components. The random number generator is seeded from the inherited random device. Pre-allocates vectors to maximum possible size to avoid resizing during sampling.
|
private |
Sample an index from log-probabilities using the log-sum-exp trick.
| num_clusters | Number of clusters (including new cluster) |
This method performs sampling from a discrete distribution defined by log-probabilities. It uses the log-sum-exp trick for numerical stability and implements roulette wheel selection.
|
overridevirtual |
Perform one complete iteration of Neal's Algorithm 3.
Executes one full sweep of the collapsed Gibbs sampler by sequentially updating the cluster assignment of each observation. The order of updates is typically randomized to avoid systematic bias.
After each full sweep:
Performs a single step of the Neal 3 algorithm for all the dataset.
Implements Sampler.
|
private |
Sample cluster assignment for a single observation.
| index | Index of the observation to update |
This method implements the core of Algorithm 3:
The probabilities combine prior information from the Process with likelihood information computed by integrating out cluster parameters.
Performs a step in the DPNeal2 sampling process.
This method is responsible for updating the allocations of the data points based on the current state of the model.
| index | The index of the data point to update. |
|
mutableprivate |
Mersenne Twister random number generator for sampling operations.
|
private |
|
private |
|
private |
|
private |