Docs
Loading...
Searching...
No Matches
splitmerge_SAMS.hpp
Go to the documentation of this file.
1
13
14#pragma once
15
16#include "../utils/Sampler.hpp"
17
47class SplitMerge_SAMS : public Sampler {
48private:
49 // ========== Random Number Generation ==========
50
52 mutable std::mt19937 gen;
53
54 // ========== Move Selection Variables ==========
55
57 int idx_i;
58
60 int idx_j;
61
63 int ci;
64
66 int cj;
67
68 // ========== Algorithm Configuration ==========
69
71 bool shuffle_bool = false;
72
73 // ========== State Management ==========
74
76 Eigen::VectorXi launch_state;
77
79 Eigen::VectorXi S;
80
82 Eigen::VectorXi original_allocations;
83
84 // ========== Proposal Probabilities ==========
85
89
93
94 // ========== Debug variables ==========
98
99 // ========== Move Selection Methods ==========
100
107 void choose_indeces();
108
116
117 // ========== SAMS-Specific Proposal Generation ==========
118
132 void sequential_allocation(int iterations, bool only_probabilities = false, bool sequential = true);
133
134 // ========== Split Move Implementation ==========
135
143 void split_move();
144
151 double compute_acceptance_ratio_split(double likelihood_old_cluster);
152
153 // ========== Merge Move Implementation ==========
154
161 void merge_move();
162
170 double compute_acceptance_ratio_merge(double likelihood_old_ci,
171 double likelihood_old_cj);
172
173 // ========== Shuffle Move Implementation ==========
174
181 void shuffle();
182
192 double compute_acceptance_ratio_shuffle(double likelihood_old_ci,
193 double likelihood_old_cj,
194 int old_ci_size, int old_cj_size);
195
196public:
197 // ========== Constructor ==========
198
213 : Sampler(d, p, l, pr), shuffle_bool(shuffle), gen(rd()) {};
214
215 // ========== MCMC Interface ==========
216
229 void step() override;
230
231 // ========== Accessor Methods ==========
236 int get_accepted_split() const { return accepted_split; };
237
242 int get_accepted_merge() const { return accepted_merge; };
243
248 int get_accepted_shuffle() const { return accepted_shuffle; };
249};
Abstract base class for MCMC sampling algorithms.
Manages distance matrices and cluster allocations for points.
Definition Data.hpp:27
Abstract base class for likelihood computation.
Definition Likelihood.hpp:27
Abstract base class for Bayesian nonparametric processes.
Definition Process.hpp:41
Sampler(Data &d, const Params &p, const Likelihood &l, Process &pr)
Constructor initializing sampler with required components.
Definition Sampler.hpp:97
std::random_device rd
Random device for generating random numbers across sampling algorithms.
Definition Sampler.hpp:73
int ci
Cluster assignment of first observation.
Definition splitmerge_SAMS.hpp:63
void choose_clusters_shuffle()
Select clusters for shuffle move.
Definition splitmerge_SAMS.cpp:340
void step() override
Perform one iteration of the SAMS algorithm.
Definition splitmerge_SAMS.cpp:392
void sequential_allocation(int iterations, bool only_probabilities=false, bool sequential=true)
Generate proposal state via sequential allocation.
Definition splitmerge_SAMS.cpp:93
Eigen::VectorXi launch_state
Launch state for sequential allocation.
Definition splitmerge_SAMS.hpp:76
int accepted_merge
Definition splitmerge_SAMS.hpp:96
void split_move()
Execute a split move using SAMS.
Definition splitmerge_SAMS.cpp:219
double log_split_gibbs_prob
Log probability of generating current state via sequential allocation (split direction).
Definition splitmerge_SAMS.hpp:88
int get_accepted_shuffle() const
Get number of accepted shuffle moves for diagnostics.
Definition splitmerge_SAMS.hpp:248
int accepted_shuffle
Definition splitmerge_SAMS.hpp:97
void merge_move()
Execute a merge move using SAMS.
Definition splitmerge_SAMS.cpp:184
bool shuffle_bool
Flag to enable shuffle moves (Mena and Martinez, 2014).
Definition splitmerge_SAMS.hpp:71
void choose_indeces()
Randomly select two observations for split-merge proposal.
Definition splitmerge_SAMS.cpp:16
double log_merge_gibbs_prob
Log probability of generating current state via sequential allocation (merge direction).
Definition splitmerge_SAMS.hpp:92
int idx_i
Index of first randomly chosen observation.
Definition splitmerge_SAMS.hpp:57
Eigen::VectorXi S
Indices of observations in clusters ci and cj.
Definition splitmerge_SAMS.hpp:79
std::mt19937 gen
Mersenne Twister random number generator for sampling operations.
Definition splitmerge_SAMS.hpp:52
Eigen::VectorXi original_allocations
Original cluster assignments before move proposal.
Definition splitmerge_SAMS.hpp:82
double compute_acceptance_ratio_merge(double likelihood_old_ci, double likelihood_old_cj)
Compute acceptance ratio for SAMS merge move.
Definition splitmerge_SAMS.cpp:159
int get_accepted_split() const
Get number of accepted split moves for diagnostics.
Definition splitmerge_SAMS.hpp:236
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.
Definition splitmerge_SAMS.cpp:316
double compute_acceptance_ratio_split(double likelihood_old_cluster)
Compute acceptance ratio for SAMS split move.
Definition splitmerge_SAMS.cpp:257
int cj
Cluster assignment of second observation.
Definition splitmerge_SAMS.hpp:66
int get_accepted_merge() const
Get number of accepted merge moves for diagnostics.
Definition splitmerge_SAMS.hpp:242
void shuffle()
Execute a shuffle move using SAMS.
Definition splitmerge_SAMS.cpp:279
int idx_j
Index of second randomly chosen observation.
Definition splitmerge_SAMS.hpp:60
int accepted_split
Definition splitmerge_SAMS.hpp:95
SplitMerge_SAMS(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
Constructor for SAMS (Sequential Allocation Merge-Split) sampler.
Definition splitmerge_SAMS.hpp:212
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35