spd_learn.functional.airm_distance#
- spd_learn.functional.airm_distance(A, B)[source]#
Compute the geodesic distance under the Affine-Invariant Riemannian Metric (AIRM).
The AIRM distance between two SPD matrices \(A\) and \(B\) is defined as the length of the geodesic connecting them:
\[d_{\text{AIRM}}(A, B) = \| \log(A^{-1/2} B A^{-1/2}) \|_F = \sqrt{\sum_{i=1}^{n} \log^2(\lambda_i)}\]where \(\lambda_i\) are the eigenvalues of \(A^{-1/2} B A^{-1/2}\).
This metric is affine-invariant: for any invertible matrix \(W\),
\[d_{\text{AIRM}}(WAW^\top, WBW^\top) = d_{\text{AIRM}}(A, B)\]- Parameters:
A (torch.Tensor) – SPD matrices with shape (…, n, n).
B (torch.Tensor) – SPD matrices with shape (…, n, n). Must be broadcastable with A.
- Returns:
Geodesic distances with shape (…).
- Return type:
Examples
>>> import torch >>> from spd_learn.functional.metrics import airm_distance >>> A = torch.eye(3) >>> B = 2 * torch.eye(3) >>> d = airm_distance(A, B) >>> print(f"Distance: {d.item():.4f}") Distance: 1.2012
See also
airm_geodesic()Geodesic interpolation under AIRM.
exp_map_airm()Riemannian exponential map.
log_map_airm()Riemannian logarithmic map.
log_euclidean_distance()Distance under Log-Euclidean metric.
bures_wasserstein_distance()Distance under Bures-Wasserstein metric.
References
See [Pennec et al., 2006], [Bhatia, 2007] for more details.