Skip to main content

A streamlined and fast implementation of parametric UMAP using PyTorch and FAISS

Project description

Parametric UMAP

A PyTorch implementation of Parametric UMAP (Uniform Manifold Approximation and Projection) for learning low-dimensional parametric embeddings of high-dimensional data.

Install

A proper installation of PyTorch (possibly with GPU accelaration) is suggested before installing this package. The package can then be installed with

pip install parametric_umap

To instead install the latest version of this repository use

pip install git+https://github.com/mr-fcharles/parametric_umap.git

Overview

Parametric UMAP (original paper) extends the original UMAP algorithm by learning a neural network that can map new data points to the lower-dimensional space without having to rerun the entire optimization. This (unofficial) implementation provides a flexible and efficient way to perform parametric dimensionality reduction leveraging PyTorch and FAISS.

Features

  • Neural network-based parametric mapping
  • Efficient nearest neighbor computation using FAISS
  • Sparse matrix operations for memory efficiency
  • GPU acceleration support
  • Model saving and loading capabilities
  • Correlation loss term to preserve distance relationships

Quick start

from parametric_umap import ParametricUMAP
from sklearn.datasets import make_swiss_roll
import numpy as np

# Create sample data
n_samples = 1000
X, color = make_swiss_roll(n_samples=n_samples, random_state=42)

# Initialize and fit the model
pumap = ParametricUMAP(
    device='cuda:0'
    n_components=2,
    hidden_dim=128,
    n_layers=3,
    n_epochs=10
)

# Fit and transform the data
embeddings = pumap.fit_transform(X)

# Transform new data
X_new = np.random.rand(100, 3)
new_embeddings = pumap.transform(X_new)

Note that by default the data is moved to the specified device before training to accelerate training process. However, if your GPU card cannot fit the entire dataset in memory you can override this behavior by setting the low_memory argument to true as follows:

embeddings = pumap.fit_transform(X,low_memory=True)

Key Parameters

Hyperparameters default values follow the original UMAP implementation

UMAP parameters

  • a: parameter for scaling distances between embedded points
  • b: parameter for controlling sharpness of the curve's transition between attraction and repulsion
  • n_neighbors: number of neighbors to compute for UMAP knn graph (default: 15)

Parametric model

  • device: 'cpu' or 'cuda' (also specific device 'cuda:1', automatically uses GPU acceleration if GPU card is detected)
  • n_components: Dimension of the output embedding (default: 2)
  • hidden_dim: Dimension of hidden layers in the MLP (default: 1024)
  • n_layers: Number of hidden layers (default: 3)
  • n_neighbors: Number of nearest neighbors (default: 15)
  • correlation_weight: Weight of the correlation loss term (default: 0.1)
  • learning_rate: Learning rate for optimization (default: 1e-4)
  • n_epochs: Number of training epochs (default: 10)
  • batch_size: Training batch size (default: 32)
  • use_batchnorm: Whether to use batch normalization in the embedding MLP (default: False)
  • use_dropout: Whether to use dropout in the embedding MLP (default: False)

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

parametric_umap-0.1.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

parametric_umap-0.1.2-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file parametric_umap-0.1.2.tar.gz.

File metadata

  • Download URL: parametric_umap-0.1.2.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/4.18.0-513.24.1.el8_9.x86_64

File hashes

Hashes for parametric_umap-0.1.2.tar.gz
Algorithm Hash digest
SHA256 35d0bca94567e0ebcd6d71c5db4b9faf3d5dc38584871035aa10fa145dd0f76c
MD5 3704d9a9a76bb058866d5427af0cf277
BLAKE2b-256 79ce02c9972737031bbc3cff223f0c02830bf2750b506934772a0f0dff896502

See more details on using hashes here.

File details

Details for the file parametric_umap-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: parametric_umap-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/4.18.0-513.24.1.el8_9.x86_64

File hashes

Hashes for parametric_umap-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a9f6bf4f6d759125f5862b45266e4ed02abb6e7c32733a101f2e71ec37a64d1
MD5 87545a84197361c383172920b9cc627d
BLAKE2b-256 6245fbd5726eac26185354fff9a50c2da9c28518317c59d5d17cb2f5eb1c6ff3

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