spd_learn.modules.SymmetricPositiveDefinite#
- class spd_learn.modules.SymmetricPositiveDefinite(mapping='exp', device=None, dtype=None)[source]#
Bases:
ModuleSymmetric Positive Definite Manifold parametrization.
This module projects a matrix onto the SPD manifold by first ensuring it is symmetric and then applying either the matrix exponential or the matrix softplus function.
- Parameters:
mapping (str, optional) – Mapping from symmetric matrices to SPD matrices. Default is “exp”. Options are: “exp” and “softplus”
device (torch.device, optional) – Device for the module. Default is None. Note: This parametrization class has no parameters or buffers, so device is accepted for API consistency but not used.
dtype (torch.dtype, optional) – Data type for the module. Default is None. Note: This parametrization class has no parameters or buffers, so dtype is accepted for API consistency but not used.
Examples
>>> import torch >>> from spd_learn.modules import SymmetricPositiveDefinite >>> # Using matrix exponential (default) >>> spd_exp = SymmetricPositiveDefinite(mapping="exp") >>> X = torch.randn(2, 3, 3) >>> S = spd_exp(X) # Projects to SPD manifold >>> # Using softplus mapping >>> spd_softplus = SymmetricPositiveDefinite(mapping="softplus") >>> S = spd_softplus(X)
- forward(X)[source]#
Forward pass projecting input onto the SPD manifold.
- Parameters:
X (torch.Tensor) – Input matrix of shape (…, n, n).
- Returns:
The projected SPD matrix of shape (…, n, n).
- Return type:
- right_inverse(X)[source]#
Map from the SPD manifold onto the tangent space at identity.
This is useful for initializing parameters from SPD matrices when using this module as a parametrization.
- Parameters:
X (torch.Tensor) – Input SPD matrix of shape (…, n, n).
- Returns:
The corresponding tangent symmetric matrix.
- Return type: