@graphty/algorithms 1.2.0 → 1.4.2

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 (337) hide show
  1. package/README.md +375 -276
  2. package/dist/algorithms.d.ts +42 -2
  3. package/dist/algorithms.js +11402 -2
  4. package/dist/algorithms.js.map +1 -1
  5. package/dist/src/algorithms/centrality/betweenness.d.ts +14 -0
  6. package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
  7. package/dist/src/algorithms/centrality/betweenness.js +144 -169
  8. package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
  9. package/dist/src/algorithms/centrality/closeness.d.ts +35 -1
  10. package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
  11. package/dist/src/algorithms/centrality/closeness.js +70 -149
  12. package/dist/src/algorithms/centrality/closeness.js.map +1 -1
  13. package/dist/src/algorithms/centrality/degree.d.ts +7 -0
  14. package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
  15. package/dist/src/algorithms/centrality/degree.js +12 -9
  16. package/dist/src/algorithms/centrality/degree.js.map +1 -1
  17. package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts +57 -0
  18. package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts.map +1 -0
  19. package/dist/src/algorithms/centrality/delta-pagerank-simple.js +304 -0
  20. package/dist/src/algorithms/centrality/delta-pagerank-simple.js.map +1 -0
  21. package/dist/src/algorithms/centrality/delta-pagerank.d.ts +106 -0
  22. package/dist/src/algorithms/centrality/delta-pagerank.d.ts.map +1 -0
  23. package/dist/src/algorithms/centrality/delta-pagerank.js +320 -0
  24. package/dist/src/algorithms/centrality/delta-pagerank.js.map +1 -0
  25. package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -3
  26. package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
  27. package/dist/src/algorithms/centrality/eigenvector.js +11 -4
  28. package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
  29. package/dist/src/algorithms/centrality/hits.d.ts +10 -3
  30. package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
  31. package/dist/src/algorithms/centrality/hits.js +11 -4
  32. package/dist/src/algorithms/centrality/hits.js.map +1 -1
  33. package/dist/src/algorithms/centrality/index.d.ts +3 -1
  34. package/dist/src/algorithms/centrality/index.d.ts.map +1 -1
  35. package/dist/src/algorithms/centrality/index.js +2 -1
  36. package/dist/src/algorithms/centrality/index.js.map +1 -1
  37. package/dist/src/algorithms/centrality/katz.d.ts +10 -3
  38. package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
  39. package/dist/src/algorithms/centrality/katz.js +13 -8
  40. package/dist/src/algorithms/centrality/katz.js.map +1 -1
  41. package/dist/src/algorithms/centrality/pagerank.d.ts +31 -0
  42. package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
  43. package/dist/src/algorithms/centrality/pagerank.js +61 -1
  44. package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
  45. package/dist/src/algorithms/community/girvan-newman.d.ts +2 -3
  46. package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
  47. package/dist/src/algorithms/community/girvan-newman.js +67 -57
  48. package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
  49. package/dist/src/algorithms/community/index.d.ts +2 -0
  50. package/dist/src/algorithms/community/index.d.ts.map +1 -1
  51. package/dist/src/algorithms/community/index.js.map +1 -1
  52. package/dist/src/algorithms/community/label-propagation.d.ts +11 -4
  53. package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
  54. package/dist/src/algorithms/community/label-propagation.js +60 -38
  55. package/dist/src/algorithms/community/label-propagation.js.map +1 -1
  56. package/dist/src/algorithms/community/leiden.d.ts +3 -3
  57. package/dist/src/algorithms/community/leiden.d.ts.map +1 -1
  58. package/dist/src/algorithms/community/leiden.js +70 -44
  59. package/dist/src/algorithms/community/leiden.js.map +1 -1
  60. package/dist/src/algorithms/community/louvain-optimized.d.ts +149 -0
  61. package/dist/src/algorithms/community/louvain-optimized.d.ts.map +1 -0
  62. package/dist/src/algorithms/community/louvain-optimized.js +338 -0
  63. package/dist/src/algorithms/community/louvain-optimized.js.map +1 -0
  64. package/dist/src/algorithms/community/louvain.d.ts +2 -3
  65. package/dist/src/algorithms/community/louvain.d.ts.map +1 -1
  66. package/dist/src/algorithms/community/louvain.js +35 -81
  67. package/dist/src/algorithms/community/louvain.js.map +1 -1
  68. package/dist/src/algorithms/community/modularity-utils.d.ts +55 -0
  69. package/dist/src/algorithms/community/modularity-utils.d.ts.map +1 -0
  70. package/dist/src/algorithms/community/modularity-utils.js +108 -0
  71. package/dist/src/algorithms/community/modularity-utils.js.map +1 -0
  72. package/dist/src/algorithms/components/connected.d.ts +23 -0
  73. package/dist/src/algorithms/components/connected.d.ts.map +1 -1
  74. package/dist/src/algorithms/components/connected.js +29 -3
  75. package/dist/src/algorithms/components/connected.js.map +1 -1
  76. package/dist/src/algorithms/matching/bipartite.d.ts +10 -0
  77. package/dist/src/algorithms/matching/bipartite.d.ts.map +1 -1
  78. package/dist/src/algorithms/matching/bipartite.js +18 -40
  79. package/dist/src/algorithms/matching/bipartite.js.map +1 -1
  80. package/dist/src/algorithms/matching/index.d.ts.map +1 -1
  81. package/dist/src/algorithms/matching/index.js.map +1 -1
  82. package/dist/src/algorithms/matching/isomorphism.d.ts +8 -0
  83. package/dist/src/algorithms/matching/isomorphism.d.ts.map +1 -1
  84. package/dist/src/algorithms/matching/isomorphism.js +36 -2
  85. package/dist/src/algorithms/matching/isomorphism.js.map +1 -1
  86. package/dist/src/algorithms/mst/index.d.ts.map +1 -1
  87. package/dist/src/algorithms/mst/index.js.map +1 -1
  88. package/dist/src/algorithms/mst/kruskal.d.ts +14 -0
  89. package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
  90. package/dist/src/algorithms/mst/kruskal.js +17 -3
  91. package/dist/src/algorithms/mst/kruskal.js.map +1 -1
  92. package/dist/src/algorithms/mst/prim.d.ts +9 -0
  93. package/dist/src/algorithms/mst/prim.d.ts.map +1 -1
  94. package/dist/src/algorithms/mst/prim.js +9 -0
  95. package/dist/src/algorithms/mst/prim.js.map +1 -1
  96. package/dist/src/algorithms/shortest-path/bellman-ford.d.ts +10 -0
  97. package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
  98. package/dist/src/algorithms/shortest-path/bellman-ford.js +11 -12
  99. package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
  100. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts +44 -0
  101. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts.map +1 -0
  102. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js +195 -0
  103. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js.map +1 -0
  104. package/dist/src/algorithms/shortest-path/dijkstra.d.ts +20 -2
  105. package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
  106. package/dist/src/algorithms/shortest-path/dijkstra.js +30 -14
  107. package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
  108. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +17 -0
  109. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
  110. package/dist/src/algorithms/shortest-path/floyd-warshall.js +17 -0
  111. package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
  112. package/dist/src/algorithms/shortest-path/index.d.ts.map +1 -1
  113. package/dist/src/algorithms/shortest-path/index.js.map +1 -1
  114. package/dist/src/algorithms/traversal/bfs-unified.d.ts +42 -0
  115. package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -0
  116. package/dist/src/algorithms/traversal/bfs-unified.js +370 -0
  117. package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -0
  118. package/dist/src/algorithms/traversal/bfs-variants.d.ts +77 -0
  119. package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -0
  120. package/dist/src/algorithms/traversal/bfs-variants.js +402 -0
  121. package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -0
  122. package/dist/src/algorithms/traversal/bfs.d.ts +4 -18
  123. package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
  124. package/dist/src/algorithms/traversal/bfs.js +5 -182
  125. package/dist/src/algorithms/traversal/bfs.js.map +1 -1
  126. package/dist/src/algorithms/traversal/dfs.d.ts +10 -0
  127. package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
  128. package/dist/src/algorithms/traversal/dfs.js +48 -0
  129. package/dist/src/algorithms/traversal/dfs.js.map +1 -1
  130. package/dist/src/algorithms/traversal/index.d.ts.map +1 -1
  131. package/dist/src/algorithms/traversal/index.js.map +1 -1
  132. package/dist/src/benchmark-all-algorithms.d.ts +25 -0
  133. package/dist/src/benchmark-all-algorithms.d.ts.map +1 -0
  134. package/dist/src/benchmark-all-algorithms.js +491 -0
  135. package/dist/src/benchmark-all-algorithms.js.map +1 -0
  136. package/dist/src/clustering/hierarchical.d.ts +23 -15
  137. package/dist/src/clustering/hierarchical.d.ts.map +1 -1
  138. package/dist/src/clustering/hierarchical.js +226 -224
  139. package/dist/src/clustering/hierarchical.js.map +1 -1
  140. package/dist/src/clustering/index.d.ts +4 -2
  141. package/dist/src/clustering/index.d.ts.map +1 -1
  142. package/dist/src/clustering/index.js +2 -2
  143. package/dist/src/clustering/index.js.map +1 -1
  144. package/dist/src/clustering/k-core.d.ts +17 -19
  145. package/dist/src/clustering/k-core.d.ts.map +1 -1
  146. package/dist/src/clustering/k-core.js +68 -30
  147. package/dist/src/clustering/k-core.js.map +1 -1
  148. package/dist/src/clustering/mcl.d.ts +6 -0
  149. package/dist/src/clustering/mcl.d.ts.map +1 -1
  150. package/dist/src/clustering/mcl.js +34 -3
  151. package/dist/src/clustering/mcl.js.map +1 -1
  152. package/dist/src/clustering/spectral.d.ts +11 -0
  153. package/dist/src/clustering/spectral.d.ts.map +1 -1
  154. package/dist/src/clustering/spectral.js +99 -47
  155. package/dist/src/clustering/spectral.js.map +1 -1
  156. package/dist/src/core/graph.d.ts +45 -0
  157. package/dist/src/core/graph.d.ts.map +1 -1
  158. package/dist/src/core/graph.js +49 -5
  159. package/dist/src/core/graph.js.map +1 -1
  160. package/dist/src/data-structures/index.d.ts.map +1 -1
  161. package/dist/src/data-structures/index.js.map +1 -1
  162. package/dist/src/data-structures/priority-queue.d.ts +18 -1
  163. package/dist/src/data-structures/priority-queue.d.ts.map +1 -1
  164. package/dist/src/data-structures/priority-queue.js +26 -5
  165. package/dist/src/data-structures/priority-queue.js.map +1 -1
  166. package/dist/src/data-structures/union-find.d.ts +21 -0
  167. package/dist/src/data-structures/union-find.d.ts.map +1 -1
  168. package/dist/src/data-structures/union-find.js +21 -0
  169. package/dist/src/data-structures/union-find.js.map +1 -1
  170. package/dist/src/flow/ford-fulkerson.d.ts +20 -12
  171. package/dist/src/flow/ford-fulkerson.d.ts.map +1 -1
  172. package/dist/src/flow/ford-fulkerson.js +170 -217
  173. package/dist/src/flow/ford-fulkerson.js.map +1 -1
  174. package/dist/src/flow/min-cut.d.ts +6 -8
  175. package/dist/src/flow/min-cut.d.ts.map +1 -1
  176. package/dist/src/flow/min-cut.js +34 -12
  177. package/dist/src/flow/min-cut.js.map +1 -1
  178. package/dist/src/index.d.ts +3 -1
  179. package/dist/src/index.d.ts.map +1 -1
  180. package/dist/src/index.js +6 -1
  181. package/dist/src/index.js.map +1 -1
  182. package/dist/src/link-prediction/adamic-adar.d.ts +26 -0
  183. package/dist/src/link-prediction/adamic-adar.d.ts.map +1 -1
  184. package/dist/src/link-prediction/adamic-adar.js +47 -30
  185. package/dist/src/link-prediction/adamic-adar.js.map +1 -1
  186. package/dist/src/link-prediction/common-neighbors.d.ts +21 -0
  187. package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
  188. package/dist/src/link-prediction/common-neighbors.js +31 -14
  189. package/dist/src/link-prediction/common-neighbors.js.map +1 -1
  190. package/dist/src/link-prediction/index.d.ts.map +1 -1
  191. package/dist/src/optimized/bit-packed.d.ts +193 -0
  192. package/dist/src/optimized/bit-packed.d.ts.map +1 -0
  193. package/dist/src/optimized/bit-packed.js +342 -0
  194. package/dist/src/optimized/bit-packed.js.map +1 -0
  195. package/dist/src/optimized/csr-graph.d.ts +149 -0
  196. package/dist/src/optimized/csr-graph.d.ts.map +1 -0
  197. package/dist/src/optimized/csr-graph.js +404 -0
  198. package/dist/src/optimized/csr-graph.js.map +1 -0
  199. package/dist/src/optimized/direction-optimized-bfs.d.ts +95 -0
  200. package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -0
  201. package/dist/src/optimized/direction-optimized-bfs.js +242 -0
  202. package/dist/src/optimized/direction-optimized-bfs.js.map +1 -0
  203. package/dist/src/optimized/graph-adapter.d.ts +111 -0
  204. package/dist/src/optimized/graph-adapter.d.ts.map +1 -0
  205. package/dist/src/optimized/graph-adapter.js +194 -0
  206. package/dist/src/optimized/graph-adapter.js.map +1 -0
  207. package/dist/src/optimized/index.d.ts +14 -0
  208. package/dist/src/optimized/index.d.ts.map +1 -0
  209. package/dist/src/optimized/index.js +30 -0
  210. package/dist/src/optimized/index.js.map +1 -0
  211. package/dist/src/pathfinding/astar.d.ts +25 -9
  212. package/dist/src/pathfinding/astar.d.ts.map +1 -1
  213. package/dist/src/pathfinding/astar.js +25 -10
  214. package/dist/src/pathfinding/astar.js.map +1 -1
  215. package/dist/src/pathfinding/utils.d.ts +15 -6
  216. package/dist/src/pathfinding/utils.d.ts.map +1 -1
  217. package/dist/src/pathfinding/utils.js +19 -7
  218. package/dist/src/pathfinding/utils.js.map +1 -1
  219. package/dist/src/research/grsbm.d.ts +0 -1
  220. package/dist/src/research/grsbm.d.ts.map +1 -1
  221. package/dist/src/research/grsbm.js +28 -23
  222. package/dist/src/research/grsbm.js.map +1 -1
  223. package/dist/src/research/index.d.ts.map +1 -1
  224. package/dist/src/research/index.js.map +1 -1
  225. package/dist/src/research/sync.d.ts +0 -1
  226. package/dist/src/research/sync.d.ts.map +1 -1
  227. package/dist/src/research/sync.js +31 -36
  228. package/dist/src/research/sync.js.map +1 -1
  229. package/dist/src/research/terahac.d.ts +2 -1
  230. package/dist/src/research/terahac.d.ts.map +1 -1
  231. package/dist/src/research/terahac.js +39 -7
  232. package/dist/src/research/terahac.js.map +1 -1
  233. package/dist/src/types/index.d.ts +8 -0
  234. package/dist/src/types/index.d.ts.map +1 -1
  235. package/dist/src/utils/algorithm-utilities.d.ts +2 -0
  236. package/dist/src/utils/algorithm-utilities.d.ts.map +1 -0
  237. package/dist/src/utils/algorithm-utilities.js +2 -0
  238. package/dist/src/utils/algorithm-utilities.js.map +1 -0
  239. package/dist/src/utils/graph-converters.d.ts +110 -0
  240. package/dist/src/utils/graph-converters.d.ts.map +1 -0
  241. package/dist/src/utils/graph-converters.js +227 -0
  242. package/dist/src/utils/graph-converters.js.map +1 -0
  243. package/dist/src/utils/graph-utilities.d.ts +62 -0
  244. package/dist/src/utils/graph-utilities.d.ts.map +1 -0
  245. package/dist/src/utils/graph-utilities.js +148 -0
  246. package/dist/src/utils/graph-utilities.js.map +1 -0
  247. package/dist/src/utils/index.d.ts +5 -0
  248. package/dist/src/utils/index.d.ts.map +1 -0
  249. package/dist/src/utils/index.js +5 -0
  250. package/dist/src/utils/index.js.map +1 -0
  251. package/dist/src/utils/math-utilities.d.ts +63 -0
  252. package/dist/src/utils/math-utilities.d.ts.map +1 -0
  253. package/dist/src/utils/math-utilities.js +132 -0
  254. package/dist/src/utils/math-utilities.js.map +1 -0
  255. package/dist/src/utils/matrix-utilities.d.ts +2 -0
  256. package/dist/src/utils/matrix-utilities.d.ts.map +1 -0
  257. package/dist/src/utils/matrix-utilities.js +2 -0
  258. package/dist/src/utils/matrix-utilities.js.map +1 -0
  259. package/dist/src/utils/optimization-helpers.d.ts +42 -0
  260. package/dist/src/utils/optimization-helpers.d.ts.map +1 -0
  261. package/dist/src/utils/optimization-helpers.js +59 -0
  262. package/dist/src/utils/optimization-helpers.js.map +1 -0
  263. package/dist/src/utils/priorityQueue.d.ts +24 -0
  264. package/dist/src/utils/priorityQueue.d.ts.map +1 -1
  265. package/dist/src/utils/priorityQueue.js +34 -4
  266. package/dist/src/utils/priorityQueue.js.map +1 -1
  267. package/package.json +58 -39
  268. package/src/algorithms/centrality/betweenness.ts +185 -200
  269. package/src/algorithms/centrality/closeness.ts +93 -194
  270. package/src/algorithms/centrality/degree.ts +18 -22
  271. package/src/algorithms/centrality/delta-pagerank-simple.ts +374 -0
  272. package/src/algorithms/centrality/delta-pagerank.ts +458 -0
  273. package/src/algorithms/centrality/eigenvector.ts +14 -15
  274. package/src/algorithms/centrality/hits.ts +17 -17
  275. package/src/algorithms/centrality/index.ts +20 -13
  276. package/src/algorithms/centrality/katz.ts +17 -25
  277. package/src/algorithms/centrality/pagerank.ts +91 -16
  278. package/src/algorithms/community/girvan-newman.ts +90 -86
  279. package/src/algorithms/community/index.ts +6 -5
  280. package/src/algorithms/community/label-propagation.ts +69 -48
  281. package/src/algorithms/community/leiden.ts +88 -65
  282. package/src/algorithms/community/louvain-optimized.ts +474 -0
  283. package/src/algorithms/community/louvain.ts +52 -122
  284. package/src/algorithms/community/modularity-utils.ts +134 -0
  285. package/src/algorithms/components/connected.ts +40 -17
  286. package/src/algorithms/matching/bipartite.ts +24 -53
  287. package/src/algorithms/matching/index.ts +4 -4
  288. package/src/algorithms/matching/isomorphism.ts +53 -23
  289. package/src/algorithms/mst/index.ts +3 -4
  290. package/src/algorithms/mst/kruskal.ts +21 -6
  291. package/src/algorithms/mst/prim.ts +13 -4
  292. package/src/algorithms/shortest-path/bellman-ford.ts +16 -28
  293. package/src/algorithms/shortest-path/bidirectional-dijkstra.ts +248 -0
  294. package/src/algorithms/shortest-path/dijkstra.ts +38 -30
  295. package/src/algorithms/shortest-path/floyd-warshall.ts +21 -4
  296. package/src/algorithms/shortest-path/index.ts +5 -5
  297. package/src/algorithms/traversal/bfs-unified.ts +437 -0
  298. package/src/algorithms/traversal/bfs-variants.ts +520 -0
  299. package/src/algorithms/traversal/bfs.ts +5 -229
  300. package/src/algorithms/traversal/dfs.ts +61 -42
  301. package/src/algorithms/traversal/index.ts +3 -3
  302. package/src/benchmark-all-algorithms.ts +580 -0
  303. package/src/clustering/hierarchical.ts +268 -272
  304. package/src/clustering/index.ts +8 -6
  305. package/src/clustering/k-core.ts +93 -61
  306. package/src/clustering/mcl.ts +53 -23
  307. package/src/clustering/spectral.ts +130 -72
  308. package/src/core/graph.ts +58 -18
  309. package/src/data-structures/index.ts +2 -2
  310. package/src/data-structures/priority-queue.ts +36 -11
  311. package/src/data-structures/union-find.ts +22 -1
  312. package/src/flow/ford-fulkerson.ts +221 -262
  313. package/src/flow/min-cut.ts +59 -51
  314. package/src/index.ts +9 -2
  315. package/src/link-prediction/adamic-adar.ts +75 -74
  316. package/src/link-prediction/common-neighbors.ts +49 -49
  317. package/src/link-prediction/index.ts +1 -1
  318. package/src/optimized/bit-packed.ts +390 -0
  319. package/src/optimized/csr-graph.ts +518 -0
  320. package/src/optimized/direction-optimized-bfs.ts +310 -0
  321. package/src/optimized/graph-adapter.ts +248 -0
  322. package/src/optimized/index.ts +34 -0
  323. package/src/pathfinding/astar.ts +40 -25
  324. package/src/pathfinding/utils.ts +20 -13
  325. package/src/research/grsbm.ts +36 -39
  326. package/src/research/index.ts +4 -4
  327. package/src/research/sync.ts +41 -54
  328. package/src/research/terahac.ts +63 -21
  329. package/src/types/index.ts +8 -0
  330. package/src/utils/algorithm-utilities.ts +2 -0
  331. package/src/utils/graph-converters.ts +269 -0
  332. package/src/utils/graph-utilities.ts +173 -0
  333. package/src/utils/index.ts +4 -0
  334. package/src/utils/math-utilities.ts +149 -0
  335. package/src/utils/matrix-utilities.ts +2 -0
  336. package/src/utils/optimization-helpers.ts +87 -0
  337. package/src/utils/priorityQueue.ts +40 -6
@@ -0,0 +1,149 @@
1
+ import type { Graph } from "../../core/graph.js";
2
+ import type { CommunityResult } from "../../types/index.js";
3
+ /**
4
+ * Optimized Louvain community detection algorithm with early pruning and threshold cycling
5
+ *
6
+ * Key optimizations:
7
+ * - Leaf node pruning: Skip nodes with degree 1
8
+ * - Importance ordering: Process high-impact nodes first
9
+ * - Threshold cycling: Adaptive convergence thresholds
10
+ * - Early termination: Stop when changes become insignificant
11
+ *
12
+ * Expected speedup: 2-5x on large graphs with many leaf nodes
13
+ */
14
+ export interface OptimizedLouvainOptions {
15
+ /**
16
+ * Resolution parameter (default: 1.0)
17
+ */
18
+ resolution?: number;
19
+ /**
20
+ * Maximum iterations per level (default: 100)
21
+ */
22
+ maxIterations?: number;
23
+ /**
24
+ * Convergence tolerance (default: 1e-6)
25
+ */
26
+ tolerance?: number;
27
+ /**
28
+ * Enable leaf node pruning (default: true)
29
+ */
30
+ pruneLeaves?: boolean;
31
+ /**
32
+ * Enable importance-based node ordering (default: true)
33
+ */
34
+ importanceOrdering?: boolean;
35
+ /**
36
+ * Base pruning threshold (default: 0.01)
37
+ */
38
+ pruningThreshold?: number;
39
+ /**
40
+ * Enable adaptive threshold cycling (default: true)
41
+ */
42
+ thresholdCycling?: boolean;
43
+ }
44
+ interface PruningStats {
45
+ leafNodesPruned: number;
46
+ lowDegreeNodesPruned: number;
47
+ stableNodesPruned: number;
48
+ }
49
+ /**
50
+ * Optimized Louvain implementation with early pruning and threshold cycling
51
+ */
52
+ export declare class OptimizedLouvain {
53
+ private graph;
54
+ private communities;
55
+ private communityWeights;
56
+ private nodeWeights;
57
+ private nodeDegrees;
58
+ private totalWeight;
59
+ private pruningStats;
60
+ /**
61
+ * Create an optimized Louvain detector for the given graph
62
+ * @param graph - The input graph to detect communities in
63
+ */
64
+ constructor(graph: Graph);
65
+ /**
66
+ * Run optimized Louvain algorithm
67
+ * @param options - Algorithm configuration options
68
+ * @returns Community detection result with communities, modularity, and iterations
69
+ */
70
+ detectCommunities(options?: OptimizedLouvainOptions): CommunityResult;
71
+ /**
72
+ * Initialize data structures
73
+ */
74
+ private initialize;
75
+ /**
76
+ * Get nodes ordered by importance (degree * log(weight))
77
+ * @returns Array of node IDs sorted by descending importance
78
+ */
79
+ private getNodesInImportanceOrder;
80
+ /**
81
+ * Perform local moving phase with optimizations
82
+ * @param nodes - Array of node IDs to process
83
+ * @param options - Local moving options
84
+ * @param options.pruneLeaves - Whether to skip leaf nodes
85
+ * @param options.threshold - Minimum gain threshold for moves
86
+ * @param options.resolution - Resolution parameter for modularity
87
+ * @returns True if any improvement was made, false otherwise
88
+ */
89
+ private performLocalMoving;
90
+ /**
91
+ * Check if node is a leaf (degree 1)
92
+ * @param nodeId - The node ID to check
93
+ * @returns True if the node has degree 1, false otherwise
94
+ */
95
+ private isLeafNode;
96
+ /**
97
+ * Get adaptive threshold that decreases with iterations
98
+ * @param iteration - Current iteration number
99
+ * @param baseThreshold - Base threshold value to scale
100
+ * @returns Adaptive threshold value that decays over iterations
101
+ */
102
+ private getAdaptiveThreshold;
103
+ /**
104
+ * Calculate modularity gain from moving a node to a community
105
+ * @param nodeId - The node ID to move
106
+ * @param targetCommunity - The target community ID
107
+ * @param resolution - Resolution parameter for modularity calculation
108
+ * @returns The modularity gain from moving the node
109
+ */
110
+ private calculateModularityGain;
111
+ /**
112
+ * Remove node from community (for gain calculation)
113
+ * @param nodeId - The node ID to remove
114
+ * @param community - The community ID to remove from
115
+ */
116
+ private removeNodeFromCommunity;
117
+ /**
118
+ * Add node to community
119
+ * @param nodeId - The node ID to add
120
+ * @param community - The community ID to add to
121
+ */
122
+ private addNodeToCommunity;
123
+ /**
124
+ * Get neighboring communities of a node
125
+ * @param nodeId - The node ID to find neighbor communities for
126
+ * @returns Set of community IDs that neighbors belong to
127
+ */
128
+ private getNeighborCommunities;
129
+ /**
130
+ * Calculate total modularity
131
+ * @param resolution - Resolution parameter for modularity calculation
132
+ * @returns The modularity score of the current partition
133
+ */
134
+ private calculateModularity;
135
+ /**
136
+ * Get pruning statistics
137
+ * @returns Statistics about nodes pruned during optimization
138
+ */
139
+ getPruningStats(): PruningStats;
140
+ }
141
+ /**
142
+ * Optimized Louvain algorithm with automatic optimization selection
143
+ * @param graph - The input graph to detect communities in
144
+ * @param options - Algorithm configuration options
145
+ * @returns Community detection result with communities, modularity, and iterations
146
+ */
147
+ export declare function louvainOptimized(graph: Graph, options?: OptimizedLouvainOptions): CommunityResult;
148
+ export {};
149
+ //# sourceMappingURL=louvain-optimized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"louvain-optimized.d.ts","sourceRoot":"","sources":["../../../../src/algorithms/community/louvain-optimized.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,sBAAsB,CAAC;AAEpE;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,uBAAuB;IACpC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,UAAU,YAAY;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAe;IAEnC;;;OAGG;gBACS,KAAK,EAAE,KAAK;IAcxB;;;;OAIG;IACI,iBAAiB,CAAC,OAAO,GAAE,uBAA4B,GAAG,eAAe;IAmEhF;;OAEG;IACH,OAAO,CAAC,UAAU;IA2ClB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAiBjC;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAoE1B;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAM5B;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAiC/B;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAM/B;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAM1B;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAuB9B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAwC3B;;;OAGG;IACI,eAAe,IAAI,YAAY;CAGzC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,uBAA4B,GAAG,eAAe,CAGrG"}
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Optimized Louvain implementation with early pruning and threshold cycling
3
+ */
4
+ export class OptimizedLouvain {
5
+ /**
6
+ * Create an optimized Louvain detector for the given graph
7
+ * @param graph - The input graph to detect communities in
8
+ */
9
+ constructor(graph) {
10
+ this.graph = graph;
11
+ this.communities = new Map();
12
+ this.communityWeights = new Map();
13
+ this.nodeWeights = new Map();
14
+ this.nodeDegrees = new Map();
15
+ this.totalWeight = 0;
16
+ this.pruningStats = {
17
+ leafNodesPruned: 0,
18
+ lowDegreeNodesPruned: 0,
19
+ stableNodesPruned: 0,
20
+ };
21
+ }
22
+ /**
23
+ * Run optimized Louvain algorithm
24
+ * @param options - Algorithm configuration options
25
+ * @returns Community detection result with communities, modularity, and iterations
26
+ */
27
+ detectCommunities(options = {}) {
28
+ const { resolution = 1.0, maxIterations = 100, tolerance = 1e-6, pruneLeaves = true, importanceOrdering = true, pruningThreshold = 0.01, thresholdCycling = true, } = options;
29
+ // Initialize
30
+ this.initialize();
31
+ let modularity = this.calculateModularity(resolution);
32
+ let iteration = 0;
33
+ let improved = true;
34
+ while (iteration < maxIterations && improved) {
35
+ // Get nodes in optimal processing order
36
+ const orderedNodes = importanceOrdering
37
+ ? this.getNodesInImportanceOrder()
38
+ : Array.from(this.graph.nodes()).map((n) => n.id);
39
+ // Apply adaptive threshold
40
+ const threshold = thresholdCycling ? this.getAdaptiveThreshold(iteration, pruningThreshold) : 0;
41
+ // Perform local optimization
42
+ improved = this.performLocalMoving(orderedNodes, {
43
+ pruneLeaves,
44
+ threshold,
45
+ resolution,
46
+ });
47
+ if (improved) {
48
+ const newModularity = this.calculateModularity(resolution);
49
+ // Check convergence
50
+ if (Math.abs(newModularity - modularity) < tolerance) {
51
+ break;
52
+ }
53
+ modularity = newModularity;
54
+ iteration++;
55
+ }
56
+ }
57
+ // Convert community assignments to result format
58
+ const communityGroups = new Map();
59
+ for (const [nodeId, community] of this.communities) {
60
+ if (!communityGroups.has(community)) {
61
+ communityGroups.set(community, []);
62
+ }
63
+ const group = communityGroups.get(community);
64
+ if (group) {
65
+ group.push(nodeId);
66
+ }
67
+ }
68
+ return {
69
+ communities: Array.from(communityGroups.values()),
70
+ modularity,
71
+ iterations: iteration,
72
+ };
73
+ }
74
+ /**
75
+ * Initialize data structures
76
+ */
77
+ initialize() {
78
+ let communityId = 0;
79
+ // Initialize each node in its own community
80
+ for (const node of this.graph.nodes()) {
81
+ this.communities.set(node.id, communityId);
82
+ // Calculate node weight and degree
83
+ let nodeWeight = 0;
84
+ let degree = 0;
85
+ for (const neighbor of Array.from(this.graph.neighbors(node.id))) {
86
+ const edge = this.graph.getEdge(node.id, neighbor);
87
+ const weight = edge?.weight ?? 1;
88
+ nodeWeight += weight;
89
+ degree++;
90
+ }
91
+ // For undirected graphs, also check incoming edges
92
+ if (!this.graph.isDirected) {
93
+ for (const neighbor of Array.from(this.graph.inNeighbors(node.id))) {
94
+ if (!this.graph.hasEdge(node.id, neighbor)) {
95
+ const edge = this.graph.getEdge(neighbor, node.id);
96
+ const weight = edge?.weight ?? 1;
97
+ nodeWeight += weight;
98
+ degree++;
99
+ }
100
+ }
101
+ }
102
+ this.nodeWeights.set(node.id, nodeWeight);
103
+ this.nodeDegrees.set(node.id, degree);
104
+ this.communityWeights.set(communityId, nodeWeight);
105
+ this.totalWeight += nodeWeight;
106
+ communityId++;
107
+ }
108
+ // Total weight is sum of all edge weights
109
+ // For undirected graphs, each edge is counted twice from both endpoints
110
+ this.totalWeight = this.totalWeight / 2;
111
+ }
112
+ /**
113
+ * Get nodes ordered by importance (degree * log(weight))
114
+ * @returns Array of node IDs sorted by descending importance
115
+ */
116
+ getNodesInImportanceOrder() {
117
+ const nodeImportance = new Map();
118
+ for (const [nodeId, degree] of this.nodeDegrees) {
119
+ const weight = this.nodeWeights.get(nodeId) ?? 0;
120
+ // Importance score: combination of degree and weight
121
+ // High-degree nodes and nodes with heavy edges are processed first
122
+ const importance = degree * Math.log(1 + weight);
123
+ nodeImportance.set(nodeId, importance);
124
+ }
125
+ // Sort by importance (descending)
126
+ return Array.from(nodeImportance.entries())
127
+ .sort((a, b) => b[1] - a[1])
128
+ .map(([nodeId]) => nodeId);
129
+ }
130
+ /**
131
+ * Perform local moving phase with optimizations
132
+ * @param nodes - Array of node IDs to process
133
+ * @param options - Local moving options
134
+ * @param options.pruneLeaves - Whether to skip leaf nodes
135
+ * @param options.threshold - Minimum gain threshold for moves
136
+ * @param options.resolution - Resolution parameter for modularity
137
+ * @returns True if any improvement was made, false otherwise
138
+ */
139
+ performLocalMoving(nodes, options) {
140
+ const { pruneLeaves, threshold, resolution } = options;
141
+ let improvement = false;
142
+ let hasChanged = true;
143
+ while (hasChanged) {
144
+ hasChanged = false;
145
+ for (const nodeId of nodes) {
146
+ // Early pruning: skip leaf nodes
147
+ if (pruneLeaves && this.isLeafNode(nodeId)) {
148
+ this.pruningStats.leafNodesPruned++;
149
+ continue;
150
+ }
151
+ const currentCommunity = this.communities.get(nodeId) ?? 0;
152
+ const neighborCommunities = this.getNeighborCommunities(nodeId);
153
+ // Skip isolated nodes
154
+ if (neighborCommunities.size === 0) {
155
+ continue;
156
+ }
157
+ // Find best community to move to
158
+ let bestCommunity = currentCommunity;
159
+ let bestGain = 0;
160
+ // Remove node from its current community to calculate gains
161
+ this.removeNodeFromCommunity(nodeId, currentCommunity);
162
+ for (const community of neighborCommunities) {
163
+ const gain = this.calculateModularityGain(nodeId, community, resolution);
164
+ // Apply threshold - only move if gain exceeds threshold
165
+ if (gain > bestGain + threshold) {
166
+ bestGain = gain;
167
+ bestCommunity = community;
168
+ }
169
+ }
170
+ // Try staying in current community
171
+ const currentGain = this.calculateModularityGain(nodeId, currentCommunity, resolution);
172
+ if (currentGain > bestGain + threshold) {
173
+ bestGain = currentGain;
174
+ bestCommunity = currentCommunity;
175
+ }
176
+ // Add node to best community
177
+ this.addNodeToCommunity(nodeId, bestCommunity);
178
+ // Track if node moved
179
+ if (bestCommunity !== currentCommunity) {
180
+ hasChanged = true;
181
+ improvement = true;
182
+ }
183
+ }
184
+ }
185
+ return improvement;
186
+ }
187
+ /**
188
+ * Check if node is a leaf (degree 1)
189
+ * @param nodeId - The node ID to check
190
+ * @returns True if the node has degree 1, false otherwise
191
+ */
192
+ isLeafNode(nodeId) {
193
+ const degree = this.nodeDegrees.get(nodeId) ?? 0;
194
+ return degree === 1;
195
+ }
196
+ /**
197
+ * Get adaptive threshold that decreases with iterations
198
+ * @param iteration - Current iteration number
199
+ * @param baseThreshold - Base threshold value to scale
200
+ * @returns Adaptive threshold value that decays over iterations
201
+ */
202
+ getAdaptiveThreshold(iteration, baseThreshold) {
203
+ // Exponentially decay threshold with iterations
204
+ // This allows coarse movements early and fine-tuning later
205
+ return baseThreshold * Math.pow(0.5, iteration / 10);
206
+ }
207
+ /**
208
+ * Calculate modularity gain from moving a node to a community
209
+ * @param nodeId - The node ID to move
210
+ * @param targetCommunity - The target community ID
211
+ * @param resolution - Resolution parameter for modularity calculation
212
+ * @returns The modularity gain from moving the node
213
+ */
214
+ calculateModularityGain(nodeId, targetCommunity, resolution) {
215
+ const nodeWeight = this.nodeWeights.get(nodeId) ?? 0;
216
+ // Sum of weights from node to target community
217
+ let weightToTarget = 0;
218
+ for (const neighbor of Array.from(this.graph.neighbors(nodeId))) {
219
+ if (this.communities.get(neighbor) === targetCommunity) {
220
+ const edge = this.graph.getEdge(nodeId, neighbor);
221
+ weightToTarget += edge?.weight ?? 1;
222
+ }
223
+ }
224
+ // For undirected graphs, also check incoming edges
225
+ if (!this.graph.isDirected) {
226
+ for (const neighbor of Array.from(this.graph.inNeighbors(nodeId))) {
227
+ if (this.communities.get(neighbor) === targetCommunity && !this.graph.hasEdge(nodeId, neighbor)) {
228
+ const edge = this.graph.getEdge(neighbor, nodeId);
229
+ weightToTarget += edge?.weight ?? 1;
230
+ }
231
+ }
232
+ }
233
+ // Weight of target community
234
+ const targetWeight = this.communityWeights.get(targetCommunity) ?? 0;
235
+ // Modularity gain formula
236
+ const gain = (weightToTarget - (resolution * nodeWeight * targetWeight) / (2 * this.totalWeight)) / this.totalWeight;
237
+ return gain;
238
+ }
239
+ /**
240
+ * Remove node from community (for gain calculation)
241
+ * @param nodeId - The node ID to remove
242
+ * @param community - The community ID to remove from
243
+ */
244
+ removeNodeFromCommunity(nodeId, community) {
245
+ const nodeWeight = this.nodeWeights.get(nodeId) ?? 0;
246
+ this.communityWeights.set(community, (this.communityWeights.get(community) ?? 0) - nodeWeight);
247
+ this.communities.delete(nodeId);
248
+ }
249
+ /**
250
+ * Add node to community
251
+ * @param nodeId - The node ID to add
252
+ * @param community - The community ID to add to
253
+ */
254
+ addNodeToCommunity(nodeId, community) {
255
+ const nodeWeight = this.nodeWeights.get(nodeId) ?? 0;
256
+ this.communityWeights.set(community, (this.communityWeights.get(community) ?? 0) + nodeWeight);
257
+ this.communities.set(nodeId, community);
258
+ }
259
+ /**
260
+ * Get neighboring communities of a node
261
+ * @param nodeId - The node ID to find neighbor communities for
262
+ * @returns Set of community IDs that neighbors belong to
263
+ */
264
+ getNeighborCommunities(nodeId) {
265
+ const communities = new Set();
266
+ for (const neighbor of Array.from(this.graph.neighbors(nodeId))) {
267
+ const community = this.communities.get(neighbor);
268
+ if (community !== undefined) {
269
+ communities.add(community);
270
+ }
271
+ }
272
+ // For undirected graphs, also check incoming edges
273
+ if (!this.graph.isDirected) {
274
+ for (const neighbor of Array.from(this.graph.inNeighbors(nodeId))) {
275
+ const community = this.communities.get(neighbor);
276
+ if (community !== undefined) {
277
+ communities.add(community);
278
+ }
279
+ }
280
+ }
281
+ return communities;
282
+ }
283
+ /**
284
+ * Calculate total modularity
285
+ * @param resolution - Resolution parameter for modularity calculation
286
+ * @returns The modularity score of the current partition
287
+ */
288
+ calculateModularity(resolution) {
289
+ if (this.totalWeight === 0) {
290
+ return 0;
291
+ }
292
+ let modularity = 0;
293
+ // Sum over all communities
294
+ const communityInternalWeights = new Map();
295
+ // Calculate internal weights for each community
296
+ for (const node of this.graph.nodes()) {
297
+ const nodeId = node.id;
298
+ const community = this.communities.get(nodeId) ?? 0;
299
+ for (const neighbor of Array.from(this.graph.neighbors(nodeId))) {
300
+ if (this.communities.get(neighbor) === community) {
301
+ const edge = this.graph.getEdge(nodeId, neighbor);
302
+ const weight = edge?.weight ?? 1;
303
+ communityInternalWeights.set(community, (communityInternalWeights.get(community) ?? 0) + weight);
304
+ }
305
+ }
306
+ }
307
+ // Calculate modularity
308
+ for (const [community, internalWeight] of communityInternalWeights) {
309
+ const communityWeight = this.communityWeights.get(community) ?? 0;
310
+ // For undirected graphs, internal weights are counted twice
311
+ const aIn = this.graph.isDirected ? internalWeight : internalWeight / 2;
312
+ const aTotal = communityWeight;
313
+ // Modularity formula: sum of (fraction of edges within community - expected fraction)
314
+ const actualFraction = aIn / this.totalWeight;
315
+ const expectedFraction = resolution * Math.pow(aTotal / (2 * this.totalWeight), 2);
316
+ modularity += actualFraction - expectedFraction;
317
+ }
318
+ return modularity;
319
+ }
320
+ /**
321
+ * Get pruning statistics
322
+ * @returns Statistics about nodes pruned during optimization
323
+ */
324
+ getPruningStats() {
325
+ return { ...this.pruningStats };
326
+ }
327
+ }
328
+ /**
329
+ * Optimized Louvain algorithm with automatic optimization selection
330
+ * @param graph - The input graph to detect communities in
331
+ * @param options - Algorithm configuration options
332
+ * @returns Community detection result with communities, modularity, and iterations
333
+ */
334
+ export function louvainOptimized(graph, options = {}) {
335
+ const optimizer = new OptimizedLouvain(graph);
336
+ return optimizer.detectCommunities(options);
337
+ }
338
+ //# sourceMappingURL=louvain-optimized.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"louvain-optimized.js","sourceRoot":"","sources":["../../../../src/algorithms/community/louvain-optimized.ts"],"names":[],"mappings":"AAoDA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IASzB;;;OAGG;IACH,YAAY,KAAY;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG;YAChB,eAAe,EAAE,CAAC;YAClB,oBAAoB,EAAE,CAAC;YACvB,iBAAiB,EAAE,CAAC;SACvB,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,iBAAiB,CAAC,UAAmC,EAAE;QAC1D,MAAM,EACF,UAAU,GAAG,GAAG,EAChB,aAAa,GAAG,GAAG,EACnB,SAAS,GAAG,IAAI,EAChB,WAAW,GAAG,IAAI,EAClB,kBAAkB,GAAG,IAAI,EACzB,gBAAgB,GAAG,IAAI,EACvB,gBAAgB,GAAG,IAAI,GAC1B,GAAG,OAAO,CA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gBAAgB,CAAC,KAAY,EAAE,UAAmC,EAAE;IAChF,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,OAAO,SAAS,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC"}
@@ -8,9 +8,8 @@ import type { CommunityResult, LouvainOptions } from "../../types/index.js";
8
8
  *
9
9
  * References:
10
10
  * - Blondel, V. D., Guillaume, J. L., Lambiotte, R., & Lefebvre, E. (2008).
11
- * Fast unfolding of communities in large networks.
12
- * Journal of statistical mechanics: theory and experiment, 2008(10), P10008.
13
- *
11
+ * Fast unfolding of communities in large networks.
12
+ * Journal of statistical mechanics: theory and experiment, 2008(10), P10008.
14
13
  * @param graph - The input graph
15
14
  * @param options - Algorithm options
16
15
  * @returns Community detection result with communities, modularity, and iterations
@@ -1 +1 @@
1
- {"version":3,"file":"louvain.d.ts","sourceRoot":"","sources":["../../../../src/algorithms/community/louvain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAC1C,OAAO,KAAK,EAAC,eAAe,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAC;AAElF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CACnB,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,cAAmB,GAC7B,eAAe,CAiCjB"}
1
+ {"version":3,"file":"louvain.d.ts","sourceRoot":"","sources":["../../../../src/algorithms/community/louvain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAU,MAAM,sBAAsB,CAAC;AAIpF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,cAAmB,GAAG,eAAe,CAkDnF"}