Skip to main content

PyPI - Version License: MIT

Neighbor embedding spectrum

This repository implements the computation of neighbor embedding spectra as described in Visualizing single-cell data with the neighbor embedding spectrum (bioarxiv).

It can use openTSNE or cne as backends.

Installation

pip install ne-spectrum

If you want to use the GPU support for the cne backend, please make sure that you have pytorch installed with CUDA support before installing ne-spectrum. Similarly, if you want to save animations as .mp4 rather than .gif files, you need to install ffmpeg.

Usage

Load MNIST as example data

from ne_spectrum import TSNESpectrum, CNESpectrum
import torchvision
from sklearn.decomposition import PCA
import os
import numpy as np

fig_path = "./"

# load MNIST as example dataset
mnist_train = torchvision.datasets.MNIST(train=True,
                                         download=True,
                                         transform=None,
                                         root=fig_path
                                         )
x_train, y_train = mnist_train.data.float().numpy(), mnist_train.targets

mnist_test = torchvision.datasets.MNIST(train=False,
                                        download=True,
                                        transform=None,
                                        root=fig_path
                                        )
x_test, y_test = mnist_test.data.float().numpy(), mnist_test.targets

x_train = x_train.reshape(x_train.shape[0], -1)
x_test = x_test.reshape(x_test.shape[0], -1)

x = np.concatenate([x_train, x_test], axis=0)
y = np.concatenate([y_train, y_test], axis=0)

# transform data with PCA to save some time when computing the kNN graphs
x_pca = PCA(n_components=50).fit_transform(x)

Compute the neighbor embedding spectrum with the openTSNE backend

# compute spectrum with openTSNE backend
tsnespectrum = TSNESpectrum()
tsnespectrum.fit(x_pca)

# save individual slides, all embeddings, and a gif animation
tsnespectrum.save_slides(save_path=os.path.join(fig_path, "mnist_tsne"),
                         cmap="tab10",
                         color=y)
tsnespectrum.save_embeddings(os.path.join(fig_path, "mnist_tsne", "embeddings.npy"))
tsnespectrum.save_video(save_path=os.path.join(fig_path, "mnist_tsne"),
                        cmap="tab10",
                        color=y)

Neighbor embedding spectrum on MNIST animated

Similarly, we can compute the neighbor embedding spectrum with the cne backend

# compute spectrum with CNE backend
cnespectrum = CNESpectrum()
cnespectrum.fit(x_pca)

# save individual slides, all embeddings, and a gif animation
cnespectrum.save_slides(save_path=os.path.join(fig_path, "mnist_cne"),
                        cmap="tab10",
                        color=y)
cnespectrum.save_embeddings(os.path.join(fig_path, "mnist_cne", "embeddings.npy"))
cnespectrum.save_video(save_path=os.path.join(fig_path, "mnist_cne"),
                       cmap="tab10",
                       color=y)

Metadata

Release files for ne-spectrum 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ne-spectrum 0.1.1
File Size Uploaded
ne_spectrum-0.1.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ne-spectrum 0.1.1
File Interpreter ABI Platform
ne_spectrum-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / ne_spectrum-0.1.1.tar.gz

Download URL ne_spectrum-0.1.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4e4fe4193119ac49e79e3d3638e7d7440b1ea8da81d3a71e29bf14fab24bc576
BLAKE2b-256 checksum
How to use checksums
b5e50d65bc83bae120c16ed74937fbeb7b0c7ad58fa9f042d6175d2b35f67bbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.0

Release files / ne_spectrum-0.1.1-py3-none-any.whl

Download URL ne_spectrum-0.1.1-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef1af57de976aef246e49ce4abee1e18f3d2d19e7a84d23188e85cafe55d2a7b
BLAKE2b-256 checksum
How to use checksums
5d8c65f433ed5547afaa65afcd048c04d53616ec4a4acb5f75c1ad0de7420729
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page