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:
- g
Graph Graph to be used (the edge directions are ignored).
- weight
EdgePropertyMap(optional, default:None) Edge weights.
- dim
int(optional, default:2) Number of dimensions.
- norm
bool(optional, default:False) If
True, the generalized eigenvectors of the Laplacian, i.e. the degree-normalized eigenvectors, are used.- scale
float(optional, default:1.) Largest absolute coordinate of the centered layout.
- pos
VertexPropertyMap(optional, default:None) If provided, the positions will be stored in this property map.
- g
- Returns:
- pos
VertexPropertyMap The vertex positions.
- pos
See also
mds_layoutLayout by classical multidimensional scaling
graph_tool.spectral.spectral_embeddingSpectral embedding of the vertices
graph_tool.spectral.laplacianLaplacian 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\), ifnorm=True). If \(\boldsymbol u_1, \boldsymbol u_2, \dots\) are these eigenvectors (normalized as inspectral_embedding()), sorted by increasing eigenvalue, vertex \(i\) is placed at \((u_{2,i}, \dots, u_{d+1,i})\), where \(d\) isdim, and the layout is then centered at the mean position and scaled so that the largest absolute coordinate isscale. The eigenvectors are obtained withspectral_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") <...>
Spectral layout of the network of American college football games, with the vertex colors given by the conferences.#