.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/topology/data/plot_01_vietoris_rips_complex.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 JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_topology_data_plot_01_vietoris_rips_complex.py: Vietoris's complex of a point cloud (1927) ========================================== To define homology for any compact metric space, Leopold Vietoris joined every set of points that are pairwise close. Today this is the Vietoris-Rips complex: at scale :math:`r` (balls of radius :math:`r`), a simplex for every set of points at most :math:`2r` apart. Sampled from a figure eight, the complex at small scales is dust. At the right scale it has :math:`\beta = (1, 2)`, the figure eight's two loops. At large scales everything fills in. Triangles are enough to count loops, and mod-2 coefficients keep the rank computation fast. .. GENERATED FROM PYTHON SOURCE LINES 16-36 .. image-sg:: /api/gallery/topology/data/images/sphx_glr_plot_01_vietoris_rips_complex_001.png :alt: Vietoris-Rips complexes of a noisy figure eight, r = 0.05: $(\beta_0, \beta_1)$ = (46, 0), r = 0.15: $(\beta_0, \beta_1)$ = (13, 0), r = 0.3: $(\beta_0, \beta_1)$ = (1, 1), r = 0.6: $(\beta_0, \beta_1)$ = (1, 2) :srcset: /api/gallery/topology/data/images/sphx_glr_plot_01_vietoris_rips_complex_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none r = 0.05: f = (80, 46, 14), (beta_0, beta_1) = (46, 0) r = 0.15: f = (80, 164, 170), (beta_0, beta_1) = (13, 0) r = 0.30: f = (80, 362, 819), (beta_0, beta_1) = (1, 1) r = 0.60: f = (80, 828, 4453), (beta_0, beta_1) = (1, 2) Text(0.5, 0.98, 'Vietoris-Rips complexes of a noisy figure eight') | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.topology import betti_numbers, vietoris_rips_complex from mathematicskit.topology.visualizers import plot_complex rng = np.random.default_rng(4) t = rng.uniform(0, 2 * np.pi, 80) points = np.column_stack([np.sin(t), np.sin(t) * np.cos(t)]) * [2, 2] + rng.normal(0, 0.04, (80, 2)) radii = [0.05, 0.15, 0.3, 0.6] fig, axes = plt.subplots(1, 4, figsize=(15, 4)) for ax, r in zip(axes, radii, strict=True): K = vietoris_rips_complex(points, r, max_dim=2) betti = betti_numbers(K, field=2)[:2] print(f"r = {r:4.2f}: f = {K.f_vector}, (beta_0, beta_1) = {betti}") plot_complex(K, ax=ax, alpha=0.25, vertex_size=6) ax.set_title(f"r = {r}: $(\\beta_0, \\beta_1)$ = {betti}") ax.axis("off") fig.suptitle("Vietoris-Rips complexes of a noisy figure eight") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.104 seconds) .. _sphx_glr_download_api_gallery_topology_data_plot_01_vietoris_rips_complex.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/topology/data/plot_01_vietoris_rips_complex.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_vietoris_rips_complex.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_vietoris_rips_complex.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_vietoris_rips_complex.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_