Skip to main content

centrality_entropy

Function centrality_entropy 

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

Compute the Shannon entropy of the degree centrality distribution.

Normalizes degrees to a probability distribution and computes H = -sum(p_i * ln(p_i)). Higher values indicate more evenly distributed importance; lower values indicate concentration around a few hubs. Returns 0.0 for trivial or edgeless graphs.

The result is normalized by ln(n) to give a value in [0, 1].

§Examples

use rust_igraph::{Graph, centrality_entropy};

// K_4: all degrees equal → maximum entropy = 1.0
let g = Graph::from_edges(
    &[(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)], false, Some(4)
).unwrap();
let h = centrality_entropy(&g).unwrap();
assert!((h - 1.0).abs() < 1e-10);