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 "Params.hpp"
18#include <Eigen/Dense>
19#include <unordered_map>
20
41class Process {
42protected:
46
49 const Params &params;
50
53 Eigen::VectorXi old_allocations;
54
57 std::unordered_map<int, std::vector<int>> old_cluster_members;
58
60 int old_K = 0;
61
67 [[nodiscard]] const std::unordered_map<int, std::vector<int>> &old_cluster_members_view() const {
69 }
70
72 int idx_i;
73
75 int idx_j;
76
78 const double log_a = log(params.a);
79
80public:
91 Process(Data &d, const Params &p) : data(d), params(p) {
92 old_allocations = data.get_allocations();
93 old_cluster_members = data.get_cluster_map();
94 old_K = data.get_K();
95 };
96
97 // ========== Gibbs Sampling Methods ==========
98
111 virtual double gibbs_prior_existing_cluster(int cls_idx, int obs_idx) const = 0;
112
123
124 virtual Eigen::VectorXd gibbs_prior_existing_clusters(int obs_idx) const = 0;
125
135 virtual double gibbs_prior_new_cluster() const = 0;
136
149 virtual double gibbs_prior_new_cluster_obs(int obs_idx) const {
150 (void)obs_idx;
152 }
153
154 // ========== Split-Merge Algorithm Methods ==========
155
166 virtual double prior_ratio_split(int ci, int cj) const = 0;
167
179 virtual double prior_ratio_merge(int size_old_ci, int size_old_cj) const = 0;
180
194 virtual double prior_ratio_shuffle(int size_old_ci, int size_old_cj, int ci, int cj) const = 0;
195
196 // ========== State Management Methods ==========
197
206 void set_old_allocations(const Eigen::VectorXi &new_allocations) { old_allocations = new_allocations; };
207
216 void set_old_cluster_members(const std::unordered_map<int, std::vector<int>> &new_cluster_members) {
217 old_cluster_members = new_cluster_members;
218 };
219
225 void set_old_K(int new_K) { old_K = new_K; }
226
231
237 [[nodiscard]] const Eigen::VectorXi &old_allocations_view() const { return old_allocations; }
238
244 void set_idx_i(int i) { idx_i = i; };
245
251 void set_idx_j(int j) { idx_j = j; };
252
253 // ========== Parameter Update Methods ==========
254
263 virtual void update_params() = 0;
264
268 virtual ~Process() {};
269};
Data structure for managing point distances and cluster allocations.
Parameter management for Bayesian nonparametric MCMC models.
Manages distance matrices and cluster allocations for points.
Definition Data.hpp:27
void set_old_K(int new_K)
Store current number of clusters for potential rollback.
Definition Process.hpp:225
void restore_state()
Restores the cached state into the data object.
Definition Process.hpp:230
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:149
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:60
const Params & params
Reference to the parameters object containing process hyperparameters.
Definition Process.hpp:49
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:216
const double log_a
Precomputed logarithm of total mass parameter for efficiency.
Definition Process.hpp:78
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:57
void set_old_allocations(const Eigen::VectorXi &new_allocations)
Store current allocations for potential rollback.
Definition Process.hpp:206
int idx_j
Index of second observation involved in split-merge move.
Definition Process.hpp:75
void set_idx_i(int i)
Set index of first observation in split-merge pair.
Definition Process.hpp:244
virtual ~Process()
Virtual destructor for proper cleanup of derived classes.
Definition Process.hpp:268
Eigen::VectorXi old_allocations
Storage for previous allocations to enable rollback in case of rejection or for computation requiring...
Definition Process.hpp:53
int idx_i
Index of first observation involved in split-merge move.
Definition Process.hpp:72
Process(Data &d, const Params &p)
Constructor initializing process with data and parameters.
Definition Process.hpp:91
const Eigen::VectorXi & old_allocations_view() const
Provides read-only access to the stored previous allocations.
Definition Process.hpp:237
void set_idx_j(int j)
Set index of second observation in split-merge pair.
Definition Process.hpp:251
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:67
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:45
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35