drl_layout#
- graph_tool.draw.drl_layout(g, weight=None, pos=None, edge_cut=0.8, schedule=None)[git][source]#
Calculate a force-directed layout with the DrL (OpenOrd) algorithm.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- weight
EdgePropertyMap(optional, default:None) Positive edge weights (similarities), which strengthen the attraction.
- pos
VertexPropertyMap(optional, default:None) Initial positions. If not given, all vertices start at the origin.
- edge_cut
float(optional, default:0.8) Amount of edge cutting, between 0 (no cutting) and 1 (aggressive cutting), which separates clusters further.
- schedulearray of shape
(5, 4)(optional, default:None) The five stages of the optimization (liquid, expansion, cooldown, crunch, and simmer), as rows (iterations, temperature, attraction, damping). If not given, the default schedule of the reference implementation is used, with the rows
(200, 2000, 10, 1),(200, 2000, 2, 1),(200, 2000, 1, 0.1),(50, 250, 1, 0.25), and(100, 250, 0.5, 0).
- g
- Returns:
- pos
VertexPropertyMap The vertex positions, in two dimensions.
- pos
See also
sfdp_layoutMultilevel force-directed layout
forceatlas2_layoutForceAtlas2 force-directed layout
lgl_layoutLarge Graph Layout
fruchterman_reingold_layoutFruchterman-Reingold spring-block layout
Notes
In the DrL force-directed algorithm [martin-openord-2011], the repulsion between vertices is replaced by a density field on a grid, to which every vertex contributes a pyramidal kernel, and the energy of a vertex \(v\) at position \(\boldsymbol x\) is
\[E_v(\boldsymbol x) = 0.02\,a^4\sum_u w_{vu}\,e(|\boldsymbol x - \boldsymbol x_u|) + D(\boldsymbol x),\]where \(a\) is the attraction of the current stage, \(w_{vu}\) the total weight of the edges between \(v\) and \(u\) (self-loops are ignored), \(e(r) = r^8\), \(r^4\), and \(r^2\) in the liquid, expansion, and later stages, and \(D\) the density term. The area \([-2000, 2000]^2\) is divided into a grid of \(1000\times 1000\) cells of side 4, and every vertex \(u\) adds the kernel \((1 - |i|/10)(1 - |j|/10)\) to the cells at offsets \(|i|, |j| \le 10\) from its own cell; \(D(\boldsymbol x)\) is the square of the resulting density at the cell of \(\boldsymbol x\), excluding the contribution of \(v\) itself, or, in the last stage, the sum \(\sum_u 10^{-4}/|\boldsymbol x - \boldsymbol x_u|^2\) over the vertices in the \(3\times 3\) cells around \(\boldsymbol x\). Positions within 10 cells of the border of the grid have \(D = 10^4\). As in the reference implementation, the density grid starts empty, as do the cells for the last stage when it begins, and every vertex is entered into them when it is first updated, so that during the first iteration of the first and of the last stage a vertex sees only the vertices updated before it.
The vertices are updated in turn, in the order of their indices. With the damping \(\delta\) of the current stage and the weighted centroid \(\boldsymbol c_v = \sum_u w_{vu}\boldsymbol x_u/\sum_u w_{vu}\) of the neighbors, the damped step \(\boldsymbol y = (1 - \delta)\boldsymbol x_v + \delta\boldsymbol c_v\) and the random jump \(\boldsymbol y' = \boldsymbol y + (T/100)\boldsymbol\xi\) are computed, where \(T\) is the temperature and the components of \(\boldsymbol\xi\) are uniform in \([-1/2, 1/2]\); the vertex moves to \(\boldsymbol y\) if \(E_v(\boldsymbol x_v) < E_v(\boldsymbol y')\), and to \(\boldsymbol y'\) otherwise. During the expansion stage, after every iteration, \(a\) decreases by 0.05 while above 1 and \(\delta\) by 0.005 while above 0.1; during the cooldown stage, \(T\) decreases by 10 while above 50; and during the simmer stage, \(T\) decreases by 2 while above 50. In all stages but the last, before the move, the edge of a vertex with \(k_v \ge k_{\min}\) neighbors to the neighbor \(u\) farthest from the centroid is removed when \(\sqrt{k_v}|\boldsymbol c_v - \boldsymbol x_u|^2\) exceeds the cut length, which lets clusters separate. With \(\ell = \max(1, 40000(1 - c))\), where \(c\) is
edge_cut, the cut length is \(4\ell\) in the liquid stage, decreases linearly in every iteration of the expansion stage, by \(3\ell/400\), and of the cooldown stage, by \(3\ell/200\) while above \(\ell\), and is \(\ell\) in the crunch stage, while \(k_{\min}\) is 20 in the liquid stage, decreases by 0.05 per iteration (while above 12) in the expansion stage and by 0.2 (while above 1) in the cooldown stage, and is 1 in the crunch stage. The cutting is disabled if \(40000(1 - c) \ge 39500\). All vertices start at the origin, unlessposis given. Every iteration takes time \(O(V + E)\), with a large constant from the density kernel, and the optimization is sequential. This is a reimplementation that follows the behavior of the reference code of Sandia National Laboratories, which is not otherwise fully specified in the publication. The layout scale is arbitrary.References
[martin-openord-2011]Shawn Martin, W. Michael Brown, Richard Klavans and Kevin W. Boyack, “OpenOrd: an open-source toolbox for large graph layout”, Visualization and Data Analysis 2011, Proceedings of SPIE 7868, 786806 (2011), DOI: 10.1117/12.871402 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["netscience"] >>> pos = gt.drl_layout(g) >>> gt.graph_draw(g, pos=pos, output="netscience-drl.png") <...>
DrL layout of a network of coauthorships in network science.#