diff ch5ex6-3.py @ 36:305cc03c2750

Chapter 5.5, exercise 6, #3: compute WS clustering coefficient and characteristic length on a BA model graph.
author Brian Neal <bgneal@gmail.com>
date Thu, 10 Jan 2013 19:24:02 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ch5ex6-3.py	Thu Jan 10 19:24:02 2013 -0600
@@ -0,0 +1,19 @@
+"""Chapter 5.5, exercise 6 in Allen Downey's Think Complexity book.
+
+3. Use the BA model to generate a graph with about 1000 vertices and compute the
+   characteristic length and clustering coefficient as defined in the Watts and
+   Strogatz paper. Do scale-free networks have the characteristics of
+   a small-world graph?
+
+"""
+
+from ch5ex6 import BAGraph
+
+g = BAGraph(5, 5)
+
+for i in xrange(1000):
+    g.step()
+
+g.set_edge_length(1)
+print "Clustering coefficient:", g.clustering_coefficient()
+print "Characteristic length:", g.big_l3()