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_a
int Number of vertices of the first part.
- N_b
int Number of vertices of the second part.
- p
float(optional, default:None) Probability of every edge.
- M
int(optional, default:None) Number of edges. Exactly one of
pandMmust be given.- directed
bool(optional, default:False) If
True, a directed graph is generated.- mode
str(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_edges
bool(optional, default:False) If
True, parallel edges are allowed in the \(G(N_a, N_b, M)\) model.
- N_a
- Returns:
- g
Graph The generated graph, where the vertices of the first part are \(0,\dots,N_a-1\), followed by those of the second part.
- g
See also
generate_erdos_renyiErdős-Rényi model
generate_bipartite_configurationRandom bipartite configuration model
generate_random_intersectionRandom 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") <...>
Random bipartite graph with parts of 30 (blue) and 40 (red) vertices and \(p=0.05\).#