Skip to content

Commit

Permalink
updated persistent homology tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamknockillaree authored Aug 18, 2023
1 parent e055d7e commit 343f1c4
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 21 deletions.
9 changes: 6 additions & 3 deletions tutorial/chap0.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,18 @@ <h3>Contents<a id="contents" name="contents"></a></h3>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7D512DA37F789B4C">5.2-1 <span class="Heading">Background to the data</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X825C5B837A08F579">5.3 <span class="Heading">Digital image analysis</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X79616D12822FDB9A">5.3 <span class="Heading">Digital image analysis and persistent homology</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X84F2B640851E82A6">5.3-1 <span class="Heading">Image segmentation by automatic thresholding</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X8066F9B17B78418E">5.3-1 <span class="Heading">Naive example of image segmentation by automatic thresholding</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7D512DA37F789B4C">5.3-2 <span class="Heading">Background to the data</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X87AF06677F05C624">5.4 <span class="Heading">Random simplicial complexes</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X7D2CC9CB85DF1BAF">5.4 <span class="Heading">Alternative approaches to computing persistent homology</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X87AF06677F05C624">5.5 <span class="Heading">Random simplicial complexes</span></a>
</span>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions tutorial/chap0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@
5.1-1 Background to the data
5.2 Mapper clustering
5.2-1 Background to the data
5.3 Digital image analysis
5.3-1 Image segmentation by automatic thresholding
5.3 Digital image analysis and persistent homology
5.3-1 Naive example of image segmentation by automatic thresholding
5.3-2 Background to the data
5.4 Random simplicial complexes
5.4 Alternative approaches to computing persistent homology
5.5 Random simplicial complexes
6 Group theoretic computations
6.1 Third homotopy group of a supsension of an Eilenberg-MacLane space
6.2 Representations of knot quandles
Expand Down
9 changes: 6 additions & 3 deletions tutorial/chap0_mj.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,18 @@ <h3>Contents<a id="contents" name="contents"></a></h3>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5_mj.html#X7D512DA37F789B4C">5.2-1 <span class="Heading">Background to the data</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5_mj.html#X825C5B837A08F579">5.3 <span class="Heading">Digital image analysis</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5_mj.html#X79616D12822FDB9A">5.3 <span class="Heading">Digital image analysis and persistent homology</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5_mj.html#X84F2B640851E82A6">5.3-1 <span class="Heading">Image segmentation by automatic thresholding</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5_mj.html#X8066F9B17B78418E">5.3-1 <span class="Heading">Naive example of image segmentation by automatic thresholding</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5_mj.html#X7D512DA37F789B4C">5.3-2 <span class="Heading">Background to the data</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5_mj.html#X87AF06677F05C624">5.4 <span class="Heading">Random simplicial complexes</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5_mj.html#X7D2CC9CB85DF1BAF">5.4 <span class="Heading">Alternative approaches to computing persistent homology</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5_mj.html#X87AF06677F05C624">5.5 <span class="Heading">Random simplicial complexes</span></a>
</span>
</div>
</div>
Expand Down
43 changes: 38 additions & 5 deletions tutorial/chap5.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7D512DA37F789B4C">5.2-1 <span class="Heading">Background to the data</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X825C5B837A08F579">5.3 <span class="Heading">Digital image analysis</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X79616D12822FDB9A">5.3 <span class="Heading">Digital image analysis and persistent homology</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X8066F9B17B78418E">5.3-1 <span class="Heading">Naive example of image segmentation by automatic thresholding</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap5.html#X7D512DA37F789B4C">5.3-2 <span class="Heading">Background to the data</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X87AF06677F05C624">5.4 <span class="Heading">Random simplicial complexes</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X7D2CC9CB85DF1BAF">5.4 <span class="Heading">Alternative approaches to computing persistent homology</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap5.html#X87AF06677F05C624">5.5 <span class="Heading">Random simplicial complexes</span></a>
</span>
</div>
</div>
Expand Down Expand Up @@ -152,9 +155,9 @@ <h5>5.2-1 <span class="Heading">Background to the data</span></h5>

<p><img src="images/mappercloud.png" align="center" height="400" alt="data cloud"/></p>

<p><a id="X825C5B837A08F579" name="X825C5B837A08F579"></a></p>
<p><a id="X79616D12822FDB9A" name="X79616D12822FDB9A"></a></p>

<h4>5.3 <span class="Heading">Digital image analysis</span></h4>
<h4>5.3 <span class="Heading">Digital image analysis and persistent homology</span></h4>

<p>The following example reads in a digital image as a filtered pure cubical complexex. The filtration is obtained by thresholding at a sequence of uniformly spaced values on the greyscale range. The persistent homology of this filtered complex is calculated in degrees <span class="SimpleMath">0</span> and <span class="SimpleMath">1</span> and displayed as two barcodes.</p>

Expand Down Expand Up @@ -210,9 +213,39 @@ <h5>5.3-2 <span class="Heading">Background to the data</span></h5>

<p><img src="../tst/examples/image1.3.2.png" align="center" height="400" alt="barcode"/></p>

<p><a id="X7D2CC9CB85DF1BAF" name="X7D2CC9CB85DF1BAF"></a></p>

<h4>5.4 <span class="Heading">Alternative approaches to computing persistent homology</span></h4>

<p>From any sequence <span class="SimpleMath">X_0 ⊂ X_1 ⊂ X_2 ⊂ ⋯ ⊂ X_T</span> of cellular spaces (such as pure cubical complexes, or cubical complexes, or simplicial complexes, or regular CW complexes) we can construct a filtered chain complex <span class="SimpleMath">C_∗ X_0 ⊂ C_∗ X_1 ⊂ C_∗ X_2 ⊂ ⋯ C_∗ X_T</span>. The induced homology homomorphisms <span class="SimpleMath">H_n(C_∗ X_0, F) → H_n(C_∗ X_1, F) → H_n(C_∗ X_2, F) → ⋯ → H_n(C_∗ X_T, F)</span> with coefficients in a field <span class="SimpleMath">F</span> can be computed by applying an appropriate sequence of elementary row operations to the boundary matrices in the chain complex <span class="SimpleMath">C_∗ X_T⊗ F</span>; the boundary matrices are sparse and are best represented as such; the row operations need to be applied in a fashion that respects the filtration. This method is used in the above examples of persistent homology. The method is not practical when the number of cells in <span class="SimpleMath">X_T</span> is large.</p>

<p>An alternative approach is to construct an admissible discrete vector field on each term <span class="SimpleMath">X_k</span> in the filtration. For each vector field there is a non-regular CW-complex <span class="SimpleMath">Y_k</span> whose cells correspond to the critical cells in <span class="SimpleMath">X_k</span> and for which there is a homotopy equivalence <span class="SimpleMath">X_k≃ Y_k</span>. For each <span class="SimpleMath">k</span> the composite homomorphism <span class="SimpleMath">H_n(C_∗ Y_k, F) stackrel≅→ H_n(C_∗ X_k, F) → H_n(C_∗ X_k+1, F) stackrel≅→ H_n(C_∗ Y_k+1, F)</span> can be computed and the persistent homology can be derived from these homology homomorphisms. This method is implemented in the function <code class="code">PersistentBettiNUmbersAlt(X,n,p)</code> where <span class="SimpleMath">p</span> is the characteristic of the field, <span class="SimpleMath">n</span> is the homology degree, and <span class="SimpleMath">X</span> can be a filtered pure cubical complex, or a filtered simplicial complex, or a filtered regular CW complex, or indeed a filtered chain complex (represented in sparse form). This function incorporates the functions <code class="code">ContractedFilteredPureCubicalComplex(X)</code> and <code class="code">ContractedFilteredRegularComplex(X)</code> which respectively input a filtered pure cubical complex and filtered regular CW-complex and return a filtered complex of the same data type in which each term of the output filtration is a deformation retract of the corresponding term in the input filtration.</p>

<p>In this approach the vector fields on the various spaces <span class="SimpleMath">X_k</span> are completely independent and so the method lends itself to a degree of easy parallelism. This is not incorporated into the current implementation.</p>

<p>As an illustration we consider a synthetic data set <span class="SimpleMath">S</span> consisting of <span class="SimpleMath">3527</span> points sampled, with errors, from an `unknown' manifold <span class="SimpleMath">M</span> in <span class="SimpleMath">R^3</span>. From such a data set one can associate a <span class="SimpleMath">3</span>-dimensional cubical complex <span class="SimpleMath">X_0</span> consisting of one unit cube centred on each (suitably scaled) data point. Given a pure cubical complex <span class="SimpleMath">X_s</span> we construct <span class="SimpleMath">X_s+1 =X_s ∪ {overline e^3_λ}_λ∈ Λ</span> by adding to <span class="SimpleMath">X_s</span> each closed unit cube <span class="SimpleMath">overline e^3_λ</span> in <span class="SimpleMath">R^3</span> that intersects non-trivially with <span class="SimpleMath">X_s</span>. We construct the filtered cubical complex <span class="SimpleMath">X_∗ ={X_i}_0≤ i≤ 19</span> and compute the persistence matrices <span class="SimpleMath">β_d^∗∗</span> for <span class="SimpleMath">d=0,1,2</span> and for <span class="SimpleMath">Z_2</span> coefficients. The filtered complex <span class="SimpleMath">X_∗</span> is quite large. In particular, the final space <span class="SimpleMath">X_19</span> in the filtration involves <span class="SimpleMath">1092727</span> vertices, <span class="SimpleMath">3246354</span> edges, <span class="SimpleMath">3214836</span> faces of dimension <span class="SimpleMath">2</span> and <span class="SimpleMath">1061208</span> faces of dimension <span class="SimpleMath">3</span>. The usual matrix reduction approach to computing persistent Betti numbers would involve an appropriate row reduction of sparse matrices one of which has over 3 million rows and 3 million columns.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">file:=HapFile("data247.txt");;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Read(file);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">F:=ThickeningFiltration(T,20);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">P2:=PersistentBettiNumbersAlt(F,2);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BarCodeCompactDisplay(P2);</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">P1:=PersistentBettiNumbersAlt(F,1);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BarCodeCompactDisplay(P1);</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">P0:=PersistentBettiNumbersAlt(F,0);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">BarCodeCompactDisplay(P0);</span>

</pre></div>

<p><img src="images/barcodes123.gif" align="center" height="400" alt="barcodes"/></p>

<p>The barcodes suggest that the data points might have been sampled from a manifold with the homotopy type of a torus.</p>

<p><a id="X87AF06677F05C624" name="X87AF06677F05C624"></a></p>

<h4>5.4 <span class="Heading">Random simplicial complexes</span></h4>
<h4>5.5 <span class="Heading">Random simplicial complexes</span></h4>

<p>For a positive integer <span class="SimpleMath">n</span> and probability <span class="SimpleMath">p</span> we denote by <span class="SimpleMath">Y(n,p)</span> the <em>Linial-Meshulam random simplicial 2-complex</em>. Its <span class="SimpleMath">1</span>-skeleton is the complete graph on <span class="SimpleMath">n</span> vertices; each possible <span class="SimpleMath">2</span>-simplex is included independently with probability <span class="SimpleMath">p</span>.</p>

Expand Down
72 changes: 70 additions & 2 deletions tutorial/chap5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
following picture.


5.3 Digital image analysis
5.3 Digital image analysis and persistent homology

The following example reads in a digital image as a filtered pure cubical
complexex. The filtration is obtained by thresholding at a sequence of
Expand Down Expand Up @@ -166,7 +166,75 @@
The following image was used in the example.


5.4 Random simplicial complexes
5.4 Alternative approaches to computing persistent homology

From any sequence X_0 ⊂ X_1 ⊂ X_2 ⊂ ⋯ ⊂ X_T of cellular spaces (such as pure
cubical complexes, or cubical complexes, or simplicial complexes, or regular
CW complexes) we can construct a filtered chain complex C_∗ X_0 ⊂ C_∗ X_1 ⊂
C_∗ X_2 ⊂ ⋯ C_∗ X_T. The induced homology homomorphisms H_n(C_∗ X_0, F) →
H_n(C_∗ X_1, F) → H_n(C_∗ X_2, F) → ⋯ → H_n(C_∗ X_T, F) with coefficients in
a field F can be computed by applying an appropriate sequence of elementary
row operations to the boundary matrices in the chain complex C_∗ X_T⊗ F; the
boundary matrices are sparse and are best represented as such; the row
operations need to be applied in a fashion that respects the filtration.
This method is used in the above examples of persistent homology. The method
is not practical when the number of cells in X_T is large.

An alternative approach is to construct an admissible discrete vector field
on each term X_k in the filtration. For each vector field there is a
non-regular CW-complex Y_k whose cells correspond to the critical cells in
X_k and for which there is a homotopy equivalence X_k≃ Y_k. For each k the
composite homomorphism H_n(C_∗ Y_k, F) stackrel≅→ H_n(C_∗ X_k, F) → H_n(C_∗
X_k+1, F) stackrel≅→ H_n(C_∗ Y_k+1, F) can be computed and the persistent
homology can be derived from these homology homomorphisms. This method is
implemented in the function PersistentBettiNUmbersAlt(X,n,p) where p is the
characteristic of the field, n is the homology degree, and X can be a
filtered pure cubical complex, or a filtered simplicial complex, or a
filtered regular CW complex, or indeed a filtered chain complex (represented
in sparse form). This function incorporates the functions
ContractedFilteredPureCubicalComplex(X) and
ContractedFilteredRegularComplex(X) which respectively input a filtered pure
cubical complex and filtered regular CW-complex and return a filtered
complex of the same data type in which each term of the output filtration is
a deformation retract of the corresponding term in the input filtration.

In this approach the vector fields on the various spaces X_k are completely
independent and so the method lends itself to a degree of easy parallelism.
This is not incorporated into the current implementation.

As an illustration we consider a synthetic data set S consisting of 3527
points sampled, with errors, from an `unknown' manifold M in R^3. From such
a data set one can associate a 3-dimensional cubical complex X_0 consisting
of one unit cube centred on each (suitably scaled) data point. Given a pure
cubical complex X_s we construct X_s+1 =X_s ∪ {overline e^3_λ}_λ∈ Λ by
adding to X_s each closed unit cube overline e^3_λ in R^3 that intersects
non-trivially with X_s. We construct the filtered cubical complex X_∗
={X_i}_0≤ i≤ 19 and compute the persistence matrices β_d^∗∗ for d=0,1,2 and
for Z_2 coefficients. The filtered complex X_∗ is quite large. In
particular, the final space X_19 in the filtration involves 1092727
vertices, 3246354 edges, 3214836 faces of dimension 2 and 1061208 faces of
dimension 3. The usual matrix reduction approach to computing persistent
Betti numbers would involve an appropriate row reduction of sparse matrices
one of which has over 3 million rows and 3 million columns.

 Example 
gap> file:=HapFile("data247.txt");;
gap> Read(file);;
gap> F:=ThickeningFiltration(T,20);;
gap> P2:=PersistentBettiNumbersAlt(F,2);;
gap> BarCodeCompactDisplay(P2);
gap> P1:=PersistentBettiNumbersAlt(F,1);;
gap> BarCodeCompactDisplay(P1);
gap> P0:=PersistentBettiNumbersAlt(F,0);;
gap> BarCodeCompactDisplay(P0);



The barcodes suggest that the data points might have been sampled from a
manifold with the homotopy type of a torus.


5.5 Random simplicial complexes

For a positive integer n and probability p we denote by Y(n,p) the
Linial-Meshulam random simplicial 2-complex. Its 1-skeleton is the complete
Expand Down
Loading

0 comments on commit 343f1c4

Please sign in to comment.