spectral_layout

spectral_layout#

graph_tool.draw.spectral_layout(g, weight=None, dim=2, norm=False, scale=1.0, pos=None)[git][source]#

Calculate a layout of the graph from the eigenvectors of its Laplacian.

Parameters:
gGraph

Graph to be used (the edge directions are ignored).

weightEdgePropertyMap (optional, default: None)

Edge weights.

dimint (optional, default: 2)

Number of dimensions.

normbool (optional, default: False)

If True, the generalized eigenvectors of the Laplacian, i.e. the degree-normalized eigenvectors, are used.

scalefloat (optional, default: 1.)

Largest absolute coordinate of the centered layout.

posVertexPropertyMap (optional, default: None)

If provided, the positions will be stored in this property map.

Returns:
posVertexPropertyMap

The vertex positions.

See also

mds_layout

Layout by classical multidimensional scaling

graph_tool.spectral.spectral_embedding

Spectral embedding of the vertices

graph_tool.spectral.laplacian

Laplacian matrix of the graph

Notes

In this spectral layout, the coordinates are the eigenvectors of the Laplacian \(\boldsymbol L = \boldsymbol D - \boldsymbol A\) (or, with norm=True, the solutions of the generalized eigenvalue problem \(\boldsymbol L\boldsymbol x = \lambda\boldsymbol D\boldsymbol x\), the degree-normalized eigenvectors of [koren-drawing-2005]) with the smallest eigenvalues, skipping the trivial one, which minimize \(\sum_{(i,j)\in E}w_{ij}|\boldsymbol x_i - \boldsymbol x_j|^2\) subject to orthogonality constraints [koren-drawing-2005] (with respect to \(\boldsymbol D\), if norm=True). If \(\boldsymbol u_1, \boldsymbol u_2, \dots\) are these eigenvectors (normalized as in spectral_embedding()), sorted by increasing eigenvalue, vertex \(i\) is placed at \((u_{2,i}, \dots, u_{d+1,i})\), where \(d\) is dim, and the layout is then centered at the mean position and scaled so that the largest absolute coordinate is scale. The eigenvectors are obtained with spectral_embedding(), and their signs are arbitrary. (Graphs with at most two vertices are placed on the \(x\) axis.) For disconnected graphs, the first eigenvectors are the indicators of the components, so that the layout is degenerate.

References

[koren-drawing-2005] (1,2)

Yehuda Koren, “Drawing graphs by eigenvectors: theory and practice”, Computers & Mathematics with Applications 49, 1867-1888 (2005), DOI: 10.1016/j.camwa.2004.08.015 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["football"]
>>> pos = gt.spectral_layout(g)
>>> gt.graph_draw(g, pos=pos, vertex_fill_color=g.vp.value,
...               output="football-spectral.pdf")
<...>
../_images/football-spectral.png

Spectral layout of the network of American college football games, with the vertex colors given by the conferences.#