shift_horizontal

selfeeg.augmentation.functional.shift_horizontal(x: ArrayLike, shift_time: float, Fs: float, forward: bool = None, random_shift: bool = False, batch_equal: bool = True) ArrayLike[source]

Shifts temporally the elements of the ArrayLike object.

Shift is applied along the last dimension. The empty elements at beginning or the ending part after shift are set to zero.

Parameters:
  • x (ArrayLike) – the input Tensor or Array. Last dimension must be the EEG time dimension.

  • shift_time (float) – Desired shift in seconds.

  • Fs (float) – The EEG sampling rate in Hz.

  • forward (bool, optional) –

    Whether to shift the EEG forward (True) or backward (False) in time. If left to None, a random selection of the shift direction will be performed.

    Default = None

  • random_shift (bool, optional) –

    Wheter to choose a random shift length lower than or equal to shift_time, i.e., consider shift_time as the exact value to shift or as an upper bound for a random selection. In case of True, the random shift value will be extracted from a uniform distribution with range [0,shift_time], while the forward argument will decide the direction of the shift

    Default = False

  • batch_equal (bool, optional) –

    whether to apply the same shift to all EEG record or not.

    Default = True

Returns:

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

Note

If random shift is set to False and forward is None, then batch_equal will be set to True since no differences in the shift can be applied.

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.shift_horizontal(x, 64, 1, True)
>>> print(xaug[...,0:64].sum()==0) # should return True
>>> print(xaug[...,65].sum()==0 ) # should return False