LabelMapping#

class dpeeg.transforms.LabelMapping(mapping: ndarray | None = None, order: bool = True)[source]#

Rearrange the original label according to mapping rules.

Parameters:
  • mapping (ndarray (2, label_num), optional) – Label mapping relationship. The first row is the original label, and the second row is the mapped label. If None, the label will be reordered in ascending order starting from zero.

  • order (bool) – Force the new labels to start incrementing from zero.

Returns:

data – Transformed eegdata.

Return type:

eegdata or dataset

Examples

>>> eegdata = dpeeg.EEGData(edata=np.random.randn(16, 3, 10),
...                         label=np.random.randint(0, 3, 16))
>>> eegdata['label']
array([3, 2, 2, 2, 3, 2, 4, 3, 4, 3, 3, 2, 4, 4, 2, 3])

Merge labels as needed:

>>> transforms.LabelMapping(
...     np.array([[2, 3, 4], [0, 0, 1]])
... )(eegdata, verbose=False)
>>> eegdata["label"]
array([0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0])