Umap

Struct Umap 

Source
pub struct Umap { /* private fields */ }
Expand description

UMAP dimensionality reduction algorithm.

This struct holds the configuration and metrics for UMAP. It can be reused to learn manifolds from multiple datasets with the same parameters.

§Example

use umap::{Umap, UmapConfig};
use ndarray::Array2;

let config = UmapConfig::default();
let umap = Umap::new(config);

// Learn the manifold structure
let manifold = umap.learn_manifold(
    data.view(),
    knn_indices.view(),
    knn_dists.view(),
);

// Create an optimizer and run training
let mut opt = Optimizer::new(
    manifold,
    init,
    500, // total epochs
    config.optimization.repulsion_strength,
    config.optimization.learning_rate,
    config.optimization.negative_sample_rate,
    &euclidean_metric,
);

while opt.remaining_epochs() > 0 {
    opt.step_epochs(opt.remaining_epochs().min(10));
}

let fitted = opt.into_fitted(config);
let embedding = fitted.embedding();

Implementations§

Source§

impl Umap

Source

pub fn new(config: UmapConfig) -> Self

Create a new UMAP instance with default Euclidean metrics.

Both the input space metric (for graph construction) and output space metric (for optimization) are set to Euclidean distance.

§Arguments
  • config - UMAP configuration parameters
Source

pub fn with_metrics( config: UmapConfig, metric: Box<dyn Metric>, output_metric: Box<dyn Metric>, ) -> Self

Create a UMAP instance with custom distance metrics.

§Arguments
  • config - UMAP configuration parameters
  • metric - Distance metric for input space (graph construction)
  • output_metric - Distance metric for output embedding space (optimization)
§Example
let umap = Umap::with_metrics(
    config,
    Box::new(MyCustomMetric),
    Box::new(EuclideanMetric),
);
Source

pub fn learn_manifold( &self, data: ArrayView2<'_, f32>, knn_indices: ArrayView2<'_, u32>, knn_dists: ArrayView2<'_, f32>, ) -> LearnedManifold

Learn the manifold structure from high-dimensional data.

This is the expensive graph construction phase that builds a fuzzy topological representation of the data. The result can be cached, serialized, and reused for multiple different optimizations.

This phase is deterministic (no randomness) and independent of the target embedding dimensionality.

§Arguments
  • data - Input data matrix (n_samples × n_features). Used for validation.
  • knn_indices - Precomputed k-nearest neighbor indices (n_samples × n_neighbors). Each row contains indices of the k nearest neighbors for that sample.
  • knn_dists - Precomputed k-nearest neighbor distances (n_samples × n_neighbors). Each row contains distances to the k nearest neighbors.
§Returns

A LearnedManifold containing the fuzzy simplicial set and local geometry.

§Panics

Panics if:

  • Parameter validation fails (invalid ranges, incompatible sizes)
  • Array shapes are incompatible
  • Number of samples <= n_neighbors
§Example
let manifold = umap.learn_manifold(
    data.view(),
    knn_indices.view(),
    knn_dists.view(),
);
// Save for later use
save_manifold(&manifold)?;
Source

pub fn fit( &self, data: ArrayView2<'_, f32>, knn_indices: ArrayView2<'_, u32>, knn_dists: ArrayView2<'_, f32>, init: ArrayView2<'_, f32>, ) -> FittedUmap

High-level convenience method that learns and optimizes in one call.

This is equivalent to:

  1. learn_manifold() - build the graph
  2. Optimizer::new() - set up optimization
  3. Run all epochs
  4. into_fitted() - extract final model

For checkpointing or more control, use the lower-level API instead.

§Arguments
  • data - Input data matrix (n_samples × n_features)
  • knn_indices - Precomputed k-nearest neighbor indices
  • knn_dists - Precomputed k-nearest neighbor distances
  • init - Initial embedding coordinates (n_samples × n_components)
§Returns

A FittedUmap containing the optimized embedding and learned manifold.

§Example
let fitted = umap.fit(
    data.view(),
    knn_indices.view(),
    knn_dists.view(),
    init.view(),
);
let embedding = fitted.embedding();

Auto Trait Implementations§

§

impl Freeze for Umap

§

impl !RefUnwindSafe for Umap

§

impl Send for Umap

§

impl Sync for Umap

§

impl Unpin for Umap

§

impl !UnwindSafe for Umap

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more