Skip to main content

core_periphery_gradient

Function core_periphery_gradient 

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

Compute the core-periphery gradient.

(max_coreness - 1) / (n - 1) — a normalized measure of how many distinct core layers exist. Values near 0 indicate flat structure (all vertices in similar cores); values near 1 indicate deep hierarchical layering. Returns 0.0 for trivial or edgeless graphs.

§Examples

use rust_igraph::{Graph, core_periphery_gradient};

// K_4: max_coreness=3, n=4 → (3-1)/(4-1) = 2/3
let g = Graph::from_edges(
    &[(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)], false, Some(4)
).unwrap();
assert!((core_periphery_gradient(&g).unwrap() - 2.0/3.0).abs() < 1e-10);