def test_clustercoefficient():

	ps = np.arange(0, 1, 0.01)
	n = 1000
	e = 10
	labels = string.ascii_lowercase + string.ascii_uppercase
	vs = []
	iter = misc.gen_identifier()
	for i in range(n):
		vs.append(Vertex(iter.next()))
	g = SmallWorldGraph(vs)
	g.add_regular_ring_lattice(e)
	c0 = g.get_clustering_coefficient()
	xs = []
	ys = []
	for p in ps:
		g = SmallWorldGraph(vs)
		g.add_regular_ring_lattice(e)
		g.rewire(p)
		ys.append(g.get_clustering_coefficient() / c0)
		xs.append(p)

	fig = plt.figure(dpi = 100)
	plt.subplot(1,1,1)
	plt.plot(xs, ys)
	plt.xscale('log')
	plt.show()
def test_average_path_len():

	ps = np.arange(0, 1, 0.05)
	print ps
	n = 1000
	e = 10
	labels = string.ascii_lowercase + string.ascii_uppercase
	vs = []
	iter = misc.gen_identifier()
	for i in range(n):
		vs.append(Vertex(iter.next()))
	g = SmallWorldGraph(vs)
	g.add_regular_ring_lattice(e)
	l0 = g.get_averaged_shortest_path()
	layout = CircleLayout(g)
	xs = []
	ys = []
	for p in ps:
		g = SmallWorldGraph(vs)
		g.add_regular_ring_lattice(e)
		g.rewire(p)
		l1 = g.get_averaged_shortest_path() / l0
		ys.append(l1)
		xs.append(p)
		print l1, p

	fig = plt.figure(dpi = 100)
	plt.subplot(1,1,1)
	plt.plot(xs, ys)
	plt.xscale('log')
	plt.show()
Пример #3
0
def makeGraph(n='52', k='5', p='0.1'):
    #create n Vertices
    n = int(n)
    k = int(k)
    p = float(p)

    names = name_generator()
    vs = [Vertex(names.next()) for c in range(n)]

    # create a graph
    g = SmallWorldGraph(vs, k, p)
    start = clock()
    g.char_length()
    charLength1 = clock() - start

    start = clock()
    g.char_length2()
    charLength2 = clock() - start

    start = clock()
    g.char_length3()
    charLength3 = clock() - start

    start = clock()
    g.char_length4()
    charLength4 = clock() - start
    return charLength1, charLength2, charLength3, charLength4
def generateData(pStart, pMultiplier):
    c0 = 0.75
    x = []
    y = []
    while (pStart < 1):
        names = name_generator()
        vs = [Vertex(names.next()) for c in range(52)]
        graph = SmallWorldGraph(vs, 5, pStart)
        x.append(pStart)
        y.append(graph.cluster_coef() / c0)
        pStart *= pMultiplier
    return [x, y]
def generateData(pStart, pMultiplier):
    l0 = (52 / (2 * 5))
    x = []
    y = []
    while (pStart < 1):
        names = name_generator()
        vs = [Vertex(names.next()) for c in range(52)]
        graph = SmallWorldGraph(vs, 5, pStart)
        x.append(pStart)
        y.append(graph.char_length() / l0)
        pStart *= pMultiplier
    return [x, y]
def main(n='20', k='4', p='0.4'):
    n = int(n)
    k = int(k)
    p = float(p)
    g = SmallWorldGraph(n, k)
    g.rewire(p)

    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
Пример #7
0
def main(script, n='25', *args):

    # create n Vertices
    n = int(n)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Node(c) for c in labels[:n]]

    # create a graph and a layout
    g = SmallWorldGraph(vs)
    # g.add_random_edges(.2)
    # g.add_all_edges()
    g.add_regular_edges(4)
    g.rewire(.20)
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
def main(script, n='10', *args):

	# create n Vertices
	n = int(n)
	labels = string.ascii_lowercase + string.ascii_uppercase
	vs = []
	iter = misc.gen_identifier()
	for i in range(n):
		vs.append(Vertex(iter.next()))
	vs = [Vertex(c) for c in labels[:n]]

	#test_average_path_len()


	# create a graph and a layout
	#g = Graph(vs)
	#g = RandomGraph(vs)
	#g.is_connected
	g = SmallWorldGraph(vs)
	g.add_regular_ring_lattice(4)
	print g.all_pairs_shortest_path()
	#v = vs[0]
	#print v
	#print g.shortest_path(v)
	#w = vs[3]
	#print w
	#print g.shortest_path(v, w)
	#print g.get_max_neighbors()
	#print g.get_clustering_coefficient()
	#p = 0.8
	#g.rewire(p)
	#print g.get_clustering_coefficient()
	#test_clustercoefficient()
	#g.add_random_edges(1.0)
	#print g.is_connected()

	# draw the graph
	layout = CircleLayout(g)
	gw = GraphWorld()
	gw.show_graph(g, layout)
	gw.mainloop()
Пример #9
0
def main(script, n='25', *args):

    # create n Vertices
    n = int(n)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Node(c) for c in labels[:n]]

    # create a graph and a layout
    g = SmallWorldGraph(vs)
    # g.add_random_edges(.2)
    # g.add_all_edges()
    g.add_regular_edges(4)
    g.rewire(.20)
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
def main(script, n='1000', k='10', *args):

    n = int(n) #number of vertices
    k = int(k) #number of edges in regular graph
    vertices = [Vertex(c) for c in range(n)]

    g = SmallWorldGraph(vertices)
    g.add_regular_edges(k)

    #regular graph's clustering coefficient and avg path length
    c_zero = g.clustering_coefficient()
    l_zero = g.average_path_length()
    print c_zero, l_zero

    f = open("plots/output.csv", "wb")
    print 'p\tC\tL'
    f.write('p,C(p)/C(0),L(p)/L(0)\n')

    #begin rewiring to tease out small-world network characteristics
    for log_exp in numpy.arange(-40, 1, 1): #incrementation scheme for logarithmic exponents
        g = SmallWorldGraph(vertices)
        g.add_regular_edges(k)
        p = numpy.power(10, log_exp/10.0)
        g.rewire(p)
        print '%s\t%s\t%s' % (p, g.clustering_coefficient()/c_zero, g.average_path_length()/l_zero)
        f.write('%s,%s,%s\n' % (p, g.clustering_coefficient()/c_zero, g.average_path_length()/l_zero))
    f.close()