sqfa.distances
Distances between Symmetric Positive Definite matrices.
Functions
|
Compute the affine invariant distance between SPD matrices. |
|
Compute the squared affine invariant distance between SPD matrices. |
|
Compute the Bhattacharyya distance between two Gaussian distributions. |
|
Compute the Calvo & Oller lower bound of the Fisher-Rao squared distance between Gaussians. |
|
Compute the Calvo & Oller lower bound of the Fisher-Rao squared distance between Gaussians. |
|
Compute the exact Fisher-Rao distance between two Gaussian distributions with the same covariance matrix. |
|
Compute the Hellinger distance between two Gaussian distributions. |
|
Compute the Jeffreys divergence between Gaussian distributions. |
|
Compute the log-Euclidean distance between SPD matrices. |
|
Compute the squared log-Euclidean distance between SPD matrices. |
|
Compute the Mahalanobis distance between Gaussian distributions, using the mean covariance matrix for each pair. |
|
Compute the squared Mahalanobis distance between Gaussian distributions, using the mean covariance matrix for each pair. |
|
Compute the Wasserstein distance between Gaussian distributions. |
|
Compute the squared Wasserstein distance between Gaussian distributions. |
- sqfa.distances.affine_invariant(A, B)
Compute the affine invariant distance between SPD matrices. A small epsilon is added inside the square root to avoid gradient instabilities.
- Parameters:
A (torch.Tensor) – Shape (n_batch_A, n_dim, n_dim), the first SPD matrix.
B (torch.Tensor) – Shape (n_batch_B, n_dim, n_dim), the second SPD matrix.
- Returns:
distance – Shape (n_batch_A, n_batch_B), the affine invariant distance.
- Return type:
torch.Tensor
- sqfa.distances.affine_invariant_sq(A, B)
Compute the squared affine invariant distance between SPD matrices.
- Parameters:
A (torch.Tensor) – Shape (n_batch_A, n_dim, n_dim), the first SPD matrix.
B (torch.Tensor) – Shape (n_batch_B, n_dim, n_dim), the second SPD matrix.
- Returns:
distance_squared – Shape (n_batch_A, n_batch_B), the squared affine invariant distance.
- Return type:
torch.Tensor
- sqfa.distances.bhattacharyya(statistics_A, statistics_B)
Compute the Bhattacharyya distance between two Gaussian distributions.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance – Shape (n_classes, n_classes), the lower bound of the Fisher-Rao distance.
- Return type:
torch.Tensor
- sqfa.distances.fisher_rao_lower_bound(statistics_A, statistics_B)
Compute the Calvo & Oller lower bound of the Fisher-Rao squared distance between Gaussians.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance – Shape (n_classes, n_classes), the lower bound of the Fisher-Rao distance.
- Return type:
torch.Tensor
- sqfa.distances.fisher_rao_lower_bound_sq(statistics_A, statistics_B)
Compute the Calvo & Oller lower bound of the Fisher-Rao squared distance between Gaussians.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance_squared – Shape (n_classes, n_classes), the lower bound of the Fisher-Rao squared distance.
- Return type:
torch.Tensor
- sqfa.distances.fisher_rao_same_cov(statistics_A, statistics_B)
Compute the exact Fisher-Rao distance between two Gaussian distributions with the same covariance matrix. The covariance matrix is taken as the mean of the two covariance matrices.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance – Shape (n_classes, n_classes), the Fisher-Rao distance.
- Return type:
torch.Tensor
References
[1]Nielsen, “A Simple Approximation Method for the Fisher–Rao
Distance between Multivariate Normal Distributions” Entropy, vol. 25, no. 4, pp. 654, 2023.
- sqfa.distances.hellinger(statistics_A, statistics_B)
Compute the Hellinger distance between two Gaussian distributions. An epsilon is added inside the square root to avoid gradient instabilities.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance – Shape (n_classes, n_classes), the lower bound of the Fisher-Rao distance.
- Return type:
torch.Tensor
- sqfa.distances.jeffreys(statistics_A, statistics_B)
Compute the Jeffreys divergence between Gaussian distributions.
Jeffreys divergence is the symmetric KL divergence: KL(A || B) + KL(B || A).
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
divergence – Shape (n_classes, n_classes), the Jeffreys divergence.
- Return type:
torch.Tensor
- sqfa.distances.log_euclidean(A, B)
Compute the log-Euclidean distance between SPD matrices. A small epsilon is added inside the square root to avoid gradient instabilities.
- Parameters:
A (torch.Tensor) – Shape (n_batch_A, n_dim, n_dim), the first SPD matrix.
B (torch.Tensor) – Shape (n_batch_B, n_dim, n_dim), the second SPD matrix.
- Returns:
distance – Shape (n_batch_A, n_batch_B), the log-Euclidean distance.
- Return type:
torch.Tensor
- sqfa.distances.log_euclidean_sq(A, B)
Compute the squared log-Euclidean distance between SPD matrices.
- Parameters:
A (torch.Tensor) – Shape (n_batch_A, n_dim, n_dim), the first SPD matrix.
B (torch.Tensor) – Shape (n_batch_B, n_dim, n_dim), the second SPD matrix.
- Returns:
distance_squared – Shape (n_batch_A, n_batch_B), the squared log-Euclidean distance.
- Return type:
torch.Tensor
- sqfa.distances.mahalanobis(statistics_A, statistics_B)
Compute the Mahalanobis distance between Gaussian distributions, using the mean covariance matrix for each pair.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance – Shape (n_classes, n_classes), the Mahalanobis distance.
- Return type:
torch.Tensor
- sqfa.distances.mahalanobis_sq(statistics_A, statistics_B)
Compute the squared Mahalanobis distance between Gaussian distributions, using the mean covariance matrix for each pair.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance_squared – Shape (n_classes, n_classes), the squared Mahalanobis distance.
- Return type:
torch.Tensor
- sqfa.distances.wasserstein(statistics_A, statistics_B)
Compute the Wasserstein distance between Gaussian distributions. A small epsilon is added inside the square root to avoid gradient instabilities.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance – Shape (n_classes, n_classes), the Wasserstein distance.
- Return type:
torch.Tensor
- sqfa.distances.wasserstein_sq(statistics_A, statistics_B)
Compute the squared Wasserstein distance between Gaussian distributions.
- Parameters:
statistics_A (dict) –
Dictionary containing the means and covariances of the first Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
statistics_B (dict) –
Dictionary containing the means and covariances of the second Gaussian distribution, with keys “means” and “covariances”. - The means are a torch.Tensor of shape (n_classes, n_filters) - The covariances are a torch.Tensor of
shape (n_classes, n_filters, n_filters).
- Returns:
distance_squared – Shape (n_classes, n_classes), the squared Wasserstein distance.
- Return type:
torch.Tensor