This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
configuration_model(deg_sequence, create_using=None, seed=None)¶
Return a random graph with the given degree sequence.
The configuration model generates a random pseudograph (graph with parallel edges and self loops) by randomly assigning edges to match the given degree sequence.
- deg_sequence (list of integers) – Each list entry corresponds to the degree of a node.
- create_using (graph, optional (default MultiGraph)) – Return graph of this type. The instance will be cleared.
- seed (hashable object, optional) – Seed for random number generator.
G – A graph with the specified degree sequence. Nodes are labeled starting at 0 with an index corresponding to the position in deg_sequence.
Return type: Raises:
NetworkXError– If the degree sequence does not have an even sum.
As described by Newman .
A non-graphical degree sequence (not realizable by some simple graph) is allowed since this function returns graphs with self loops and parallel edges. An exception is raised if the degree sequence does not have an even sum.
This configuration model construction process can lead to duplicate edges and loops. You can remove the self-loops and parallel edges (see below) which will likely result in a graph that doesn’t have the exact degree sequence specified.
The density of self-loops and parallel edges tends to decrease as the number of nodes increases. However, typically the number of self-loops will approach a Poisson distribution with a nonzero mean, and similarly for the number of parallel edges. Consider a node with k stubs. The probability of being joined to another stub of the same node is basically (k-1)/N where k is the degree and N is the number of nodes. So the probability of a self-loop scales like c/N for some constant c. As N grows, this means we expect c self-loops. Similarly for parallel edges.
 M.E.J. Newman, “The structure and function of complex networks”, SIAM REVIEW 45-2, pp 167-256, 2003.
>>> from networkx.utils import powerlaw_sequence >>> z=nx.utils.create_degree_sequence(100,powerlaw_sequence) >>> G=nx.configuration_model(z)
To remove parallel edges:
To remove self loops: