pub fn random_walk_node2vec(
graph: &Graph,
weights: Option<&[f64]>,
start: VertexId,
mode: DijkstraMode,
steps: u32,
p: f64,
q: f64,
seed: u64,
) -> IgraphResult<Node2VecWalkResult>Expand description
Performs a second-order biased random walk (Node2Vec) starting at start
for up to steps transitions.
§Parameters
p— Return parameter. Higherpmakes it less likely to return to the previously visited vertex.p > 1discourages backtracking;p < 1encourages it.q— In-out parameter. Higherqbiases towards BFS-like exploration (staying close tot);q < 1biases towards DFS-like exploration (moving away fromt).weights— Optional edge weights (positive).Nonefor unweighted.mode— Direction mode for directed graphs (Out,In,All).seed— Deterministic RNG seed.
§Returns
(vertex_chain, edge_chain) where vertex_chain[0] == start. If the walk
gets stuck (no admissible outgoing edges), the result is truncated.
§Errors
Returns IgraphError::InvalidArgument if p or q are not positive
finite, if start is out of range, or if weights are invalid.
§Examples
use rust_igraph::{Graph, random_walk_node2vec, DijkstraMode};
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();
g.add_edge(0, 2).unwrap(); // shortcut
// With q < 1: biased towards DFS (exploring further away)
let (vs, es) = random_walk_node2vec(
&g, None, 0, DijkstraMode::Out, 10, 1.0, 0.5, 42
).unwrap();
assert_eq!(vs[0], 0);
assert!(vs.len() <= 11);