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

Module providing spatial methods for processes utilizing spatial information. More...

#include <spatial_module_cache.hpp>

Inheritance diagram for SpatialModuleCache:
Module

Public Member Functions

 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.
Spatial Methods
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.
Public Member Functions inherited from Module
 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

Protected Attributes

const Datadata_module
 Reference to data object with cluster assignments.
const double spatial_weight = 1.0
 Weighting factor for spatial similarity.
SpatialCachecache
 Spatial cache for additional optimizations.
Protected Attributes inherited from Module
const Eigen::VectorXi * old_allocations_provider
 Provider function for accessing old allocation state.
const std::unordered_map< int, std::vector< int > > * old_cluster_members_provider
 Provider function for accessing old cluster members map.

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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_coeffWeighting factor for spatial similarity.
old_alloc_providerfunction to access old allocations for split-merge.
old_cluster_members_provider_function to access old cluster members for split-merge.

Member Function Documentation

◆ 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_idxThe index of the cluster (0 to K-1).
old_alloIf 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_idxThe 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_idxThe index of the observation (0 to N-1).
cls_idxThe index of the cluster to consider for neighbor counting.
Returns
The number of neighbors for the observation in the specified cluster.

Implements Module.

Member Data Documentation

◆ cache

SpatialCache& SpatialModuleCache::cache
protected

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: