generate_random_dot_product

generate_random_dot_product#

graph_tool.generation.generate_random_dot_product(x, y=None, directed=None, signature=None)[git][source]#

Generate a (generalized) random dot product graph.

Parameters:
xtwo-dimensional array

Latent positions \(\boldsymbol x_v\) of the vertices, as rows.

ytwo-dimensional array (optional, default: None)

Latent positions \(\boldsymbol y_v\) of the vertices as targets, for directed graphs. If not given, x is used.

directedbool (optional, default: False)

If True, a directed graph is generated (implied if y is given).

Returns:
gGraph

The generated graph.

See also

generate_kernel_graph

Inhomogeneous random graph

spectral_graph_forge

Random graph with a given low-rank spectrum

graph_tool.spectral.spectral_embedding

Spectral embedding of the vertices

Notes

In the random dot product graph [young-random-2007] [athreya-statistical-2018], every pair \(u < v\) (or every ordered pair \(u \neq v\), if directed) is an edge independently with probability

\[p_{uv} = \min\left(\max\left(\sum_k \boldsymbol x_{uk} s_k \boldsymbol y_{vk}, 0\right), 1\right),\]

where \(\boldsymbol y = \boldsymbol x\) if y is not given, and \(s_k = 1\), unless signature is given. With signs \(s_k = -1\), this is the generalized random dot product graph of Rubin-Delanchy et al. [rubin-delanchy-statistical-2022], which can have any symmetric probability matrix of low rank, and which includes the stochastic block model as a special case. For undirected graphs, only the pairs \(u < v\) are considered, so that y should be chosen such that \(\sum_k \boldsymbol x_{uk} s_k \boldsymbol y_{vk}\) is symmetric in \(u\) and \(v\). The algorithm runs in time \(O(N^2d)\) for latent positions of dimension \(d\).

References

[young-random-2007]

Stephen J. Young and Edward R. Scheinerman, “Random dot product graph models for social networks”, in Algorithms and Models for the Web-Graph, Lecture Notes in Computer Science 4863, 138-149 (2007), DOI: 10.1007/978-3-540-77004-6_11 [sci-hub, @tor]

[athreya-statistical-2018]

Avanti Athreya et al., “Statistical inference on random dot product graphs: a survey”, Journal of Machine Learning Research 18, 1-92 (2018), arXiv: 1709.05454

[rubin-delanchy-statistical-2022]

Patrick Rubin-Delanchy, Joshua Cape, Minh Tang and Carey E. Priebe, “A statistical interpretation of spectral embedding: the generalised random dot product graph”, Journal of the Royal Statistical Society Series B 84, 1446-1473 (2022), DOI: 10.1111/rssb.12509 [sci-hub, @tor], arXiv: 1709.05506

Examples

>>> x = np.random.dirichlet([1, 1, 1], 1000) * .5
>>> g = gt.generate_random_dot_product(x)
>>> print(g.num_edges())
41728

A smaller instance with latent positions concentrated near the corners of the simplex is drawn as follows, with every vertex in the color of its largest latent coordinate:

>>> x = np.random.dirichlet([.1, .1, .1], 150) * .3
>>> g = gt.generate_random_dot_product(x)
>>> cmap = matplotlib.colors.ListedColormap(
...     ["#9bbedc", "#f28c8e", "#a6d7a4"])
>>> gt.graph_draw(g, pos=gt.sfdp_layout(g),
...               vertex_fill_color=g.new_vp("int", vals=x.argmax(axis=1)),
...               vcmap=cmap,
...               output="generate_random_dot_product-small.pdf")
<...>
../_images/generate_random_dot_product-small.png

Random dot product graph with \(N=150\) latent positions drawn from the Dirichlet distribution with parameters \((0.1, 0.1, 0.1)\) and scaled by 0.3. The vertex colors indicate the largest coordinate of every latent position.#