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 drc 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 drc 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dowker_rips_complex-1.0.0.tar.gz.
File metadata
- Download URL: dowker_rips_complex-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1d554837da3700a199abbebff7d543d73db34a72151f12248b5e8fbbfb39260
|
|
| MD5 |
e3a6d413b92e004bd2558953bafac118
|
|
| BLAKE2b-256 |
66abda8f0e7581fcd039e4b7fa62d8a3295f748213ee20b9ea39365fecdb9104
|
File details
Details for the file dowker_rips_complex-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dowker_rips_complex-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
066b1da803fa33f8cb40c3e1d3bb1f582f478ecdabf8db6737733489790795c1
|
|
| MD5 |
3ac30f9d5ec5732ed9911d32e9152d98
|
|
| BLAKE2b-256 |
c00620422c2f7dc5eb845efeba8d09af3b536f7421d9c7595c882ffebf3ca6eb
|