Estimation
This module implements estimation strategies for covariance matrices inside the network.
- anotherspdnet.estimation.normalize_trace(Sigma_batch: torch.Tensor) torch.Tensor [source]
Normalize covariance by the trace (trace is equal to n_features).
- Parameters:
Sigma_batch (torch.Tensor) – Batch of covariance matrices of shape (…, n_features, n_features), where … are the batches dimensions
- Returns:
Normalized batch of covariance matrices of shape (…, n_features, n_features)
- Return type:
torch.Tensor
- anotherspdnet.estimation.normalize_determinant(Sigma_batch: torch.Tensor) torch.Tensor [source]
Normalize covariance by the determinant (determinant=1).
- Parameters:
Sigma_batch (torch.Tensor) – Batch of covariance matrices of shape (…, n_features, n_features), where … are the batches dimensions
- Returns:
Normalized batch of covariance matrices of shape (…, n_features, n_features)
- Return type:
torch.Tensor
- anotherspdnet.estimation.student_function(x: torch.Tensor, n_features: int, nu: float) torch.Tensor [source]
Student function.
- Parameters:
x (torch.Tensor) – Input tensor.
n_features (int) – Number of features.
nu (float) – Degrees of freedom.
- Returns:
Computed Student function over input tensor.
- Return type:
torch.Tensor
- anotherspdnet.estimation.huber_function(x: torch.Tensor, delta: float, beta: float) torch.Tensor [source]
- Huber function defined as:
u(x) = 1/beta is x <= delta
u(x) = delta/(beta*x) if x > delta
- Parameters:
x (torch.Tensor) – Input tensor.
delta (float) – Threshold value.
beta (float) – Scaling factor.
- Returns:
Computed Huber function over input tensor.
- Return type:
torch.Tensor
- anotherspdnet.estimation.tyler_function(x: torch.Tensor, n_features: int) torch.Tensor [source]
Tyler function.
- Parameters:
x (torch.Tensor) – Input tensor.
n_features (int) – Number of features.
- Returns:
Computed Tyler function over input tensor.
- Return type:
torch.Tensor
- class anotherspdnet.estimation.SCM(*args: Any, **kwargs: Any)[source]
Layer to compute SCM to estimate covariance matrix.
- class anotherspdnet.estimation.Mestimation(*args: Any, **kwargs: Any)[source]
Torch implementation of M-estimators of covariance matrix.
- __init__(m_estimation_function: Callable, n_iter: int = 30, tol: float = 1e-06, verbose: bool = False, assume_centered: bool = False, normalize: Callable | None = None) None [source]
Initializes the M-estimation module.
- Parameters:
m_estimation_function (Callable) – The M-estimation function to use.
n_iter (int, optional (default=30)) – The number of iterations to perform.
tol (float, optional (default=1e-6)) – Tolerance for stopping criterion.
verbose (bool, optional (default=False)) – Whether to display a progress bar during estimation.
assume_centered (bool, optional (default=False)) – Whether to assume that the data is already centered.
normalize (Callable, optional (default=None)) – A function to normalize the covariance matrix. If None, no normalization will be performed.
- forward(X: torch.Tensor, init: torch.Tensor | None = None, **kwargs) torch.Tensor [source]
Compute M-estimator of covariance matrix on a batch of data.
- Parameters:
X (torch.Tensor of shape (..., n_samples, n_features)) – Input tensor, where … are the batches dimensions.
init (torch.Tensor, optional (default=None)) – The initial estimate of the covariance matrix. If None, it will be initialized as the identity matrix. The shape should be (n_features, n_features) in which case, it is repeated over batches dimensions or it can be (…, n_features, n_features), where … are the batches dimensions.
**kwargs – Additional keyword arguments to pass to the M-estimation function.
- Returns:
Estimated covariance matrices (one per batch).
- Return type:
torch.Tensor of shape (…, n_features, n_features)