@graphty/algorithms 2.1.2 → 2.2.0

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.
Files changed (355) hide show
  1. package/README.md +139 -50
  2. package/dist/algorithms.js +15260 -10390
  3. package/dist/algorithms.js.map +1 -1
  4. package/dist/algorithms.standalone.js +26675 -21542
  5. package/dist/algorithms.standalone.js.map +1 -1
  6. package/dist/src/algorithms/centrality/betweenness.d.ts +18 -0
  7. package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
  8. package/dist/src/algorithms/centrality/betweenness.js +40 -1
  9. package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
  10. package/dist/src/algorithms/centrality/closeness.d.ts +20 -0
  11. package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
  12. package/dist/src/algorithms/centrality/closeness.js +93 -8
  13. package/dist/src/algorithms/centrality/closeness.js.map +1 -1
  14. package/dist/src/algorithms/centrality/degree.d.ts +9 -0
  15. package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
  16. package/dist/src/algorithms/centrality/degree.js +18 -0
  17. package/dist/src/algorithms/centrality/degree.js.map +1 -1
  18. package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -0
  19. package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
  20. package/dist/src/algorithms/centrality/eigenvector.js +29 -0
  21. package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
  22. package/dist/src/algorithms/centrality/hits.d.ts +9 -0
  23. package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
  24. package/dist/src/algorithms/centrality/hits.js +23 -0
  25. package/dist/src/algorithms/centrality/hits.js.map +1 -1
  26. package/dist/src/algorithms/centrality/katz.d.ts +9 -0
  27. package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
  28. package/dist/src/algorithms/centrality/katz.js +31 -0
  29. package/dist/src/algorithms/centrality/katz.js.map +1 -1
  30. package/dist/src/algorithms/centrality/pagerank.d.ts +13 -13
  31. package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
  32. package/dist/src/algorithms/centrality/pagerank.js +47 -10
  33. package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
  34. package/dist/src/algorithms/community/girvan-newman-legacy.d.ts +27 -0
  35. package/dist/src/algorithms/community/girvan-newman-legacy.d.ts.map +1 -0
  36. package/dist/src/algorithms/community/girvan-newman-legacy.js +335 -0
  37. package/dist/src/algorithms/community/girvan-newman-legacy.js.map +1 -0
  38. package/dist/src/algorithms/community/girvan-newman.d.ts +5 -3
  39. package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
  40. package/dist/src/algorithms/community/girvan-newman.js +34 -308
  41. package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
  42. package/dist/src/algorithms/community/label-propagation.d.ts +9 -6
  43. package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
  44. package/dist/src/algorithms/community/label-propagation.js +24 -110
  45. package/dist/src/algorithms/community/label-propagation.js.map +1 -1
  46. package/dist/src/algorithms/components/connected.d.ts.map +1 -1
  47. package/dist/src/algorithms/components/connected.js +28 -77
  48. package/dist/src/algorithms/components/connected.js.map +1 -1
  49. package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
  50. package/dist/src/algorithms/mst/kruskal.js +59 -3
  51. package/dist/src/algorithms/mst/kruskal.js.map +1 -1
  52. package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
  53. package/dist/src/algorithms/shortest-path/bellman-ford.js +46 -0
  54. package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
  55. package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
  56. package/dist/src/algorithms/shortest-path/dijkstra.js +27 -0
  57. package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
  58. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +15 -5
  59. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
  60. package/dist/src/algorithms/shortest-path/floyd-warshall.js +97 -107
  61. package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
  62. package/dist/src/algorithms/traversal/bfs-unified.d.ts +2 -12
  63. package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -1
  64. package/dist/src/algorithms/traversal/bfs-unified.js +47 -308
  65. package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -1
  66. package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -1
  67. package/dist/src/algorithms/traversal/bfs-variants.js +5 -25
  68. package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -1
  69. package/dist/src/algorithms/traversal/bfs.d.ts +0 -3
  70. package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
  71. package/dist/src/algorithms/traversal/bfs.js +0 -4
  72. package/dist/src/algorithms/traversal/bfs.js.map +1 -1
  73. package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
  74. package/dist/src/algorithms/traversal/dfs.js +33 -154
  75. package/dist/src/algorithms/traversal/dfs.js.map +1 -1
  76. package/dist/src/clustering/hierarchical-legacy.d.ts +56 -0
  77. package/dist/src/clustering/hierarchical-legacy.d.ts.map +1 -0
  78. package/dist/src/clustering/hierarchical-legacy.js +441 -0
  79. package/dist/src/clustering/hierarchical-legacy.js.map +1 -0
  80. package/dist/src/clustering/hierarchical.d.ts +7 -39
  81. package/dist/src/clustering/hierarchical.d.ts.map +1 -1
  82. package/dist/src/clustering/hierarchical.js +56 -417
  83. package/dist/src/clustering/hierarchical.js.map +1 -1
  84. package/dist/src/clustering/k-core-legacy.d.ts +30 -0
  85. package/dist/src/clustering/k-core-legacy.d.ts.map +1 -0
  86. package/dist/src/clustering/k-core-legacy.js +191 -0
  87. package/dist/src/clustering/k-core-legacy.js.map +1 -0
  88. package/dist/src/clustering/k-core.d.ts +8 -7
  89. package/dist/src/clustering/k-core.d.ts.map +1 -1
  90. package/dist/src/clustering/k-core.js +33 -174
  91. package/dist/src/clustering/k-core.js.map +1 -1
  92. package/dist/src/clustering/mcl-legacy.d.ts +42 -0
  93. package/dist/src/clustering/mcl-legacy.d.ts.map +1 -0
  94. package/dist/src/clustering/mcl-legacy.js +386 -0
  95. package/dist/src/clustering/mcl-legacy.js.map +1 -0
  96. package/dist/src/clustering/mcl.d.ts +9 -32
  97. package/dist/src/clustering/mcl.d.ts.map +1 -1
  98. package/dist/src/clustering/mcl.js +48 -374
  99. package/dist/src/clustering/mcl.js.map +1 -1
  100. package/dist/src/index.d.ts +29 -3
  101. package/dist/src/index.d.ts.map +1 -1
  102. package/dist/src/index.js +2 -1
  103. package/dist/src/index.js.map +1 -1
  104. package/dist/src/indexed/accelerator.d.ts +141 -11
  105. package/dist/src/indexed/accelerator.d.ts.map +1 -1
  106. package/dist/src/indexed/accelerator.js +319 -5
  107. package/dist/src/indexed/accelerator.js.map +1 -1
  108. package/dist/src/indexed/all-pairs.d.ts +59 -0
  109. package/dist/src/indexed/all-pairs.d.ts.map +1 -0
  110. package/dist/src/indexed/all-pairs.js +274 -0
  111. package/dist/src/indexed/all-pairs.js.map +1 -0
  112. package/dist/src/indexed/bellman-ford.d.ts +25 -0
  113. package/dist/src/indexed/bellman-ford.d.ts.map +1 -0
  114. package/dist/src/indexed/bellman-ford.js +59 -0
  115. package/dist/src/indexed/bellman-ford.js.map +1 -0
  116. package/dist/src/indexed/betweenness.d.ts +85 -0
  117. package/dist/src/indexed/betweenness.d.ts.map +1 -0
  118. package/dist/src/indexed/betweenness.js +188 -0
  119. package/dist/src/indexed/betweenness.js.map +1 -0
  120. package/dist/src/indexed/bfs.d.ts +69 -2
  121. package/dist/src/indexed/bfs.d.ts.map +1 -1
  122. package/dist/src/indexed/bfs.js +148 -1
  123. package/dist/src/indexed/bfs.js.map +1 -1
  124. package/dist/src/indexed/bipartite.d.ts +37 -0
  125. package/dist/src/indexed/bipartite.d.ts.map +1 -0
  126. package/dist/src/indexed/bipartite.js +54 -0
  127. package/dist/src/indexed/bipartite.js.map +1 -0
  128. package/dist/src/indexed/closeness.d.ts +49 -0
  129. package/dist/src/indexed/closeness.d.ts.map +1 -0
  130. package/dist/src/indexed/closeness.js +127 -0
  131. package/dist/src/indexed/closeness.js.map +1 -0
  132. package/dist/src/indexed/common-neighbors.d.ts +14 -1
  133. package/dist/src/indexed/common-neighbors.d.ts.map +1 -1
  134. package/dist/src/indexed/common-neighbors.js +24 -14
  135. package/dist/src/indexed/common-neighbors.js.map +1 -1
  136. package/dist/src/indexed/degree.d.ts +19 -0
  137. package/dist/src/indexed/degree.d.ts.map +1 -0
  138. package/dist/src/indexed/degree.js +45 -0
  139. package/dist/src/indexed/degree.js.map +1 -0
  140. package/dist/src/indexed/delta-pagerank.d.ts +145 -0
  141. package/dist/src/indexed/delta-pagerank.d.ts.map +1 -0
  142. package/dist/src/indexed/delta-pagerank.js +428 -0
  143. package/dist/src/indexed/delta-pagerank.js.map +1 -0
  144. package/dist/src/indexed/dfs.d.ts +55 -0
  145. package/dist/src/indexed/dfs.d.ts.map +1 -0
  146. package/dist/src/indexed/dfs.js +146 -0
  147. package/dist/src/indexed/dfs.js.map +1 -0
  148. package/dist/src/indexed/eigenvector.d.ts +48 -0
  149. package/dist/src/indexed/eigenvector.d.ts.map +1 -0
  150. package/dist/src/indexed/eigenvector.js +162 -0
  151. package/dist/src/indexed/eigenvector.js.map +1 -0
  152. package/dist/src/indexed/facade.d.ts +109 -0
  153. package/dist/src/indexed/facade.d.ts.map +1 -0
  154. package/dist/src/indexed/facade.js +204 -0
  155. package/dist/src/indexed/facade.js.map +1 -0
  156. package/dist/src/indexed/flow.d.ts +120 -0
  157. package/dist/src/indexed/flow.d.ts.map +1 -0
  158. package/dist/src/indexed/flow.js +377 -0
  159. package/dist/src/indexed/flow.js.map +1 -0
  160. package/dist/src/indexed/girvan-newman.d.ts +42 -0
  161. package/dist/src/indexed/girvan-newman.d.ts.map +1 -0
  162. package/dist/src/indexed/girvan-newman.js +90 -0
  163. package/dist/src/indexed/girvan-newman.js.map +1 -0
  164. package/dist/src/indexed/grsbm.d.ts +85 -0
  165. package/dist/src/indexed/grsbm.d.ts.map +1 -0
  166. package/dist/src/indexed/grsbm.js +287 -0
  167. package/dist/src/indexed/grsbm.js.map +1 -0
  168. package/dist/src/indexed/hierarchical.d.ts +69 -0
  169. package/dist/src/indexed/hierarchical.d.ts.map +1 -0
  170. package/dist/src/indexed/hierarchical.js +245 -0
  171. package/dist/src/indexed/hierarchical.js.map +1 -0
  172. package/dist/src/indexed/index.d.ts +29 -3
  173. package/dist/src/indexed/index.d.ts.map +1 -1
  174. package/dist/src/indexed/index.js +29 -3
  175. package/dist/src/indexed/index.js.map +1 -1
  176. package/dist/src/indexed/isomorphism.d.ts +42 -0
  177. package/dist/src/indexed/isomorphism.d.ts.map +1 -0
  178. package/dist/src/indexed/isomorphism.js +269 -0
  179. package/dist/src/indexed/isomorphism.js.map +1 -0
  180. package/dist/src/indexed/label-propagation.d.ts +134 -0
  181. package/dist/src/indexed/label-propagation.d.ts.map +1 -0
  182. package/dist/src/indexed/label-propagation.js +486 -0
  183. package/dist/src/indexed/label-propagation.js.map +1 -0
  184. package/dist/src/indexed/leiden.d.ts +52 -0
  185. package/dist/src/indexed/leiden.d.ts.map +1 -0
  186. package/dist/src/indexed/leiden.js +384 -0
  187. package/dist/src/indexed/leiden.js.map +1 -0
  188. package/dist/src/indexed/link-prediction.d.ts +147 -0
  189. package/dist/src/indexed/link-prediction.d.ts.map +1 -0
  190. package/dist/src/indexed/link-prediction.js +317 -0
  191. package/dist/src/indexed/link-prediction.js.map +1 -0
  192. package/dist/src/indexed/markov.d.ts +54 -0
  193. package/dist/src/indexed/markov.d.ts.map +1 -0
  194. package/dist/src/indexed/markov.js +284 -0
  195. package/dist/src/indexed/markov.js.map +1 -0
  196. package/dist/src/indexed/matching.d.ts +53 -0
  197. package/dist/src/indexed/matching.d.ts.map +1 -0
  198. package/dist/src/indexed/matching.js +139 -0
  199. package/dist/src/indexed/matching.js.map +1 -0
  200. package/dist/src/indexed/min-cut.d.ts +48 -0
  201. package/dist/src/indexed/min-cut.d.ts.map +1 -0
  202. package/dist/src/indexed/min-cut.js +175 -0
  203. package/dist/src/indexed/min-cut.js.map +1 -0
  204. package/dist/src/indexed/modularity.d.ts +34 -0
  205. package/dist/src/indexed/modularity.d.ts.map +1 -0
  206. package/dist/src/indexed/modularity.js +74 -0
  207. package/dist/src/indexed/modularity.js.map +1 -0
  208. package/dist/src/indexed/mst.d.ts +29 -1
  209. package/dist/src/indexed/mst.d.ts.map +1 -1
  210. package/dist/src/indexed/mst.js +62 -0
  211. package/dist/src/indexed/mst.js.map +1 -1
  212. package/dist/src/indexed/pagerank.d.ts +29 -6
  213. package/dist/src/indexed/pagerank.d.ts.map +1 -1
  214. package/dist/src/indexed/pagerank.js +107 -11
  215. package/dist/src/indexed/pagerank.js.map +1 -1
  216. package/dist/src/indexed/point-to-point.d.ts +53 -0
  217. package/dist/src/indexed/point-to-point.d.ts.map +1 -0
  218. package/dist/src/indexed/point-to-point.js +173 -0
  219. package/dist/src/indexed/point-to-point.js.map +1 -0
  220. package/dist/src/indexed/scc.d.ts +53 -0
  221. package/dist/src/indexed/scc.d.ts.map +1 -0
  222. package/dist/src/indexed/scc.js +110 -0
  223. package/dist/src/indexed/scc.js.map +1 -0
  224. package/dist/src/indexed/spectral.d.ts +61 -0
  225. package/dist/src/indexed/spectral.d.ts.map +1 -0
  226. package/dist/src/indexed/spectral.js +476 -0
  227. package/dist/src/indexed/spectral.js.map +1 -0
  228. package/dist/src/indexed/structures/bit-set.d.ts +45 -0
  229. package/dist/src/indexed/structures/bit-set.d.ts.map +1 -0
  230. package/dist/src/indexed/structures/bit-set.js +57 -0
  231. package/dist/src/indexed/structures/bit-set.js.map +1 -0
  232. package/dist/src/indexed/structures/max-heap.d.ts +52 -0
  233. package/dist/src/indexed/structures/max-heap.d.ts.map +1 -0
  234. package/dist/src/indexed/structures/max-heap.js +66 -0
  235. package/dist/src/indexed/structures/max-heap.js.map +1 -0
  236. package/dist/src/indexed/structures/min-heap.d.ts +30 -1
  237. package/dist/src/indexed/structures/min-heap.d.ts.map +1 -1
  238. package/dist/src/indexed/structures/min-heap.js +46 -6
  239. package/dist/src/indexed/structures/min-heap.js.map +1 -1
  240. package/dist/src/indexed/structures/ring-queue.d.ts +41 -0
  241. package/dist/src/indexed/structures/ring-queue.d.ts.map +1 -0
  242. package/dist/src/indexed/structures/ring-queue.js +64 -0
  243. package/dist/src/indexed/structures/ring-queue.js.map +1 -0
  244. package/dist/src/indexed/sync.d.ts +50 -0
  245. package/dist/src/indexed/sync.d.ts.map +1 -0
  246. package/dist/src/indexed/sync.js +175 -0
  247. package/dist/src/indexed/sync.js.map +1 -0
  248. package/dist/src/indexed/terahac.d.ts +58 -0
  249. package/dist/src/indexed/terahac.d.ts.map +1 -0
  250. package/dist/src/indexed/terahac.js +244 -0
  251. package/dist/src/indexed/terahac.js.map +1 -0
  252. package/dist/src/indexed/to-snapshot.d.ts +45 -2
  253. package/dist/src/indexed/to-snapshot.d.ts.map +1 -1
  254. package/dist/src/indexed/to-snapshot.js +140 -6
  255. package/dist/src/indexed/to-snapshot.js.map +1 -1
  256. package/dist/src/link-prediction/common-neighbors-legacy.d.ts +71 -0
  257. package/dist/src/link-prediction/common-neighbors-legacy.d.ts.map +1 -0
  258. package/dist/src/link-prediction/common-neighbors-legacy.js +172 -0
  259. package/dist/src/link-prediction/common-neighbors-legacy.js.map +1 -0
  260. package/dist/src/link-prediction/common-neighbors.d.ts +11 -19
  261. package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
  262. package/dist/src/link-prediction/common-neighbors.js +56 -123
  263. package/dist/src/link-prediction/common-neighbors.js.map +1 -1
  264. package/dist/src/optimized/direction-optimized-bfs.d.ts +6 -0
  265. package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -1
  266. package/dist/src/optimized/direction-optimized-bfs.js +6 -0
  267. package/dist/src/optimized/direction-optimized-bfs.js.map +1 -1
  268. package/dist/src/research/grsbm-legacy.d.ts +82 -0
  269. package/dist/src/research/grsbm-legacy.d.ts.map +1 -0
  270. package/dist/src/research/grsbm-legacy.js +416 -0
  271. package/dist/src/research/grsbm-legacy.js.map +1 -0
  272. package/dist/src/research/grsbm.d.ts +9 -66
  273. package/dist/src/research/grsbm.d.ts.map +1 -1
  274. package/dist/src/research/grsbm.js +67 -391
  275. package/dist/src/research/grsbm.js.map +1 -1
  276. package/dist/src/research/sync-legacy.d.ts +48 -0
  277. package/dist/src/research/sync-legacy.d.ts.map +1 -0
  278. package/dist/src/research/sync-legacy.js +337 -0
  279. package/dist/src/research/sync-legacy.js.map +1 -0
  280. package/dist/src/research/sync.d.ts +10 -32
  281. package/dist/src/research/sync.d.ts.map +1 -1
  282. package/dist/src/research/sync.js +28 -316
  283. package/dist/src/research/sync.js.map +1 -1
  284. package/package.json +4 -3
  285. package/src/algorithms/centrality/betweenness.ts +51 -1
  286. package/src/algorithms/centrality/closeness.ts +112 -12
  287. package/src/algorithms/centrality/degree.ts +19 -0
  288. package/src/algorithms/centrality/eigenvector.ts +34 -0
  289. package/src/algorithms/centrality/hits.ts +24 -0
  290. package/src/algorithms/centrality/katz.ts +32 -0
  291. package/src/algorithms/centrality/pagerank.ts +53 -13
  292. package/src/algorithms/community/girvan-newman-legacy.ts +414 -0
  293. package/src/algorithms/community/girvan-newman.ts +36 -386
  294. package/src/algorithms/community/label-propagation.ts +24 -133
  295. package/src/algorithms/components/connected.ts +28 -95
  296. package/src/algorithms/mst/kruskal.ts +65 -4
  297. package/src/algorithms/shortest-path/bellman-ford.ts +49 -0
  298. package/src/algorithms/shortest-path/dijkstra.ts +29 -0
  299. package/src/algorithms/shortest-path/floyd-warshall.ts +106 -136
  300. package/src/algorithms/traversal/bfs-unified.ts +52 -366
  301. package/src/algorithms/traversal/bfs-variants.ts +5 -28
  302. package/src/algorithms/traversal/bfs.ts +0 -4
  303. package/src/algorithms/traversal/dfs.ts +39 -182
  304. package/src/clustering/hierarchical-legacy.ts +551 -0
  305. package/src/clustering/hierarchical.ts +64 -520
  306. package/src/clustering/k-core-legacy.ts +229 -0
  307. package/src/clustering/k-core.ts +38 -209
  308. package/src/clustering/mcl-legacy.ts +498 -0
  309. package/src/clustering/mcl.ts +46 -479
  310. package/src/index.ts +90 -3
  311. package/src/indexed/accelerator.ts +502 -16
  312. package/src/indexed/all-pairs.ts +342 -0
  313. package/src/indexed/bellman-ford.ts +72 -0
  314. package/src/indexed/betweenness.ts +258 -0
  315. package/src/indexed/bfs.ts +189 -3
  316. package/src/indexed/bipartite.ts +77 -0
  317. package/src/indexed/closeness.ts +160 -0
  318. package/src/indexed/common-neighbors.ts +31 -14
  319. package/src/indexed/degree.ts +55 -0
  320. package/src/indexed/delta-pagerank.ts +513 -0
  321. package/src/indexed/dfs.ts +189 -0
  322. package/src/indexed/eigenvector.ts +202 -0
  323. package/src/indexed/facade.ts +229 -0
  324. package/src/indexed/flow.ts +500 -0
  325. package/src/indexed/girvan-newman.ts +120 -0
  326. package/src/indexed/grsbm.ts +390 -0
  327. package/src/indexed/hierarchical.ts +295 -0
  328. package/src/indexed/index.ts +94 -3
  329. package/src/indexed/isomorphism.ts +305 -0
  330. package/src/indexed/label-propagation.ts +582 -0
  331. package/src/indexed/leiden.ts +436 -0
  332. package/src/indexed/link-prediction.ts +399 -0
  333. package/src/indexed/markov.ts +324 -0
  334. package/src/indexed/matching.ts +192 -0
  335. package/src/indexed/min-cut.ts +201 -0
  336. package/src/indexed/modularity.ts +81 -0
  337. package/src/indexed/mst.ts +79 -1
  338. package/src/indexed/pagerank.ts +128 -15
  339. package/src/indexed/point-to-point.ts +220 -0
  340. package/src/indexed/scc.ts +132 -0
  341. package/src/indexed/spectral.ts +550 -0
  342. package/src/indexed/structures/bit-set.ts +65 -0
  343. package/src/indexed/structures/max-heap.ts +74 -0
  344. package/src/indexed/structures/min-heap.ts +51 -6
  345. package/src/indexed/structures/ring-queue.ts +70 -0
  346. package/src/indexed/sync.ts +229 -0
  347. package/src/indexed/terahac.ts +290 -0
  348. package/src/indexed/to-snapshot.ts +156 -6
  349. package/src/link-prediction/common-neighbors-legacy.ts +252 -0
  350. package/src/link-prediction/common-neighbors.ts +65 -168
  351. package/src/optimized/direction-optimized-bfs.ts +6 -1
  352. package/src/research/grsbm-legacy.ts +586 -0
  353. package/src/research/grsbm.ts +76 -555
  354. package/src/research/sync-legacy.ts +456 -0
  355. package/src/research/sync.ts +30 -431
@@ -0,0 +1,127 @@
1
+ import { IndexedMinHeap } from "./structures/min-heap.js";
2
+ /**
3
+ * Build the per-source scorer: a breadth-first search, or Dijkstra when `weighted`, then the legacy formula.
4
+ * @param s - The snapshot
5
+ * @param o - The options
6
+ * @returns The scorer
7
+ */
8
+ function scorer(s, o) {
9
+ const { nodeCount: n, rowPtr, colIdx } = s;
10
+ const cutoff = o.cutoff ?? Infinity;
11
+ const weights = o.weighted === true ? (o.weights ?? s.weights) : null;
12
+ const dist = new Float64Array(n).fill(Infinity);
13
+ const reached = new Uint32Array(n);
14
+ const heap = weights === null ? null : new IndexedMinHeap(n);
15
+ // A popped node is final, as in the legacy search: without this a negative cycle never ends.
16
+ const settled = new Uint8Array(n);
17
+ /**
18
+ * Fill `dist` from the source and list the reached nodes in `reached`.
19
+ * @param source - The source index
20
+ * @returns How many nodes were reached, the source included
21
+ */
22
+ function search(source) {
23
+ let tail = 0;
24
+ dist[source] = 0;
25
+ reached[tail++] = source;
26
+ if (heap === null || weights === null) {
27
+ for (let head = 0; head < tail; head++) {
28
+ const v = reached[head];
29
+ if (dist[v] >= cutoff) {
30
+ continue;
31
+ }
32
+ for (let a = rowPtr[v], end = rowPtr[v + 1]; a < end; a++) {
33
+ const w = colIdx[a];
34
+ if (dist[w] === Infinity) {
35
+ dist[w] = dist[v] + 1;
36
+ reached[tail++] = w;
37
+ }
38
+ }
39
+ }
40
+ return tail;
41
+ }
42
+ heap.push(source, 0);
43
+ while (!heap.isEmpty()) {
44
+ const v = heap.pop();
45
+ settled[v] = 1;
46
+ if (dist[v] >= cutoff) {
47
+ continue;
48
+ }
49
+ for (let a = rowPtr[v], end = rowPtr[v + 1]; a < end; a++) {
50
+ const w = colIdx[a];
51
+ if (settled[w] === 1) {
52
+ continue;
53
+ }
54
+ const d = dist[v] + weights[a];
55
+ if (d < dist[w]) {
56
+ if (dist[w] === Infinity) {
57
+ reached[tail++] = w;
58
+ }
59
+ dist[w] = d;
60
+ heap.pushOrDecrease(w, d);
61
+ }
62
+ }
63
+ }
64
+ return tail;
65
+ }
66
+ return (source) => {
67
+ const count = search(source);
68
+ let score = 0;
69
+ let total = 0;
70
+ for (let i = 1; i < count; i++) {
71
+ const d = dist[reached[i]];
72
+ if (o.harmonic === true) {
73
+ score += d > 0 ? 1 / d : 0;
74
+ }
75
+ else {
76
+ total += d;
77
+ }
78
+ }
79
+ for (let i = 0; i < count; i++) {
80
+ dist[reached[i]] = Infinity;
81
+ settled[reached[i]] = 0;
82
+ }
83
+ if (o.harmonic === true) {
84
+ return o.normalized === true && n > 1 ? score / (n - 1) : score;
85
+ }
86
+ if (total <= 0) {
87
+ return 0;
88
+ }
89
+ return o.normalized === true && n > 1 ? (count - 1) / total / (n - 1) : 1 / total;
90
+ };
91
+ }
92
+ /**
93
+ * Closeness centrality of every node: `1 / sum(distance to each reached node)` by default, the legacy
94
+ * `closenessCentrality` (hops) and `weightedClosenessCentrality` (`weighted: true`) numbers. The weighted
95
+ * route reads the snapshot's f32 arc weights, so it matches legacy to f32 rounding; pass the f64 weights as
96
+ * `weights` for the exact legacy sums. As in legacy, a node's distance is final once it is searched from, so a
97
+ * negative weight gives the legacy (not the true shortest) distance and never loops. An unreached node adds
98
+ * nothing, and a node that reaches nothing scores 0.
99
+ * @param s - The snapshot
100
+ * @param options - Normalisation, harmonic form, cutoff and weights
101
+ * @returns One score per node index; `iterations` is the number of searches run
102
+ * @public
103
+ */
104
+ export function closenessCentrality(s, options = {}) {
105
+ const score = scorer(s, options);
106
+ const scores = new Float64Array(s.nodeCount);
107
+ for (let v = 0; v < s.nodeCount; v++) {
108
+ scores[v] = score(v);
109
+ }
110
+ return { scores, iterations: s.nodeCount, converged: true };
111
+ }
112
+ /**
113
+ * Closeness centrality of one node, with one search rather than n.
114
+ * @param s - The snapshot
115
+ * @param node - The node index
116
+ * @param options - As {@link closenessCentrality}
117
+ * @returns The node's score
118
+ * @throws RangeError for a node index outside `[0, nodeCount)`
119
+ * @public
120
+ */
121
+ export function nodeClosenessCentrality(s, node, options = {}) {
122
+ if (!Number.isInteger(node) || node < 0 || node >= s.nodeCount) {
123
+ throw new RangeError(`nodeClosenessCentrality: node must be an index in [0, ${s.nodeCount}), got ${node}`);
124
+ }
125
+ return scorer(s, options)(node);
126
+ }
127
+ //# sourceMappingURL=closeness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"closeness.js","sourceRoot":"","sources":["../../../src/indexed/closeness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AA6B1D;;;;;GAKG;AACH,SAAS,MAAM,CAAC,CAAgB,EAAE,CAAmB;IACjD,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC;IACpC,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtE,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;IAC7D,6FAA6F;IAC7F,MAAM,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S,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAChE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,CAAgB,EAAE,IAAY,EAAE,UAA4B,EAAE;IAClG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;QAC7D,MAAM,IAAI,UAAU,CAAC,yDAAyD,CAAC,CAAC,SAAS,UAAU,IAAI,EAAE,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC"}
@@ -1,9 +1,22 @@
1
- import type { GraphSnapshot } from "@graphty/graph-format";
1
+ import type { AdjacencyView, GraphSnapshot } from "@graphty/graph-format";
2
2
  /** Options of the index-based common-neighbour score. @public */
3
3
  export interface CommonNeighborsOptions {
4
4
  /** Intersect out(u) with in(v) instead of the two undirected rows. */
5
5
  readonly directed?: boolean | undefined;
6
6
  }
7
+ /**
8
+ * Merge row u of `fwd` with row v of `bwd` (both sorted) and add up each DISTINCT common neighbour
9
+ * once: 1 per neighbour, or `weight(z)` when a weight function is given. Skipping the repeats of a
10
+ * match in row v gives simple-graph semantics on a multigraph; a repeat in row u is then smaller
11
+ * than the next entry of row v and the ordinary advance passes it.
12
+ * @param fwd - The view whose row u is read
13
+ * @param bwd - The view whose row v is read
14
+ * @param u - A node index
15
+ * @param v - A node index
16
+ * @param weight - Optional weight of a common neighbour
17
+ * @returns The count, or the weight sum, over distinct common neighbours
18
+ */
19
+ export declare function sortedRowMerge(fwd: AdjacencyView, bwd: AdjacencyView, u: number, v: number, weight?: (z: number) => number): number;
7
20
  /**
8
21
  * The number of distinct common neighbours of two nodes, by a merge of their sorted rows.
9
22
  * @param s - The snapshot
@@ -1 +1 @@
1
- {"version":3,"file":"common-neighbors.d.ts","sourceRoot":"","sources":["../../../src/indexed/common-neighbors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE1E,iEAAiE;AACjE,MAAM,WAAW,sBAAsB;IACnC,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAE,sBAA2B,GAAG,MAAM,CA4BnH"}
1
+ {"version":3,"file":"common-neighbors.d.ts","sourceRoot":"","sources":["../../../src/indexed/common-neighbors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE1E,iEAAiE;AACjE,MAAM,WAAW,sBAAsB;IACnC,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,aAAa,EAClB,GAAG,EAAE,aAAa,EAClB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAC/B,MAAM,CAuBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAE,sBAA2B,GAAG,MAAM,CAEnH"}
@@ -1,30 +1,28 @@
1
1
  /**
2
- * The number of distinct common neighbours of two nodes, by a merge of their sorted rows.
3
- * @param s - The snapshot
2
+ * Merge row u of `fwd` with row v of `bwd` (both sorted) and add up each DISTINCT common neighbour
3
+ * once: 1 per neighbour, or `weight(z)` when a weight function is given. Skipping the repeats of a
4
+ * match in row v gives simple-graph semantics on a multigraph; a repeat in row u is then smaller
5
+ * than the next entry of row v and the ordinary advance passes it.
6
+ * @param fwd - The view whose row u is read
7
+ * @param bwd - The view whose row v is read
4
8
  * @param u - A node index
5
9
  * @param v - A node index
6
- * @param o - Options
7
- * @returns The count of distinct common neighbours
8
- * @public
10
+ * @param weight - Optional weight of a common neighbour
11
+ * @returns The count, or the weight sum, over distinct common neighbours
9
12
  */
10
- export function commonNeighborsScore(s, u, v, o = {}) {
11
- const fwd = s;
12
- const bwd = o.directed === true ? s.reverse() : s;
13
+ export function sortedRowMerge(fwd, bwd, u, v, weight) {
13
14
  let i = fwd.rowPtr[u];
14
15
  const iEnd = fwd.rowPtr[u + 1];
15
16
  let j = bwd.rowPtr[v];
16
17
  const jEnd = bwd.rowPtr[v + 1];
17
- let count = 0;
18
+ let sum = 0;
18
19
  while (i < iEnd && j < jEnd) {
19
20
  const a = fwd.colIdx[i];
20
21
  const b = bwd.colIdx[j];
21
22
  if (a === b) {
22
- count++;
23
+ sum += weight === undefined ? 1 : weight(a);
23
24
  i++;
24
25
  j++;
25
- while (i < iEnd && fwd.colIdx[i] === a) {
26
- i++;
27
- }
28
26
  while (j < jEnd && bwd.colIdx[j] === b) {
29
27
  j++;
30
28
  }
@@ -36,6 +34,18 @@ export function commonNeighborsScore(s, u, v, o = {}) {
36
34
  j++;
37
35
  }
38
36
  }
39
- return count;
37
+ return sum;
38
+ }
39
+ /**
40
+ * The number of distinct common neighbours of two nodes, by a merge of their sorted rows.
41
+ * @param s - The snapshot
42
+ * @param u - A node index
43
+ * @param v - A node index
44
+ * @param o - Options
45
+ * @returns The count of distinct common neighbours
46
+ * @public
47
+ */
48
+ export function commonNeighborsScore(s, u, v, o = {}) {
49
+ return sortedRowMerge(s, o.directed === true ? s.reverse() : s, u, v);
40
50
  }
41
51
  //# sourceMappingURL=common-neighbors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common-neighbors.js","sourceRoot":"","sources":["../../../src/indexed/common-neighbors.ts"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,CAAgB,EAAE,CAAS,EAAE,CAAS,EAAE,IAA4B,EAAE;IACvG,MAAM,GAAG,GAAkB,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAkB,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;QAC1B,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACV,KAAK,EAAE,CAAC;YACR,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;YACJ,OAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,CAAC,EAAE,CAAC;Y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,CAAC;YACJ,OAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,CAAC,EAAE,CAAC;YACR,CAAC;QACL,CAAC;aAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACf,CAAC,EAAE,CAAC;QACR,CAAC;aAAM,CAAC;YACJ,CAAC,EAAE,CAAC;QACR,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,CAAgB,EAAE,CAAS,EAAE,CAAS,EAAE,IAA4B,EAAE;IACvG,OAAO,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { F64, GraphSnapshot } from "@graphty/graph-format";
2
+ /** Options of the index-based degree centrality, matching the legacy `degreeCentrality`. @public */
3
+ export interface DegreeCentralityOptions {
4
+ /** On a directed snapshot, which neighbours to count; ignored when undirected. Default `"total"`. */
5
+ readonly mode?: "in" | "out" | "total" | undefined;
6
+ /** Divide by `n - 1`, the most neighbours a node can have. Default false. */
7
+ readonly normalized?: boolean | undefined;
8
+ }
9
+ /**
10
+ * Degree centrality: each node's number of distinct neighbours (in, out, or both on a directed snapshot),
11
+ * optionally divided by `n - 1`. Equals the legacy `degreeCentrality` on every graph it can hold, and on a
12
+ * multigraph equals it on the same graph with each pair's parallel edges merged.
13
+ * @param s - The snapshot
14
+ * @param options - Direction and normalisation
15
+ * @returns One score per node index
16
+ * @public
17
+ */
18
+ export declare function degreeCentrality(s: GraphSnapshot, options?: DegreeCentralityOptions): F64;
19
+ //# sourceMappingURL=degree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"degree.d.ts","sourceRoot":"","sources":["../../../src/indexed/degree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,GAAG,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE/E,oGAAoG;AACpG,MAAM,WAAW,uBAAuB;IACpC,qGAAqG;IACrG,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;IACnD,6EAA6E;IAC7E,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,GAAE,uBAA4B,GAAG,GAAG,CAgB7F"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Add each node's number of DISTINCT neighbours in `g` to `out`: parallel edges count once and a self-loop
3
+ * counts once, as the legacy `Graph.degree` counts them.
4
+ * @param g - The adjacency
5
+ * @param out - Per-node totals, added to in place
6
+ */
7
+ function addDistinctNeighbours(g, out) {
8
+ const { rowPtr, colIdx } = g;
9
+ for (let v = 0; v < g.nodeCount; v++) {
10
+ let prev = -1;
11
+ for (let a = rowPtr[v], end = rowPtr[v + 1]; a < end; a++) {
12
+ if (colIdx[a] !== prev) {
13
+ prev = colIdx[a];
14
+ out[v]++;
15
+ }
16
+ }
17
+ }
18
+ }
19
+ /**
20
+ * Degree centrality: each node's number of distinct neighbours (in, out, or both on a directed snapshot),
21
+ * optionally divided by `n - 1`. Equals the legacy `degreeCentrality` on every graph it can hold, and on a
22
+ * multigraph equals it on the same graph with each pair's parallel edges merged.
23
+ * @param s - The snapshot
24
+ * @param options - Direction and normalisation
25
+ * @returns One score per node index
26
+ * @public
27
+ */
28
+ export function degreeCentrality(s, options = {}) {
29
+ const scores = new Float64Array(s.nodeCount);
30
+ const mode = s.directed ? (options.mode ?? "total") : "out";
31
+ if (mode !== "in") {
32
+ addDistinctNeighbours(s, scores);
33
+ }
34
+ if (mode !== "out") {
35
+ addDistinctNeighbours(s.reverse(), scores);
36
+ }
37
+ const max = s.nodeCount - 1;
38
+ if (options.normalized === true && max > 0) {
39
+ for (let v = 0; v < scores.length; v++) {
40
+ scores[v] /= max;
41
+ }
42
+ }
43
+ return scores;
44
+ }
45
+ //# sourceMappingURL=degree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"degree.js","sourceRoot":"","sources":["../../../src/indexed/degree.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,CAAgB,EAAE,GAAQ;IACrD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC;QACd,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YACxD,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBACrB,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBACjB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACb,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAgB,EAAE,UAAmC,EAAE;IACpF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5D,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAChB,qBAAqB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACjB,qBAAqB,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAC5B,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;QACrB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,145 @@
1
+ import type { F64, GraphSnapshot, NumericVector } from "@graphty/graph-format";
2
+ import type { PageRankResult } from "./pagerank.js";
3
+ /**
4
+ * The delta PageRank engines over snapshots: the `useDelta` path of the legacy `pageRank`
5
+ * ({@link deltaPageRank}), and the {@link DeltaPageRank} and {@link PriorityDeltaPageRank} engines.
6
+ * Each reproduces its legacy counterpart's arithmetic, including its quirks, so a facade over it
7
+ * gives the legacy answer: neighbours are visited in logical edge order (the legacy adjacency's
8
+ * insertion order), and every weight comes from the per-arc `weights` override when one is given.
9
+ * @module
10
+ */
11
+ /** Options of {@link deltaPageRank}. @internal */
12
+ export interface DeltaPageRankOptions {
13
+ /** Probability of following a link; default 0.85. */
14
+ readonly dampingFactor?: number | undefined;
15
+ /** Iteration cap; default 100. */
16
+ readonly maxIterations?: number | undefined;
17
+ /** Stop when no score moved by this much or more in one iteration (L-infinity); default 1e-6. */
18
+ readonly tolerance?: number | undefined;
19
+ /** Use arc weights; default false. */
20
+ readonly weighted?: boolean | undefined;
21
+ /** Per-arc weight override, arcCount long -- a facade passes `expandEdges(s, shadow.data)`. */
22
+ readonly weights?: NumericVector | undefined;
23
+ /** Starting score per node index, nodeCount long; normalised to sum 1. Default 1 / n each. */
24
+ readonly initialRanks?: NumericVector | undefined;
25
+ /** Teleport distribution per node index, nodeCount long; normalised to sum 1. Default uniform. */
26
+ readonly personalization?: NumericVector | undefined;
27
+ }
28
+ /** Options of {@link DeltaPageRank}'s and {@link PriorityDeltaPageRank}'s constructors. @public */
29
+ export interface DeltaPageRankEngineOptions {
30
+ /** Per-arc weight override, arcCount long; default the snapshot's own arc weights. */
31
+ readonly weights?: NumericVector | undefined;
32
+ }
33
+ /** Options of {@link DeltaPageRank.compute} and {@link PriorityDeltaPageRank.computeWithPriority}. @public */
34
+ export interface DeltaPageRankComputeOptions {
35
+ /** Probability of following a link; default 0.85. */
36
+ readonly dampingFactor?: number | undefined;
37
+ /** Stop when every pending delta is below this; default 1e-6. */
38
+ readonly tolerance?: number | undefined;
39
+ /** Rounds (DeltaPageRank) or processed nodes (PriorityDeltaPageRank); default 100. */
40
+ readonly maxIterations?: number | undefined;
41
+ /** A delta below this is dropped rather than propagated; default tolerance / 10. */
42
+ readonly deltaThreshold?: number | undefined;
43
+ /** Split a node's delta by arc weight instead of evenly; default false. */
44
+ readonly weighted?: boolean | undefined;
45
+ /**
46
+ * Teleport distribution per node index, nodeCount long; normalised to sum 1.
47
+ * {@link DeltaPageRank} only: the priority engine ignores it, as its legacy counterpart does.
48
+ */
49
+ readonly personalization?: NumericVector | undefined;
50
+ }
51
+ /**
52
+ * PageRank by power iteration with an L-infinity stopping rule: the `useDelta` path of the legacy
53
+ * `pageRank`, which it takes when `useDelta !== false` and the graph has more than 100 nodes. Its
54
+ * other path runs the same iteration, so this answers both. A node with no out-arcs is dangling
55
+ * and its rank is spread over every node (by the personalization when one is given); a node whose
56
+ * out-weights sum to 0 but has arcs is not dangling and passes nothing on, as in legacy.
57
+ *
58
+ * Not in the `indexed` namespace: it propagates no deltas, and it exists only so the legacy
59
+ * `pageRank` facade can reproduce legacy arithmetic exactly. Snapshot callers use
60
+ * `indexed.pageRank`.
61
+ * @param s - A DIRECTED snapshot
62
+ * @param o - Algorithm options
63
+ * @returns The scores, the iteration count and the convergence flag
64
+ * @internal
65
+ */
66
+ export declare function deltaPageRank(s: GraphSnapshot, o?: DeltaPageRankOptions): PageRankResult;
67
+ /**
68
+ * Delta-propagating PageRank that keeps its state between calls, as the legacy `DeltaPageRank`
69
+ * does: each round, every active node with a delta of at least `deltaThreshold` adds it to its
70
+ * score and pushes `dampingFactor * delta` along its out-arcs; the teleport share is added to
71
+ * every node's next delta each round, and the scores are normalised at the end. The out-weights
72
+ * that split a delta are the WEIGHTED out-degrees even when `weighted` is false -- legacy's
73
+ * arithmetic, kept so the two agree.
74
+ * @public
75
+ */
76
+ export declare class DeltaPageRank {
77
+ private readonly s;
78
+ private readonly order;
79
+ private readonly weights;
80
+ private readonly outW;
81
+ private readonly scores;
82
+ private deltas;
83
+ private active;
84
+ /**
85
+ * Start every node at score 0 with a pending delta of 1 / n, all active.
86
+ * @param s - A DIRECTED snapshot
87
+ * @param o - The per-arc weight override
88
+ */
89
+ constructor(s: GraphSnapshot, o?: DeltaPageRankEngineOptions);
90
+ /**
91
+ * Propagate deltas until none is active, every pending delta is below `tolerance`, or
92
+ * `maxIterations` rounds have run; then normalise the scores.
93
+ * @param o - Algorithm options
94
+ * @returns A copy of the scores per node index
95
+ */
96
+ compute(o?: DeltaPageRankComputeOptions): F64;
97
+ /**
98
+ * Make only the given nodes and their in- and out-neighbours active, then {@link compute}.
99
+ * An index outside the graph names nothing and is skipped, but a non-empty `modified` still
100
+ * starts a round, as legacy does for an id the graph lacks. The snapshot is frozen, so this
101
+ * re-runs over the same graph; a changed graph is a new snapshot and a new engine.
102
+ * @param modified - Node indices to reactivate
103
+ * @param o - Algorithm options
104
+ * @returns A copy of the scores per node index
105
+ */
106
+ update(modified: ArrayLike<number>, o?: DeltaPageRankComputeOptions): F64;
107
+ /**
108
+ * The propagation rounds behind {@link compute} and {@link update}.
109
+ * @param o - Algorithm options
110
+ * @param startRound - Run the first round even when no node is active
111
+ * @returns A copy of the scores per node index
112
+ */
113
+ private run;
114
+ }
115
+ /**
116
+ * Delta PageRank processed one node at a time, largest pending delta first, keeping its state
117
+ * between calls as the legacy `PriorityDeltaPageRank` does. `maxIterations` counts processed
118
+ * nodes; every 1000 of them the run stops if no pending delta reaches `tolerance`. At the end
119
+ * each pending delta of at least `deltaThreshold` is added to its score (and stays pending), the
120
+ * teleport share is added, and the scores are normalised. The out-weights are the WEIGHTED
121
+ * out-degrees even when `weighted` is false, as in legacy.
122
+ * @public
123
+ */
124
+ export declare class PriorityDeltaPageRank {
125
+ private readonly s;
126
+ private readonly order;
127
+ private readonly weights;
128
+ private readonly outW;
129
+ private readonly scores;
130
+ private readonly deltas;
131
+ private readonly heap;
132
+ /**
133
+ * Start every node at score 0 with a pending delta of 1 / n, queued in index order.
134
+ * @param s - A DIRECTED snapshot
135
+ * @param o - The per-arc weight override
136
+ */
137
+ constructor(s: GraphSnapshot, o?: DeltaPageRankEngineOptions);
138
+ /**
139
+ * Process queued nodes, largest pending delta first.
140
+ * @param o - Algorithm options; `personalization` is ignored
141
+ * @returns A copy of the scores per node index
142
+ */
143
+ computeWithPriority(o?: DeltaPageRankComputeOptions): F64;
144
+ }
145
+ //# sourceMappingURL=delta-pagerank.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delta-pagerank.d.ts","sourceRoot":"","sources":["../../../src/indexed/delta-pagerank.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,aAAa,EAAO,MAAM,uBAAuB,CAAC;AAEpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;GAOG;AAEH,kDAAkD;AAClD,MAAM,WAAW,oBAAoB;IACjC,qDAAqD;IACrD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,kC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