|
Docs
|
Sequential Allocation Merge-Split (SAMS) sampler for Bayesian nonparametric models. More...
#include <splitmerge_SAMS.hpp>
Public Member Functions | |
| SplitMerge_SAMS (Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle) | |
| Constructor for SAMS (Sequential Allocation Merge-Split) sampler. | |
| void | step () override |
| Perform one iteration of the SAMS 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 | sequential_allocation (int iterations, bool only_probabilities=false, bool sequential=true) |
| Generate proposal state via sequential allocation. | |
| void | split_move () |
| Execute a split move using SAMS. | |
| double | compute_acceptance_ratio_split (double likelihood_old_cluster) |
| Compute acceptance ratio for SAMS split move. | |
| void | merge_move () |
| Execute a merge move using SAMS. | |
| double | compute_acceptance_ratio_merge (double likelihood_old_ci, double likelihood_old_cj) |
| Compute acceptance ratio for SAMS merge move. | |
| void | shuffle () |
| Execute a shuffle move using SAMS. | |
| 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 SAMS 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 sequential allocation. | |
| 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 sequential allocation (split direction). | |
| double | log_merge_gibbs_prob = 0 |
| Log probability of generating current state via sequential allocation (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. | |
Sequential Allocation Merge-Split (SAMS) sampler for Bayesian nonparametric models.
This class implements the SAMS algorithm, a variant of the split-merge sampler that uses sequential allocation instead of restricted Gibbs sampling for proposal generation. SAMS can be more efficient than standard split-merge for certain model configurations and provides an alternative proposal mechanism.
Key differences from standard Split-Merge:
The algorithm maintains the same three types of moves (split, merge, shuffle) but uses a different mechanism for generating proposals within each move type.
|
inline |
Constructor for SAMS (Sequential Allocation Merge-Split) 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 SAMS sampler, which uses sequential allocation instead of restricted Gibbs sampling for generating proposals. This can provide computational advantages for certain model configurations.
|
private |
Select clusters for shuffle move.
Determines cluster assignments and prepares for redistribution 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 determine the type of move and the clusters involved.
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 SAMS 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 SAMS 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 SAMS split move.
| likelihood_old_cluster | Likelihood of the original single cluster |
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 using SAMS.
Attempts to merge two clusters into one using sequential allocation to determine the final unified assignment.
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 sequential allocation.
| iterations | Number of allocation passes to perform |
| only_probabilities | If true, only compute proposal probabilities without updating state |
| sequential | If true, use sequential allocation; if false, use restricted Gibbs sampling |
Implements the core SAMS algorithm by sequentially allocating observations to clusters. Unlike restricted Gibbs sampling, this approach processes observations one by one in random order, making allocation decisions based on current partial assignments.
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 |
| sequential | If true, unallocate points before sampling (default true) changing allocations (used in merge move). |
|
private |
Execute a shuffle move using SAMS.
Redistributes observations between two clusters using sequential allocation while maintaining the two-cluster structure.
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 using SAMS.
Attempts to split a cluster using sequential allocation to generate the proposal state. The two anchor observations are placed in separate subclusters initially.
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 SAMS algorithm.
Executes one step of the SAMS sampler:
The sequential allocation approach can be more efficient than restricted Gibbs sampling while maintaining the theoretical properties of split-merge.
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 sequential allocation.
|
private |
Log probability of generating current state via sequential allocation (merge direction).
|
private |
Log probability of generating current state via sequential allocation (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).