graphscope.nx.generators.degree_seq.expected_degree_graph(w, seed=None, selfloops=True)[source]#

Returns 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} .\]
  • w (list) – The list of expected degrees.

  • selfloops (bool (default=True)) – Set to False to remove the possibility of self-loop edges.

  • seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.

Return type:



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


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) .\]