Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

expected_degree_graph

expected_degree_graph(w, seed=None, selfloops=True)[source]

Return a random graph with given expected degrees.

Given a sequence of expected degrees \(W=(w_0,w_1,\ldots,w_{n-1}\)) of length \(n\) this algorithm assigns an edge between node \(u\) and node \(v\) with probability

\[p_{uv} = \frac{w_u w_v}{\sum_k w_k} .\]
Parameters:
  • w (list) – The list of expected degrees.
  • selfloops (bool (default=True)) – Set to False to remove the possibility of self-loop edges.
  • seed (hashable object, optional) – The seed for the random number generator.
Returns:

Return type:

Graph

Examples

>>> z=[10 for i in range(100)]
>>> G=nx.expected_degree_graph(z)

Notes

The nodes have integer labels corresponding to index of expected degrees input sequence.

The complexity of this algorithm is \(\mathcal{O}(n+m)\) where \(n\) is the number of nodes and \(m\) is the expected number of edges.

The model in [1] includes the possibility of self-loop edges. Set selfloops=False to produce a graph without self loops.

For finite graphs this model doesn’t produce exactly the given expected degree sequence. Instead the expected degrees are as follows.

For the case without self loops (selfloops=False),

\[E[deg(u)] = \sum_{v \ne u} p_{uv} = w_u \left( 1 - \frac{w_u}{\sum_k w_k} \right) .\]

NetworkX uses the standard convention that a self-loop edge counts 2 in the degree of a node, so with self loops (selfloops=True),

\[E[deg(u)] = \sum_{v \ne u} p_{uv} + 2 p_{uu} = w_u \left( 1 + \frac{w_u}{\sum_k w_k} \right) .\]

References

[1]Fan Chung and L. Lu, Connected components in random graphs with given expected degree sequences, Ann. Combinatorics, 6, pp. 125-145, 2002.
[2]Joel Miller and Aric Hagberg, Efficient generation of networks with given expected degrees, in Algorithms and Models for the Web-Graph (WAW 2011), Alan Frieze, Paul Horn, and Paweł Prałat (Eds), LNCS 6732, pp. 115-126, 2011.