warp_signal

selfeeg.augmentation.functional.warp_signal(x: ArrayLike, segments: int = 10, stretch_strength: float = 2.0, squeeze_strength: float = 0.5, batch_equal: bool = True) ArrayLike[source]

stretches and squeezes portions of the ArrayLike object.

The function is applied along the last dimension of the input ArrayLike object. To do that warp_signal:

  1. divides the last dimension of x into N segments

  2. selects at random a subset segments

  3. stretches those segments according to stretch_strength

  4. squeezes other segments according to squeeze_strength

  5. resamples x to the original dimension. For this part pchip interpolation with a uniform virtual grid is used

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 to consider when dividing the last dimension of x.

    Default = 10

  • stretch_strength (float, optional) –

    The stretch power, i.e. a multiplication factor which determines the number of samples the stretched segment must have.

    Default = 2.

  • squeeze_strength (float, optional) –

    The squeeze power. The same as stretch but for the segments to squeeze.

    Default = 0.5

  • batch_equal (bool, optional) –

    Whether to apply the same warp to all records or not.

    Default = True

Returns:

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

Example

>>> import torch
>>> import selfeeg.augmentation as aug
>>> x = torch.zeros(16,32,1024) + torch.sin(torch.linspace(0, 8*torch.pi,1024))
>>> xaug = aug.warp_signal(x,20)