egraph 6.0.0-alpha.9 → 6.0.0-beta.1
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 +76 -36
- package/package.json +1 -1
- package/pkg/README.md +76 -36
- package/pkg/egraph_wasm.d.ts +1336 -1154
- package/pkg/egraph_wasm.js +13444 -8529
- package/pkg/egraph_wasm_bg.wasm +0 -0
- package/pkg/index.d.ts +1840 -1270
- package/pkg/index.js +189 -76
package/README.md
CHANGED
|
@@ -12,9 +12,10 @@ npm install egraph
|
|
|
12
12
|
|
|
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
|
-
- **Zero-Copy Linear Memory Views**: `coordsView()` on `Layout2d`, `LayoutNd`, and `ManifoldLayout2d` (plus `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
|
-
- **
|
|
17
|
-
- **
|
|
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`), explicit `target` (`"layout2d" | "layout3d" | "layoutNd" | "manifold2d"`), `step(layout)`, `runSteps(layout, k)`, `run(layout)`, and `runProgressive(solver, layout, onFrame, options?)` across `Layout2d`, `Layout3d`, `LayoutNd`, `ManifoldLayout2d`, and `EdgePolylines`.
|
|
17
|
+
- **Strict `camelCase`, `BigInt` Seeds, `.code` Errors & `f32` CSR**: Canonical `camelCase` option literals (`"barnesHut"`, `"fitFft"`, `"linearFft"`, `"ibFft"`, `"twoStepRandomWalk"`, `"hyperbolicLorentz"`), `number | bigint` 64-bit seeds, structured `Error` `.code` (`EgraphErrorCode`), and strict `weightDtype: "float32"` validation on `CsrGraph`.
|
|
18
|
+
- **Track A, Track B, Separated Solvers, 3D & Non-Euclidean Engines**: `TsNetSolver.pure2Hop({ backend: "auto2d" })` / `fromGraphRowNormalized`, `SgdSolver.sparseBarrierDog`, separated embedding classes (`Sgd2Solver`, `PacmapGraphSolver`, `LargeVisSolver`, `DrGraphSolver`, `GraphCneSolver`, `SnapTFdpSolver`), `TFdpSolver`, `IbUmapSolver`, `GuMapSolver`, `Layout3d` + `ArenaOctree3d`, `DynamicKdTree`, `EdgePolylines` + `FdebSolver(polylines)`, `ManifoldLayout2d` (`"hyperbolicLorentz"`, `toPoincareLayout`, `ManifoldMetric`, `torusSpectralPhaseInit`, `torusAutoPan`, `torusEdgeSegments`, geodesic crossings), `LayoutGenerator`s (`ClassicalMds`, `PivotMds`, `Hde`, `RdMds`, `KorenSpectral`, `CoarseBackbone`, `SfcLayout`), `LayoutTransform`s (`PfsPrimeOverlapRemoval`, `TwinDeclutterer` `.apply()`), `MetricReport` (`toRecord()`), `listDatasets` / synthetic generators, `DijkstraWorkspace`, Laplacian builders, and `ChebyshevDogKernel`.
|
|
18
19
|
|
|
19
20
|
## Quick Start (Browser / Bundler ESM)
|
|
20
21
|
|
|
@@ -36,11 +37,11 @@ const indices = new Uint32Array([1, 3, 0, 2, 1, 3, 2, 0]);
|
|
|
36
37
|
const graph = CsrGraph.fromCsr(indptr, indices);
|
|
37
38
|
|
|
38
39
|
// Initialize with normalized PivotMDS (f32 Layout2d)
|
|
39
|
-
const layout = pivotMdsInit(graph, 4, 42);
|
|
40
|
+
const layout = pivotMdsInit(graph, { numPivots: 4, seed: 42 });
|
|
40
41
|
|
|
41
42
|
// Run Track A Pure 1+2-Hop Adaptive tsNET progressively in requestAnimationFrame
|
|
42
43
|
const solver = TsNetSolver.pure2Hop(graph, {
|
|
43
|
-
backend: "
|
|
44
|
+
backend: "auto2d",
|
|
44
45
|
seed: 42,
|
|
45
46
|
});
|
|
46
47
|
|
|
@@ -69,8 +70,8 @@ import init, { CsrGraph, TFdpSolver, pivotMdsInit } from "egraph";
|
|
|
69
70
|
await init();
|
|
70
71
|
|
|
71
72
|
const graph = CsrGraph.fromEdgeList(4, new Uint32Array([0, 1, 1, 2, 2, 3, 3, 0]));
|
|
72
|
-
const layout = pivotMdsInit(graph, 4, 42);
|
|
73
|
-
const solver = new TFdpSolver(graph, { backend: "
|
|
73
|
+
const layout = pivotMdsInit(graph, { numPivots: 4, seed: 42 });
|
|
74
|
+
const solver = new TFdpSolver(graph, { backend: "ibFft", iterations: 200, seed: 42 });
|
|
74
75
|
solver.run(layout);
|
|
75
76
|
|
|
76
77
|
const xy = layout.coordsView();
|
|
@@ -83,7 +84,7 @@ console.log(Array.from(xy));
|
|
|
83
84
|
|
|
84
85
|
```js
|
|
85
86
|
const solver = TsNetSolver.pure2Hop(graph, {
|
|
86
|
-
backend: "
|
|
87
|
+
backend: "auto2d", // "auto2d", "fitFft", "linearFft", "barnesHut", "exact"
|
|
87
88
|
perplexityC: 0.9,
|
|
88
89
|
seed: 42,
|
|
89
90
|
});
|
|
@@ -91,26 +92,28 @@ solver.run(layout);
|
|
|
91
92
|
|
|
92
93
|
const rnSolver = TsNetSolver.fromGraphRowNormalizedWithOptions(graph, {
|
|
93
94
|
w2: 0.5,
|
|
94
|
-
mode: "
|
|
95
|
-
backend: "
|
|
95
|
+
mode: "twoStepRandomWalk",
|
|
96
|
+
backend: "auto2d",
|
|
96
97
|
seed: 42,
|
|
97
98
|
});
|
|
98
99
|
rnSolver.run(layout);
|
|
99
100
|
```
|
|
100
101
|
|
|
101
|
-
### Track B &
|
|
102
|
+
### Track B, Separated Embedding & Force Models
|
|
102
103
|
|
|
103
104
|
```js
|
|
104
105
|
import {
|
|
105
106
|
ForceAtlas2Solver,
|
|
106
107
|
GuMapSolver,
|
|
108
|
+
PacmapGraphSolver,
|
|
107
109
|
SgdSolver,
|
|
110
|
+
SnapTFdpSolver,
|
|
108
111
|
TFdpSolver,
|
|
109
112
|
} from "egraph";
|
|
110
113
|
|
|
111
114
|
// t-FDP with ibFFT repulsion
|
|
112
115
|
const tfdp = new TFdpSolver(graph, {
|
|
113
|
-
backend: "
|
|
116
|
+
backend: "ibFft",
|
|
114
117
|
iterations: 200,
|
|
115
118
|
seed: 42,
|
|
116
119
|
});
|
|
@@ -118,13 +121,17 @@ tfdp.run(layout);
|
|
|
118
121
|
|
|
119
122
|
// ForceAtlas2 (Barnes-Hut)
|
|
120
123
|
const fa2 = new ForceAtlas2Solver(graph, {
|
|
124
|
+
backend: "barnesHut",
|
|
121
125
|
iterations: 200,
|
|
122
|
-
useBarnesHut: true,
|
|
123
126
|
theta: 0.5,
|
|
124
127
|
seed: 42,
|
|
125
128
|
});
|
|
126
129
|
fa2.run(layout);
|
|
127
130
|
|
|
131
|
+
// PaCMAP-Graph & SNAP-tFDP (standalone separated classes)
|
|
132
|
+
new PacmapGraphSolver(graph, { phaseIterations: [20, 20, 40], seed: 42 }).run(layout);
|
|
133
|
+
new SnapTFdpSolver(graph, { iterations: 100, seed: 42 }).run(layout);
|
|
134
|
+
|
|
128
135
|
// GuMap from regularized Chebyshev DoG landmarks
|
|
129
136
|
const gumap = GuMapSolver.fromGraphDog(graph, {
|
|
130
137
|
iterations: 200,
|
|
@@ -139,27 +146,47 @@ const barrierSgd = SgdSolver.sparseBarrierDog(graph, { seed: 42 });
|
|
|
139
146
|
barrierSgd.run(layout);
|
|
140
147
|
```
|
|
141
148
|
|
|
142
|
-
###
|
|
149
|
+
### `Layout3d`, `EdgePolylines` (`FdebSolver`), `BigInt` Seeds & Non-Euclidean Manifolds
|
|
143
150
|
|
|
144
151
|
```js
|
|
145
152
|
import {
|
|
146
153
|
ArenaOctree3d,
|
|
147
|
-
|
|
154
|
+
EdgePolylines,
|
|
155
|
+
FdebSolver,
|
|
156
|
+
ForceAtlas2Solver,
|
|
157
|
+
Layout3d,
|
|
148
158
|
ManifoldLayout2d,
|
|
149
159
|
SgdSolver,
|
|
160
|
+
TsNetSolver,
|
|
150
161
|
geodesicDistortion,
|
|
151
162
|
runProgressive,
|
|
152
163
|
} from "egraph";
|
|
153
164
|
|
|
154
|
-
// 3D
|
|
155
|
-
const layout3d =
|
|
165
|
+
// 3D Layout3d with 64-bit BigInt seed, target: "layout3d", and ArenaOctree3d
|
|
166
|
+
const layout3d = Layout3d.init(graph.numNodes(), { seed: 42n });
|
|
167
|
+
new ForceAtlas2Solver(graph, {
|
|
168
|
+
target: "layout3d",
|
|
169
|
+
backend: "barnesHut",
|
|
170
|
+
iterations: 100,
|
|
171
|
+
seed: 42n,
|
|
172
|
+
}).run(layout3d);
|
|
173
|
+
|
|
156
174
|
const octree = new ArenaOctree3d();
|
|
157
175
|
octree.build(layout3d);
|
|
158
176
|
const repulsion = octree.computeCoulombRepulsion(0.5);
|
|
159
177
|
|
|
160
|
-
//
|
|
161
|
-
const
|
|
162
|
-
|
|
178
|
+
// Edge bundling via EdgePolylines + FdebSolver
|
|
179
|
+
const polylines = EdgePolylines.straightLineFromGraph(graph, layout);
|
|
180
|
+
const fdeb = new FdebSolver(polylines, { cycles: 3, stepsPerCycle: 15 });
|
|
181
|
+
fdeb.run(polylines);
|
|
182
|
+
console.log("bundled points:", polylines.edgeOffsetsView().length, polylines.pointsView().length);
|
|
183
|
+
|
|
184
|
+
// Hyperbolic Lorentz hyperboloid -> Poincaré disk + explicit target: "manifold2d"
|
|
185
|
+
const lorentz = ManifoldLayout2d.init("hyperbolicLorentz", graph.numNodes(), { seed: 42 });
|
|
186
|
+
await runProgressive(
|
|
187
|
+
SgdSolver.full(graph, { target: "manifold2d", iterations: 60, seed: 42 }),
|
|
188
|
+
lorentz,
|
|
189
|
+
);
|
|
163
190
|
const poincare = lorentz.toPoincareLayout();
|
|
164
191
|
console.log("geodesicDistortion:", geodesicDistortion(graph, poincare));
|
|
165
192
|
|
|
@@ -167,9 +194,16 @@ console.log("geodesicDistortion:", geodesicDistortion(graph, poincare));
|
|
|
167
194
|
const torus = ManifoldLayout2d.torusSpectralPhaseInit(graph, 42);
|
|
168
195
|
const panned = torus.torusAutoPan(graph);
|
|
169
196
|
console.log(panned.coordsView().length);
|
|
197
|
+
|
|
198
|
+
// Structured error codes (.code: EgraphErrorCode) on invalid (target, backend) pairs
|
|
199
|
+
try {
|
|
200
|
+
TsNetSolver.pure2Hop(graph, { target: "layout3d", backend: "fitFft" });
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error("Error code:", err.code); // "UnsupportedOperation"
|
|
203
|
+
}
|
|
170
204
|
```
|
|
171
205
|
|
|
172
|
-
### Clustering (`labelsView()`), Overlap Removal,
|
|
206
|
+
### Clustering (`labelsView()`), Overlap Removal, `LayoutTransform` & Datasets
|
|
173
207
|
|
|
174
208
|
```js
|
|
175
209
|
import {
|
|
@@ -180,16 +214,18 @@ import {
|
|
|
180
214
|
leidenCommunities,
|
|
181
215
|
listDatasets,
|
|
182
216
|
prismDistortion,
|
|
183
|
-
transitiveReduction,
|
|
184
217
|
} from "egraph";
|
|
185
218
|
|
|
186
|
-
// Synthetic SBM graph + zero-copy LeidenResult.labelsView()
|
|
187
|
-
const { graph: sbmGraph, labels: groundTruth } = generateSbmGraph(
|
|
219
|
+
// Synthetic SBM graph ({ ...options }) + zero-copy LeidenResult.labelsView()
|
|
220
|
+
const { graph: sbmGraph, labels: groundTruth } = generateSbmGraph(
|
|
221
|
+
new Uint32Array([12, 12]),
|
|
222
|
+
{ pIntra: 0.5, pInter: 0.05, seed: 42 },
|
|
223
|
+
);
|
|
188
224
|
const leiden = leidenCommunities(sbmGraph, { seed: 42 });
|
|
189
225
|
const labels = leiden.labelsView();
|
|
190
226
|
console.log("datasets:", listDatasets().length, "communities:", leiden.numCommunities, labels.length, groundTruth.length);
|
|
191
227
|
|
|
192
|
-
// Overlap removal (PRISM) + TwinDeclutterer
|
|
228
|
+
// Overlap removal (PRISM) + TwinDeclutterer LayoutTransform (.apply)
|
|
193
229
|
const original = Layout2d.fromCoords(layout.coordsView());
|
|
194
230
|
const radii = new Float32Array(graph.numNodes()).fill(0.25);
|
|
195
231
|
const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
@@ -198,18 +234,20 @@ const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
|
198
234
|
seed: 42,
|
|
199
235
|
});
|
|
200
236
|
prism.run(layout);
|
|
201
|
-
new TwinDeclutterer({ iterations: 4 }).
|
|
237
|
+
new TwinDeclutterer({ iterations: 4 }).apply(layout);
|
|
202
238
|
|
|
203
239
|
const distortion = prismDistortion(original, layout);
|
|
204
240
|
console.log(prism.lastOverlapCount, distortion.sigmaDist, distortion.sigmaDisp);
|
|
205
241
|
```
|
|
206
242
|
|
|
207
|
-
### Linalg, Chebyshev & Shortest Paths
|
|
243
|
+
### Linalg, `LayoutGenerator`s, Chebyshev & Shortest Paths
|
|
208
244
|
|
|
209
245
|
```js
|
|
210
246
|
import {
|
|
211
247
|
ChebyshevDogKernel,
|
|
248
|
+
ClassicalMds,
|
|
212
249
|
DijkstraWorkspace,
|
|
250
|
+
PivotMds,
|
|
213
251
|
classicalMds,
|
|
214
252
|
combinatorialLaplacian,
|
|
215
253
|
pivotMds,
|
|
@@ -217,22 +255,24 @@ import {
|
|
|
217
255
|
|
|
218
256
|
const ws = new DijkstraWorkspace(graph.numNodes());
|
|
219
257
|
const dists = ws.dijkstraFrom(graph, 0);
|
|
220
|
-
const
|
|
221
|
-
const
|
|
258
|
+
const mdsNd = classicalMds(graph, 3);
|
|
259
|
+
const mds3d = new ClassicalMds({ target: "layout3d" }).generate(graph);
|
|
260
|
+
const mds2d = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
261
|
+
const mds2dFn = pivotMds(graph, { numPivots: 4, seed: 42 });
|
|
222
262
|
const lap = combinatorialLaplacian(graph);
|
|
223
263
|
const dog = new ChebyshevDogKernel(graph, { seed: 42 });
|
|
224
|
-
console.log(dists.length,
|
|
264
|
+
console.log(dists.length, mdsNd.dims, mds3d.len(), mds2d.numNodes, mds2dFn.numNodes, lap.nnz, dog.degree);
|
|
225
265
|
```
|
|
226
266
|
|
|
227
267
|
## Migration from v5 / Legacy Alpha
|
|
228
268
|
|
|
229
|
-
See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for a complete v5
|
|
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:
|
|
230
270
|
|
|
231
|
-
1. Replacing `Graph` host object weights with `CsrGraph.fromCsr` / `CsrGraph.fromEdgeList` and host-side arrays
|
|
232
|
-
2. Migrating
|
|
233
|
-
3. Consolidating `TsNet` / `BhTsNet` / `FitTsNet` / `LTsNet` into `TsNetSolver` (`pure2Hop`, `fromGraphRowNormalized`, `
|
|
234
|
-
4.
|
|
235
|
-
5. Migrating from `egraph/dist/web/egraph_wasm` to pure ESM, `coordsView()`, `
|
|
271
|
+
1. Replacing `Graph` host object weights with `CsrGraph.fromCsr` / `CsrGraph.fromEdgeList` (`weightDtype: "float32"`) and host-side arrays
|
|
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
|
|
236
276
|
|
|
237
277
|
## License
|
|
238
278
|
|
package/package.json
CHANGED
package/pkg/README.md
CHANGED
|
@@ -12,9 +12,10 @@ npm install egraph
|
|
|
12
12
|
|
|
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
|
-
- **Zero-Copy Linear Memory Views**: `coordsView()` on `Layout2d`, `LayoutNd`, and `ManifoldLayout2d` (plus `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
|
-
- **
|
|
17
|
-
- **
|
|
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`), explicit `target` (`"layout2d" | "layout3d" | "layoutNd" | "manifold2d"`), `step(layout)`, `runSteps(layout, k)`, `run(layout)`, and `runProgressive(solver, layout, onFrame, options?)` across `Layout2d`, `Layout3d`, `LayoutNd`, `ManifoldLayout2d`, and `EdgePolylines`.
|
|
17
|
+
- **Strict `camelCase`, `BigInt` Seeds, `.code` Errors & `f32` CSR**: Canonical `camelCase` option literals (`"barnesHut"`, `"fitFft"`, `"linearFft"`, `"ibFft"`, `"twoStepRandomWalk"`, `"hyperbolicLorentz"`), `number | bigint` 64-bit seeds, structured `Error` `.code` (`EgraphErrorCode`), and strict `weightDtype: "float32"` validation on `CsrGraph`.
|
|
18
|
+
- **Track A, Track B, Separated Solvers, 3D & Non-Euclidean Engines**: `TsNetSolver.pure2Hop({ backend: "auto2d" })` / `fromGraphRowNormalized`, `SgdSolver.sparseBarrierDog`, separated embedding classes (`Sgd2Solver`, `PacmapGraphSolver`, `LargeVisSolver`, `DrGraphSolver`, `GraphCneSolver`, `SnapTFdpSolver`), `TFdpSolver`, `IbUmapSolver`, `GuMapSolver`, `Layout3d` + `ArenaOctree3d`, `DynamicKdTree`, `EdgePolylines` + `FdebSolver(polylines)`, `ManifoldLayout2d` (`"hyperbolicLorentz"`, `toPoincareLayout`, `ManifoldMetric`, `torusSpectralPhaseInit`, `torusAutoPan`, `torusEdgeSegments`, geodesic crossings), `LayoutGenerator`s (`ClassicalMds`, `PivotMds`, `Hde`, `RdMds`, `KorenSpectral`, `CoarseBackbone`, `SfcLayout`), `LayoutTransform`s (`PfsPrimeOverlapRemoval`, `TwinDeclutterer` `.apply()`), `MetricReport` (`toRecord()`), `listDatasets` / synthetic generators, `DijkstraWorkspace`, Laplacian builders, and `ChebyshevDogKernel`.
|
|
18
19
|
|
|
19
20
|
## Quick Start (Browser / Bundler ESM)
|
|
20
21
|
|
|
@@ -36,11 +37,11 @@ const indices = new Uint32Array([1, 3, 0, 2, 1, 3, 2, 0]);
|
|
|
36
37
|
const graph = CsrGraph.fromCsr(indptr, indices);
|
|
37
38
|
|
|
38
39
|
// Initialize with normalized PivotMDS (f32 Layout2d)
|
|
39
|
-
const layout = pivotMdsInit(graph, 4, 42);
|
|
40
|
+
const layout = pivotMdsInit(graph, { numPivots: 4, seed: 42 });
|
|
40
41
|
|
|
41
42
|
// Run Track A Pure 1+2-Hop Adaptive tsNET progressively in requestAnimationFrame
|
|
42
43
|
const solver = TsNetSolver.pure2Hop(graph, {
|
|
43
|
-
backend: "
|
|
44
|
+
backend: "auto2d",
|
|
44
45
|
seed: 42,
|
|
45
46
|
});
|
|
46
47
|
|
|
@@ -69,8 +70,8 @@ import init, { CsrGraph, TFdpSolver, pivotMdsInit } from "egraph";
|
|
|
69
70
|
await init();
|
|
70
71
|
|
|
71
72
|
const graph = CsrGraph.fromEdgeList(4, new Uint32Array([0, 1, 1, 2, 2, 3, 3, 0]));
|
|
72
|
-
const layout = pivotMdsInit(graph, 4, 42);
|
|
73
|
-
const solver = new TFdpSolver(graph, { backend: "
|
|
73
|
+
const layout = pivotMdsInit(graph, { numPivots: 4, seed: 42 });
|
|
74
|
+
const solver = new TFdpSolver(graph, { backend: "ibFft", iterations: 200, seed: 42 });
|
|
74
75
|
solver.run(layout);
|
|
75
76
|
|
|
76
77
|
const xy = layout.coordsView();
|
|
@@ -83,7 +84,7 @@ console.log(Array.from(xy));
|
|
|
83
84
|
|
|
84
85
|
```js
|
|
85
86
|
const solver = TsNetSolver.pure2Hop(graph, {
|
|
86
|
-
backend: "
|
|
87
|
+
backend: "auto2d", // "auto2d", "fitFft", "linearFft", "barnesHut", "exact"
|
|
87
88
|
perplexityC: 0.9,
|
|
88
89
|
seed: 42,
|
|
89
90
|
});
|
|
@@ -91,26 +92,28 @@ solver.run(layout);
|
|
|
91
92
|
|
|
92
93
|
const rnSolver = TsNetSolver.fromGraphRowNormalizedWithOptions(graph, {
|
|
93
94
|
w2: 0.5,
|
|
94
|
-
mode: "
|
|
95
|
-
backend: "
|
|
95
|
+
mode: "twoStepRandomWalk",
|
|
96
|
+
backend: "auto2d",
|
|
96
97
|
seed: 42,
|
|
97
98
|
});
|
|
98
99
|
rnSolver.run(layout);
|
|
99
100
|
```
|
|
100
101
|
|
|
101
|
-
### Track B &
|
|
102
|
+
### Track B, Separated Embedding & Force Models
|
|
102
103
|
|
|
103
104
|
```js
|
|
104
105
|
import {
|
|
105
106
|
ForceAtlas2Solver,
|
|
106
107
|
GuMapSolver,
|
|
108
|
+
PacmapGraphSolver,
|
|
107
109
|
SgdSolver,
|
|
110
|
+
SnapTFdpSolver,
|
|
108
111
|
TFdpSolver,
|
|
109
112
|
} from "egraph";
|
|
110
113
|
|
|
111
114
|
// t-FDP with ibFFT repulsion
|
|
112
115
|
const tfdp = new TFdpSolver(graph, {
|
|
113
|
-
backend: "
|
|
116
|
+
backend: "ibFft",
|
|
114
117
|
iterations: 200,
|
|
115
118
|
seed: 42,
|
|
116
119
|
});
|
|
@@ -118,13 +121,17 @@ tfdp.run(layout);
|
|
|
118
121
|
|
|
119
122
|
// ForceAtlas2 (Barnes-Hut)
|
|
120
123
|
const fa2 = new ForceAtlas2Solver(graph, {
|
|
124
|
+
backend: "barnesHut",
|
|
121
125
|
iterations: 200,
|
|
122
|
-
useBarnesHut: true,
|
|
123
126
|
theta: 0.5,
|
|
124
127
|
seed: 42,
|
|
125
128
|
});
|
|
126
129
|
fa2.run(layout);
|
|
127
130
|
|
|
131
|
+
// PaCMAP-Graph & SNAP-tFDP (standalone separated classes)
|
|
132
|
+
new PacmapGraphSolver(graph, { phaseIterations: [20, 20, 40], seed: 42 }).run(layout);
|
|
133
|
+
new SnapTFdpSolver(graph, { iterations: 100, seed: 42 }).run(layout);
|
|
134
|
+
|
|
128
135
|
// GuMap from regularized Chebyshev DoG landmarks
|
|
129
136
|
const gumap = GuMapSolver.fromGraphDog(graph, {
|
|
130
137
|
iterations: 200,
|
|
@@ -139,27 +146,47 @@ const barrierSgd = SgdSolver.sparseBarrierDog(graph, { seed: 42 });
|
|
|
139
146
|
barrierSgd.run(layout);
|
|
140
147
|
```
|
|
141
148
|
|
|
142
|
-
###
|
|
149
|
+
### `Layout3d`, `EdgePolylines` (`FdebSolver`), `BigInt` Seeds & Non-Euclidean Manifolds
|
|
143
150
|
|
|
144
151
|
```js
|
|
145
152
|
import {
|
|
146
153
|
ArenaOctree3d,
|
|
147
|
-
|
|
154
|
+
EdgePolylines,
|
|
155
|
+
FdebSolver,
|
|
156
|
+
ForceAtlas2Solver,
|
|
157
|
+
Layout3d,
|
|
148
158
|
ManifoldLayout2d,
|
|
149
159
|
SgdSolver,
|
|
160
|
+
TsNetSolver,
|
|
150
161
|
geodesicDistortion,
|
|
151
162
|
runProgressive,
|
|
152
163
|
} from "egraph";
|
|
153
164
|
|
|
154
|
-
// 3D
|
|
155
|
-
const layout3d =
|
|
165
|
+
// 3D Layout3d with 64-bit BigInt seed, target: "layout3d", and ArenaOctree3d
|
|
166
|
+
const layout3d = Layout3d.init(graph.numNodes(), { seed: 42n });
|
|
167
|
+
new ForceAtlas2Solver(graph, {
|
|
168
|
+
target: "layout3d",
|
|
169
|
+
backend: "barnesHut",
|
|
170
|
+
iterations: 100,
|
|
171
|
+
seed: 42n,
|
|
172
|
+
}).run(layout3d);
|
|
173
|
+
|
|
156
174
|
const octree = new ArenaOctree3d();
|
|
157
175
|
octree.build(layout3d);
|
|
158
176
|
const repulsion = octree.computeCoulombRepulsion(0.5);
|
|
159
177
|
|
|
160
|
-
//
|
|
161
|
-
const
|
|
162
|
-
|
|
178
|
+
// Edge bundling via EdgePolylines + FdebSolver
|
|
179
|
+
const polylines = EdgePolylines.straightLineFromGraph(graph, layout);
|
|
180
|
+
const fdeb = new FdebSolver(polylines, { cycles: 3, stepsPerCycle: 15 });
|
|
181
|
+
fdeb.run(polylines);
|
|
182
|
+
console.log("bundled points:", polylines.edgeOffsetsView().length, polylines.pointsView().length);
|
|
183
|
+
|
|
184
|
+
// Hyperbolic Lorentz hyperboloid -> Poincaré disk + explicit target: "manifold2d"
|
|
185
|
+
const lorentz = ManifoldLayout2d.init("hyperbolicLorentz", graph.numNodes(), { seed: 42 });
|
|
186
|
+
await runProgressive(
|
|
187
|
+
SgdSolver.full(graph, { target: "manifold2d", iterations: 60, seed: 42 }),
|
|
188
|
+
lorentz,
|
|
189
|
+
);
|
|
163
190
|
const poincare = lorentz.toPoincareLayout();
|
|
164
191
|
console.log("geodesicDistortion:", geodesicDistortion(graph, poincare));
|
|
165
192
|
|
|
@@ -167,9 +194,16 @@ console.log("geodesicDistortion:", geodesicDistortion(graph, poincare));
|
|
|
167
194
|
const torus = ManifoldLayout2d.torusSpectralPhaseInit(graph, 42);
|
|
168
195
|
const panned = torus.torusAutoPan(graph);
|
|
169
196
|
console.log(panned.coordsView().length);
|
|
197
|
+
|
|
198
|
+
// Structured error codes (.code: EgraphErrorCode) on invalid (target, backend) pairs
|
|
199
|
+
try {
|
|
200
|
+
TsNetSolver.pure2Hop(graph, { target: "layout3d", backend: "fitFft" });
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error("Error code:", err.code); // "UnsupportedOperation"
|
|
203
|
+
}
|
|
170
204
|
```
|
|
171
205
|
|
|
172
|
-
### Clustering (`labelsView()`), Overlap Removal,
|
|
206
|
+
### Clustering (`labelsView()`), Overlap Removal, `LayoutTransform` & Datasets
|
|
173
207
|
|
|
174
208
|
```js
|
|
175
209
|
import {
|
|
@@ -180,16 +214,18 @@ import {
|
|
|
180
214
|
leidenCommunities,
|
|
181
215
|
listDatasets,
|
|
182
216
|
prismDistortion,
|
|
183
|
-
transitiveReduction,
|
|
184
217
|
} from "egraph";
|
|
185
218
|
|
|
186
|
-
// Synthetic SBM graph + zero-copy LeidenResult.labelsView()
|
|
187
|
-
const { graph: sbmGraph, labels: groundTruth } = generateSbmGraph(
|
|
219
|
+
// Synthetic SBM graph ({ ...options }) + zero-copy LeidenResult.labelsView()
|
|
220
|
+
const { graph: sbmGraph, labels: groundTruth } = generateSbmGraph(
|
|
221
|
+
new Uint32Array([12, 12]),
|
|
222
|
+
{ pIntra: 0.5, pInter: 0.05, seed: 42 },
|
|
223
|
+
);
|
|
188
224
|
const leiden = leidenCommunities(sbmGraph, { seed: 42 });
|
|
189
225
|
const labels = leiden.labelsView();
|
|
190
226
|
console.log("datasets:", listDatasets().length, "communities:", leiden.numCommunities, labels.length, groundTruth.length);
|
|
191
227
|
|
|
192
|
-
// Overlap removal (PRISM) + TwinDeclutterer
|
|
228
|
+
// Overlap removal (PRISM) + TwinDeclutterer LayoutTransform (.apply)
|
|
193
229
|
const original = Layout2d.fromCoords(layout.coordsView());
|
|
194
230
|
const radii = new Float32Array(graph.numNodes()).fill(0.25);
|
|
195
231
|
const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
@@ -198,18 +234,20 @@ const prism = PrismOverlapRemoval.fromRadii(radii, {
|
|
|
198
234
|
seed: 42,
|
|
199
235
|
});
|
|
200
236
|
prism.run(layout);
|
|
201
|
-
new TwinDeclutterer({ iterations: 4 }).
|
|
237
|
+
new TwinDeclutterer({ iterations: 4 }).apply(layout);
|
|
202
238
|
|
|
203
239
|
const distortion = prismDistortion(original, layout);
|
|
204
240
|
console.log(prism.lastOverlapCount, distortion.sigmaDist, distortion.sigmaDisp);
|
|
205
241
|
```
|
|
206
242
|
|
|
207
|
-
### Linalg, Chebyshev & Shortest Paths
|
|
243
|
+
### Linalg, `LayoutGenerator`s, Chebyshev & Shortest Paths
|
|
208
244
|
|
|
209
245
|
```js
|
|
210
246
|
import {
|
|
211
247
|
ChebyshevDogKernel,
|
|
248
|
+
ClassicalMds,
|
|
212
249
|
DijkstraWorkspace,
|
|
250
|
+
PivotMds,
|
|
213
251
|
classicalMds,
|
|
214
252
|
combinatorialLaplacian,
|
|
215
253
|
pivotMds,
|
|
@@ -217,22 +255,24 @@ import {
|
|
|
217
255
|
|
|
218
256
|
const ws = new DijkstraWorkspace(graph.numNodes());
|
|
219
257
|
const dists = ws.dijkstraFrom(graph, 0);
|
|
220
|
-
const
|
|
221
|
-
const
|
|
258
|
+
const mdsNd = classicalMds(graph, 3);
|
|
259
|
+
const mds3d = new ClassicalMds({ target: "layout3d" }).generate(graph);
|
|
260
|
+
const mds2d = new PivotMds({ numPivots: 4, seed: 42 }).generate(graph);
|
|
261
|
+
const mds2dFn = pivotMds(graph, { numPivots: 4, seed: 42 });
|
|
222
262
|
const lap = combinatorialLaplacian(graph);
|
|
223
263
|
const dog = new ChebyshevDogKernel(graph, { seed: 42 });
|
|
224
|
-
console.log(dists.length,
|
|
264
|
+
console.log(dists.length, mdsNd.dims, mds3d.len(), mds2d.numNodes, mds2dFn.numNodes, lap.nnz, dog.degree);
|
|
225
265
|
```
|
|
226
266
|
|
|
227
267
|
## Migration from v5 / Legacy Alpha
|
|
228
268
|
|
|
229
|
-
See [docs/MIGRATION_V6.md](https://github.com/likr/egraph-rs/blob/master/docs/MIGRATION_V6.md) for a complete v5
|
|
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:
|
|
230
270
|
|
|
231
|
-
1. Replacing `Graph` host object weights with `CsrGraph.fromCsr` / `CsrGraph.fromEdgeList` and host-side arrays
|
|
232
|
-
2. Migrating
|
|
233
|
-
3. Consolidating `TsNet` / `BhTsNet` / `FitTsNet` / `LTsNet` into `TsNetSolver` (`pure2Hop`, `fromGraphRowNormalized`, `
|
|
234
|
-
4.
|
|
235
|
-
5. Migrating from `egraph/dist/web/egraph_wasm` to pure ESM, `coordsView()`, `
|
|
271
|
+
1. Replacing `Graph` host object weights with `CsrGraph.fromCsr` / `CsrGraph.fromEdgeList` (`weightDtype: "float32"`) and host-side arrays
|
|
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
|
|
236
276
|
|
|
237
277
|
## License
|
|
238
278
|
|