Computes and stores pairwise spatial distances between high-dimensional data points.
More...
Computes and stores pairwise spatial distances between high-dimensional data points.
Efficiently computes the upper triangle of the distance matrix to save memory, utilizing OpenMP for multi-threaded parallel execution. Provides fast access to mean distances, spatial quantiles, and the spatial correlation integral.
| void cmp::statistics::PairwiseDistanceStats::compute |
( |
const Eigen::MatrixXd & |
data | ) |
|
|
inline |
Computes the upper triangle of the pairwise Euclidean distance matrix.
Mathematical Formulation
Evaluates the \( L_2 \)-norm between all unique pairs:
\[
d_{ij} = ||\mathbf{x}_i - \mathbf{x}_j||_2 \quad \text{for } 1 \le i < j \le N
\]
Utilizes OpenMP dynamic scheduling to balance the uneven workload of the triangular nested loops.
- Parameters
-
| data | Matrix of size (N, D) where N is number of points, D is dimensions. |
- Exceptions
-
| std::invalid_argument | if fewer than 2 points are provided. |
| std::vector< double > cmp::statistics::PairwiseDistanceStats::correlation_integral |
( |
const std::vector< double > & |
r_thresholds | ) |
const |
|
inline |
Computes the spatial Correlation Integral \( C(r) \) for a grid of radial thresholds.
Mathematical Formulation
Computes the fraction of pairwise distances strictly less than \( r \):
\[
C(r) = \frac{2}{N(N-1)} \sum_{i=1}^{N-1} \sum_{j=i+1}^N \Theta(r - d_{ij})
\]
where \( \Theta \) is the Heaviside step function.
- ### Implementation Algorithm
- Copies and sorts the requested threshold bounds \( r \).
- Utilizes OpenMP parallelization and binary search (
std::upper_bound) in \( \mathcal{O}(\log K) \) to rapidly bin every pairwise distance into thread-local histograms.
- Calculates the cumulative sum globally to construct the integral profile \( C(r) \).
- Parameters
-
| r_thresholds | A vector of spatial radii ( \( r \)). Does not need to be pre-sorted. |
- Returns
- std::vector<double> The fraction of pairwise distances less than each corresponding radius \( r \).
- Exceptions
-
| std::runtime_error | if called before compute(). |