Docs
Loading...
Searching...
No Matches
SplitMerge_SAMS Class Reference

Sequential Allocation Merge-Split (SAMS) sampler for Bayesian nonparametric models. More...

#include <splitmerge_SAMS.hpp>

Inheritance diagram for SplitMerge_SAMS:
Sampler

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
Datadata
 Reference to the data object containing observations and current allocations.
const Paramsparams
 Reference to the parameters object containing model hyperparameters and MCMC settings.
const Likelihoodlikelihood
 Reference to the likelihood computation object for evaluating cluster assignments.
Processprocess
 Reference to the stochastic process object (DP, NGGP, DPW, NGGPW).
std::random_device rd
 Random device for generating random numbers across sampling algorithms.

Detailed Description

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:

  • Sequential Allocation: Observations are allocated one by one in random order
  • Simplified Proposals: No need for full restricted Gibbs chains
  • Efficient Computation: Faster proposal generation for large clusters
  • Maintained Ergodicity: Preserves theoretical properties of 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.

Note
reference Dahl, D. B. and Newcomb, S. (2022). "Sequentially allocated merge-split samplers for conjugate Bayesian nonparametric models" reference Martinez, A. F. and Mena, R. H. (2014). "On a Nonparametric Change Point Detection Model in Markovian Regimes"
See also
Sampler, SplitMerge

Constructor & Destructor Documentation

◆ SplitMerge_SAMS()

SplitMerge_SAMS::SplitMerge_SAMS ( Data & d,
Params & p,
Likelihood & l,
Process & pr,
bool shuffle )
inline

Constructor for SAMS (Sequential Allocation Merge-Split) sampler.

Parameters
dReference to Data object containing observations
pReference to Params object with hyperparameters
lReference to Likelihood object for probability computations
prReference to Process object defining the prior
shuffleFlag 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.

Member Function Documentation

◆ choose_clusters_shuffle()

void SplitMerge_SAMS::choose_clusters_shuffle ( )
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.

◆ choose_indeces()

void SplitMerge_SAMS::choose_indeces ( )
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.

◆ compute_acceptance_ratio_merge()

double SplitMerge_SAMS::compute_acceptance_ratio_merge ( double likelihood_old_ci,
double likelihood_old_cj )
private

Compute acceptance ratio for SAMS merge move.

Parameters
likelihood_old_ciLikelihood of first original cluster
likelihood_old_cjLikelihood of second original cluster
Returns
Log acceptance ratio for the merge proposal

Compute the log acceptance ratio for a merge move.

Parameters
likelihood_old_ciThe log likelihood of cluster ci before the merge.
likelihood_old_cjThe log likelihood of cluster cj before the merge.
Returns
The log acceptance ratio for the merge move.

◆ compute_acceptance_ratio_shuffle()

double SplitMerge_SAMS::compute_acceptance_ratio_shuffle ( double likelihood_old_ci,
double likelihood_old_cj,
int old_ci_size,
int old_cj_size )
private

Compute acceptance ratio for SAMS shuffle move.

Parameters
likelihood_old_ciLikelihood of first cluster before shuffle
likelihood_old_cjLikelihood of second cluster before shuffle
old_ci_sizeSize of first cluster before shuffle
old_cj_sizeSize of second cluster before shuffle
Returns
Log acceptance ratio for the shuffle proposal

Compute the log acceptance ratio for a shuffle move.

Returns
The log acceptance ratio for the shuffle move.

◆ compute_acceptance_ratio_split()

double SplitMerge_SAMS::compute_acceptance_ratio_split ( double likelihood_old_cluster)
private

Compute acceptance ratio for SAMS split move.

Parameters
likelihood_old_clusterLikelihood of the original single cluster
Returns
Log acceptance ratio for the split proposal

Compute the log acceptance ratio for a split move.

Parameters
likelihood_old_clusterThe log likelihood of the original cluster before the split.
Returns
The log acceptance ratio for the split move.

◆ get_accepted_merge()

int SplitMerge_SAMS::get_accepted_merge ( ) const
inline

Get number of accepted merge moves for diagnostics.

Returns
Count of accepted merge moves

◆ get_accepted_shuffle()

int SplitMerge_SAMS::get_accepted_shuffle ( ) const
inline

Get number of accepted shuffle moves for diagnostics.

Returns
Count of accepted shuffle moves

◆ get_accepted_split()

int SplitMerge_SAMS::get_accepted_split ( ) const
inline

Get number of accepted split moves for diagnostics.

Returns
Count of accepted split moves

◆ merge_move()

void SplitMerge_SAMS::merge_move ( )
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.

◆ sequential_allocation()

void SplitMerge_SAMS::sequential_allocation ( int iterations,
bool only_probabilities = false,
bool sequential = true )
private

Generate proposal state via sequential allocation.

Parameters
iterationsNumber of allocation passes to perform
only_probabilitiesIf true, only compute proposal probabilities without updating state
sequentialIf 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.

Parameters
iterationsNumber of Gibbs sampling iterations to perform.
only_probabilitiesIf true, only compute the probabilities without
sequentialIf true, unallocate points before sampling (default true) changing allocations (used in merge move).

◆ shuffle()

void SplitMerge_SAMS::shuffle ( )
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.

◆ split_move()

void SplitMerge_SAMS::split_move ( )
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.

◆ step()

void SplitMerge_SAMS::step ( )
overridevirtual

Perform one iteration of the SAMS algorithm.

Executes one step of the SAMS sampler:

  1. Randomly select two observations as anchors
  2. Determine move type based on their current assignments
  3. Generate proposal using sequential allocation
  4. Compute acceptance ratio and accept/reject the proposal

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.

Member Data Documentation

◆ accepted_merge

int SplitMerge_SAMS::accepted_merge = 0
private

◆ accepted_shuffle

int SplitMerge_SAMS::accepted_shuffle = 0
private

◆ accepted_split

int SplitMerge_SAMS::accepted_split = 0
private

◆ ci

int SplitMerge_SAMS::ci
private

Cluster assignment of first observation.

◆ cj

int SplitMerge_SAMS::cj
private

Cluster assignment of second observation.

◆ gen

std::mt19937 SplitMerge_SAMS::gen
mutableprivate

Mersenne Twister random number generator for sampling operations.

◆ idx_i

int SplitMerge_SAMS::idx_i
private

Index of first randomly chosen observation.

◆ idx_j

int SplitMerge_SAMS::idx_j
private

Index of second randomly chosen observation.

◆ launch_state

Eigen::VectorXi SplitMerge_SAMS::launch_state
private

Launch state for sequential allocation.

◆ log_merge_gibbs_prob

double SplitMerge_SAMS::log_merge_gibbs_prob = 0
private

Log probability of generating current state via sequential allocation (merge direction).

◆ log_split_gibbs_prob

double SplitMerge_SAMS::log_split_gibbs_prob = 0
private

Log probability of generating current state via sequential allocation (split direction).

◆ original_allocations

Eigen::VectorXi SplitMerge_SAMS::original_allocations
private

Original cluster assignments before move proposal.

◆ S

Eigen::VectorXi SplitMerge_SAMS::S
private

Indices of observations in clusters ci and cj.

◆ shuffle_bool

bool SplitMerge_SAMS::shuffle_bool = false
private

Flag to enable shuffle moves (Mena and Martinez, 2014).


The documentation for this class was generated from the following files: