spd_learn.functional.grassmann_distance#

spd_learn.functional.grassmann_distance(U: Tensor, V: Tensor, metric: str = 'geodesic') → Tensor[source]#

Distance between the column spans of two bases.

With principal angles \(\theta_i\) between the subspaces \(\operatorname{span}(U)\) and \(\operatorname{span}(V)\) [Knyazev and Argentati, 2002]:

\[d_{\text{geodesic}} = \|\theta\|_2, \quad d_{\text{chordal}} = \|\sin\theta\|_2, \quad d_{\text{FS}} = \arccos\prod_i \cos\theta_i, \quad d_{\text{BC}} = \sqrt{1 - \prod_i \cos^2\theta_i}.\]

The chordal distance equals the projection distance \(\|P_U - P_V\|_F / \sqrt{2}\) between the orthogonal projectors.

Bases are orthonormalised by QR; full column rank is assumed. Complex bases are supported. The computation runs outside autocast, because half-precision matmuls destroy the small-angle accuracy. First derivatives are finite everywhere; second derivatives are not at repeated angles.

Parameters:
  • U (Tensor) – Bases of shape (..., n, k) with k <= n, with identical shapes.

  • V (Tensor) – Bases of shape (..., n, k) with k <= n, with identical shapes.

  • metric ({"geodesic", "chordal", "fubini_study", "binet_cauchy"}) – Distance to compute.

Returns:

Distances of shape (...).

Return type:

Tensor

Raises:

ValueError – If the shapes differ, k > n (bases passed as rows), or metric is unknown.