Mercurial > public > think_complexity
comparison ch4ex4.py @ 24:5c2c4ce095ef
A stab at the L(p)/L(0) plot.
I still don't quite get how the graphs in the Watts and Strogatz paper were
generated. My results have basically the same shape, but don't converge to 0.
I'm not sure how this is possible if the rewire function does not remove edges.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 03 Jan 2013 18:41:13 -0600 |
parents | 74c9d126bd05 |
children | a46783561538 |
comparison
equal
deleted
inserted
replaced
23:74c9d126bd05 | 24:5c2c4ce095ef |
---|---|
18 n = 1000 | 18 n = 1000 |
19 k = 10 | 19 k = 10 |
20 vs = [Vertex(str(i)) for i in range(n)] | 20 vs = [Vertex(str(i)) for i in range(n)] |
21 g = SmallWorldGraph(vs, k, 0.0) | 21 g = SmallWorldGraph(vs, k, 0.0) |
22 c0 = g.clustering_coefficient() | 22 c0 = g.clustering_coefficient() |
23 print 'c0 =', c0 | 23 l0 = g.big_l() |
24 print 'c0 =', c0, 'l0 =', l0 | |
24 | 25 |
25 # compute data | 26 # compute data |
26 p_vals = [0, | 27 p_vals = [# 0, |
27 0.0001, 0.0002, 0.0004, 0.0006, 0.0008, | 28 0.0001, 0.0002, 0.0004, # 0.0006, 0.0008, |
28 0.001, 0.002, 0.004, 0.006, 0.008, | 29 0.001, 0.002, 0.004, # 0.006, 0.008, |
29 0.01, 0.02, 0.04, 0.06, 0.08, | 30 0.01, 0.02, 0.04, # 0.06, 0.08, |
30 0.1, 0.2, 0.4, 0.6, 0.8, | 31 0.1, 0.2, 0.4, # 0.6, 0.8, |
31 1.0] | 32 1.0] |
32 | 33 |
33 c_vals = [] | 34 c_vals = [] |
35 l_vals = [] | |
34 for p in p_vals: | 36 for p in p_vals: |
35 g = SmallWorldGraph(vs, k, p) | 37 g = SmallWorldGraph(vs, k, p) |
36 c_vals.append(g.clustering_coefficient() / c0) | 38 c_vals.append(g.clustering_coefficient() / c0) |
39 l_vals.append(g.big_l() / l0) | |
37 | 40 |
38 # plot graph | 41 # plot graph |
39 pyplot.clf() | 42 pyplot.clf() |
40 pyplot.xscale('log') | 43 pyplot.xscale('log') |
41 pyplot.yscale('log') | 44 pyplot.yscale('log') |
42 pyplot.title('') | 45 pyplot.title('') |
43 pyplot.xlabel('p') | 46 pyplot.xlabel('p') |
44 pyplot.ylabel('C(p)/C(0)') | 47 pyplot.ylabel('C(p)/C(0)') |
45 pyplot.plot(p_vals, c_vals, label=title, color='green', linewidth=3) | 48 pyplot.plot(p_vals, c_vals, label='C(p)/C(0)', color='green', linewidth=3) |
49 pyplot.plot(p_vals, l_vals, label='L(p)/L(0)', color='blue', linewidth=3) | |
46 pyplot.legend(loc=4) | 50 pyplot.legend(loc=4) |
47 pyplot.show() | 51 pyplot.show() |