Skip to contents

Performs UMAP dimensionality reduction on the input data. This function provides a user-friendly interface with input validation before calling the Rust implementation. Leverages GPU-accelerated kNN searches and in the default setting also uses a GPU-accelerated Adam optimiser for the embedding.

Usage

umap_gpu(
  data,
  knn = NULL,
  n_dim = 2L,
  k = 15L,
  min_dist = 0.5,
  spread = 1,
  knn_method = c("nndescent", "exhaustive", "ivf"),
  nn_params = params_nn_gpu(),
  umap_params = params_umap_gpu(),
  seed = 42L,
  backend = c("wgpu", "mlx"),
  .verbose = TRUE
)

Arguments

data

Numerical matrix or data frame. The data to embed of shape samples x features. Will be coerced to a matrix.

knn

Optional NearestNeighbours class. If provided, UMAP will skip the k-nearest neighbour graph generation and use this one. Defaults to NULL. See manifoldsR::new_nearest_neighbour() for details.

n_dim

Integer. Number of dimensions in the embedding space. Defaults to 2L.

k

Integer. Number of nearest neighbours to consider for manifold approximation. Larger values result in more global structure being preserved. Defaults to 15L.

min_dist

Numeric. Minimum distance between points in the embedding. Controls how tightly points are packed. Smaller values result in more clustered embeddings. Must be >= 0. Defaults to 0.5. If you use SGD, consider reducing this!

spread

Numeric. Effective scale of embedded points. Determines the scale at which embedded points will be spread out. Defaults to 1.0.

knn_method

Character. (Approximate) Nearest neighbour method to use. One of "exhaustive", "ivf" or "nndescent". These are GPU-accelerated methods.

nn_params

Named list. Nearest neighbour search parameters, see params_nn_gpu().

umap_params

Named list. UMAP (GPU) algorithm parameters, see params_umap_gpu().

seed

Integer. Random seed for reproducibility. Defaults to 42L.

backend

String. One of c("wgpu", "mlx"). "mlx" runs the kNN search and the "adam_gpu" optimiser on MLX (Apple Silicon, needs a build with the MLX backend, see mlx_available()). "adam_v06_gpu" stays on WGPU, CPU optimisers stay on the CPU.

.verbose

Logical. Controls verbosity. Defaults to TRUE.

Value

A numerical matrix with dimensions samples x n_dim containing the UMAP embedding.