davidson_harel_layout#
- graph_tool.draw.davidson_harel_layout(g, pos=None, n_iter=10, fine_iter=None, trials=10, cool=0.75, T=None, radius=None, width=None, node_dist=1.0, border=0.0, edge_lengths=None, crossings=None, node_edge_dist=None)[git][source]#
Calculate a layout of the graph by simulated annealing with the Davidson-Harel energy.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- pos
VertexPropertyMap(optional, default:None) Initial positions, which are modified in place. If not given, random positions in the layout square are used.
- n_iter
int(optional, default:10) Number of annealing stages.
- fine_iter
int(optional, default:None) Number of fine-tuning stages. If not given, \(\max(10, \log_2 V)\) is used.
- trials
int(optional, default:10) Number of moves tried for every vertex in every stage.
- cool
float(optional, default:0.75) Factor by which the temperature and the move radius are multiplied after every annealing stage.
- T
float(optional, default:None) Initial temperature. If not given, a tenth of the median absolute energy difference of one random move per vertex is used.
- radius
float(optional, default:None) Initial move radius. If not given,
width / 4is used.- width
float(optional, default:None) Side of the square to which the layout is confined. If not given, \(10\sqrt{V}\) is used.
- node_dist
float(optional, default:1.) Weight \(\lambda_1\) of the repulsion between vertices.
- border
float(optional, default:0.) Weight \(\lambda_2\) of the repulsion from the borders.
- edge_lengths
float(optional, default:None) Weight \(\lambda_3\) of the edge lengths. If not given, \(\rho/10\) is used, where \(\rho\) is the density of the graph.
- crossings
float(optional, default:None) Weight \(\lambda_4\) of the edge crossings. If not given, \(1 - \sqrt{\rho}\) is used.
- node_edge_dist
float(optional, default:None) Weight \(\lambda_5\) of the distances between vertices and edges, used in the fine-tuning stages. If not given, \((1 - \rho)/5\) is used.
- g
- Returns:
- pos
VertexPropertyMap Vector vertex property map with the \((x, y)\) coordinates.
- pos
See also
gem_layoutGEM force-directed layout
fruchterman_reingold_layoutFruchterman-Reingold spring-block layout
kamada_kawai_layoutKamada-Kawai spring layout
sfdp_layoutMultilevel force-directed layout
Notes
The layout of Davidson and Harel [davidson-drawing-1996] minimizes the energy
\[E = \lambda_1\sum_{i<j}\frac{1}{d_{ij}^2} + \lambda_2\sum_i \left(\frac{1}{l_i^2} + \frac{1}{r_i^2} + \frac{1}{t_i^2} + \frac{1}{b_i^2}\right) + \lambda_3\sum_{(i,j)\in E}d_{ij}^2 + \lambda_4 C + \lambda_5\sum_{i}\sum_{e\not\ni i}\frac{1}{g_{ie}^2},\]where \(d_{ij}\) are the distances between vertices, \(l_i\), \(r_i\), \(t_i\), and \(b_i\) the distances of vertex \(i\) to the four sides of the layout square, \(C\) the number of crossings between edges without common endpoints, and \(g_{ie}\) the distance between vertex \(i\) and the segment of edge \(e\) (in the first and last terms, the distances below \(10^{-6}\) times
widthare replaced by this value). The layout square, of sidewidth, is centered at the origin, and the energy is minimized by simulated annealing: every stage consists oftrialssweeps over the vertices in random order, in which every vertex tries a move to the point at distance \(\rho\) (the current radius) in a uniformly random direction, clamped to the square, which is accepted if \(\Delta E < 0\), or otherwise with probability \(e^{-\Delta E/T}\), and the temperature \(T\) and the radius \(\rho\) are multiplied bycoolafter every stage. Then_iterannealing stages are followed byfine_iterfine-tuning stages, in which the last term of the energy is included, the moves are to points drawn uniformly in a disk of radius \(0.01\) times the largest side of the bounding box of the layout, and only moves with \(\Delta E < 0\) are accepted. The publication does not give default values for the weights.Every annealing stage takes time \(O(t(V^2 + E^2))\), where \(t\) is
trials, dominated by the counting of the crossings, and every fine-tuning stage \(O(tVE)\), so that the layout is suitable only for small graphs. The initial positions are drawn with NumPy’s random number generator, and the moves with graph-tool’s.References
[davidson-drawing-1996]Ron Davidson and David Harel, “Drawing graphs nicely using simulated annealing”, ACM Transactions on Graphics 15, 301-331 (1996), DOI: 10.1145/234535.234538 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> pos = gt.davidson_harel_layout(g) >>> gt.graph_draw(g, pos=pos, output="karate-davidson-harel.pdf") <...>
Davidson-Harel layout of the karate club network.#