Skip to main content

Implementation of the Dowker-Rips complex.

Project description

Implementation of the Dowker-Rips complex introduced in Flagifying the Dowker Complex. The complex is implemented as a class named DowkerRipsComplex that largely follows the API conventions from scikit-learn.


Example of running DowkerRipsComplex

The following is an example of computing persistent homology of the filtered complex $\left\{\mathrm{DR}_{\varepsilon}(X,Y)\right\}_{\varepsilon\in\mathbb{R}^{+}}$, that is, of the Dowker-Rips complex with relations $R_{\varepsilon}\subseteq X\times Y$ defined by $(x,y)\in R_{\varepsilon}$ iff $d(x,y)\leq\varepsilon$ for $\varepsilon\geq 0$, and where $X$ and $Y$ are subsets of $\mathbb{R}^{n}$ equipped with the Euclidean norm. In the following example, we refer to $X$ and $Y$ as vertices and witnesses, respectively.

>>> from dowker_rips_complex import DowkerRipsComplex
>>> from sklearn.datasets import make_blobs
>>> X, y = make_blobs(
        n_samples=200,
        centers=[[-1, 0], [1, 0]],
        cluster_std=0.75,
        random_state=42,
    )
>>> vertices, witnesses = X[y == 0], X[y == 1]
>>> drc = DowkerRipsComplex()  # use default parameters
>>> persistence = drc.fit_transform([vertices, witnesses])
>>> persistence
[array([[0.07438909, 0.1733489 ],
        [0.08154549, 0.24042536],
        [0.17218398, 0.24239226],
        [0.13146845, 0.25247845],
        [0.16269606, 0.2926637 ],
        [0.10576964, 0.32222554],
        [0.1382231 , 0.358332  ],
        [0.07358199, 0.3740825 ],
        [0.39632082, 0.4189592 ],
        [0.24082384, 0.577262  ],
        [0.02419385,        inf]], dtype=float32),
 array([[0.5035793 , 0.55263996]], dtype=float32)]

The output above is a list of arrays, where the $i$-th array contains (birth, death)-times of homological generators in dimension $i-1$. Validity of Dowker-Rips duality can be verified by swapping the roles of vertices as witnesses as follows.

>>> import numpy as np
>>> persistence_swapped = DowkerRipsComplex().fit_transform([witnesses, vertices])
>>> all(
        np.allclose(homology, homology_swapped)
        for homology, homology_swapped
        in zip(persistence, persistence_swapped)
    )
True

Any DowkerRipsComplex object accepts further parameters during instantiation. A full description of these can be displayed by calling help(DowkerRipsComplex). These parameters, among other things, allow the user to specify persistence-related parameters such as the maximal homological dimension to compute or which metric to use.

Behind the scenes, DowkerRipsComplex computes the input matrix required for Ripser from a matrix of pairwise distances between vertices and witnesses. This process is implemented in two ways, one relying on NumPy and one relying on Numba. Since Numba creates some overhead stemming from the compilation of Python code into machine code, the NumPy-implementation is usually faster than the Numba-implementation on smaller data sets. The NumPy-implementation, however, creates a large temporary array, which can lead to OOM errors on larger datasets, in which case the Numba-implementation must be used. Setting use_numpy=True during instantiation of an instance of DowkerRipsComplex forces the use of the NumPy-implementation; in case of an OOM error, the computation will fall back on the Numba-implementation and a corresponding warning is raised.


Installation and requirements

The package can be installed via pip by running pip install -U dowker-rips-complex.

Required Python dependencies are specified in pyproject.toml. Provided that uv is installed, these dependencies can be installed by running uv pip install -r pyproject.toml. The environment specified in uv.lock can be recreated by running uv sync.


Installing from PyPI for uv users

$ uv init
$ uv add dowker-rips-complex
$ uv run python
>>> from dowker-rips-complex import DowkerRipsComplex
>>> ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dowker_rips_complex-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dowker_rips_complex-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file dowker_rips_complex-0.1.0.tar.gz.

File metadata

  • Download URL: dowker_rips_complex-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for dowker_rips_complex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18c73e6c976dc4c9da35726ff889810eff7cbb40191c6c382b7bb5ecd1fa4e0c
MD5 179d26baf769d4daa1c465f0a928561f
BLAKE2b-256 76530afaf7e10dafebb0c17aada205c92754595597d2f7412c18099e716fe0f4

See more details on using hashes here.

File details

Details for the file dowker_rips_complex-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dowker_rips_complex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cdc8320a38338982be3b0f5caf48750848a4f5b5b1f2659cedd93e668c8d843
MD5 292fd7eb387085a5ef59e6a52a4dc3f2
BLAKE2b-256 58fa758c50c1213376c5e6314a6990e52e1202dd058bbefd8e039c12507ffa69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page