mogutda: Topological Data Analysis in Python
mogutda contains Python codes that demonstrate the numerical calculation
of algebraic topology in an application to topological data analysis
(TDA). Its core code is the numerical methods concerning implicial complex,
and the estimation of homology and Betti numbers.
Topological data analysis aims at studying the shapes of the data, and draw some insights from them. A lot of machine learning algorithms deal with distances, which are extremely useful, but they miss the information the data may carry from their geometry.
The codes in this package were developed as a demonstration of a few posts of my blog.
It was not designed to be a Python package but a pedagogical collection of codes.
However, the codes and the blog posts have been unexpectedly popular. Therefore,
I modularized the code into the package
(or corresponding repository: MoguNumerics)
mogu is simply a collection of unrelated numerical routines with a lot of
dependencies, but the part of TDA can be quite independent.
In order to provide other researchers and developers an independent package, which is compact (without
unecessary alternative packages to load), and efficient, I decided to modularize
the codes of TDA separately, and name this package
It runs under Python 3.5, 3.6, 3.7, and 3.8.
Release 0.1.5 can work under
numpy>0.16.0, but previous
release will constitute error under the new
You can install by:
pip install -U mogutda
To establish a simplicial complex for a torus, type
import numpy as np from mogutda import SimplicialComplex torus_sc = [(1,2,4), (4,2,5), (2,3,5), (3,5,6), (5,6,1), (1,6,2), (6,7,2), (7,3,2), (1,3,4), (3,4,6), (4,6,7), (4,5,7), (5,7,1), (7,3,1)] torus_c = SimplicialComplex(simplices=torus_sc)
To retrieve its Betti numbers, type:
print(torus_c.betti_number(0)) # print 1 print(torus_c.betti_number(1)) # print 2 print(torus_c.betti_number(2)) # print 1
Codes in this repository are demo codes for a few entries of my blog, Everything about Data Analytics, and the corresponding entries are:
Richard Hennigan put a nice Wolfram Demonstration online explaining what the simplicial complexes are, and how homologies are defined:
It is recommended that for real application, you should use the following packages for efficiency, because my codes serve the pedagogical purpose only.
If you want to contribute, feel free to fork the repository, and submit a pull request whenever you are ready.
If you spot any bugs or issues, go to the Issue page.
I may not approve pull request immediately if your suggested change is big. If you want to incorporate something big, please discuss with me first.