Docs
Loading...
Searching...
No Matches
Data Class Reference

Manages distance matrices and cluster allocations for points. More...

#include <Data.hpp>

Inheritance diagram for Data:
Datax

Public Member Functions

 Data (const Params &p, const Eigen::VectorXi &initial_allocations=Eigen::VectorXi())
 Constructs a Data object with a distance matrix.
virtual ~Data ()=default
double get_distance (int i, int j) const
 Getters.
int get_n () const
 Gets the total number of points.
int get_K () const
 Gets the current number of clusters.
const Eigen::VectorXi & get_allocations () const
 Gets the cluster allocations vector.
int get_cluster_size (unsigned cluster_index) const
 Gets the size of a specific cluster.
int get_cluster_assignment (int index) const
 Gets the cluster assignment of a specific point.
Eigen::VectorXi get_cluster_assignments (int cluster) const
 Gets all point indices assigned to a specific cluster.
Eigen::Map< const Eigen::VectorXi > get_cluster_assignments_ref (int cluster) const
 Gets all point indices assigned to a specific cluster (map form).
std::unordered_map< int, std::vector< int > > get_cluster_map_copy () const
 Gets the full mapping of clusters to their member points.
virtual void set_allocation (int index, int cluster)
 Setters.
virtual void set_allocations (const Eigen::VectorXi &new_allocations)
 Sets all cluster allocations at once.
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.
const std::unordered_map< int, std::vector< int > > & get_cluster_map () const
 Gets the full mapping of clusters to their member points.

Protected Member Functions

void compact_cluster (int old_cluster)
 Removes an empty cluster and compacts cluster indices.
void set_allocation_wo_compaction (int index, int cluster)
 Assigns a point to a cluster without compaction.

Protected Attributes

const Paramsparams
 Reference to model parameters.
Eigen::VectorXi allocations
 Cluster allocation for each point.
int K
 Current number of clusters.
std::unordered_map< int, std::vector< int > > cluster_members
 Maps cluster indices to vectors of point indices in that cluster.

Detailed Description

Manages distance matrices and cluster allocations for points.

This class stores a distance matrix between points and tracks their cluster assignments. It provides methods to query distances, manage cluster allocations, and maintain cluster membership information.

Constructor & Destructor Documentation

◆ Data()

Data::Data ( const Params & p,
const Eigen::VectorXi & initial_allocations = Eigen::VectorXi() )

Constructs a Data object with a distance matrix.

Parameters
pReference to model parameters
initial_allocationsOptional initial cluster assignments (default: all in one cluster)
Exceptions
std::invalid_argumentif distance matrix is not square

◆ ~Data()

virtual Data::~Data ( )
virtualdefault

Member Function Documentation

◆ compact_cluster()

void Data::compact_cluster ( int old_cluster)
protected

Removes an empty cluster and compacts cluster indices.

Parameters
old_clusterIndex of the cluster to remove

◆ get_allocations()

const Eigen::VectorXi & Data::get_allocations ( ) const
inline

Gets the cluster allocations vector.

Returns
Reference to the allocations vector

◆ get_cluster_assignment()

int Data::get_cluster_assignment ( int index) const
inline

Gets the cluster assignment of a specific point.

Parameters
indexIndex of the point
Returns
Cluster index the point is assigned to
Exceptions
std::out_of_rangeif index is out of bounds

◆ get_cluster_assignments()

Eigen::VectorXi Data::get_cluster_assignments ( int cluster) const

Gets all point indices assigned to a specific cluster.

Parameters
clusterIndex of the cluster
Returns
Vector of point indices in the cluster
Exceptions
std::out_of_rangeif cluster index is invalid

◆ get_cluster_assignments_ref()

Eigen::Map< const Eigen::VectorXi > Data::get_cluster_assignments_ref ( int cluster) const

Gets all point indices assigned to a specific cluster (map form).

Parameters
clusterIndex of the cluster
Returns
Map to vector of point indices in the cluster
Exceptions
std::out_of_rangeif cluster index is invalid

◆ get_cluster_map()

const std::unordered_map< int, std::vector< int > > & Data::get_cluster_map ( ) const
inline

Gets the full mapping of clusters to their member points.

Returns
Reference to the vector of cluster members

◆ get_cluster_map_copy()

std::unordered_map< int, std::vector< int > > Data::get_cluster_map_copy ( ) const
inline

Gets the full mapping of clusters to their member points.

Returns
Unordered map of cluster indices to vectors of point indices

◆ get_cluster_size()

int Data::get_cluster_size ( unsigned cluster_index) const
inline

Gets the size of a specific cluster.

Parameters
cluster_indexIndex of the cluster
Returns
Number of points in the cluster (0 if cluster doesn't exist)

◆ get_distance()

double Data::get_distance ( int i,
int j ) const

Getters.

Gets the distance between two points

Parameters
iIndex of first point
jIndex of second point
Returns
Distance between points i and j

◆ get_K()

int Data::get_K ( ) const
inline

Gets the current number of clusters.

Returns
Number of clusters

◆ get_n()

int Data::get_n ( ) const
inline

Gets the total number of points.

Returns
Number of points

◆ restore_state()

void Data::restore_state ( Eigen::VectorXi & old_allocations,
std::unordered_map< int, std::vector< int > > & old_cluster_members,
int old_K )
virtual

Restores allocations, cluster memberships, and cluster count from a saved state.

Parameters
old_allocationsVector holding the saved allocations (swapped into place)
old_cluster_membersMap of saved cluster memberships (swapped into place)
old_KNumber of clusters in the saved state

Reimplemented in Datax.

◆ set_allocation()

void Data::set_allocation ( int index,
int cluster )
virtual

Setters.

Assigns a point to a cluster

Parameters
indexIndex of the point to reassign
clusterTarget cluster index (K for new cluster, -1 for unallocated)
Exceptions
std::out_of_rangeif index or cluster is invalid

Reimplemented in Datax.

◆ set_allocation_wo_compaction()

void Data::set_allocation_wo_compaction ( int index,
int cluster )
protected

Assigns a point to a cluster without compaction.

Parameters
indexIndex of the point to reassign
clusterTarget cluster index (K for new cluster, -1 for unallocated)
Exceptions
std::out_of_rangeif index or cluster is invalid

◆ set_allocations()

void Data::set_allocations ( const Eigen::VectorXi & new_allocations)
virtual

Sets all cluster allocations at once.

Parameters
new_allocationsVector of cluster assignments for all points
Exceptions
std::invalid_argumentif vector size doesn't match number of points

Reimplemented in Datax.

Member Data Documentation

◆ allocations

Eigen::VectorXi Data::allocations
protected

Cluster allocation for each point.

◆ cluster_members

std::unordered_map<int, std::vector<int> > Data::cluster_members
protected

Maps cluster indices to vectors of point indices in that cluster.

◆ K

int Data::K
protected

Current number of clusters.

◆ params

const Params& Data::params
protected

Reference to model parameters.


The documentation for this class was generated from the following files: