.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/biosignal-erp/plot_embedding_MEG.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_auto_examples_biosignal-erp_plot_embedding_MEG.py: =============================================== Comparison of embeddings of covariance matrices =============================================== Comparison of several embeddings of a set of ERP covariance matrices extracted on MEG data: SE, LLE and t-SNE Spectral Embedding (SE) is based on computing the low-dimensional representation that best preserves locality instead of local linearity in LLE [1]_. Locally Linear Embedding (LLE) assumes that the local neighborhood of a matrix on the manifold can be well approximated by the affine subspace spanned by the k-nearest neighbors of the matrix and finds a low-dimensional embedding of the data based on these affine approximations. t-SNE reduces SPD matrices into lower dimensional SPD matrices by computing conditional probabilities that represent similarities [2]_. This fully Riemannian algorithm helps preserve the non-Euclidean structure of the data. .. GENERATED FROM PYTHON SOURCE LINES 22-39 .. code-block:: Python # Authors: Pedro Rodrigues , # Gabriel Wagner vom Berg # Thibault de Surrel # # License: BSD (3-clause) import matplotlib.pyplot as plt import mne from mne import io from mne.datasets import sample from sklearn.model_selection import train_test_split from pyriemann.estimation import XdawnCovariances from pyriemann.utils.viz import plot_embedding print(__doc__) .. GENERATED FROM PYTHON SOURCE LINES 40-42 Set parameters and read data ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-64 .. code-block:: Python data_path = str(sample.data_path()) raw_fname = data_path + "/MEG/sample/sample_audvis_filt-0-40_raw.fif" event_fname = data_path + "/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif" tmin, tmax = -0., 1 event_id = dict(aud_l=1, aud_r=2, vis_l=3, vis_r=4) # Setup for reading the raw data raw = io.Raw(raw_fname, preload=True, verbose=False) raw.filter(2, None, method="iir") # replace baselining with high-pass events = mne.read_events(event_fname) raw.info["bads"] = ["MEG 2443"] # set bad channels picks = mne.pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False, exclude="bads") # Read epochs epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=False, picks=picks, baseline=None, preload=True, verbose=False) X = epochs.get_data(copy=False) y = epochs.events[:, -1] .. rst-class:: sphx-glr-script-out .. code-block:: none Using default location ~/mne_data for sample... 0%| | 0.00/1.65G [00:00`_ A. Goh and R Vidal, in 2008 IEEE Conference on Computer Vision and Pattern Recognition. .. [2] `Geometry-Aware visualization of high dimensional Symmetric Positive Definite matrices `_ T. de Surrel, S. Chevallier, F. Lotte and F. Yger. Transactions on Machine Learning Research, 2025 .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 0.360 seconds) .. _sphx_glr_download_auto_examples_biosignal-erp_plot_embedding_MEG.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_embedding_MEG.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_embedding_MEG.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_embedding_MEG.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_