Mercurial > public > think_complexity
diff 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 |
line wrap: on
line diff
--- a/ch4ex4.py Wed Jan 02 16:50:55 2013 -0600 +++ b/ch4ex4.py Thu Jan 03 18:41:13 2013 -0600 @@ -20,20 +20,23 @@ vs = [Vertex(str(i)) for i in range(n)] g = SmallWorldGraph(vs, k, 0.0) c0 = g.clustering_coefficient() -print 'c0 =', c0 +l0 = g.big_l() +print 'c0 =', c0, 'l0 =', l0 # compute data -p_vals = [0, - 0.0001, 0.0002, 0.0004, 0.0006, 0.0008, - 0.001, 0.002, 0.004, 0.006, 0.008, - 0.01, 0.02, 0.04, 0.06, 0.08, - 0.1, 0.2, 0.4, 0.6, 0.8, +p_vals = [# 0, + 0.0001, 0.0002, 0.0004, # 0.0006, 0.0008, + 0.001, 0.002, 0.004, # 0.006, 0.008, + 0.01, 0.02, 0.04, # 0.06, 0.08, + 0.1, 0.2, 0.4, # 0.6, 0.8, 1.0] c_vals = [] +l_vals = [] for p in p_vals: g = SmallWorldGraph(vs, k, p) c_vals.append(g.clustering_coefficient() / c0) + l_vals.append(g.big_l() / l0) # plot graph pyplot.clf() @@ -42,6 +45,7 @@ pyplot.title('') pyplot.xlabel('p') pyplot.ylabel('C(p)/C(0)') -pyplot.plot(p_vals, c_vals, label=title, color='green', linewidth=3) +pyplot.plot(p_vals, c_vals, label='C(p)/C(0)', color='green', linewidth=3) +pyplot.plot(p_vals, l_vals, label='L(p)/L(0)', color='blue', linewidth=3) pyplot.legend(loc=4) pyplot.show()