davidson_harel_layout

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:
gGraph

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

posVertexPropertyMap (optional, default: None)

Initial positions, which are modified in place. If not given, random positions in the layout square are used.

n_iterint (optional, default: 10)

Number of annealing stages.

fine_iterint (optional, default: None)

Number of fine-tuning stages. If not given, \(\max(10, \log_2 V)\) is used.

trialsint (optional, default: 10)

Number of moves tried for every vertex in every stage.

coolfloat (optional, default: 0.75)

Factor by which the temperature and the move radius are multiplied after every annealing stage.

Tfloat (optional, default: None)

Initial temperature. If not given, a tenth of the median absolute energy difference of one random move per vertex is used.

radiusfloat (optional, default: None)

Initial move radius. If not given, width / 4 is used.

widthfloat (optional, default: None)

Side of the square to which the layout is confined. If not given, \(10\sqrt{V}\) is used.

node_distfloat (optional, default: 1.)

Weight \(\lambda_1\) of the repulsion between vertices.

borderfloat (optional, default: 0.)

Weight \(\lambda_2\) of the repulsion from the borders.

edge_lengthsfloat (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.

crossingsfloat (optional, default: None)

Weight \(\lambda_4\) of the edge crossings. If not given, \(1 - \sqrt{\rho}\) is used.

node_edge_distfloat (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.

Returns:
posVertexPropertyMap

Vector vertex property map with the \((x, y)\) coordinates.

See also

gem_layout

GEM force-directed layout

fruchterman_reingold_layout

Fruchterman-Reingold spring-block layout

kamada_kawai_layout

Kamada-Kawai spring layout

sfdp_layout

Multilevel 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 width are replaced by this value). The layout square, of side width, is centered at the origin, and the energy is minimized by simulated annealing: every stage consists of trials sweeps 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 by cool after every stage. The n_iter annealing stages are followed by fine_iter fine-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")
<...>
../_images/karate-davidson-harel.png

Davidson-Harel layout of the karate club network.#