EEGSymEncoder

class selfeeg.models.encoders.EEGSymEncoder(Chans: int, Samples: int, Fs: float, scales_time: tuple = (500, 250, 125), lateral_chans: int = 3, first_left: bool = True, F: int = 8, pool: int = 2, dropRate: float = 0.5, ELUalpha: float = 1.0, bias: bool = True, residual: bool = True, seed: int = None)[source]

Pytorch implementation of the EEGSym Encoder.

See EEGSym for some references. The expected input is a 3D tensor with size (Batch x Channels x Samples). However Channel order is expected to be symmetrical along lateral channels to perform the reshaping operation correctly. For instance, if the first channel index refers to the FP1 channel, then the last must refer to the other hemisphere counterpart, i.e. FP2. See the original paper to further understand this operation.

Parameters:
  • Chans (int) – The number of EEG channels.

  • Sample (int) – The number of EEG Samples.

  • Fs (float) – The sampling frequency.

  • scales_time (tuple of 3 float, optional) –

    The portion of EEG (in milliseconds) the short, medium and long temporal convolutional layers must cover. Kernel size will be automatically calculated based on the given sampling rate.

    Default = (500,250,125)

  • lateral_chans (int, optional) –

    The amount of lateral channels. It will be used to reshape the 3D tensor in a 5D tensor with size ( batch x filters x hemisphere x channel x samples ). See the original paper for more info.

    Default = 3

  • first_left (bool, optional) –

    Whether the first half of the channels are of the left hemisphere or not.

    Default = True

  • F (int, optional) –

    The output filters of each branch of the first inception block. Other output will be automatically calculated.

    Default = 8

  • pool (int, optional) –

    The size of the pooling kernel.

    Default = 2

  • dropRate (float, optional) –

    The dropout percentage in range [0,1].

    Default = 0.5

  • bias (bool, optional) –

    If True, adds a learnable bias to the convolutional layers.

    Default = True

  • residual (bool, optional) –

    Whether to add a residual block after the inception block. Currently not implemented, will be added in future releases.

    Default = True

  • seed (int, optional) –

    A custom seed for model initialization. It must be a nonnegative number. If None is passed, no custom seed will be set

    Default = None

Example

>>> import selfeeg.models
>>> import torch
>>> x = torch.randn(4,8,1024)
>>> mdl = models.EEGSymEncoder(8,1024,64)
>>> out = mdl(x)
>>> print(out.shape) # shoud return torch.Size([4, 36])
>>> print(torch.isnan(out).sum()) # shoud return 0