Cluster
=======

>>> from networkx import *
>>> G = Graph()

>>> triangles(G)
[]
>>> triangles(G,with_labels=True)
{}

>>> clustering(G)
[]
>>> clustering(G,with_labels=True)
{}

>>> transitivity(G)
0.0

>>> G = path_graph(10)

>>> triangles(G)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> triangles(G,with_labels=True)
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0}

>>> clustering(G)
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
>>> clustering(G,with_labels=True)
{0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}

>>> transitivity(G)
0.0


>>> G = cubical_graph()

>>> triangles(G)
[0, 0, 0, 0, 0, 0, 0, 0]
>>> triangles(G,1)
0
>>> triangles(G,[1,2])
[0, 0]
>>> triangles(G,1,with_labels=True)
{1: 0}
>>> triangles(G,[1,2],with_labels=True)
{1: 0, 2: 0}
>>> clustering(G)
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
>>> clustering(G,1)
0.0
>>> clustering(G,[1,2])
[0.0, 0.0]
>>> clustering(G,1,with_labels=True)
{1: 0.0}
>>> clustering(G,[1,2],with_labels=True)
{1: 0.0, 2: 0.0}
>>> transitivity(G)
0.0


>>> G = complete_graph(5)

>>> triangles(G)
[6, 6, 6, 6, 6]
>>> sum(triangles(G))/3
10
>>> triangles(G,1)
6
>>> clustering(G)
[1.0, 1.0, 1.0, 1.0, 1.0]
>>> average_clustering(G)
1.0
>>> transitivity(G)
1.0

>>> G.delete_edge(1,2)

>>> triangles(G)
[5, 3, 3, 5, 5]
>>> triangles(G,1)
3
>>> clustering(G) == [5./6., 1.0, 1.0, 5./6., 5./6.]
True
>>> clustering(G,[1,4],with_labels=True)
{1: 1.0, 4: 0.83333333333333337}
>>> transitivity(G)
0.875


Transitivity is weighted average of clustering
----------------------------------------------

>>> t1=transitivity(G)
>>> print t1
0.875
>>> (cluster_d2,weights)=clustering(G,with_labels=True,weights=True)
>>> trans=[]
>>> for v in G.nodes():
...   trans.append(cluster_d2[v]*weights[v])
>>> t2=sum(trans)
>>> abs(t1-t2)<1e-15 
True



