Skip to main content

transitivity_local_undirected

Function transitivity_local_undirected 

Source
pub fn transitivity_local_undirected(
    graph: &Graph,
) -> IgraphResult<Vec<Option<f64>>>
Expand description

Local transitivity (clustering coefficient) per vertex.

For vertex v with simple-degree d and t adjacent triangles, returns 2t / (d * (d - 1)). None when d < 2 (no closed triple possible — upstream’s IGRAPH_TRANSITIVITY_NAN mode); use result.iter().map(|o| o.unwrap_or(0.0)) for IGRAPH_TRANSITIVITY_ZERO behaviour.

Counterpart of igraph_transitivity_local_undirected() from references/igraph/src/properties/triangles.c:369.

§Examples

use rust_igraph::{Graph, transitivity_local_undirected};

// Triangle: every vertex has clustering 1.0.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
assert_eq!(
    transitivity_local_undirected(&g).unwrap(),
    vec![Some(1.0), Some(1.0), Some(1.0)],
);

// Star centre: 3 neighbours but 0 triangles → 0.0.
// Leaves: degree 1 → None (no closed triple possible).
let mut g = Graph::with_vertices(4);
for v in 1..4 { g.add_edge(0, v).unwrap(); }
let r = transitivity_local_undirected(&g).unwrap();
assert_eq!(r, vec![Some(0.0), None, None, None]);