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,227 +0,0 @@
1
- """Lukes Algorithm for exact optimal weighted tree partitioning."""
2
-
3
- from copy import deepcopy
4
- from functools import lru_cache
5
- from random import choice
6
-
7
- import networkx as nx
8
- from networkx.utils import not_implemented_for
9
-
10
- __all__ = ["lukes_partitioning"]
11
-
12
- D_EDGE_W = "weight"
13
- D_EDGE_VALUE = 1.0
14
- D_NODE_W = "weight"
15
- D_NODE_VALUE = 1
16
- PKEY = "partitions"
17
- CLUSTER_EVAL_CACHE_SIZE = 2048
18
-
19
-
20
- def _split_n_from(n, min_size_of_first_part):
21
- # splits j in two parts of which the first is at least
22
- # the second argument
23
- assert n >= min_size_of_first_part
24
- for p1 in range(min_size_of_first_part, n + 1):
25
- yield p1, n - p1
26
-
27
-
28
- @nx._dispatchable(node_attrs="node_weight", edge_attrs="edge_weight")
29
- def lukes_partitioning(G, max_size, node_weight=None, edge_weight=None):
30
- """Optimal partitioning of a weighted tree using the Lukes algorithm.
31
-
32
- This algorithm partitions a connected, acyclic graph featuring integer
33
- node weights and float edge weights. The resulting clusters are such
34
- that the total weight of the nodes in each cluster does not exceed
35
- max_size and that the weight of the edges that are cut by the partition
36
- is minimum. The algorithm is based on [1]_.
37
-
38
- Parameters
39
- ----------
40
- G : NetworkX graph
41
-
42
- max_size : int
43
- Maximum weight a partition can have in terms of sum of
44
- node_weight for all nodes in the partition
45
-
46
- edge_weight : key
47
- Edge data key to use as weight. If None, the weights are all
48
- set to one.
49
-
50
- node_weight : key
51
- Node data key to use as weight. If None, the weights are all
52
- set to one. The data must be int.
53
-
54
- Returns
55
- -------
56
- partition : list
57
- A list of sets of nodes representing the clusters of the
58
- partition.
59
-
60
- Raises
61
- ------
62
- NotATree
63
- If G is not a tree.
64
- TypeError
65
- If any of the values of node_weight is not int.
66
-
67
- References
68
- ----------
69
- .. [1] Lukes, J. A. (1974).
70
- "Efficient Algorithm for the Partitioning of Trees."
71
- IBM Journal of Research and Development, 18(3), 217–224.
72
-
73
- """
74
- # First sanity check and tree preparation
75
- if not nx.is_tree(G):
76
- raise nx.NotATree("lukes_partitioning works only on trees")
77
- else:
78
- if nx.is_directed(G):
79
- root = [n for n, d in G.in_degree() if d == 0]
80
- assert len(root) == 1
81
- root = root[0]
82
- t_G = deepcopy(G)
83
- else:
84
- root = choice(list(G.nodes))
85
- # this has the desirable side effect of not inheriting attributes
86
- t_G = nx.dfs_tree(G, root)
87
-
88
- # Since we do not want to screw up the original graph,
89
- # if we have a blank attribute, we make a deepcopy
90
- if edge_weight is None or node_weight is None:
91
- safe_G = deepcopy(G)
92
- if edge_weight is None:
93
- nx.set_edge_attributes(safe_G, D_EDGE_VALUE, D_EDGE_W)
94
- edge_weight = D_EDGE_W
95
- if node_weight is None:
96
- nx.set_node_attributes(safe_G, D_NODE_VALUE, D_NODE_W)
97
- node_weight = D_NODE_W
98
- else:
99
- safe_G = G
100
-
101
- # Second sanity check
102
- # The values of node_weight MUST BE int.
103
- # I cannot see any room for duck typing without incurring serious
104
- # danger of subtle bugs.
105
- all_n_attr = nx.get_node_attributes(safe_G, node_weight).values()
106
- for x in all_n_attr:
107
- if not isinstance(x, int):
108
- raise TypeError(
109
- "lukes_partitioning needs integer "
110
- f"values for node_weight ({node_weight})"
111
- )
112
-
113
- # SUBROUTINES -----------------------
114
- # these functions are defined here for two reasons:
115
- # - brevity: we can leverage global "safe_G"
116
- # - caching: signatures are hashable
117
-
118
- @not_implemented_for("undirected")
119
- # this is intended to be called only on t_G
120
- def _leaves(gr):
121
- for x in gr.nodes:
122
- if not nx.descendants(gr, x):
123
- yield x
124
-
125
- @not_implemented_for("undirected")
126
- def _a_parent_of_leaves_only(gr):
127
- tleaves = set(_leaves(gr))
128
- for n in set(gr.nodes) - tleaves:
129
- if all(x in tleaves for x in nx.descendants(gr, n)):
130
- return n
131
-
132
- @lru_cache(CLUSTER_EVAL_CACHE_SIZE)
133
- def _value_of_cluster(cluster):
134
- valid_edges = [e for e in safe_G.edges if e[0] in cluster and e[1] in cluster]
135
- return sum(safe_G.edges[e][edge_weight] for e in valid_edges)
136
-
137
- def _value_of_partition(partition):
138
- return sum(_value_of_cluster(frozenset(c)) for c in partition)
139
-
140
- @lru_cache(CLUSTER_EVAL_CACHE_SIZE)
141
- def _weight_of_cluster(cluster):
142
- return sum(safe_G.nodes[n][node_weight] for n in cluster)
143
-
144
- def _pivot(partition, node):
145
- ccx = [c for c in partition if node in c]
146
- assert len(ccx) == 1
147
- return ccx[0]
148
-
149
- def _concatenate_or_merge(partition_1, partition_2, x, i, ref_weight):
150
- ccx = _pivot(partition_1, x)
151
- cci = _pivot(partition_2, i)
152
- merged_xi = ccx.union(cci)
153
-
154
- # We first check if we can do the merge.
155
- # If so, we do the actual calculations, otherwise we concatenate
156
- if _weight_of_cluster(frozenset(merged_xi)) <= ref_weight:
157
- cp1 = list(filter(lambda x: x != ccx, partition_1))
158
- cp2 = list(filter(lambda x: x != cci, partition_2))
159
-
160
- option_2 = [merged_xi] + cp1 + cp2
161
- return option_2, _value_of_partition(option_2)
162
- else:
163
- option_1 = partition_1 + partition_2
164
- return option_1, _value_of_partition(option_1)
165
-
166
- # INITIALIZATION -----------------------
167
- leaves = set(_leaves(t_G))
168
- for lv in leaves:
169
- t_G.nodes[lv][PKEY] = {}
170
- slot = safe_G.nodes[lv][node_weight]
171
- t_G.nodes[lv][PKEY][slot] = [{lv}]
172
- t_G.nodes[lv][PKEY][0] = [{lv}]
173
-
174
- for inner in [x for x in t_G.nodes if x not in leaves]:
175
- t_G.nodes[inner][PKEY] = {}
176
- slot = safe_G.nodes[inner][node_weight]
177
- t_G.nodes[inner][PKEY][slot] = [{inner}]
178
- nx._clear_cache(t_G)
179
-
180
- # CORE ALGORITHM -----------------------
181
- while True:
182
- x_node = _a_parent_of_leaves_only(t_G)
183
- weight_of_x = safe_G.nodes[x_node][node_weight]
184
- best_value = 0
185
- best_partition = None
186
- bp_buffer = {}
187
- x_descendants = nx.descendants(t_G, x_node)
188
- for i_node in x_descendants:
189
- for j in range(weight_of_x, max_size + 1):
190
- for a, b in _split_n_from(j, weight_of_x):
191
- if (
192
- a not in t_G.nodes[x_node][PKEY]
193
- or b not in t_G.nodes[i_node][PKEY]
194
- ):
195
- # it's not possible to form this particular weight sum
196
- continue
197
-
198
- part1 = t_G.nodes[x_node][PKEY][a]
199
- part2 = t_G.nodes[i_node][PKEY][b]
200
- part, value = _concatenate_or_merge(part1, part2, x_node, i_node, j)
201
-
202
- if j not in bp_buffer or bp_buffer[j][1] < value:
203
- # we annotate in the buffer the best partition for j
204
- bp_buffer[j] = part, value
205
-
206
- # we also keep track of the overall best partition
207
- if best_value <= value:
208
- best_value = value
209
- best_partition = part
210
-
211
- # as illustrated in Lukes, once we finished a child, we can
212
- # discharge the partitions we found into the graph
213
- # (the key phrase is make all x == x')
214
- # so that they are used by the subsequent children
215
- for w, (best_part_for_vl, vl) in bp_buffer.items():
216
- t_G.nodes[x_node][PKEY][w] = best_part_for_vl
217
- bp_buffer.clear()
218
-
219
- # the absolute best partition for this node
220
- # across all weights has to be stored at 0
221
- t_G.nodes[x_node][PKEY][0] = best_partition
222
- t_G.remove_nodes_from(x_descendants)
223
-
224
- if x_node == root:
225
- # the 0-labeled partition of root
226
- # is the optimal one for the whole tree
227
- return t_G.nodes[root][PKEY][0]
@@ -1,452 +0,0 @@
1
- """Functions for detecting communities based on modularity."""
2
-
3
- import random
4
- from collections import defaultdict
5
- from copy import deepcopy
6
-
7
- import networkx as nx
8
- from networkx.algorithms.community.quality import modularity
9
- from networkx.utils.mapped_queue import MappedQueue
10
-
11
- __all__ = [
12
- "greedy_modularity_communities",
13
- "naive_greedy_modularity_communities",
14
- ]
15
-
16
-
17
- def _greedy_modularity_communities_generator(G, weight=None, resolution=1):
18
- r"""Yield community partitions of G and the modularity change at each step.
19
-
20
- This function performs Clauset-Newman-Moore greedy modularity maximization [2]_
21
- At each step of the process it yields the change in modularity that will occur in
22
- the next step followed by yielding the new community partition after that step.
23
-
24
- Greedy modularity maximization begins with each node in its own community
25
- and repeatedly joins the pair of communities that lead to the largest
26
- modularity until one community contains all nodes (the partition has one set).
27
-
28
- This function maximizes the generalized modularity, where `resolution`
29
- is the resolution parameter, often expressed as $\gamma$.
30
- See :func:`~networkx.algorithms.community.quality.modularity`.
31
-
32
- Parameters
33
- ----------
34
- G : NetworkX graph
35
-
36
- weight : string or None, optional (default=None)
37
- The name of an edge attribute that holds the numerical value used
38
- as a weight. If None, then each edge has weight 1.
39
- The degree is the sum of the edge weights adjacent to the node.
40
-
41
- resolution : float (default=1)
42
- If resolution is less than 1, modularity favors larger communities.
43
- Greater than 1 favors smaller communities.
44
-
45
- Yields
46
- ------
47
- Alternating yield statements produce the following two objects:
48
-
49
- communities: dict_values
50
- A dict_values of frozensets of nodes, one for each community.
51
- This represents a partition of the nodes of the graph into communities.
52
- The first yield is the partition with each node in its own community.
53
-
54
- dq: float
55
- The change in modularity when merging the next two communities
56
- that leads to the largest modularity.
57
-
58
- See Also
59
- --------
60
- modularity
61
-
62
- References
63
- ----------
64
- .. [1] Newman, M. E. J. "Networks: An Introduction", page 224
65
- Oxford University Press 2011.
66
- .. [2] Clauset, A., Newman, M. E., & Moore, C.
67
- "Finding community structure in very large networks."
68
- Physical Review E 70(6), 2004.
69
- .. [3] Reichardt and Bornholdt "Statistical Mechanics of Community
70
- Detection" Phys. Rev. E74, 2006.
71
- .. [4] Newman, M. E. J."Analysis of weighted networks"
72
- Physical Review E 70(5 Pt 2):056131, 2004.
73
- """
74
- directed = G.is_directed()
75
- N = G.number_of_nodes()
76
-
77
- # Count edges (or the sum of edge-weights for weighted graphs)
78
- m = G.size(weight)
79
- q0 = 1 / m
80
-
81
- # Calculate degrees (notation from the papers)
82
- # a : the fraction of (weighted) out-degree for each node
83
- # b : the fraction of (weighted) in-degree for each node
84
- if directed:
85
- a = {node: deg_out * q0 for node, deg_out in G.out_degree(weight=weight)}
86
- b = {node: deg_in * q0 for node, deg_in in G.in_degree(weight=weight)}
87
- else:
88
- a = b = {node: deg * q0 * 0.5 for node, deg in G.degree(weight=weight)}
89
-
90
- # this preliminary step collects the edge weights for each node pair
91
- # It handles multigraph and digraph and works fine for graph.
92
- dq_dict = defaultdict(lambda: defaultdict(float))
93
- for u, v, wt in G.edges(data=weight, default=1):
94
- if u == v:
95
- continue
96
- dq_dict[u][v] += wt
97
- dq_dict[v][u] += wt
98
-
99
- # now scale and subtract the expected edge-weights term
100
- for u, nbrdict in dq_dict.items():
101
- for v, wt in nbrdict.items():
102
- dq_dict[u][v] = q0 * wt - resolution * (a[u] * b[v] + b[u] * a[v])
103
-
104
- # Use -dq to get a max_heap instead of a min_heap
105
- # dq_heap holds a heap for each node's neighbors
106
- dq_heap = {u: MappedQueue({(u, v): -dq for v, dq in dq_dict[u].items()}) for u in G}
107
- # H -> all_dq_heap holds a heap with the best items for each node
108
- H = MappedQueue([dq_heap[n].heap[0] for n in G if len(dq_heap[n]) > 0])
109
-
110
- # Initialize single-node communities
111
- communities = {n: frozenset([n]) for n in G}
112
- yield communities.values()
113
-
114
- # Merge the two communities that lead to the largest modularity
115
- while len(H) > 1:
116
- # Find best merge
117
- # Remove from heap of row maxes
118
- # Ties will be broken by choosing the pair with lowest min community id
119
- try:
120
- negdq, u, v = H.pop()
121
- except IndexError:
122
- break
123
- dq = -negdq
124
- yield dq
125
- # Remove best merge from row u heap
126
- dq_heap[u].pop()
127
- # Push new row max onto H
128
- if len(dq_heap[u]) > 0:
129
- H.push(dq_heap[u].heap[0])
130
- # If this element was also at the root of row v, we need to remove the
131
- # duplicate entry from H
132
- if dq_heap[v].heap[0] == (v, u):
133
- H.remove((v, u))
134
- # Remove best merge from row v heap
135
- dq_heap[v].remove((v, u))
136
- # Push new row max onto H
137
- if len(dq_heap[v]) > 0:
138
- H.push(dq_heap[v].heap[0])
139
- else:
140
- # Duplicate wasn't in H, just remove from row v heap
141
- dq_heap[v].remove((v, u))
142
-
143
- # Perform merge
144
- communities[v] = frozenset(communities[u] | communities[v])
145
- del communities[u]
146
-
147
- # Get neighbor communities connected to the merged communities
148
- u_nbrs = set(dq_dict[u])
149
- v_nbrs = set(dq_dict[v])
150
- all_nbrs = (u_nbrs | v_nbrs) - {u, v}
151
- both_nbrs = u_nbrs & v_nbrs
152
- # Update dq for merge of u into v
153
- for w in all_nbrs:
154
- # Calculate new dq value
155
- if w in both_nbrs:
156
- dq_vw = dq_dict[v][w] + dq_dict[u][w]
157
- elif w in v_nbrs:
158
- dq_vw = dq_dict[v][w] - resolution * (a[u] * b[w] + a[w] * b[u])
159
- else: # w in u_nbrs
160
- dq_vw = dq_dict[u][w] - resolution * (a[v] * b[w] + a[w] * b[v])
161
- # Update rows v and w
162
- for row, col in [(v, w), (w, v)]:
163
- dq_heap_row = dq_heap[row]
164
- # Update dict for v,w only (u is removed below)
165
- dq_dict[row][col] = dq_vw
166
- # Save old max of per-row heap
167
- if len(dq_heap_row) > 0:
168
- d_oldmax = dq_heap_row.heap[0]
169
- else:
170
- d_oldmax = None
171
- # Add/update heaps
172
- d = (row, col)
173
- d_negdq = -dq_vw
174
- # Save old value for finding heap index
175
- if w in v_nbrs:
176
- # Update existing element in per-row heap
177
- dq_heap_row.update(d, d, priority=d_negdq)
178
- else:
179
- # We're creating a new nonzero element, add to heap
180
- dq_heap_row.push(d, priority=d_negdq)
181
- # Update heap of row maxes if necessary
182
- if d_oldmax is None:
183
- # No entries previously in this row, push new max
184
- H.push(d, priority=d_negdq)
185
- else:
186
- # We've updated an entry in this row, has the max changed?
187
- row_max = dq_heap_row.heap[0]
188
- if d_oldmax != row_max or d_oldmax.priority != row_max.priority:
189
- H.update(d_oldmax, row_max)
190
-
191
- # Remove row/col u from dq_dict matrix
192
- for w in dq_dict[u]:
193
- # Remove from dict
194
- dq_old = dq_dict[w][u]
195
- del dq_dict[w][u]
196
- # Remove from heaps if we haven't already
197
- if w != v:
198
- # Remove both row and column
199
- for row, col in [(w, u), (u, w)]:
200
- dq_heap_row = dq_heap[row]
201
- # Check if replaced dq is row max
202
- d_old = (row, col)
203
- if dq_heap_row.heap[0] == d_old:
204
- # Update per-row heap and heap of row maxes
205
- dq_heap_row.remove(d_old)
206
- H.remove(d_old)
207
- # Update row max
208
- if len(dq_heap_row) > 0:
209
- H.push(dq_heap_row.heap[0])
210
- else:
211
- # Only update per-row heap
212
- dq_heap_row.remove(d_old)
213
-
214
- del dq_dict[u]
215
- # Mark row u as deleted, but keep placeholder
216
- dq_heap[u] = MappedQueue()
217
- # Merge u into v and update a
218
- a[v] += a[u]
219
- a[u] = 0
220
- if directed:
221
- b[v] += b[u]
222
- b[u] = 0
223
-
224
- yield communities.values()
225
-
226
-
227
- @nx._dispatchable(edge_attrs="weight")
228
- def greedy_modularity_communities(
229
- G,
230
- weight=None,
231
- resolution=1,
232
- cutoff=1,
233
- best_n=None,
234
- ):
235
- r"""Find communities in G using greedy modularity maximization.
236
-
237
- This function uses Clauset-Newman-Moore greedy modularity maximization [2]_
238
- to find the community partition with the largest modularity.
239
-
240
- Greedy modularity maximization begins with each node in its own community
241
- and repeatedly joins the pair of communities that lead to the largest
242
- modularity until no further increase in modularity is possible (a maximum).
243
- Two keyword arguments adjust the stopping condition. `cutoff` is a lower
244
- limit on the number of communities so you can stop the process before
245
- reaching a maximum (used to save computation time). `best_n` is an upper
246
- limit on the number of communities so you can make the process continue
247
- until at most n communities remain even if the maximum modularity occurs
248
- for more. To obtain exactly n communities, set both `cutoff` and `best_n` to n.
249
-
250
- This function maximizes the generalized modularity, where `resolution`
251
- is the resolution parameter, often expressed as $\gamma$.
252
- See :func:`~networkx.algorithms.community.quality.modularity`.
253
-
254
- Parameters
255
- ----------
256
- G : NetworkX graph
257
-
258
- weight : string or None, optional (default=None)
259
- The name of an edge attribute that holds the numerical value used
260
- as a weight. If None, then each edge has weight 1.
261
- The degree is the sum of the edge weights adjacent to the node.
262
-
263
- resolution : float, optional (default=1)
264
- If resolution is less than 1, modularity favors larger communities.
265
- Greater than 1 favors smaller communities.
266
-
267
- cutoff : int, optional (default=1)
268
- A minimum number of communities below which the merging process stops.
269
- The process stops at this number of communities even if modularity
270
- is not maximized. The goal is to let the user stop the process early.
271
- The process stops before the cutoff if it finds a maximum of modularity.
272
-
273
- best_n : int or None, optional (default=None)
274
- A maximum number of communities above which the merging process will
275
- not stop. This forces community merging to continue after modularity
276
- starts to decrease until `best_n` communities remain.
277
- If ``None``, don't force it to continue beyond a maximum.
278
-
279
- Raises
280
- ------
281
- ValueError : If the `cutoff` or `best_n` value is not in the range
282
- ``[1, G.number_of_nodes()]``, or if `best_n` < `cutoff`.
283
-
284
- Returns
285
- -------
286
- communities: list
287
- A list of frozensets of nodes, one for each community.
288
- Sorted by length with largest communities first.
289
-
290
- Examples
291
- --------
292
- >>> G = nx.karate_club_graph()
293
- >>> c = nx.community.greedy_modularity_communities(G)
294
- >>> sorted(c[0])
295
- [8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
296
-
297
- See Also
298
- --------
299
- modularity
300
-
301
- References
302
- ----------
303
- .. [1] Newman, M. E. J. "Networks: An Introduction", page 224
304
- Oxford University Press 2011.
305
- .. [2] Clauset, A., Newman, M. E., & Moore, C.
306
- "Finding community structure in very large networks."
307
- Physical Review E 70(6), 2004.
308
- .. [3] Reichardt and Bornholdt "Statistical Mechanics of Community
309
- Detection" Phys. Rev. E74, 2006.
310
- .. [4] Newman, M. E. J."Analysis of weighted networks"
311
- Physical Review E 70(5 Pt 2):056131, 2004.
312
- """
313
- if not G.size():
314
- return [{n} for n in G]
315
-
316
- if (cutoff < 1) or (cutoff > G.number_of_nodes()):
317
- raise ValueError(f"cutoff must be between 1 and {len(G)}. Got {cutoff}.")
318
- if best_n is not None:
319
- if (best_n < 1) or (best_n > G.number_of_nodes()):
320
- raise ValueError(f"best_n must be between 1 and {len(G)}. Got {best_n}.")
321
- if best_n < cutoff:
322
- raise ValueError(f"Must have best_n >= cutoff. Got {best_n} < {cutoff}")
323
- if best_n == 1:
324
- return [set(G)]
325
- else:
326
- best_n = G.number_of_nodes()
327
-
328
- # retrieve generator object to construct output
329
- community_gen = _greedy_modularity_communities_generator(
330
- G, weight=weight, resolution=resolution
331
- )
332
-
333
- # construct the first best community
334
- communities = next(community_gen)
335
-
336
- # continue merging communities until one of the breaking criteria is satisfied
337
- while len(communities) > cutoff:
338
- try:
339
- dq = next(community_gen)
340
- # StopIteration occurs when communities are the connected components
341
- except StopIteration:
342
- communities = sorted(communities, key=len, reverse=True)
343
- # if best_n requires more merging, merge big sets for highest modularity
344
- while len(communities) > best_n:
345
- comm1, comm2, *rest = communities
346
- communities = [comm1 ^ comm2]
347
- communities.extend(rest)
348
- return communities
349
-
350
- # keep going unless max_mod is reached or best_n says to merge more
351
- if dq < 0 and len(communities) <= best_n:
352
- break
353
- communities = next(community_gen)
354
-
355
- return sorted(communities, key=len, reverse=True)
356
-
357
-
358
- @nx.utils.not_implemented_for("directed")
359
- @nx.utils.not_implemented_for("multigraph")
360
- @nx._dispatchable(edge_attrs="weight")
361
- def naive_greedy_modularity_communities(G, resolution=1, weight=None):
362
- r"""Find communities in G using greedy modularity maximization.
363
-
364
- This implementation is O(n^4), much slower than alternatives, but it is
365
- provided as an easy-to-understand reference implementation.
366
-
367
- Greedy modularity maximization begins with each node in its own community
368
- and joins the pair of communities that most increases modularity until no
369
- such pair exists.
370
-
371
- This function maximizes the generalized modularity, where `resolution`
372
- is the resolution parameter, often expressed as $\gamma$.
373
- See :func:`~networkx.algorithms.community.quality.modularity`.
374
-
375
- Parameters
376
- ----------
377
- G : NetworkX graph
378
- Graph must be simple and undirected.
379
-
380
- resolution : float (default=1)
381
- If resolution is less than 1, modularity favors larger communities.
382
- Greater than 1 favors smaller communities.
383
-
384
- weight : string or None, optional (default=None)
385
- The name of an edge attribute that holds the numerical value used
386
- as a weight. If None, then each edge has weight 1.
387
- The degree is the sum of the edge weights adjacent to the node.
388
-
389
- Returns
390
- -------
391
- list
392
- A list of sets of nodes, one for each community.
393
- Sorted by length with largest communities first.
394
-
395
- Examples
396
- --------
397
- >>> G = nx.karate_club_graph()
398
- >>> c = nx.community.naive_greedy_modularity_communities(G)
399
- >>> sorted(c[0])
400
- [8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
401
-
402
- See Also
403
- --------
404
- greedy_modularity_communities
405
- modularity
406
- """
407
- # First create one community for each node
408
- communities = [frozenset([u]) for u in G.nodes()]
409
- # Track merges
410
- merges = []
411
- # Greedily merge communities until no improvement is possible
412
- old_modularity = None
413
- new_modularity = modularity(G, communities, resolution=resolution, weight=weight)
414
- while old_modularity is None or new_modularity > old_modularity:
415
- # Save modularity for comparison
416
- old_modularity = new_modularity
417
- # Find best pair to merge
418
- trial_communities = list(communities)
419
- to_merge = None
420
- for i, u in enumerate(communities):
421
- for j, v in enumerate(communities):
422
- # Skip i==j and empty communities
423
- if j <= i or len(u) == 0 or len(v) == 0:
424
- continue
425
- # Merge communities u and v
426
- trial_communities[j] = u | v
427
- trial_communities[i] = frozenset([])
428
- trial_modularity = modularity(
429
- G, trial_communities, resolution=resolution, weight=weight
430
- )
431
- if trial_modularity >= new_modularity:
432
- # Check if strictly better or tie
433
- if trial_modularity > new_modularity:
434
- # Found new best, save modularity and group indexes
435
- new_modularity = trial_modularity
436
- to_merge = (i, j, new_modularity - old_modularity)
437
- elif to_merge and min(i, j) < min(to_merge[0], to_merge[1]):
438
- # Break ties by choosing pair with lowest min id
439
- new_modularity = trial_modularity
440
- to_merge = (i, j, new_modularity - old_modularity)
441
- # Un-merge
442
- trial_communities[i] = u
443
- trial_communities[j] = v
444
- if to_merge is not None:
445
- # If the best merge improves modularity, use it
446
- merges.append(to_merge)
447
- i, j, dq = to_merge
448
- u, v = communities[i], communities[j]
449
- communities[j] = u | v
450
- communities[i] = frozenset([])
451
- # Remove empty communities and sort
452
- return sorted((c for c in communities if len(c) > 0), key=len, reverse=True)