|
Docs
|
Manages distance matrices and cluster allocations for points. More...
#include <Data.hpp>
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 Params & | params |
| 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. | |
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.
| Data::Data | ( | const Params & | p, |
| const Eigen::VectorXi & | initial_allocations = Eigen::VectorXi() ) |
Constructs a Data object with a distance matrix.
| p | Reference to model parameters |
| initial_allocations | Optional initial cluster assignments (default: all in one cluster) |
| std::invalid_argument | if distance matrix is not square |
|
virtualdefault |
|
protected |
Removes an empty cluster and compacts cluster indices.
| old_cluster | Index of the cluster to remove |
|
inline |
Gets the cluster allocations vector.
|
inline |
Gets the cluster assignment of a specific point.
| index | Index of the point |
| std::out_of_range | if index is out of bounds |
| Eigen::VectorXi Data::get_cluster_assignments | ( | int | cluster | ) | const |
Gets all point indices assigned to a specific cluster.
| cluster | Index of the cluster |
| std::out_of_range | if cluster index is invalid |
| Eigen::Map< const Eigen::VectorXi > Data::get_cluster_assignments_ref | ( | int | cluster | ) | const |
Gets all point indices assigned to a specific cluster (map form).
| cluster | Index of the cluster |
| std::out_of_range | if cluster index is invalid |
|
inline |
Gets the full mapping of clusters to their member points.
|
inline |
Gets the full mapping of clusters to their member points.
|
inline |
Gets the size of a specific cluster.
| cluster_index | Index of the cluster |
| double Data::get_distance | ( | int | i, |
| int | j ) const |
Getters.
Gets the distance between two points
| i | Index of first point |
| j | Index of second point |
|
inline |
Gets the current number of clusters.
|
inline |
Gets the total number of points.
|
virtual |
Restores allocations, cluster memberships, and cluster count from a saved state.
| old_allocations | Vector holding the saved allocations (swapped into place) |
| old_cluster_members | Map of saved cluster memberships (swapped into place) |
| old_K | Number of clusters in the saved state |
Reimplemented in Datax.
|
virtual |
Setters.
Assigns a point to a cluster
| index | Index of the point to reassign |
| cluster | Target cluster index (K for new cluster, -1 for unallocated) |
| std::out_of_range | if index or cluster is invalid |
Reimplemented in Datax.
|
protected |
Assigns a point to a cluster without compaction.
| index | Index of the point to reassign |
| cluster | Target cluster index (K for new cluster, -1 for unallocated) |
| std::out_of_range | if index or cluster is invalid |
|
virtual |
Sets all cluster allocations at once.
| new_allocations | Vector of cluster assignments for all points |
| std::invalid_argument | if vector size doesn't match number of points |
Reimplemented in Datax.
|
protected |
Cluster allocation for each point.
|
protected |
Maps cluster indices to vectors of point indices in that cluster.
|
protected |
Current number of clusters.
|
protected |
Reference to model parameters.