Thesis docs
Loading...
Searching...
No Matches
splitmerge.hpp
Go to the documentation of this file.
1
14
15#pragma once
16
17#include "../utils/Sampler.hpp"
18
43class SplitMerge : public Sampler {
44private:
45 // ========== Random Number Generation ==========
46
48 mutable std::mt19937 gen;
49
50 // ========== Move Selection Variables ==========
51
53 int idx_i;
54
56 int idx_j;
57
59 int ci;
60
62 int cj;
63
64 // ========== Algorithm Configuration ==========
65
67 bool shuffle_bool = false;
68
69 // ========== State Management ==========
70
72 Eigen::VectorXi launch_state;
73
75 Eigen::VectorXi S;
76
78 Eigen::VectorXi original_allocations;
79
80 // ========== Proposal Probabilities ==========
81
84 double log_split_gibbs_prob = 0;
85
88 double log_merge_gibbs_prob = 0;
89
90 // ========== Debug variables ==========
91 int accepted_split = 0;
92 int accepted_merge = 0;
93 int accepted_shuffle = 0;
94
95 // ========== Move Selection Methods ==========
96
103 void choose_indeces();
104
111 void choose_clusters_shuffle();
112
113 // ========== Proposal Generation ==========
114
126 void restricted_gibbs(int iterations, bool only_probabilities = false);
127
128 // ========== Split Move Implementation ==========
129
137 void split_move();
138
148 double compute_acceptance_ratio_split(double likelihood_old_cluster);
149
150 // ========== Merge Move Implementation ==========
151
158 void merge_move();
159
167 double compute_acceptance_ratio_merge(double likelihood_old_ci,
168 double likelihood_old_cj);
169
170 // ========== Shuffle Move Implementation ==========
171
178 void shuffle();
179
189 double compute_acceptance_ratio_shuffle(double likelihood_old_ci,
190 double likelihood_old_cj,
191 int old_ci_size, int old_cj_size);
192
193public:
194 // ========== Constructor ==========
195
209 SplitMerge(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
210 : Sampler(d, p, l, pr), shuffle_bool(shuffle), gen(rd()) {};
211
212 // ========== MCMC Interface ==========
213
226 void step() override;
227
228 // ========== Accessor Methods ==========
233 int get_accepted_split() const { return accepted_split; };
234
239 int get_accepted_merge() const { return accepted_merge; };
240
245 int get_accepted_shuffle() const { return accepted_shuffle; };
246};
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
SplitMerge(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
Constructor for Split-Merge sampler.
Definition splitmerge.hpp:209
void step() override
Perform one iteration of the split-merge algorithm.
Definition splitmerge.cpp:389
int get_accepted_split() const
Get number of accepted split moves for diagnostics.
Definition splitmerge.hpp:233
int get_accepted_merge() const
Get number of accepted merge moves for diagnostics.
Definition splitmerge.hpp:239
int get_accepted_shuffle() const
Get number of accepted shuffle moves for diagnostics.
Definition splitmerge.hpp:245
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35