networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
random_clustered_graph(joint_degree_sequence, create_using=None, seed=None)

This uses a configuration model-like approach to generate a random graph (with parallel edges and self-loops) by randomly assigning edges to match the given joint degree sequence.

The joint degree sequence is a list of pairs of integers of the form $[(d_{1,i}, d_{1,t}), \dotsc, (d_{n,i}, d_{n,t})]$. According to this list, vertex $u$ is a member of $d_{u,t}$ triangles and has $d_{u, i}$ other edges. The number $d_{u,t}$ is the triangle degree of $u$ and the number $d_{u,i}$ is the independent edge degree.

Notes

As described by Miller (see also Newman for an equivalent description).

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 independent degree sequence does not have an even sum or the triangle degree sequence sum is not divisible by 3.

This configuration model-like 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. This "finite-size effect" decreases as the size of the graph increases.

Parameters

joint_degree_sequence : list of integer pairs

Each list entry corresponds to the independent edge degree and triangle 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 independent edge degree sequence sum is not even or the triangle degree sequence sum is not divisible by 3.

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.

Generate a random graph with the given joint independent edge degree and triangle degree sequence.

Examples

>>> deg = [(1, 0), (1, 0), (1, 0), (2, 0), (1, 0), (2, 1), (0, 1), (0, 1)]
... G = nx.random_clustered_graph(deg)

To remove parallel edges:

>>> G = nx.Graph(G)

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.random_clustered.random_clustered_graph

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/random_clustered.py#9
type: <class 'function'>
Commit: