spd_learn.models.GeodesicCCALoss#
- class spd_learn.models.GeodesicCCALoss(outdim_size: int = 10, eps: float = 0.0001)[source]#
Bases:
ModuleGeodesic Canonical Correlation Analysis (GeodesicCCA) Loss.
Computes the negative geodesic canonical correlation loss between two batches of Symmetric Positive Definite (SPD) matrices [Ju et al., 2024].
Each batch of SPD matrices \(Y_1, Y_2 \in \mathbb{P}_d\) is mapped to the tangent space at their empirical Fréchet mean via the matrix logarithm:
\[L_1 = \log(Y_1), \quad L_2 = \log(Y_2)\]The tangent matrices are centered across the batch and vectorized into Euclidean representations \(H_1, H_2 \in \mathbb{R}^{B \times m}\) where \(m = d(d+1)/2\). Regularized covariance matrices are then computed:
\[\Sigma_{11} = \frac{1}{N} H_1^\top H_1 + \epsilon I_m, \quad \Sigma_{22} = \frac{1}{N} H_2^\top H_2 + \epsilon I_m, \quad \Sigma_{12} = \frac{1}{N} H_1^\top H_2\]where \(N = \max(B - 1, 1)\). The whitened cross-correlation matrix \(T = \Sigma_{11}^{-1/2} \Sigma_{12} \Sigma_{22}^{-1/2}\) is formed, and its top-\(k\) singular values \(\rho_i\) (\(k = \min(\text{outdim\_size}, m)\)) are extracted via the eigendecomposition of \(T^\top T + \epsilon I_m\). The loss returned is the negative sum of these canonical correlations:
\[\mathcal{L}_{\text{GeoCCA}} = -\sum_{i=1}^k \rho_i\]- Parameters:
- forward(Y1: Tensor, Y2: Tensor) Tensor[source]#
Compute the negative geodesic canonical correlation loss.
- Parameters:
Y1 (torch.Tensor) – Batch of SPD matrices from view 1 of shape (batch_size, d, d).
Y2 (torch.Tensor) – Batch of SPD matrices from view 2 of shape (batch_size, d, d).
- Returns:
Scalar negative total geodesic correlation.
- Return type: