Shortcuts

after_hook_running_norm

class torcheeg.transforms.after_hook_running_norm(data: List[ndarray | Tensor], decay_rate: float = 0.9, eps: float = 1e-06)[source][source]

A common hook function used to normalize the signal of the whole trial/session/subject after dividing it into chunks and transforming the divided chunks.

It is used as follows:

from torcheeg.datasets import DEAPDataset
from torcheeg.transforms import after_hook_running_norm
from torcheeg.datasets.constants import DEAP_CHANNEL_LOCATION_DICT

dataset = DEAPDataset(root_path='./data_preprocessed_python',
                      offline_transform=transforms.Compose([
                          transforms.BandDifferentialEntropy(),
                          transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
                      ]),
                      online_transform=transforms.ToTensor(),
                      after_trial=after_hook_running_norm,
                      label_transform=transforms.Compose([
                          transforms.Select('valence'),
                          transforms.Binary(5.0),
                      ]))

If you want to pass in parameters, use partial to generate a new function:

from functools import partial
from torcheeg.datasets import DEAPDataset
from torcheeg.transforms import after_hook_running_norm

dataset = DEAPDataset(root_path='./data_preprocessed_python',
                      offline_transform=transforms.Compose([
                          transforms.BandDifferentialEntropy(),
                          transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
                      ]),
                      online_transform=transforms.ToTensor(),
                      after_trial=partial(after_hook_running_norm, decay_rate=0.9, eps=1e-6),
                      label_transform=transforms.Compose([
                          transforms.Select('valence'),
                          transforms.Binary(5.0),
                      ]))
Parameters:
  • data (list) – A list of np.ndarray or torch.Tensor, one of which corresponds to an EEG signal in trial.

  • decay_rate (float) – The decay rate used in the running normalization (default: 0.9)

  • eps (float) – The term added to the denominator to improve numerical stability (default: 1e-6)

Returns:

The normalized results of a trial. It is a list of np.ndarray or torch.Tensor, one of which corresponds to an EEG signal in trial.

Return type:

list

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources