.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/08_neighbor_embedding/plot_01_spectral_embeddings.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 or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_08_neighbor_embedding_plot_01_spectral_embeddings.py: Laplacian eigenmaps and diffusion maps ====================================== Spectral embeddings use the eigenvectors of a graph operator: Laplacian eigenmaps take the smoothest non-constant functions on the kNN graph, diffusion maps the leading eigenvectors of a random walk on the data, scaled by their eigenvalues so that map distances approximate diffusion distances. Both are global, deterministic and fast, and both serve as initialization of the neighbor-embedding methods (UMAP starts from a spectral layout). .. GENERATED FROM PYTHON SOURCE LINES 12-28 .. image-sg:: /auto_examples/08_neighbor_embedding/images/sphx_glr_plot_01_spectral_embeddings_001.png :alt: Laplacian eigenmap, S curve, diffusion map, S curve, Laplacian eigenmap, swiss roll, diffusion map, swiss roll :srcset: /auto_examples/08_neighbor_embedding/images/sphx_glr_plot_01_spectral_embeddings_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from graphclust import DiffusionMap, LaplacianEigenmap from graphclust.datasets import make_s_curve, make_swiss_roll from graphclust.plotting import plot_embedding fig, axes = plt.subplots(1, 4, figsize=(14, 3.5)) for i, (X, t, name) in enumerate([(*make_s_curve(1500, random_state=0), "S curve"), (*make_swiss_roll(1500, random_state=0), "swiss roll")]): # [snippet:spectral] le = LaplacianEigenmap(k=10).fit(X) dm = DiffusionMap(k=10, alpha=1.0).fit(X) # [/snippet:spectral] plot_embedding(le.embedding_, t, ax=axes[2 * i], s=5, title=f"Laplacian eigenmap, {name}") plot_embedding(dm.embedding_, t, ax=axes[2 * i + 1], s=5, title=f"diffusion map, {name}") plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.622 seconds) .. _sphx_glr_download_auto_examples_08_neighbor_embedding_plot_01_spectral_embeddings.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/graphclust/main?urlpath=lab/tree/notebooks/auto_examples/08_neighbor_embedding/plot_01_spectral_embeddings.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_spectral_embeddings.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_spectral_embeddings.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_spectral_embeddings.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_