egraph 6.0.0-beta.3 → 6.0.0-beta.5
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.
- package/README.md +78 -84
- package/package.json +1 -1
- package/pkg/README.md +78 -84
- package/pkg/egraph_wasm.d.ts +1501 -825
- package/pkg/egraph_wasm.js +3782 -5160
- package/pkg/egraph_wasm_bg.wasm +0 -0
- package/pkg/index.d.ts +1980 -1160
- package/pkg/index.js +124 -6
package/README.md
CHANGED
|
@@ -13,19 +13,20 @@ npm install egraph
|
|
|
13
13
|
- **Pure ESM & Single `.wasm`**: Modern `"exports"` entrypoints for browsers/bundlers (`./pkg/index.js`) and Node.js 18+ (`./pkg/egraph_wasm.node.js`), sharing a single `wasm-opt -Oz` optimized `.wasm` binary.
|
|
14
14
|
- **Strictly Single-Threaded**: Pure CPU Rust with deterministic seeded execution (`seed = 42` default), zero `rayon`, zero `std::thread`, zero Web Workers, and zero `SharedArrayBuffer`.
|
|
15
15
|
- **Zero-Copy Linear Memory Views**: `coordsView()` on `Layout2d`, `Layout3d`, `LayoutNd`, and `ManifoldLayout2d` (plus `edgeOffsetsView()` / `pointsView()` on `EdgePolylines`, `labelsView()` on all 5 clustering result classes, and `centroidsView()` on `KMeansResult`) returns a cached typed-array view directly over WebAssembly linear memory and automatically refreshes if `memory.grow` detaches the `ArrayBuffer`.
|
|
16
|
-
- **Target-Checked Cooperative Execution & TS Contracts**: TypeScript interfaces (`LayoutStorage`, `IterativeSolver`, `LayoutGenerator`, `LayoutTransform`),
|
|
17
|
-
- **Strict `camelCase`, `BigInt` Seeds, `.code` Errors & `f32` CSR**:
|
|
18
|
-
- **
|
|
16
|
+
- **Target-Checked Cooperative Execution & TS Contracts**: TypeScript interfaces (`LayoutStorage`, `IterativeSolver`, `LayoutGenerator`, `LayoutTransform`), typed `#[wasm_bindgen]` enums (`TargetKind`, `WeightDtype`, `ManifoldKind`, `TsNetBackend`, `FieldRepulsionBackend`, `ForceBackend`, `MetricTarget`, `SolverStatus`, etc.), `step(layout)`, `runSteps(layout, k)`, `run(layout)`, and `runProgressive(solver, layout, onFrame, options?)`.
|
|
17
|
+
- **Strict `camelCase`, `BigInt` Seeds, `.code` Errors & `f32` CSR**: `number | bigint` 64-bit seeds, structured `Error` `.code` (`EgraphErrorCode`), and strict `WeightDtype.Float32` validation on `Graph`.
|
|
18
|
+
- **Comprehensive Layout, 3D & Non-Euclidean Engines**: `SgdSolver` (`full`, `randomPair`, `ortmannSparseStress`, `omega`), `StressMajorizationSolver`, `KamadaKawaiSolver`, `MaxentStressSolver`, `TsNetSolver` (`fromKnn`, `fromProbabilities`, `fromGraphPartialBfs`), `TFdpSolver`, `IbUmapSolver`, `GuMapSolver`, `SnapTFdpSolver`, `LargeVisSolver`, `DrGraphSolver`, `GraphCneSolver`, `ForceAtlas2Solver`, `YifanHuSolver`, `LinLogSolver`, `FruchtermanReingoldSolver`, `GemSolver`, `GripSolver`, `Layout3d` + `ArenaOctree3d`, `DynamicKdTree`, `EdgePolylines` + `FdebSolver(polylines)`, `ManifoldLayout2d` (`ManifoldKind.HyperbolicLorentz`, `toPoincareLayout`, `metric()` (`ManifoldMetricRecord`), `torusAutoPan`, geodesic crossings), `LayoutGenerator`s (`ClassicalMds`, `PivotMds`, `Hde`, `RdMds`, `KorenSpectral`, `SfcLayout`), `PfsPrimeOverlapRemoval`, `MetricReport` (`toRecord()`), `listDatasets` / synthetic generators, and `DijkstraWorkspace`.
|
|
19
19
|
|
|
20
20
|
## Quick Start (Browser / Bundler ESM)
|
|
21
21
|
|
|
22
22
|
```js
|
|
23
23
|
import init, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Graph,
|
|
25
|
+
FieldRepulsionBackend,
|
|
26
|
+
MetricTarget,
|
|
27
|
+
PivotMds,
|
|
28
|
+
TFdpSolver,
|
|
27
29
|
evaluateMetrics,
|
|
28
|
-
pivotMdsInit,
|
|
29
30
|
runProgressive,
|
|
30
31
|
} from "egraph";
|
|
31
32
|
|
|
@@ -34,14 +35,16 @@ await init();
|
|
|
34
35
|
// Build an undirected CSR graph (0 - 1 - 2 - 3 - 0)
|
|
35
36
|
const indptr = new Uint32Array([0, 2, 4, 6, 8]);
|
|
36
37
|
const indices = new Uint32Array([1, 3, 0, 2, 1, 3, 2, 0]);
|
|
37
|
-
const graph =
|
|
38
|
+
const graph = Graph.fromCsr(indptr, indices);
|
|
38
39
|
|
|
39
40
|
// Initialize with normalized PivotMDS (f32 Layout2d)
|
|
40
|
-
const layout =
|
|
41
|
+
const layout = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
41
42
|
|
|
42
|
-
// Run
|
|
43
|
-
const solver =
|
|
44
|
-
|
|
43
|
+
// Run t-FDP (Zhong et al., 2024) progressively in requestAnimationFrame
|
|
44
|
+
const solver = new TFdpSolver(graph, {
|
|
45
|
+
alpha: 0.1,
|
|
46
|
+
backend: FieldRepulsionBackend.IbFft,
|
|
47
|
+
iterations: 200,
|
|
45
48
|
seed: 42,
|
|
46
49
|
});
|
|
47
50
|
|
|
@@ -56,7 +59,11 @@ await runProgressive(
|
|
|
56
59
|
);
|
|
57
60
|
|
|
58
61
|
// Selectively evaluate quality metrics -> MetricReport
|
|
59
|
-
const report = evaluateMetrics(graph, layout, [
|
|
62
|
+
const report = evaluateMetrics(graph, layout, [
|
|
63
|
+
MetricTarget.ScaleNormalizedStress,
|
|
64
|
+
MetricTarget.NeighborhoodPreservation2Hop,
|
|
65
|
+
MetricTarget.CrossingNumber,
|
|
66
|
+
]);
|
|
60
67
|
console.log(report.toRecord());
|
|
61
68
|
```
|
|
62
69
|
|
|
@@ -65,13 +72,18 @@ console.log(report.toRecord());
|
|
|
65
72
|
The same `"egraph"` import automatically resolves to the Node ESM loader via `"exports"`:
|
|
66
73
|
|
|
67
74
|
```js
|
|
68
|
-
import init, {
|
|
75
|
+
import init, { Graph, FieldRepulsionBackend, PivotMds, TFdpSolver } from "egraph";
|
|
69
76
|
|
|
70
77
|
await init();
|
|
71
78
|
|
|
72
|
-
const graph =
|
|
73
|
-
const layout =
|
|
74
|
-
const solver = new TFdpSolver(graph, {
|
|
79
|
+
const graph = Graph.fromEdgeList(4, new Uint32Array([0, 1, 1, 2, 2, 3, 3, 0]));
|
|
80
|
+
const layout = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
81
|
+
const solver = new TFdpSolver(graph, {
|
|
82
|
+
alpha: 0.1,
|
|
83
|
+
backend: FieldRepulsionBackend.IbFft,
|
|
84
|
+
iterations: 200,
|
|
85
|
+
seed: 42,
|
|
86
|
+
});
|
|
75
87
|
solver.run(layout);
|
|
76
88
|
|
|
77
89
|
const xy = layout.coordsView();
|
|
@@ -80,70 +92,50 @@ console.log(Array.from(xy));
|
|
|
80
92
|
|
|
81
93
|
## Solver & Engine Examples
|
|
82
94
|
|
|
83
|
-
###
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
const solver = TsNetSolver.pure2Hop(graph, {
|
|
87
|
-
backend: "auto2d", // "auto2d", "fitFft", "linearFft", "barnesHut", "exact"
|
|
88
|
-
perplexityC: 0.9,
|
|
89
|
-
seed: 42,
|
|
90
|
-
});
|
|
91
|
-
solver.run(layout);
|
|
92
|
-
|
|
93
|
-
const rnSolver = TsNetSolver.fromGraphRowNormalizedWithOptions(graph, {
|
|
94
|
-
w2: 0.5,
|
|
95
|
-
mode: "twoStepRandomWalk",
|
|
96
|
-
backend: "auto2d",
|
|
97
|
-
seed: 42,
|
|
98
|
-
});
|
|
99
|
-
rnSolver.run(layout);
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Track B, Separated Embedding & Force Models
|
|
95
|
+
### Neighborhood, Force & Embedding Models
|
|
103
96
|
|
|
104
97
|
```js
|
|
105
98
|
import {
|
|
99
|
+
FieldRepulsionBackend,
|
|
106
100
|
ForceAtlas2Solver,
|
|
107
|
-
|
|
108
|
-
PacmapGraphSolver,
|
|
101
|
+
ForceBackend,
|
|
109
102
|
SgdSolver,
|
|
110
103
|
SnapTFdpSolver,
|
|
111
104
|
TFdpSolver,
|
|
105
|
+
TsNetBackend,
|
|
106
|
+
TsNetSolver,
|
|
112
107
|
} from "egraph";
|
|
113
108
|
|
|
114
|
-
//
|
|
109
|
+
// tsNET from Partial BFS k-NN (Meidiana et al., 2025)
|
|
110
|
+
const tsnet = TsNetSolver.fromGraphPartialBfs(graph, {
|
|
111
|
+
k: 4,
|
|
112
|
+
uniformPerplexity: 3.0,
|
|
113
|
+
backend: TsNetBackend.Auto2d,
|
|
114
|
+
seed: 42,
|
|
115
|
+
});
|
|
116
|
+
tsnet.run(layout);
|
|
117
|
+
|
|
118
|
+
// t-FDP with ibFFT repulsion (Zhong et al., 2024)
|
|
115
119
|
const tfdp = new TFdpSolver(graph, {
|
|
116
|
-
|
|
120
|
+
alpha: 0.1,
|
|
121
|
+
backend: FieldRepulsionBackend.IbFft,
|
|
117
122
|
iterations: 200,
|
|
118
123
|
seed: 42,
|
|
119
124
|
});
|
|
120
125
|
tfdp.run(layout);
|
|
121
126
|
|
|
122
|
-
// ForceAtlas2
|
|
127
|
+
// ForceAtlas2 with Barnes–Hut (Jacomy et al., 2014)
|
|
123
128
|
const fa2 = new ForceAtlas2Solver(graph, {
|
|
124
|
-
backend:
|
|
129
|
+
backend: ForceBackend.BarnesHut,
|
|
125
130
|
iterations: 200,
|
|
126
131
|
theta: 0.5,
|
|
127
132
|
seed: 42,
|
|
128
133
|
});
|
|
129
134
|
fa2.run(layout);
|
|
130
135
|
|
|
131
|
-
//
|
|
132
|
-
|
|
136
|
+
// Full-stress SGD (Zheng et al., 2019) and SNAP-tFDP (Chen et al., 2026)
|
|
137
|
+
SgdSolver.full(graph, { iterations: 60, seed: 42 }).run(layout);
|
|
133
138
|
new SnapTFdpSolver(graph, { iterations: 100, seed: 42 }).run(layout);
|
|
134
|
-
|
|
135
|
-
// GuMap from regularized Chebyshev DoG landmarks
|
|
136
|
-
const gumap = GuMapSolver.fromGraphDog(graph, {
|
|
137
|
-
iterations: 200,
|
|
138
|
-
minDist: 0.1,
|
|
139
|
-
spread: 1.0,
|
|
140
|
-
seed: 42,
|
|
141
|
-
});
|
|
142
|
-
gumap.run(layout);
|
|
143
|
-
|
|
144
|
-
// Regularized DoG 3-tier Sparse Barrier SGD
|
|
145
|
-
const barrierSgd = SgdSolver.sparseBarrierDog(graph, { seed: 42 });
|
|
146
|
-
barrierSgd.run(layout);
|
|
147
139
|
```
|
|
148
140
|
|
|
149
141
|
### `Layout3d`, `EdgePolylines` (`FdebSolver`), `BigInt` Seeds & Non-Euclidean Manifolds
|
|
@@ -154,19 +146,23 @@ import {
|
|
|
154
146
|
EdgePolylines,
|
|
155
147
|
FdebSolver,
|
|
156
148
|
ForceAtlas2Solver,
|
|
149
|
+
ForceBackend,
|
|
157
150
|
Layout3d,
|
|
151
|
+
ManifoldKind,
|
|
158
152
|
ManifoldLayout2d,
|
|
159
153
|
SgdSolver,
|
|
154
|
+
TargetKind,
|
|
155
|
+
TsNetBackend,
|
|
160
156
|
TsNetSolver,
|
|
161
157
|
geodesicDistortion,
|
|
162
158
|
runProgressive,
|
|
163
159
|
} from "egraph";
|
|
164
160
|
|
|
165
|
-
// 3D Layout3d with 64-bit BigInt seed, target:
|
|
161
|
+
// 3D Layout3d with 64-bit BigInt seed, target: TargetKind.Layout3d, and ArenaOctree3d
|
|
166
162
|
const layout3d = Layout3d.init(graph.numNodes(), { seed: 42n });
|
|
167
163
|
new ForceAtlas2Solver(graph, {
|
|
168
|
-
target:
|
|
169
|
-
backend:
|
|
164
|
+
target: TargetKind.Layout3d,
|
|
165
|
+
backend: ForceBackend.BarnesHut,
|
|
170
166
|
iterations: 100,
|
|
171
167
|
seed: 42n,
|
|
172
168
|
}).run(layout3d);
|
|
@@ -181,35 +177,38 @@ const fdeb = new FdebSolver(polylines, { cycles: 3, stepsPerCycle: 15 });
|
|
|
181
177
|
fdeb.run(polylines);
|
|
182
178
|
console.log("bundled points:", polylines.edgeOffsetsView().length, polylines.pointsView().length);
|
|
183
179
|
|
|
184
|
-
// Hyperbolic Lorentz hyperboloid -> Poincaré disk + explicit target:
|
|
185
|
-
const lorentz = ManifoldLayout2d.init(
|
|
180
|
+
// Hyperbolic Lorentz hyperboloid -> Poincaré disk + explicit target: TargetKind.Manifold2d
|
|
181
|
+
const lorentz = ManifoldLayout2d.init(ManifoldKind.HyperbolicLorentz, graph.numNodes(), { seed: 42 });
|
|
186
182
|
await runProgressive(
|
|
187
|
-
SgdSolver.full(graph, { target:
|
|
183
|
+
SgdSolver.full(graph, { target: TargetKind.Manifold2d, iterations: 60, seed: 42 }),
|
|
188
184
|
lorentz,
|
|
189
185
|
);
|
|
190
186
|
const poincare = lorentz.toPoincareLayout();
|
|
191
187
|
console.log("geodesicDistortion:", geodesicDistortion(graph, poincare));
|
|
192
188
|
|
|
193
|
-
// Torus
|
|
194
|
-
const torus = ManifoldLayout2d.
|
|
189
|
+
// Torus layout + optimal boundary auto-pan (Chen et al., 2020)
|
|
190
|
+
const torus = ManifoldLayout2d.init(ManifoldKind.Torus2d, graph.numNodes(), { seed: 42 });
|
|
191
|
+
SgdSolver.full(graph, { target: TargetKind.Manifold2d, iterations: 60, seed: 42 }).run(torus);
|
|
195
192
|
const panned = torus.torusAutoPan(graph);
|
|
196
193
|
console.log(panned.coordsView().length);
|
|
197
194
|
|
|
198
195
|
// Structured error codes (.code: EgraphErrorCode) on invalid (target, backend) pairs
|
|
199
196
|
try {
|
|
200
|
-
TsNetSolver.
|
|
197
|
+
TsNetSolver.fromGraphPartialBfs(graph, {
|
|
198
|
+
target: TargetKind.Layout3d,
|
|
199
|
+
backend: TsNetBackend.FitFft,
|
|
200
|
+
});
|
|
201
201
|
} catch (err) {
|
|
202
202
|
console.error("Error code:", err.code); // "UnsupportedOperation"
|
|
203
203
|
}
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
### Clustering (`labelsView()`), Overlap Removal
|
|
206
|
+
### Clustering (`labelsView()`), Overlap Removal & Datasets
|
|
207
207
|
|
|
208
208
|
```js
|
|
209
209
|
import {
|
|
210
210
|
Layout2d,
|
|
211
211
|
PrismOverlapRemoval,
|
|
212
|
-
TwinDeclutterer,
|
|
213
212
|
generateSbmGraph,
|
|
214
213
|
leidenCommunities,
|
|
215
214
|
listDatasets,
|
|
@@ -225,7 +224,7 @@ const leiden = leidenCommunities(sbmGraph, { seed: 42 });
|
|
|
225
224
|
const labels = leiden.labelsView();
|
|
226
225
|
console.log("datasets:", listDatasets().length, "communities:", leiden.numCommunities, labels.length, groundTruth.length);
|
|
227
226
|
|
|
228
|
-
// Overlap removal (PRISM)
|
|
227
|
+
// Overlap removal (PRISM)
|
|
229
228
|
const original = Layout2d.fromCoords(layout.coordsView());
|
|
230
229
|
const radii = new Float32Array(graph.numNodes()).fill(0.25);
|
|
231
230
|
const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
@@ -234,45 +233,40 @@ const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
|
234
233
|
seed: 42,
|
|
235
234
|
});
|
|
236
235
|
prism.run(layout);
|
|
237
|
-
new TwinDeclutterer({ iterations: 4 }).apply(layout);
|
|
238
236
|
|
|
239
237
|
const distortion = prismDistortion(original, layout);
|
|
240
238
|
console.log(prism.lastOverlapCount, distortion.sigmaDist, distortion.sigmaDisp);
|
|
241
239
|
```
|
|
242
240
|
|
|
243
|
-
### Linalg, `LayoutGenerator`s
|
|
241
|
+
### Linalg, `LayoutGenerator`s & Shortest Paths
|
|
244
242
|
|
|
245
243
|
```js
|
|
246
244
|
import {
|
|
247
|
-
ChebyshevDogKernel,
|
|
248
245
|
ClassicalMds,
|
|
249
246
|
DijkstraWorkspace,
|
|
247
|
+
LaplacianKind,
|
|
250
248
|
PivotMds,
|
|
249
|
+
TargetKind,
|
|
251
250
|
classicalMds,
|
|
252
251
|
combinatorialLaplacian,
|
|
252
|
+
laplacian,
|
|
253
253
|
pivotMds,
|
|
254
254
|
} from "egraph";
|
|
255
255
|
|
|
256
256
|
const ws = new DijkstraWorkspace(graph.numNodes());
|
|
257
257
|
const dists = ws.dijkstraFrom(graph, 0);
|
|
258
258
|
const mdsNd = classicalMds(graph, 3);
|
|
259
|
-
const mds3d = new ClassicalMds({ target:
|
|
259
|
+
const mds3d = new ClassicalMds({ target: TargetKind.Layout3d }).generate(graph);
|
|
260
260
|
const mds2d = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
261
261
|
const mds2dFn = pivotMds(graph, { numPivots: 4, seed: 42 });
|
|
262
262
|
const lap = combinatorialLaplacian(graph);
|
|
263
|
-
const
|
|
264
|
-
console.log(dists.length, mdsNd.dims, mds3d.len(), mds2d.numNodes, mds2dFn.numNodes, lap.nnz,
|
|
263
|
+
const normLap = laplacian(graph, LaplacianKind.SymmetricNormalized);
|
|
264
|
+
console.log(dists.length, mdsNd.dims, mds3d.len(), mds2d.numNodes, mds2dFn.numNodes, lap.nnz, normLap.nnz);
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
-
## Migration
|
|
268
|
-
|
|
269
|
-
See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for a complete v5, `alpha.8 -> alpha.9`, and v6 API freeze migration guide, including:
|
|
267
|
+
## Migration & Literature Attribution
|
|
270
268
|
|
|
271
|
-
|
|
272
|
-
2. Migrating overlap removal and post-processing to `PrismOverlapRemoval` / `ForbidOverlapRemoval` and `LayoutTransform.apply()` (`PfsPrimeOverlapRemoval`, `TwinDeclutterer`)
|
|
273
|
-
3. Consolidating `TsNet` / `BhTsNet` / `FitTsNet` / `LTsNet` into `TsNetSolver` (`pure2Hop`, `fromGraphRowNormalized`, `auto2d`/`auto3d`/`fitFft`/`linearFft`/`barnesHut`/`exact`) and `LayoutGenerator` structs (`ClassicalMds`, `PivotMds`, `Hde`, `RdMds`, `KorenSpectral`, `CoarseBackbone`, `SfcLayout`)
|
|
274
|
-
4. Adopting `Layout3d`, `EdgePolylines` + `FdebSolver(polylines)`, separated SGD classes (`Sgd2Solver`, `PacmapGraphSolver`, `LargeVisSolver`, `DrGraphSolver`, `GraphCneSolver`, `SnapTFdpSolver`), and explicit `target` (`"layout2d" | "layout3d" | "layoutNd" | "manifold2d"`)
|
|
275
|
-
5. Migrating from `egraph/dist/web/egraph_wasm` to pure ESM, `coordsView()`, `edgeOffsetsView()`, `pointsView()`, `labelsView()`, `runProgressive`, `{ ...options }`, `camelCase` literals, `number | bigint` seeds, and `.code` structured errors
|
|
269
|
+
See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for upgrading from v5, earlier v6 prereleases, and string-based modes to typed enums, [docs/PAPER_MAPPING.md](https://github.com/likr/egraph-rs/blob/master/docs/PAPER_MAPPING.md) for the complete algorithm-to-literature mapping table, and [docs/UNIMPLEMENTED_PAPERS.md](https://github.com/likr/egraph-rs/blob/master/docs/UNIMPLEMENTED_PAPERS.md) for major graph-drawing literature not yet implemented.
|
|
276
270
|
|
|
277
271
|
## License
|
|
278
272
|
|
package/package.json
CHANGED
package/pkg/README.md
CHANGED
|
@@ -13,19 +13,20 @@ npm install egraph
|
|
|
13
13
|
- **Pure ESM & Single `.wasm`**: Modern `"exports"` entrypoints for browsers/bundlers (`./pkg/index.js`) and Node.js 18+ (`./pkg/egraph_wasm.node.js`), sharing a single `wasm-opt -Oz` optimized `.wasm` binary.
|
|
14
14
|
- **Strictly Single-Threaded**: Pure CPU Rust with deterministic seeded execution (`seed = 42` default), zero `rayon`, zero `std::thread`, zero Web Workers, and zero `SharedArrayBuffer`.
|
|
15
15
|
- **Zero-Copy Linear Memory Views**: `coordsView()` on `Layout2d`, `Layout3d`, `LayoutNd`, and `ManifoldLayout2d` (plus `edgeOffsetsView()` / `pointsView()` on `EdgePolylines`, `labelsView()` on all 5 clustering result classes, and `centroidsView()` on `KMeansResult`) returns a cached typed-array view directly over WebAssembly linear memory and automatically refreshes if `memory.grow` detaches the `ArrayBuffer`.
|
|
16
|
-
- **Target-Checked Cooperative Execution & TS Contracts**: TypeScript interfaces (`LayoutStorage`, `IterativeSolver`, `LayoutGenerator`, `LayoutTransform`),
|
|
17
|
-
- **Strict `camelCase`, `BigInt` Seeds, `.code` Errors & `f32` CSR**:
|
|
18
|
-
- **
|
|
16
|
+
- **Target-Checked Cooperative Execution & TS Contracts**: TypeScript interfaces (`LayoutStorage`, `IterativeSolver`, `LayoutGenerator`, `LayoutTransform`), typed `#[wasm_bindgen]` enums (`TargetKind`, `WeightDtype`, `ManifoldKind`, `TsNetBackend`, `FieldRepulsionBackend`, `ForceBackend`, `MetricTarget`, `SolverStatus`, etc.), `step(layout)`, `runSteps(layout, k)`, `run(layout)`, and `runProgressive(solver, layout, onFrame, options?)`.
|
|
17
|
+
- **Strict `camelCase`, `BigInt` Seeds, `.code` Errors & `f32` CSR**: `number | bigint` 64-bit seeds, structured `Error` `.code` (`EgraphErrorCode`), and strict `WeightDtype.Float32` validation on `Graph`.
|
|
18
|
+
- **Comprehensive Layout, 3D & Non-Euclidean Engines**: `SgdSolver` (`full`, `randomPair`, `ortmannSparseStress`, `omega`), `StressMajorizationSolver`, `KamadaKawaiSolver`, `MaxentStressSolver`, `TsNetSolver` (`fromKnn`, `fromProbabilities`, `fromGraphPartialBfs`), `TFdpSolver`, `IbUmapSolver`, `GuMapSolver`, `SnapTFdpSolver`, `LargeVisSolver`, `DrGraphSolver`, `GraphCneSolver`, `ForceAtlas2Solver`, `YifanHuSolver`, `LinLogSolver`, `FruchtermanReingoldSolver`, `GemSolver`, `GripSolver`, `Layout3d` + `ArenaOctree3d`, `DynamicKdTree`, `EdgePolylines` + `FdebSolver(polylines)`, `ManifoldLayout2d` (`ManifoldKind.HyperbolicLorentz`, `toPoincareLayout`, `metric()` (`ManifoldMetricRecord`), `torusAutoPan`, geodesic crossings), `LayoutGenerator`s (`ClassicalMds`, `PivotMds`, `Hde`, `RdMds`, `KorenSpectral`, `SfcLayout`), `PfsPrimeOverlapRemoval`, `MetricReport` (`toRecord()`), `listDatasets` / synthetic generators, and `DijkstraWorkspace`.
|
|
19
19
|
|
|
20
20
|
## Quick Start (Browser / Bundler ESM)
|
|
21
21
|
|
|
22
22
|
```js
|
|
23
23
|
import init, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Graph,
|
|
25
|
+
FieldRepulsionBackend,
|
|
26
|
+
MetricTarget,
|
|
27
|
+
PivotMds,
|
|
28
|
+
TFdpSolver,
|
|
27
29
|
evaluateMetrics,
|
|
28
|
-
pivotMdsInit,
|
|
29
30
|
runProgressive,
|
|
30
31
|
} from "egraph";
|
|
31
32
|
|
|
@@ -34,14 +35,16 @@ await init();
|
|
|
34
35
|
// Build an undirected CSR graph (0 - 1 - 2 - 3 - 0)
|
|
35
36
|
const indptr = new Uint32Array([0, 2, 4, 6, 8]);
|
|
36
37
|
const indices = new Uint32Array([1, 3, 0, 2, 1, 3, 2, 0]);
|
|
37
|
-
const graph =
|
|
38
|
+
const graph = Graph.fromCsr(indptr, indices);
|
|
38
39
|
|
|
39
40
|
// Initialize with normalized PivotMDS (f32 Layout2d)
|
|
40
|
-
const layout =
|
|
41
|
+
const layout = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
41
42
|
|
|
42
|
-
// Run
|
|
43
|
-
const solver =
|
|
44
|
-
|
|
43
|
+
// Run t-FDP (Zhong et al., 2024) progressively in requestAnimationFrame
|
|
44
|
+
const solver = new TFdpSolver(graph, {
|
|
45
|
+
alpha: 0.1,
|
|
46
|
+
backend: FieldRepulsionBackend.IbFft,
|
|
47
|
+
iterations: 200,
|
|
45
48
|
seed: 42,
|
|
46
49
|
});
|
|
47
50
|
|
|
@@ -56,7 +59,11 @@ await runProgressive(
|
|
|
56
59
|
);
|
|
57
60
|
|
|
58
61
|
// Selectively evaluate quality metrics -> MetricReport
|
|
59
|
-
const report = evaluateMetrics(graph, layout, [
|
|
62
|
+
const report = evaluateMetrics(graph, layout, [
|
|
63
|
+
MetricTarget.ScaleNormalizedStress,
|
|
64
|
+
MetricTarget.NeighborhoodPreservation2Hop,
|
|
65
|
+
MetricTarget.CrossingNumber,
|
|
66
|
+
]);
|
|
60
67
|
console.log(report.toRecord());
|
|
61
68
|
```
|
|
62
69
|
|
|
@@ -65,13 +72,18 @@ console.log(report.toRecord());
|
|
|
65
72
|
The same `"egraph"` import automatically resolves to the Node ESM loader via `"exports"`:
|
|
66
73
|
|
|
67
74
|
```js
|
|
68
|
-
import init, {
|
|
75
|
+
import init, { Graph, FieldRepulsionBackend, PivotMds, TFdpSolver } from "egraph";
|
|
69
76
|
|
|
70
77
|
await init();
|
|
71
78
|
|
|
72
|
-
const graph =
|
|
73
|
-
const layout =
|
|
74
|
-
const solver = new TFdpSolver(graph, {
|
|
79
|
+
const graph = Graph.fromEdgeList(4, new Uint32Array([0, 1, 1, 2, 2, 3, 3, 0]));
|
|
80
|
+
const layout = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
81
|
+
const solver = new TFdpSolver(graph, {
|
|
82
|
+
alpha: 0.1,
|
|
83
|
+
backend: FieldRepulsionBackend.IbFft,
|
|
84
|
+
iterations: 200,
|
|
85
|
+
seed: 42,
|
|
86
|
+
});
|
|
75
87
|
solver.run(layout);
|
|
76
88
|
|
|
77
89
|
const xy = layout.coordsView();
|
|
@@ -80,70 +92,50 @@ console.log(Array.from(xy));
|
|
|
80
92
|
|
|
81
93
|
## Solver & Engine Examples
|
|
82
94
|
|
|
83
|
-
###
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
const solver = TsNetSolver.pure2Hop(graph, {
|
|
87
|
-
backend: "auto2d", // "auto2d", "fitFft", "linearFft", "barnesHut", "exact"
|
|
88
|
-
perplexityC: 0.9,
|
|
89
|
-
seed: 42,
|
|
90
|
-
});
|
|
91
|
-
solver.run(layout);
|
|
92
|
-
|
|
93
|
-
const rnSolver = TsNetSolver.fromGraphRowNormalizedWithOptions(graph, {
|
|
94
|
-
w2: 0.5,
|
|
95
|
-
mode: "twoStepRandomWalk",
|
|
96
|
-
backend: "auto2d",
|
|
97
|
-
seed: 42,
|
|
98
|
-
});
|
|
99
|
-
rnSolver.run(layout);
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Track B, Separated Embedding & Force Models
|
|
95
|
+
### Neighborhood, Force & Embedding Models
|
|
103
96
|
|
|
104
97
|
```js
|
|
105
98
|
import {
|
|
99
|
+
FieldRepulsionBackend,
|
|
106
100
|
ForceAtlas2Solver,
|
|
107
|
-
|
|
108
|
-
PacmapGraphSolver,
|
|
101
|
+
ForceBackend,
|
|
109
102
|
SgdSolver,
|
|
110
103
|
SnapTFdpSolver,
|
|
111
104
|
TFdpSolver,
|
|
105
|
+
TsNetBackend,
|
|
106
|
+
TsNetSolver,
|
|
112
107
|
} from "egraph";
|
|
113
108
|
|
|
114
|
-
//
|
|
109
|
+
// tsNET from Partial BFS k-NN (Meidiana et al., 2025)
|
|
110
|
+
const tsnet = TsNetSolver.fromGraphPartialBfs(graph, {
|
|
111
|
+
k: 4,
|
|
112
|
+
uniformPerplexity: 3.0,
|
|
113
|
+
backend: TsNetBackend.Auto2d,
|
|
114
|
+
seed: 42,
|
|
115
|
+
});
|
|
116
|
+
tsnet.run(layout);
|
|
117
|
+
|
|
118
|
+
// t-FDP with ibFFT repulsion (Zhong et al., 2024)
|
|
115
119
|
const tfdp = new TFdpSolver(graph, {
|
|
116
|
-
|
|
120
|
+
alpha: 0.1,
|
|
121
|
+
backend: FieldRepulsionBackend.IbFft,
|
|
117
122
|
iterations: 200,
|
|
118
123
|
seed: 42,
|
|
119
124
|
});
|
|
120
125
|
tfdp.run(layout);
|
|
121
126
|
|
|
122
|
-
// ForceAtlas2
|
|
127
|
+
// ForceAtlas2 with Barnes–Hut (Jacomy et al., 2014)
|
|
123
128
|
const fa2 = new ForceAtlas2Solver(graph, {
|
|
124
|
-
backend:
|
|
129
|
+
backend: ForceBackend.BarnesHut,
|
|
125
130
|
iterations: 200,
|
|
126
131
|
theta: 0.5,
|
|
127
132
|
seed: 42,
|
|
128
133
|
});
|
|
129
134
|
fa2.run(layout);
|
|
130
135
|
|
|
131
|
-
//
|
|
132
|
-
|
|
136
|
+
// Full-stress SGD (Zheng et al., 2019) and SNAP-tFDP (Chen et al., 2026)
|
|
137
|
+
SgdSolver.full(graph, { iterations: 60, seed: 42 }).run(layout);
|
|
133
138
|
new SnapTFdpSolver(graph, { iterations: 100, seed: 42 }).run(layout);
|
|
134
|
-
|
|
135
|
-
// GuMap from regularized Chebyshev DoG landmarks
|
|
136
|
-
const gumap = GuMapSolver.fromGraphDog(graph, {
|
|
137
|
-
iterations: 200,
|
|
138
|
-
minDist: 0.1,
|
|
139
|
-
spread: 1.0,
|
|
140
|
-
seed: 42,
|
|
141
|
-
});
|
|
142
|
-
gumap.run(layout);
|
|
143
|
-
|
|
144
|
-
// Regularized DoG 3-tier Sparse Barrier SGD
|
|
145
|
-
const barrierSgd = SgdSolver.sparseBarrierDog(graph, { seed: 42 });
|
|
146
|
-
barrierSgd.run(layout);
|
|
147
139
|
```
|
|
148
140
|
|
|
149
141
|
### `Layout3d`, `EdgePolylines` (`FdebSolver`), `BigInt` Seeds & Non-Euclidean Manifolds
|
|
@@ -154,19 +146,23 @@ import {
|
|
|
154
146
|
EdgePolylines,
|
|
155
147
|
FdebSolver,
|
|
156
148
|
ForceAtlas2Solver,
|
|
149
|
+
ForceBackend,
|
|
157
150
|
Layout3d,
|
|
151
|
+
ManifoldKind,
|
|
158
152
|
ManifoldLayout2d,
|
|
159
153
|
SgdSolver,
|
|
154
|
+
TargetKind,
|
|
155
|
+
TsNetBackend,
|
|
160
156
|
TsNetSolver,
|
|
161
157
|
geodesicDistortion,
|
|
162
158
|
runProgressive,
|
|
163
159
|
} from "egraph";
|
|
164
160
|
|
|
165
|
-
// 3D Layout3d with 64-bit BigInt seed, target:
|
|
161
|
+
// 3D Layout3d with 64-bit BigInt seed, target: TargetKind.Layout3d, and ArenaOctree3d
|
|
166
162
|
const layout3d = Layout3d.init(graph.numNodes(), { seed: 42n });
|
|
167
163
|
new ForceAtlas2Solver(graph, {
|
|
168
|
-
target:
|
|
169
|
-
backend:
|
|
164
|
+
target: TargetKind.Layout3d,
|
|
165
|
+
backend: ForceBackend.BarnesHut,
|
|
170
166
|
iterations: 100,
|
|
171
167
|
seed: 42n,
|
|
172
168
|
}).run(layout3d);
|
|
@@ -181,35 +177,38 @@ const fdeb = new FdebSolver(polylines, { cycles: 3, stepsPerCycle: 15 });
|
|
|
181
177
|
fdeb.run(polylines);
|
|
182
178
|
console.log("bundled points:", polylines.edgeOffsetsView().length, polylines.pointsView().length);
|
|
183
179
|
|
|
184
|
-
// Hyperbolic Lorentz hyperboloid -> Poincaré disk + explicit target:
|
|
185
|
-
const lorentz = ManifoldLayout2d.init(
|
|
180
|
+
// Hyperbolic Lorentz hyperboloid -> Poincaré disk + explicit target: TargetKind.Manifold2d
|
|
181
|
+
const lorentz = ManifoldLayout2d.init(ManifoldKind.HyperbolicLorentz, graph.numNodes(), { seed: 42 });
|
|
186
182
|
await runProgressive(
|
|
187
|
-
SgdSolver.full(graph, { target:
|
|
183
|
+
SgdSolver.full(graph, { target: TargetKind.Manifold2d, iterations: 60, seed: 42 }),
|
|
188
184
|
lorentz,
|
|
189
185
|
);
|
|
190
186
|
const poincare = lorentz.toPoincareLayout();
|
|
191
187
|
console.log("geodesicDistortion:", geodesicDistortion(graph, poincare));
|
|
192
188
|
|
|
193
|
-
// Torus
|
|
194
|
-
const torus = ManifoldLayout2d.
|
|
189
|
+
// Torus layout + optimal boundary auto-pan (Chen et al., 2020)
|
|
190
|
+
const torus = ManifoldLayout2d.init(ManifoldKind.Torus2d, graph.numNodes(), { seed: 42 });
|
|
191
|
+
SgdSolver.full(graph, { target: TargetKind.Manifold2d, iterations: 60, seed: 42 }).run(torus);
|
|
195
192
|
const panned = torus.torusAutoPan(graph);
|
|
196
193
|
console.log(panned.coordsView().length);
|
|
197
194
|
|
|
198
195
|
// Structured error codes (.code: EgraphErrorCode) on invalid (target, backend) pairs
|
|
199
196
|
try {
|
|
200
|
-
TsNetSolver.
|
|
197
|
+
TsNetSolver.fromGraphPartialBfs(graph, {
|
|
198
|
+
target: TargetKind.Layout3d,
|
|
199
|
+
backend: TsNetBackend.FitFft,
|
|
200
|
+
});
|
|
201
201
|
} catch (err) {
|
|
202
202
|
console.error("Error code:", err.code); // "UnsupportedOperation"
|
|
203
203
|
}
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
### Clustering (`labelsView()`), Overlap Removal
|
|
206
|
+
### Clustering (`labelsView()`), Overlap Removal & Datasets
|
|
207
207
|
|
|
208
208
|
```js
|
|
209
209
|
import {
|
|
210
210
|
Layout2d,
|
|
211
211
|
PrismOverlapRemoval,
|
|
212
|
-
TwinDeclutterer,
|
|
213
212
|
generateSbmGraph,
|
|
214
213
|
leidenCommunities,
|
|
215
214
|
listDatasets,
|
|
@@ -225,7 +224,7 @@ const leiden = leidenCommunities(sbmGraph, { seed: 42 });
|
|
|
225
224
|
const labels = leiden.labelsView();
|
|
226
225
|
console.log("datasets:", listDatasets().length, "communities:", leiden.numCommunities, labels.length, groundTruth.length);
|
|
227
226
|
|
|
228
|
-
// Overlap removal (PRISM)
|
|
227
|
+
// Overlap removal (PRISM)
|
|
229
228
|
const original = Layout2d.fromCoords(layout.coordsView());
|
|
230
229
|
const radii = new Float32Array(graph.numNodes()).fill(0.25);
|
|
231
230
|
const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
@@ -234,45 +233,40 @@ const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
|
234
233
|
seed: 42,
|
|
235
234
|
});
|
|
236
235
|
prism.run(layout);
|
|
237
|
-
new TwinDeclutterer({ iterations: 4 }).apply(layout);
|
|
238
236
|
|
|
239
237
|
const distortion = prismDistortion(original, layout);
|
|
240
238
|
console.log(prism.lastOverlapCount, distortion.sigmaDist, distortion.sigmaDisp);
|
|
241
239
|
```
|
|
242
240
|
|
|
243
|
-
### Linalg, `LayoutGenerator`s
|
|
241
|
+
### Linalg, `LayoutGenerator`s & Shortest Paths
|
|
244
242
|
|
|
245
243
|
```js
|
|
246
244
|
import {
|
|
247
|
-
ChebyshevDogKernel,
|
|
248
245
|
ClassicalMds,
|
|
249
246
|
DijkstraWorkspace,
|
|
247
|
+
LaplacianKind,
|
|
250
248
|
PivotMds,
|
|
249
|
+
TargetKind,
|
|
251
250
|
classicalMds,
|
|
252
251
|
combinatorialLaplacian,
|
|
252
|
+
laplacian,
|
|
253
253
|
pivotMds,
|
|
254
254
|
} from "egraph";
|
|
255
255
|
|
|
256
256
|
const ws = new DijkstraWorkspace(graph.numNodes());
|
|
257
257
|
const dists = ws.dijkstraFrom(graph, 0);
|
|
258
258
|
const mdsNd = classicalMds(graph, 3);
|
|
259
|
-
const mds3d = new ClassicalMds({ target:
|
|
259
|
+
const mds3d = new ClassicalMds({ target: TargetKind.Layout3d }).generate(graph);
|
|
260
260
|
const mds2d = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
261
261
|
const mds2dFn = pivotMds(graph, { numPivots: 4, seed: 42 });
|
|
262
262
|
const lap = combinatorialLaplacian(graph);
|
|
263
|
-
const
|
|
264
|
-
console.log(dists.length, mdsNd.dims, mds3d.len(), mds2d.numNodes, mds2dFn.numNodes, lap.nnz,
|
|
263
|
+
const normLap = laplacian(graph, LaplacianKind.SymmetricNormalized);
|
|
264
|
+
console.log(dists.length, mdsNd.dims, mds3d.len(), mds2d.numNodes, mds2dFn.numNodes, lap.nnz, normLap.nnz);
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
-
## Migration
|
|
268
|
-
|
|
269
|
-
See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for a complete v5, `alpha.8 -> alpha.9`, and v6 API freeze migration guide, including:
|
|
267
|
+
## Migration & Literature Attribution
|
|
270
268
|
|
|
271
|
-
|
|
272
|
-
2. Migrating overlap removal and post-processing to `PrismOverlapRemoval` / `ForbidOverlapRemoval` and `LayoutTransform.apply()` (`PfsPrimeOverlapRemoval`, `TwinDeclutterer`)
|
|
273
|
-
3. Consolidating `TsNet` / `BhTsNet` / `FitTsNet` / `LTsNet` into `TsNetSolver` (`pure2Hop`, `fromGraphRowNormalized`, `auto2d`/`auto3d`/`fitFft`/`linearFft`/`barnesHut`/`exact`) and `LayoutGenerator` structs (`ClassicalMds`, `PivotMds`, `Hde`, `RdMds`, `KorenSpectral`, `CoarseBackbone`, `SfcLayout`)
|
|
274
|
-
4. Adopting `Layout3d`, `EdgePolylines` + `FdebSolver(polylines)`, separated SGD classes (`Sgd2Solver`, `PacmapGraphSolver`, `LargeVisSolver`, `DrGraphSolver`, `GraphCneSolver`, `SnapTFdpSolver`), and explicit `target` (`"layout2d" | "layout3d" | "layoutNd" | "manifold2d"`)
|
|
275
|
-
5. Migrating from `egraph/dist/web/egraph_wasm` to pure ESM, `coordsView()`, `edgeOffsetsView()`, `pointsView()`, `labelsView()`, `runProgressive`, `{ ...options }`, `camelCase` literals, `number | bigint` seeds, and `.code` structured errors
|
|
269
|
+
See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for upgrading from v5, earlier v6 prereleases, and string-based modes to typed enums, [docs/PAPER_MAPPING.md](https://github.com/likr/egraph-rs/blob/master/docs/PAPER_MAPPING.md) for the complete algorithm-to-literature mapping table, and [docs/UNIMPLEMENTED_PAPERS.md](https://github.com/likr/egraph-rs/blob/master/docs/UNIMPLEMENTED_PAPERS.md) for major graph-drawing literature not yet implemented.
|
|
276
270
|
|
|
277
271
|
## License
|
|
278
272
|
|