11#include <unordered_map>
15#ifndef VERBOSITY_LEVEL
16#define VERBOSITY_LEVEL 0
59 Data(
const Params &p,
const Eigen::VectorXi &initial_allocations = Eigen::VectorXi());
108 if (index < 0 || index >=
params.n) {
109 throw std::out_of_range(
"Index out of bounds in get_cluster_assignment");
166 std::unordered_map<
int, std::vector<int>> &old_cluster_members,
int old_K);
Parameter management for Bayesian nonparametric MCMC models.
virtual void set_allocation(int index, int cluster)
Setters.
Definition Data.cpp:182
int get_cluster_assignment(int index) const
Gets the cluster assignment of a specific point.
Definition Data.hpp:107
const std::unordered_map< int, std::vector< int > > & get_cluster_map() const
Gets the full mapping of clusters to their member points.
Definition Data.hpp:172
void compact_cluster(int old_cluster)
Removes an empty cluster and compacts cluster indices.
Definition Data.cpp:76
int get_n() const
Gets the total number of points.
Definition Data.hpp:78
int get_cluster_size(unsigned cluster_index) const
Gets the size of a specific cluster.
Definition Data.hpp:97
std::unordered_map< int, std::vector< int > > get_cluster_map_copy() const
Gets the full mapping of clusters to their member points.
Definition Data.hpp:134
const Params & params
Reference to model parameters.
Definition Data.hpp:29
void set_allocation_wo_compaction(int index, int cluster)
Assigns a point to a cluster without compaction.
Definition Data.cpp:113
std::unordered_map< int, std::vector< int > > cluster_members
Maps cluster indices to vectors of point indices in that cluster.
Definition Data.hpp:35
Data(const Params &p, const Eigen::VectorXi &initial_allocations=Eigen::VectorXi())
Constructs a Data object with a distance matrix.
Definition Data.cpp:10
const Eigen::VectorXi & get_allocations() const
Gets the cluster allocations vector.
Definition Data.hpp:90
virtual void restore_state(Eigen::VectorXi &old_allocations, std::unordered_map< int, std::vector< int > > &old_cluster_members, int old_K)
Restores allocations, cluster memberships, and cluster count from a saved state.
Definition Data.cpp:213
Eigen::VectorXi allocations
Cluster allocation for each point.
Definition Data.hpp:31
Eigen::Map< const Eigen::VectorXi > get_cluster_assignments_ref(int cluster) const
Gets all point indices assigned to a specific cluster (map form).
Definition Data.cpp:59
virtual void set_allocations(const Eigen::VectorXi &new_allocations)
Sets all cluster allocations at once.
Definition Data.cpp:195
double get_distance(int i, int j) const
Getters.
Definition Data.cpp:33
int get_K() const
Gets the current number of clusters.
Definition Data.hpp:84
int K
Current number of clusters.
Definition Data.hpp:32
Eigen::VectorXi get_cluster_assignments(int cluster) const
Gets all point indices assigned to a specific cluster.
Definition Data.cpp:43
Structure containing all parameters needed for the NGGP (Normalized Generalized Gamma Process) and DP...
Definition Params.hpp:35