Thesis 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
46class SplitMerge_SAMS : public Sampler {
47private:
48 // ========== Random Number Generation ==========
49
51 mutable std::mt19937 gen;
52
53 // ========== Move Selection Variables ==========
54
56 int idx_i;
57
59 int idx_j;
60
62 int ci;
63
65 int cj;
66
67 // ========== Algorithm Configuration ==========
68
70 bool shuffle_bool = false;
71
72 // ========== State Management ==========
73
75 Eigen::VectorXi launch_state;
76
78 Eigen::VectorXi S;
79
81 Eigen::VectorXi original_allocations;
82
83 // ========== Proposal Probabilities ==========
84
87 double log_split_gibbs_prob = 0;
88
91 double log_merge_gibbs_prob = 0;
92
93 // ========== Debug variables ==========
94 int accepted_split = 0;
95 int accepted_merge = 0;
96 int accepted_shuffle = 0;
97
98 // ========== Move Selection Methods ==========
99
106 void choose_indeces();
107
114 void choose_clusters_shuffle();
115
116 // ========== SAMS-Specific Proposal Generation ==========
117
130 void sequential_allocation(int iterations, bool only_probabilities = false, bool sequential = true);
131
132 // ========== Split Move Implementation ==========
133
141 void split_move();
142
149 double compute_acceptance_ratio_split(double likelihood_old_cluster);
150
151 // ========== Merge Move Implementation ==========
152
159 void merge_move();
160
168 double compute_acceptance_ratio_merge(double likelihood_old_ci,
169 double likelihood_old_cj);
170
171 // ========== Shuffle Move Implementation ==========
172
179 void shuffle();
180
190 double compute_acceptance_ratio_shuffle(double likelihood_old_ci,
191 double likelihood_old_cj,
192 int old_ci_size, int old_cj_size);
193
194public:
195 // ========== Constructor ==========
196
210 SplitMerge_SAMS(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
211 : Sampler(d, p, l, pr), shuffle_bool(shuffle), gen(rd()) {};
212
213 // ========== MCMC Interface ==========
214
227 void step() override;
228
229 // ========== Accessor Methods ==========
234 int get_accepted_split() const { return accepted_split; };
235
240 int get_accepted_merge() const { return accepted_merge; };
241
246 int get_accepted_shuffle() const { return accepted_shuffle; };
247};
Abstract base class for MCMC sampling algorithms.
Manages distance matrices and cluster allocations for points.
Definition Data.hpp:26
Computes log-likelihood for clusters based on distance-based cohesion and repulsion.
Definition Likelihood.hpp:19
Abstract base class for Bayesian nonparametric processes.
Definition Process.hpp:41
Sampler(Data &d, Params &p, Likelihood &l, Process &pr)
Constructor initializing sampler with required components.
Definition Sampler.hpp:98
std::random_device rd
Random device for generating random numbers across sampling algorithms.
Definition Sampler.hpp:74
void step() override
Perform one iteration of the SAMS algorithm.
Definition splitmerge_SAMS.cpp:367
int get_accepted_shuffle() const
Get number of accepted shuffle moves for diagnostics.
Definition splitmerge_SAMS.hpp:246
int get_accepted_split() const
Get number of accepted split moves for diagnostics.
Definition splitmerge_SAMS.hpp:234
int get_accepted_merge() const
Get number of accepted merge moves for diagnostics.
Definition splitmerge_SAMS.hpp:240
SplitMerge_SAMS(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
Constructor for SAMS (Sequential Allocation Merge-Split) sampler.
Definition splitmerge_SAMS.hpp:210
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35