Docs
Loading...
Searching...
No Matches
splitmerge_LSS.hpp
Go to the documentation of this file.
1
14
15#pragma once
16
17#include "../utils/Sampler.hpp"
18
51class SplitMerge_LSS : public Sampler {
52private:
53 // ========== Random Number Generation ==========
54
56 mutable std::mt19937 gen;
57
58 // ========== Move Selection Variables ==========
59
61 int idx_i;
62
64 int idx_j;
65
67 int ci;
68
70 int cj;
71
72 // ========== Algorithm Configuration ==========
73
75 bool shuffle_bool = false;
76
77 // ========== State Management ==========
78
80 Eigen::VectorXi launch_state;
81
83 Eigen::VectorXi S;
84
86 Eigen::VectorXi original_allocations;
87
88 // ========== Proposal Probabilities ==========
89
93
97
98 // ========== Debug variables ==========
102
103 // ========== Move Selection Methods ==========
104
112 void choose_indeces(bool similarity = false);
113
121
122 // ========== SAMS-Specific Proposal Generation ==========
123
138 void sequential_allocation(int iterations, bool only_probabilities = false,
139 bool sequential = true);
140
141 // ========== Split Move Implementation ==========
142
150 void split_move();
151
158 double compute_acceptance_ratio_split(double likelihood_old_cluster);
159
160 // ========== Merge Move Implementation ==========
161
168 void merge_move();
169
177 double compute_acceptance_ratio_merge(double likelihood_old_ci,
178 double likelihood_old_cj);
179
180 // ========== Shuffle Move Implementation ==========
181
188 void shuffle();
189
199 double compute_acceptance_ratio_shuffle(double likelihood_old_ci,
200 double likelihood_old_cj,
201 int old_ci_size, int old_cj_size);
202
203public:
204 // ========== Constructor ==========
205
222 : Sampler(d, p, l, pr), shuffle_bool(shuffle), gen(rd()) {};
223
224 // ========== MCMC Interface ==========
225
240 void step() override;
241
242 // ========== Accessor Methods ==========
247 int get_accepted_split() const { return accepted_split; };
248
253 int get_accepted_merge() const { return accepted_merge; };
254
259 int get_accepted_shuffle() const { return accepted_shuffle; };
260};
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 get_accepted_split() const
Get number of accepted split moves for diagnostics.
Definition splitmerge_LSS.hpp:247
double log_merge_gibbs_prob
Log probability of generating current state via sequential allocation (merge direction).
Definition splitmerge_LSS.hpp:96
int accepted_split
Definition splitmerge_LSS.hpp:99
Eigen::VectorXi S
Indices of observations in clusters ci and cj.
Definition splitmerge_LSS.hpp:83
double compute_acceptance_ratio_merge(double likelihood_old_ci, double likelihood_old_cj)
Compute acceptance ratio for LSS merge move.
Definition splitmerge_LSS.cpp:195
double compute_acceptance_ratio_split(double likelihood_old_cluster)
Compute acceptance ratio for LSS split move.
Definition splitmerge_LSS.cpp:296
void merge_move()
Execute a merge move using LSS.
Definition splitmerge_LSS.cpp:220
SplitMerge_LSS(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
Constructor for LSS (Locality Sensitive Sampling) Split-Merge sampler.
Definition splitmerge_LSS.hpp:221
Eigen::VectorXi launch_state
Launch state for sequential allocation.
Definition splitmerge_LSS.hpp:80
int accepted_merge
Definition splitmerge_LSS.hpp:100
void split_move()
Execute a split move using LSS.
Definition splitmerge_LSS.cpp:257
int cj
Cluster assignment of second observation.
Definition splitmerge_LSS.hpp:70
void choose_indeces(bool similarity=false)
Randomly select two observations for split-merge proposal.
Definition splitmerge_LSS.cpp:19
void step() override
Perform one iteration of the LSS Split-Merge algorithm.
Definition splitmerge_LSS.cpp:434
Eigen::VectorXi original_allocations
Original cluster assignments before move proposal.
Definition splitmerge_LSS.hpp:86
int accepted_shuffle
Definition splitmerge_LSS.hpp:101
int idx_j
Index of second randomly chosen observation.
Definition splitmerge_LSS.hpp:64
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 LSS shuffle move.
Definition splitmerge_LSS.cpp:357
std::mt19937 gen
Mersenne Twister random number generator for sampling operations.
Definition splitmerge_LSS.hpp:56
void choose_clusters_shuffle()
Select clusters for shuffle move.
Definition splitmerge_LSS.cpp:382
int get_accepted_merge() const
Get number of accepted merge moves for diagnostics.
Definition splitmerge_LSS.hpp:253
int get_accepted_shuffle() const
Get number of accepted shuffle moves for diagnostics.
Definition splitmerge_LSS.hpp:259
void sequential_allocation(int iterations, bool only_probabilities=false, bool sequential=true)
Generate proposal state via sequential allocation.
Definition splitmerge_LSS.cpp:122
int idx_i
Index of first randomly chosen observation.
Definition splitmerge_LSS.hpp:61
double log_split_gibbs_prob
Log probability of generating current state via sequential allocation (split direction).
Definition splitmerge_LSS.hpp:92
void shuffle()
Execute a shuffle move using LSS.
Definition splitmerge_LSS.cpp:318
bool shuffle_bool
Flag to enable shuffle moves (Mena and Martinez, 2014).
Definition splitmerge_LSS.hpp:75
int ci
Cluster assignment of first observation.
Definition splitmerge_LSS.hpp:67
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35