fling-layout 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fling_layout-0.1.0/.gitignore +228 -0
- fling_layout-0.1.0/LICENSE +21 -0
- fling_layout-0.1.0/PKG-INFO +241 -0
- fling_layout-0.1.0/README.md +206 -0
- fling_layout-0.1.0/fling/__init__.py +5 -0
- fling_layout-0.1.0/fling/baselines.py +492 -0
- fling_layout-0.1.0/fling/conditional.py +398 -0
- fling_layout-0.1.0/fling/data.py +117 -0
- fling_layout-0.1.0/fling/estimators.py +2070 -0
- fling_layout-0.1.0/fling/figstyle.py +152 -0
- fling_layout-0.1.0/fling/graphs.py +131 -0
- fling_layout-0.1.0/fling/metrics.py +169 -0
- fling_layout-0.1.0/fling/nets.py +96 -0
- fling_layout-0.1.0/fling/optim.py +124 -0
- fling_layout-0.1.0/fling/vis.py +432 -0
- fling_layout-0.1.0/pyproject.toml +52 -0
- fling_layout-0.1.0/scripts/draw_large.py +129 -0
- fling_layout-0.1.0/scripts/lib.py +116 -0
- fling_layout-0.1.0/scripts/million.py +266 -0
- fling_layout-0.1.0/scripts/model_comparison.py +692 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# UV
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
201
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
203
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# Custom
|
|
224
|
+
cache/
|
|
225
|
+
data/
|
|
226
|
+
figures/
|
|
227
|
+
tables/
|
|
228
|
+
!website/data/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Berfin Inal and Daniel Probst
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: fling-layout
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Graph drawing with a learned layout function
|
|
5
|
+
Project-URL: Homepage, https://github.com/daenuprobst/fling-layout
|
|
6
|
+
Project-URL: Repository, https://github.com/daenuprobst/fling-layout
|
|
7
|
+
Author: Berfin Inal, Daniel Probst
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: graph-drawing,graph-layout,implicit-neural-representation,stress
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: fa2-modified>=0.4
|
|
15
|
+
Requires-Dist: networkx>=3.0
|
|
16
|
+
Requires-Dist: numpy>=1.24
|
|
17
|
+
Requires-Dist: s-gd2>=1.8
|
|
18
|
+
Requires-Dist: scikit-learn>=1.3
|
|
19
|
+
Requires-Dist: scipy>=1.10
|
|
20
|
+
Requires-Dist: torch>=2.0
|
|
21
|
+
Provides-Extra: all
|
|
22
|
+
Requires-Dist: colorcet>=3.0; extra == 'all'
|
|
23
|
+
Requires-Dist: datashader>=0.16; extra == 'all'
|
|
24
|
+
Requires-Dist: matplotlib>=3.7; extra == 'all'
|
|
25
|
+
Requires-Dist: pandas>=2.0; extra == 'all'
|
|
26
|
+
Requires-Dist: pynndescent>=0.5; extra == 'all'
|
|
27
|
+
Provides-Extra: figures
|
|
28
|
+
Requires-Dist: matplotlib>=3.7; extra == 'figures'
|
|
29
|
+
Provides-Extra: large
|
|
30
|
+
Requires-Dist: colorcet>=3.0; extra == 'large'
|
|
31
|
+
Requires-Dist: datashader>=0.16; extra == 'large'
|
|
32
|
+
Requires-Dist: pandas>=2.0; extra == 'large'
|
|
33
|
+
Requires-Dist: pynndescent>=0.5; extra == 'large'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# fling-layout
|
|
37
|
+
|
|
38
|
+
Graph drawing with a learned layout function. Fling computes a graph layout by fitting a function of node features instead of a table of coordinates.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## From coordinates to a function
|
|
42
|
+
Most graph layout methods (stress, ForceAtlas2, t-SNE) optimise the node coordinates directly. Each position is an independent free parameter, and the resulting layout is defined only for the nodes present during optimisation. Incorporating a new node requires re-optimising the layout, which is costly and does not in general preserve the previous drawing.
|
|
43
|
+
|
|
44
|
+
Fling instead parameterises the layout as a function of node features. Each node is represented by its diffusion potentials to a set of landmark nodes, and a small neural network maps this representation to a position. The network weights are trained on a layout energy, and the drawing is the output of the trained network.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
This makes the network inductive. In a growing citation network, for example, newly published papers can be embedded by a single forward pass, without re-optimisation.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
model = FlingStress(n_components=2).fit(graph)
|
|
53
|
+
# embed new nodes without re-optimisation
|
|
54
|
+
pos = model.transform(larger_graph)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Requires Python 3.10 or newer. The package is `fling-layout` and the module it installs is `fling`.
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
pip install fling-layout
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This gives you the full library: all four `Fling` variants, the baselines in `fling.baselines` and
|
|
68
|
+
the metrics in `fling.metrics`. The required dependencies (numpy, scipy, networkx, torch,
|
|
69
|
+
scikit-learn, s_gd2 and fa2-modified) are installed automatically.
|
|
70
|
+
|
|
71
|
+
Two extras are optional: `figures` adds matplotlib, which only `fling.figstyle` needs, and `large`
|
|
72
|
+
adds datashader, pandas, colorcet and pynndescent for drawing graphs with millions of nodes. `all` installs both:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
pip install "fling-layout[all]"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Library
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
<p align="center">
|
|
83
|
+
<img src="https://raw.githubusercontent.com/daenuprobst/fling-layout/main/docs/images/fling_overview.png" width="800" alt="Fling overview: random walks with restart from landmarks give each node its diffusion potentials, a small network maps them to a position, and the outputs form the layout">
|
|
84
|
+
</p>
|
|
85
|
+
|
|
86
|
+
Each node carries its diffusion potentials to a set of landmarks. A small network maps that feature
|
|
87
|
+
vector to a position, and the weights are trained on a layout energy. The variants differ only
|
|
88
|
+
in the energy they minimise.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import networkx as nx
|
|
92
|
+
from fling import FlingStress
|
|
93
|
+
|
|
94
|
+
graph = nx.convert_node_labels_to_integers(nx.les_miserables_graph())
|
|
95
|
+
pos = FlingStress(n_components=2, seed=0).fit_transform(graph)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A new node is placed with a single forward pass, without refitting.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
# set up a 2D stress layout
|
|
102
|
+
model = FlingStress(n_components=2, seed=0)
|
|
103
|
+
|
|
104
|
+
# train the network on the original graph
|
|
105
|
+
model.fit(graph)
|
|
106
|
+
|
|
107
|
+
# place the nodes of a larger graph that contains the original one, without refitting
|
|
108
|
+
pos_all = model.transform(larger_graph)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`FlingBlend` conditions the field on a weight between two energies, so a single fit covers every weight.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from fling import FlingBlend
|
|
115
|
+
|
|
116
|
+
model = FlingBlend(n_components=2, seed=0).fit(graph)
|
|
117
|
+
early = model.draw(0.0)
|
|
118
|
+
late = model.draw(1.0)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
<p align="center">
|
|
122
|
+
<img src="https://raw.githubusercontent.com/daenuprobst/fling-layout/main/docs/images/fling_blend.png" width="800" alt="One FlingBlend fit drawn at lambda 0, 0.25, 0.5, 0.75 and 1: the ring structure untangles as lambda moves from stress towards neighbour embedding">
|
|
123
|
+
</p>
|
|
124
|
+
|
|
125
|
+
### Variants
|
|
126
|
+
|
|
127
|
+
| class | energy | default iters |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `Fling` | all-pairs stress by majorisation, with a second field for the pair sum | 400 |
|
|
130
|
+
| `FlingStress` | scale-normalised pivot stress | 500 |
|
|
131
|
+
| `FlingVis` | neighbour embedding plus node–edge clearance and crossings | 2000 |
|
|
132
|
+
| `FlingBlend` | a weighted blend of two energies, conditioned on the weight | 1500 |
|
|
133
|
+
|
|
134
|
+
### Parameters
|
|
135
|
+
|
|
136
|
+
Shared by all variants.
|
|
137
|
+
|
|
138
|
+
| name | default | meaning |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `n_components` | 3 | output dimension; use 2 for a drawing |
|
|
141
|
+
| `seed` | 0 | random seed |
|
|
142
|
+
| `iters` | per variant | optimiser steps |
|
|
143
|
+
| `lr` | 0.005 | learning rate |
|
|
144
|
+
| `n_landmarks` | 64 | landmarks the diffusion potentials are measured to |
|
|
145
|
+
| `alpha` | 0.05 | teleport of the diffusion, which sets how far a node sees |
|
|
146
|
+
| `diff_K` | 20 | diffusion steps behind each potential |
|
|
147
|
+
| `width` | 128 | hidden width of the coordinate network |
|
|
148
|
+
| `depth` | 2 | hidden layers |
|
|
149
|
+
| `w0` | 4.0 for `Fling`, 2.0 otherwise | activation frequency, used only by siren, finer and gabor |
|
|
150
|
+
| `act` | `gelu` | activation |
|
|
151
|
+
|
|
152
|
+
Specific to `FlingStress`.
|
|
153
|
+
|
|
154
|
+
| name | default | meaning |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `npiv` | `None` | number of pivot columns; `None` picks 400, or fewer on small graphs |
|
|
157
|
+
|
|
158
|
+
Specific to `FlingVis`.
|
|
159
|
+
|
|
160
|
+
| name | default | meaning |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| `w_ne` | 0.3 | weight of the node–edge clearance term |
|
|
163
|
+
| `w_cross` | 0.3 | weight of the crossing term |
|
|
164
|
+
| `clear` | 0.6 | clearance target as a fraction of the median edge length |
|
|
165
|
+
| `n_neg` | 4096 | sampled negatives per step |
|
|
166
|
+
| `exaggeration` | 4.0 | attraction factor over the first third of training |
|
|
167
|
+
|
|
168
|
+
Specific to `FlingBlend`.
|
|
169
|
+
|
|
170
|
+
| name | default | meaning |
|
|
171
|
+
|---|---|---|
|
|
172
|
+
| `lam` | `None` | fixes a single weight; `None` trains the whole family |
|
|
173
|
+
| `n_lam` | 4 | weights drawn per step, so each step costs `n_lam` objective evaluations |
|
|
174
|
+
|
|
175
|
+
`alpha` sets how far a node sees. Each potential is a personalised PageRank whose step `k` carries
|
|
176
|
+
weight `alpha * (1 - alpha) ** k`, so the mass is spent after roughly `1 / alpha` hops and `diff_K`
|
|
177
|
+
only has to be long enough to reach that. Raising `diff_K` alone does nothing, because the weights
|
|
178
|
+
have already decayed.
|
|
179
|
+
|
|
180
|
+
The default sees about twenty hops. Leave it there unless a drawing looks wrong, because the effect
|
|
181
|
+
of changing it is large, not monotone, and different on every graph. Measured on sampled stress, a
|
|
182
|
+
120 × 120 grid folds at the default and wants a lower `alpha` (0.046 down to 0.012 at 0.01), a 400
|
|
183
|
+
× 400 grid draws a clean lattice at the default and gets worse at 0.02 (0.012 up to 0.061), and the
|
|
184
|
+
million-node road network is fine at the default but collapses onto a line at 0.005 (0.015 up to
|
|
185
|
+
0.274). Sweep it over several seeds and look at the drawing rather than the number.
|
|
186
|
+
|
|
187
|
+
### Baselines and metrics
|
|
188
|
+
|
|
189
|
+
`fling.baselines` holds `sgd_stress`, `fa2`, `tsnet`, `tsnet_star`, `NNPNet`, `impred` and the
|
|
190
|
+
landmark readouts. `fling.metrics` holds `evaluate`, `normalized_stress`,
|
|
191
|
+
`neighborhood_preservation` and `fast_D`. `fling.data` loads the benchmark graphs.
|
|
192
|
+
|
|
193
|
+
For example, to compare Fling with the sgd² stress baseline on one of the benchmark graphs:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from fling import FlingStress
|
|
197
|
+
from fling.baselines import sgd_stress
|
|
198
|
+
from fling.data import graphs
|
|
199
|
+
from fling.metrics import evaluate
|
|
200
|
+
|
|
201
|
+
# the benchmark graphs as (name, graph) pairs: grid_400, tree_400, delaunay_600, sbm_240, lesmis
|
|
202
|
+
benchmarks = dict(graphs(quick=True))
|
|
203
|
+
graph = benchmarks["lesmis"]
|
|
204
|
+
|
|
205
|
+
# draw it with Fling and with the baseline
|
|
206
|
+
pos_fling = FlingStress(n_components=2, seed=0).fit_transform(graph)
|
|
207
|
+
pos_sgd = sgd_stress(graph, seed=0)
|
|
208
|
+
|
|
209
|
+
# score both drawings on the same metrics
|
|
210
|
+
print(evaluate(pos_fling, graph))
|
|
211
|
+
print(evaluate(pos_sgd, graph))
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`evaluate` returns a dictionary with normalised stress, neighbourhood preservation (`np_jaccard`,
|
|
215
|
+
`knn_recall`), edge length variation (`edge_cov`), edge crossings and the minimum crossing angle.
|
|
216
|
+
The crossing metrics are skipped (`None`) on larger graphs, where counting them is slow.
|
|
217
|
+
|
|
218
|
+
## Tutorial
|
|
219
|
+
|
|
220
|
+
For a hands-on introduction, work through the
|
|
221
|
+
[tutorial notebook](https://github.com/daenuprobst/fling-layout/blob/main/tutorial.ipynb) on GitHub,
|
|
222
|
+
or [open it in Google Colab](https://colab.research.google.com/github/daenuprobst/fling-layout/blob/main/tutorial.ipynb).
|
|
223
|
+
It draws a first layout, compares graphs of different shapes and real road and mesh networks, fits
|
|
224
|
+
on a few nodes and places the rest, adds new nodes without refitting, and compares speed with sgd².
|
|
225
|
+
Each section ends with small exercises to try.
|
|
226
|
+
|
|
227
|
+
## Citation
|
|
228
|
+
|
|
229
|
+
If you use Fling in your work, please cite:
|
|
230
|
+
|
|
231
|
+
```bibtex
|
|
232
|
+
@misc{inal2026inductivegraphlayoutimplicit,
|
|
233
|
+
title={Inductive Graph Layout with Implicit Neural Fields},
|
|
234
|
+
author={Berfin Inal and Daniel Probst},
|
|
235
|
+
year={2026},
|
|
236
|
+
eprint={2608.08876},
|
|
237
|
+
archivePrefix={arXiv},
|
|
238
|
+
primaryClass={cs.HC},
|
|
239
|
+
url={https://arxiv.org/abs/2608.08876},
|
|
240
|
+
}
|
|
241
|
+
```
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# fling-layout
|
|
2
|
+
|
|
3
|
+
Graph drawing with a learned layout function. Fling computes a graph layout by fitting a function of node features instead of a table of coordinates.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## From coordinates to a function
|
|
7
|
+
Most graph layout methods (stress, ForceAtlas2, t-SNE) optimise the node coordinates directly. Each position is an independent free parameter, and the resulting layout is defined only for the nodes present during optimisation. Incorporating a new node requires re-optimising the layout, which is costly and does not in general preserve the previous drawing.
|
|
8
|
+
|
|
9
|
+
Fling instead parameterises the layout as a function of node features. Each node is represented by its diffusion potentials to a set of landmark nodes, and a small neural network maps this representation to a position. The network weights are trained on a layout energy, and the drawing is the output of the trained network.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
This makes the network inductive. In a growing citation network, for example, newly published papers can be embedded by a single forward pass, without re-optimisation.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
model = FlingStress(n_components=2).fit(graph)
|
|
18
|
+
# embed new nodes without re-optimisation
|
|
19
|
+
pos = model.transform(larger_graph)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Requires Python 3.10 or newer. The package is `fling-layout` and the module it installs is `fling`.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install fling-layout
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This gives you the full library: all four `Fling` variants, the baselines in `fling.baselines` and
|
|
33
|
+
the metrics in `fling.metrics`. The required dependencies (numpy, scipy, networkx, torch,
|
|
34
|
+
scikit-learn, s_gd2 and fa2-modified) are installed automatically.
|
|
35
|
+
|
|
36
|
+
Two extras are optional: `figures` adds matplotlib, which only `fling.figstyle` needs, and `large`
|
|
37
|
+
adds datashader, pandas, colorcet and pynndescent for drawing graphs with millions of nodes. `all` installs both:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
pip install "fling-layout[all]"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Library
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
<p align="center">
|
|
48
|
+
<img src="https://raw.githubusercontent.com/daenuprobst/fling-layout/main/docs/images/fling_overview.png" width="800" alt="Fling overview: random walks with restart from landmarks give each node its diffusion potentials, a small network maps them to a position, and the outputs form the layout">
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
Each node carries its diffusion potentials to a set of landmarks. A small network maps that feature
|
|
52
|
+
vector to a position, and the weights are trained on a layout energy. The variants differ only
|
|
53
|
+
in the energy they minimise.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import networkx as nx
|
|
57
|
+
from fling import FlingStress
|
|
58
|
+
|
|
59
|
+
graph = nx.convert_node_labels_to_integers(nx.les_miserables_graph())
|
|
60
|
+
pos = FlingStress(n_components=2, seed=0).fit_transform(graph)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A new node is placed with a single forward pass, without refitting.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# set up a 2D stress layout
|
|
67
|
+
model = FlingStress(n_components=2, seed=0)
|
|
68
|
+
|
|
69
|
+
# train the network on the original graph
|
|
70
|
+
model.fit(graph)
|
|
71
|
+
|
|
72
|
+
# place the nodes of a larger graph that contains the original one, without refitting
|
|
73
|
+
pos_all = model.transform(larger_graph)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`FlingBlend` conditions the field on a weight between two energies, so a single fit covers every weight.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from fling import FlingBlend
|
|
80
|
+
|
|
81
|
+
model = FlingBlend(n_components=2, seed=0).fit(graph)
|
|
82
|
+
early = model.draw(0.0)
|
|
83
|
+
late = model.draw(1.0)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
<p align="center">
|
|
87
|
+
<img src="https://raw.githubusercontent.com/daenuprobst/fling-layout/main/docs/images/fling_blend.png" width="800" alt="One FlingBlend fit drawn at lambda 0, 0.25, 0.5, 0.75 and 1: the ring structure untangles as lambda moves from stress towards neighbour embedding">
|
|
88
|
+
</p>
|
|
89
|
+
|
|
90
|
+
### Variants
|
|
91
|
+
|
|
92
|
+
| class | energy | default iters |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `Fling` | all-pairs stress by majorisation, with a second field for the pair sum | 400 |
|
|
95
|
+
| `FlingStress` | scale-normalised pivot stress | 500 |
|
|
96
|
+
| `FlingVis` | neighbour embedding plus node–edge clearance and crossings | 2000 |
|
|
97
|
+
| `FlingBlend` | a weighted blend of two energies, conditioned on the weight | 1500 |
|
|
98
|
+
|
|
99
|
+
### Parameters
|
|
100
|
+
|
|
101
|
+
Shared by all variants.
|
|
102
|
+
|
|
103
|
+
| name | default | meaning |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `n_components` | 3 | output dimension; use 2 for a drawing |
|
|
106
|
+
| `seed` | 0 | random seed |
|
|
107
|
+
| `iters` | per variant | optimiser steps |
|
|
108
|
+
| `lr` | 0.005 | learning rate |
|
|
109
|
+
| `n_landmarks` | 64 | landmarks the diffusion potentials are measured to |
|
|
110
|
+
| `alpha` | 0.05 | teleport of the diffusion, which sets how far a node sees |
|
|
111
|
+
| `diff_K` | 20 | diffusion steps behind each potential |
|
|
112
|
+
| `width` | 128 | hidden width of the coordinate network |
|
|
113
|
+
| `depth` | 2 | hidden layers |
|
|
114
|
+
| `w0` | 4.0 for `Fling`, 2.0 otherwise | activation frequency, used only by siren, finer and gabor |
|
|
115
|
+
| `act` | `gelu` | activation |
|
|
116
|
+
|
|
117
|
+
Specific to `FlingStress`.
|
|
118
|
+
|
|
119
|
+
| name | default | meaning |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `npiv` | `None` | number of pivot columns; `None` picks 400, or fewer on small graphs |
|
|
122
|
+
|
|
123
|
+
Specific to `FlingVis`.
|
|
124
|
+
|
|
125
|
+
| name | default | meaning |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `w_ne` | 0.3 | weight of the node–edge clearance term |
|
|
128
|
+
| `w_cross` | 0.3 | weight of the crossing term |
|
|
129
|
+
| `clear` | 0.6 | clearance target as a fraction of the median edge length |
|
|
130
|
+
| `n_neg` | 4096 | sampled negatives per step |
|
|
131
|
+
| `exaggeration` | 4.0 | attraction factor over the first third of training |
|
|
132
|
+
|
|
133
|
+
Specific to `FlingBlend`.
|
|
134
|
+
|
|
135
|
+
| name | default | meaning |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| `lam` | `None` | fixes a single weight; `None` trains the whole family |
|
|
138
|
+
| `n_lam` | 4 | weights drawn per step, so each step costs `n_lam` objective evaluations |
|
|
139
|
+
|
|
140
|
+
`alpha` sets how far a node sees. Each potential is a personalised PageRank whose step `k` carries
|
|
141
|
+
weight `alpha * (1 - alpha) ** k`, so the mass is spent after roughly `1 / alpha` hops and `diff_K`
|
|
142
|
+
only has to be long enough to reach that. Raising `diff_K` alone does nothing, because the weights
|
|
143
|
+
have already decayed.
|
|
144
|
+
|
|
145
|
+
The default sees about twenty hops. Leave it there unless a drawing looks wrong, because the effect
|
|
146
|
+
of changing it is large, not monotone, and different on every graph. Measured on sampled stress, a
|
|
147
|
+
120 × 120 grid folds at the default and wants a lower `alpha` (0.046 down to 0.012 at 0.01), a 400
|
|
148
|
+
× 400 grid draws a clean lattice at the default and gets worse at 0.02 (0.012 up to 0.061), and the
|
|
149
|
+
million-node road network is fine at the default but collapses onto a line at 0.005 (0.015 up to
|
|
150
|
+
0.274). Sweep it over several seeds and look at the drawing rather than the number.
|
|
151
|
+
|
|
152
|
+
### Baselines and metrics
|
|
153
|
+
|
|
154
|
+
`fling.baselines` holds `sgd_stress`, `fa2`, `tsnet`, `tsnet_star`, `NNPNet`, `impred` and the
|
|
155
|
+
landmark readouts. `fling.metrics` holds `evaluate`, `normalized_stress`,
|
|
156
|
+
`neighborhood_preservation` and `fast_D`. `fling.data` loads the benchmark graphs.
|
|
157
|
+
|
|
158
|
+
For example, to compare Fling with the sgd² stress baseline on one of the benchmark graphs:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from fling import FlingStress
|
|
162
|
+
from fling.baselines import sgd_stress
|
|
163
|
+
from fling.data import graphs
|
|
164
|
+
from fling.metrics import evaluate
|
|
165
|
+
|
|
166
|
+
# the benchmark graphs as (name, graph) pairs: grid_400, tree_400, delaunay_600, sbm_240, lesmis
|
|
167
|
+
benchmarks = dict(graphs(quick=True))
|
|
168
|
+
graph = benchmarks["lesmis"]
|
|
169
|
+
|
|
170
|
+
# draw it with Fling and with the baseline
|
|
171
|
+
pos_fling = FlingStress(n_components=2, seed=0).fit_transform(graph)
|
|
172
|
+
pos_sgd = sgd_stress(graph, seed=0)
|
|
173
|
+
|
|
174
|
+
# score both drawings on the same metrics
|
|
175
|
+
print(evaluate(pos_fling, graph))
|
|
176
|
+
print(evaluate(pos_sgd, graph))
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`evaluate` returns a dictionary with normalised stress, neighbourhood preservation (`np_jaccard`,
|
|
180
|
+
`knn_recall`), edge length variation (`edge_cov`), edge crossings and the minimum crossing angle.
|
|
181
|
+
The crossing metrics are skipped (`None`) on larger graphs, where counting them is slow.
|
|
182
|
+
|
|
183
|
+
## Tutorial
|
|
184
|
+
|
|
185
|
+
For a hands-on introduction, work through the
|
|
186
|
+
[tutorial notebook](https://github.com/daenuprobst/fling-layout/blob/main/tutorial.ipynb) on GitHub,
|
|
187
|
+
or [open it in Google Colab](https://colab.research.google.com/github/daenuprobst/fling-layout/blob/main/tutorial.ipynb).
|
|
188
|
+
It draws a first layout, compares graphs of different shapes and real road and mesh networks, fits
|
|
189
|
+
on a few nodes and places the rest, adds new nodes without refitting, and compares speed with sgd².
|
|
190
|
+
Each section ends with small exercises to try.
|
|
191
|
+
|
|
192
|
+
## Citation
|
|
193
|
+
|
|
194
|
+
If you use Fling in your work, please cite:
|
|
195
|
+
|
|
196
|
+
```bibtex
|
|
197
|
+
@misc{inal2026inductivegraphlayoutimplicit,
|
|
198
|
+
title={Inductive Graph Layout with Implicit Neural Fields},
|
|
199
|
+
author={Berfin Inal and Daniel Probst},
|
|
200
|
+
year={2026},
|
|
201
|
+
eprint={2608.08876},
|
|
202
|
+
archivePrefix={arXiv},
|
|
203
|
+
primaryClass={cs.HC},
|
|
204
|
+
url={https://arxiv.org/abs/2608.08876},
|
|
205
|
+
}
|
|
206
|
+
```
|