コード例 #1
0
 def test_clustering_coefficient(self):
     """tests the clustering coefficent"""
     v = Vertex('v')
     w = Vertex('w')
     x = Vertex('x')
     e = Arc(v,w)
     e2 = Arc(x, w)
     e3 = Arc(x, v)
     dg = DirectedGraph([v, w, x],[e, e2, e3])
     self.assertAlmostEqual(dg.clustering_coefficient(),0.5)
コード例 #2
0
def ErdosRenyiClustering():
    """
    Creates an Erdos-Renyi graph of 1000 vertices and iterates through
    p, checking the clustering coefficient each time. Uses pylot to
    graph all that stuff, to see if there's anything interesting
    """
    import matplotlib.pyplot as pyplot
    vs = [Vertex(str(v)) for v in range(100)]
    cs = []
    ps = []
    p = 0.01
    for i in range(100):
        drg = DirectedGraph(vs)
        drg.add_random_arcs(p)
        ps.append(p)
        cs.append(drg.clustering_coefficient())
        p += 0.01
    pyplot.plot(ps,cs)
    pyplot.xlabel('p')
    pyplot.ylabel('clustering coefficient')
    pyplot.show()