Skip to main content

walk_entropy

Function walk_entropy 

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

Compute the walk entropy of the graph.

H = -Σ p(v)·ln(p(v)) where p(v) = d(v) / (2m)

Shannon entropy of the degree distribution treated as a probability distribution over edge endpoints. Higher entropy indicates more uniform degree distribution. Returns 0.0 for graphs with no edges.

§Examples

use rust_igraph::{Graph, walk_entropy};

// K_3: d=2 for all, p=1/3 each → H = -3·(1/3)·ln(1/3) = ln(3)
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
assert!((walk_entropy(&g).unwrap() - 3.0_f64.ln()).abs() < 1e-10);