Shortcuts

ToDynamicG

class torcheeg.transforms.pyg.ToDynamicG(edge_func: str | Callable = 'gaussian_distance', 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, **kwargs)[source][source]

A transformation method for dynamically constructing the functional connections between electrodes according to the input EEG signals. The obtained graph structure based on functional connections can be applied to the input of the torch_geometric model. In the graph, nodes correspond to electrodes, and edges correspond to associations between electrodes (functionally connected)

TorchEEG provides algorithms to dynamically calculate functional connections between electrodes:

  • Gaussian Distance

  • Absolute Pearson Correlation Coefficient

  • Phase Locking Value

from torcheeg.transforms.pyg import ToDynamicG

t = ToDynamicG(edge_func='gaussian_distance', sigma=1.0, top_k=10, complete_graph=False)
t(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 320], x=[32, 128], edge_weight=[320])

t = ToDynamicG(edge_func='absolute_pearson_correlation_coefficient', threshold=0.1, binary=True)
t(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 310], x=[32, 128], edge_weight=[310])

t = ToDynamicG(edge_func='phase_locking_value')
t(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 992], x=[32, 128], edge_weight=[992])

t = ToDynamicG(edge_func=lambda x, y: (x * y).mean())
t(eeg=np.random.randn(32, 128))['eeg']
>>> Data(edge_index=[2, 1024], x=[32, 128], edge_weight=[1024])
Parameters:
  • edge_func (str or Callable) – Algorithms for computing functional connections. You can use the algorithms provided by TorchEEG, including gaussian_distance, absolute_pearson_correlation_coefficient and phase_locking_value. Or you can use custom functions by passing a callable object containing two parameters representing the signal of the two electrodes, and other named parameters (passed in when initializing the transform), and outputs the value of the functional connection between the two electrodes. (default: gaussian_distance)

  • 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

Read the Docs v: latest
Versions
latest
stable
v1.1.1
v1.1.0
v1.0.11
v1.0.10
v1.0.9
v1.0.8.post1
v1.0.8
v1.0.7
v1.0.6
v1.0.4
v1.0.3
v1.0.2
v1.0.1
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.

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