Docs
Toggle main menu visibility
Loading...
Searching...
No Matches
binary_cache.hpp
Go to the documentation of this file.
1
#pragma once
2
7
8
#include "
../../utils/ClusterInfo.hpp
"
9
#include <vector>
10
16
17
class
BinaryCache
:
public
ClusterInfo
{
18
public
:
19
// Important to declare the struct useful.
20
// HINT: If the name changed modified the file which uses it accordingly.
26
struct
ClusterStats
{
27
int
binary_sum
= 0;
28
int
n
= 0;
29
};
30
31
private
:
32
std::vector<ClusterStats>
cluster_stats
;
33
34
public
:
35
const
Eigen::VectorXi
binary_covariates
;
36
37
BinaryCache
(
const
Eigen::VectorXi &allocations_ref,
const
Eigen::VectorXi &
binary_covariates
)
38
:
binary_covariates
(
binary_covariates
) {
39
40
const
int
K = allocations_ref.maxCoeff() + 1;
41
recompute
(K > 0 ? K : 0, allocations_ref);
42
}
43
51
void
set_allocation
(
int
index,
int
cluster,
int
old_cluster)
override
;
52
58
inline
ClusterStats
get_cluster_stats
(
int
cluster)
const
{
return
cluster_stats
[cluster]; }
59
65
inline
const
ClusterStats
&
get_cluster_stats_ref
(
int
cluster)
const
{
return
cluster_stats
[cluster]; }
66
72
void
recompute
(
const
int
K,
const
Eigen::VectorXi &allocations_in)
override
;
73
79
inline
void
move_cluster_info
(
int
from_cluster,
int
to_cluster)
override
{
80
cluster_stats
[to_cluster] = std::move(
cluster_stats
[from_cluster]);
81
};
82
87
void
remove_info
(
int
cluster)
override
{
88
if
(cluster ==
static_cast<
int
>
(
cluster_stats
.size()) - 1) {
89
cluster_stats
.pop_back();
90
}
else
{
91
cluster_stats
.erase(
cluster_stats
.begin() + cluster);
92
}
93
}
94
};
ClusterInfo.hpp
Abstract base class for managing cluster information and caches.
BinaryCache::binary_covariates
const Eigen::VectorXi binary_covariates
Definition
binary_cache.hpp:35
BinaryCache::recompute
void recompute(const int K, const Eigen::VectorXi &allocations_in) override
Recomputes all cluster information from current allocations.
Definition
binary_cache.cpp:8
BinaryCache::get_cluster_stats_ref
const ClusterStats & get_cluster_stats_ref(int cluster) const
Get cluster statistics reference for a specific cluster.
Definition
binary_cache.hpp:65
BinaryCache::remove_info
void remove_info(int cluster) override
Removes information related to a specific cluster.
Definition
binary_cache.hpp:87
BinaryCache::get_cluster_stats
ClusterStats get_cluster_stats(int cluster) const
Get cluster statistics for a specific cluster.
Definition
binary_cache.hpp:58
BinaryCache::move_cluster_info
void move_cluster_info(int from_cluster, int to_cluster) override
Moves cluster information from one cluster to another.
Definition
binary_cache.hpp:79
BinaryCache::BinaryCache
BinaryCache(const Eigen::VectorXi &allocations_ref, const Eigen::VectorXi &binary_covariates)
Definition
binary_cache.hpp:37
BinaryCache::cluster_stats
std::vector< ClusterStats > cluster_stats
Definition
binary_cache.hpp:32
BinaryCache::set_allocation
void set_allocation(int index, int cluster, int old_cluster) override
Assigns a point to a cluster.
Definition
binary_cache.cpp:27
ClusterInfo::ClusterInfo
ClusterInfo()=default
BinaryCache::ClusterStats
Structure to hold statistics for each cluster.
Definition
binary_cache.hpp:26
BinaryCache::ClusterStats::binary_sum
int binary_sum
Definition
binary_cache.hpp:27
BinaryCache::ClusterStats::n
int n
Definition
binary_cache.hpp:28
BNPClust
processes
caches
binary_cache.hpp
Generated by
1.17.0