Skip to main content

Logo

PyPI version downloads test deploy docs codecov DOI Streamlit App

tda-mapper

A simple and efficient Python implementation of Mapper algorithm for Topological Data Analysis

The Mapper algorithm is a well-known technique in the field of topological data analysis that allows data to be represented as a graph. Mapper is used in various fields such as machine learning, data mining, and social sciences, due to its ability to preserve topological features of the underlying space, providing a visual representation that facilitates exploration and interpretation. For an in-depth coverage of Mapper you can read the original paper.

This library contains an implementation of Mapper, where the construction of open covers is based on vp-trees for improved performance and scalability. The details about this methodology are contained in our preprint.

Step 1 Step 2 Step 3 Step 4
Step 1 Step 2 Step 3 Step 2
Chose lens Cover image Run clustering Build graph

Example

Here you can find an example to use to kickstart your analysis. In this toy-example we use a two-dimensional dataset of two concentric circles. The Mapper graph is a topological summary of the whole point cloud.

import numpy as np

from sklearn.datasets import make_circles
from sklearn.decomposition import PCA
from sklearn.cluster import DBSCAN

from tdamapper.core import MapperAlgorithm
from tdamapper.cover import CubicalCover
from tdamapper.plot import MapperLayoutInteractive

X, y = make_circles(                # load a labelled dataset
    n_samples=5000,
    noise=0.05,
    factor=0.3,
    random_state=42)
lens = PCA(2).fit_transform(X)

mapper_algo = MapperAlgorithm(
    cover=CubicalCover(
        n_intervals=10,
        overlap_frac=0.3),
    clustering=DBSCAN())
mapper_graph = mapper_algo.fit_transform(X, lens)

mapper_plot = MapperLayoutInteractive(
    mapper_graph,
    colors=y,                       # color according to categorical values
    cmap='jet',                     # Jet colormap, for classes
    agg=np.nanmean,                 # aggregate on nodes according to mean
    dim=2,
    iterations=60,
    seed=42,
    width=600,
    height=600)

fig_mean = mapper_plot.plot()
fig_mean.show(config={'scrollZoom': True})

mapper_plot.update(                 # reuse the plot with the same positions
    colors=y,
    cmap='viridis',                 # viridis colormap, for ranges
    agg=np.nanstd,                  # aggregate on nodes according to std
)

fig_std = mapper_plot.plot()
fig_std.show(config={'scrollZoom': True})
Dataset Mapper graph (average) Mapper graph (deviation)
Dataset Mapper graph (average) Mapper graph (standard deviation)

More examples can be found in the documentation.

Demo App

You can also run a demo app locally by running

pip install -r app/requirements.txt
streamlit run app/streamlit_app.py

Citations

If you want to use tda-mapper in your work or research, you can cite the archive uploaded on Zenodo, pointing to the specific version of the software used in your work.

If you want to cite the methodology on which tda-mapper is based, you can use the preprint.

Download files

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

Source Distribution

tda_mapper-0.7.3.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

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

tda_mapper-0.7.3-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file tda_mapper-0.7.3.tar.gz.

File metadata

  • Download URL: tda_mapper-0.7.3.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for tda_mapper-0.7.3.tar.gz
Algorithm Hash digest
SHA256 8e00e41bf81eced3fd74f34c7461cc66dd058c0cd9ded8ed3b2397f7d9ef6db5
MD5 9ecfd315390ade0a713b2c4353bb7536
BLAKE2b-256 13462acdc121e5e85b0de9850af6c6e1d014bfd2e8779b1b4b52bd6f3435c0d5

See more details on using hashes here.

File details

Details for the file tda_mapper-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: tda_mapper-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for tda_mapper-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4695881669b620f0f1989dcecbb59e9b99ddc1b326236d545c88f0be8f21c48a
MD5 fc4b2baea60cc17df5ba52a6563d01a8
BLAKE2b-256 20af5adff2aa576eef99c2b99133c9c3fff362dd42b0a82ef73d8de7ab5afa1c

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