mds_layout#
- graph_tool.draw.mds_layout(g, weight=None, dim=2, pos=None)[git][source]#
Calculate a layout by classical multidimensional scaling of the graph distances.
- Parameters:
- g
Graph Graph to be used. If it is directed, it is treated as undirected. It must be connected.
- weight
EdgePropertyMap(optional, default:None) Non-negative edge lengths. If not supplied, every edge has unit length.
- dim
int(optional, default:2) Number of dimensions of the layout.
- pos
VertexPropertyMap(optional, default:None) Vector vertex property map where the coordinates are stored.
- g
- Returns:
- pos
VertexPropertyMap Vector vertex property map with the coordinates.
- pos
See also
stress_layoutLayout by stress majorization
kamada_kawai_layoutKamada-Kawai spring layout
spectral_layoutLayout from the eigenvectors of the Laplacian
Notes
Classical multidimensional scaling [torgerson-multidimensional-1952] [gower-some-1966] finds the coordinates whose inner products best approximate those implied by the matrix of squared graph distances \(\boldsymbol D^{(2)}\): the coordinates are the leading
dimeigenvectors of \(\boldsymbol B = -\frac{1}{2}\boldsymbol J \boldsymbol D^{(2)}\boldsymbol J\), where \(\boldsymbol J\) is the centering matrix, scaled by the square roots of their eigenvalues. The layout is deterministic, and is often used to initializekamada_kawai_layout(). It requires the all-pairs distances, in time \(O(V(V+E))\) and \(O(V^2)\) memory, plus the dense eigenvalue problem, in time \(O(V^3)\).References
[torgerson-multidimensional-1952]Warren S. Torgerson, “Multidimensional scaling: I. Theory and method”, Psychometrika 17, 401-419 (1952), DOI: 10.1007/BF02288916 [sci-hub, @tor]
[gower-some-1966]J. C. Gower, “Some distance properties of latent root and vector methods used in multivariate analysis”, Biometrika 53, 325-338 (1966), DOI: 10.1093/biomet/53.3-4.325 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> pos = gt.mds_layout(g) >>> gt.graph_draw(g, pos=pos, output="karate-mds.pdf") <...>
Classical multidimensional scaling layout of the karate club network.#