{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Can two-dimensional topological voids exist in two dimensions?\n", "\n", "#### License: Apache 2.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The classic example of a two-dimensional homology class is the \"void\" surrounded by a sphere in three-dimensional space.\n", "Challenge question: **Can two-dimensional topological voids arise from point clouds in two-dimensional space?**\n", "We will answer this question programmatically by computing Vietoris-Rips persistence homology of random point clouds in the square $[0, 1] \\times [0, 1] \\subset \\mathbb{R}^2$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from giotto.homology import VietorisRipsPersistence as VR\n", "import itertools\n", "\n", "import matplotlib.pyplot as plt\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Initializing the Vietoris-Rips transformer\n", "vr = VR(homology_dimensions=(2,), max_edge_length=np.inf)\n", "n_samples = 15000\n", "n_points = 6" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create n_samples point clouds of n_points points\n", "PCS = np.random.random((n_samples, n_points, 2)) \n", "# Compute persistence diagrams of all point clouds\n", "DGMS = vr.fit_transform(PCS) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "diffs = np.nan_to_num(DGMS[:, :, 1] - DGMS[:, :, 0]) # Compute lifetimes\n", "indices = np.argwhere(diffs != 0) # Indices with non-zero lifetime\n", "print('There are {} persistent homology classes in dimension 2 across all samples!'.format(len(indices[:, 0])))\n", "print('There are {} different point clouds with at least one persistent homology class in dimension 2.'.format(len(np.unique(indices[:, 0]))))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now plot the edges which exist when these persistent homology classes are born.\n", "What do the clique complexes of the resulting graphs remind you of?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i in indices[:, 0]:\n", " for e in itertools.combinations(PCS[i], 2):\n", " if np.linalg.norm(e[0] - e[1]) < DGMS[i, 0, 1] - 0.00001:\n", " edge = np.stack([e[0], e[1]])\n", " plt.plot(edge[:, 0], edge[:, 1])\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }