Function Repository Resource:

PersistentHomology

Source Notebook

Perform persistent homology on a point cloud dataset

Contributed by: Andrew Ortegaray

ResourceFunction["PersistentHomology"][{e1,e2,}]

performs persistent homology on the ei and returns a PersistentHomologyObject that can be queried for results.

ResourceFunction["PersistentHomology"][{e1,e2,},"Modulus"p]

performs persistent homology over the coefficient field p.

Details and Options

ResourceFunction["PersistentHomology"] works for any dataset where the ei are numerical lists of the same length.
The following options can be given:
"Distance""Maximal"the maximal distance scale to perform homology
"Modulus"2the characteristic of the coefficient field used

Examples

Basic Examples (3) 

Perform persistent homology on random data:

In[1]:=
SeedRandom[314]; data = RandomReal[{0, 1}, {10, 3} ];
ph = ResourceFunction["PersistentHomology"][data]
Out[1]=

Query the output for the barcode:

In[2]:=
ph["Barcode"]
Out[2]=

Visualize the MeshRegion for the H1 generator found:

In[3]:=
ph["GeneratorMeshes"][[10]]
Out[3]=

Scope (2) 

Dimensionality (2) 

PersistentHomology can be performed for data of any dimension:

In[4]:=
data = RandomReal[{0, 1}, {10, 42}];
In[5]:=
ResourceFunction["PersistentHomology"][data]
Out[5]=

Evaluate the persistent homology of data with dimension 1000:

In[6]:=
data = RandomReal[{0, 1}, {10, 1000}];
In[7]:=
ResourceFunction["PersistentHomology"][data]
Out[7]=

Options (3) 

Distance (2) 

The maximum distance used in computations can be specified:

In[8]:=
data = RandomReal[{0, 1}, {10, 3}];
In[9]:=
ResourceFunction["PersistentHomology"][data, "Distance" -> 0.75]
Out[9]=

This will sometimes speed up computation times:

In[10]:=
AbsoluteTiming[
 ResourceFunction["PersistentHomology"][data, "Distance" -> 0.75]]
Out[10]=
In[11]:=
AbsoluteTiming[ResourceFunction["PersistentHomology"][data]]
Out[11]=

Modulus (1) 

The finite field chosen for computations can be specified:

In[12]:=
data = RandomReal[{0, 1}, {10, 3}];
In[13]:=
ResourceFunction["PersistentHomology"][data, "Modulus" -> 7]
Out[13]=

Properties and Relations (1) 

PersistentHomology is invariant under isometries:

In[14]:=
data = SpherePoints[10];
In[15]:=
ResourceFunction["PersistentHomology"][data]["Barcode"]
Out[15]=
In[16]:=
ResourceFunction[
  "PersistentHomology"][({0, 0, 1} + #1 &) /@ SpherePoints[10]]["Barcode"]
Out[16]=
In[17]:=
ResourceFunction["PersistentHomology"][
  RotationTransform[\[Pi]/4, {1, 1, 1}][data]]["Barcode"]
Out[17]=

Possible Issues (1) 

PersistentHomology computation times grow quickly in the number of data points:

In[18]:=
data = RandomReal[{0, 1}, {20, 3}];
AbsoluteTiming[ResourceFunction["PersistentHomology"][data[[1 ;; 5]]]]
Out[18]=
In[19]:=
AbsoluteTiming[
 ResourceFunction["PersistentHomology"][data[[1 ;; 10]]]]
Out[19]=
In[20]:=
AbsoluteTiming[
 ResourceFunction["PersistentHomology"][data[[1 ;; 15]]]]
Out[20]=
In[21]:=
AbsoluteTiming[
 ResourceFunction["PersistentHomology"][data[[1 ;; 20]]]]
Out[21]=

Neat Examples (1) 

Draw some data in and perform PersistentHomology on it:

In[22]:=
DynamicModule[{data = {}, phom = Graphics[{}]},
 Column[{
   Button["Compute", phom = ResourceFunction["PersistentHomology"][data]["Barcode"]],
   Row@{ClickPane[
      Framed@Dynamic[
        ListPlot[data, PlotRange -> { {-1, 1}, {-1, 1} }, PlotStyle -> PointSize[Large], ImageSize -> 250, PlotLabel -> Length[data]], Initialization :> {introdata = {{-0.6276498538011699, 0.2755882642199108}, {-0.4923245614035091, 0.5533552010221645}, {-0.2955729166666671, 0.6799858764026732}, {-0.09562317251462027, 0.5479957591277764}, {-0.1305738304093571, 0.16936042970631437`}, {-0.3572505482456144, -0.12215624768016273`}, {-0.5747898391812869, 0.00902071289351639}, {
           0.25758406432748493`, 0.46985879247442125`}, {
           0.413788377192982, 0.7182412030281331}, {
           0.7561220760233913, 0.6458332949515377}, {
           0.7347176535087716, 0.19375513074283965`}, {
           0.6180327119883036, -0.1418198551823316}, {
           0.4325886330409352, -0.18868725050704988`}, {
           0.20876736111111072`, -0.11716642246814621`}, {
           0.19435307017543813`, 0.19434651743463421`}}}], AppendTo[data, #] &], Dynamic[Show[phom, ImageSize -> 250]]}
   }, Alignment -> Left
  ]]
Out[22]=

Publisher

Wolfram Summer School

Version History

  • 1.0.1 – 15 March 2021
  • 1.0.0 – 29 July 2020

Source Metadata

License Information