networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
configuration_model(deg_sequence, create_using=None, seed=None)

The configuration model generates a random pseudograph (graph with parallel edges and self loops) by randomly assigning edges to match the given degree sequence.

Notes

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.

Parameters

deg_sequence : list of nonnegative integers

Each list entry corresponds to the degree of a node.

create_using : NetworkX graph constructor, optional (default MultiGraph)

Graph type to create. If graph instance, then cleared before populated.

seed : integer, random_state, or None (default)

Indicator of random number generation state. See Randomness<randomness> .

Raises

NetworkXError

If the degree sequence does not have an even sum.

Returns

G : MultiGraph

A graph with the specified degree sequence. Nodes are labeled starting at 0 with an index corresponding to the position in deg_sequence.

Returns a random graph with the given degree sequence.

See Also

is_graphical

Examples

You can create a degree sequence following a particular distribution by using the one of the distribution functions in ~networkx.utils.random_sequence (or one of your own). For example, to create an undirected multigraph on one hundred nodes with degree sequence chosen from the power law distribution:

>>> sequence = nx.random_powerlaw_tree_sequence(100, tries=5000)
... G = nx.configuration_model(sequence)
... len(G) 100
>>> actual_degrees = [d for v, d in G.degree()]
... actual_degrees == sequence True

The returned graph is a multigraph, which may have parallel edges. To remove any parallel edges from the returned graph:

>>> G = nx.Graph(G)

Similarly, to remove self-loops:

>>> G.remove_edges_from(nx.selfloop_edges(G))
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.generators.degree_seq.random_degree_sequence_graph networkx.generators.degree_seq.directed_configuration_model networkx.generators.degree_seq.directed_havel_hakimi_graph networkx.generators.degree_seq.configuration_model

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/generators/degree_seq.py#128
type: <class 'function'>
Commit: