Skip to main content

triangle_density

Function triangle_density 

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

Compute the triangle density of the graph.

T_d = 6·triangles / (n·(n-1)·(n-2)) for n ≥ 3

Fraction of all possible vertex triples that form a triangle. Returns 0.0 for graphs with fewer than 3 vertices. Related to transitivity but normalized by the total number of triples, not just connected triples (paths of length 2).

§Examples

use rust_igraph::{Graph, triangle_density};

// K_3: 1 triangle, n=3, denom=6 → 6·1/6 = 1.0
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
assert!((triangle_density(&g).unwrap() - 1.0).abs() < 1e-10);