.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/ERP/plot_embedding_MEG.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_ERP_plot_embedding_MEG.py: ============================================ Embedding ERP MEG data in 2D Euclidean space ============================================ Riemannian embeddings via Laplacian Eigenmaps (LE) and Locally Linear Embedding (LLE) of a set of ERP data. Embedding via Laplacian Eigenmaps is referred to as Spectral Embedding (SE). Locally Linear Embedding (LLE) assumes that the local neighborhood of a point on the manifold can be well approximated by the affine subspace spanned by the k-nearest neighbors of the point and finds a low-dimensional embedding of the data based on these affine approximations. Laplacian Eigenmaps (LE) are based on computing the low dimensional representation that best preserves locality instead of local linearity in LLE [1]_. .. GENERATED FROM PYTHON SOURCE LINES 19-38 .. code-block:: default # Authors: Pedro Rodrigues , # Gabriel Wagner vom Berg # License: BSD (3-clause) from pyriemann.estimation import XdawnCovariances from pyriemann.utils.viz import plot_embedding import mne from mne import io from mne.datasets import sample from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt print(__doc__) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Set parameters and read data .. GENERATED FROM PYTHON SOURCE LINES 40-62 .. code-block:: default 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() y = epochs.events[:, -1] .. rst-class:: sphx-glr-script-out .. code-block:: none Filtering raw data in 1 contiguous segment Setting up high-pass filter at 2 Hz IIR filter parameters --------------------- Butterworth highpass zero-phase (two-pass forward and reverse) non-causal filter: - Filter order 8 (effective, after forward-backward) - Cutoff at 2.00 Hz: -6.02 dB .. GENERATED FROM PYTHON SOURCE LINES 63-64 Embedding of Xdawn covariance matrices .. GENERATED FROM PYTHON SOURCE LINES 64-71 .. code-block:: default nfilter = 4 xdwn = XdawnCovariances(estimator='scm', nfilter=nfilter) split = train_test_split(X, y, train_size=0.25, random_state=42) Xtrain, Xtest, ytrain, ytest = split covs = xdwn.fit(Xtrain, ytrain).transform(Xtest) .. GENERATED FROM PYTHON SOURCE LINES 72-74 Laplacian Eigenmaps (LE), also called Spectral Embedding (SE) ------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 74-79 .. code-block:: default plot_embedding(covs, ytest, metric='riemann', embd_type='Spectral', normalize=True) plt.show() .. image-sg:: /auto_examples/ERP/images/sphx_glr_plot_embedding_MEG_001.png :alt: Spectral Embedding of covariances :srcset: /auto_examples/ERP/images/sphx_glr_plot_embedding_MEG_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-82 Locally Linear Embedding (LLE) ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 82-88 .. code-block:: default plot_embedding(covs, ytest, metric='riemann', embd_type='LocallyLinear', normalize=False) plt.show() .. image-sg:: /auto_examples/ERP/images/sphx_glr_plot_embedding_MEG_002.png :alt: LocallyLinear Embedding of covariances :srcset: /auto_examples/ERP/images/sphx_glr_plot_embedding_MEG_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-95 References ---------- .. [1] `Clustering and dimensionality reduction on Riemannian manifolds `_ A. Goh and R Vidal, in 2008 IEEE Conference on Computer Vision and Pattern Recognition. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 20.420 seconds) .. _sphx_glr_download_auto_examples_ERP_plot_embedding_MEG.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_embedding_MEG.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_embedding_MEG.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_