Skip to main content

rwpe

Function rwpe 

Source
pub fn rwpe(graph: &Graph, k_steps: usize) -> IgraphResult<Vec<Vec<f64>>>
Expand description

Compute Random Walk Positional Encoding for all vertices.

For each vertex, returns a vector of k_steps values where entry i is P(walk of length i+1 returns to start). This is the diagonal of (D⁻¹A)^(i+1).

§Parameters

  • graph — The input graph (undirected).
  • k_steps — Number of walk lengths to compute (1 through k_steps).

§Returns

A Vec<Vec<f64>> of shape [vcount][k_steps]. Entry [v][k] is the return probability for vertex v at walk length k+1.

§Examples

use rust_igraph::{Graph, rwpe};

// Triangle: each vertex has degree 2, connected to the other two.
// At step 1: from any vertex, probability of return is 0 (must leave).
// At step 2: from any vertex, each neighbor has prob 0.5 to go back.
//   P(return at step 2) = 0.5 * 0.5 + 0.5 * 0.5 = 0.5
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
let pe = rwpe(&g, 2).unwrap();
assert_eq!(pe.len(), 3);
assert!((pe[0][0] - 0.0).abs() < 1e-10); // step 1: no self-loop
assert!((pe[0][1] - 0.5).abs() < 1e-10); // step 2: return prob = 0.5