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,981 +0,0 @@
1
- """
2
- Threshold Graphs - Creation, manipulation and identification.
3
- """
4
-
5
- from math import sqrt
6
-
7
- import networkx as nx
8
- from networkx.utils import py_random_state
9
-
10
- __all__ = ["is_threshold_graph", "find_threshold_graph"]
11
-
12
-
13
- @nx._dispatchable
14
- def is_threshold_graph(G):
15
- """
16
- Returns `True` if `G` is a threshold graph.
17
-
18
- Parameters
19
- ----------
20
- G : NetworkX graph instance
21
- An instance of `Graph`, `DiGraph`, `MultiGraph` or `MultiDiGraph`
22
-
23
- Returns
24
- -------
25
- bool
26
- `True` if `G` is a threshold graph, `False` otherwise.
27
-
28
- Examples
29
- --------
30
- >>> from networkx.algorithms.threshold import is_threshold_graph
31
- >>> G = nx.path_graph(3)
32
- >>> is_threshold_graph(G)
33
- True
34
- >>> G = nx.barbell_graph(3, 3)
35
- >>> is_threshold_graph(G)
36
- False
37
-
38
- References
39
- ----------
40
- .. [1] Threshold graphs: https://en.wikipedia.org/wiki/Threshold_graph
41
- """
42
- return is_threshold_sequence([d for n, d in G.degree()])
43
-
44
-
45
- def is_threshold_sequence(degree_sequence):
46
- """
47
- Returns True if the sequence is a threshold degree sequence.
48
-
49
- Uses the property that a threshold graph must be constructed by
50
- adding either dominating or isolated nodes. Thus, it can be
51
- deconstructed iteratively by removing a node of degree zero or a
52
- node that connects to the remaining nodes. If this deconstruction
53
- fails then the sequence is not a threshold sequence.
54
- """
55
- ds = degree_sequence[:] # get a copy so we don't destroy original
56
- ds.sort()
57
- while ds:
58
- if ds[0] == 0: # if isolated node
59
- ds.pop(0) # remove it
60
- continue
61
- if ds[-1] != len(ds) - 1: # is the largest degree node dominating?
62
- return False # no, not a threshold degree sequence
63
- ds.pop() # yes, largest is the dominating node
64
- ds = [d - 1 for d in ds] # remove it and decrement all degrees
65
- return True
66
-
67
-
68
- def creation_sequence(degree_sequence, with_labels=False, compact=False):
69
- """
70
- Determines the creation sequence for the given threshold degree sequence.
71
-
72
- The creation sequence is a list of single characters 'd'
73
- or 'i': 'd' for dominating or 'i' for isolated vertices.
74
- Dominating vertices are connected to all vertices present when it
75
- is added. The first node added is by convention 'd'.
76
- This list can be converted to a string if desired using "".join(cs)
77
-
78
- If with_labels==True:
79
- Returns a list of 2-tuples containing the vertex number
80
- and a character 'd' or 'i' which describes the type of vertex.
81
-
82
- If compact==True:
83
- Returns the creation sequence in a compact form that is the number
84
- of 'i's and 'd's alternating.
85
- Examples:
86
- [1,2,2,3] represents d,i,i,d,d,i,i,i
87
- [3,1,2] represents d,d,d,i,d,d
88
-
89
- Notice that the first number is the first vertex to be used for
90
- construction and so is always 'd'.
91
-
92
- with_labels and compact cannot both be True.
93
-
94
- Returns None if the sequence is not a threshold sequence
95
- """
96
- if with_labels and compact:
97
- raise ValueError("compact sequences cannot be labeled")
98
-
99
- # make an indexed copy
100
- if isinstance(degree_sequence, dict): # labeled degree sequence
101
- ds = [[degree, label] for (label, degree) in degree_sequence.items()]
102
- else:
103
- ds = [[d, i] for i, d in enumerate(degree_sequence)]
104
- ds.sort()
105
- cs = [] # creation sequence
106
- while ds:
107
- if ds[0][0] == 0: # isolated node
108
- (d, v) = ds.pop(0)
109
- if len(ds) > 0: # make sure we start with a d
110
- cs.insert(0, (v, "i"))
111
- else:
112
- cs.insert(0, (v, "d"))
113
- continue
114
- if ds[-1][0] != len(ds) - 1: # Not dominating node
115
- return None # not a threshold degree sequence
116
- (d, v) = ds.pop()
117
- cs.insert(0, (v, "d"))
118
- ds = [[d[0] - 1, d[1]] for d in ds] # decrement due to removing node
119
-
120
- if with_labels:
121
- return cs
122
- if compact:
123
- return make_compact(cs)
124
- return [v[1] for v in cs] # not labeled
125
-
126
-
127
- def make_compact(creation_sequence):
128
- """
129
- Returns the creation sequence in a compact form
130
- that is the number of 'i's and 'd's alternating.
131
-
132
- Examples
133
- --------
134
- >>> from networkx.algorithms.threshold import make_compact
135
- >>> make_compact(["d", "i", "i", "d", "d", "i", "i", "i"])
136
- [1, 2, 2, 3]
137
- >>> make_compact(["d", "d", "d", "i", "d", "d"])
138
- [3, 1, 2]
139
-
140
- Notice that the first number is the first vertex
141
- to be used for construction and so is always 'd'.
142
-
143
- Labeled creation sequences lose their labels in the
144
- compact representation.
145
-
146
- >>> make_compact([3, 1, 2])
147
- [3, 1, 2]
148
- """
149
- first = creation_sequence[0]
150
- if isinstance(first, str): # creation sequence
151
- cs = creation_sequence[:]
152
- elif isinstance(first, tuple): # labeled creation sequence
153
- cs = [s[1] for s in creation_sequence]
154
- elif isinstance(first, int): # compact creation sequence
155
- return creation_sequence
156
- else:
157
- raise TypeError("Not a valid creation sequence type")
158
-
159
- ccs = []
160
- count = 1 # count the run lengths of d's or i's.
161
- for i in range(1, len(cs)):
162
- if cs[i] == cs[i - 1]:
163
- count += 1
164
- else:
165
- ccs.append(count)
166
- count = 1
167
- ccs.append(count) # don't forget the last one
168
- return ccs
169
-
170
-
171
- def uncompact(creation_sequence):
172
- """
173
- Converts a compact creation sequence for a threshold
174
- graph to a standard creation sequence (unlabeled).
175
- If the creation_sequence is already standard, return it.
176
- See creation_sequence.
177
- """
178
- first = creation_sequence[0]
179
- if isinstance(first, str): # creation sequence
180
- return creation_sequence
181
- elif isinstance(first, tuple): # labeled creation sequence
182
- return creation_sequence
183
- elif isinstance(first, int): # compact creation sequence
184
- ccscopy = creation_sequence[:]
185
- else:
186
- raise TypeError("Not a valid creation sequence type")
187
- cs = []
188
- while ccscopy:
189
- cs.extend(ccscopy.pop(0) * ["d"])
190
- if ccscopy:
191
- cs.extend(ccscopy.pop(0) * ["i"])
192
- return cs
193
-
194
-
195
- def creation_sequence_to_weights(creation_sequence):
196
- """
197
- Returns a list of node weights which create the threshold
198
- graph designated by the creation sequence. The weights
199
- are scaled so that the threshold is 1.0. The order of the
200
- nodes is the same as that in the creation sequence.
201
- """
202
- # Turn input sequence into a labeled creation sequence
203
- first = creation_sequence[0]
204
- if isinstance(first, str): # creation sequence
205
- if isinstance(creation_sequence, list):
206
- wseq = creation_sequence[:]
207
- else:
208
- wseq = list(creation_sequence) # string like 'ddidid'
209
- elif isinstance(first, tuple): # labeled creation sequence
210
- wseq = [v[1] for v in creation_sequence]
211
- elif isinstance(first, int): # compact creation sequence
212
- wseq = uncompact(creation_sequence)
213
- else:
214
- raise TypeError("Not a valid creation sequence type")
215
- # pass through twice--first backwards
216
- wseq.reverse()
217
- w = 0
218
- prev = "i"
219
- for j, s in enumerate(wseq):
220
- if s == "i":
221
- wseq[j] = w
222
- prev = s
223
- elif prev == "i":
224
- prev = s
225
- w += 1
226
- wseq.reverse() # now pass through forwards
227
- for j, s in enumerate(wseq):
228
- if s == "d":
229
- wseq[j] = w
230
- prev = s
231
- elif prev == "d":
232
- prev = s
233
- w += 1
234
- # Now scale weights
235
- if prev == "d":
236
- w += 1
237
- wscale = 1 / w
238
- return [ww * wscale for ww in wseq]
239
- # return wseq
240
-
241
-
242
- def weights_to_creation_sequence(
243
- weights, threshold=1, with_labels=False, compact=False
244
- ):
245
- """
246
- Returns a creation sequence for a threshold graph
247
- determined by the weights and threshold given as input.
248
- If the sum of two node weights is greater than the
249
- threshold value, an edge is created between these nodes.
250
-
251
- The creation sequence is a list of single characters 'd'
252
- or 'i': 'd' for dominating or 'i' for isolated vertices.
253
- Dominating vertices are connected to all vertices present
254
- when it is added. The first node added is by convention 'd'.
255
-
256
- If with_labels==True:
257
- Returns a list of 2-tuples containing the vertex number
258
- and a character 'd' or 'i' which describes the type of vertex.
259
-
260
- If compact==True:
261
- Returns the creation sequence in a compact form that is the number
262
- of 'i's and 'd's alternating.
263
- Examples:
264
- [1,2,2,3] represents d,i,i,d,d,i,i,i
265
- [3,1,2] represents d,d,d,i,d,d
266
-
267
- Notice that the first number is the first vertex to be used for
268
- construction and so is always 'd'.
269
-
270
- with_labels and compact cannot both be True.
271
- """
272
- if with_labels and compact:
273
- raise ValueError("compact sequences cannot be labeled")
274
-
275
- # make an indexed copy
276
- if isinstance(weights, dict): # labeled weights
277
- wseq = [[w, label] for (label, w) in weights.items()]
278
- else:
279
- wseq = [[w, i] for i, w in enumerate(weights)]
280
- wseq.sort()
281
- cs = [] # creation sequence
282
- cutoff = threshold - wseq[-1][0]
283
- while wseq:
284
- if wseq[0][0] < cutoff: # isolated node
285
- (w, label) = wseq.pop(0)
286
- cs.append((label, "i"))
287
- else:
288
- (w, label) = wseq.pop()
289
- cs.append((label, "d"))
290
- cutoff = threshold - wseq[-1][0]
291
- if len(wseq) == 1: # make sure we start with a d
292
- (w, label) = wseq.pop()
293
- cs.append((label, "d"))
294
- # put in correct order
295
- cs.reverse()
296
-
297
- if with_labels:
298
- return cs
299
- if compact:
300
- return make_compact(cs)
301
- return [v[1] for v in cs] # not labeled
302
-
303
-
304
- # Manipulating NetworkX.Graphs in context of threshold graphs
305
- @nx._dispatchable(graphs=None, returns_graph=True)
306
- def threshold_graph(creation_sequence, create_using=None):
307
- """
308
- Create a threshold graph from the creation sequence or compact
309
- creation_sequence.
310
-
311
- The input sequence can be a
312
-
313
- creation sequence (e.g. ['d','i','d','d','d','i'])
314
- labeled creation sequence (e.g. [(0,'d'),(2,'d'),(1,'i')])
315
- compact creation sequence (e.g. [2,1,1,2,0])
316
-
317
- Use cs=creation_sequence(degree_sequence,labeled=True)
318
- to convert a degree sequence to a creation sequence.
319
-
320
- Returns None if the sequence is not valid
321
- """
322
- # Turn input sequence into a labeled creation sequence
323
- first = creation_sequence[0]
324
- if isinstance(first, str): # creation sequence
325
- ci = list(enumerate(creation_sequence))
326
- elif isinstance(first, tuple): # labeled creation sequence
327
- ci = creation_sequence[:]
328
- elif isinstance(first, int): # compact creation sequence
329
- cs = uncompact(creation_sequence)
330
- ci = list(enumerate(cs))
331
- else:
332
- raise ValueError("not a valid creation sequence")
333
-
334
- G = nx.empty_graph(0, create_using)
335
- if G.is_directed():
336
- raise nx.NetworkXError("Directed Graph not supported")
337
-
338
- G.name = "Threshold Graph"
339
-
340
- # add nodes and edges
341
- # if type is 'i' just add nodea
342
- # if type is a d connect to everything previous
343
- while ci:
344
- (v, node_type) = ci.pop(0)
345
- if node_type == "d": # dominating type, connect to all existing nodes
346
- # We use `for u in list(G):` instead of
347
- # `for u in G:` because we edit the graph `G` in
348
- # the loop. Hence using an iterator will result in
349
- # `RuntimeError: dictionary changed size during iteration`
350
- for u in list(G):
351
- G.add_edge(v, u)
352
- G.add_node(v)
353
- return G
354
-
355
-
356
- @nx._dispatchable
357
- def find_alternating_4_cycle(G):
358
- """
359
- Returns False if there aren't any alternating 4 cycles.
360
- Otherwise returns the cycle as [a,b,c,d] where (a,b)
361
- and (c,d) are edges and (a,c) and (b,d) are not.
362
- """
363
- for u, v in G.edges():
364
- for w in G.nodes():
365
- if not G.has_edge(u, w) and u != w:
366
- for x in G.neighbors(w):
367
- if not G.has_edge(v, x) and v != x:
368
- return [u, v, w, x]
369
- return False
370
-
371
-
372
- @nx._dispatchable(returns_graph=True)
373
- def find_threshold_graph(G, create_using=None):
374
- """
375
- Returns a threshold subgraph that is close to largest in `G`.
376
-
377
- The threshold graph will contain the largest degree node in G.
378
-
379
- Parameters
380
- ----------
381
- G : NetworkX graph instance
382
- An instance of `Graph`, or `MultiDiGraph`
383
- create_using : NetworkX graph class or `None` (default), optional
384
- Type of graph to use when constructing the threshold graph.
385
- If `None`, infer the appropriate graph type from the input.
386
-
387
- Returns
388
- -------
389
- graph :
390
- A graph instance representing the threshold graph
391
-
392
- Examples
393
- --------
394
- >>> from networkx.algorithms.threshold import find_threshold_graph
395
- >>> G = nx.barbell_graph(3, 3)
396
- >>> T = find_threshold_graph(G)
397
- >>> T.nodes # may vary
398
- NodeView((7, 8, 5, 6))
399
-
400
- References
401
- ----------
402
- .. [1] Threshold graphs: https://en.wikipedia.org/wiki/Threshold_graph
403
- """
404
- return threshold_graph(find_creation_sequence(G), create_using)
405
-
406
-
407
- @nx._dispatchable
408
- def find_creation_sequence(G):
409
- """
410
- Find a threshold subgraph that is close to largest in G.
411
- Returns the labeled creation sequence of that threshold graph.
412
- """
413
- cs = []
414
- # get a local pointer to the working part of the graph
415
- H = G
416
- while H.order() > 0:
417
- # get new degree sequence on subgraph
418
- dsdict = dict(H.degree())
419
- ds = [(d, v) for v, d in dsdict.items()]
420
- ds.sort()
421
- # Update threshold graph nodes
422
- if ds[-1][0] == 0: # all are isolated
423
- cs.extend(zip(dsdict, ["i"] * (len(ds) - 1) + ["d"]))
424
- break # Done!
425
- # pull off isolated nodes
426
- while ds[0][0] == 0:
427
- (d, iso) = ds.pop(0)
428
- cs.append((iso, "i"))
429
- # find new biggest node
430
- (d, bigv) = ds.pop()
431
- # add edges of star to t_g
432
- cs.append((bigv, "d"))
433
- # form subgraph of neighbors of big node
434
- H = H.subgraph(H.neighbors(bigv))
435
- cs.reverse()
436
- return cs
437
-
438
-
439
- # Properties of Threshold Graphs
440
- def triangles(creation_sequence):
441
- """
442
- Compute number of triangles in the threshold graph with the
443
- given creation sequence.
444
- """
445
- # shortcut algorithm that doesn't require computing number
446
- # of triangles at each node.
447
- cs = creation_sequence # alias
448
- dr = cs.count("d") # number of d's in sequence
449
- ntri = dr * (dr - 1) * (dr - 2) / 6 # number of triangles in clique of nd d's
450
- # now add dr choose 2 triangles for every 'i' in sequence where
451
- # dr is the number of d's to the right of the current i
452
- for i, typ in enumerate(cs):
453
- if typ == "i":
454
- ntri += dr * (dr - 1) / 2
455
- else:
456
- dr -= 1
457
- return ntri
458
-
459
-
460
- def triangle_sequence(creation_sequence):
461
- """
462
- Return triangle sequence for the given threshold graph creation sequence.
463
-
464
- """
465
- cs = creation_sequence
466
- seq = []
467
- dr = cs.count("d") # number of d's to the right of the current pos
468
- dcur = (dr - 1) * (dr - 2) // 2 # number of triangles through a node of clique dr
469
- irun = 0 # number of i's in the last run
470
- drun = 0 # number of d's in the last run
471
- for i, sym in enumerate(cs):
472
- if sym == "d":
473
- drun += 1
474
- tri = dcur + (dr - 1) * irun # new triangles at this d
475
- else: # cs[i]="i":
476
- if prevsym == "d": # new string of i's
477
- dcur += (dr - 1) * irun # accumulate shared shortest paths
478
- irun = 0 # reset i run counter
479
- dr -= drun # reduce number of d's to right
480
- drun = 0 # reset d run counter
481
- irun += 1
482
- tri = dr * (dr - 1) // 2 # new triangles at this i
483
- seq.append(tri)
484
- prevsym = sym
485
- return seq
486
-
487
-
488
- def cluster_sequence(creation_sequence):
489
- """
490
- Return cluster sequence for the given threshold graph creation sequence.
491
- """
492
- triseq = triangle_sequence(creation_sequence)
493
- degseq = degree_sequence(creation_sequence)
494
- cseq = []
495
- for i, deg in enumerate(degseq):
496
- tri = triseq[i]
497
- if deg <= 1: # isolated vertex or single pair gets cc 0
498
- cseq.append(0)
499
- continue
500
- max_size = (deg * (deg - 1)) // 2
501
- cseq.append(tri / max_size)
502
- return cseq
503
-
504
-
505
- def degree_sequence(creation_sequence):
506
- """
507
- Return degree sequence for the threshold graph with the given
508
- creation sequence
509
- """
510
- cs = creation_sequence # alias
511
- seq = []
512
- rd = cs.count("d") # number of d to the right
513
- for i, sym in enumerate(cs):
514
- if sym == "d":
515
- rd -= 1
516
- seq.append(rd + i)
517
- else:
518
- seq.append(rd)
519
- return seq
520
-
521
-
522
- def density(creation_sequence):
523
- """
524
- Return the density of the graph with this creation_sequence.
525
- The density is the fraction of possible edges present.
526
- """
527
- N = len(creation_sequence)
528
- two_size = sum(degree_sequence(creation_sequence))
529
- two_possible = N * (N - 1)
530
- den = two_size / two_possible
531
- return den
532
-
533
-
534
- def degree_correlation(creation_sequence):
535
- """
536
- Return the degree-degree correlation over all edges.
537
- """
538
- cs = creation_sequence
539
- s1 = 0 # deg_i*deg_j
540
- s2 = 0 # deg_i^2+deg_j^2
541
- s3 = 0 # deg_i+deg_j
542
- m = 0 # number of edges
543
- rd = cs.count("d") # number of d nodes to the right
544
- rdi = [i for i, sym in enumerate(cs) if sym == "d"] # index of "d"s
545
- ds = degree_sequence(cs)
546
- for i, sym in enumerate(cs):
547
- if sym == "d":
548
- rdi.pop(0)
549
- degi = ds[i]
550
- for dj in rdi:
551
- degj = ds[dj]
552
- s1 += degj * degi
553
- s2 += degi**2 + degj**2
554
- s3 += degi + degj
555
- m += 1
556
- denom = 2 * m * s2 - s3 * s3
557
- numer = 4 * m * s1 - s3 * s3
558
- if denom == 0:
559
- if numer == 0:
560
- return 1
561
- raise ValueError(f"Zero Denominator but Numerator is {numer}")
562
- return numer / denom
563
-
564
-
565
- def shortest_path(creation_sequence, u, v):
566
- """
567
- Find the shortest path between u and v in a
568
- threshold graph G with the given creation_sequence.
569
-
570
- For an unlabeled creation_sequence, the vertices
571
- u and v must be integers in (0,len(sequence)) referring
572
- to the position of the desired vertices in the sequence.
573
-
574
- For a labeled creation_sequence, u and v are labels of vertices.
575
-
576
- Use cs=creation_sequence(degree_sequence,with_labels=True)
577
- to convert a degree sequence to a creation sequence.
578
-
579
- Returns a list of vertices from u to v.
580
- Example: if they are neighbors, it returns [u,v]
581
- """
582
- # Turn input sequence into a labeled creation sequence
583
- first = creation_sequence[0]
584
- if isinstance(first, str): # creation sequence
585
- cs = [(i, creation_sequence[i]) for i in range(len(creation_sequence))]
586
- elif isinstance(first, tuple): # labeled creation sequence
587
- cs = creation_sequence[:]
588
- elif isinstance(first, int): # compact creation sequence
589
- ci = uncompact(creation_sequence)
590
- cs = [(i, ci[i]) for i in range(len(ci))]
591
- else:
592
- raise TypeError("Not a valid creation sequence type")
593
-
594
- verts = [s[0] for s in cs]
595
- if v not in verts:
596
- raise ValueError(f"Vertex {v} not in graph from creation_sequence")
597
- if u not in verts:
598
- raise ValueError(f"Vertex {u} not in graph from creation_sequence")
599
- # Done checking
600
- if u == v:
601
- return [u]
602
-
603
- uindex = verts.index(u)
604
- vindex = verts.index(v)
605
- bigind = max(uindex, vindex)
606
- if cs[bigind][1] == "d":
607
- return [u, v]
608
- # must be that cs[bigind][1]=='i'
609
- cs = cs[bigind:]
610
- while cs:
611
- vert = cs.pop()
612
- if vert[1] == "d":
613
- return [u, vert[0], v]
614
- # All after u are type 'i' so no connection
615
- return -1
616
-
617
-
618
- def shortest_path_length(creation_sequence, i):
619
- """
620
- Return the shortest path length from indicated node to
621
- every other node for the threshold graph with the given
622
- creation sequence.
623
- Node is indicated by index i in creation_sequence unless
624
- creation_sequence is labeled in which case, i is taken to
625
- be the label of the node.
626
-
627
- Paths lengths in threshold graphs are at most 2.
628
- Length to unreachable nodes is set to -1.
629
- """
630
- # Turn input sequence into a labeled creation sequence
631
- first = creation_sequence[0]
632
- if isinstance(first, str): # creation sequence
633
- if isinstance(creation_sequence, list):
634
- cs = creation_sequence[:]
635
- else:
636
- cs = list(creation_sequence)
637
- elif isinstance(first, tuple): # labeled creation sequence
638
- cs = [v[1] for v in creation_sequence]
639
- i = [v[0] for v in creation_sequence].index(i)
640
- elif isinstance(first, int): # compact creation sequence
641
- cs = uncompact(creation_sequence)
642
- else:
643
- raise TypeError("Not a valid creation sequence type")
644
-
645
- # Compute
646
- N = len(cs)
647
- spl = [2] * N # length 2 to every node
648
- spl[i] = 0 # except self which is 0
649
- # 1 for all d's to the right
650
- for j in range(i + 1, N):
651
- if cs[j] == "d":
652
- spl[j] = 1
653
- if cs[i] == "d": # 1 for all nodes to the left
654
- for j in range(i):
655
- spl[j] = 1
656
- # and -1 for any trailing i to indicate unreachable
657
- for j in range(N - 1, 0, -1):
658
- if cs[j] == "d":
659
- break
660
- spl[j] = -1
661
- return spl
662
-
663
-
664
- def betweenness_sequence(creation_sequence, normalized=True):
665
- """
666
- Return betweenness for the threshold graph with the given creation
667
- sequence. The result is unscaled. To scale the values
668
- to the interval [0,1] divide by (n-1)*(n-2).
669
- """
670
- cs = creation_sequence
671
- seq = [] # betweenness
672
- lastchar = "d" # first node is always a 'd'
673
- dr = float(cs.count("d")) # number of d's to the right of current pos
674
- irun = 0 # number of i's in the last run
675
- drun = 0 # number of d's in the last run
676
- dlast = 0.0 # betweenness of last d
677
- for i, c in enumerate(cs):
678
- if c == "d": # cs[i]=="d":
679
- # betweenness = amt shared with earlier d's and i's
680
- # + new isolated nodes covered
681
- # + new paths to all previous nodes
682
- b = dlast + (irun - 1) * irun / dr + 2 * irun * (i - drun - irun) / dr
683
- drun += 1 # update counter
684
- else: # cs[i]="i":
685
- if lastchar == "d": # if this is a new run of i's
686
- dlast = b # accumulate betweenness
687
- dr -= drun # update number of d's to the right
688
- drun = 0 # reset d counter
689
- irun = 0 # reset i counter
690
- b = 0 # isolated nodes have zero betweenness
691
- irun += 1 # add another i to the run
692
- seq.append(float(b))
693
- lastchar = c
694
-
695
- # normalize by the number of possible shortest paths
696
- if normalized:
697
- order = len(cs)
698
- scale = 1.0 / ((order - 1) * (order - 2))
699
- seq = [s * scale for s in seq]
700
-
701
- return seq
702
-
703
-
704
- def eigenvectors(creation_sequence):
705
- """
706
- Return a 2-tuple of Laplacian eigenvalues and eigenvectors
707
- for the threshold network with creation_sequence.
708
- The first value is a list of eigenvalues.
709
- The second value is a list of eigenvectors.
710
- The lists are in the same order so corresponding eigenvectors
711
- and eigenvalues are in the same position in the two lists.
712
-
713
- Notice that the order of the eigenvalues returned by eigenvalues(cs)
714
- may not correspond to the order of these eigenvectors.
715
- """
716
- ccs = make_compact(creation_sequence)
717
- N = sum(ccs)
718
- vec = [0] * N
719
- val = vec[:]
720
- # get number of type d nodes to the right (all for first node)
721
- dr = sum(ccs[::2])
722
-
723
- nn = ccs[0]
724
- vec[0] = [1.0 / sqrt(N)] * N
725
- val[0] = 0
726
- e = dr
727
- dr -= nn
728
- type_d = True
729
- i = 1
730
- dd = 1
731
- while dd < nn:
732
- scale = 1.0 / sqrt(dd * dd + i)
733
- vec[i] = i * [-scale] + [dd * scale] + [0] * (N - i - 1)
734
- val[i] = e
735
- i += 1
736
- dd += 1
737
- if len(ccs) == 1:
738
- return (val, vec)
739
- for nn in ccs[1:]:
740
- scale = 1.0 / sqrt(nn * i * (i + nn))
741
- vec[i] = i * [-nn * scale] + nn * [i * scale] + [0] * (N - i - nn)
742
- # find eigenvalue
743
- type_d = not type_d
744
- if type_d:
745
- e = i + dr
746
- dr -= nn
747
- else:
748
- e = dr
749
- val[i] = e
750
- st = i
751
- i += 1
752
- dd = 1
753
- while dd < nn:
754
- scale = 1.0 / sqrt(i - st + dd * dd)
755
- vec[i] = [0] * st + (i - st) * [-scale] + [dd * scale] + [0] * (N - i - 1)
756
- val[i] = e
757
- i += 1
758
- dd += 1
759
- return (val, vec)
760
-
761
-
762
- def spectral_projection(u, eigenpairs):
763
- """
764
- Returns the coefficients of each eigenvector
765
- in a projection of the vector u onto the normalized
766
- eigenvectors which are contained in eigenpairs.
767
-
768
- eigenpairs should be a list of two objects. The
769
- first is a list of eigenvalues and the second a list
770
- of eigenvectors. The eigenvectors should be lists.
771
-
772
- There's not a lot of error checking on lengths of
773
- arrays, etc. so be careful.
774
- """
775
- coeff = []
776
- evect = eigenpairs[1]
777
- for ev in evect:
778
- c = sum(evv * uv for (evv, uv) in zip(ev, u))
779
- coeff.append(c)
780
- return coeff
781
-
782
-
783
- def eigenvalues(creation_sequence):
784
- """
785
- Return sequence of eigenvalues of the Laplacian of the threshold
786
- graph for the given creation_sequence.
787
-
788
- Based on the Ferrer's diagram method. The spectrum is integral
789
- and is the conjugate of the degree sequence.
790
-
791
- See::
792
-
793
- @Article{degree-merris-1994,
794
- author = {Russel Merris},
795
- title = {Degree maximal graphs are Laplacian integral},
796
- journal = {Linear Algebra Appl.},
797
- year = {1994},
798
- volume = {199},
799
- pages = {381--389},
800
- }
801
-
802
- """
803
- degseq = degree_sequence(creation_sequence)
804
- degseq.sort()
805
- eiglist = [] # zero is always one eigenvalue
806
- eig = 0
807
- row = len(degseq)
808
- bigdeg = degseq.pop()
809
- while row:
810
- if bigdeg < row:
811
- eiglist.append(eig)
812
- row -= 1
813
- else:
814
- eig += 1
815
- if degseq:
816
- bigdeg = degseq.pop()
817
- else:
818
- bigdeg = 0
819
- return eiglist
820
-
821
-
822
- # Threshold graph creation routines
823
-
824
-
825
- @py_random_state(2)
826
- def random_threshold_sequence(n, p, seed=None):
827
- """
828
- Create a random threshold sequence of size n.
829
- A creation sequence is built by randomly choosing d's with
830
- probability p and i's with probability 1-p.
831
-
832
- s=nx.random_threshold_sequence(10,0.5)
833
-
834
- returns a threshold sequence of length 10 with equal
835
- probably of an i or a d at each position.
836
-
837
- A "random" threshold graph can be built with
838
-
839
- G=nx.threshold_graph(s)
840
-
841
- seed : integer, random_state, or None (default)
842
- Indicator of random number generation state.
843
- See :ref:`Randomness<randomness>`.
844
- """
845
- if not (0 <= p <= 1):
846
- raise ValueError("p must be in [0,1]")
847
-
848
- cs = ["d"] # threshold sequences always start with a d
849
- for i in range(1, n):
850
- if seed.random() < p:
851
- cs.append("d")
852
- else:
853
- cs.append("i")
854
- return cs
855
-
856
-
857
- # maybe *_d_threshold_sequence routines should
858
- # be (or be called from) a single routine with a more descriptive name
859
- # and a keyword parameter?
860
- def right_d_threshold_sequence(n, m):
861
- """
862
- Returns a "right-dominated" threshold sequence with `n` vertices and `m` edges.
863
-
864
- Each vertex in the sequence is either dominant or isolated.
865
- In the "right-dominated" version, once the basic sequence is formed,
866
- isolated vertices may be flipped to dominant from the right in order
867
- to reach the target number of edges.
868
-
869
- Parameters
870
- ----------
871
- n : int
872
- Number of vertices.
873
- m : int
874
- Number of edges.
875
-
876
- Returns
877
- -------
878
- A list of 'd' (dominant) and 'i' (isolated) forming a right-dominated threshold sequence.
879
-
880
- Raises
881
- ------
882
- ValueError
883
- If `m` exceeds the maximum number of edges.
884
-
885
- Examples
886
- --------
887
- >>> from networkx.algorithms.threshold import right_d_threshold_sequence
888
- >>> right_d_threshold_sequence(5, 3)
889
- ['d', 'i', 'i', 'd', 'i']
890
- """
891
-
892
- cs = ["d"] + ["i"] * (n - 1) # create sequence with n insolated nodes
893
-
894
- # m <n : not enough edges, make disconnected
895
- if m < n:
896
- cs[m] = "d"
897
- return cs
898
-
899
- # too many edges
900
- if m > n * (n - 1) / 2:
901
- raise ValueError("Too many edges for this many nodes.")
902
-
903
- # connected case m >n-1
904
- ind = n - 1
905
- sum = n - 1
906
- while sum < m:
907
- cs[ind] = "d"
908
- ind -= 1
909
- sum += ind
910
- ind = m - (sum - ind)
911
- cs[ind] = "d"
912
- return cs
913
-
914
-
915
- def left_d_threshold_sequence(n, m):
916
- """
917
- Returns a "left-dominated" threshold sequence with `n` vertices and `m` edges.
918
-
919
- Each vertex in the sequence is either dominant or isolated.
920
- In the "left-dominated" version, once the basic sequence is formed,
921
- isolated vertices may be flipped to dominant from the left in order
922
- to reach the target number of edges.
923
-
924
- Parameters
925
- ----------
926
- n : int
927
- Number of vertices.
928
- m : int
929
- Number of edges.
930
-
931
- Returns
932
- -------
933
- A list of 'd' (dominant) and 'i' (isolated) forming a left-dominated threshold sequence.
934
-
935
- Raises
936
- ------
937
- ValueError
938
- If `m` exceeds the maximum number of edges.
939
-
940
- Examples
941
- --------
942
- For certain small cases, both left and right dominated versions produce
943
- the same sequence. However, for larger values of `m`, the difference in
944
- flipping order becomes evident. For instance, compare the sequences for
945
- ``n=6, m=8``:
946
-
947
- >>> from networkx.algorithms.threshold import left_d_threshold_sequence
948
- >>> seq = left_d_threshold_sequence(6, 8)
949
- >>> seq
950
- ['d', 'd', 'd', 'i', 'i', 'd']
951
-
952
- In contrast, the right-dominated version yields:
953
-
954
- >>> from networkx.algorithms.threshold import right_d_threshold_sequence
955
- >>> right_seq = right_d_threshold_sequence(6, 8)
956
- >>> right_seq
957
- ['d', 'i', 'i', 'd', 'i', 'd']
958
- """
959
-
960
- cs = ["d"] + ["i"] * (n - 1) # create sequence with n insolated nodes
961
-
962
- # m <n : not enough edges, make disconnected
963
- if m < n:
964
- cs[m] = "d"
965
- return cs
966
-
967
- # too many edges
968
- if m > n * (n - 1) / 2:
969
- raise ValueError("Too many edges for this many nodes.")
970
-
971
- # Connected case when M>N-1
972
- cs[n - 1] = "d"
973
- sum = n - 1
974
- ind = 1
975
- while sum < m:
976
- cs[ind] = "d"
977
- sum += ind
978
- ind += 1
979
- if sum > m: # be sure not to change the first vertex
980
- cs[sum - m] = "i"
981
- return cs