Skip to main content

A framework for computing the magnitude of a metric space.

Project description

magnipy: Metric Space Magnitude Computations

This is a repository for computing the magnitude of a metric space, which encodes the effective size, diversity, and geometry of a metric space. Given a dataset or distance matrix, magnitude measures the effective number of distinct points in the space at a scale of dissimilarity between observations. We introduce the following codebase to compute and compare the magnitude of metric spaces.

magnipy logo

🔍 Main Functionalities and Classes

Magnipy: For in-depth magnitude computations on a single metric space.

The functionalities of Magnipy for an individual metric space include:

  • Computing the metric space's distance matrix based on a feature space (attributes), adjecencies between observations (structure), or both features and adjecencies (full).
  • Calculating the similarity matrix from the distances
  • Executing an automated scale-finding procedure to find suitable evaluation scales
  • Computing the magnitude weight of each point across multiple distance scales
  • Evaluating and plotting magnitude functions across varying distance scales
  • Estimating magnitude dimension profiles and calculating the magnitude dimension to quantify intrinsic dimensionality

Diversipy: For comparing magnitude (and thus diversity) across multiple datasets.

The functionalities of Diversipy for a list of spaces (that share the same distance metric) include:

  • Executing an automated scale-finding procedure and the determining a common evaluation interval across datasets
  • Computing magnitude functions across varying distance scales
  • Calculating MagArea, the area under a magnitude function, a multi-scale measure of the intrinsic diversity of a dataset
  • Calculating MagDiff, the area between magnitude functions, to measure the difference in diversity between datasets

Graphipy: For in-depth magnitude computations on a single metric graph.

The functionalities of Graphipy for an individual metric graph include:

  • Calculating the magnitude of a networkx graph by computing magnitude seperately for each disconnected subgraph
  • Computing the metric based of features (attributes), graph structure (structure), or both features and graph structure (full).
  • Other functionalities similar to Magnipy

⚙️ Dependencies

To get started,

  1. Clone this repository locally into a directory of your choosing
  2. Create and activate a new Python virtual environment

Our dependencies are managed using the poetry package manager. Using your activated virtual environment, run the following to install poetry:

$ pip install poetry

With poetry installed, run the following command from the main directory to download the necessary dependencies:

$ poetry install

📚 Tutorials

Tutorials demonstrating the main functionalities can be found under the notebooks folder.

The following tutorials demonstrate how to initialize and utiltize the corresponding classes:

  • magnipy_tutorial.ipynb: Using Magnipy for computing the magnitude of one metric space
  • diversipy_tutorial.ipynb: Using Diversipy for comparing the magnitude of multiple metric spaces
  • graphipy_tutorial.ipynb: Using Graphipy for computing the magnitude of metric graphs

The following supplementary demos are also provided:

  • mode_dropping.ipynb: Using MagDiff for detecting mode dropping / mode collapse

📝 Citation

Please consider citing our work!

@inproceedings{limbeck2025geometry,
  title         = {Geometry-aware Edge Pooling for Graph Neural Networks}, 
  author        = {Katharina Limbeck and Lydia Mezrag and Guy Wolf and Bastian Rieck},
  booktitle     = {Advances in Neural Information Processing Systems},
  volume        = {38},
  year          = {2025}
}

@inproceedings{limbeck2024metric,
  title         = {Metric Space Magnitude for Evaluating the Diversity of Latent Representations}, 
  author        = {Katharina Limbeck and Rayna Andreeva and Rik Sarkar and Bastian Rieck},
  booktitle     = {Advances in Neural Information Processing Systems},
  volume        = {37},
  year          = {2024}
}

@inproceedings{andreeva2023metric,
  title         = {Metric Space Magnitude and Generalisation in Neural Networks},
  author        = {Andreeva, Rayna and Limbeck, Katharina and Rieck, Bastian and Sarkar, Rik},
  year          = {2023},
  booktitle     = {Proceedings of 2nd Annual Workshop on Topology, Algebra, and Geometry in Machine Learning~(TAG-ML)},
  volume        = {221},
  pages         = {242--253}
}

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

magnipy-1.0.0.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

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

magnipy-1.0.0-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file magnipy-1.0.0.tar.gz.

File metadata

  • Download URL: magnipy-1.0.0.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.3 Linux/6.17.0-1025-oem

File hashes

Hashes for magnipy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c19cce9d73e537e3133c232316d2402baea86d666f4382c28079cef410843718
MD5 1dae768211a296e2b5d999ceab0fd6ff
BLAKE2b-256 452868ca9d31e190f471a5d9a533c9760a0b44a5dae2542d2e7134a4ae636c39

See more details on using hashes here.

File details

Details for the file magnipy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: magnipy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.3 Linux/6.17.0-1025-oem

File hashes

Hashes for magnipy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11f1536ee4ed5ee92b92e8d42ab113b9a0212f2f6839cc7aa70f8a3dcd64dc3e
MD5 1366c5315ebecc627eb9296603a791d1
BLAKE2b-256 d7abc5d883218ff97e97b7a9fdc17d298e686f60cd93f2f09657017867ab5d23

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