Skip to main content

Pure MLX + NumPy implementations of UMAP, t-SNE, PaCMAP, and NNDescent for Apple Silicon.

Project description

mlx-vis

Pure MLX + NumPy implementations of UMAP, t-SNE, PaCMAP, and NNDescent for Apple Silicon. No scipy, no sklearn - just Metal GPU acceleration via MLX.

Fashion-MNIST 70K, 500 iterations on M3 Ultra

Install

uv pip install mlx-vis

From source:

git clone --recurse-submodules https://github.com/hanxiao/mlx-vis.git
cd mlx-vis
uv pip install .

Usage

import numpy as np
from mlx_vis import UMAP, TSNE, PaCMAP, NNDescent

X = np.random.randn(10000, 128).astype(np.float32)

# UMAP
Y = UMAP(n_components=2, n_neighbors=15).fit_transform(X)

# t-SNE
Y = TSNE(n_components=2, perplexity=30).fit_transform(X)

# PaCMAP
Y = PaCMAP(n_components=2, n_neighbors=10).fit_transform(X)

# NNDescent (approximate k-NN graph)
indices, distances = NNDescent(k=15).build(X)

Submodule imports also work:

from mlx_vis.umap import UMAP
from mlx_vis.tsne import TSNE
from mlx_vis.pacmap import PaCMAP
from mlx_vis.nndescent import NNDescent

Methods

Method Class Main API Output
UMAP UMAP(n_components, n_neighbors, min_dist, ...) fit_transform(X) np.ndarray (n, d)
t-SNE TSNE(n_components, perplexity, ...) fit_transform(X) np.ndarray (n, d)
PaCMAP PaCMAP(n_components, n_neighbors, ...) fit_transform(X) np.ndarray (n, d)
NNDescent NNDescent(k, n_iters, ...) build(X) (indices, distances)

Visualization

Requires matplotlib and ffmpeg (for video). Not installed by default.

from mlx_vis import UMAP, scatter, animate
import numpy as np

X = np.random.randn(10000, 128).astype(np.float32)
Y = UMAP(n_components=2).fit_transform(X)

# static scatter plot
scatter(Y, title="My Embedding", save="plot.png")

# with labels
labels = np.random.randint(0, 5, 10000)
scatter(Y, labels=labels, theme="dark", save="labeled.png")

Animation from epoch snapshots:

snaps, times = [], []
import time; t0 = time.time()

def cb(epoch, Y_np):
    snaps.append(Y_np)
    times.append(time.time() - t0)

Y = UMAP(n_components=2, n_epochs=200).fit_transform(X, epoch_callback=cb)

animate(snaps, labels=labels, timestamps=times,
        method_name="umap-mlx", save="animation.mp4")

Full Fashion-MNIST example with all three methods:

python -m mlx_vis.examples.fashion_mnist --method umap --theme dark
python -m mlx_vis.examples.fashion_mnist --method all

Dependencies

  • mlx >= 0.20.0
  • numpy >= 1.24.0

License

Apache-2.0

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

mlx_vis-0.1.1.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

mlx_vis-0.1.1-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file mlx_vis-0.1.1.tar.gz.

File metadata

  • Download URL: mlx_vis-0.1.1.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlx_vis-0.1.1.tar.gz
Algorithm Hash digest
SHA256 44475ea7b3482fc5d93fe9a1f8b36ca680a8494414219ab8d1501bf117611d6f
MD5 75f753150cf1d8b3af30d79748930d6b
BLAKE2b-256 0ffd31ef5642d9f35b9b84015958cad75933d0bae294051c03de23e46114f79c

See more details on using hashes here.

File details

Details for the file mlx_vis-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mlx_vis-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlx_vis-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dc7615f3894f754819fcb58f29cb477c3fb437deaa8c5b67bfef5b3e7dfd0bb
MD5 759335c58326ff374755cceb43f912b2
BLAKE2b-256 a4a40e857272c8cb2c907868286fc92e4b42a06fd312fb9966af0041282ebb71

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