.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/simulated/plot_riemannian_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_auto_examples_simulated_plot_riemannian_gaussian.py: ===================================================================== Sample from the Riemannian Gaussian distribution in the SPD manifold ===================================================================== Spectral embedding of samples from the Riemannian Gaussian distribution with different centerings and dispersions. .. GENERATED FROM PYTHON SOURCE LINES 10-23 .. code-block:: Python # Authors: Pedro Rodrigues # # License: BSD (3-clause) import numpy as np import matplotlib.pyplot as plt from pyriemann.embedding import SpectralEmbedding from pyriemann.datasets import sample_gaussian_spd, generate_random_spd_matrix print(__doc__) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Set parameters for sampling from the Riemannian Gaussian distribution .. GENERATED FROM PYTHON SOURCE LINES 25-51 .. code-block:: Python n_matrices = 100 # how many SPD matrices to generate n_dim = 2 # number of dimensions of the SPD matrices sigma = 1.0 # dispersion of the Gaussian distribution epsilon = 4.0 # parameter for controlling the distance between centers random_state = 42 # ensure reproducibility # Generate the samples on three different conditions mean = generate_random_spd_matrix(n_dim) # random reference point samples_1 = sample_gaussian_spd(n_matrices=n_matrices, mean=mean, sigma=sigma, random_state=random_state) samples_2 = sample_gaussian_spd(n_matrices=n_matrices, mean=mean, sigma=sigma/2, random_state=random_state) samples_3 = sample_gaussian_spd(n_matrices=n_matrices, mean=epsilon*mean, sigma=sigma, random_state=random_state) # Stack all of the samples into one data array for the embedding samples = np.concatenate([samples_1, samples_2, samples_3]) labels = np.array(n_matrices*[1] + n_matrices*[2] + n_matrices*[3]) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Apply the spectral embedding over the SPD matrices .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python lapl = SpectralEmbedding(metric='riemann', n_components=2) embd = lapl.fit_transform(X=samples) .. GENERATED FROM PYTHON SOURCE LINES 57-58 Plot the results .. GENERATED FROM PYTHON SOURCE LINES 58-78 .. code-block:: Python fig, ax = plt.subplots(figsize=(8, 6)) colors = {1: 'C0', 2: 'C1', 3: 'C2'} for i in range(len(samples)): ax.scatter(embd[i, 0], embd[i, 1], c=colors[labels[i]], s=50) ax.scatter([], [], c='C0', s=50, label=r'$\varepsilon = 1.00, \sigma = 1.00$') ax.scatter([], [], c='C1', s=50, label=r'$\varepsilon = 1.00, \sigma = 0.50$') ax.scatter([], [], c='C2', s=50, label=r'$\varepsilon = 4.00, \sigma = 1.00$') ax.set_xticks([-1, -0.5, 0, 0.5, 1.0]) ax.set_xticklabels([-1, -0.5, 0, 0.5, 1.0], fontsize=12) ax.set_yticks([-1, -0.5, 0, 0.5, 1.0]) ax.set_yticklabels([-1, -0.5, 0, 0.5, 1.0], fontsize=12) ax.set_title(r'Spectral embedding of data points (fixed $n_{dim} = 4$)', fontsize=14) ax.set_xlabel(r'$\phi_1$', fontsize=14) ax.set_ylabel(r'$\phi_2$', fontsize=14) ax.legend() plt.show() .. image-sg:: /auto_examples/simulated/images/sphx_glr_plot_riemannian_gaussian_001.png :alt: Spectral embedding of data points (fixed $n_{dim} = 4$) :srcset: /auto_examples/simulated/images/sphx_glr_plot_riemannian_gaussian_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.603 seconds) .. _sphx_glr_download_auto_examples_simulated_plot_riemannian_gaussian.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_riemannian_gaussian.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_riemannian_gaussian.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_