Skip to main content

layout_umap

Function layout_umap 

Source
pub fn layout_umap(
    graph: &Graph,
    seed: Option<&[[f64; 2]]>,
    distances: Option<&[f64]>,
    params: &UmapParams,
) -> IgraphResult<Vec<[f64; 2]>>
Expand description

Compute the 2D UMAP layout.

Places vertices using stochastic gradient descent that minimizes cross-entropy between high-dimensional edge probabilities and low-dimensional distances.

§Arguments

  • graph — input graph (treated as directed for kNN, undirected for general).
  • seed — optional initial positions [x, y] per vertex.
  • distances — optional per-edge distances. If None, all edges have weight 1.
  • params — algorithm parameters.

Returns [x, y] positions for each vertex.

§Errors

Returns error if distances length doesn’t match edge count, distances are negative/NaN, or seed dimensions are wrong.

§Examples

use rust_igraph::{Graph, layout_umap, UmapParams};

let mut g = Graph::with_vertices(6);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(4, 5).unwrap();

let params = UmapParams { epochs: 50, ..UmapParams::default() };
let pos = layout_umap(&g, None, None, &params).unwrap();
assert_eq!(pos.len(), 6);
assert!(pos.iter().all(|p| p[0].is_finite() && p[1].is_finite()));