Thesis docs
Loading...
Searching...
No Matches
Data.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <Eigen/Dense>
9#include <Rcpp.h>
10#include <RcppEigen.h>
11#include <unordered_map>
12
13// compilation time verbosity level
14#ifndef VERBOSITY_LEVEL
15#define VERBOSITY_LEVEL 0
16#endif
17
26class Data {
27private:
28 Eigen::MatrixXd D;
29 int n;
30
31 Eigen::VectorXi allocations;
32 int K;
33
35 std::unordered_map<int, std::vector<int>> cluster_members;
36
41 void compact_cluster(int old_cluster);
42
43public:
50 Data(const Eigen::MatrixXd &distances,
51 const Eigen::VectorXi &initial_allocations = Eigen::VectorXi());
52
53 // Getters
54
61 double get_distance(int i, int j) const;
62
67 int get_n() const { return n; }
68
73 int get_K() const { return K; }
74
79 const Eigen::VectorXi &get_allocations() const { return allocations; }
80
86 int get_cluster_size(unsigned cluster_index) const {
87 return (cluster_index < K &&
88 cluster_members.find(cluster_index) != cluster_members.end())
89 ? cluster_members.at(cluster_index).size()
90 : 0;
91 }
92
99 int get_cluster_assignment(int index) const {
100 if (index < 0 || index >= n) {
101 throw std::out_of_range("Index out of bounds in get_cluster_assignment");
102 }
103 return allocations(index);
104 }
105
112 Eigen::VectorXi get_cluster_assignments(int cluster) const;
113
114 // Setters
115
122 void set_allocation(int index, int cluster);
123
129 void set_allocations(const Eigen::VectorXi &new_allocations);
130};
void set_allocation(int index, int cluster)
Assigns a point to a cluster.
Definition Data.cpp:103
int get_cluster_assignment(int index) const
Gets the cluster assignment of a specific point.
Definition Data.hpp:99
int get_n() const
Gets the total number of points.
Definition Data.hpp:67
int get_cluster_size(unsigned cluster_index) const
Gets the size of a specific cluster.
Definition Data.hpp:86
Data(const Eigen::MatrixXd &distances, 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:79
void set_allocations(const Eigen::VectorXi &new_allocations)
Sets all cluster allocations at once.
Definition Data.cpp:180
double get_distance(int i, int j) const
Gets the distance between two points.
Definition Data.cpp:41
int get_K() const
Gets the current number of clusters.
Definition Data.hpp:73
Eigen::VectorXi get_cluster_assignments(int cluster) const
Gets all point indices assigned to a specific cluster.
Definition Data.cpp:51