Module providing spatial methods for processes utilizing spatial information.
More...
#include <spatial_module_cache.hpp>
|
| | SpatialModuleCache (const Data &data_, SpatialCache &spatial_cache_, double spatial_coeff, const Eigen::VectorXi *old_alloc_provider=nullptr, const std::unordered_map< int, std::vector< int > > *old_cluster_members_provider_=nullptr) |
| | Constructs a SpatialModuleCache with parameter and data references.
|
| Eigen::VectorXd | compute_similarity_obs (int obs_idx) const override |
| | Counts neighbors of an observation grouped by cluster membership.
|
| double | compute_similarity_cls (int cls_idx, bool old_allo=false) const override |
| | Counts internal edges within a cluster.
|
| double | compute_similarity_obs (int obs_idx, int cls_idx) const override |
| | Counts neighbors of an observation within a specific cluster.
|
| | Module (const Eigen::VectorXi *old_allocations_provider_=nullptr, const std::unordered_map< int, std::vector< int > > *old_cluster_members_provider_=nullptr) |
| void | set_old_allocations_provider (const Eigen::VectorXi *provider) |
| void | set_old_cluster_members_provider (const std::unordered_map< int, std::vector< int > > *provider) |
| virtual | ~Module ()=default |
Module providing spatial methods for processes utilizing spatial information.
- Note
- This is a work-in-progress class, intended to replace SpatialModule but at the moment it does not work properly.
This class offers utility functions to compute neighbor counts based on an adjacency matrix W, facilitating the incorporation of spatial dependencies in clustering algorithms. The neighbor relationships are cached at construction time for efficient repeated access.
◆ SpatialModuleCache()
| SpatialModuleCache::SpatialModuleCache |
( |
const Data & | data_, |
|
|
SpatialCache & | spatial_cache_, |
|
|
double | spatial_coeff, |
|
|
const Eigen::VectorXi * | old_alloc_provider = nullptr, |
|
|
const std::unordered_map< int, std::vector< int > > * | old_cluster_members_provider_ = nullptr ) |
|
inline |
Constructs a SpatialModuleCache with parameter and data references.
Initializes the neighbor cache by calling neighbor_cache_compute().
- Parameters
-
| data_ | Reference to the Data object with cluster assignments. |
| spatial_cache_ | Precomputed spatial cache. |
| spatial_coeff | Weighting factor for spatial similarity. |
| old_alloc_provider | function to access old allocations for split-merge. |
| old_cluster_members_provider_ | function to access old cluster members for split-merge. |
◆ compute_similarity_cls()
| double SpatialModuleCache::compute_similarity_cls |
( |
int | cls_idx, |
|
|
bool | old_allo = false ) const |
|
overridevirtual |
Counts internal edges within a cluster.
Computes the number of edges where both endpoints belong to the specified cluster. This is calculated as: (1/2) * sum_{i,j in cluster} W(i,j). The division by 2 accounts for the symmetry of W (each edge counted twice).
- Parameters
-
| cls_idx | The index of the cluster (0 to K-1). |
| old_allo | If true, uses old allocations from old_allocations_provider; if false, uses current allocations from data_module (default: false). |
- Returns
- The total number of internal edges in the cluster.
Implements Module.
◆ compute_similarity_obs() [1/2]
| Eigen::VectorXd SpatialModuleCache::compute_similarity_obs |
( |
int | obs_idx | ) |
const |
|
overridevirtual |
Counts neighbors of an observation grouped by cluster membership.
Returns a vector where element k contains the number of neighbors of obs_idx that belong to cluster k.
- Parameters
-
| obs_idx | The index of the observation (0 to N-1). |
- Returns
- A K-dimensional vector of neighbor counts per cluster.
Implements Module.
◆ compute_similarity_obs() [2/2]
| double SpatialModuleCache::compute_similarity_obs |
( |
int | obs_idx, |
|
|
int | cls_idx ) const |
|
overridevirtual |
Counts neighbors of an observation within a specific cluster.
Uses the cached neighbor list to efficiently count how many neighbors of observation obs_idx belong to cluster cls_idx.
- Parameters
-
| obs_idx | The index of the observation (0 to N-1). |
| cls_idx | The index of the cluster to consider for neighbor counting. |
- Returns
- The number of neighbors for the observation in the specified cluster.
Implements Module.
◆ cache
Spatial cache for additional optimizations.
◆ data_module
| const Data& SpatialModuleCache::data_module |
|
protected |
Reference to data object with cluster assignments.
◆ spatial_weight
| const double SpatialModuleCache::spatial_weight = 1.0 |
|
protected |
Weighting factor for spatial similarity.
The documentation for this class was generated from the following files: