Skip to main content

Implementation of the Dowker complex.

Project description

An implementation of the Dowker complex originally introduced in Homology Groups of Relations and adapted to the setting of persistent homology in A functorial Dowker theorem and persistent homology of asymmetric networks. The complex is implemented as a class named DowkerComplex that largely follows the API conventions from scikit-learn.


Example of running DowkerComplex

The following is an example of computing persistent homology of the filtered complex $\left\{\mathrm{D}_{\varepsilon}(X,Y)\right\}_{\varepsilon\in\mathbb{R}^{+}}$, that is, of the Dowker 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_complex import DowkerComplex
>>> 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]
>>> dc = DowkerComplex()  # use default parameters
>>> persistence = dc.fit_transform([vertices, witnesses])
>>> persistence
[array([[0.39632083, 0.4189592 ],
        [0.17218397, 0.24239225],
        [0.07438909, 0.1733489 ],
        [0.13146844, 0.25247844],
        [0.16269607, 0.29266369],
        [0.0815455 , 0.24042536],
        [0.10576964, 0.32222553],
        [0.1382231 , 0.358332  ],
        [0.07358198, 0.37408252],
        [0.24082383, 0.57726198],
        [0.02419385,        inf]]),
 array([[0.5035793 , 0.63405836]])]

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 duality can be verified by swapping the roles of vertices as witnesses as follows.

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

Any DowkerComplex object accepts further parameters during instantiation. A full description of these can be displayed by calling help(DowkerComplex). 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.


Installation and requirements

The package can be installed via pip by running pip install -U dowker-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-complex
$ uv run python
>>> from dowker-complex import DowkerComplex
>>> ...

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_complex-0.1.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

dowker_complex-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file dowker_complex-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for dowker_complex-0.1.2.tar.gz
Algorithm Hash digest
SHA256 406ced9e786cc49d5d346c50f67718cf4a0f5b8aa66356ff48570e5f4f5f74a9
MD5 b250dcdb02c87b534127932d00da5a42
BLAKE2b-256 618aea4931a27dd0664033c907f1f340b3c60aa18759b84c7c46070c9fb31a24

See more details on using hashes here.

File details

Details for the file dowker_complex-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: dowker_complex-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for dowker_complex-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f54cffb193ef625ddb29b7a402bd1a054a8ad53dc1b008b8c7c37e86569a2e2
MD5 b793c0e437d4eaba72be2ea30cc40978
BLAKE2b-256 691ffed6bf3faee9423e17dc4e732f96828a8cf3de3a3d9e4ac861cbaf0500a1

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