aryagraph.layout.stress#
- aryagraph.layout.stress(g: Any, *, weight: str | Callable[[Hashable, Hashable, dict], float] | None = None, seed: int = 0, iterations: int = 300, tol: float = 1e-05, init: str | Layout | Mapping[Hashable, Any] = 'mds') Layout[source]#
Stress-majorization layout (the modern replacement for Kamada–Kawai).
- Parameters:
weight –
Nonemeans every edge has length 1; otherwise edge lengths come from this attribute / callable (shortest-path distances via Dijkstra).iterations, tol – Stop after iterations majorization steps or when the relative stress decrease falls below tol.
init –
"mds"(classical MDS; pivot MDS with 50 pivots above 1000 nodes),"random", or aLayout/{node: (x, y)}start.
- Returns:
Layout – Abstract layout with edge lengths ≈ 1 (≈ weight), principal axis horizontal.
meta["stress"]is the final normalised stressΣ (‖x_i − x_j‖/d_ij − 1)² / 2. Disconnected graphs are laid out per component and packed.
Notes
Complexity: O(n·m) for distances, O(n³) once for the Laplacian solve and O(n²) per iteration (about a second for 1000 nodes).