Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple python project for computing persistent homology

License

NotificationsYou must be signed in to change notification settings

Quenouillaume/persil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple python project for computingPersistent homoLogy. THIS REPO IS NO LONGER MAINTAINED as it has been integrated intoSageMath !The algorithm implemented is described in thisarticle by Afra Zomorodian and Gunnar Carlsson.

Installation

On Unix

Install directly from github withpython3 -m pip install git+https://github.com/quenouillaume/persilYou can update the module withpython3 -m pip install --upgrade --user git+https://github.com/quenouillaume/persil

On Windows

Download repository as a ZIP file, then open a terminal in your downloads folder and enter:python /m pip install persil-main.zipTo update, download the latest version as a ZIP file, then, as before, open a terminal in your downloads folder and enter:python /m pip install --upgrade --user persil-main.zip

In Sage

Load Sage with

module load gcc/8.3.0module load sage/9.1

Then, to install:

sage -pip install --user git+https://github.com/quenouillaume/persil/

To upgrade, use:

sage -pip install --upgrade --user git+https://github.com/quenouillaume/persil/

Guide

I have not yet written a guide, but it will come soon ! For now, you can use the following code as example.

Simple example

This code computes the peristent homology for the complex described in Zomorodian+Carlsson's article.

frompersil.simplexchainimport*frompersil.homologyimport*# First step: create a list of simplices and filtration values (also called degrees)list_simplex_degree= [([0],0), ([1],0), ([2],1), ([3],1), ([0,1],1), ([1,2],1), ([0,3],2), ([2,3],2), ([0,2],3), ([0,1,2],4), ([0,2,3],5)]# add them one by one in a fresh complexfc=FilteredComplex()for (simplex,value)inlist_simplex_degree:fc.insert(simplex,value)# compute persistent homology in Z/2Zzc=ZomorodianCarlsson(fc)zc.computeIntervals()foriinrange(2):print(zc.getIntervals(i))

This code outputs:

[(0,1), (1,1), (1,2), (0,inf)][(3,4), (2,5)]

Graphical representation

On the same complex as above, shows the persistence diagram for dimension 0

frompersil.simplexchainimport*frompersil.homologyimport*frompersil.graphicalimport*# First step: create a list of simplices and filtration values (also called degrees)list_simplex_degree= [([0],0), ([1],0), ([2],1), ([3],1), ([0,1],1), ([1,2],1), ([0,3],2), ([2,3],2), ([0,2],3), ([0,1,2],4), ([0,2,3],5)]# add them one by one in a fresh complexfc=FilteredComplex()for (simplex,value)inlist_simplex_degree:fc.insert(simplex,value)# compute persistent homology in Z/2Zzc=ZomorodianCarlsson(fc)zc.computeIntervals()persistence_diagram(zc.intervals[0])

This draws a persistence diagram with one vertical line and 3 points !

Rips-Vietoris Complex

The RipsComplex class is used to construct Rips complexes from a cloud point. Initialize it as follows:

r=RipsComplex(pointList,distance,threshold)

where:

  • pointList is a list of points
  • distance is a function taking two points as argument and returning their distance as a float
  • threshold is the maximum distance to be considered when constructing the complex. It can be omitted, in which case the program will compute the entire Rips complex, but this can get quite long.
  • Additionally, you can add the optional argumentverbose = True, which will make the construction print info on the progress of the construction

Once the object is initialized, compute the Complex with:

r.compute_skeleton(d)

whered is the maximum desired dimension. For instance ifd is 2, the resulting complex will contain points, edges and triangles.

Finally, you can access the Rips complex withr.complex. You can then compute its homology like in the previous examples.If you are working with points in the 2d plane, you can plot the point cloud and the neibourhood graph withr.plot(). This technically also works with points in higher dimension but it will only plot a projection on the two first axes.

Here is a full example:

importrandomfromnumpyimportsqrtfrompersilimport*defeuclidianDistance(x,y):returnsqrt(sum([(x[i]-y[i])**2foriinrange(len(x))]))defrandomPoints(n,D):# returns a list of n random points in the unit cube of dimension Dl= [tuple([random.random()foriinrange(D)])forjinrange(n)]returnll=randomPoints(1000,3)r=RipsComplex(l,euclidianDistance,0.23,verbose=True)r.compute_skeleton(2)zc=ZomorodianCarlsson(r.complex,strict=True,verbose=True)zc.computeIntervals()persistence_diagram(zc.intervals[1])

About

A simple python project for computing persistent homology

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp