masking
- selfeeg.augmentation.functional.masking(x: ArrayLike, mask_number: int = 1, masked_ratio: float = 0.1, batch_equal: bool = True) ArrayLike[source]
puts to zero random portions of the ArrayLike object.
maskiing is applied along its last dimension. The function will apply the same masking operation to all Channels of the same EEG. The number of portions to mask and the overall masked ratio can be set as input.
- Parameters:
x (ArrayLike) – The input Tensor or Array. The last two dimensions must refer to the EEG recording (Channels x Samples).
mask_number (int, optional) –
The number of masking blocks, i.e., how many portions of the signal the function must mask. It must be a positive integer. Note that the created portions will have random length, but the overall masked ratio will be the one given as input.
Default = 1
masked_ratio (float, optional) –
The overall percentage of the signal to mask. It must be a scalar in range [0,1].
Default = 0.1
batch_equal (bool, optional) –
Whether to apply the same masking to all elements in the batch or not. It does apply only if x has more than 2 dimensions.
Default = True
- Returns:
x (ArrayLike) – the augmented version of the input Tensor or Array.
Note
mask_number and mask_ratio should be used to tune the number and width of masked blocks. For example, given masked_ratio = 0.50 and mask_number = 3, the number of samples put to 0 will be in total half the signal length with 3 distinct blocks of consecutive zeroes of random length.
Example
>>> import torch >>> import selfeeg.augmentation as aug >>> 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