A new minor TorchEEG version release, bringing new transform operation supports to TorchEEG. It further includes some new features. More feedback was taken to improve TorchEEG usability.
Transforms
TorchEEG further supports a large number of practical torch-based data augmentation methods.
- RandomWindowSlice
python
transform = RandomWindowSlice()
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
transform = RandomWindowSlice(window_size=100)
transform(eeg=torch.randn(1, 32, 128))['eeg'].shape
>>> (1, 32, 128)
transform = RandomWindowSlice(p=1.0, series_dim=0)
transform(eeg=torch.randn(128, 9, 9))['eeg'].shape
>>> (128, 9, 9)
* RandomWindowWarp
python
transform = RandomWindowWarp()
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
transform = RandomWindowWarp(window_size=24, warp_size=48)
transform(eeg=torch.randn(1, 32, 128))['eeg'].shape
>>> (1, 32, 128)
transform = RandomWindowWarp(p=1.0, series_dim=0)
transform(eeg=torch.randn(128, 9, 9))['eeg'].shape
>>> (128, 9, 9)
* RandomPCANoise
python
transform = RandomPCANoise()
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
transform = RandomPCANoise(mean=0.5, std=2.0, n_components=4)
transform(eeg=torch.randn(1, 32, 128))['eeg'].shape
>>> (1, 32, 128)
transform = RandomPCANoise(p=1.0, series_dim=0)
transform(eeg=torch.randn(128, 9, 9))['eeg'].shape
>>> (128, 9, 9)
* RandomFlip
python
transform = RandomFlip(dim=-1)
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
transform = RandomFlip(dim=1)
transform(eeg=torch.randn(128, 9, 9))['eeg'].shape
>>> (128, 9, 9)
* RandomSignFlip
python
transform = RandomSignFlip()
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
* RandomShift
python
transform = RandomShift(dim=-1, shift_min=8, shift_max=24)
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
* RandomChannelShuffle
python
transform = RandomChannelShuffle()
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
* RandomFrequencyShift
python
transform = RandomFrequencyShift()
transform(eeg=torch.randn(32, 128))['eeg'].shape
>>> (32, 128)
transform = RandomFrequencyShift(frequency=128, shift_min=4.0)
transform(eeg=torch.randn(1, 32, 128))['eeg'].shape
>>> (1, 32, 128)
transform = RandomFrequencyShift(p=1.0, series_dim=0)
transform(eeg=torch.randn(128, 9, 9))['eeg'].shape
>>> (128, 9, 9)
On the transformation of constructing graphs, TorchEEG provides a dynamic graph constructing strategy, which makes some GNN algorithms based on computational functional connections more easily implemented.
* ToDynamicG
python
transform = ToDynamicG(edge_func='gaussian_distance', sigma=1.0, top_k=10, complete_graph=False)
transform(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 320], x=[32, 128], edge_weight=[320])
transform = ToDynamicG(edge_func='absolute_pearson_correlation_coefficient', threshold=0.1, binary=True)
transform(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 310], x=[32, 128], edge_weight=[310])
transform = ToDynamicG(edge_func='phase_locking_value')
transform(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 992], x=[32, 128], edge_weight=[992])
transform = ToDynamicG(edge_func=lambda x, y: (x * y).mean())
transform(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 1024], x=[32, 128], edge_weight=[1024])
Utils
In terms of visualization, TorchEEG further supports the visualization of graph data structures to help users debug graph structures.
- plot_graph
python
eeg = np.random.randn(32, 128)
g = ToG(DEAP_ADJACENCY_MATRIX)(eeg=eeg)['eeg']
plot_graph(g)