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

Split-Merge sampler for Bayesian nonparametric mixture models. More...

#include <splitmerge.hpp>

Inheritance diagram for SplitMerge:
Sampler

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
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

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:

  • Split moves: Divide a cluster into two subclusters
  • Merge moves: Combine two clusters into one
  • Shuffle moves: Redistribute observations between two existing clusters

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.

Note
reference Jain, S. and Neal, R. M. (2004). "A Split-Merge Markov Chain Monte Carlo Procedure for the Dirichlet Process Mixture Model" reference Martinez, A. F. and Mena, R. H. (2014). "On a Nonparametric Change Point Detection Model in Markovian Regimes"
See also
Sampler, SplitMerge_SAMS

Constructor & Destructor Documentation

◆ SplitMerge()

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

Constructor for Split-Merge 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 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.

Member Function Documentation

◆ choose_clusters_shuffle()

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

◆ choose_indeces()

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

◆ compute_acceptance_ratio_merge()

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

Compute acceptance ratio for 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::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 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::compute_acceptance_ratio_split ( double likelihood_old_cluster)
private

Compute acceptance ratio for split move.

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

Computes the Metropolis-Hastings acceptance probability by combining prior ratios, likelihood ratios, and proposal probabilities.

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::get_accepted_merge ( ) const
inline

Get number of accepted merge moves for diagnostics.

Returns
Count of accepted merge moves

◆ get_accepted_shuffle()

int SplitMerge::get_accepted_shuffle ( ) const
inline

Get number of accepted shuffle moves for diagnostics.

Returns
Count of accepted shuffle moves

◆ get_accepted_split()

int SplitMerge::get_accepted_split ( ) const
inline

Get number of accepted split moves for diagnostics.

Returns
Count of accepted split moves

◆ merge_move()

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

◆ restricted_gibbs()

void SplitMerge::restricted_gibbs ( int iterations,
bool only_probabilities = false )
private

Generate proposal state via restricted Gibbs sampling.

Parameters
iterationsNumber of restricted Gibbs iterations to perform
only_probabilitiesIf 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.

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

◆ shuffle()

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

◆ split_move()

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

◆ step()

void SplitMerge::step ( )
overridevirtual

Perform one iteration of the split-merge algorithm.

Executes one step of the split-merge sampler:

  1. Randomly select two observations
  2. Determine move type based on current cluster assignments
  3. Generate proposal via restricted Gibbs sampling
  4. Compute acceptance ratio and accept/reject via Metropolis-Hastings

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.

Member Data Documentation

◆ accepted_merge

int SplitMerge::accepted_merge = 0
private

◆ accepted_shuffle

int SplitMerge::accepted_shuffle = 0
private

◆ accepted_split

int SplitMerge::accepted_split = 0
private

◆ ci

int SplitMerge::ci
private

Cluster assignment of first observation.

◆ cj

int SplitMerge::cj
private

Cluster assignment of second observation.

◆ gen

std::mt19937 SplitMerge::gen
mutableprivate

Mersenne Twister random number generator for sampling operations.

◆ idx_i

int SplitMerge::idx_i
private

Index of first randomly chosen observation.

◆ idx_j

int SplitMerge::idx_j
private

Index of second randomly chosen observation.

◆ launch_state

Eigen::VectorXi SplitMerge::launch_state
private

Launch state for restricted Gibbs sampling.

◆ log_merge_gibbs_prob

double SplitMerge::log_merge_gibbs_prob = 0
private

Log probability of generating current state via restricted Gibbs (merge direction).

◆ log_split_gibbs_prob

double SplitMerge::log_split_gibbs_prob = 0
private

Log probability of generating current state via restricted Gibbs (split direction).

◆ original_allocations

Eigen::VectorXi SplitMerge::original_allocations
private

Original cluster assignments before move proposal.

◆ S

Eigen::VectorXi SplitMerge::S
private

Indices of observations in clusters ci and cj.

◆ shuffle_bool

bool SplitMerge::shuffle_bool = false
private

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


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