Docs
Loading...
Searching...
No Matches
Process.hpp
Go to the documentation of this file.
1
13
14#pragma once
15
16#include "Data.hpp"
17#include <Eigen/Dense>
18#include <unordered_map>
19
40class Process {
41protected:
45
48 Eigen::VectorXi old_allocations;
49
52 std::unordered_map<int, std::vector<int>> old_cluster_members;
53
55 int old_K = 0;
56
62 [[nodiscard]] const std::unordered_map<int, std::vector<int>> &
66
68 int idx_i;
69
71 int idx_j;
72
73public:
83 Process(Data &d) : data(d) {
84 old_allocations = data.get_allocations();
85 old_cluster_members = data.get_cluster_map();
86 old_K = data.get_K();
87 };
88
89 // ========== Gibbs Sampling Methods ==========
90
103 virtual double gibbs_prior_existing_cluster(int cls_idx,
104 int obs_idx) const = 0;
105
116
117 virtual Eigen::VectorXd gibbs_prior_existing_clusters(int obs_idx) const = 0;
118
128 virtual double gibbs_prior_new_cluster() const = 0;
129
142 virtual double gibbs_prior_new_cluster_obs(int obs_idx) const {
143 (void)obs_idx;
145 }
146
147 // ========== Split-Merge Algorithm Methods ==========
148
159 virtual double prior_ratio_split(int ci, int cj) const = 0;
160
172 virtual double prior_ratio_merge(int size_old_ci, int size_old_cj) const = 0;
173
187 virtual double prior_ratio_shuffle(int size_old_ci, int size_old_cj, int ci,
188 int cj) const = 0;
189
190 // ========== State Management Methods ==========
191
200 void set_old_allocations(const Eigen::VectorXi &new_allocations) {
201 old_allocations = new_allocations;
202 };
203
213 const std::unordered_map<int, std::vector<int>> &new_cluster_members) {
214 old_cluster_members = new_cluster_members;
215 };
216
222 void set_old_K(int new_K) { old_K = new_K; }
223
229 }
230
236 [[nodiscard]] const Eigen::VectorXi &old_allocations_view() const {
237 return old_allocations;
238 }
239
245 void set_idx_i(int i) { idx_i = i; };
246
252 void set_idx_j(int j) { idx_j = j; };
253
254 // ========== Parameter Update Methods ==========
255
264 virtual void update_params() = 0;
265
269 virtual ~Process() {};
270};
Data structure for managing point distances and cluster allocations.
Manages distance matrices and cluster allocations for points.
Definition Data.hpp:26
void set_old_K(int new_K)
Store current number of clusters for potential rollback.
Definition Process.hpp:222
void restore_state()
Restores the cached state into the data object.
Definition Process.hpp:227
virtual double gibbs_prior_new_cluster_obs(int obs_idx) const
Compute prior probability for creating a new cluster for a specific observation.
Definition Process.hpp:142
Process(Data &d)
Constructor initializing process with data and parameters.
Definition Process.hpp:83
virtual double gibbs_prior_existing_cluster(int cls_idx, int obs_idx) const =0
Compute prior probability for assigning observation to existing cluster.
int old_K
Number of clusters associated with the stored previous state.
Definition Process.hpp:55
virtual double prior_ratio_split(int ci, int cj) const =0
Compute prior ratio for split move in split-merge algorithm.
void set_old_cluster_members(const std::unordered_map< int, std::vector< int > > &new_cluster_members)
Store current cluster members for potential rollback.
Definition Process.hpp:212
virtual double prior_ratio_shuffle(int size_old_ci, int size_old_cj, int ci, int cj) const =0
Compute prior ratio for shuffle move in split-merge algorithm.
virtual double prior_ratio_merge(int size_old_ci, int size_old_cj) const =0
Compute prior ratio for merge move in split-merge algorithm.
std::unordered_map< int, std::vector< int > > old_cluster_members
Storage for previous cluster members to enable rollback in case of rejection or for computation requi...
Definition Process.hpp:52
void set_old_allocations(const Eigen::VectorXi &new_allocations)
Store current allocations for potential rollback.
Definition Process.hpp:200
int idx_j
Index of second observation involved in split-merge move.
Definition Process.hpp:71
void set_idx_i(int i)
Set index of first observation in split-merge pair.
Definition Process.hpp:245
virtual ~Process()
Virtual destructor for proper cleanup of derived classes.
Definition Process.hpp:269
Eigen::VectorXi old_allocations
Storage for previous allocations to enable rollback in case of rejection or for computation requiring...
Definition Process.hpp:48
int idx_i
Index of first observation involved in split-merge move.
Definition Process.hpp:68
const Eigen::VectorXi & old_allocations_view() const
Provides read-only access to the stored previous allocations.
Definition Process.hpp:236
void set_idx_j(int j)
Set index of second observation in split-merge pair.
Definition Process.hpp:252
virtual Eigen::VectorXd gibbs_prior_existing_clusters(int obs_idx) const =0
Compute prior probabilities for assigning observation to all existing clusters.
const std::unordered_map< int, std::vector< int > > & old_cluster_members_view() const
Provides read-only access to the stored previous cluster members.
Definition Process.hpp:63
virtual void update_params()=0
Update process parameters during MCMC sampling.
virtual double gibbs_prior_new_cluster() const =0
Compute prior probability for creating a new cluster.
Data & data
Reference to the data object containing observations and allocations.
Definition Process.hpp:44