Skip to main content

degree_entropy_ln

Function degree_entropy_ln 

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

Compute the Shannon entropy of the degree distribution (natural log).

H(G) = -Σ_k p(k) ln(p(k))

where p(k) = n_k / n is the fraction of vertices with degree k. Returns 0.0 for empty graphs or when all vertices have the same degree. Uses the natural logarithm (ln), complementing the base-2 degree_entropy in graph_entropy.rs.

§Examples

use rust_igraph::{Graph, degree_entropy_ln};

// K_3: all degree 2 → single class → H = 0
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
assert!(degree_entropy_ln(&g).unwrap().abs() < 1e-10);