okstra 0.130.4 → 0.131.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.
Files changed (365) hide show
  1. package/README.md +0 -1
  2. package/docs/architecture.md +2 -2
  3. package/docs/cli.md +1 -1
  4. package/docs/for-ai/README.md +0 -2
  5. package/docs/for-ai/skills/okstra-run.md +13 -2
  6. package/docs/for-ai/skills/okstra-setup.md +4 -1
  7. package/docs/project-structure-overview.md +5 -4
  8. package/docs/task-process/implementation-planning.md +13 -0
  9. package/docs/task-process/implementation.md +17 -2
  10. package/package.json +1 -1
  11. package/runtime/BUILD.json +2 -2
  12. package/runtime/agents/workers/report-writer-worker.md +7 -0
  13. package/runtime/bin/lib/okstra/usage.sh +4 -4
  14. package/runtime/prompts/lead/okstra-lead-contract.md +2 -2
  15. package/runtime/prompts/lead/plan-body-verification.md +26 -5
  16. package/runtime/prompts/lead/report-writer.md +6 -2
  17. package/runtime/prompts/profiles/_common-contract.md +2 -1
  18. package/runtime/prompts/profiles/_implementation-deliverable.md +6 -1
  19. package/runtime/prompts/profiles/_implementation-executor.md +2 -2
  20. package/runtime/prompts/profiles/_implementation-verifier.md +33 -10
  21. package/runtime/prompts/profiles/final-verification.md +21 -6
  22. package/runtime/prompts/profiles/implementation-planning.md +16 -4
  23. package/runtime/python/okstra_ctl/codex_dispatch.py +31 -0
  24. package/runtime/python/okstra_ctl/conformance.py +49 -11
  25. package/runtime/python/okstra_ctl/report_finalize.py +52 -1
  26. package/runtime/python/okstra_ctl/run.py +15 -3
  27. package/runtime/python/okstra_ctl/worker_prompt_contract.py +14 -6
  28. package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -1
  29. package/runtime/python/okstra_vendor/__init__.py +0 -44
  30. package/runtime/schemas/final-report-v1.0.schema.json +99 -5
  31. package/runtime/skills/okstra-run/SKILL.md +11 -4
  32. package/runtime/skills/okstra-setup/SKILL.md +3 -2
  33. package/runtime/skills/okstra-setup/references/project-config.md +16 -7
  34. package/runtime/templates/reports/final-report.template.md +15 -9
  35. package/runtime/templates/reports/i18n/en.json +1 -0
  36. package/runtime/templates/reports/i18n/ko.json +1 -0
  37. package/runtime/validators/lib/fixtures.sh +6 -0
  38. package/runtime/validators/validate-run.py +2019 -96
  39. package/src/cli-registry.mjs +0 -7
  40. package/src/commands/lifecycle/doctor.mjs +0 -9
  41. package/src/lib/skill-catalog.mjs +0 -1
  42. package/docs/for-ai/skills/okstra-graphify.md +0 -64
  43. package/runtime/python/okstra_ctl/graphify_cmd.py +0 -225
  44. package/runtime/python/okstra_vendor/graphify/.vendored-version +0 -1
  45. package/runtime/python/okstra_vendor/graphify/__init__.py +0 -28
  46. package/runtime/python/okstra_vendor/graphify/__main__.py +0 -1371
  47. package/runtime/python/okstra_vendor/graphify/analyze.py +0 -540
  48. package/runtime/python/okstra_vendor/graphify/benchmark.py +0 -129
  49. package/runtime/python/okstra_vendor/graphify/build.py +0 -107
  50. package/runtime/python/okstra_vendor/graphify/cache.py +0 -169
  51. package/runtime/python/okstra_vendor/graphify/cluster.py +0 -137
  52. package/runtime/python/okstra_vendor/graphify/detect.py +0 -510
  53. package/runtime/python/okstra_vendor/graphify/export.py +0 -1014
  54. package/runtime/python/okstra_vendor/graphify/extract.py +0 -3277
  55. package/runtime/python/okstra_vendor/graphify/hooks.py +0 -220
  56. package/runtime/python/okstra_vendor/graphify/ingest.py +0 -297
  57. package/runtime/python/okstra_vendor/graphify/manifest.py +0 -4
  58. package/runtime/python/okstra_vendor/graphify/report.py +0 -175
  59. package/runtime/python/okstra_vendor/graphify/security.py +0 -203
  60. package/runtime/python/okstra_vendor/graphify/serve.py +0 -373
  61. package/runtime/python/okstra_vendor/graphify/skill-aider.md +0 -1184
  62. package/runtime/python/okstra_vendor/graphify/skill-claw.md +0 -1184
  63. package/runtime/python/okstra_vendor/graphify/skill-codex.md +0 -1242
  64. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +0 -1268
  65. package/runtime/python/okstra_vendor/graphify/skill-droid.md +0 -1239
  66. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +0 -1183
  67. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +0 -1238
  68. package/runtime/python/okstra_vendor/graphify/skill-trae.md +0 -1208
  69. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +0 -253
  70. package/runtime/python/okstra_vendor/graphify/skill-windows.md +0 -1245
  71. package/runtime/python/okstra_vendor/graphify/skill.md +0 -1319
  72. package/runtime/python/okstra_vendor/graphify/transcribe.py +0 -182
  73. package/runtime/python/okstra_vendor/graphify/validate.py +0 -72
  74. package/runtime/python/okstra_vendor/graphify/watch.py +0 -188
  75. package/runtime/python/okstra_vendor/graphify/wiki.py +0 -214
  76. package/runtime/python/okstra_vendor/networkx/__init__.py +0 -62
  77. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +0 -134
  78. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +0 -26
  79. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +0 -259
  80. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +0 -71
  81. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +0 -412
  82. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +0 -396
  83. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +0 -150
  84. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +0 -149
  85. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +0 -369
  86. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +0 -44
  87. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +0 -143
  88. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +0 -53
  89. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +0 -265
  90. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +0 -1508
  91. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +0 -255
  92. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +0 -83
  93. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +0 -5
  94. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +0 -122
  95. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +0 -302
  96. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +0 -255
  97. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +0 -160
  98. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +0 -127
  99. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +0 -164
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +0 -88
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +0 -322
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +0 -290
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +0 -289
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +0 -57
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +0 -360
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +0 -105
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +0 -603
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +0 -316
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +0 -590
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +0 -232
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +0 -526
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +0 -112
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +0 -69
  114. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +0 -168
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +0 -205
  116. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +0 -164
  117. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +0 -20
  118. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +0 -591
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +0 -236
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +0 -282
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +0 -364
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +0 -227
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +0 -96
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +0 -150
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +0 -107
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +0 -357
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +0 -130
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +0 -787
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +0 -88
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +0 -331
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +0 -150
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +0 -200
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +0 -128
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +0 -209
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +0 -141
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +0 -361
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +0 -181
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +0 -95
  139. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +0 -172
  140. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +0 -443
  141. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +0 -818
  142. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +0 -732
  143. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +0 -4
  144. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +0 -505
  145. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +0 -565
  146. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +0 -163
  147. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +0 -28
  148. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +0 -153
  149. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +0 -354
  150. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +0 -171
  151. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +0 -30
  152. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +0 -216
  153. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +0 -79
  154. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +0 -338
  155. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +0 -162
  156. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +0 -220
  157. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +0 -384
  158. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +0 -227
  159. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +0 -452
  160. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +0 -347
  161. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +0 -6
  162. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +0 -115
  163. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +0 -394
  164. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +0 -282
  165. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +0 -71
  166. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +0 -359
  167. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +0 -196
  168. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +0 -11
  169. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +0 -811
  170. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +0 -616
  171. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +0 -408
  172. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +0 -1270
  173. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +0 -592
  174. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +0 -220
  175. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +0 -235
  176. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +0 -152
  177. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +0 -88
  178. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +0 -588
  179. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +0 -142
  180. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +0 -416
  181. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +0 -1234
  182. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +0 -677
  183. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +0 -1392
  184. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +0 -1095
  185. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +0 -272
  186. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +0 -142
  187. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +0 -268
  188. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +0 -167
  189. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +0 -470
  190. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +0 -11
  191. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +0 -370
  192. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +0 -407
  193. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +0 -238
  194. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +0 -241
  195. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +0 -178
  196. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +0 -611
  197. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +0 -356
  198. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +0 -662
  199. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +0 -425
  200. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +0 -300
  201. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +0 -194
  202. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +0 -435
  203. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +0 -483
  204. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +0 -57
  205. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +0 -196
  206. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +0 -107
  207. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +0 -7
  208. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +0 -1306
  209. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +0 -336
  210. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +0 -1262
  211. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +0 -352
  212. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +0 -308
  213. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +0 -264
  214. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +0 -1102
  215. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +0 -192
  216. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +0 -2
  217. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +0 -337
  218. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +0 -498
  219. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +0 -687
  220. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +0 -280
  221. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +0 -1148
  222. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +0 -27
  223. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +0 -738
  224. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +0 -78
  225. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +0 -59
  226. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +0 -219
  227. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +0 -155
  228. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +0 -4
  229. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +0 -324
  230. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +0 -468
  231. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +0 -633
  232. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +0 -77
  233. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +0 -73
  234. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +0 -464
  235. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +0 -1463
  236. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +0 -306
  237. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +0 -98
  238. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +0 -167
  239. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +0 -138
  240. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +0 -5
  241. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +0 -239
  242. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +0 -264
  243. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +0 -716
  244. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +0 -625
  245. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +0 -2542
  246. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +0 -2107
  247. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +0 -966
  248. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +0 -404
  249. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +0 -30
  250. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +0 -296
  251. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +0 -374
  252. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +0 -564
  253. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +0 -406
  254. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +0 -981
  255. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +0 -142
  256. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +0 -406
  257. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +0 -5
  258. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +0 -90
  259. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +0 -576
  260. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +0 -529
  261. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +0 -185
  262. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +0 -182
  263. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +0 -7
  264. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +0 -1042
  265. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +0 -413
  266. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +0 -88
  267. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +0 -219
  268. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +0 -1281
  269. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +0 -106
  270. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +0 -273
  271. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +0 -500
  272. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +0 -76
  273. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +0 -86
  274. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +0 -77
  275. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +0 -278
  276. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +0 -13
  277. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +0 -435
  278. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +0 -1363
  279. package/runtime/python/okstra_vendor/networkx/classes/filters.py +0 -95
  280. package/runtime/python/okstra_vendor/networkx/classes/function.py +0 -1549
  281. package/runtime/python/okstra_vendor/networkx/classes/graph.py +0 -2082
  282. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +0 -269
  283. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +0 -977
  284. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +0 -1294
  285. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +0 -1447
  286. package/runtime/python/okstra_vendor/networkx/convert.py +0 -502
  287. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +0 -1314
  288. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +0 -7
  289. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +0 -2036
  290. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +0 -470
  291. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +0 -570
  292. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +0 -361
  293. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +0 -2978
  294. package/runtime/python/okstra_vendor/networkx/exception.py +0 -131
  295. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +0 -34
  296. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  297. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +0 -227
  298. package/runtime/python/okstra_vendor/networkx/generators/classic.py +0 -1091
  299. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +0 -68
  300. package/runtime/python/okstra_vendor/networkx/generators/community.py +0 -1070
  301. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +0 -886
  302. package/runtime/python/okstra_vendor/networkx/generators/directed.py +0 -572
  303. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +0 -174
  304. package/runtime/python/okstra_vendor/networkx/generators/ego.py +0 -66
  305. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +0 -499
  306. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +0 -1037
  307. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +0 -163
  308. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +0 -443
  309. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +0 -125
  310. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +0 -70
  311. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +0 -664
  312. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +0 -405
  313. package/runtime/python/okstra_vendor/networkx/generators/line.py +0 -501
  314. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +0 -110
  315. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +0 -259
  316. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +0 -117
  317. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +0 -1416
  318. package/runtime/python/okstra_vendor/networkx/generators/small.py +0 -1070
  319. package/runtime/python/okstra_vendor/networkx/generators/social.py +0 -554
  320. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +0 -120
  321. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +0 -54
  322. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +0 -131
  323. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +0 -74
  324. package/runtime/python/okstra_vendor/networkx/generators/trees.py +0 -1070
  325. package/runtime/python/okstra_vendor/networkx/generators/triads.py +0 -94
  326. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +0 -188
  327. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +0 -13
  328. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +0 -650
  329. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +0 -466
  330. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +0 -77
  331. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +0 -168
  332. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +0 -512
  333. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +0 -166
  334. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +0 -186
  335. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +0 -17
  336. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +0 -330
  337. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +0 -489
  338. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +0 -1084
  339. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +0 -879
  340. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +0 -427
  341. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +0 -1053
  342. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +0 -19
  343. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +0 -156
  344. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +0 -190
  345. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +0 -261
  346. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +0 -137
  347. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +0 -108
  348. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +0 -393
  349. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +0 -113
  350. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +0 -286
  351. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +0 -379
  352. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +0 -851
  353. package/runtime/python/okstra_vendor/networkx/relabel.py +0 -285
  354. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +0 -8
  355. package/runtime/python/okstra_vendor/networkx/utils/backends.py +0 -2171
  356. package/runtime/python/okstra_vendor/networkx/utils/configs.py +0 -396
  357. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +0 -1233
  358. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +0 -338
  359. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +0 -297
  360. package/runtime/python/okstra_vendor/networkx/utils/misc.py +0 -703
  361. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +0 -198
  362. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +0 -159
  363. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +0 -106
  364. package/runtime/skills/okstra-graphify/SKILL.md +0 -169
  365. package/src/commands/graphify.mjs +0 -32
@@ -1,220 +0,0 @@
1
- """
2
- Local Community Detection Algorithms
3
-
4
- Local Community Detection (LCD) aims to detected one or a few communities
5
- starting from certain source nodes in the network. This differs from Global
6
- Community Detection (GCD), which aims to partition an entire network into
7
- communities.
8
-
9
- LCD is often useful when only a portion of the graph is known or the
10
- graph is large enough that GCD is infeasable
11
-
12
- [1]_ Gives a good introduction and overview of LCD
13
-
14
- References
15
- ----------
16
- .. [1] Baltsou, Georgia, Konstantinos Christopoulos, and Konstantinos Tsichlas.
17
- Local community detection: A survey. IEEE Access 10 (2022): 110701-110726.
18
- https://doi.org/10.1109/ACCESS.2022.3213980
19
-
20
-
21
- """
22
-
23
- __all__ = ["greedy_source_expansion"]
24
-
25
-
26
- def _clauset_greedy_source_expansion(G, *, source, cutoff=None):
27
- if cutoff is None:
28
- cutoff = float("inf")
29
- C = {source}
30
- B = {source}
31
- U = G[source].keys() - C
32
- T = {frozenset([node, nbr]) for node in B for nbr in G.neighbors(node)}
33
- I = {edge for edge in T if all(node in C for node in edge)}
34
-
35
- R_value = 0
36
- while len(C) < cutoff:
37
- if not U:
38
- break
39
-
40
- max_R = 0
41
- best_node = None
42
- best_node_B = best_node_T = best_node_I = set()
43
-
44
- for v in U:
45
- R_tmp, B_tmp, T_tmp, I_tmp = _calculate_local_modularity_for_candidate(
46
- G, v, C, B, T, I
47
- )
48
- if R_tmp > max_R:
49
- max_R = R_tmp
50
- best_node = v
51
- best_node_B = B_tmp
52
- best_node_T = T_tmp
53
- best_node_I = I_tmp
54
-
55
- C = C | {best_node}
56
- U.update(G[best_node].keys() - C)
57
- U.remove(best_node)
58
- B = best_node_B
59
- T = best_node_T
60
- I = best_node_I
61
- if max_R < R_value:
62
- break
63
- R_value = max_R
64
-
65
- return C
66
-
67
-
68
- def _calculate_local_modularity_for_candidate(G, v, C, B, T, I):
69
- """
70
- Compute the local modularity R and updated variables when adding node v to the community.
71
-
72
- Parameters
73
- ----------
74
- G : NetworkX graph
75
- The input graph.
76
- v : node
77
- The candidate node to add to the community.
78
- C : set
79
- The current set of community nodes.
80
- B : set
81
- The current set of boundary nodes.
82
- T : set of frozenset
83
- The current set of boundary edges.
84
- I : set of frozenset
85
- The current set of internal boundary edges.
86
-
87
- Returns
88
- -------
89
- R_tmp : float
90
- The local modularity after adding node v.
91
- B_tmp : set
92
- The updated set of boundary nodes.
93
- T_tmp : set of frozenset
94
- The updated set of boundary edges.
95
- I_tmp : set of frozenset
96
- The updated set of internal boundary edges.
97
- """
98
- C_tmp = C | {v}
99
- B_tmp = B.copy()
100
- T_tmp = T.copy()
101
- I_tmp = I.copy()
102
- removed_B_nodes = set()
103
-
104
- # Update boundary nodes and edges
105
- for nbr in G[v]:
106
- if nbr not in C_tmp:
107
- # v has nbrs not in the community, so it remains a boundary node
108
- B_tmp.add(v)
109
- # Add edge between v and nbr to boundary edges
110
- T_tmp.add(frozenset([v, nbr]))
111
-
112
- if nbr in B:
113
- # Check if nbr should be removed from boundary nodes
114
- # Go through nbrs nbrs to see if it is still a boundary node
115
- nbr_still_in_B = any(nbr_nbr not in C_tmp for nbr_nbr in G[nbr])
116
- if not nbr_still_in_B:
117
- B_tmp.remove(nbr)
118
- removed_B_nodes.add(nbr)
119
-
120
- if nbr in C_tmp:
121
- # Add edge between v and nbr to internal edges
122
- I_tmp.add(frozenset([v, nbr]))
123
-
124
- # Remove edges no longer in the boundary
125
- for removed_node in removed_B_nodes:
126
- for removed_node_nbr in G[removed_node]:
127
- if removed_node_nbr not in B_tmp:
128
- T_tmp.discard(frozenset([removed_node_nbr, removed_node]))
129
- I_tmp.discard(frozenset([removed_node_nbr, removed_node]))
130
-
131
- R_tmp = len(I_tmp) / len(T_tmp) if len(T_tmp) > 0 else 1
132
- return R_tmp, B_tmp, T_tmp, I_tmp
133
-
134
-
135
- ALGORITHMS = {
136
- "clauset": _clauset_greedy_source_expansion,
137
- }
138
-
139
-
140
- def greedy_source_expansion(G, *, source, cutoff=None, method="clauset"):
141
- r"""Find the local community around a source node.
142
-
143
- Find the local community around a source node using Greedy Source
144
- Expansion. Greedy Source Expansion generally identifies a local community
145
- starting from the source node and expands it based on the criteria of the
146
- chosen algorithm.
147
-
148
- The algorithm is specified with the `method` keyword argument.
149
-
150
- * `"clauset"` [1]_ uses local modularity gain to determine local communities.
151
- The algorithm adds nbring nodes that maximize local modularity to the
152
- community iteratively, stopping when no additional nodes improve the modularity
153
- or when a predefined cutoff is reached.
154
-
155
- Local modularity measures the density of edges within a community relative
156
- to the total graph. By focusing on local modularity, the algorithm efficiently
157
- uncovers communities around a specific node without requiring global
158
- optimization over the entire graph.
159
-
160
- The algorithm assumes that the graph $G$ consists of a known community $C$ and
161
- an unknown set of nodes $U$, which are adjacent to $C$ . The boundary of the
162
- community $B$, consists of nodes in $C$ that have at least one nbr in $U$.
163
-
164
- Mathematically, the local modularity is expressed as:
165
-
166
- .. math::
167
- R = \frac{I}{T}
168
-
169
- where $T$ is the number of edges with one or more endpoints in $B$, and $I$ is the
170
- number of those edges with neither endpoint in $U$.
171
-
172
- Parameters
173
- ----------
174
- G : NetworkX graph
175
- The input graph.
176
-
177
- source : node
178
- The source node from which the community expansion begins.
179
-
180
- cutoff : int, optional (default=None)
181
- The maximum number of nodes to include in the community. If None, the algorithm
182
- expands until no further modularity gain can be made.
183
-
184
- method : string, optional (default='clauset')
185
- The algorithm to use to carry out greedy source expansion.
186
- Supported options: 'clauset'. Other inputs produce a ValueError
187
-
188
- Returns
189
- -------
190
- set
191
- A set of nodes representing the local community around the source node.
192
-
193
- Examples
194
- --------
195
- >>> G = nx.karate_club_graph()
196
- >>> nx.community.greedy_source_expansion(G, source=16)
197
- {16, 0, 4, 5, 6, 10}
198
-
199
- Notes
200
- -----
201
- This algorithm is designed for detecting local communities around a specific node,
202
- which is useful for large networks where global community detection is computationally
203
- expensive.
204
-
205
- The result of the algorithm may vary based on the structure of the graph, the choice of
206
- the source node, and the presence of ties between nodes during the greedy expansion process.
207
-
208
- References
209
- ----------
210
- .. [1] Clauset, Aaron. Finding local community structure in networks.
211
- Physical Review E—Statistical, Nonlinear, and Soft Matter Physics 72, no. 2 (2005): 026132.
212
- https://arxiv.org/pdf/physics/0503036
213
-
214
- """
215
- try:
216
- algo = ALGORITHMS[method]
217
- except KeyError as e:
218
- raise ValueError(f"{method} is not a valid choice for an algorithm.") from e
219
-
220
- return algo(G, source=source, cutoff=cutoff)
@@ -1,384 +0,0 @@
1
- """Functions for detecting communities based on Louvain Community Detection
2
- Algorithm"""
3
-
4
- import itertools
5
- from collections import defaultdict, deque
6
-
7
- import networkx as nx
8
- from networkx.algorithms.community import modularity
9
- from networkx.utils import py_random_state
10
-
11
- __all__ = ["louvain_communities", "louvain_partitions"]
12
-
13
-
14
- @py_random_state("seed")
15
- @nx._dispatchable(edge_attrs="weight")
16
- def louvain_communities(
17
- G, weight="weight", resolution=1, threshold=0.0000001, max_level=None, seed=None
18
- ):
19
- r"""Find the best partition of a graph using the Louvain Community Detection
20
- Algorithm.
21
-
22
- Louvain Community Detection Algorithm is a simple method to extract the community
23
- structure of a network. This is a heuristic method based on modularity optimization. [1]_
24
-
25
- The algorithm works in 2 steps. On the first step it assigns every node to be
26
- in its own community and then for each node it tries to find the maximum positive
27
- modularity gain by moving each node to all of its neighbor communities. If no positive
28
- gain is achieved the node remains in its original community.
29
-
30
- The modularity gain obtained by moving an isolated node $i$ into a community $C$ can
31
- easily be calculated by the following formula (combining [1]_ [2]_ and some algebra):
32
-
33
- .. math::
34
- \Delta Q = \frac{k_{i,in}}{2m} - \gamma\frac{ \Sigma_{tot} \cdot k_i}{2m^2}
35
-
36
- where $m$ is the size of the graph, $k_{i,in}$ is the sum of the weights of the links
37
- from $i$ to nodes in $C$, $k_i$ is the sum of the weights of the links incident to node $i$,
38
- $\Sigma_{tot}$ is the sum of the weights of the links incident to nodes in $C$ and $\gamma$
39
- is the resolution parameter.
40
-
41
- For the directed case the modularity gain can be computed using this formula according to [3]_
42
-
43
- .. math::
44
- \Delta Q = \frac{k_{i,in}}{m}
45
- - \gamma\frac{k_i^{out} \cdot\Sigma_{tot}^{in} + k_i^{in} \cdot \Sigma_{tot}^{out}}{m^2}
46
-
47
- where $k_i^{out}$, $k_i^{in}$ are the outer and inner weighted degrees of node $i$ and
48
- $\Sigma_{tot}^{in}$, $\Sigma_{tot}^{out}$ are the sum of in-going and out-going links incident
49
- to nodes in $C$.
50
-
51
- The first phase continues until no individual move can improve the modularity.
52
-
53
- The second phase consists in building a new network whose nodes are now the communities
54
- found in the first phase. To do so, the weights of the links between the new nodes are given by
55
- the sum of the weight of the links between nodes in the corresponding two communities. Once this
56
- phase is complete it is possible to reapply the first phase creating bigger communities with
57
- increased modularity.
58
-
59
- The above two phases are executed until no modularity gain is achieved (or is less than
60
- the `threshold`, or until `max_levels` is reached).
61
-
62
- Be careful with self-loops in the input graph. These are treated as
63
- previously reduced communities -- as if the process had been started
64
- in the middle of the algorithm. Large self-loop edge weights thus
65
- represent strong communities and in practice may be hard to add
66
- other nodes to. If your input graph edge weights for self-loops
67
- do not represent already reduced communities you may want to remove
68
- the self-loops before inputting that graph.
69
-
70
- Parameters
71
- ----------
72
- G : NetworkX graph
73
- weight : string or None, optional (default="weight")
74
- The name of an edge attribute that holds the numerical value
75
- used as a weight. If None then each edge has weight 1.
76
- resolution : float, optional (default=1)
77
- If resolution is less than 1, the algorithm favors larger communities.
78
- Greater than 1 favors smaller communities
79
- threshold : float, optional (default=0.0000001)
80
- Modularity gain threshold for each level. If the gain of modularity
81
- between 2 levels of the algorithm is less than the given threshold
82
- then the algorithm stops and returns the resulting communities.
83
- max_level : int or None, optional (default=None)
84
- The maximum number of levels (steps of the algorithm) to compute.
85
- Must be a positive integer or None. If None, then there is no max
86
- level and the threshold parameter determines the stopping condition.
87
- seed : integer, random_state, or None (default)
88
- Indicator of random number generation state.
89
- See :ref:`Randomness<randomness>`.
90
-
91
- Returns
92
- -------
93
- list
94
- A list of sets (partition of `G`). Each set represents one community and contains
95
- all the nodes that constitute it.
96
-
97
- Examples
98
- --------
99
- >>> import networkx as nx
100
- >>> G = nx.petersen_graph()
101
- >>> nx.community.louvain_communities(G, seed=123)
102
- [{0, 4, 5, 7, 9}, {1, 2, 3, 6, 8}]
103
-
104
- Notes
105
- -----
106
- The order in which the nodes are considered can affect the final output. In the algorithm
107
- the ordering happens using a random shuffle.
108
-
109
- References
110
- ----------
111
- .. [1] Blondel, V.D. et al. Fast unfolding of communities in
112
- large networks. J. Stat. Mech 10008, 1-12(2008). https://doi.org/10.1088/1742-5468/2008/10/P10008
113
- .. [2] Traag, V.A., Waltman, L. & van Eck, N.J. From Louvain to Leiden: guaranteeing
114
- well-connected communities. Sci Rep 9, 5233 (2019). https://doi.org/10.1038/s41598-019-41695-z
115
- .. [3] Nicolas Dugué, Anthony Perez. Directed Louvain : maximizing modularity in directed networks.
116
- [Research Report] Université d’Orléans. 2015. hal-01231784. https://hal.archives-ouvertes.fr/hal-01231784
117
-
118
- See Also
119
- --------
120
- louvain_partitions
121
- :any:`leiden_communities`
122
- """
123
-
124
- partitions = louvain_partitions(G, weight, resolution, threshold, seed)
125
- if max_level is not None:
126
- if max_level <= 0:
127
- raise ValueError("max_level argument must be a positive integer or None")
128
- partitions = itertools.islice(partitions, max_level)
129
- final_partition = deque(partitions, maxlen=1)
130
- return final_partition.pop()
131
-
132
-
133
- @py_random_state("seed")
134
- @nx._dispatchable(edge_attrs="weight")
135
- def louvain_partitions(
136
- G, weight="weight", resolution=1, threshold=0.0000001, seed=None
137
- ):
138
- """Yield partitions for each level of the Louvain Community Detection Algorithm
139
-
140
- Louvain Community Detection Algorithm is a simple method to extract the community
141
- structure of a network. This is a heuristic method based on modularity optimization. [1]_
142
-
143
- The partitions at each level (step of the algorithm) form a dendrogram of communities.
144
- A dendrogram is a diagram representing a tree and each level represents
145
- a partition of the G graph. The top level contains the smallest communities
146
- and as you traverse to the bottom of the tree the communities get bigger
147
- and the overall modularity increases making the partition better.
148
-
149
- Each level is generated by executing the two phases of the Louvain Community
150
- Detection Algorithm.
151
-
152
- Be careful with self-loops in the input graph. These are treated as
153
- previously reduced communities -- as if the process had been started
154
- in the middle of the algorithm. Large self-loop edge weights thus
155
- represent strong communities and in practice may be hard to add
156
- other nodes to. If your input graph edge weights for self-loops
157
- do not represent already reduced communities you may want to remove
158
- the self-loops before inputting that graph.
159
-
160
- Parameters
161
- ----------
162
- G : NetworkX graph
163
- weight : string or None, optional (default="weight")
164
- The name of an edge attribute that holds the numerical value
165
- used as a weight. If None then each edge has weight 1.
166
- resolution : float, optional (default=1)
167
- If resolution is less than 1, the algorithm favors larger communities.
168
- Greater than 1 favors smaller communities
169
- threshold : float, optional (default=0.0000001)
170
- Modularity gain threshold for each level. If the gain of modularity
171
- between 2 levels of the algorithm is less than the given threshold
172
- then the algorithm stops and returns the resulting communities.
173
- seed : integer, random_state, or None (default)
174
- Indicator of random number generation state.
175
- See :ref:`Randomness<randomness>`.
176
-
177
- Yields
178
- ------
179
- list
180
- A list of sets (partition of `G`). Each set represents one community and contains
181
- all the nodes that constitute it.
182
-
183
- References
184
- ----------
185
- .. [1] Blondel, V.D. et al. Fast unfolding of communities in
186
- large networks. J. Stat. Mech 10008, 1-12(2008)
187
-
188
- See Also
189
- --------
190
- louvain_communities
191
- :any:`leiden_partitions`
192
- """
193
-
194
- partition = [{u} for u in G.nodes()]
195
- if nx.is_empty(G):
196
- yield partition
197
- return
198
- mod = modularity(G, partition, resolution=resolution, weight=weight)
199
- is_directed = G.is_directed()
200
- if G.is_multigraph():
201
- graph = _convert_multigraph(G, weight, is_directed)
202
- else:
203
- graph = G.__class__()
204
- graph.add_nodes_from(G)
205
- graph.add_weighted_edges_from(G.edges(data=weight, default=1))
206
-
207
- m = graph.size(weight="weight")
208
- partition, inner_partition, improvement = _one_level(
209
- graph, m, partition, resolution, is_directed, seed
210
- )
211
- improvement = True
212
- while improvement:
213
- # gh-5901 protect the sets in the yielded list from further manipulation here
214
- yield [s.copy() for s in partition]
215
- new_mod = modularity(
216
- graph, inner_partition, resolution=resolution, weight="weight"
217
- )
218
- if new_mod - mod <= threshold:
219
- return
220
- mod = new_mod
221
- graph = _gen_graph(graph, inner_partition)
222
- partition, inner_partition, improvement = _one_level(
223
- graph, m, partition, resolution, is_directed, seed
224
- )
225
-
226
-
227
- def _one_level(G, m, partition, resolution=1, is_directed=False, seed=None):
228
- """Calculate one level of the Louvain partitions tree
229
-
230
- Parameters
231
- ----------
232
- G : NetworkX Graph/DiGraph
233
- The graph from which to detect communities
234
- m : number
235
- The size of the graph `G`.
236
- partition : list of sets of nodes
237
- A valid partition of the graph `G`
238
- resolution : positive number
239
- The resolution parameter for computing the modularity of a partition
240
- is_directed : bool
241
- True if `G` is a directed graph.
242
- seed : integer, random_state, or None (default)
243
- Indicator of random number generation state.
244
- See :ref:`Randomness<randomness>`.
245
-
246
- """
247
- node2com = {u: i for i, u in enumerate(G.nodes())}
248
- inner_partition = [{u} for u in G.nodes()]
249
- if is_directed:
250
- in_degrees = dict(G.in_degree(weight="weight"))
251
- out_degrees = dict(G.out_degree(weight="weight"))
252
- Stot_in = list(in_degrees.values())
253
- Stot_out = list(out_degrees.values())
254
- # Calculate weights for both in and out neighbors without considering self-loops
255
- nbrs = {}
256
- for u in G:
257
- nbrs[u] = defaultdict(float)
258
- for _, n, wt in G.out_edges(u, data="weight"):
259
- if u != n:
260
- nbrs[u][n] += wt
261
- for n, _, wt in G.in_edges(u, data="weight"):
262
- if u != n:
263
- nbrs[u][n] += wt
264
- else:
265
- degrees = dict(G.degree(weight="weight"))
266
- Stot = list(degrees.values())
267
- nbrs = {u: {v: data["weight"] for v, data in G[u].items() if v != u} for u in G}
268
- rand_nodes = list(G.nodes)
269
- seed.shuffle(rand_nodes)
270
- nb_moves = 1
271
- improvement = False
272
- while nb_moves > 0:
273
- nb_moves = 0
274
- for u in rand_nodes:
275
- best_mod = 0
276
- best_com = node2com[u]
277
- weights2com = _neighbor_weights(nbrs[u], node2com)
278
- if is_directed:
279
- in_degree = in_degrees[u]
280
- out_degree = out_degrees[u]
281
- Stot_in[best_com] -= in_degree
282
- Stot_out[best_com] -= out_degree
283
- remove_cost = (
284
- -weights2com[best_com] / m
285
- + resolution
286
- * (out_degree * Stot_in[best_com] + in_degree * Stot_out[best_com])
287
- / m**2
288
- )
289
- else:
290
- degree = degrees[u]
291
- Stot[best_com] -= degree
292
- remove_cost = -weights2com[best_com] / m + resolution * (
293
- Stot[best_com] * degree
294
- ) / (2 * m**2)
295
- for nbr_com, wt in weights2com.items():
296
- if is_directed:
297
- gain = (
298
- remove_cost
299
- + wt / m
300
- - resolution
301
- * (
302
- out_degree * Stot_in[nbr_com]
303
- + in_degree * Stot_out[nbr_com]
304
- )
305
- / m**2
306
- )
307
- else:
308
- gain = (
309
- remove_cost
310
- + wt / m
311
- - resolution * (Stot[nbr_com] * degree) / (2 * m**2)
312
- )
313
- if gain > best_mod:
314
- best_mod = gain
315
- best_com = nbr_com
316
- if is_directed:
317
- Stot_in[best_com] += in_degree
318
- Stot_out[best_com] += out_degree
319
- else:
320
- Stot[best_com] += degree
321
- if best_com != node2com[u]:
322
- com = G.nodes[u].get("nodes", {u})
323
- partition[node2com[u]].difference_update(com)
324
- inner_partition[node2com[u]].remove(u)
325
- partition[best_com].update(com)
326
- inner_partition[best_com].add(u)
327
- improvement = True
328
- nb_moves += 1
329
- node2com[u] = best_com
330
- partition = list(filter(len, partition))
331
- inner_partition = list(filter(len, inner_partition))
332
- return partition, inner_partition, improvement
333
-
334
-
335
- def _neighbor_weights(nbrs, node2com):
336
- """Calculate weights between node and its neighbor communities.
337
-
338
- Parameters
339
- ----------
340
- nbrs : dictionary
341
- Dictionary with nodes' neighbors as keys and their edge weight as value.
342
- node2com : dictionary
343
- Dictionary with all graph's nodes as keys and their community index as value.
344
-
345
- """
346
- weights = defaultdict(float)
347
- for nbr, wt in nbrs.items():
348
- weights[node2com[nbr]] += wt
349
- return weights
350
-
351
-
352
- def _gen_graph(G, partition):
353
- """Generate a new graph based on the partitions of a given graph"""
354
- H = G.__class__()
355
- node2com = {}
356
- for i, part in enumerate(partition):
357
- nodes = set()
358
- for node in part:
359
- node2com[node] = i
360
- nodes.update(G.nodes[node].get("nodes", {node}))
361
- H.add_node(i, nodes=nodes)
362
-
363
- for node1, node2, wt in G.edges(data=True):
364
- wt = wt["weight"]
365
- com1 = node2com[node1]
366
- com2 = node2com[node2]
367
- temp = H.get_edge_data(com1, com2, {"weight": 0})["weight"]
368
- H.add_edge(com1, com2, weight=wt + temp)
369
- return H
370
-
371
-
372
- def _convert_multigraph(G, weight, is_directed):
373
- """Convert a Multigraph to normal Graph"""
374
- if is_directed:
375
- H = nx.DiGraph()
376
- else:
377
- H = nx.Graph()
378
- H.add_nodes_from(G)
379
- for u, v, wt in G.edges(data=weight, default=1):
380
- if H.has_edge(u, v):
381
- H[u][v]["weight"] += wt
382
- else:
383
- H.add_edge(u, v, weight=wt)
384
- return H