Minimum-Distortion Embedding
Project description
PyMDE
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pymde-0.1.15-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 320694d374e359120875e46a5be856ba4352ede92ca0e4771d7992bb0ed9b49c |
|
MD5 | 2c1dbef17b9bb30c34f27674329fca72 |
|
BLAKE2b-256 | 13baf97915a902f21bec2b0bd54570bbf068d57a84a8c4c37a7657ebe58754b9 |
Hashes for pymde-0.1.15-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f0e5d8f41071057e332c2f6f56dcb4248f0118cc542167031972771010b59d1 |
|
MD5 | 79dab63fa73a11b801e3855fd1cef696 |
|
BLAKE2b-256 | 31faeafa0f09baee5ee9a475d29fd290b91d09480d4a7fc5e532ce8899f95835 |
Hashes for pymde-0.1.15-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 360adea43ed5618e30085e32ebcb78c802fa8032358a503705723067743db63e |
|
MD5 | e08e19ce837faf70d0d46a9bc4fb1c4e |
|
BLAKE2b-256 | 09b7d1459013652abcd06b3135434a5db168ab23d12c70d8d3ada3af804f3ed6 |
Hashes for pymde-0.1.15-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4537252b44558a89b6c28a57d28872788359e6d481d6451c28d9acad84eff1af |
|
MD5 | 6e4523c0bbea33a40c7ab03441ea68ff |
|
BLAKE2b-256 | 7f3222b680757ce24b9260c2d9e63b003467c96185a4df1958bb7c2d61816e5f |
Hashes for pymde-0.1.15-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1130f44175abe7b95e14702208c8d81b0e8b47ab46078d99302a85bb89e611dc |
|
MD5 | df06709911ee58e674cfcb96354afca5 |
|
BLAKE2b-256 | 0ff7a83670a9222b4fed5a75a0ff134fc496b6ab4b0026d55bac2a429ea54633 |
Hashes for pymde-0.1.15-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e2a8a2631fecc6b597e5996e19ed0c90eecef521852f61743f4f558d0f0ce8 |
|
MD5 | 074b860fabe6642c543e569a62165241 |
|
BLAKE2b-256 | 26a77597ab176b21689b5dc292d540f9b1fa4c28b4bbb2246b3308a3c8097455 |
Hashes for pymde-0.1.15-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0b3058c2debcf7d7ba24456bb8fd8d0b636eddbd7d237573b9c69aed34c5c2d |
|
MD5 | ab35a44543607933cc9880791793b705 |
|
BLAKE2b-256 | dee0bef010abc5ac0b12d6cc024353bc25f1acba749f788e7c8906da776af3e7 |
Hashes for pymde-0.1.15-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b362975a9d3ce5b7f865c794bcf86f058abbcbf15ab9884121464f293355b5b5 |
|
MD5 | fdfb3dbed7a914ab6e298967fd897348 |
|
BLAKE2b-256 | 7cb0152da46a52bd000b499d510bcb81533a3242f79dc22a57e90c7707fe546d |
Hashes for pymde-0.1.15-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56d548d0ffcc203186d30f031d2dcaa40e7e09a8ecb88193fab0be6e938ff40 |
|
MD5 | bd0bb6ef7ff372ee265f2ba105429f86 |
|
BLAKE2b-256 | ffd3587146535ca266526fb000583aba644c1b247f19860566defc28ee44ff0a |
Hashes for pymde-0.1.15-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2c012b88506f3213107b955ed21b49dbec566d26b2e98ce87c4510dc21589c |
|
MD5 | e35464ec1f58b16df8ddc39d42a6829f |
|
BLAKE2b-256 | 1008a94659fb21b80c287097680b5448cff9776aabf3f0ba54e75534e7b21174 |
Hashes for pymde-0.1.15-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ca577a7d3ef4f673870dfe0e0099daf0a30ff7369ec56da6269a27e658dcbf |
|
MD5 | bc6edc593cb7a26d3e294942b24154ff |
|
BLAKE2b-256 | 9904f48de859faf3f7ae631deee8654015141588b9e392ed3b1d0ea263c42afb |
Hashes for pymde-0.1.15-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc7da179388fe0341633d04a3a7ade3127639c2df201586d6db8e9b06e2daa4c |
|
MD5 | 1b4e77982d938442c947cfe7e2187d66 |
|
BLAKE2b-256 | 4320b815baebddb5a2bea3ade25fa8f662b1cacbcc368479ab97f95e38127638 |
Hashes for pymde-0.1.15-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec8543105edc3f277d06b8bde99005fa2acaeb5f2a8c00eede5643bed166b795 |
|
MD5 | 82dc0fe045ed8808adeb3f48aa2944f5 |
|
BLAKE2b-256 | e0f036db9567edd5bdf828f1c5b71f2fca4a0a1036cf38c4044b8a1ee3b5c7e5 |
Hashes for pymde-0.1.15-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcb841a3a886a825994cbb457a6488aa45bd57d6a5dc98a4b435e14f75e10fb8 |
|
MD5 | 24759f190ce7ee8bb45c962e60510f87 |
|
BLAKE2b-256 | 5e86cdde353f884beee86de56ca555c677c18fc79f958749d786dae0860d141e |
Hashes for pymde-0.1.15-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d7a025f2fb26930d5f243b07affa28a7942a6f8ab15cbd093042426e8823f89 |
|
MD5 | 1fc0e947423ee41b992b93694f11b5e8 |
|
BLAKE2b-256 | fda1cf072b303a2c401329253436fe449a203a76ec4478e3f267f1385dd756ca |