spd_learn.models.GyroAtt#
- class spd_learn.models.GyroAtt(n_patches: int = 6, n_chans: int = 22, n_outputs: int = 2, temporal_out_channels: int = 20, temporal_kernel_size: int = 25, temporal_padding: int | None = None, attention_in_features: int = 20, attention_out_features: int = 18, attention_type: str = 'gyro', metric: str = 'LEM', drop_prob: float = 0.0, covariance_method=<function sample_covariance>, spatial_filters: int | None = None, att_out_features: int | None = None, temporal_filters: int | None = None)[source]#
Bases:
MAttGyrovector Riemannian Attention Network for EEG Decoding.
Implements the full deep architecture for EEG decoding introduced in GyroAtt [Wang et al., 2025].
The architecture comprises:
Spatiotemporal Frontend: Spatial and temporal 2D convolutions (inherited from MAtt).
Patch Covariance Embedding: Signal segmentation into patches via
PatchEmbeddingLayer, sample covariance estimation viaCovLayer, and trace normalization viaTraceNorm.Riemannian Attention: Either
GyroSPDAttention(orthogonal gyro-automorphisms and Fréchet aggregation) orSymSPDAttention(tangent space projections viaSPDLinear).Classification Backend: Riemannian ReEig activation, LogEig tangent projection, dropout, and linear classification.
- Parameters:
n_patches (int, default=6) – Number of temporal patches.
n_chans (int, default=22) – Number of EEG channels.
n_outputs (int, default=2) – Number of output classification classes.
temporal_out_channels (int, default=20) – Number of output channels for the temporal convolution.
temporal_kernel_size (int, default=25) – Kernel size for the temporal convolution along the time dimension.
temporal_padding (int, optional) – Padding along time for the temporal convolution. Defaults to
temporal_kernel_size // 2.attention_in_features (int, default=20) – Input feature dimension for the attention module.
attention_out_features (int, default=18) – Feature dimensionality of the attention output SPD matrices.
attention_type ({"gyro", "sym"}, default="gyro") – Type of Riemannian attention module to use.
metric ({"LEM", "LCM"}, default="LEM") – Riemannian metric used in the attention mechanism.
drop_prob (float, default=0.0) – Dropout probability before the final linear classifier.
covariance_method (callable, default=sample_covariance) – Method used for computing sample covariances.
spatial_filters (int, optional) – Alias for
temporal_out_channelsandattention_in_features.att_out_features (int, optional) – Alias for
attention_out_features.temporal_filters (int, optional) – Alias for intermediate feature dimension.
References
[1]Rui Wang, Chen Hu, Xiaoning Song, Xiaojun Wu, Nicu Sebe, and Ziheng Chen. Towards a general attention framework on gyrovector spaces for matrix manifolds. In Advances in Neural Information Processing Systems, volume 38. 2025. URL: https://openreview.net/forum?id=ChenHu-ML/GyroAtt.
Examples
>>> import torch >>> from spd_learn.models import GyroAtt >>> model = GyroAtt(n_chans=22, n_outputs=2, attention_type="gyro") >>> x = torch.randn(4, 22, 1000) >>> out = model(x) >>> out.shape torch.Size([4, 2])
- forward(x: Tensor) Tensor[source]#
Forward pass of GyroAtt.
- Parameters:
x (torch.Tensor) – Input tensor of shape (batch, n_chans, n_times) or precomputed covariance patches of shape (batch, n_patches, spatial_filters, spatial_filters).
- Returns:
Logits of shape (batch, n_outputs).
- Return type: