Skip to main content

Crate rune_node2vec

Crate rune_node2vec 

Source
Expand description

Node2Vec — graph node embeddings via biased random walks and skip-gram.

Node2Vec (Grover & Leskovec, 2016) learns a continuous vector representation for every node in an undirected graph. It generalises DeepWalk by introducing two hyperparameters (p and q) that bias the random walk to explore either the local neighbourhood (BFS-like) or the wider graph (DFS-like), letting the embedding capture both structural equivalence and community membership.

The algorithm has two phases:

  1. Biased random walks — for each node, generate num_walks walks of length walk_length. At each step the transition probability is weighted by 1/p (return to previous), 1.0 (common neighbour), or 1/q (exploration), and sampled in O(1) with the alias method.

  2. Skip-gram with negative sampling — treats each walk as a sentence, pairs each node with its context window, and optimises embeddings with SGD. Negative nodes are drawn proportional to degree^(3/4).

§Features

  • Pure Rust — no unsafe code, no dependencies beyond the library itself
  • Deterministic output via random_seed
  • Supports isolated nodes (walk length 1; embedding is random-initialised)
  • p=1, q=1 reproduces standard DeepWalk behaviour
  • Fluent builder API matching the rest of the rune-* family

§Quick Start

use rune_node2vec::Node2Vec;

// A triangle: nodes 0-1-2-0
let edges = vec![(0, 1), (1, 2), (2, 0)];
let result = Node2Vec::new()
    .embedding_dim(8)
    .n_epochs(5)
    .fit(3, &edges);

assert_eq!(result.embeddings.len(), 3);
assert_eq!(result.embeddings[0].len(), 8);

§CLI

rune-node2vec graph.edgelist --dim 64 --epochs 5
cat graph.edgelist | rune-node2vec -

Structs§

EmbedResult
The output of a completed Node2Vec run.
Node2Vec
Builder for configuring and running the Node2Vec algorithm.