6. Evolutionยถ

The degree of a node in an undirected graph is the number of neighbors it has.

The degree distribution of a graph is the probability distribution of the degrees over the entire network.

degrees = G.degree()
degree_values = sorted(set(degrees.values()))
histogram = [list(degrees.values()).count(i)/float(nx.number_of_nodes( G)) \
            for i in degree_values]

import matplotlib.pyplot as plt

plt.bar(degree_values,histogram)
plt.xlabel('Degree')
plt.ylabel('Fraction of Nodes')
plt.show()
alternate text

From University of Michigan, Python for Data Science Coursera Specialization

6.1. Preferential Attachment Modelยถ

The degree distribution of a graph is the probability distribution of the degrees over the entire network.

  • Many real networks have degree distributions that look like power laws (๐‘ƒ๐‘˜ =C๐‘˜^-a).
  • Networks with a power law distribution have many nodes with small degree and a few nodes with very large degree.
  • Models of network generation allow us to identify mechanisms that give rise to observed patterns in real data.
  • The Preferential Attachment Model produces networks with a power law degree distribution.
alternate text

From University of Michigan, Python for Data Science Coursera Specialization

nx.barabasi_albert_graph(n, m) returns a network with n nodes. Each new node attaches to m existing nodes according to the Preferential Attachment model.

G = nx.barabasi_albert_graph(1000000,1)
degrees = G.degree()
degree_values = sorted(set(degrees.values()))
histogram = [list(degrees.values().count(i))/float(nx.number_of_node s(G)) \
              for i in degree_values]

import matplotlib.pyplot as plt

plt.plot(degree_values,histogram, 'o')
plt.xlabel('Degree')
plt.ylabel('Fraction of Nodes')
plt.xscale('log')
plt.yscale('log')
plt.show()

6.2. Small World Modelยถ

Social networks tend to have high clustering coefficient and small average path length.

  • Start with a ring of ๐‘› nodes, where each node is connected to its ๐‘˜ nearest neighbors.
  • Fix a parameter ๐‘ โˆˆ [0,1]
  • Consider each edge ๐‘ข, ๐‘ฃ . With probability ๐‘, select a node ๐‘ค at random and rewire the edge (๐‘ข, ๐‘ฃ) so it becomes (๐‘ข, ๐‘ค).
G = nx.watts_strogatz_graph(1000,6,0.04)
degrees = G.degree()
degree_values = sorted(set(degrees.values()))
histogram = [list(degrees.values()).count(i)/float(nx.number_of_node s(G)) \
              for i in degree_values]

import matplotlib.pyplot as plt

plt.bar(degree_values,histogram)
plt.xlabel('Degree')
plt.ylabel('Fraction of Nodes')
plt.show()
alternate text

From University of Michigan, Python for Data Science Coursera Specialization

Variants of the small world model in NetworkX:

  • Small world networks can be disconnected, which is sometime undesirable.
  • nx.connected_watts_strogatz_graph(n, k, p, t) runs watts_strogatz_graph(n, k, p) up to t times, until it returns a connected small world network.
  • nx.newman_watts_strogatz_graph(n, k, p) runs a model similar to the small world model, sbut rather than rewiring edges, new edges are added with probability ๐‘.