Skip to main content

hop_entropy

Function hop_entropy 

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

Normalised Shannon entropy of the hop-distance distribution.

Computes BFS distances from all vertices, builds a histogram of finite distances (excluding self-loops d=0), and returns the Shannon entropy normalised by ln(diameter) so the result is in [0, 1].

Returns 0.0 for graphs with fewer than 2 finite distances or diameter ≤ 1.

§Examples

use rust_igraph::{Graph, hop_entropy};

// Path 0-1-2: distances {1,1,2} → 2 classes → entropy > 0
let g = Graph::from_edges(&[(0, 1), (1, 2)], false, Some(3)).unwrap();
let h = hop_entropy(&g).unwrap();
assert!(h > 0.0);
assert!(h <= 1.0);