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.
The functionalities of Magnipy
for an individual metric space include:
- Computing the metric space's distance matrix
- 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
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
To get started,
- Clone this repository locally into a directory of your choosing
- 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 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
: UsingMagnipy
for computing the magnitude of one metric spacediversipy_tutorial.ipynb
: UsingDiversipy
for comparing the magnitude of multiple metric spaces
The following supplementary demos are also provided:
mode_dropping.ipynb
: UsingMagDiff
for detecting mode dropping / mode collapse
Please consider citing our work!
@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}
}