generate_random_intersection

generate_random_intersection#

graph_tool.generation.generate_random_intersection(N, M, p=None, k=None)[git][source]#

Generate a random intersection graph.

Parameters:
Nint

Number of vertices.

Mint

Number of attributes.

pfloat or iterable of float (optional, default: None)

Probability that a vertex has an attribute, the same for all attributes, or one value for every attribute.

kint (optional, default: None)

Number of attributes of every vertex. Exactly one of p and k must be given.

Returns:
gGraph

The generated undirected graph.

See also

generate_bipartite_erdos_renyi

Random bipartite graph

graph_projection

Projection of a bipartite graph

interval_graph

Intersection graph of intervals

Notes

In a random intersection graph [karonski-random-1999], every vertex receives a random subset of \(M\) attributes, and two vertices are connected if they share at least one attribute. In the uniform model, every vertex has every attribute independently with probability \(p\); in the general model, with a probability \(p_j\) that depends on the attribute; and in the \(k\) model [godehardt-two-2003], every vertex has a uniformly random subset of \(k\) attributes. The bipartite graph between vertices and attributes is generated in time \(O(N + M + E_b)\), and is projected on the vertices with graph_projection(), in time \(O(\sum_j n_j^2)\), where \(n_j\) is the number of vertices with attribute \(j\).

References

[karonski-random-1999]

Michał Karoński, Edward R. Scheinerman and Karen B. Singer-Cohen, “On random intersection graphs: The subgraph problem”, Combinatorics, Probability and Computing 8, 131-159 (1999), DOI: 10.1017/S0963548398003459 [sci-hub, @tor]

[godehardt-two-2003]

Erhard Godehardt and Jerzy Jaworski, “Two models of random intersection graphs for classification”, in Exploratory Data Analysis in Empirical Research, 67-81 (2003), DOI: 10.1007/978-3-642-55721-7_8 [sci-hub, @tor]

Examples

>>> g = gt.generate_random_intersection(1000, 500, p=0.002)
>>> print(g.num_edges())
999
>>> g = gt.generate_random_intersection(1000, 500, k=2)
>>> print(g.num_edges())
3934

A smaller instance is drawn as follows:

>>> g = gt.generate_random_intersection(100, 100, k=2)
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               output="generate_random_intersection-small.pdf")
<...>
../_images/generate_random_intersection-small.png

Random intersection graph with \(N=100\) vertices and \(M=100\) attributes, with \(k=2\) attributes per vertex.#