Giter Site home page Giter Site logo

stephenhky / mogutda Goto Github PK

View Code? Open in Web Editor NEW
110.0 8.0 26.0 82 KB

Topological Data Analysis in Python: Simplicial Complex

Home Page: https://mogutda.readthedocs.io/

License: MIT License

Python 100.00%
tda python package topology homology topological-data-analysis

mogutda's Introduction

mogutda: Topological Data Analysis in Python

CircleCI GitHub release Documentation Status Updates Python 3 pypi download stars

Introduction

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.

History

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. (See: PyTDA.) However, the codes and the blog posts have been unexpectedly popular. Therefore, I modularized the code into the package mogu. (or corresponding repository: MoguNumerics) However, 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 mogutda.

Prerequisite

It runs under Python 3.8, 3.9, 3.10, and 3.11.

Simple Tutorial: Simplicial Complex

You can install by:

pip install 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

Demo Codes and Blog Entries

Codes in this repository are demo codes for a few entries of my blog, Everything about Data Analytics, and the corresponding entries are:

Wolfram Demonstration

Richard Hennigan put a nice Wolfram Demonstration online explaining what the simplicial complexes are, and how homologies are defined:

News

  • 08/18/2023: mogutda 0.4.0 released.
  • 06/20/2023: mogutda 0.3.5 released.
  • 09/09/2022: mogutda 0.3.4 released.
  • 07/15/2021: mogutda 0.3.3 released.
  • 04/10/2021: mogutda 0.3.2 released.
  • 11/28/2020: mogutda 0.3.1 released.
  • 08/16/2020: mogutda 0.3.0 released.
  • 04/28/2020: mogutda 0.2.1 released.
  • 01/16/2020: mogutda 0.2.0 released.
  • 02/20/2019: mogutda 0.1.5 released.
  • 12/31/2018: mogutda 0.1.4 released.
  • 07/18/2018: mogutda 0.1.3 released.
  • 07/02/2018: mogutda 0.1.2 released.
  • 06/13/2018: mogutda 0.1.1 released.
  • 06/11/2018: mogutda 0.1.0 released.

Other TDA Packages

It is recommended that for real application, you should use the following packages for efficiency, because my codes serve the pedagogical purpose only.

C++

Python

R

Contributions

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.

References

  • Afra J. Zomorodian. Topology for Computing (New York, NY: Cambridge University Press, 2009). [Amazon]
  • Afra J. Zomorodian. "Topological Data Analysis," Proceedings of Symposia in Applied Mathematics (2011). [link]
  • Afra Zomorodian, Gunnar Carlsson, “Computing Persistent Homology,” Discrete Comput. Geom. 33, 249-274 (2005). [pdf]
  • Gunnar Carlsson, “Topology and Data”, Bull. Amer. Math. Soc. 46, 255-308 (2009). [link]
  • Jeffrey Ray, Marcello Trovati, "A Survey of Topological Data Analysis (TDA) Methods Implemented in Python," in Advances in Intelligent Networking and Collaborative Systems, Springer (2018).
  • P. Y. Lum, G. Singh, A. Lehman, T. Ishkanov, M. Vejdemo-Johansson, M. Alagappan, J. Carlsson, G. Carlsson, “Extracting insights from the shape of complex data using topology”, Sci. Rep. 3, 1236 (2013). [link]
  • Robert Ghrist, “Barcodes: The persistent topology of data,” Bull. Amer. Math. Soc. 45, 1-15 (2008). [pdf]

Links

mogutda's People

Contributors

filco306 avatar grishhelen avatar islast avatar pyup-bot avatar stephenhky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mogutda's Issues

ValueError: zero-size array to reduction operation maximum which has no identity

Hi, I'm having this error when i tried to run a simple test code. I'm using python3.8

import numpy as np
from mogutda import SimplicialComplex

e1 = [(0, 1), (1, 2), (2, 0)]
sc1 = SimplicialComplex(e1)

print(sc1.betti_number(1))

ValueError Traceback (most recent call last)
Input In [11], in <cell line: 7>()
4 e1 = [(0, 1), (1, 2), (2, 0)]
5 sc1 = SimplicialComplex(e1)
----> 7 print(sc1.betti_number(1))

File ~\Anaconda3\envs\tda\lib\site-packages\mogutda\abssimcomplex.py:64, in SimplicialComplex.betti_number(self, i, eps)
62 if eps is None:
63 try:
---> 64 boundop_ip1_rank = np.linalg.matrix_rank(boundop_ip1.toarray())
65 except np.linalg.LinAlgError:
66 boundop_ip1_rank = boundop_ip1.shape[1]

File <array_function internals>:180, in matrix_rank(*args, **kwargs)

File ~\Anaconda3\envs\tda\lib\site-packages\numpy\linalg\linalg.py:1900, in matrix_rank(A, tol, hermitian)
1898 S = svd(A, compute_uv=False, hermitian=hermitian)
1899 if tol is None:
-> 1900 tol = S.max(axis=-1, keepdims=True) * max(A.shape[-2:]) * finfo(S.dtype).eps
1901 else:
1902 tol = asarray(tol)[..., newaxis]

File ~\Anaconda3\envs\tda\lib\site-packages\numpy\core_methods.py:40, in _amax(a, axis, out, keepdims, initial, where)
38 def _amax(a, axis=None, out=None, keepdims=False,
39 initial=_NoValue, where=True):
---> 40 return umr_maximum(a, axis, None, out, keepdims, initial, where)

ValueError: zero-size array to reduction operation maximum which has no identity

Persistence diagram of a clique complex

Hi everybody,

I have seen a ton of codes to compute a persistence diagram when the input data is a point cloud. Is there a way to compute the persistence diagram of a filtration of a clique complex if the input data is a weighted graph? It cannot be done with the Ripser library right? Any code would be very much appreciated.

Thank you.

error

C:\Users\zhuqunxi>pip install mogutda
Collecting mogutda
Using cached https://files.pythonhosted.org/packages/bb/4e/78e81217c3d8cef2c0bff47707d785e04594358a77b079f3fea8ac0e27a2/mogutda-0.1.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\zhuqunxi\AppData\Local\Temp\pip-install-7fyvqvip\mogutda\setup.py", line 18, in
long_description=package_description(),
File "C:\Users\zhuqunxi\AppData\Local\Temp\pip-install-7fyvqvip\mogutda\setup.py", line 10, in package_description
text = open('README.md', 'r').read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x9d in position 5556: illegal multibyte sequence

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\zhuqunxi\AppData\Local\Temp\pip-install-7fyvqvip\mogutda\

Cannot seem to be able to download the MoguTDA package

I get the following shell output:

Collecting mogutda
  Using cached mogutda-0.3.0.tar.gz (9.2 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-i43vzm5w/mogutda/setup.py'"'"'; __file__='"'"'/tmp/pip-install-i43vzm5w/mogutda/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-fqvz4km0
         cwd: /tmp/pip-install-i43vzm5w/mogutda/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-i43vzm5w/mogutda/setup.py", line 42, in <module>
        install_requires=install_requirements(),
      File "/tmp/pip-install-i43vzm5w/mogutda/setup.py", line 16, in install_requirements
        return [package_string.strip() for package_string in open('requirements.txt', 'r')]
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output

Thanks

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.