Skip to main content

Minimum-Distortion Embedding

Project description

PyMDE

PyPI version Conda Version

The official documentation for PyMDE is available at www.pymde.org.

This repository accompanies the monograph Minimum-Distortion Embedding.

PyMDE is a Python library for computing vector embeddings for finite sets of items, such as images, biological cells, nodes in a network, or any other abstract object.

What sets PyMDE apart from other embedding libraries is that it provides a simple but general framework for embedding, called Minimum-Distortion Embedding (MDE). With MDE, it is easy to recreate well-known embeddings and to create new ones, tailored to your particular application.

PyMDE is competitive in runtime with more specialized embedding methods. With a GPU, it can be even faster.

Overview

PyMDE can be enjoyed by beginners and experts alike. It can be used to:

  • visualize datasets, small or large;
  • generate feature vectors for supervised learning;
  • compress high-dimensional vector data;
  • draw graphs (in up to orders of magnitude less time than packages like NetworkX);
  • create custom embeddings, with custom objective functions and constraints (such as having uncorrelated feature columns);
  • and more.

PyMDE is very young software, under active development. If you run into issues, or have any feedback, please reach out by filing a Github issue.

This README gives a very brief overview of PyMDE. Make sure to read the official documentation at www.pymde.org, which has in-depth tutorials and API documentation.

Installation

PyMDE is available on the Python Package Index, and on Conda Forge.

To install with pip, use

pip install pymde

Alternatively, to install with conda, use

conda install -c pytorch -c conda-forge pymde

PyMDE has the following requirements:

  • Python >= 3.7
  • numpy >= 1.17.5
  • scipy
  • torch >= 1.7.1
  • torchvision >= 0.8.2
  • pynndescent
  • requests

Getting started

Getting started with PyMDE is easy. For embeddings that work out-of-the box, we provide two main functions:

pymde.preserve_neighbors

which preserves the local structure of original data, and

pymde.preserve_distances

which preserves pairwise distances or dissimilarity scores in the original data.

Arguments. The input to these functions is the original data, represented either as a data matrix in which each row is a feature vector, or as a (possibly sparse) graph encoding pairwise distances. The embedding dimension is specified by the embedding_dim keyword argument, which is 2 by default.

Return value. The return value is an MDE object. Calling the embed() method on this object returns an embedding, which is a matrix (torch.Tensor) in which each row is an embedding vector. For example, if the original input is a data matrix of shape (n_items, n_features), then the embedding matrix has shape (n_items, embeddimg_dim).

We give examples of using these functions below.

Preserving neighbors

The following code produces an embedding of the MNIST dataset (images of handwritten digits), in a fashion similar to LargeVis, t-SNE, UMAP, and other neighborhood-based embeddings. The original data is a matrix of shape (70000, 784), with each row representing an image.

import pymde

mnist = pymde.datasets.MNIST()
embedding = pymde.preserve_neighbors(mnist.data, verbose=True).embed()
pymde.plot(embedding, color_by=mnist.attributes['digits'])

Unlike most other embedding methods, PyMDE can compute embeddings that satisfy constraints. For example:

embedding = pymde.preserve_neighbors(mnist.data, constraint=pymde.Standardized(), verbose=True).embed()
pymde.plot(embedding, color_by=mnist.attributes['digits'])

The standardization constraint enforces the embedding vectors to be centered and have uncorrelated features.

Preserving distances

The function pymde.preserve_distances is useful when you're more interested in preserving the gross global structure instead of local structure.

Here's an example that produces an embedding of an academic coauthorship network, from Google Scholar. The original data is a sparse graph on roughly 40,000 authors, with an edge between authors who have collaborated on at least one paper.

import pymde

google_scholar = pymde.datasets.google_scholar()
embedding = pymde.preserve_distances(google_scholar.data, verbose=True).embed()
pymde.plot(embedding, color_by=google_scholar.attributes['coauthors'], color_map='viridis', background_color='black')

More collaborative authors are colored brighter, and are near the center of the embedding.

Example notebooks

We have several example notebooks that show how to use PyMDE on real (and synthetic) datasets.

Citing

To cite our work, please use the following BibTex entry.

@article{agrawal2021minimum,
  author  = {Agrawal, Akshay and Ali, Alnur and Boyd, Stephen},
  title   = {Minimum-Distortion Embedding},
  journal = {arXiv},
  year    = {2021},
}

PyMDE was designed and developed by Akshay Agrawal.

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

pymde-0.2.3.tar.gz (65.9 kB view details)

Uploaded Source

Built Distributions

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

pymde-0.2.3-cp313-cp313-win_amd64.whl (99.4 kB view details)

Uploaded CPython 3.13Windows x86-64

pymde-0.2.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (182.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

pymde-0.2.3-cp313-cp313-macosx_11_0_arm64.whl (95.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pymde-0.2.3-cp313-cp313-macosx_10_13_x86_64.whl (95.5 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

pymde-0.2.3-cp312-cp312-win_amd64.whl (100.1 kB view details)

Uploaded CPython 3.12Windows x86-64

pymde-0.2.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (186.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

pymde-0.2.3-cp312-cp312-macosx_11_0_arm64.whl (96.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pymde-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl (96.1 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

pymde-0.2.3-cp311-cp311-win_amd64.whl (99.7 kB view details)

Uploaded CPython 3.11Windows x86-64

pymde-0.2.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (180.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

pymde-0.2.3-cp311-cp311-macosx_11_0_arm64.whl (96.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pymde-0.2.3-cp311-cp311-macosx_10_9_x86_64.whl (95.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

pymde-0.2.3-cp310-cp310-win_amd64.whl (99.5 kB view details)

Uploaded CPython 3.10Windows x86-64

pymde-0.2.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (172.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

pymde-0.2.3-cp310-cp310-macosx_11_0_arm64.whl (96.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pymde-0.2.3-cp310-cp310-macosx_10_9_x86_64.whl (95.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file pymde-0.2.3.tar.gz.

File metadata

  • Download URL: pymde-0.2.3.tar.gz
  • Upload date:
  • Size: 65.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pymde-0.2.3.tar.gz
Algorithm Hash digest
SHA256 033a20efadf75c3fda41dbf4f7413fe2619857e4b62050e02916bdfbd5baa91c
MD5 9fa606ebb964263ff69226b2637a53c3
BLAKE2b-256 0026696751f63f56d56479656e1ab41629d886b034e457609f576b306598ba89

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pymde-0.2.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 99.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pymde-0.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8ba8c7a6edc98173f21c5db486e145a2f4c333b61b734e6d029cf52034b8e30c
MD5 81d5e2c3b404c2b80bf1fe53446da2ea
BLAKE2b-256 570d95b729217cd37132f67d2d68ba7d106e46854ac2fd308ffbb61b869ff047

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c34d36857b181af63bb1616db22a32b729ac86a05554c0e2cf4431672dbb2207
MD5 51bc7485bc39c907826b51af6a4c0bf1
BLAKE2b-256 272fa4a034260e5919074f37f9d3f4d421ebad2c7a9527bcc986fa9c1160e65f

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a93740d1280dabb90c8095ccabcb3d503574345981ea8c0a623a4961aeec800
MD5 28fcb581544170699027f2408a645be3
BLAKE2b-256 269f1b1f39dfd31f3025820d505d0f043ab77420a28ec562d1b7b21382a01b6f

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 42e8add68b7c77c0de2db9642280700707bb2d5b301af295afe70d03152c56d3
MD5 647b8571d04f4b52a012074ae78f1848
BLAKE2b-256 277ede2bac761cffc8d2104a8571e669032bf8c6e4fa360312ceb5b95f266bf6

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pymde-0.2.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 100.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pymde-0.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7d1cb7a6ff7852de1665b7ce39fc086ec9c130fb42e6fd29ad5d2f65888402f5
MD5 1f0a6338f17792330016b1587337de2d
BLAKE2b-256 62ed60b19a4599673c72ff8ba8ae24179aef3cd3a4d7b4db1bc12348251b4397

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b2d73e4ae6d01678b85239b98f389f31f2d6afb747e2ccb9ce86c45dedf96729
MD5 57df74776fbb2a6428d4119c19986989
BLAKE2b-256 570580541fff140aaa79ad5a8a1295d863036de3251f3e81123fa76eb41e2809

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f4c9b50ee2dd0dfdfeb2d9b43e4ef39312c73b37b136b66d27547c814c03ee2
MD5 c9964b1438ce6ae19f20f50324ac4e2b
BLAKE2b-256 72df6ff3f02a206dccdd130f9e2e0dee6ddf0ba694e5cdb8292805596f9ba644

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 da27ba12dc3d7efa93daa678bde0137b442b4ff28e34a4dd15d53da10a8eaf09
MD5 123380ee10dd6f4e243232fe83b4812b
BLAKE2b-256 e9a4039c89ace631ca5be824aa40e9fb44b7400e61914dc2b48f6f6a6398e9c9

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pymde-0.2.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 99.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pymde-0.2.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 52f1d0c052d266d8f65a126ac38ed1c185c7e979a7dea578d6dd8352584d0f8d
MD5 d2439a68743229ceb8f9f74b127520bc
BLAKE2b-256 7e6eddde7b72579e473282ee3173eacabfbe5d3c8af43c520758d6ecf533d8cc

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ded5ee179053d9fb05f790cbf5ec0d7e7f1f603e141ffce039bdc8608f05b2e
MD5 77a868bd5240e1bb3853d370fb2bef13
BLAKE2b-256 b56239a265a28c7c50fdb863fa995ae3d13f4bd7f613c223a8d4cc04b8d346a4

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0791dcdd5411853ab5e990b87c5961590dda340d389392b0a0507abfb2570c73
MD5 bed56e67641a20d3ba1bd1b964e20056
BLAKE2b-256 6a62b9a0db3e2d4edcb9ac42cabd95efa9417d9825d74c05f0adfd8f8ab4748f

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3ede2a78d0531b11bf9de7a0621efcf5b5d0a3249ec0fa7a4d65300d97c2535a
MD5 139d5f189f46f0b23f2c3b90f500cee1
BLAKE2b-256 0aa4c99c4349463183858a1240e4e192d5cb8ee6459643ccd7ad358817341532

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pymde-0.2.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 99.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pymde-0.2.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 10a6246f5edcecc07a19371882f287bb91709617f51e9a8613625f6204fbf0aa
MD5 1dc0ea05f131013b3298c40c88de7199
BLAKE2b-256 f7f14edf9d6f9cbb81606c64e612c4aa92ece322e977551f57e13b6f0dd566d3

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1456030619ea51b3fd338884b4fb864f98fcc8f3aeae728c033ebfb6d9c4202d
MD5 6a354e63d9c1968a563b5893300c3333
BLAKE2b-256 468b084938b20168e2407479ca74bc9c001bf84f56cc15e8824146cd4347107c

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97e781acb1e68bbf808b8e530a5e50f2be8986a0c76e7de5813f565fd539bd51
MD5 0cd25951d3b7033c602f8dd94a8fbeda
BLAKE2b-256 b643559026908fc65b8b2cce977baa2dbd86a63e49437d2ecba6dc639b655262

See more details on using hashes here.

File details

Details for the file pymde-0.2.3-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pymde-0.2.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 78f6bea1e14dbe5ad0642cb9c0c22455d6678767468b316a9d465374705ced93
MD5 0d0012d9b0b3fcde658faa205092ea15
BLAKE2b-256 ab4a49e0f21a019fb10da35fe2437ee9f6f1ba167471fb64a936d8a1220e74e0

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