Skip to main content

harmonic_centrality_cutoff

Function harmonic_centrality_cutoff 

Source
pub fn harmonic_centrality_cutoff(
    graph: &Graph,
    cutoff: u32,
    normalized: bool,
) -> IgraphResult<Vec<f64>>
Expand description

Range-limited harmonic centrality.

Computes the sum (or mean) of inverse distances to vertices reachable within cutoff hops. Vertices beyond the cutoff contribute 0, same as unreachable vertices.

When normalized = true, returns (1/(n-1)) * sum(1/d) (mean inverse distance). When normalized = false, returns the raw sum(1/d).

For graphs with vcount < 2, returns zeros (the normalization factor n-1 would be 0).

§Parameters

  • graph — the input graph.
  • cutoff — maximum path length to consider.
  • normalized — if true, divides sum by n - 1.

§Examples

use rust_igraph::{Graph, harmonic_centrality_cutoff};

// Path: 0—1—2—3—4
let mut g = Graph::with_vertices(5);
for i in 0..4 { g.add_edge(i, i + 1).unwrap(); }
let h = harmonic_centrality_cutoff(&g, 2, true).unwrap();
// Vertex 0: reaches 1 (d=1) and 2 (d=2) within cutoff 2.
// sum_inv = 1/1 + 1/2 = 1.5, normalized by (5-1)=4 → 0.375
let expected = 1.5 / 4.0;
assert!((h[0] - expected).abs() < 1e-12);