spd_learn.models.SPDNet#
- class spd_learn.models.SPDNet(input_type='raw', cov_method=<function covariance>, subspacedim=None, threshold=0.0001, upper=True, n_chans=None, n_outputs=None)[source]#
Bases:
ModuleSymmetric Positive Definite Neural Network (SPDNet).
This class implements the SPDNet model [Huang and Van Gool, 2017]. SPDNet is a deep learning architecture designed for processing SPD matrices, which are common in applications like diffusion tensor imaging and covariance-based representations of EEG signals.
The network consists of a series of layers that operate directly on SPD matrices, preserving their geometric structure. The main layers are:
BiMap: A bilinear mapping layer for linear transformation on the SPD manifold.
ReEig: A rectified eigenvalue layer that clamps eigenvalues as non-linearity.
LogEig: Logarithmic eigenvalue layer mapping SPD matrices to Euclidean space.
- Parameters:
input_type ({"raw", "cov"}, default="raw") – The type of input data. If “raw”, the input is expected to be raw signals (batch, channels, time) and a CovLayer is automatically added to compute covariance matrices. If “cov”, the input is expected to be already valid SPD matrices (batch, channels, channels).
cov_method (Callable, default=covariance) – The covariance estimation method to use when input_type is “raw”. Can be one of covariance, sample_covariance, real_covariance, or cross_covariance.
subspacedim (int, optional) – The subspace dimension for the BiMap layer. If None, it is set to n_chans.
threshold (float, default=1e-4) – The threshold for the rectified eigenvalue layer (ReEig).
upper (bool, default=True) – If True, only the upper triangular part of the matrix is used in the LogEig layer.
n_chans (int) – The number of channels in the input data. This is used to define the size of the covariance matrix and the BiMap layer.
n_outputs (int) – The number of outputs for the final classification layer.
- forward(X: Tensor) Tensor[source]#
Forward pass of the SPDNet model.
- Parameters:
X (torch.Tensor) – Input tensor. If input_type is “raw”, the shape should be (batch_size, n_channels, n_times). If input_type is “cov”, the shape should be (batch_size, n_channels, n_channels).
- Returns:
Output of the classifier, with shape (batch_size, n_outputs).
- Return type: