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,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