generate_bipartite_erdos_renyi

generate_bipartite_erdos_renyi#

graph_tool.generation.generate_bipartite_erdos_renyi(N_a, N_b, p=None, M=None, directed=False, mode='out', parallel_edges=False)[git][source]#

Generate a random bipartite graph with the Erdős-Rényi model.

Parameters:
N_aint

Number of vertices of the first part.

N_bint

Number of vertices of the second part.

pfloat (optional, default: None)

Probability of every edge.

Mint (optional, default: None)

Number of edges. Exactly one of p and M must be given.

directedbool (optional, default: False)

If True, a directed graph is generated.

modestr (optional, default: "out")

Direction of the edges, for directed graphs: from the first part to the second ("out"), from the second to the first ("in"), or both, independently ("all").

parallel_edgesbool (optional, default: False)

If True, parallel edges are allowed in the \(G(N_a, N_b, M)\) model.

Returns:
gGraph

The generated graph, where the vertices of the first part are \(0,\dots,N_a-1\), followed by those of the second part.

See also

generate_erdos_renyi

Erdős-Rényi model

generate_bipartite_configuration

Random bipartite configuration model

generate_random_intersection

Random intersection graph

Notes

Every pair of vertices of different parts (in each allowed direction) is connected independently with probability \(p\), or \(M\) distinct pairs are chosen uniformly at random. With parallel_edges=True, the multigraph is chosen uniformly among those with \(M\) edges (i.e. the multiset of pairs is uniform). The algorithm runs in time \(O(N + E)\).

Examples

>>> g = gt.generate_bipartite_erdos_renyi(100, 200, p=0.05)
>>> print(g.num_edges())
986
>>> g = gt.generate_bipartite_erdos_renyi(100, 200, M=500)
>>> print(g.num_edges())
500

A smaller instance is drawn as follows, with the two parts in different colors:

>>> g = gt.generate_bipartite_erdos_renyi(30, 40, p=0.05)
>>> b = g.new_vp("int", vals=[0] * 30 + [1] * 40)
>>> cmap = matplotlib.colors.ListedColormap(
...     ["#9bbedc", "#f28c8e"])
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap,
...               output="generate_bipartite_erdos_renyi-small.pdf")
<...>
../_images/generate_bipartite_erdos_renyi-small.png

Random bipartite graph with parts of 30 (blue) and 40 (red) vertices and \(p=0.05\).#