okstra 0.130.4 → 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 (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 +1722 -98
  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,591 +0,0 @@
1
- """Betweenness centrality measures."""
2
-
3
- import math
4
- from collections import deque
5
- from heapq import heappop, heappush
6
- from itertools import count
7
-
8
- import networkx as nx
9
- from networkx.algorithms.shortest_paths.weighted import _weight_function
10
- from networkx.utils import py_random_state
11
- from networkx.utils.decorators import not_implemented_for
12
-
13
- __all__ = ["betweenness_centrality", "edge_betweenness_centrality"]
14
-
15
-
16
- @py_random_state("seed")
17
- @nx._dispatchable(edge_attrs="weight")
18
- def betweenness_centrality(
19
- G, k=None, normalized=True, weight=None, endpoints=False, seed=None
20
- ):
21
- r"""Compute the shortest-path betweenness centrality for nodes.
22
-
23
- Betweenness centrality of a node $v$ is the sum of the
24
- fraction of all-pairs shortest paths that pass through $v$.
25
-
26
- .. math::
27
-
28
- c_B(v) = \sum_{s, t \in V} \frac{\sigma(s, t | v)}{\sigma(s, t)}
29
-
30
- where $V$ is the set of nodes, $\sigma(s, t)$ is the number of
31
- shortest $(s, t)$-paths, and $\sigma(s, t | v)$ is the number of
32
- those paths passing through some node $v$ other than $s$ and $t$.
33
- If $s = t$, $\sigma(s, t) = 1$, and if $v \in \{s, t\}$,
34
- $\sigma(s, t | v) = 0$ [2]_.
35
- The denominator $\sigma(s, t)$ is a normalization factor that can be
36
- turned off to get the raw path counts.
37
-
38
- Parameters
39
- ----------
40
- G : graph
41
- A NetworkX graph.
42
-
43
- k : int, optional (default=None)
44
- If `k` is not `None`, use `k` sampled nodes as sources for the considered paths.
45
- The resulting sampled counts are then inflated to approximate betweenness.
46
- Higher values of `k` give better approximation. Must have ``k <= len(G)``.
47
-
48
- normalized : bool, optional (default=True)
49
- If `True`, the betweenness values are rescaled by dividing by the number of
50
- possible $(s, t)$-pairs in the graph.
51
-
52
- weight : None or string, optional (default=None)
53
- If `None`, all edge weights are 1.
54
- Otherwise holds the name of the edge attribute used as weight.
55
- Weights are used to calculate weighted shortest paths, so they are
56
- interpreted as distances.
57
-
58
- endpoints : bool, optional (default=False)
59
- If `True`, include the endpoints $s$ and $t$ in the shortest path counts.
60
- This is taken into account when rescaling the values.
61
-
62
- seed : integer, random_state, or None (default)
63
- Indicator of random number generation state.
64
- See :ref:`Randomness<randomness>`.
65
- Note that this is only used if ``k is not None``.
66
-
67
- Returns
68
- -------
69
- nodes : dict
70
- Dictionary of nodes with betweenness centrality as the value.
71
-
72
- See Also
73
- --------
74
- betweenness_centrality_subset
75
- edge_betweenness_centrality
76
- load_centrality
77
-
78
- Notes
79
- -----
80
- The algorithm is from Ulrik Brandes [1]_.
81
- See [4]_ for the original first published version and [2]_ for details on
82
- algorithms for variations and related metrics.
83
-
84
- For approximate betweenness calculations, set `k` to the number of sampled
85
- nodes ("pivots") used as sources to estimate the betweenness values.
86
- The formula then sums over $s$ is in these pivots, instead of over all nodes.
87
- The resulting sum is then inflated to approximate the full sum.
88
- For a discussion of how to choose `k` for efficiency, see [3]_.
89
-
90
- For weighted graphs the edge weights must be greater than zero.
91
- Zero edge weights can produce an infinite number of equal length
92
- paths between pairs of nodes.
93
-
94
- Directed graphs and undirected graphs count paths differently.
95
- In directed graphs, each pair of source-target nodes is considered separately
96
- in each direction, as the shortest paths can differ by direction.
97
- However, in undirected graphs, each pair of nodes is considered only once,
98
- as the shortest paths are symmetric.
99
- This means the normalization factor to divide by is $N(N-1)$ for directed graphs
100
- and $N(N-1)/2$ for undirected graphs, where $N = n$ (the number of nodes)
101
- if endpoints are included and $N = n-1$ otherwise.
102
-
103
- This algorithm is not guaranteed to be correct if edge weights
104
- are floating point numbers. As a workaround you can use integer
105
- numbers by multiplying the relevant edge attributes by a convenient
106
- constant factor (e.g. 100) and converting to integers.
107
-
108
- References
109
- ----------
110
- .. [1] Ulrik Brandes:
111
- A Faster Algorithm for Betweenness Centrality.
112
- Journal of Mathematical Sociology 25(2):163--177, 2001.
113
- https://doi.org/10.1080/0022250X.2001.9990249
114
- .. [2] Ulrik Brandes:
115
- On Variants of Shortest-Path Betweenness
116
- Centrality and their Generic Computation.
117
- Social Networks 30(2):136--145, 2008.
118
- https://doi.org/10.1016/j.socnet.2007.11.001
119
- .. [3] Ulrik Brandes and Christian Pich:
120
- Centrality Estimation in Large Networks.
121
- International Journal of Bifurcation and Chaos 17(7):2303--2318, 2007.
122
- https://dx.doi.org/10.1142/S0218127407018403
123
- .. [4] Linton C. Freeman:
124
- A set of measures of centrality based on betweenness.
125
- Sociometry 40: 35--41, 1977
126
- https://doi.org/10.2307/3033543
127
-
128
- Examples
129
- --------
130
- Consider an undirected 3-path. Each pair of nodes has exactly one shortest
131
- path between them. Since the graph is undirected, only ordered pairs are counted.
132
- Of these (and when `endpoints` is `False`), none of the shortest paths pass
133
- through 0 and 2, and only the shortest path between 0 and 2 passes through 1.
134
- As such, the counts should be ``{0: 0, 1: 1, 2: 0}``.
135
-
136
- >>> G = nx.path_graph(3)
137
- >>> nx.betweenness_centrality(G, normalized=False, endpoints=False)
138
- {0: 0.0, 1: 1.0, 2: 0.0}
139
-
140
- If `endpoints` is `True`, we also need to count endpoints as being on the path:
141
- $\sigma(s, t | s) = \sigma(s, t | t) = \sigma(s, t)$.
142
- In our example, 0 is then part of two shortest paths (0 to 1 and 0 to 2);
143
- similarly, 2 is part of two shortest paths (0 to 2 and 1 to 2).
144
- 1 is part of all three shortest paths. This makes the new raw
145
- counts ``{0: 2, 1: 3, 2: 2}``.
146
-
147
- >>> nx.betweenness_centrality(G, normalized=False, endpoints=True)
148
- {0: 2.0, 1: 3.0, 2: 2.0}
149
-
150
- With normalization, the values are divided by the number of ordered $(s, t)$-pairs.
151
- If we are not counting endpoints, there are $n - 1$ possible choices for $s$
152
- (all except the node we are computing betweenness centrality for), which in turn
153
- leaves $n - 2$ possible choices for $t$ as $s \ne t$.
154
- The total number of ordered pairs when `endpoints` is `False` is $(n - 1)(n - 2)/2 = 1$.
155
- If `endpoints` is `True`, there are $n(n - 1)/2 = 3$ ordered $(s, t)$-pairs to divide by.
156
-
157
- >>> nx.betweenness_centrality(G, normalized=True, endpoints=False)
158
- {0: 0.0, 1: 1.0, 2: 0.0}
159
- >>> nx.betweenness_centrality(G, normalized=True, endpoints=True)
160
- {0: 0.6666666666666666, 1: 1.0, 2: 0.6666666666666666}
161
-
162
- If the graph is directed instead, we now need to consider $(s, t)$-pairs
163
- in both directions. Our example becomes a directed 3-path.
164
- Without counting endpoints, we only have one path through 1 (0 to 2).
165
- This means the raw counts are ``{0: 0, 1: 1, 2: 0}``.
166
-
167
- >>> DG = nx.path_graph(3, create_using=nx.DiGraph)
168
- >>> nx.betweenness_centrality(DG, normalized=False, endpoints=False)
169
- {0: 0.0, 1: 1.0, 2: 0.0}
170
-
171
- If we do include endpoints, the raw counts are ``{0: 2, 1: 3, 2: 2}``.
172
-
173
- >>> nx.betweenness_centrality(DG, normalized=False, endpoints=True)
174
- {0: 2.0, 1: 3.0, 2: 2.0}
175
-
176
- If we want to normalize directed betweenness centrality, the raw counts
177
- are normalized by the number of $(s, t)$-pairs. There are $n(n - 1)$
178
- possible paths with endpoints and $(n - 1)(n - 2)$ without endpoints.
179
- In our example, that's 6 with endpoints and 2 without endpoints.
180
-
181
- >>> nx.betweenness_centrality(DG, normalized=True, endpoints=True)
182
- {0: 0.3333333333333333, 1: 0.5, 2: 0.3333333333333333}
183
- >>> nx.betweenness_centrality(DG, normalized=True, endpoints=False)
184
- {0: 0.0, 1: 0.5, 2: 0.0}
185
-
186
- Computing the full betweenness centrality can be costly.
187
- This function can also be used to compute approximate betweenness centrality
188
- by setting `k`. This only determines the number of source nodes to sample;
189
- all nodes are targets.
190
-
191
- For simplicity, we only consider the case where endpoints are included in the counts.
192
- Since the partial sums only include `k` terms, instead of ``n``,
193
- we multiply them by ``n / k``, to approximate the full sum.
194
- As the sets of sources and targets are not the same anymore,
195
- paths have to be counted in a directed way. We thus count each as half a path.
196
- This ensures that the results approximate the standard betweenness for ``k == n``.
197
-
198
- For instance, in the undirected 3-path graph case, setting ``k = 2`` (with ``seed=42``)
199
- selects nodes 0 and 2 as sources.
200
- This means only shortest paths starting at these nodes are considered.
201
- The raw counts with endpoints are ``{0: 3, 1: 4, 2: 3}``. Accounting for the partial sum
202
- and applying the undirectedness half-path correction, we get
203
-
204
- >>> nx.betweenness_centrality(G, k=2, normalized=False, endpoints=True, seed=42)
205
- {0: 2.25, 1: 3.0, 2: 2.25}
206
-
207
- When normalizing, we instead want to divide by the total number of $(s, t)$-pairs.
208
- This is $k(n - 1)$ with endpoints.
209
-
210
- >>> nx.betweenness_centrality(G, k=2, normalized=True, endpoints=True, seed=42)
211
- {0: 0.75, 1: 1.0, 2: 0.75}
212
- """
213
- betweenness = dict.fromkeys(G, 0.0) # b[v]=0 for v in G
214
- if k == len(G):
215
- # This is done for performance; the result is the same regardless.
216
- k = None
217
- if k is None:
218
- nodes = G
219
- else:
220
- nodes = seed.sample(list(G.nodes()), k)
221
- for s in nodes:
222
- # single source shortest paths
223
- if weight is None: # use BFS
224
- S, P, sigma, _ = _single_source_shortest_path_basic(G, s)
225
- else: # use Dijkstra's algorithm
226
- S, P, sigma, _ = _single_source_dijkstra_path_basic(G, s, weight)
227
- # accumulation
228
- if endpoints:
229
- betweenness, _ = _accumulate_endpoints(betweenness, S, P, sigma, s)
230
- else:
231
- betweenness, _ = _accumulate_basic(betweenness, S, P, sigma, s)
232
- # rescaling
233
- betweenness = _rescale(
234
- betweenness,
235
- len(G),
236
- normalized=normalized,
237
- directed=G.is_directed(),
238
- endpoints=endpoints,
239
- sampled_nodes=None if k is None else nodes,
240
- )
241
- return betweenness
242
-
243
-
244
- @py_random_state("seed")
245
- @nx._dispatchable(edge_attrs="weight")
246
- def edge_betweenness_centrality(G, k=None, normalized=True, weight=None, seed=None):
247
- r"""Compute betweenness centrality for edges.
248
-
249
- Betweenness centrality of an edge $e$ is the sum of the
250
- fraction of all-pairs shortest paths that pass through $e$.
251
-
252
- .. math::
253
-
254
- c_B(e) = \sum_{s, t \in V} \frac{\sigma(s, t | e)}{\sigma(s, t)}
255
-
256
- where $V$ is the set of nodes, $\sigma(s, t)$ is the number of
257
- shortest $(s, t)$-paths, and $\sigma(s, t | e)$ is the number of
258
- those paths passing through edge $e$ [1]_.
259
- The denominator $\sigma(s, t)$ is a normalization factor that can be
260
- turned off to get the raw path counts.
261
-
262
- Parameters
263
- ----------
264
- G : graph
265
- A NetworkX graph.
266
-
267
- k : int, optional (default=None)
268
- If `k` is not `None`, use `k` sampled nodes as sources for the considered paths.
269
- The resulting sampled counts are then inflated to approximate betweenness.
270
- Higher values of `k` give better approximation. Must have ``k <= len(G)``.
271
-
272
- normalized : bool, optional (default=True)
273
- If `True`, the betweenness values are rescaled by dividing by the number of
274
- possible $(s, t)$-pairs in the graph.
275
-
276
- weight : None or string, optional (default=None)
277
- If `None`, all edge weights are 1.
278
- Otherwise holds the name of the edge attribute used as weight.
279
- Weights are used to calculate weighted shortest paths, so they are
280
- interpreted as distances.
281
-
282
- seed : integer, random_state, or None (default)
283
- Indicator of random number generation state.
284
- See :ref:`Randomness<randomness>`.
285
- Note that this is only used if ``k is not None``.
286
-
287
- Returns
288
- -------
289
- edges : dict
290
- Dictionary of edges with betweenness centrality as the value.
291
-
292
- See Also
293
- --------
294
- betweenness_centrality
295
- edge_betweenness_centrality_subset
296
- edge_load
297
-
298
- Notes
299
- -----
300
- The algorithm is from Ulrik Brandes [1]_.
301
-
302
- For weighted graphs the edge weights must be greater than zero.
303
- Zero edge weights can produce an infinite number of equal length
304
- paths between pairs of nodes.
305
-
306
- References
307
- ----------
308
- .. [1] Ulrik Brandes: On Variants of Shortest-Path Betweenness
309
- Centrality and their Generic Computation.
310
- Social Networks 30(2):136--145, 2008.
311
- https://doi.org/10.1016/j.socnet.2007.11.001
312
-
313
- Examples
314
- --------
315
- Consider an undirected 3-path. Each pair of nodes has exactly one shortest
316
- path between them. Since the graph is undirected, only ordered pairs are counted.
317
- Each edge has two shortest paths passing through it.
318
- As such, the raw counts should be ``{(0, 1): 2, (1, 2): 2}``.
319
-
320
- >>> G = nx.path_graph(3)
321
- >>> nx.edge_betweenness_centrality(G, normalized=False)
322
- {(0, 1): 2.0, (1, 2): 2.0}
323
-
324
- With normalization, the values are divided by the number of ordered $(s, t)$-pairs,
325
- which is $n(n-1)/2$. For the 3-path, this is $3(3-1)/2 = 3$.
326
-
327
- >>> nx.edge_betweenness_centrality(G, normalized=True)
328
- {(0, 1): 0.6666666666666666, (1, 2): 0.6666666666666666}
329
-
330
- For a directed graph, all $(s, t)$-pairs are considered. The normalization factor
331
- is $n(n-1)$ to reflect this.
332
-
333
- >>> DG = nx.path_graph(3, create_using=nx.DiGraph)
334
- >>> nx.edge_betweenness_centrality(DG, normalized=False)
335
- {(0, 1): 2.0, (1, 2): 2.0}
336
- >>> nx.edge_betweenness_centrality(DG, normalized=True)
337
- {(0, 1): 0.3333333333333333, (1, 2): 0.3333333333333333}
338
-
339
- Computing the full edge betweenness centrality can be costly.
340
- This function can also be used to compute approximate edge betweenness centrality
341
- by setting `k`. This determines the number of source nodes to sample.
342
-
343
- Since the partial sums only include `k` terms, instead of ``n``,
344
- we multiply them by ``n / k``, to approximate the full sum.
345
- As the sets of sources and targets are not the same anymore,
346
- paths have to be counted in a directed way. We thus count each as half a path.
347
- This ensures that the results approximate the standard betweenness for ``k == n``.
348
-
349
- For instance, in the undirected 3-path graph case, setting ``k = 2`` (with ``seed=42``)
350
- selects nodes 0 and 2 as sources.
351
- This means only shortest paths starting at these nodes are considered.
352
- The raw counts are ``{(0, 1): 3, (1, 2): 3}``. Accounting for the partial sum
353
- and applying the undirectedness half-path correction, we get
354
-
355
- >>> nx.edge_betweenness_centrality(G, k=2, normalized=False, seed=42)
356
- {(0, 1): 2.25, (1, 2): 2.25}
357
-
358
- When normalizing, we instead want to divide by the total number of $(s, t)$-pairs.
359
- This is $k(n-1)$, which is $4$ in our case.
360
-
361
- >>> nx.edge_betweenness_centrality(G, k=2, normalized=True, seed=42)
362
- {(0, 1): 0.75, (1, 2): 0.75}
363
- """
364
- betweenness = dict.fromkeys(G, 0.0) # b[v]=0 for v in G
365
- # b[e]=0 for e in G.edges()
366
- betweenness.update(dict.fromkeys(G.edges(), 0.0))
367
- if k is None:
368
- nodes = G
369
- else:
370
- nodes = seed.sample(list(G.nodes()), k)
371
- for s in nodes:
372
- # single source shortest paths
373
- if weight is None: # use BFS
374
- S, P, sigma, _ = _single_source_shortest_path_basic(G, s)
375
- else: # use Dijkstra's algorithm
376
- S, P, sigma, _ = _single_source_dijkstra_path_basic(G, s, weight)
377
- # accumulation
378
- betweenness = _accumulate_edges(betweenness, S, P, sigma, s)
379
- # rescaling
380
- for n in G: # remove nodes to only return edges
381
- del betweenness[n]
382
- betweenness = _rescale(
383
- betweenness,
384
- len(G),
385
- normalized=normalized,
386
- directed=G.is_directed(),
387
- sampled_nodes=None if k is None else nodes,
388
- )
389
- if G.is_multigraph():
390
- betweenness = _add_edge_keys(G, betweenness, weight=weight)
391
- return betweenness
392
-
393
-
394
- # helpers for betweenness centrality
395
-
396
-
397
- def _single_source_shortest_path_basic(G, s):
398
- S = []
399
- P = {}
400
- for v in G:
401
- P[v] = []
402
- sigma = dict.fromkeys(G, 0.0) # sigma[v]=0 for v in G
403
- D = {}
404
- sigma[s] = 1.0
405
- D[s] = 0
406
- Q = deque([s])
407
- while Q: # use BFS to find shortest paths
408
- v = Q.popleft()
409
- S.append(v)
410
- Dv = D[v]
411
- sigmav = sigma[v]
412
- for w in G[v]:
413
- if w not in D:
414
- Q.append(w)
415
- D[w] = Dv + 1
416
- if D[w] == Dv + 1: # this is a shortest path, count paths
417
- sigma[w] += sigmav
418
- P[w].append(v) # predecessors
419
- return S, P, sigma, D
420
-
421
-
422
- def _single_source_dijkstra_path_basic(G, s, weight):
423
- weight = _weight_function(G, weight)
424
- # modified from Eppstein
425
- S = []
426
- P = {}
427
- for v in G:
428
- P[v] = []
429
- sigma = dict.fromkeys(G, 0.0) # sigma[v]=0 for v in G
430
- D = {}
431
- sigma[s] = 1.0
432
- seen = {s: 0}
433
- c = count()
434
- Q = [] # use Q as heap with (distance,node id) tuples
435
- heappush(Q, (0, next(c), s, s))
436
- while Q:
437
- (dist, _, pred, v) = heappop(Q)
438
- if v in D:
439
- continue # already searched this node.
440
- sigma[v] += sigma[pred] # count paths
441
- S.append(v)
442
- D[v] = dist
443
- for w, edgedata in G[v].items():
444
- vw_dist = dist + weight(v, w, edgedata)
445
- if w not in D and (w not in seen or vw_dist < seen[w]):
446
- seen[w] = vw_dist
447
- heappush(Q, (vw_dist, next(c), v, w))
448
- sigma[w] = 0.0
449
- P[w] = [v]
450
- elif vw_dist == seen[w]: # handle equal paths
451
- sigma[w] += sigma[v]
452
- P[w].append(v)
453
- return S, P, sigma, D
454
-
455
-
456
- def _accumulate_basic(betweenness, S, P, sigma, s):
457
- delta = dict.fromkeys(S, 0)
458
- while S:
459
- w = S.pop()
460
- coeff = (1 + delta[w]) / sigma[w]
461
- for v in P[w]:
462
- delta[v] += sigma[v] * coeff
463
- if w != s:
464
- betweenness[w] += delta[w]
465
- return betweenness, delta
466
-
467
-
468
- def _accumulate_endpoints(betweenness, S, P, sigma, s):
469
- betweenness[s] += len(S) - 1
470
- delta = dict.fromkeys(S, 0)
471
- while S:
472
- w = S.pop()
473
- coeff = (1 + delta[w]) / sigma[w]
474
- for v in P[w]:
475
- delta[v] += sigma[v] * coeff
476
- if w != s:
477
- betweenness[w] += delta[w] + 1
478
- return betweenness, delta
479
-
480
-
481
- def _accumulate_edges(betweenness, S, P, sigma, s):
482
- delta = dict.fromkeys(S, 0)
483
- while S:
484
- w = S.pop()
485
- coeff = (1 + delta[w]) / sigma[w]
486
- for v in P[w]:
487
- c = sigma[v] * coeff
488
- if (v, w) not in betweenness:
489
- betweenness[(w, v)] += c
490
- else:
491
- betweenness[(v, w)] += c
492
- delta[v] += c
493
- if w != s:
494
- betweenness[w] += delta[w]
495
- return betweenness
496
-
497
-
498
- def _rescale(
499
- betweenness, n, *, normalized, directed, endpoints=True, sampled_nodes=None
500
- ):
501
- # For edge betweenness, `endpoints` is always `True`.
502
-
503
- k = None if sampled_nodes is None else len(sampled_nodes)
504
- # N is used to count the number of valid (s, t) pairs where s != t that
505
- # could have a path pass through v. If endpoints is False, then v must
506
- # not be the target t, hence why we subtract by 1.
507
- N = n if endpoints else n - 1
508
- if N < 2:
509
- # No rescaling necessary: b=0 for all nodes
510
- return betweenness
511
-
512
- K_source = N if k is None else k
513
-
514
- if k is None or endpoints:
515
- # No sampling adjustment needed
516
- if normalized:
517
- # Divide by the number of valid (s, t) node pairs that could have
518
- # a path through v where s != t.
519
- scale = 1 / (K_source * (N - 1))
520
- else:
521
- # Scale to the full BC
522
- if not directed:
523
- # The non-normalized BC values are computed the same way for
524
- # directed and undirected graphs: shortest paths are computed and
525
- # counted for each *ordered* (s, t) pair. Undirected graphs should
526
- # only count valid *unordered* node pairs {s, t}; that is, (s, t)
527
- # and (t, s) should be counted only once. We correct for this here.
528
- correction = 2
529
- else:
530
- correction = 1
531
- scale = N / (K_source * correction)
532
-
533
- if scale != 1:
534
- for v in betweenness:
535
- betweenness[v] *= scale
536
- return betweenness
537
-
538
- # Sampling adjustment needed when excluding endpoints when using k. In this
539
- # case, we need to handle source nodes differently from non-source nodes,
540
- # because source nodes can't include themselves since endpoints are excluded.
541
- # Without this, k == n would be a special case that would violate the
542
- # assumption that node `v` is not one of the (s, t) node pairs.
543
- if normalized:
544
- # NaN for undefined 0/0; there is no data for source node when k=1
545
- scale_source = 1 / ((K_source - 1) * (N - 1)) if K_source > 1 else math.nan
546
- scale_nonsource = 1 / (K_source * (N - 1))
547
- else:
548
- correction = 1 if directed else 2
549
- scale_source = N / ((K_source - 1) * correction) if K_source > 1 else math.nan
550
- scale_nonsource = N / (K_source * correction)
551
-
552
- sampled_nodes = set(sampled_nodes)
553
- for v in betweenness:
554
- betweenness[v] *= scale_source if v in sampled_nodes else scale_nonsource
555
- return betweenness
556
-
557
-
558
- @not_implemented_for("graph")
559
- def _add_edge_keys(G, betweenness, weight=None):
560
- r"""Adds the corrected betweenness centrality (BC) values for multigraphs.
561
-
562
- Parameters
563
- ----------
564
- G : NetworkX graph.
565
-
566
- betweenness : dictionary
567
- Dictionary mapping adjacent node tuples to betweenness centrality values.
568
-
569
- weight : string or function
570
- See `_weight_function` for details. Defaults to `None`.
571
-
572
- Returns
573
- -------
574
- edges : dictionary
575
- The parameter `betweenness` including edges with keys and their
576
- betweenness centrality values.
577
-
578
- The BC value is divided among edges of equal weight.
579
- """
580
- _weight = _weight_function(G, weight)
581
-
582
- edge_bc = dict.fromkeys(G.edges, 0.0)
583
- for u, v in betweenness:
584
- d = G[u][v]
585
- wt = _weight(u, v, d)
586
- keys = [k for k in d if _weight(u, v, {k: d[k]}) == wt]
587
- bc = betweenness[(u, v)] / len(keys)
588
- for k in keys:
589
- edge_bc[(u, v, k)] = bc
590
-
591
- return edge_bc