Search code examples
graphgraph-theorysocial-networkingweb-analytics

How to find Global Clustering Coefficient of graph?


I start learning network analysis & its metrics calculation from last week. Don't have enough knowledge. Can anyone check this ?

The formula of finding the global clustering co-efficient is,

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

I calculate the global clustering co-efficient as,

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

I don't know I do it correctly or not. Can anyone check this ? or correct me If I am wrong

enter image description here


Solution

  • The denominator must count all triples with 2 or 3 edges. So, the the given graph we have the following triples:
    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
    This gives a total of 20 triples, so the gcc is 2*3/20 = 0.3.

    This algorithm is implemented in python's networkx package. The code for this example is:

    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))