Module raphtory::algorithms::local_clustering_coefficient
source · Expand description
Local Clustering coefficient - measures the degree to which nodes in a graph tend to cluster together.
It is calculated by dividing the number of triangles (sets of three nodes that are all connected to each other) in the graph by the total number of possible triangles. The resulting value is a number between 0 and 1 that represents the density of clustering in the graph.
A high clustering coefficient indicates that nodes tend to be connected to nodes that are themselves connected to each other, while a low clustering coefficient indicates that nodes tend to be connected to nodes that are not connected to each other.
In a social network of a particular community, we can compute the clustering coefficient of each node to get an idea of how strongly connected and cohesive that node’s neighborhood is.
A high clustering coefficient for a node in a social network indicates that the node’s neighbors tend to be strongly connected with each other, forming a tightly-knit group or community. In contrast, a low clustering coefficient for a node indicates that its neighbors are relatively less connected with each other, suggesting a more fragmented or diverse community.
Examples
use raphtory::algorithms::local_clustering_coefficient::{local_clustering_coefficient};
use raphtory::prelude::*;
let g = Graph::new();
let windowed_graph = g.window(0, 7);
let vs = vec![
(1, 1, 2),
(2, 1, 3),
(3, 2, 1),
(4, 3, 2),
(5, 1, 4),
(6, 4, 5),
];
for (t, src, dst) in &vs {
g.add_edge(*t, *src, *dst, NO_PROPS, None);
}
let actual = (1..=5)
.map(|v| local_clustering_coefficient(&windowed_graph, v))
.collect::<Vec<_>>();
println!("local clustering coefficient of all nodes: {:?}", actual);Functions
- measures the degree to which nodes in a graph tend to cluster together