.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/make_graph_gaussian.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_make_graph_gaussian.py: Make Gaussian Graph. ======================== This example demonstrates how to create a graph from EEG electrode positions using a gaussian kernel. The example uses the Biosemi 64 channel montage. The graph is created with two different values of sigma (0.1 and 0.3) and epsilon=0.5. .. GENERATED FROM PYTHON SOURCE LINES 8-9 .. code-block:: Python import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import mne import numpy as np from eegrasp import EEGrasp .. GENERATED FROM PYTHON SOURCE LINES 16-23 .. code-block:: Python montage = mne.channels.make_standard_montage('biosemi64') ch_names = montage.ch_names eeg_pos = montage.get_positions()['ch_pos'] # Restructure into array eeg_pos = np.array([pos for _, pos in eeg_pos.items()]) .. GENERATED FROM PYTHON SOURCE LINES 24-33 .. code-block:: Python # Initialize EEGrasp object eegrasp = EEGrasp(coordinates=eeg_pos) # Compute distance matrix Z = eegrasp.compute_distance(method='Euclidean') # Compute weight matrix G = eegrasp.compute_graph(epsilon=0.5, sigma=0.1, distances=Z) W = eegrasp.graph_weights .. GENERATED FROM PYTHON SOURCE LINES 34-39 .. code-block:: Python # Compute new weight matrix G2 = eegrasp.compute_graph(epsilon=0.5, sigma=0.3, distances=Z) W2 = eegrasp.graph_weights .. GENERATED FROM PYTHON SOURCE LINES 40-69 .. code-block:: Python # Plot Montage fig = plt.figure(figsize=(14, 8)) ax = fig.add_subplot(1, 2, 1, projection='3d') montage.plot(kind='3d', axes=ax, show=False) ax.view_init(azim=70, elev=15) # set view angle plt.title('Electrode Positions') # Plot Graph ax = fig.add_subplot(2, 2, 2) im = ax.imshow(W, cmap='viridis') ax.set_title('Weight Matrix (sigma=0.1, epsilon=0.5)') plt.colorbar(im, label='Weight') ax.set_xlabel('Electrode Index') ax.set_ylabel('Electrode Index') # Plot new Graph ax = fig.add_subplot(2, 2, 4) im = ax.imshow(W2, cmap='viridis') ax.set_title('Weight Matrix (sigma=0.3, epsilon=0.5)') plt.colorbar(im, label='Weight') ax.set_xlabel('Electrode Index') ax.set_ylabel('Electrode Index') plt.tight_layout() plt.show() .. image-sg:: /examples/images/sphx_glr_make_graph_gaussian_001.png :alt: Electrode Positions, Weight Matrix (sigma=0.1, epsilon=0.5), Weight Matrix (sigma=0.3, epsilon=0.5) :srcset: /examples/images/sphx_glr_make_graph_gaussian_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.788 seconds) **Estimated memory usage:** 189 MB .. _sphx_glr_download_examples_make_graph_gaussian.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: make_graph_gaussian.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: make_graph_gaussian.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: make_graph_gaussian.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_