Geometries on the SPD manifold¶
The set \(\mathcal{S}_n^{++}\) of \(n \times n\) SPD matrices can carry several
Riemannian (or information) geometries. They lead to different distances,
geodesics and, above all, different means, which is what batch
normalization relies on. Each geometry has its own module under
yetanotherspdnet.functions.spd_geometries, with the same naming pattern:
<geometry>_geodesic, <geometry>_mean, <geometry>_std_scalar, and
exp/log maps where they are needed.
All functions take batches (..., n, n); means reduce over every leading
dimension and return one (n, n) matrix.
Overview¶
Geometry |
Module |
Mean |
Cost |
|
|---|---|---|---|---|
Affine-invariant (AI) |
|
Karcher mean, iterative |
highest |
|
Log-Euclidean (LE) |
|
\(\exp(\frac1N\sum \log P_i)\) |
one eigendecomposition per matrix |
|
Euclidean / left KL |
|
arithmetic \(\frac1N\sum P_i\) |
lowest |
|
Right KL |
|
harmonic \((\frac1N\sum P_i^{-1})^{-1}\) |
low |
|
Symmetrized KL |
|
GAH: AI midpoint of arithmetic and harmonic |
low |
|
Symmetrized KL, adaptive |
|
point \(t\) on the AI geodesic harmonic → arithmetic, \(t\) learned |
low |
|
Bures–Wasserstein (BW) |
|
fixed-point barycenter |
medium |
|
Affine-invariant¶
The reference geometry: invariant under congruence \(P \mapsto A P A^\top\), so it is insensitive to the units and mixing of the underlying signals.
The mean (Fréchet/Karcher mean) has no closed form and is computed by a
fixed-point iteration (affine_invariant_mean(data, n_iterations=5)). The
number of iterations trades accuracy for cost; in batch normalization a few
iterations are usually enough because the running mean smooths the estimate.
Log-Euclidean¶
Maps the manifold to the flat space of symmetric matrices with the matrix logarithm, averages there, and maps back:
A closed form, invariant to similarity (orthogonal changes of basis and scaling) but not to general congruence. A good default when speed matters.
Kullback–Leibler family¶
Seeing \(P\) as the covariance of a zero-mean Gaussian, the Kullback–Leibler divergence gives two dual means: the arithmetic mean (left KL) and the harmonic mean (right KL). The symmetrized KL (Jeffreys) divergence has as mean the affine-invariant midpoint of the two, the GAH mean:
It is almost as cheap as the arithmetic mean and much closer to the AI mean. The adaptive variant replaces \(\tfrac12\) by a parameter \(t\) learned during training.
Bures–Wasserstein¶
The 2-Wasserstein distance between the Gaussians \(\mathcal{N}(0, P_i)\):
Its geometry has non-negative curvature and closed-form exp/log maps:
The barycenter is computed by a fixed-point iteration
(bures_wasserstein_mean(data, n_iterations=...)). BW is the geometry of the
GBWBN batch normalization (see Batch normalization).
Note
Exp_I is only injective on tangent vectors \(V\) such that \(I + V/2\) is
positive definite. Batch normalization transports tangent vectors to the
identity before applying Exp_I; when the data are very spread out, some of
them leave that domain and the centred batch no longer has exactly the
identity as mean. For concentrated data, centring is exact.
Choosing a geometry¶
Default:
"affine_invariant"for fidelity,"log_euclidean"or"geometric_arithmetic_harmonic"when batches are large or matrices big.The arithmetic and harmonic means are the cheapest. They are useful as baselines, but they are biased towards large (respectively small) eigenvalues.
"bures_wasserstein"together withBatchNormSPDMeanScalarVariancegives GBWBN, which also learns a pre/post power transform.