|
Docs
|
Locality Sensitive Sampling (LSS) Split-Merge sampler for Bayesian nonparametric models. More...
#include <splitmerge_LSS.hpp>
Public Member Functions | |
| SplitMerge_LSS (Data &d, utils_params &p, Likelihood &l, Process &pr, bool shuffle) | |
| Constructor for LSS (Locality Sensitive Sampling) Split-Merge sampler. | |
| void | step () override |
| Perform one iteration of the LSS 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 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 (bool similarity=false) |
| 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 LSS. | |
| double | compute_acceptance_ratio_split (double likelihood_old_cluster) |
| Compute acceptance ratio for LSS split move. | |
| void | merge_move () |
| Execute a merge move using LSS. | |
| double | compute_acceptance_ratio_merge (double likelihood_old_clusters) |
| Compute acceptance ratio for LSS merge move. | |
| void | shuffle () |
| Execute a shuffle move using LSS. | |
| double | compute_acceptance_ratio_shuffle (double likelihood_old_clusters, int old_ci_size, int old_cj_size) |
| Compute acceptance ratio for LSS shuffle move. | |
Private Attributes | |
| const utils_params & | params |
| 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 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. | |
Locality Sensitive Sampling (LSS) Split-Merge sampler for Bayesian nonparametric models.
This class implements the LSS Split-Merge algorithm, a variant of the split-merge sampler that uses locality sensitive sampling to select anchor points based on similarity information. LSS can be more efficient than standard split-merge for large datasets by focusing computational effort on similar observations.
Key differences from standard Split-Merge:
The algorithm maintains the same three types of moves (split, merge, shuffle) but uses locality sensitive sampling for anchor point selection and sequential allocation for generating proposals within each move type.
|
inline |
Constructor for LSS (Locality Sensitive Sampling) Split-Merge sampler.
| d | Reference to Data object containing observations |
| p | Reference to utils_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 LSS Split-Merge sampler, which uses locality sensitive sampling for anchor point selection and sequential allocation for generating proposals. This can provide computational advantages for large datasets.
|
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.
| similarity | If true, select indices from similar clusters |
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 LSS merge move.
| likelihood_old_clusters | Joint likelihood of the two original clusters |
Compute the log acceptance ratio for a merge move.
| likelihood_old_clusters | The joint log likelihood of clusters ci and cj before the merge. |
|
private |
Compute acceptance ratio for LSS shuffle move.
| likelihood_old_clusters | Joint likelihood of clusters 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 LSS 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 LSS.
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 LSS.
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 LSS.
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 LSS Split-Merge algorithm.
Executes one step of the LSS Split-Merge sampler:
The locality sensitive sampling approach selects similar or dissimilar points based on distance information, while sequential allocation provides efficient proposal generation 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 |
|
private |
Indices of observations in clusters ci and cj.
|
private |
Flag to enable shuffle moves (Mena and Martinez, 2014).