Ripser.py: A Lean Persistent Homology Library for Python

repository·master·Indexed 43 days ago

https://github.com/scikit-tda/ripser.py

A Python package for computing persistence cohomology using the fast C++ Ripser engine. It supports visualizing persistence diagrams, computing representative cocycles, and performing lowerstar filtrations on images. Features include a Scikit-learn compatible Rips transformer, approximate sparse filtrations via furthest point sampling (getGreedyPerm and getApproxSparseDM), and support for different coefficient fields (e.g., Z/2, Z/3).

Tokens
6.9K
Snippets
26
Records
37
Agent score
51%

What's inside Ripser.py

  1. Use sparse distance matrices with Ripser.py

    master

    Ripser.py supports sparse distance matrices using the scipy.sparse library. This enables:

    • Sparse filtrations: Using approximation algorithms to increase computational speed.
    • Sublevelset filtration (Watershed algorithm): Quantifying critical points in grid data like time series and images. The library includes a helper function specifically for image data to facilitate this.
  2. Specify arbitrary coefficient fields

    master
    Unlike many TDA tools that are limited to binary coefficients, Ripser.py allows you to specify arbitrary field coefficients $\mathbb{Z} / p\mathbb{Z}$ for any prime $p$. This is useful for detecting topological 'twists' in data, such as differentiating a Moebius strip from an ordinary loop.
  3. Retrieve representative cocycles

    master
    Ripser.py can return representative cocycles associated with different homology classes. This feature works for both sparse and dense filtrations over any field and can be used for topological nonlinear dimension reduction (NLDR), such as mapping a point cloud to a circle or a projective plane.
  4. Understand the Ripser.py interfaces

    master

    Ripser.py provides two distinct ways to interact with the library:

    1. Lightweight and functional interface: A direct, functional approach for quick computations.
    2. Object-oriented interface: Designed to follow the Scikit-Learn transformer paradigm, making it easy to integrate into machine learning pipelines.
  5. Compute higher order homology

    master
    While many TDA applications focus on 0-dimensional (connected components) and 1-dimensional (loops) homology, Ripser.py is efficient enough to compute 2-dimensional homology (voids) for modest point clouds.
  6. Optimize Ripser.py with robin_hood hashing

    master

    You can achieve up to a 30% speed-up by replacing the standard STL unordered_map with the robin_hood implementation. While the PyPI package is compiled with robin_hood by default, you can manually enable it during a local build by cloning the robin_hood repository into your project root before installing ripser.py.

    1. Clone the hashing implementation into a directory named robinhood at the project root: git clone https://github.com/martinus/robin-hood-hashing robinhood
    2. Install ripser.py with verbose output to verify the detection: pip install -v .
    git clone https://github.com/martinus/robin-hood-hashing robinhood
    pip install -v .
  7. Build Ripser.py from source

    master

    If you need to develop the package or if the pip installation fails, you can build it locally. Clone the repository and run one of the following commands from the root directory:

    • For a standard local installation: pip install .
    • For an editable installation (useful for development): pip install -e .

    Dependencies:

    • Cython
    • numpy
    • scipy
    • scikit-learn
    • persim

    Platform-specific notes:

    • Windows: You may need to install MinGW.
    • Mac: Ensure Xcode and Xcode command line tools are updated.
    pip install .
    # OR
    pip install -e .
  8. Optimize performance with robin_hood_hashmap during source compilation

    master

    For improved computational performance when compiling from source, you can integrate the robin_hood_hashmap library. To do this, clone the robin-hood-hashing repository into the ripser/robinhood directory before compiling.

    git clone https://github.com/martinus/robin-hood-hashing ripser/robinhood