generate_rmat#
- graph_tool.generation.generate_rmat(scale, m, a=0.57, b=0.19, c=0.19, directed=True, unique=False)[git][source]#
Generate a graph with the R-MAT model.
- Parameters:
- scale
int The graph will have \(2^\text{scale}\) vertices.
- m
int Number of edges.
- a, b, c
float(optional, default:0.57, 0.19, 0.19) Probabilities of the quadrants of the adjacency matrix (the fourth is \(d = 1 - a - b - c\)); the defaults are those of the Graph500 benchmark.
- directed
bool(optional, default:True) If
True, a directed graph is generated.- unique
bool(optional, default:False) If
True, the graph has \(m\) distinct edges (with no parallel edges), otherwise duplicates are kept.
- scale
- Returns:
- g
Graph The generated graph.
- g
See also
generate_sscaSSCA#2 benchmark graph
generate_erdos_renyiErdős-Rényi model
Notes
In the R-MAT model [chakrabarti-r-mat-2004], every edge is placed by recursively choosing one of the four quadrants of the adjacency matrix, which yields skewed degree distributions and a community-like structure. The source \(u\) and target \(v\) of an edge are determined by their binary digits, from the most significant to the least significant, in
scalesteps: at every step, with probabilities \(a, b, c, d\), the digits of \((u, v)\) are \((0, 0)\), \((0, 1)\), \((1, 0)\), and \((1, 1)\), respectively. After every step, each of the four probabilities is multiplied by an independent factor drawn uniformly from \([0.9, 1.1]\), and they are normalized again; this noise accumulates over the steps of an edge and starts anew for every edge. The edges are sampled independently, and the vertex labels are permuted randomly (with the same permutation for all edges). Self-loops may occur. Withunique=True, edges are sampled until there are \(m\) distinct ones (distinct ordered pairs, or unordered ones for undirected graphs), and the repeated ones are discarded; otherwise, parallel edges are kept. For undirected graphs, the direction of the sampled pairs is ignored. The algorithm runs in time \(O(m\,\text{scale})\), and withunique=Truerequires \(O(m)\) additional memory.References
[chakrabarti-r-mat-2004]Deepayan Chakrabarti, Yiping Zhan and Christos Faloutsos, “R-MAT: A recursive model for graph mining”, Proceedings of the 2004 SIAM International Conference on Data Mining, 442-446 (2004), DOI: 10.1137/1.9781611972740.43 [sci-hub, @tor]
Examples
>>> g = gt.generate_rmat(12, 40000) >>> print(g.num_vertices(), g.num_edges()) 4096 40000
A smaller undirected instance without parallel edges is drawn as follows:
>>> g = gt.generate_rmat(8, 500, directed=False, unique=True) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), ... output="generate_rmat-small.pdf") <...>
Undirected R-MAT graph with \(2^8\) vertices and 500 distinct edges, with the default probabilities \(a, b, c\).#