Mercurial > public > think_complexity
diff ch5ex6.py @ 35:10db8c3a6b83
Chapter 5.5, exercise 6, #2: plot P(k) vs. k for a WS graph.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 09 Jan 2013 20:51:16 -0600 |
parents | 66a5e7f7c10f |
children |
line wrap: on
line diff
--- a/ch5ex6.py Wed Jan 09 20:19:49 2013 -0600 +++ b/ch5ex6.py Wed Jan 09 20:51:16 2013 -0600 @@ -6,7 +6,6 @@ k for a graph with 150 000 vertices. """ -import collections import random import sys @@ -86,27 +85,6 @@ for w in vs: self.add_edge(Edge(v, w)) - def get_p(self): - """This method returns a dictionary of probabilities where each key is - the connectivity k and the value is the probability [0-1] for this - graph. - - """ - # First, for each vertex, count up how many neighbors it has - vs = self.vertices() - - c = collections.Counter() - for v in vs: - n = len(self.out_vertices(v)) - c[n] += 1 - - n = len(vs) - if n > 0: - for k in c: - c[k] = float(c[k]) / n - - return c - def main(script, m0, m, n):