Skip to main content

even_odd_walk_ratio

Function even_odd_walk_ratio 

Source
pub fn even_odd_walk_ratio(graph: &Graph) -> IgraphResult<f64>
Expand description

Compute the even-odd walk ratio.

Ratio of even-length walks of length 2 to odd-length walks of length 1 (edges). A walk of length 2 from u to w passes through some intermediate v — the total count is Σ_v d(v)² (counting ordered pairs of neighbors). The odd-length count is 2m (each edge contributes 2 directed walks of length 1).

Returns (Σ d²) / (2m) — for bipartite graphs this relates to the ratio of even vs odd spectral moments. Returns 0.0 for graphs with no edges.

§Examples

use rust_igraph::{Graph, even_odd_walk_ratio};

// Path 0-1-2: degrees [1,2,1], Σd²=1+4+1=6, 2m=4 → 6/4=1.5
let g = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
assert!((even_odd_walk_ratio(&g).unwrap() - 1.5).abs() < 1e-10);