|
Docs
|
Split-Merge sampler for Bayesian nonparametric mixture models. More...
#include <splitmerge.hpp>
Public Member Functions | |
| SplitMerge (Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle) | |
| Constructor for Split-Merge sampler. | |
| void | step () override |
| Perform one iteration of the split-merge algorithm. | |
| int | get_accepted_split () const |
| Get number of accepted split moves for diagnostics. | |
| int | get_accepted_merge () const |
| Get number of accepted merge moves for diagnostics. | |
| int | get_accepted_shuffle () const |
| Get number of accepted shuffle moves for diagnostics. | |
| 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 | choose_indeces () |
| Randomly select two observations for split-merge proposal. | |
| void | choose_clusters_shuffle () |
| Select clusters for shuffle move. | |
| void | restricted_gibbs (int iterations, bool only_probabilities=false) |
| Generate proposal state via restricted Gibbs sampling. | |
| void | split_move () |
| Execute a split move proposal. | |
| double | compute_acceptance_ratio_split (double likelihood_old_cluster) |
| Compute acceptance ratio for split move. | |
| void | merge_move () |
| Execute a merge move proposal. | |
| double | compute_acceptance_ratio_merge (double likelihood_old_ci, double likelihood_old_cj) |
| Compute acceptance ratio for merge move. | |
| void | shuffle () |
| Execute a shuffle move proposal. | |
| double | compute_acceptance_ratio_shuffle (double likelihood_old_ci, double likelihood_old_cj, int old_ci_size, int old_cj_size) |
| Compute acceptance ratio for shuffle move. | |
Private Attributes | |
| std::mt19937 | gen |
| Mersenne Twister random number generator for sampling operations. | |
| int | idx_i |
| Index of first randomly chosen observation. | |
| int | idx_j |
| Index of second randomly chosen observation. | |
| int | ci |
| Cluster assignment of first observation. | |
| int | cj |
| Cluster assignment of second observation. | |
| bool | shuffle_bool = false |
| Flag to enable shuffle moves (Mena and Martinez, 2014). | |
| Eigen::VectorXi | launch_state |
| Launch state for restricted Gibbs sampling. | |
| Eigen::VectorXi | S |
| Indices of observations in clusters ci and cj. | |
| Eigen::VectorXi | original_allocations |
| Original cluster assignments before move proposal. | |
| double | log_split_gibbs_prob = 0 |
| Log probability of generating current state via restricted Gibbs (split direction). | |
| double | log_merge_gibbs_prob = 0 |
| Log probability of generating current state via restricted Gibbs (merge direction). | |
| int | accepted_split = 0 |
| int | accepted_merge = 0 |
| int | accepted_shuffle = 0 |
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. | |
Split-Merge sampler for Bayesian nonparametric mixture models.
This class implements the split-merge algorithm, an advanced MCMC method that proposes joint updates to cluster assignments through split and merge moves. This approach can achieve better mixing than sequential Gibbs sampling, particularly for models with strong within-cluster correlations.
The algorithm alternates between three types of moves:
Each move uses restricted Gibbs sampling to generate proposals, followed by Metropolis-Hastings acceptance/rejection based on prior and likelihood ratios. The algorithm maintains detailed balance and ergodicity.
|
inline |
Constructor for Split-Merge 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 defining the prior |
| shuffle | Flag to enable shuffle moves in addition to split-merge |
Initializes the split-merge sampler with the option to include shuffle moves. When shuffle is enabled, the algorithm can propose redistributions between existing clusters in addition to split-merge moves.
|
private |
Select clusters for shuffle move.
Determines the cluster assignments of the selected observations and prepares for a shuffle move between two existing clusters.
Randomly choose two distinct clusters ci and cj from the current allocations. Update idx_i and idx_j to be random points from these clusters.
|
private |
Randomly select two observations for split-merge proposal.
Uniformly samples two distinct observation indices that will be used to determine the type of move (split, merge, or shuffle).
Randomly choose two distinct indices i and j from the data points. Identify their clusters ci and cj. Prepare the launch_state and S vectors for the split-merge operation.
|
private |
Compute acceptance ratio for merge move.
| likelihood_old_ci | Likelihood of first original cluster |
| likelihood_old_cj | Likelihood of second original cluster |
Compute the log acceptance ratio for a merge move.
| likelihood_old_ci | The log likelihood of cluster ci before the merge. |
| likelihood_old_cj | The log likelihood of cluster cj before the merge. |
|
private |
Compute acceptance ratio for shuffle move.
| likelihood_old_ci | Likelihood of first cluster before shuffle |
| likelihood_old_cj | Likelihood of second cluster before shuffle |
| old_ci_size | Size of first cluster before shuffle |
| old_cj_size | Size of second cluster before shuffle |
Compute the log acceptance ratio for a shuffle move.
|
private |
Compute acceptance ratio for split move.
| likelihood_old_cluster | Likelihood of the original single cluster |
Computes the Metropolis-Hastings acceptance probability by combining prior ratios, likelihood ratios, and proposal probabilities.
Compute the log acceptance ratio for a split move.
| likelihood_old_cluster | The log likelihood of the original cluster before the split. |
|
inline |
Get number of accepted merge moves for diagnostics.
|
inline |
Get number of accepted shuffle moves for diagnostics.
|
inline |
Get number of accepted split moves for diagnostics.
|
private |
Execute a merge move proposal.
Attempts to merge two clusters containing the selected observations into a single cluster.
Propose a merge move by combining clusters ci and cj. Compute the acceptance ratio and decide whether to accept or reject the move.
|
private |
Generate proposal state via restricted Gibbs sampling.
| iterations | Number of restricted Gibbs iterations to perform |
| only_probabilities | If true, only compute proposal probabilities without updating state |
Performs restricted Gibbs sampling on observations in the selected clusters to generate a proposal state. Also computes the probability of generating this state for use in the acceptance ratio.
Perform restricted Gibbs sampling on the points in S to propose new allocations for iter iterations.
| iterations | Number of Gibbs sampling iterations to perform. |
| only_probabilities | If true, only compute the probabilities without changing allocations (used in merge move). |
|
private |
Execute a shuffle move proposal.
Redistributes observations between two existing clusters without changing the total number of clusters.
Perform a shuffle move to refine the allocations of points in S. This move helps to improve mixing by allowing points to switch clusters.
|
private |
Execute a split move proposal.
Attempts to split a cluster containing both selected observations into two separate clusters using restricted Gibbs sampling to generate the proposal allocation.
Propose a split move by dividing cluster ci into two clusters. Compute the acceptance ratio and decide whether to accept or reject the move.
|
overridevirtual |
Perform one iteration of the split-merge algorithm.
Executes one step of the split-merge sampler:
The algorithm automatically chooses between split, merge, and shuffle moves based on the cluster assignments of the selected observations.
Perform a single split-merge MCMC step. Randomly choose two indices and decide whether to propose a split or merge move.
Implements Sampler.
|
private |
|
private |
|
private |
|
private |
Cluster assignment of first observation.
|
private |
Cluster assignment of second observation.
|
mutableprivate |
Mersenne Twister random number generator for sampling operations.
|
private |
Index of first randomly chosen observation.
|
private |
Index of second randomly chosen observation.
|
private |
Launch state for restricted Gibbs sampling.
|
private |
Log probability of generating current state via restricted Gibbs (merge direction).
|
private |
Log probability of generating current state via restricted Gibbs (split direction).
|
private |
Original cluster assignments before move proposal.
|
private |
Indices of observations in clusters ci and cj.
|
private |
Flag to enable shuffle moves (Mena and Martinez, 2014).