Skip to main content

node2vec_walk

Function node2vec_walk 

Source
pub fn node2vec_walk(
    adjacency: &[Vec<(usize, f64)>],
    start_node: usize,
    walk_length: usize,
    p: f64,
    q: f64,
    rng_seed: u64,
) -> Result<Vec<usize>>
Expand description

Perform a Node2Vec biased random walk on a weighted graph.

Node2Vec generalises DeepWalk by interpolating between BFS-like (p<1) and DFS-like (q<1) exploration using the return parameter p and the in-out parameter q.

The transition probability from node v to neighbour x (when the previous node was t) is proportional to:

  • 1/p if x == t (backtrack)
  • 1 if x is also a neighbour of t (same distance)
  • 1/q otherwise (explore further)

§Parameters

  • adjacency – weighted adjacency list; adjacency[u] is a list of (neighbour, weight) pairs.
  • start_node – starting node index.
  • walk_length – desired walk length (≥ 1).
  • p – return parameter (> 0). Higher values discourage backtracking.
  • q – in-out parameter (> 0). < 1 favours DFS-like walks; > 1 favours BFS-like walks.
  • rng_seed – PRNG seed.

§Errors

Returns GraphError::InvalidParameter for out-of-range start_node or non-positive p/q.