okstra 0.130.3 → 0.131.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) 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 +21 -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/report_views.py +32 -5
  27. package/runtime/python/okstra_ctl/run.py +15 -3
  28. package/runtime/python/okstra_ctl/worker_prompt_contract.py +14 -6
  29. package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -1
  30. package/runtime/python/okstra_vendor/__init__.py +0 -44
  31. package/runtime/schemas/final-report-v1.0.schema.json +101 -6
  32. package/runtime/skills/okstra-run/SKILL.md +11 -4
  33. package/runtime/skills/okstra-setup/SKILL.md +3 -2
  34. package/runtime/skills/okstra-setup/references/project-config.md +16 -7
  35. package/runtime/templates/reports/final-report.template.md +18 -12
  36. package/runtime/templates/reports/i18n/en.json +1 -0
  37. package/runtime/templates/reports/i18n/ko.json +1 -0
  38. package/runtime/templates/reports/report.css +18 -0
  39. package/runtime/validators/lib/fixtures.sh +6 -0
  40. package/runtime/validators/validate-run.py +1722 -98
  41. package/src/cli-registry.mjs +0 -7
  42. package/src/commands/lifecycle/doctor.mjs +0 -9
  43. package/src/lib/skill-catalog.mjs +0 -1
  44. package/docs/for-ai/skills/okstra-graphify.md +0 -64
  45. package/runtime/python/okstra_ctl/graphify_cmd.py +0 -225
  46. package/runtime/python/okstra_vendor/graphify/.vendored-version +0 -1
  47. package/runtime/python/okstra_vendor/graphify/__init__.py +0 -28
  48. package/runtime/python/okstra_vendor/graphify/__main__.py +0 -1371
  49. package/runtime/python/okstra_vendor/graphify/analyze.py +0 -540
  50. package/runtime/python/okstra_vendor/graphify/benchmark.py +0 -129
  51. package/runtime/python/okstra_vendor/graphify/build.py +0 -107
  52. package/runtime/python/okstra_vendor/graphify/cache.py +0 -169
  53. package/runtime/python/okstra_vendor/graphify/cluster.py +0 -137
  54. package/runtime/python/okstra_vendor/graphify/detect.py +0 -510
  55. package/runtime/python/okstra_vendor/graphify/export.py +0 -1014
  56. package/runtime/python/okstra_vendor/graphify/extract.py +0 -3277
  57. package/runtime/python/okstra_vendor/graphify/hooks.py +0 -220
  58. package/runtime/python/okstra_vendor/graphify/ingest.py +0 -297
  59. package/runtime/python/okstra_vendor/graphify/manifest.py +0 -4
  60. package/runtime/python/okstra_vendor/graphify/report.py +0 -175
  61. package/runtime/python/okstra_vendor/graphify/security.py +0 -203
  62. package/runtime/python/okstra_vendor/graphify/serve.py +0 -373
  63. package/runtime/python/okstra_vendor/graphify/skill-aider.md +0 -1184
  64. package/runtime/python/okstra_vendor/graphify/skill-claw.md +0 -1184
  65. package/runtime/python/okstra_vendor/graphify/skill-codex.md +0 -1242
  66. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +0 -1268
  67. package/runtime/python/okstra_vendor/graphify/skill-droid.md +0 -1239
  68. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +0 -1183
  69. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +0 -1238
  70. package/runtime/python/okstra_vendor/graphify/skill-trae.md +0 -1208
  71. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +0 -253
  72. package/runtime/python/okstra_vendor/graphify/skill-windows.md +0 -1245
  73. package/runtime/python/okstra_vendor/graphify/skill.md +0 -1319
  74. package/runtime/python/okstra_vendor/graphify/transcribe.py +0 -182
  75. package/runtime/python/okstra_vendor/graphify/validate.py +0 -72
  76. package/runtime/python/okstra_vendor/graphify/watch.py +0 -188
  77. package/runtime/python/okstra_vendor/graphify/wiki.py +0 -214
  78. package/runtime/python/okstra_vendor/networkx/__init__.py +0 -62
  79. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +0 -134
  80. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +0 -26
  81. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +0 -259
  82. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +0 -71
  83. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +0 -412
  84. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +0 -396
  85. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +0 -150
  86. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +0 -149
  87. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +0 -369
  88. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +0 -44
  89. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +0 -143
  90. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +0 -53
  91. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +0 -265
  92. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +0 -1508
  93. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +0 -255
  94. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +0 -83
  95. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +0 -5
  96. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +0 -122
  97. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +0 -302
  98. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +0 -255
  99. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +0 -160
  100. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +0 -127
  101. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +0 -164
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +0 -88
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +0 -322
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +0 -290
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +0 -289
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +0 -57
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +0 -360
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +0 -105
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +0 -603
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +0 -316
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +0 -590
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +0 -232
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +0 -526
  114. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +0 -112
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +0 -69
  116. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +0 -168
  117. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +0 -205
  118. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +0 -164
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +0 -20
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +0 -591
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +0 -236
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +0 -282
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +0 -364
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +0 -227
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +0 -96
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +0 -150
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +0 -107
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +0 -357
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +0 -130
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +0 -787
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +0 -88
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +0 -331
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +0 -150
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +0 -200
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +0 -128
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +0 -209
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +0 -141
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +0 -361
  139. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +0 -181
  140. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +0 -95
  141. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +0 -172
  142. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +0 -443
  143. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +0 -818
  144. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +0 -732
  145. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +0 -4
  146. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +0 -505
  147. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +0 -565
  148. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +0 -163
  149. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +0 -28
  150. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +0 -153
  151. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +0 -354
  152. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +0 -171
  153. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +0 -30
  154. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +0 -216
  155. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +0 -79
  156. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +0 -338
  157. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +0 -162
  158. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +0 -220
  159. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +0 -384
  160. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +0 -227
  161. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +0 -452
  162. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +0 -347
  163. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +0 -6
  164. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +0 -115
  165. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +0 -394
  166. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +0 -282
  167. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +0 -71
  168. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +0 -359
  169. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +0 -196
  170. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +0 -11
  171. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +0 -811
  172. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +0 -616
  173. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +0 -408
  174. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +0 -1270
  175. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +0 -592
  176. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +0 -220
  177. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +0 -235
  178. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +0 -152
  179. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +0 -88
  180. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +0 -588
  181. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +0 -142
  182. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +0 -416
  183. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +0 -1234
  184. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +0 -677
  185. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +0 -1392
  186. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +0 -1095
  187. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +0 -272
  188. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +0 -142
  189. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +0 -268
  190. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +0 -167
  191. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +0 -470
  192. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +0 -11
  193. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +0 -370
  194. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +0 -407
  195. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +0 -238
  196. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +0 -241
  197. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +0 -178
  198. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +0 -611
  199. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +0 -356
  200. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +0 -662
  201. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +0 -425
  202. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +0 -300
  203. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +0 -194
  204. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +0 -435
  205. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +0 -483
  206. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +0 -57
  207. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +0 -196
  208. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +0 -107
  209. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +0 -7
  210. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +0 -1306
  211. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +0 -336
  212. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +0 -1262
  213. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +0 -352
  214. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +0 -308
  215. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +0 -264
  216. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +0 -1102
  217. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +0 -192
  218. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +0 -2
  219. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +0 -337
  220. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +0 -498
  221. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +0 -687
  222. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +0 -280
  223. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +0 -1148
  224. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +0 -27
  225. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +0 -738
  226. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +0 -78
  227. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +0 -59
  228. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +0 -219
  229. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +0 -155
  230. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +0 -4
  231. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +0 -324
  232. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +0 -468
  233. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +0 -633
  234. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +0 -77
  235. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +0 -73
  236. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +0 -464
  237. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +0 -1463
  238. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +0 -306
  239. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +0 -98
  240. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +0 -167
  241. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +0 -138
  242. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +0 -5
  243. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +0 -239
  244. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +0 -264
  245. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +0 -716
  246. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +0 -625
  247. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +0 -2542
  248. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +0 -2107
  249. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +0 -966
  250. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +0 -404
  251. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +0 -30
  252. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +0 -296
  253. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +0 -374
  254. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +0 -564
  255. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +0 -406
  256. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +0 -981
  257. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +0 -142
  258. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +0 -406
  259. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +0 -5
  260. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +0 -90
  261. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +0 -576
  262. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +0 -529
  263. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +0 -185
  264. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +0 -182
  265. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +0 -7
  266. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +0 -1042
  267. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +0 -413
  268. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +0 -88
  269. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +0 -219
  270. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +0 -1281
  271. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +0 -106
  272. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +0 -273
  273. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +0 -500
  274. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +0 -76
  275. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +0 -86
  276. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +0 -77
  277. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +0 -278
  278. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +0 -13
  279. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +0 -435
  280. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +0 -1363
  281. package/runtime/python/okstra_vendor/networkx/classes/filters.py +0 -95
  282. package/runtime/python/okstra_vendor/networkx/classes/function.py +0 -1549
  283. package/runtime/python/okstra_vendor/networkx/classes/graph.py +0 -2082
  284. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +0 -269
  285. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +0 -977
  286. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +0 -1294
  287. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +0 -1447
  288. package/runtime/python/okstra_vendor/networkx/convert.py +0 -502
  289. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +0 -1314
  290. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +0 -7
  291. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +0 -2036
  292. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +0 -470
  293. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +0 -570
  294. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +0 -361
  295. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +0 -2978
  296. package/runtime/python/okstra_vendor/networkx/exception.py +0 -131
  297. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +0 -34
  298. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  299. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +0 -227
  300. package/runtime/python/okstra_vendor/networkx/generators/classic.py +0 -1091
  301. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +0 -68
  302. package/runtime/python/okstra_vendor/networkx/generators/community.py +0 -1070
  303. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +0 -886
  304. package/runtime/python/okstra_vendor/networkx/generators/directed.py +0 -572
  305. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +0 -174
  306. package/runtime/python/okstra_vendor/networkx/generators/ego.py +0 -66
  307. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +0 -499
  308. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +0 -1037
  309. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +0 -163
  310. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +0 -443
  311. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +0 -125
  312. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +0 -70
  313. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +0 -664
  314. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +0 -405
  315. package/runtime/python/okstra_vendor/networkx/generators/line.py +0 -501
  316. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +0 -110
  317. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +0 -259
  318. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +0 -117
  319. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +0 -1416
  320. package/runtime/python/okstra_vendor/networkx/generators/small.py +0 -1070
  321. package/runtime/python/okstra_vendor/networkx/generators/social.py +0 -554
  322. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +0 -120
  323. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +0 -54
  324. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +0 -131
  325. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +0 -74
  326. package/runtime/python/okstra_vendor/networkx/generators/trees.py +0 -1070
  327. package/runtime/python/okstra_vendor/networkx/generators/triads.py +0 -94
  328. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +0 -188
  329. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +0 -13
  330. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +0 -650
  331. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +0 -466
  332. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +0 -77
  333. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +0 -168
  334. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +0 -512
  335. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +0 -166
  336. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +0 -186
  337. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +0 -17
  338. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +0 -330
  339. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +0 -489
  340. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +0 -1084
  341. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +0 -879
  342. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +0 -427
  343. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +0 -1053
  344. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +0 -19
  345. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +0 -156
  346. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +0 -190
  347. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +0 -261
  348. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +0 -137
  349. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +0 -108
  350. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +0 -393
  351. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +0 -113
  352. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +0 -286
  353. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +0 -379
  354. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +0 -851
  355. package/runtime/python/okstra_vendor/networkx/relabel.py +0 -285
  356. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +0 -8
  357. package/runtime/python/okstra_vendor/networkx/utils/backends.py +0 -2171
  358. package/runtime/python/okstra_vendor/networkx/utils/configs.py +0 -396
  359. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +0 -1233
  360. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +0 -338
  361. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +0 -297
  362. package/runtime/python/okstra_vendor/networkx/utils/misc.py +0 -703
  363. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +0 -198
  364. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +0 -159
  365. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +0 -106
  366. package/runtime/skills/okstra-graphify/SKILL.md +0 -169
  367. package/src/commands/graphify.mjs +0 -32
@@ -1,163 +0,0 @@
1
- """
2
- Communicability.
3
- """
4
-
5
- import networkx as nx
6
- from networkx.utils import not_implemented_for
7
-
8
- __all__ = ["communicability", "communicability_exp"]
9
-
10
-
11
- @not_implemented_for("directed")
12
- @not_implemented_for("multigraph")
13
- @nx._dispatchable
14
- def communicability(G):
15
- r"""Returns communicability between all pairs of nodes in G.
16
-
17
- The communicability between pairs of nodes in G is the sum of
18
- walks of different lengths starting at node u and ending at node v.
19
-
20
- Parameters
21
- ----------
22
- G: graph
23
-
24
- Returns
25
- -------
26
- comm: dictionary of dictionaries
27
- Dictionary of dictionaries keyed by nodes with communicability
28
- as the value.
29
-
30
- Raises
31
- ------
32
- NetworkXError
33
- If the graph is not undirected and simple.
34
-
35
- See Also
36
- --------
37
- communicability_exp:
38
- Communicability between all pairs of nodes in G using spectral
39
- decomposition.
40
- communicability_betweenness_centrality:
41
- Communicability betweenness centrality for each node in G.
42
-
43
- Notes
44
- -----
45
- This algorithm uses a spectral decomposition of the adjacency matrix.
46
- Let G=(V,E) be a simple undirected graph. Using the connection between
47
- the powers of the adjacency matrix and the number of walks in the graph,
48
- the communicability between nodes `u` and `v` based on the graph spectrum
49
- is [1]_
50
-
51
- .. math::
52
- C(u,v)=\sum_{j=1}^{n}\phi_{j}(u)\phi_{j}(v)e^{\lambda_{j}},
53
-
54
- where `\phi_{j}(u)` is the `u\rm{th}` element of the `j\rm{th}` orthonormal
55
- eigenvector of the adjacency matrix associated with the eigenvalue
56
- `\lambda_{j}`.
57
-
58
- References
59
- ----------
60
- .. [1] Ernesto Estrada, Naomichi Hatano,
61
- "Communicability in complex networks",
62
- Phys. Rev. E 77, 036111 (2008).
63
- https://arxiv.org/abs/0707.0756
64
-
65
- Examples
66
- --------
67
- >>> G = nx.Graph([(0, 1), (1, 2), (1, 5), (5, 4), (2, 4), (2, 3), (4, 3), (3, 6)])
68
- >>> c = nx.communicability(G)
69
- """
70
- import numpy as np
71
-
72
- nodelist = list(G) # ordering of nodes in matrix
73
- A = nx.to_numpy_array(G, nodelist)
74
- # convert to 0-1 matrix
75
- A[A != 0.0] = 1
76
- w, vec = np.linalg.eigh(A)
77
- expw = np.exp(w)
78
- mapping = dict(zip(nodelist, range(len(nodelist))))
79
- c = {}
80
- # computing communicabilities
81
- for u in G:
82
- c[u] = {}
83
- for v in G:
84
- s = 0
85
- p = mapping[u]
86
- q = mapping[v]
87
- for j in range(len(nodelist)):
88
- s += vec[:, j][p] * vec[:, j][q] * expw[j]
89
- c[u][v] = float(s)
90
- return c
91
-
92
-
93
- @not_implemented_for("directed")
94
- @not_implemented_for("multigraph")
95
- @nx._dispatchable
96
- def communicability_exp(G):
97
- r"""Returns communicability between all pairs of nodes in G.
98
-
99
- Communicability between pair of node (u,v) of node in G is the sum of
100
- walks of different lengths starting at node u and ending at node v.
101
-
102
- Parameters
103
- ----------
104
- G: graph
105
-
106
- Returns
107
- -------
108
- comm: dictionary of dictionaries
109
- Dictionary of dictionaries keyed by nodes with communicability
110
- as the value.
111
-
112
- Raises
113
- ------
114
- NetworkXError
115
- If the graph is not undirected and simple.
116
-
117
- See Also
118
- --------
119
- communicability:
120
- Communicability between pairs of nodes in G.
121
- communicability_betweenness_centrality:
122
- Communicability betweenness centrality for each node in G.
123
-
124
- Notes
125
- -----
126
- This algorithm uses matrix exponentiation of the adjacency matrix.
127
-
128
- Let G=(V,E) be a simple undirected graph. Using the connection between
129
- the powers of the adjacency matrix and the number of walks in the graph,
130
- the communicability between nodes u and v is [1]_,
131
-
132
- .. math::
133
- C(u,v) = (e^A)_{uv},
134
-
135
- where `A` is the adjacency matrix of G.
136
-
137
- References
138
- ----------
139
- .. [1] Ernesto Estrada, Naomichi Hatano,
140
- "Communicability in complex networks",
141
- Phys. Rev. E 77, 036111 (2008).
142
- https://arxiv.org/abs/0707.0756
143
-
144
- Examples
145
- --------
146
- >>> G = nx.Graph([(0, 1), (1, 2), (1, 5), (5, 4), (2, 4), (2, 3), (4, 3), (3, 6)])
147
- >>> c = nx.communicability_exp(G)
148
- """
149
- import scipy as sp
150
-
151
- nodelist = list(G) # ordering of nodes in matrix
152
- A = nx.to_numpy_array(G, nodelist)
153
- # convert to 0-1 matrix
154
- A[A != 0.0] = 1
155
- # communicability matrix
156
- expA = sp.linalg.expm(A)
157
- mapping = dict(zip(nodelist, range(len(nodelist))))
158
- c = {}
159
- for u in G:
160
- c[u] = {}
161
- for v in G:
162
- c[u][v] = float(expA[mapping[u], mapping[v]])
163
- return c
@@ -1,28 +0,0 @@
1
- """Functions for computing and measuring community structure.
2
-
3
- The ``community`` subpackage can be accessed by using :mod:`networkx.community`, then accessing the
4
- functions as attributes of ``community``. For example::
5
-
6
- >>> import networkx as nx
7
- >>> G = nx.barbell_graph(5, 1)
8
- >>> communities_generator = nx.community.girvan_newman(G)
9
- >>> top_level_communities = next(communities_generator)
10
- >>> next_level_communities = next(communities_generator)
11
- >>> sorted(map(sorted, next_level_communities))
12
- [[0, 1, 2, 3, 4], [5], [6, 7, 8, 9, 10]]
13
-
14
- """
15
-
16
- from networkx.algorithms.community.asyn_fluid import *
17
- from networkx.algorithms.community.bipartitions import *
18
- from networkx.algorithms.community.centrality import *
19
- from networkx.algorithms.community.divisive import *
20
- from networkx.algorithms.community.kclique import *
21
- from networkx.algorithms.community.label_propagation import *
22
- from networkx.algorithms.community.lukes import *
23
- from networkx.algorithms.community.modularity_max import *
24
- from networkx.algorithms.community.quality import *
25
- from networkx.algorithms.community.community_utils import *
26
- from networkx.algorithms.community.louvain import *
27
- from networkx.algorithms.community.leiden import *
28
- from networkx.algorithms.community.local import *
@@ -1,153 +0,0 @@
1
- """Asynchronous Fluid Communities algorithm for community detection."""
2
-
3
- from collections import Counter
4
-
5
- import networkx as nx
6
- from networkx.algorithms.components import is_connected
7
- from networkx.exception import NetworkXError
8
- from networkx.utils import groups, not_implemented_for, py_random_state
9
-
10
- __all__ = ["asyn_fluidc"]
11
-
12
-
13
- @not_implemented_for("directed")
14
- @not_implemented_for("multigraph")
15
- @py_random_state(3)
16
- @nx._dispatchable
17
- def asyn_fluidc(G, k, max_iter=100, seed=None):
18
- """Returns communities in `G` as detected by Fluid Communities algorithm.
19
-
20
- The asynchronous fluid communities algorithm is described in
21
- [1]_. The algorithm is based on the simple idea of fluids interacting
22
- in an environment, expanding and pushing each other. Its initialization is
23
- random, so found communities may vary on different executions.
24
-
25
- The algorithm proceeds as follows. First each of the initial k communities
26
- is initialized in a random vertex in the graph. Then the algorithm iterates
27
- over all vertices in a random order, updating the community of each vertex
28
- based on its own community and the communities of its neighbors. This
29
- process is performed several times until convergence.
30
- At all times, each community has a total density of 1, which is equally
31
- distributed among the vertices it contains. If a vertex changes of
32
- community, vertex densities of affected communities are adjusted
33
- immediately. When a complete iteration over all vertices is done, such that
34
- no vertex changes the community it belongs to, the algorithm has converged
35
- and returns.
36
-
37
- This is the original version of the algorithm described in [1]_.
38
- Unfortunately, it does not support weighted graphs yet.
39
-
40
- Parameters
41
- ----------
42
- G : NetworkX graph
43
- Graph must be simple and undirected.
44
-
45
- k : integer
46
- The number of communities to be found.
47
-
48
- max_iter : integer
49
- The number of maximum iterations allowed. By default 100.
50
-
51
- seed : integer, random_state, or None (default)
52
- Indicator of random number generation state.
53
- See :ref:`Randomness<randomness>`.
54
-
55
- Returns
56
- -------
57
- communities : iterable
58
- Iterable of communities given as sets of nodes.
59
-
60
- Notes
61
- -----
62
- k variable is not an optional argument.
63
-
64
- References
65
- ----------
66
- .. [1] Parés F., Garcia-Gasulla D. et al. "Fluid Communities: A
67
- Competitive and Highly Scalable Community Detection Algorithm".
68
- [https://arxiv.org/pdf/1703.09307.pdf].
69
- """
70
- # Initial checks
71
- if not isinstance(k, int):
72
- raise NetworkXError("k must be an integer.")
73
- if not k > 0:
74
- raise NetworkXError("k must be greater than 0.")
75
- if not is_connected(G):
76
- raise NetworkXError("Fluid Communities require connected Graphs.")
77
- if len(G) < k:
78
- raise NetworkXError("k cannot be bigger than the number of nodes.")
79
- if max_iter <= 0:
80
- msg = f"{max_iter=} must be greater than 0"
81
- raise ValueError(msg)
82
- # Initialization
83
- max_density = 1.0
84
- vertices = list(G)
85
- seed.shuffle(vertices)
86
- communities = {n: i for i, n in enumerate(vertices[:k])}
87
- density = {}
88
- com_to_numvertices = {}
89
- for vertex in communities:
90
- com_to_numvertices[communities[vertex]] = 1
91
- density[communities[vertex]] = max_density
92
- # Set up control variables and start iterating
93
- iter_count = 0
94
- cont = True
95
- while cont and iter_count < max_iter:
96
- cont = False
97
- iter_count += 1
98
- # Loop over all vertices in graph in a random order
99
- vertices = list(G)
100
- seed.shuffle(vertices)
101
- for vertex in vertices:
102
- # Updating rule
103
- com_counter = Counter()
104
- # Take into account self vertex community
105
- try:
106
- com_counter.update({communities[vertex]: density[communities[vertex]]})
107
- except KeyError:
108
- pass
109
- # Gather neighbor vertex communities
110
- for v in G[vertex]:
111
- try:
112
- com_counter.update({communities[v]: density[communities[v]]})
113
- except KeyError:
114
- continue
115
- # Check which is the community with highest density
116
- new_com = -1
117
- if len(com_counter.keys()) > 0:
118
- max_freq = max(com_counter.values())
119
- best_communities = [
120
- com
121
- for com, freq in com_counter.items()
122
- if (max_freq - freq) < 0.0001
123
- ]
124
- # If actual vertex com in best communities, it is preserved
125
- try:
126
- if communities[vertex] in best_communities:
127
- new_com = communities[vertex]
128
- except KeyError:
129
- pass
130
-
131
- # If vertex community changes...
132
- if new_com == -1:
133
- # Set flag of non-convergence
134
- cont = True
135
- # Randomly chose a new community from candidates
136
- new_com = seed.choice(best_communities)
137
- # Update previous community status
138
- try:
139
- com_to_numvertices[communities[vertex]] -= 1
140
- density[communities[vertex]] = (
141
- max_density / com_to_numvertices[communities[vertex]]
142
- )
143
- except KeyError:
144
- pass
145
- # Update new community status
146
- communities[vertex] = new_com
147
- com_to_numvertices[communities[vertex]] += 1
148
- density[communities[vertex]] = (
149
- max_density / com_to_numvertices[communities[vertex]]
150
- )
151
- # If maximum iterations reached --> output actual results
152
- # Return results by grouping communities as list of vertices
153
- return iter(groups(communities).values())
@@ -1,354 +0,0 @@
1
- """Functions for splitting a network into two communities (finding a bipartition)."""
2
-
3
- import random
4
- from copy import deepcopy
5
- from itertools import count
6
-
7
- import networkx as nx
8
-
9
- __all__ = [
10
- "kernighan_lin_bisection",
11
- "spectral_modularity_bipartition",
12
- "greedy_node_swap_bipartition",
13
- ]
14
-
15
-
16
- def _kernighan_lin_sweep(edge_info, side):
17
- """
18
- This is a modified form of Kernighan-Lin, which moves single nodes at a
19
- time, alternating between sides to keep the bisection balanced. We keep
20
- two min-heaps of swap costs to make optimal-next-move selection fast.
21
- """
22
- heap0, heap1 = cost_heaps = nx.utils.BinaryHeap(), nx.utils.BinaryHeap()
23
- # we use heap methods insert, pop, and get
24
- for u, nbrs in edge_info.items():
25
- cost_u = sum(wt if side[v] else -wt for v, wt in nbrs.items())
26
- if side[u]:
27
- heap1.insert(u, cost_u)
28
- else:
29
- heap0.insert(u, -cost_u)
30
-
31
- def _update_heap_values(node):
32
- side_node = side[node]
33
- for nbr, wt in edge_info[node].items():
34
- side_nbr = side[nbr]
35
- if side_nbr == side_node:
36
- wt = -wt
37
- heap_nbr = cost_heaps[side_nbr]
38
- if nbr in heap_nbr:
39
- cost_nbr = heap_nbr.get(nbr) + 2 * wt
40
- # allow_increase lets us update a value already on the heap
41
- heap_nbr.insert(nbr, cost_nbr, allow_increase=True)
42
-
43
- i = 0
44
- totcost = 0
45
- while heap0 and heap1:
46
- u, cost_u = heap0.pop()
47
- _update_heap_values(u)
48
- v, cost_v = heap1.pop()
49
- _update_heap_values(v)
50
- totcost += cost_u + cost_v
51
- i += 1
52
- yield totcost, i, (u, v)
53
-
54
-
55
- @nx.utils.not_implemented_for("directed")
56
- @nx.utils.py_random_state(4)
57
- @nx._dispatchable(edge_attrs="weight")
58
- def kernighan_lin_bisection(G, partition=None, max_iter=10, weight="weight", seed=None):
59
- """Partition a graph into two blocks using the Kernighan–Lin algorithm.
60
-
61
- This algorithm partitions a network into two sets by iteratively
62
- swapping pairs of nodes to reduce the edge cut between the two sets. The
63
- pairs are chosen according to a modified form of Kernighan-Lin [1]_, which
64
- moves nodes individually, alternating between sides to keep the bisection
65
- balanced.
66
-
67
- Kernighan-Lin is an approximate algorithm for maximal modularity bisection.
68
- In [2]_ they suggest that fine-tuned improvements can be made using
69
- greedy node swapping, (see `greedy_node_swap_bipartition`).
70
- The improvements are typically only a few percent of the modularity value.
71
- But they claim that can make a difference between a good and excellent method.
72
- This function does not perform any improvements. But you can do that yourself.
73
-
74
- Parameters
75
- ----------
76
- G : NetworkX graph
77
- Graph must be undirected.
78
-
79
- partition : tuple
80
- Pair of iterables containing an initial partition. If not
81
- specified, a random balanced partition is used.
82
-
83
- max_iter : int
84
- Maximum number of times to attempt swaps to find an
85
- improvement before giving up.
86
-
87
- weight : string or function (default: "weight")
88
- If this is a string, then edge weights will be accessed via the
89
- edge attribute with this key (that is, the weight of the edge
90
- joining `u` to `v` will be ``G.edges[u, v][weight]``). If no
91
- such edge attribute exists, the weight of the edge is assumed to
92
- be one.
93
-
94
- If this is a function, the weight of an edge is the value
95
- returned by the function. The function must accept exactly three
96
- positional arguments: the two endpoints of an edge and the
97
- dictionary of edge attributes for that edge. The function must
98
- return a number or None to indicate a hidden edge.
99
-
100
- seed : integer, random_state, or None (default)
101
- Indicator of random number generation state.
102
- See :ref:`Randomness<randomness>`.
103
- Only used if partition is None
104
-
105
- Returns
106
- -------
107
- partition : tuple
108
- A pair of sets of nodes representing the bipartition.
109
-
110
- Raises
111
- ------
112
- NetworkXError
113
- If `partition` is not a valid partition of the nodes of the graph.
114
-
115
- References
116
- ----------
117
- .. [1] Kernighan, B. W.; Lin, Shen (1970).
118
- "An efficient heuristic procedure for partitioning graphs."
119
- *Bell Systems Technical Journal* 49: 291--307.
120
- Oxford University Press 2011.
121
- .. [2] M. E. J. Newman,
122
- "Modularity and community structure in networks",
123
- PNAS, 103 (23), p. 8577-8582,
124
- https://doi.org/10.1073/pnas.0601602103
125
-
126
- """
127
- nodes = list(G)
128
-
129
- if partition is None:
130
- seed.shuffle(nodes)
131
- mid = len(nodes) // 2
132
- A, B = nodes[:mid], nodes[mid:]
133
- else:
134
- try:
135
- A, B = partition
136
- except (TypeError, ValueError) as err:
137
- raise nx.NetworkXError("partition must be two sets") from err
138
- if not nx.community.is_partition(G, [A, B]):
139
- raise nx.NetworkXError("partition invalid")
140
-
141
- side = {node: (node in A) for node in nodes}
142
-
143
- # ruff: noqa: E731 skips check for no lambda functions
144
- # Using shortest_paths _weight_function with sum instead of min on multiedges
145
- if callable(weight):
146
- sum_weight = weight
147
- elif G.is_multigraph():
148
- sum_weight = lambda u, v, d: sum(dd.get(weight, 1) for dd in d.values())
149
- else:
150
- sum_weight = lambda u, v, d: d.get(weight, 1)
151
-
152
- edge_info = {
153
- u: {v: wt for v, d in nbrs.items() if (wt := sum_weight(u, v, d)) is not None}
154
- for u, nbrs in G._adj.items()
155
- }
156
-
157
- for i in range(max_iter):
158
- costs = list(_kernighan_lin_sweep(edge_info, side))
159
- # find out how many edges to update: min_i
160
- min_cost, min_i, _ = min(costs)
161
- if min_cost >= 0:
162
- break
163
-
164
- for _, _, (u, v) in costs[:min_i]:
165
- side[u] = 1
166
- side[v] = 0
167
-
168
- part1 = {u for u, s in side.items() if s == 0}
169
- part2 = {u for u, s in side.items() if s == 1}
170
- return part1, part2
171
-
172
-
173
- @nx.utils.not_implemented_for("directed")
174
- @nx.utils.not_implemented_for("multigraph")
175
- def spectral_modularity_bipartition(G):
176
- r"""Return a bipartition of the nodes based on the spectrum of the
177
- modularity matrix of the graph.
178
-
179
- This method calculates the eigenvector associated with the second
180
- largest eigenvalue of the modularity matrix, where the modularity
181
- matrix *B* is defined by
182
-
183
- ..math::
184
-
185
- B_{i j} = A_{i j} - \frac{k_i k_j}{2 m},
186
-
187
- where *A* is the adjacency matrix, `k_i` is the degree of node *i*,
188
- and *m* is the number of edges in the graph. Nodes whose
189
- corresponding values in the eigenvector are negative are placed in
190
- one block, nodes whose values are nonnegative are placed in another
191
- block.
192
-
193
- Parameters
194
- ----------
195
- G : NetworkX graph
196
-
197
- Returns
198
- -------
199
- C : tuple
200
- Pair of communities as two sets of nodes of ``G``, partitioned
201
- according to second largest eigenvalue of the modularity matrix.
202
-
203
- Examples
204
- --------
205
- >>> G = nx.karate_club_graph()
206
- >>> MrHi, Officer = nx.community.spectral_modularity_bipartition(G)
207
- >>> MrHi, Officer = sorted([sorted(MrHi), sorted(Officer)])
208
- >>> MrHi
209
- [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 16, 17, 19, 21]
210
- >>> Officer
211
- [8, 9, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
212
-
213
- References
214
- ----------
215
- .. [1] M. E. J. Newman *Networks: An Introduction*, pages 373--378
216
- Oxford University Press 2011.
217
- .. [2] M. E. J. Newman,
218
- "Modularity and community structure in networks",
219
- PNAS, 103 (23), p. 8577-8582,
220
- https://doi.org/10.1073/pnas.0601602103
221
-
222
- """
223
- import numpy as np
224
-
225
- B = nx.linalg.modularity_matrix(G)
226
- eigenvalues, eigenvectors = np.linalg.eig(B)
227
- index = np.argsort(eigenvalues)[-1]
228
- v2 = zip(np.real(eigenvectors[:, index]), G)
229
- left, right = set(), set()
230
- for u, n in v2:
231
- if u < 0:
232
- left.add(n)
233
- else:
234
- right.add(n)
235
- return left, right
236
-
237
-
238
- @nx.utils.not_implemented_for("multigraph")
239
- def greedy_node_swap_bipartition(G, *, init_split=None, max_iter=10):
240
- """Split the nodes into two communities based on greedy
241
- modularity maximization.
242
-
243
- The algorithm works by selecting a node to change communities which
244
- will maximize the modularity. The swap is made and the community
245
- structure with the highest modularity is kept.
246
-
247
- Parameters
248
- ----------
249
- G : NetworkX graph
250
-
251
- init_split : 2-tuple of sets of nodes
252
- Pair of sets of nodes in ``G`` providing an initial bipartition
253
- for the algorithm. If not specified, a random balanced partition
254
- is used. If this pair of sets is not a partition of the nodes of `G`,
255
- :exc:`NetworkXException` is raised.
256
-
257
- max_iter : int
258
- Maximum number of iterations of attempting swaps to find an improvement.
259
-
260
- Returns
261
- -------
262
- max_split : 2-tuple of sets of nodes
263
- Pair of sets of nodes of ``G``, partitioned according to a
264
- node swap greedy modularity maximization algorithm.
265
-
266
- Raises
267
- ------
268
- NetworkXError
269
- if init_split is not a valid partition of the
270
- graph into two communities or if G is a MultiGraph
271
-
272
- Examples
273
- --------
274
- >>> G = nx.barbell_graph(3, 0)
275
- >>> left, right = nx.community.greedy_node_swap_bipartition(G)
276
- >>> # Sort the communities so the nodes appear in increasing order.
277
- >>> left, right = sorted([sorted(left), sorted(right)])
278
- >>> sorted(left)
279
- [0, 1, 2]
280
- >>> sorted(right)
281
- [3, 4, 5]
282
-
283
- Notes
284
- -----
285
- This function is not implemented for multigraphs.
286
-
287
- References
288
- ----------
289
- .. [1] M. E. J. Newman "Networks: An Introduction", pages 373--375.
290
- Oxford University Press 2011.
291
-
292
- """
293
- if init_split is None:
294
- m1 = len(G) // 2
295
- m2 = len(G) - m1
296
- some_nodes = set(random.sample(list(G), m1))
297
- other_nodes = {n for n in G if n not in some_nodes}
298
- best_split_so_far = (some_nodes, other_nodes)
299
- else:
300
- if not nx.community.is_partition(G, init_split):
301
- raise nx.NetworkXError("init_split is not a partition of G")
302
- if not len(init_split) == 2:
303
- raise nx.NetworkXError("init_split must be a bipartition")
304
- best_split_so_far = deepcopy(init_split)
305
-
306
- best_mod = nx.community.modularity(G, best_split_so_far)
307
-
308
- max_split, max_mod = best_split_so_far, best_mod
309
- its = 0
310
- m = G.number_of_edges()
311
- G_degree = dict(G.degree)
312
-
313
- while max_mod >= best_mod and its < max_iter:
314
- best_split_so_far = max_split
315
- best_mod = max_mod
316
- next_split = deepcopy(max_split)
317
- next_mod = max_mod
318
- nodes = set(G)
319
- while nodes:
320
- max_swap = -1
321
- max_node = None
322
- max_node_comm = None
323
- left, right = next_split
324
- leftd = sum(G_degree[n] for n in left)
325
- rightd = sum(G_degree[n] for n in right)
326
- for n in nodes:
327
- if n in left:
328
- in_comm, out_comm = left, right
329
- in_deg, out_deg = leftd, rightd
330
- else:
331
- in_comm, out_comm = right, left
332
- in_deg, out_deg = rightd, leftd
333
-
334
- d_eii = -len(G[n].keys() & in_comm) / m
335
- d_ejj = len(G[n].keys() & out_comm) / m
336
- deg = G_degree[n]
337
- d_sum_ai = (deg / (2 * m**2)) * (in_deg - out_deg - deg)
338
- swap_change = d_eii + d_ejj + d_sum_ai
339
-
340
- if swap_change > max_swap:
341
- max_swap = swap_change
342
- max_node = n
343
- max_node_comm = in_comm
344
- non_max_node_comm = out_comm
345
- # swap the node from one comm to the other
346
- max_node_comm.remove(max_node)
347
- non_max_node_comm.add(max_node)
348
- next_mod += max_swap
349
- # deepcopy next_split each time it reaches a high (might go lower later)
350
- if next_mod > max_mod:
351
- max_split, max_mod = deepcopy(next_split), next_mod
352
- nodes.remove(max_node)
353
- its += 1
354
- return best_split_so_far