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

configuration_model
(deg_sequence, create_using=None, seed=None)[source]¶ 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.
Parameters:  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.
Returns: 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.See also
is_valid_degree_sequence()
Notes
As described by Newman [1].
A nongraphical 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 selfloops and parallel edges (see below) which will likely result in a graph that doesn’t have the exact degree sequence specified.
The density of selfloops and parallel edges tends to decrease as the number of nodes increases. However, typically the number of selfloops 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 (k1)/N where k is the degree and N is the number of nodes. So the probability of a selfloop scales like c/N for some constant c. As N grows, this means we expect c selfloops. Similarly for parallel edges.
References
[1] M.E.J. Newman, “The structure and function of complex networks”, SIAM REVIEW 452, pp 167256, 2003. Examples
>>> from networkx.utils import powerlaw_sequence >>> z=nx.utils.create_degree_sequence(100,powerlaw_sequence) >>> G=nx.configuration_model(z)
To remove parallel edges:
>>> G=nx.Graph(G)
To remove self loops:
>>> G.remove_edges_from(G.selfloop_edges())