如何找到图的全局聚类系数?

How to find Global Clustering Coefficient of graph?

我从上周开始学习网络分析及其指标计算。没有足够的知识。谁能检查这个?

寻找全局聚类系数的公式是,

C = (3 * Number of Triangles) / (Number of connected triples of vertices)

我将全局聚类系数计算为,

Number of Triangles = 2 
(as there are 2 directly connected triangles in the graph i-e Node4->Node5->Node6 and Node1->Node3->Node4)

Number of connected triples of vertices = 4 
(as Node1, Node2, Node3 & Node6 have three vertices connected)

 C = (3 * 2) / 4 = 1.5

我不知道我做得对不对。任何人都可以检查这个吗?或者纠正我如果我错了

分母必须计算所有具有 2 条或 3 条边的三元组。 因此,给定的图我们有以下三元组:
5-4-6
6-5-4、6-4-2、6-5-2
4-6-1、4-5-1、4-6-3、4-5-3、4-1-3、4-6-5
1-4-3、1-3-2、1-4-2
3-4-1、3-1-7、3-4-7
7-3-2
2-7-1、2-1-6、2-7-6
这给出了总共 20 个三元组,所以 gcc 是 2*3/20 = 0.3.

该算法在python的networkx包中实现。这个例子的代码是:

import networkx as nx
g = nx.Graph()
g.add_edges_from([(5,6), (5,4), (4,6), (4,1), (4,3), (3,1), (3,7), (7,2), (1,2), (6,2)])
print(nx.transitivity(g))