StaticSingleAug
- class selfeeg.augmentation.compose.StaticSingleAug(augmentation: function, arguments: list or dict or list[list or dict] = None)[source]
Single static augmentation with preset arguments.
StaticSingleAugperforms a single data augmentation where the optional arguments are previously set and given during initialization. No random choice of the arguments is performed. The class accepts multiple set of optional arguments. In this case they are called individually at each class call, in a circular manner. This means that the first call uses the first set of arguments, the second will use the second set of arguments, and so on. When the last set of arguments is used, the class will restart from the first set of arguments.To perform an augmentation, simply call the instantiated class (see provided example or check the introductory notebook).
- Parameters:
augmentation (function) – The augmentation function to apply. It can be a custom function, but the first argument must be the element to augment.
arguments (list, dict, list[list or dict], optional) –
The set of arguments to pass to the augmentation function. It can be:
None. In this case the default parameters of the function are used.
2. list. In this case the function is called with the sintax
augmentation(x, *arguments)3. dict. In this case the function is called with the sintax
augmentation(x, **arguments)4. a list of dicts or lists. This is a particular case where multiple combinations of arguments are given. Each element of the list must be a list or a dict with the specific argument combination. Every time
perform_augmentationis called, one of the given combinations is used to perform the data augmentation. The list is followed sequentially with repetition, meaning that the first call uses the first set of arguments of the list, the second call uses the second set of arguments, and so on. When the last element of the list is used, the function will restart scrolling the given list.Default = None
- perform_augmentation(X: ArrayLike)[source]
Apply the augmentation with the given arguments. __call__() will call this method.
Example
>>> import selfeeg.augmentation as aug >>> import torch >>> BatchEEG = torch.zeros(16,32,1024) + torch.sin(torch.linspace(0, 8*np.pi,1024)) >>> Fs = 64 >>> Aug_eye = aug.StaticSingleAug( ... aug.add_eeg_artifact, ... [{'Fs': Fs, 'artifact': 'eye', 'amplitude': 0.5, 'batch_equal': False}, ... {'Fs': Fs, 'artifact': 'eye', 'amplitude': 1.0, 'batch_equal': False}] ... ) >>> BatchEEGaug1 = Aug_eye(BatchEEG) >>> BatchEEGaug2 = Aug_eye(BatchEEG)
plot the augmentations (require matplotlib to be installed)
>>> import matplotlib.pyplot as plt >>> plt.style.use('seaborn-v0_8-white') >>> plt.rcParams['figure.figsize'] = (15.0, 6.0) >>> plt.plot(BatchEEG[0,0],linewidth=2.5) >>> plt.plot(BatchEEGaug1[0,0]) >>> plt.plot(BatchEEGaug2[0,0]) >>> plt.tick_params(axis='both', which='major', labelsize=12) >>> plt.title('Example of addition of EEG eye blink artifact', fontsize=15) >>> plt.legend(['original sample', 'augmented sample amp 0.5', ... 'augmented sample amp 1']) >>> plt.show()