spectral_graph_forge

spectral_graph_forge#

graph_tool.generation.spectral_graph_forge(g, alpha, transformation='identity')[git][source]#

Generate a random graph with approximately the same spectral structure as a given one.

Parameters:
gGraph

Undirected graph.

alphafloat

Fraction of the eigenvectors retained, in \([0, 1]\).

transformationstr (optional, default: "identity")

Matrix that is approximated: the adjacency matrix ("identity") or the modularity matrix ("modularity").

Returns:
hGraph

The generated undirected graph.

See also

corrupt_graph

Random removal and addition of edges

random_rewire

Random rewiring preserving the degrees

generate_random_dot_product

Generalized random dot product graph

graph_tool.spectral.adjacency

Adjacency matrix

Notes

In the spectral graph forge of Baldesi, Butts, and Markopoulou [baldesi-spectral-2018], the matrix \(B\) (the adjacency matrix \(A\), or the modularity matrix \(A - \boldsymbol k\boldsymbol k^\top/2E\), where \(\boldsymbol k\) is the vector of degrees) is approximated by its leading eigenvectors,

\[\tilde B = \sum_{i=1}^{\lfloor\alpha N\rceil} \lambda_i\boldsymbol v_i\boldsymbol v_i^\top,\]

where \(B = \sum_i\lambda_i\boldsymbol v_i\boldsymbol v_i^\top\) is the eigendecomposition with \(|\lambda_1| \ge |\lambda_2| \ge \dots\), and \(\lfloor\alpha N\rceil\) is \(\alpha N\) rounded to the nearest integer. For the modularity matrix, \(\boldsymbol k\boldsymbol k^\top/2E\) is added back to \(\tilde B\). Every pair \(i < j\) is then connected independently with probability \(\min(\max(\tilde B_{ij}, 0), 1)\), so that the result is a simple graph.

This is a generalized random dot product graph, sampled with generate_random_dot_product(), with the latent positions \(\boldsymbol x_{ik} = \sqrt{|\lambda_k|}v_{ik}\) and the signs \(s_k = \operatorname{sign}\lambda_k\), for \(k \le \lfloor\alpha N\rceil\), and, for the modularity matrix, the additional dimension \(\boldsymbol x_{ik} = k_i/\sqrt{2E}\) with \(s_k = 1\). It is not, in general, a stochastic block model, since \(\tilde B\) is not constant within groups of vertices, but the stochastic block model is a special case of this model. The algorithm uses dense matrices, and runs in time \(O(N^3)\).

References

[baldesi-spectral-2018]

Luca Baldesi, Carter T. Butts and Athina Markopoulou, “Spectral graph forge: Graph generation targeting modularity”, in IEEE INFOCOM 2018, 1727-1735 (2018), DOI: 10.1109/INFOCOM.2018.8485916 [sci-hub, @tor], arXiv: 1801.01715

Examples

>>> g = gt.collection.data["karate"]
>>> h = gt.spectral_graph_forge(g, 0.8)
>>> print(h.num_edges())
78

The generated graph is drawn as follows:

>>> gt.graph_draw(h, pos=gt.sfdp_layout(h),
...               output="spectral_graph_forge-karate.pdf")
<...>
../_images/spectral_graph_forge-karate.png

Random graph generated by the spectral graph forge from the karate club network, with \(\alpha=0.8\).#