ToG¶
- class torcheeg.transforms.pyg.ToG(adj: List[List], add_self_loop: bool = True, threshold: float | None = None, top_k: int | None = None, binary: bool = False, complete_graph: bool = False, apply_to_baseline: bool = False)[source][source]¶
A transformation method for constructing a graph representation of EEG signals, the results of which are applied to the input of the
torch_geometric
model. In the graph, nodes correspond to electrodes, and edges correspond to associations between electrodes (eg, spatially adjacent or functionally connected)TorchEEG
provides some common graph structures. Consider using the following adjacency matrices depending on the dataset (with different EEG acquisition systems):datasets.constants.emotion_recognition.deap.DEAP_ADJACENCY_MATRIX
datasets.constants.emotion_recognition.dreamer.DREAMER_ADJACENCY_MATRIX
datasets.constants.emotion_recognition.seed.SEED_ADJACENCY_MATRIX
…
from torcheeg.transforms.pyg import ToG from torcheeg.datasets.constants import DEAP_ADJACENCY_MATRIX t = ToG(adj=DEAP_ADJACENCY_MATRIX) t(eeg=np.random.randn(32, 128))['eeg'] >>> torch_geometric.data.Data
- Parameters:
adj (list) – An adjacency matrix represented by a 2D array, each element in the adjacency matrix represents the electrode-to-electrode edge weight. Please keep the order of electrodes in the rows and columns of the adjacency matrix consistent with the EEG signal to be transformed.
add_self_loop (bool) – Whether to add self-loop edges to the graph. (default:
True
)threshold (float, optional) – Used to cut edges when not None. Edges whose weights exceed a threshold are retained. (default:
None
)top_k (int, optional) – Used to cut edges when not None. Keep the k edges connected to each node with the largest weights. (default:
None
)binary (bool) – Whether to binarize the weights on the edges to 0 and 1. If set to True, binarization are done after topk and threshold, the edge weights that still have values are set to 1, otherwise they are set to 0. (default:
False
)complete_graph (bool) – Whether to build as a complete graph. If False, only construct edges between electrodes based on non-zero elements; if True, construct variables between all electrodes and set the weight of non-existing edges to 0. (default:
False
)apply_to_baseline – (bool): Whether to act on the baseline signal at the same time, if the baseline is passed in when calling. (default:
False
)
- __call__(*args, eeg: ndarray | Tensor, baseline: ndarray | None = None, **kwargs) Dict[str, Data] [source][source]¶
- Parameters:
eeg (np.ndarray) – The input EEG signals in shape of [number of electrodes, number of data points].
baseline (torch.Tensor, optional) – The corresponding baseline signal, if apply_to_baseline is set to True and baseline is passed, the baseline signal will be transformed with the same way as the experimental signal.
- Returns:
The graph representation data types that torch_geometric can accept. Nodes correspond to electrodes, and edges are determined via the given adjacency matrix.
- Return type:
torch_geometric.data.Data