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,466 +0,0 @@
1
- """
2
- Functions for constructing matrix-like objects from graph attributes.
3
- """
4
-
5
- import networkx as nx
6
-
7
- __all__ = ["attr_matrix", "attr_sparse_matrix"]
8
-
9
-
10
- def _node_value(G, node_attr):
11
- """Returns a function that returns a value from G.nodes[u].
12
-
13
- We return a function expecting a node as its sole argument. Then, in the
14
- simplest scenario, the returned function will return G.nodes[u][node_attr].
15
- However, we also handle the case when `node_attr` is None (returns the node)
16
- or when `node_attr` is a function itself.
17
-
18
- Parameters
19
- ----------
20
- G : graph
21
- A NetworkX graph
22
-
23
- node_attr : {None, str, callable}
24
- Specification of how the value of the node attribute should be obtained
25
- from the node attribute dictionary.
26
-
27
- Returns
28
- -------
29
- value : function
30
- A function expecting a node as its sole argument. The function will
31
- returns a value from G.nodes[u] that depends on `edge_attr`.
32
-
33
- """
34
- if node_attr is None:
35
-
36
- def value(u):
37
- return u
38
-
39
- elif not callable(node_attr):
40
- # assume it is a key for the node attribute dictionary
41
- def value(u):
42
- return G.nodes[u][node_attr]
43
-
44
- else:
45
- # Advanced: Allow users to specify something else.
46
- #
47
- # For example,
48
- # node_attr = lambda u: G.nodes[u].get('size', .5) * 3
49
- #
50
- value = node_attr
51
-
52
- return value
53
-
54
-
55
- def _edge_value(G, edge_attr):
56
- """Returns a function that returns a value from G[u][v].
57
-
58
- Suppose there exists an edge between u and v. Then we return a function
59
- expecting u and v as arguments. For Graph and DiGraph, G[u][v] is
60
- the edge attribute dictionary, and the function (essentially) returns
61
- G[u][v][edge_attr]. However, we also handle cases when `edge_attr` is None
62
- and when it is a function itself. For MultiGraph and MultiDiGraph, G[u][v]
63
- is a dictionary of all edges between u and v. In this case, the returned
64
- function sums the value of `edge_attr` for every edge between u and v.
65
-
66
- Parameters
67
- ----------
68
- G : graph
69
- A NetworkX graph
70
-
71
- edge_attr : {None, str, callable}
72
- Specification of how the value of the edge attribute should be obtained
73
- from the edge attribute dictionary, G[u][v]. For multigraphs, G[u][v]
74
- is a dictionary of all the edges between u and v. This allows for
75
- special treatment of multiedges.
76
-
77
- Returns
78
- -------
79
- value : function
80
- A function expecting two nodes as parameters. The nodes should
81
- represent the from- and to- node of an edge. The function will
82
- return a value from G[u][v] that depends on `edge_attr`.
83
-
84
- """
85
-
86
- if edge_attr is None:
87
- # topological count of edges
88
-
89
- if G.is_multigraph():
90
-
91
- def value(u, v):
92
- return len(G[u][v])
93
-
94
- else:
95
-
96
- def value(u, v):
97
- return 1
98
-
99
- elif not callable(edge_attr):
100
- # assume it is a key for the edge attribute dictionary
101
-
102
- if edge_attr == "weight":
103
- # provide a default value
104
- if G.is_multigraph():
105
-
106
- def value(u, v):
107
- return sum(d.get(edge_attr, 1) for d in G[u][v].values())
108
-
109
- else:
110
-
111
- def value(u, v):
112
- return G[u][v].get(edge_attr, 1)
113
-
114
- else:
115
- # otherwise, the edge attribute MUST exist for each edge
116
- if G.is_multigraph():
117
-
118
- def value(u, v):
119
- return sum(d[edge_attr] for d in G[u][v].values())
120
-
121
- else:
122
-
123
- def value(u, v):
124
- return G[u][v][edge_attr]
125
-
126
- else:
127
- # Advanced: Allow users to specify something else.
128
- #
129
- # Alternative default value:
130
- # edge_attr = lambda u,v: G[u][v].get('thickness', .5)
131
- #
132
- # Function on an attribute:
133
- # edge_attr = lambda u,v: abs(G[u][v]['weight'])
134
- #
135
- # Handle Multi(Di)Graphs differently:
136
- # edge_attr = lambda u,v: numpy.prod([d['size'] for d in G[u][v].values()])
137
- #
138
- # Ignore multiple edges
139
- # edge_attr = lambda u,v: 1 if len(G[u][v]) else 0
140
- #
141
- value = edge_attr
142
-
143
- return value
144
-
145
-
146
- @nx._dispatchable(edge_attrs={"edge_attr": None}, node_attrs="node_attr")
147
- def attr_matrix(
148
- G,
149
- edge_attr=None,
150
- node_attr=None,
151
- normalized=False,
152
- rc_order=None,
153
- dtype=None,
154
- order=None,
155
- ):
156
- """Returns the attribute matrix using attributes from `G` as a numpy array.
157
-
158
- If only `G` is passed in, then the adjacency matrix is constructed.
159
-
160
- Let A be a discrete set of values for the node attribute `node_attr`. Then
161
- the elements of A represent the rows and columns of the constructed matrix.
162
- Now, iterate through every edge e=(u,v) in `G` and consider the value
163
- of the edge attribute `edge_attr`. If ua and va are the values of the
164
- node attribute `node_attr` for u and v, respectively, then the value of
165
- the edge attribute is added to the matrix element at (ua, va).
166
-
167
- Parameters
168
- ----------
169
- G : graph
170
- The NetworkX graph used to construct the attribute matrix.
171
-
172
- edge_attr : str, optional (default: number of edges for each matrix element)
173
- Each element of the matrix represents a running total of the
174
- specified edge attribute for edges whose node attributes correspond
175
- to the rows/cols of the matrix. The attribute must be present for
176
- all edges in the graph. If no attribute is specified, then we
177
- just count the number of edges whose node attributes correspond
178
- to the matrix element.
179
-
180
- node_attr : str, optional (default: use nodes of the graph)
181
- Each row and column in the matrix represents a particular value
182
- of the node attribute. The attribute must be present for all nodes
183
- in the graph. Note, the values of this attribute should be reliably
184
- hashable. So, float values are not recommended. If no attribute is
185
- specified, then the rows and columns will be the nodes of the graph.
186
-
187
- normalized : bool, optional (default: False)
188
- If True, then each row is normalized by the summation of its values.
189
-
190
- rc_order : list, optional (default: order of nodes in G)
191
- A list of the node attribute values. This list specifies the ordering
192
- of rows and columns of the array. If no ordering is provided, then
193
- the ordering will be the same as the node order in `G`.
194
- When `rc_order` is `None`, the function returns a 2-tuple ``(matrix, ordering)``
195
-
196
- Other Parameters
197
- ----------------
198
- dtype : NumPy data-type, optional
199
- A valid NumPy dtype used to initialize the array. Keep in mind certain
200
- dtypes can yield unexpected results if the array is to be normalized.
201
- The parameter is passed to numpy.zeros(). If unspecified, the NumPy
202
- default is used.
203
-
204
- order : {'C', 'F'}, optional
205
- Whether to store multidimensional data in C- or Fortran-contiguous
206
- (row- or column-wise) order in memory. This parameter is passed to
207
- numpy.zeros(). If unspecified, the NumPy default is used.
208
-
209
- Returns
210
- -------
211
- M : 2D NumPy ndarray
212
- The attribute matrix.
213
-
214
- ordering : list
215
- If `rc_order` was specified, then only the attribute matrix is returned.
216
- However, if `rc_order` was None, then the ordering used to construct
217
- the matrix is returned as well.
218
-
219
- Examples
220
- --------
221
- Construct an adjacency matrix:
222
-
223
- >>> G = nx.Graph()
224
- >>> G.add_edge(0, 1, thickness=1, weight=3)
225
- >>> G.add_edge(0, 2, thickness=2)
226
- >>> G.add_edge(1, 2, thickness=3)
227
- >>> nx.attr_matrix(G, rc_order=[0, 1, 2])
228
- array([[0., 1., 1.],
229
- [1., 0., 1.],
230
- [1., 1., 0.]])
231
-
232
- Alternatively, we can obtain the matrix describing edge thickness.
233
-
234
- >>> nx.attr_matrix(G, edge_attr="thickness", rc_order=[0, 1, 2])
235
- array([[0., 1., 2.],
236
- [1., 0., 3.],
237
- [2., 3., 0.]])
238
-
239
- We can also color the nodes and ask for the probability distribution over
240
- all edges (u,v) describing:
241
-
242
- Pr(v has color Y | u has color X)
243
-
244
- >>> G.nodes[0]["color"] = "red"
245
- >>> G.nodes[1]["color"] = "red"
246
- >>> G.nodes[2]["color"] = "blue"
247
- >>> rc = ["red", "blue"]
248
- >>> nx.attr_matrix(G, node_attr="color", normalized=True, rc_order=rc)
249
- array([[0.33333333, 0.66666667],
250
- [1. , 0. ]])
251
-
252
- For example, the above tells us that for all edges (u,v):
253
-
254
- Pr( v is red | u is red) = 1/3
255
- Pr( v is blue | u is red) = 2/3
256
-
257
- Pr( v is red | u is blue) = 1
258
- Pr( v is blue | u is blue) = 0
259
-
260
- Finally, we can obtain the total weights listed by the node colors.
261
-
262
- >>> nx.attr_matrix(G, edge_attr="weight", node_attr="color", rc_order=rc)
263
- array([[3., 2.],
264
- [2., 0.]])
265
-
266
- Thus, the total weight over all edges (u,v) with u and v having colors:
267
-
268
- (red, red) is 3 # the sole contribution is from edge (0,1)
269
- (red, blue) is 2 # contributions from edges (0,2) and (1,2)
270
- (blue, red) is 2 # same as (red, blue) since graph is undirected
271
- (blue, blue) is 0 # there are no edges with blue endpoints
272
-
273
- """
274
- import numpy as np
275
-
276
- edge_value = _edge_value(G, edge_attr)
277
- node_value = _node_value(G, node_attr)
278
-
279
- if rc_order is None:
280
- ordering = list({node_value(n) for n in G})
281
- else:
282
- ordering = rc_order
283
-
284
- N = len(ordering)
285
- undirected = not G.is_directed()
286
- index = dict(zip(ordering, range(N)))
287
- M = np.zeros((N, N), dtype=dtype, order=order)
288
-
289
- seen = set()
290
- for u, nbrdict in G.adjacency():
291
- for v in nbrdict:
292
- # Obtain the node attribute values.
293
- i, j = index[node_value(u)], index[node_value(v)]
294
- if v not in seen:
295
- M[i, j] += edge_value(u, v)
296
- if undirected:
297
- M[j, i] = M[i, j]
298
-
299
- if undirected:
300
- seen.add(u)
301
-
302
- if normalized:
303
- M /= M.sum(axis=1).reshape((N, 1))
304
-
305
- if rc_order is None:
306
- return M, ordering
307
- else:
308
- return M
309
-
310
-
311
- @nx._dispatchable(edge_attrs={"edge_attr": None}, node_attrs="node_attr")
312
- def attr_sparse_matrix(
313
- G, edge_attr=None, node_attr=None, normalized=False, rc_order=None, dtype=None
314
- ):
315
- """Returns a SciPy sparse array using attributes from G.
316
-
317
- If only `G` is passed in, then the adjacency matrix is constructed.
318
-
319
- Let A be a discrete set of values for the node attribute `node_attr`. Then
320
- the elements of A represent the rows and columns of the constructed matrix.
321
- Now, iterate through every edge e=(u,v) in `G` and consider the value
322
- of the edge attribute `edge_attr`. If ua and va are the values of the
323
- node attribute `node_attr` for u and v, respectively, then the value of
324
- the edge attribute is added to the matrix element at (ua, va).
325
-
326
- Parameters
327
- ----------
328
- G : graph
329
- The NetworkX graph used to construct the NumPy matrix.
330
-
331
- edge_attr : str, optional (default: number of edges for each matrix element)
332
- Each element of the matrix represents a running total of the
333
- specified edge attribute for edges whose node attributes correspond
334
- to the rows/cols of the matrix. The attribute must be present for
335
- all edges in the graph. If no attribute is specified, then we
336
- just count the number of edges whose node attributes correspond
337
- to the matrix element.
338
-
339
- node_attr : str, optional (default: use nodes of the graph)
340
- Each row and column in the matrix represents a particular value
341
- of the node attribute. The attribute must be present for all nodes
342
- in the graph. Note, the values of this attribute should be reliably
343
- hashable. So, float values are not recommended. If no attribute is
344
- specified, then the rows and columns will be the nodes of the graph.
345
-
346
- normalized : bool, optional (default: False)
347
- If True, then each row is normalized by the summation of its values.
348
-
349
- rc_order : list, optional (default: order of nodes in G)
350
- A list of the node attribute values. This list specifies the ordering
351
- of rows and columns of the array and the return value. If no ordering
352
- is provided, then the ordering will be that of nodes in `G`.
353
-
354
- Other Parameters
355
- ----------------
356
- dtype : NumPy data-type, optional
357
- A valid NumPy dtype used to initialize the array. Keep in mind certain
358
- dtypes can yield unexpected results if the array is to be normalized.
359
- The parameter is passed to numpy.zeros(). If unspecified, the NumPy
360
- default is used.
361
-
362
- Returns
363
- -------
364
- M : SciPy sparse array
365
- The attribute matrix.
366
-
367
- ordering : list
368
- If `rc_order` was specified, then only the matrix is returned.
369
- However, if `rc_order` was None, then the ordering used to construct
370
- the matrix is returned as well.
371
-
372
- Examples
373
- --------
374
- Construct an adjacency matrix:
375
-
376
- >>> G = nx.Graph()
377
- >>> G.add_edge(0, 1, thickness=1, weight=3)
378
- >>> G.add_edge(0, 2, thickness=2)
379
- >>> G.add_edge(1, 2, thickness=3)
380
- >>> M = nx.attr_sparse_matrix(G, rc_order=[0, 1, 2])
381
- >>> M.toarray()
382
- array([[0., 1., 1.],
383
- [1., 0., 1.],
384
- [1., 1., 0.]])
385
-
386
- Alternatively, we can obtain the matrix describing edge thickness.
387
-
388
- >>> M = nx.attr_sparse_matrix(G, edge_attr="thickness", rc_order=[0, 1, 2])
389
- >>> M.toarray()
390
- array([[0., 1., 2.],
391
- [1., 0., 3.],
392
- [2., 3., 0.]])
393
-
394
- We can also color the nodes and ask for the probability distribution over
395
- all edges (u,v) describing:
396
-
397
- Pr(v has color Y | u has color X)
398
-
399
- >>> G.nodes[0]["color"] = "red"
400
- >>> G.nodes[1]["color"] = "red"
401
- >>> G.nodes[2]["color"] = "blue"
402
- >>> rc = ["red", "blue"]
403
- >>> M = nx.attr_sparse_matrix(G, node_attr="color", normalized=True, rc_order=rc)
404
- >>> M.toarray()
405
- array([[0.33333333, 0.66666667],
406
- [1. , 0. ]])
407
-
408
- For example, the above tells us that for all edges (u,v):
409
-
410
- Pr( v is red | u is red) = 1/3
411
- Pr( v is blue | u is red) = 2/3
412
-
413
- Pr( v is red | u is blue) = 1
414
- Pr( v is blue | u is blue) = 0
415
-
416
- Finally, we can obtain the total weights listed by the node colors.
417
-
418
- >>> M = nx.attr_sparse_matrix(G, edge_attr="weight", node_attr="color", rc_order=rc)
419
- >>> M.toarray()
420
- array([[3., 2.],
421
- [2., 0.]])
422
-
423
- Thus, the total weight over all edges (u,v) with u and v having colors:
424
-
425
- (red, red) is 3 # the sole contribution is from edge (0,1)
426
- (red, blue) is 2 # contributions from edges (0,2) and (1,2)
427
- (blue, red) is 2 # same as (red, blue) since graph is undirected
428
- (blue, blue) is 0 # there are no edges with blue endpoints
429
-
430
- """
431
- import numpy as np
432
- import scipy as sp
433
-
434
- edge_value = _edge_value(G, edge_attr)
435
- node_value = _node_value(G, node_attr)
436
-
437
- if rc_order is None:
438
- ordering = list({node_value(n) for n in G})
439
- else:
440
- ordering = rc_order
441
-
442
- N = len(ordering)
443
- undirected = not G.is_directed()
444
- index = dict(zip(ordering, range(N)))
445
- M = sp.sparse.lil_array((N, N), dtype=dtype)
446
-
447
- seen = set()
448
- for u, nbrdict in G.adjacency():
449
- for v in nbrdict:
450
- # Obtain the node attribute values.
451
- i, j = index[node_value(u)], index[node_value(v)]
452
- if v not in seen:
453
- M[i, j] += edge_value(u, v)
454
- if undirected:
455
- M[j, i] = M[i, j]
456
-
457
- if undirected:
458
- seen.add(u)
459
-
460
- if normalized:
461
- M *= 1 / M.sum(axis=1)[:, np.newaxis] # in-place mult preserves sparse
462
-
463
- if rc_order is None:
464
- return M, ordering
465
- else:
466
- return M
@@ -1,77 +0,0 @@
1
- """Bethe Hessian or deformed Laplacian matrix of graphs."""
2
-
3
- import networkx as nx
4
- from networkx.utils import not_implemented_for
5
-
6
- __all__ = ["bethe_hessian_matrix"]
7
-
8
-
9
- @not_implemented_for("directed")
10
- @not_implemented_for("multigraph")
11
- @nx._dispatchable
12
- def bethe_hessian_matrix(G, r=None, nodelist=None):
13
- r"""Returns the Bethe Hessian matrix of G.
14
-
15
- The Bethe Hessian is a family of matrices parametrized by r, defined as
16
- H(r) = (r^2 - 1) I - r A + D where A is the adjacency matrix, D is the
17
- diagonal matrix of node degrees, and I is the identify matrix. It is equal
18
- to the graph laplacian when the regularizer r = 1.
19
-
20
- The default choice of regularizer should be the ratio [2]_
21
-
22
- .. math::
23
- r_m = \left(\sum k_i \right)^{-1}\left(\sum k_i^2 \right) - 1
24
-
25
- Parameters
26
- ----------
27
- G : Graph
28
- A NetworkX graph
29
- r : float
30
- Regularizer parameter
31
- nodelist : list, optional
32
- The rows and columns are ordered according to the nodes in nodelist.
33
- If nodelist is None, then the ordering is produced by ``G.nodes()``.
34
-
35
- Returns
36
- -------
37
- H : scipy.sparse.csr_array
38
- The Bethe Hessian matrix of `G`, with parameter `r`.
39
-
40
- Examples
41
- --------
42
- >>> k = [3, 2, 2, 1, 0]
43
- >>> G = nx.havel_hakimi_graph(k)
44
- >>> H = nx.bethe_hessian_matrix(G)
45
- >>> H.toarray()
46
- array([[ 3.5625, -1.25 , -1.25 , -1.25 , 0. ],
47
- [-1.25 , 2.5625, -1.25 , 0. , 0. ],
48
- [-1.25 , -1.25 , 2.5625, 0. , 0. ],
49
- [-1.25 , 0. , 0. , 1.5625, 0. ],
50
- [ 0. , 0. , 0. , 0. , 0.5625]])
51
-
52
- See Also
53
- --------
54
- bethe_hessian_spectrum
55
- adjacency_matrix
56
- laplacian_matrix
57
-
58
- References
59
- ----------
60
- .. [1] A. Saade, F. Krzakala and L. Zdeborová
61
- "Spectral Clustering of Graphs with the Bethe Hessian",
62
- Advances in Neural Information Processing Systems, 2014.
63
- .. [2] C. M. Le, E. Levina
64
- "Estimating the number of communities in networks by spectral methods"
65
- arXiv:1507.00827, 2015.
66
- """
67
- import scipy as sp
68
-
69
- if nodelist is None:
70
- nodelist = list(G)
71
- if r is None:
72
- r = sum(d**2 for v, d in nx.degree(G)) / sum(d for v, d in nx.degree(G)) - 1
73
- A = nx.to_scipy_sparse_array(G, nodelist=nodelist, format="csr")
74
- n, m = A.shape
75
- D = sp.sparse.dia_array((A.sum(axis=1), 0), shape=(m, n)).tocsr()
76
- I = sp.sparse.eye_array(m, n, format="csr")
77
- return (r**2 - 1) * I - r * A + D
@@ -1,168 +0,0 @@
1
- """
2
- Adjacency matrix and incidence matrix of graphs.
3
- """
4
-
5
- import networkx as nx
6
-
7
- __all__ = ["incidence_matrix", "adjacency_matrix"]
8
-
9
-
10
- @nx._dispatchable(edge_attrs="weight")
11
- def incidence_matrix(
12
- G, nodelist=None, edgelist=None, oriented=False, weight=None, *, dtype=None
13
- ):
14
- """Returns incidence matrix of G.
15
-
16
- The incidence matrix assigns each row to a node and each column to an edge.
17
- For a standard incidence matrix a 1 appears wherever a row's node is
18
- incident on the column's edge. For an oriented incidence matrix each
19
- edge is assigned an orientation (arbitrarily for undirected and aligning to
20
- direction for directed). A -1 appears for the source (tail) of an edge and
21
- 1 for the destination (head) of the edge. The elements are zero otherwise.
22
-
23
- Parameters
24
- ----------
25
- G : graph
26
- A NetworkX graph
27
-
28
- nodelist : list, optional (default= all nodes in G)
29
- The rows are ordered according to the nodes in nodelist.
30
- If nodelist is None, then the ordering is produced by G.nodes().
31
-
32
- edgelist : list, optional (default= all edges in G)
33
- The columns are ordered according to the edges in edgelist.
34
- If edgelist is None, then the ordering is produced by G.edges().
35
-
36
- oriented: bool, optional (default=False)
37
- If True, matrix elements are +1 or -1 for the head or tail node
38
- respectively of each edge. If False, +1 occurs at both nodes.
39
-
40
- weight : string or None, optional (default=None)
41
- The edge data key used to provide each value in the matrix.
42
- If None, then each edge has weight 1. Edge weights, if used,
43
- should be positive so that the orientation can provide the sign.
44
-
45
- dtype : a NumPy dtype or None (default=None)
46
- The dtype of the output sparse array. This type should be a compatible
47
- type of the weight argument, eg. if weight would return a float this
48
- argument should also be a float.
49
- If None, then the default for SciPy is used.
50
-
51
- Returns
52
- -------
53
- A : SciPy sparse array
54
- The incidence matrix of G.
55
-
56
- Notes
57
- -----
58
- For MultiGraph/MultiDiGraph, the edges in edgelist should be
59
- (u,v,key) 3-tuples.
60
-
61
- "Networks are the best discrete model for so many problems in
62
- applied mathematics" [1]_.
63
-
64
- References
65
- ----------
66
- .. [1] Gil Strang, Network applications: A = incidence matrix,
67
- http://videolectures.net/mit18085f07_strang_lec03/
68
- """
69
- import scipy as sp
70
-
71
- if nodelist is None:
72
- nodelist = list(G)
73
- if edgelist is None:
74
- if G.is_multigraph():
75
- edgelist = list(G.edges(keys=True))
76
- else:
77
- edgelist = list(G.edges())
78
- A = sp.sparse.lil_array((len(nodelist), len(edgelist)), dtype=dtype)
79
- node_index = {node: i for i, node in enumerate(nodelist)}
80
- for ei, e in enumerate(edgelist):
81
- (u, v) = e[:2]
82
- if u == v:
83
- continue # self loops give zero column
84
- try:
85
- ui = node_index[u]
86
- vi = node_index[v]
87
- except KeyError as err:
88
- raise nx.NetworkXError(
89
- f"node {u} or {v} in edgelist but not in nodelist"
90
- ) from err
91
- if weight is None:
92
- wt = 1
93
- else:
94
- if G.is_multigraph():
95
- ekey = e[2]
96
- wt = G[u][v][ekey].get(weight, 1)
97
- else:
98
- wt = G[u][v].get(weight, 1)
99
- if oriented:
100
- A[ui, ei] = -wt
101
- A[vi, ei] = wt
102
- else:
103
- A[ui, ei] = wt
104
- A[vi, ei] = wt
105
- return A.asformat("csc")
106
-
107
-
108
- @nx._dispatchable(edge_attrs="weight")
109
- def adjacency_matrix(G, nodelist=None, dtype=None, weight="weight"):
110
- """Returns adjacency matrix of `G`.
111
-
112
- Parameters
113
- ----------
114
- G : graph
115
- A NetworkX graph
116
-
117
- nodelist : list, optional
118
- The rows and columns are ordered according to the nodes in `nodelist`.
119
- If ``nodelist=None`` (the default), then the ordering is produced by
120
- ``G.nodes()``.
121
-
122
- dtype : NumPy data-type, optional
123
- The desired data-type for the array.
124
- If `None`, then the NumPy default is used.
125
-
126
- weight : string or None, optional (default='weight')
127
- The edge data key used to provide each value in the matrix.
128
- If None, then each edge has weight 1.
129
-
130
- Returns
131
- -------
132
- A : SciPy sparse array
133
- Adjacency matrix representation of G.
134
-
135
- Notes
136
- -----
137
- For directed graphs, entry ``i, j`` corresponds to an edge from ``i`` to ``j``.
138
-
139
- If you want a pure Python adjacency matrix representation try
140
- :func:`~networkx.convert.to_dict_of_dicts` which will return a
141
- dictionary-of-dictionaries format that can be addressed as a
142
- sparse matrix.
143
-
144
- For multigraphs with parallel edges the weights are summed.
145
- See :func:`networkx.convert_matrix.to_numpy_array` for other options.
146
-
147
- The convention used for self-loop edges in graphs is to assign the
148
- diagonal matrix entry value to the edge weight attribute
149
- (or the number 1 if the edge has no weight attribute). If the
150
- alternate convention of doubling the edge weight is desired the
151
- resulting SciPy sparse array can be modified as follows::
152
-
153
- >>> G = nx.Graph([(1, 1)])
154
- >>> A = nx.adjacency_matrix(G)
155
- >>> A.toarray()
156
- array([[1]])
157
- >>> A.setdiag(A.diagonal() * 2)
158
- >>> A.toarray()
159
- array([[2]])
160
-
161
- See Also
162
- --------
163
- to_numpy_array
164
- to_scipy_sparse_array
165
- to_dict_of_dicts
166
- adjacency_spectrum
167
- """
168
- return nx.to_scipy_sparse_array(G, nodelist=nodelist, dtype=dtype, weight=weight)