Docs
Loading...
Searching...
No Matches
splitmerge_LSS_SDDS.hpp
Go to the documentation of this file.
1
19
20#pragma once
21
22#include "../utils/Sampler.hpp"
23
65private:
66 // ========== Random Number Generation ==========
67
69 mutable std::mt19937 gen;
70
71 // ========== Move Selection Variables ==========
72
74 int idx_i;
75
77 int idx_j;
78
80 int ci;
81
83 int cj;
84
85 // ========== Algorithm Configuration ==========
86
88 bool shuffle_bool = false;
89
90 // ========== State Management ==========
91
93 Eigen::VectorXi launch_state;
94
96 Eigen::VectorXi S;
97
100
102 const Eigen::VectorXi &original_allocations;
103
104 // ========== Proposal Probabilities ==========
105
108 std::uniform_real_distribution<> dis_real;
109
111 std::uniform_int_distribution<> dis_int;
112
116 Eigen::Vector2d log_probs;
117
120 Eigen::Vector2d probs;
121
125
129
132 const double rand_split_prob = log(0.5);
133
134 // ========== Debug variables ==========
138 int split_moves = 0;
139 int merge_moves = 0;
141
142 // ========== Move Selection Methods ==========
143
156 void choose_indeces(bool similarity = false);
157
165
166 // ========== SAMS-Specific Proposal Generation ==========
167
185 void sequential_allocation(int iterations, bool only_probabilities = false, bool sequential = true);
186
187 // ========== Split Move Implementation ==========
188
199 void smart_split_move();
200
211 void dumb_split_move();
212
227 double compute_acceptance_ratio_split(double likelihood_old_cluster);
228
229 // ========== Merge Move Implementation ==========
230
241 void smart_merge_move();
242
251 void dumb_merge_move();
252
269 double compute_acceptance_ratio_merge(double likelihood_old_ci, double likelihood_old_cj);
270
271 // ========== Shuffle Move Implementation ==========
272
282 void shuffle();
283
300 double compute_acceptance_ratio_shuffle(double likelihood_old_ci, double likelihood_old_cj, int old_ci_size,
301 int old_cj_size);
302
303public:
304 // ========== Constructor ==========
305
327 : Sampler(d, p, l, pr), shuffle_bool(shuffle), original_allocations(pr.old_allocations_view()), gen(rd()),
328 dis_real(0.0, 1.0), dis_int(0, 1) {};
329
330 // ========== MCMC Interface ==========
331
358 void step() override final;
359
360 // ========== Accessor Methods ==========
365 double get_accepted_split() const { return static_cast<double>(accepted_split)/split_moves; };
366
371 double get_accepted_merge() const { return static_cast<double>(accepted_merge)/merge_moves; };
372
377 double get_accepted_shuffle() const { return static_cast<double>(accepted_shuffle)/shuffle_moves; };
378};
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
SplitMerge_LSS_SDDS(Data &d, Params &p, Likelihood &l, Process &pr, bool shuffle)
Constructor for LSS-SDDS (Locality Sensitive Sampling with Smart-split, Dumb-merge,...
Definition splitmerge_LSS_SDDS.hpp:326
std::uniform_int_distribution dis_int
uniform integer distribution for general use
Definition splitmerge_LSS_SDDS.hpp:111
int ci
Cluster assignment of first observation.
Definition splitmerge_LSS_SDDS.hpp:80
int split_moves
Definition splitmerge_LSS_SDDS.hpp:138
void step() override final
Perform one iteration of the LSS-SDDS Split-Merge algorithm.
Definition splitmerge_LSS_SDDS.cpp:396
std::uniform_real_distribution dis_real
uniform distribution between 0 and 1
Definition splitmerge_LSS_SDDS.hpp:108
int shuffle_moves
Definition splitmerge_LSS_SDDS.hpp:140
void dumb_split_move()
Execute a dumb split move with random allocation.
Definition splitmerge_LSS_SDDS.cpp:262
Eigen::Vector2d log_probs
Log probabilities of allocating a point to clusters ci and cj.
Definition splitmerge_LSS_SDDS.hpp:116
double compute_acceptance_ratio_split(double likelihood_old_cluster)
Compute acceptance ratio for LSS split move.
Definition splitmerge_LSS_SDDS.cpp:290
int accepted_merge
Definition splitmerge_LSS_SDDS.hpp:136
int accepted_split
Definition splitmerge_LSS_SDDS.hpp:135
int idx_i
Index of first randomly chosen observation.
Definition splitmerge_LSS_SDDS.hpp:74
void dumb_merge_move()
Execute a dumb merge move with direct merging.
Definition splitmerge_LSS_SDDS.cpp:207
void smart_merge_move()
Execute a smart merge move using sequential allocation.
Definition splitmerge_LSS_SDDS.cpp:180
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_SDDS.cpp:334
void sequential_allocation(int iterations, bool only_probabilities=false, bool sequential=true)
Generate proposal state via sequential allocation.
Definition splitmerge_LSS_SDDS.cpp:104
int merge_moves
Definition splitmerge_LSS_SDDS.hpp:139
double get_accepted_merge() const
Get number of accepted merge moves for diagnostics.
Definition splitmerge_LSS_SDDS.hpp:371
const double rand_split_prob
Constant log probability for random split allocation (dumb split).
Definition splitmerge_LSS_SDDS.hpp:132
Eigen::Vector2d probs
Probabilities of allocating a point to clusters ci and cj.
Definition splitmerge_LSS_SDDS.hpp:120
const Eigen::VectorXi & original_allocations
Cached reference to original allocations stored in the process.
Definition splitmerge_LSS_SDDS.hpp:102
double get_accepted_shuffle() const
Get number of accepted shuffle moves for diagnostics.
Definition splitmerge_LSS_SDDS.hpp:377
Eigen::VectorXi launch_state
Launch state for sequential allocation.
Definition splitmerge_LSS_SDDS.hpp:93
void choose_clusters_shuffle()
Select clusters for shuffle move.
Definition splitmerge_LSS_SDDS.cpp:353
void choose_indeces(bool similarity=false)
Randomly select two observations for split-merge proposal.
Definition splitmerge_LSS_SDDS.cpp:22
std::mt19937 gen
Mersenne Twister random number generator for sampling operations.
Definition splitmerge_LSS_SDDS.hpp:69
bool shuffle_bool
Flag to enable shuffle moves (Mena and Martinez, 2014).
Definition splitmerge_LSS_SDDS.hpp:88
void shuffle()
Execute a shuffle move using LSS.
Definition splitmerge_LSS_SDDS.cpp:306
double compute_acceptance_ratio_merge(double likelihood_old_ci, double likelihood_old_cj)
Compute acceptance ratio for LSS merge move.
Definition splitmerge_LSS_SDDS.cpp:162
Eigen::VectorXi S
Indices of observations in clusters ci and cj.
Definition splitmerge_LSS_SDDS.hpp:96
double get_accepted_split() const
Get number of accepted split moves for diagnostics.
Definition splitmerge_LSS_SDDS.hpp:365
int accepted_shuffle
Definition splitmerge_LSS_SDDS.hpp:137
int idx_j
Index of second randomly chosen observation.
Definition splitmerge_LSS_SDDS.hpp:77
int cj
Cluster assignment of second observation.
Definition splitmerge_LSS_SDDS.hpp:83
double log_merge_gibbs_prob
Log probability of generating current state via sequential allocation (merge direction).
Definition splitmerge_LSS_SDDS.hpp:128
double log_split_gibbs_prob
Log probability of generating current state via sequential allocation (split direction).
Definition splitmerge_LSS_SDDS.hpp:124
int launch_state_size
Size of the launch state and S vectors.
Definition splitmerge_LSS_SDDS.hpp:99
void smart_split_move()
Execute a smart split move using sequential allocation.
Definition splitmerge_LSS_SDDS.cpp:234
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35