permutation_signal

selfeeg.augmentation.functional.permutation_signal(x: ArrayLike, segments: int = 10, seg_to_per: int = -1, batch_equal: bool = True) ArrayLike[source]

permutes some portions of the ArrayLike object along its last dimension.

Given an input x where last two dimensions must refer to the EEG recording (Channels x Samples), permutation_signal divides the elements of the last dimension of x into N segments, then chooses M<=N segments and shuffle them. Permutations are equally performed along each Channel of the same EEG.

Parameters:
  • x (ArrayLike) – The input Tensor or Array. The last two dimensions must refer to the EEG recording (Channels x Samples).

  • segments (int, optional) –

    The number of segments in which the last dimension of the input ArrayLike object x must be divided. Must be an integer greater than 1.

    Default = 1

  • seg_to_per (int, optional) –

    The number of segments to permute. Must be an integer greater than 1 and lower than segments. -1 can be used to permute all the segments.

    Default = -1

  • batch_equal (bool, optional) –

    Whether to apply the same permutation to all EEG record or not. If True, the function is called recursively in order to apply a different permutation to all EEGs.

    Default = True

Returns:

x (ArrayLike) – The augmented version of the input Tensor or Array.

Example

>>> import torch
>>> import selfeeg.augmentation as aug
>>> torch.manual_seed(1234)
>>> x = torch.ones(16,32,1024)*2 + torch.sin(torch.linspace(0, 8*torch.pi,1024))
>>> xaug = aug.masking(x, 3, 0.5)
>>> print( torch.isclose(
...     ((xaug[0,0]==0).sum()/len(xaug[0,0])) ,
...     torch.tensor([0.5]), rtol=1e-8,atol=1e-8) ) # should return True
>>> a = xaug[0,0]==0
>>> print( (a[:-1].ne(a[1:])).sum()==6) # should return True