scientific-computing-system 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (430) hide show
  1. package/.binder/postBuild +9 -0
  2. package/.binder/requirements.txt +10 -0
  3. package/.gitattributes +35 -0
  4. package/.github/CODEOWNERS +4 -0
  5. package/.github/FUNDING.yml +3 -0
  6. package/.github/ISSUE_TEMPLATE/bug_report.md +50 -0
  7. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  8. package/.github/ISSUE_TEMPLATE/feature_request.md +28 -0
  9. package/.github/PULL_REQUEST_TEMPLATE.md +29 -0
  10. package/.github/dependabot.yml +32 -0
  11. package/.github/labeler.yml +50 -0
  12. package/.github/workflows/benchmarks.yml +97 -0
  13. package/.github/workflows/bot-reviewer.yml +58 -0
  14. package/.github/workflows/changelog.yml +130 -0
  15. package/.github/workflows/cli-package-smoke.yml +45 -0
  16. package/.github/workflows/codeql.yml +55 -0
  17. package/.github/workflows/npm-publish.yml +33 -0
  18. package/.github/workflows/p08-cancel-noncanonical-runs.yml +41 -0
  19. package/.github/workflows/pr-automation.yml +78 -0
  20. package/.github/workflows/public-external-validation-p08-v2-glm.yml +161 -0
  21. package/.github/workflows/public-external-validation-p08-v2-recovery-merge-gate.yml +72 -0
  22. package/.github/workflows/public-external-validation-p08-v2-recovery-merge.yml +113 -0
  23. package/.github/workflows/public-external-validation-p08-v2-run-recovery-anatomy-gate.yml +57 -0
  24. package/.github/workflows/public-external-validation-p08-v2-run-recovery-merge-gate.yml +63 -0
  25. package/.github/workflows/public-external-validation-p08-v2-run-recovery-merge.yml +89 -0
  26. package/.github/workflows/public-external-validation-p08-v2-run-recovery.yml +182 -0
  27. package/.github/workflows/public-external-validation-p08-v3-glm-gate.yml +67 -0
  28. package/.github/workflows/public-external-validation-p08-v4-recovery-glm-gate.yml +78 -0
  29. package/.github/workflows/public-external-validation-p08-v4-recovery-glm.yml +248 -0
  30. package/.github/workflows/public-external-validation-p08-v5-run-recovery-glm-gate.yml +66 -0
  31. package/.github/workflows/public-external-validation-p08-v5-run-recovery-glm.yml +218 -0
  32. package/.github/workflows/pypi-registry-smoke.yml +116 -0
  33. package/.github/workflows/release.yml +359 -0
  34. package/.github/workflows/tests.yml +250 -0
  35. package/.github/workflows/tmp-compassion-raw-acquire.yml +63 -0
  36. package/.github/workflows/wsl-science-runner-smoke.yml +45 -0
  37. package/.pre-commit-config.yaml +48 -0
  38. package/CHANGELOG.md +1139 -0
  39. package/CITATION.cff +29 -0
  40. package/CODE_OF_CONDUCT.md +25 -0
  41. package/CONTRIBUTING.md +275 -0
  42. package/LICENSE +21 -0
  43. package/README.md +281 -0
  44. package/ROADMAP.md +155 -0
  45. package/SECURITY.md +82 -0
  46. package/assets/logo.svg +38 -0
  47. package/assets/social_preview.png +0 -0
  48. package/benchmarks/results.json +43 -0
  49. package/benchmarks/robust_runner.py +118 -0
  50. package/benchmarks/run_benchmarks.py +394 -0
  51. package/bin/scs.js +2 -0
  52. package/cliff.toml +100 -0
  53. package/dashboard/app.py +224 -0
  54. package/docs/ARCHITECTURE.md +252 -0
  55. package/docs/CASE_STUDY_HUBBLE.md +78 -0
  56. package/docs/CASE_STUDY_QUANTUM_ML.md +79 -0
  57. package/docs/api.md +133 -0
  58. package/docs/assets/icon.svg +17 -0
  59. package/docs/assets/logo.svg +38 -0
  60. package/docs/benchmarks.md +62 -0
  61. package/docs/cookbook.md +930 -0
  62. package/docs/getting-started.md +185 -0
  63. package/docs/index.md +111 -0
  64. package/docs/maintenance.md +61 -0
  65. package/docs/ml_reference.md +92 -0
  66. package/docs/research-workflows.md +82 -0
  67. package/docs/stylesheets/extra.css +122 -0
  68. package/docs/tour_of_numerical_methods.md +330 -0
  69. package/docs/tutorials/core_demo.md +35 -0
  70. package/docs/tutorials/data_analysis_demo.md +43 -0
  71. package/docs/tutorials/diffeq_demo.md +48 -0
  72. package/docs/tutorials/fft2_demo.md +67 -0
  73. package/docs/tutorials/graph_demo.md +45 -0
  74. package/docs/tutorials/hypothesis_demo.md +44 -0
  75. package/docs/tutorials/hypothesis_tests_demo.md +170 -0
  76. package/docs/tutorials/hypothesis_with_stats_demo.md +80 -0
  77. package/docs/tutorials/knowledge_demo.md +114 -0
  78. package/docs/tutorials/linalg_demo.md +103 -0
  79. package/docs/tutorials/math_utils_demo.md +46 -0
  80. package/docs/tutorials/ml_advanced_demo.md +96 -0
  81. package/docs/tutorials/ml_and_viz_demo.md +93 -0
  82. package/docs/tutorials/ml_demo.md +70 -0
  83. package/docs/tutorials/modeling_demo.md +82 -0
  84. package/docs/tutorials/montecarlo_demo.md +42 -0
  85. package/docs/tutorials/nlp_attention_demo.md +107 -0
  86. package/docs/tutorials/nlp_bpe_demo.md +103 -0
  87. package/docs/tutorials/nlp_mini_gpt_demo.md +110 -0
  88. package/docs/tutorials/nlp_viz.md +76 -0
  89. package/docs/tutorials/numerical_integration_demo.md +65 -0
  90. package/docs/tutorials/optimization_demo.md +106 -0
  91. package/docs/tutorials/pandas_io_demo.md +160 -0
  92. package/docs/tutorials/pca_demo.md +87 -0
  93. package/docs/tutorials/probability_demo.md +48 -0
  94. package/docs/tutorials/quantum_demo.md +31 -0
  95. package/docs/tutorials/quick_start.md +44 -0
  96. package/docs/tutorials/scientific_demo.md +46 -0
  97. package/docs/tutorials/signals_demo.md +167 -0
  98. package/docs/tutorials/stats_demo.md +94 -0
  99. package/docs/tutorials/stiff_ode_demo.md +84 -0
  100. package/docs/tutorials/time_series_demo.md +145 -0
  101. package/examples/core_demo.py +40 -0
  102. package/examples/data_analysis_demo.py +60 -0
  103. package/examples/diffeq_demo.py +34 -0
  104. package/examples/discovery_pipeline_demo.py +57 -0
  105. package/examples/ensemble_showcase.py +81 -0
  106. package/examples/fft2_demo.py +32 -0
  107. package/examples/graph_demo.py +49 -0
  108. package/examples/hypothesis_custom_generator.py +121 -0
  109. package/examples/hypothesis_demo.py +48 -0
  110. package/examples/hypothesis_tests_demo.py +52 -0
  111. package/examples/hypothesis_with_stats_demo.py +43 -0
  112. package/examples/interpolate_demo.py +57 -0
  113. package/examples/knowledge_demo.py +100 -0
  114. package/examples/linalg_demo.py +61 -0
  115. package/examples/math_utils_demo.py +53 -0
  116. package/examples/ml_and_viz_demo.py +47 -0
  117. package/examples/modeling_demo.py +110 -0
  118. package/examples/montecarlo_demo.py +41 -0
  119. package/examples/nlp_attention_demo.py +168 -0
  120. package/examples/nlp_bpe_demo.py +79 -0
  121. package/examples/nlp_mini_gpt_demo.py +76 -0
  122. package/examples/nlp_viz_demo.py +98 -0
  123. package/examples/numerical_integration_demo.py +60 -0
  124. package/examples/optimization_demo.py +34 -0
  125. package/examples/pca_demo.py +124 -0
  126. package/examples/pde_demo.py +65 -0
  127. package/examples/plot_demo.py +84 -0
  128. package/examples/plotting_notebook.ipynb +87 -0
  129. package/examples/probability_demo.py +39 -0
  130. package/examples/quantum_demo.py +42 -0
  131. package/examples/scientific_demo.py +49 -0
  132. package/examples/signals_demo.py +86 -0
  133. package/examples/stats_demo.py +40 -0
  134. package/examples/tour_of_numerical_methods.ipynb +497 -0
  135. package/index.js +1 -0
  136. package/mkdocs.yml +159 -0
  137. package/package.json +1 -0
  138. package/pyproject.toml +288 -0
  139. package/requirements-dev.lock +427 -0
  140. package/requirements-dev.txt +39 -0
  141. package/requirements.lock +6 -0
  142. package/requirements.txt +13 -0
  143. package/scripts/build_gif.py +111 -0
  144. package/scripts/build_video.py +214 -0
  145. package/scripts/cleanup_deployments.py +173 -0
  146. package/scripts/crop_readme_png.py +40 -0
  147. package/scripts/make_pi_dashboard.py +316 -0
  148. package/scripts/make_pi_gif.py +138 -0
  149. package/scripts/publish.py +203 -0
  150. package/scripts/render_promo.mjs +93 -0
  151. package/scripts/render_readme.py +211 -0
  152. package/scripts/render_readme_sections.py +168 -0
  153. package/scripts/verify_cli_install.py +99 -0
  154. package/scripts/verify_cookbook.py +601 -0
  155. package/scripts/verify_d1_numerics.py +504 -0
  156. package/scripts/verify_d2_edge_cases.py +442 -0
  157. package/scripts/verify_d4_hypothesis.py +337 -0
  158. package/scripts/verify_ml_reference.py +160 -0
  159. package/scripts/verify_pypi_release.py +97 -0
  160. package/scripts/verify_release_integrity.py +194 -0
  161. package/src/cds/__init__.py +132 -0
  162. package/src/cds/__main__.py +8 -0
  163. package/src/cds/_version.py +11 -0
  164. package/src/cds/bayes/__init__.py +25 -0
  165. package/src/cds/bayes/conjugate.py +560 -0
  166. package/src/cds/cli/__init__.py +104 -0
  167. package/src/cds/cli/__main__.py +8 -0
  168. package/src/cds/cli/_handlers.py +323 -0
  169. package/src/cds/cli/_parser.py +155 -0
  170. package/src/cds/cli/_style.py +208 -0
  171. package/src/cds/cli/_system_info.py +71 -0
  172. package/src/cds/core/__init__.py +5 -0
  173. package/src/cds/core/_numeric.py +92 -0
  174. package/src/cds/core/models.py +166 -0
  175. package/src/cds/data_analysis/__init__.py +30 -0
  176. package/src/cds/data_analysis/dataset.py +122 -0
  177. package/src/cds/data_analysis/loader.py +75 -0
  178. package/src/cds/data_analysis/pandas_io.py +108 -0
  179. package/src/cds/data_analysis/transform.py +36 -0
  180. package/src/cds/data_analysis/viz.py +88 -0
  181. package/src/cds/data_io/__init__.py +27 -0
  182. package/src/cds/data_io/streaming.py +314 -0
  183. package/src/cds/diffeq/__init__.py +37 -0
  184. package/src/cds/diffeq/_implicit.py +349 -0
  185. package/src/cds/diffeq/solvers.py +312 -0
  186. package/src/cds/diffeq/symplectic.py +225 -0
  187. package/src/cds/fractals/__init__.py +34 -0
  188. package/src/cds/fractals/sets.py +356 -0
  189. package/src/cds/genetics/__init__.py +22 -0
  190. package/src/cds/genetics/sequence.py +199 -0
  191. package/src/cds/graph/__init__.py +31 -0
  192. package/src/cds/graph/algorithms.py +399 -0
  193. package/src/cds/hypothesis/__init__.py +51 -0
  194. package/src/cds/hypothesis/evaluator.py +311 -0
  195. package/src/cds/hypothesis/generator.py +275 -0
  196. package/src/cds/hypothesis/mining.py +314 -0
  197. package/src/cds/infotheory/__init__.py +25 -0
  198. package/src/cds/infotheory/measures.py +276 -0
  199. package/src/cds/interpolate/__init__.py +156 -0
  200. package/src/cds/knowledge/__init__.py +45 -0
  201. package/src/cds/knowledge/graph.py +489 -0
  202. package/src/cds/knowledge/notes.py +231 -0
  203. package/src/cds/knowledge/retrieval.py +339 -0
  204. package/src/cds/math_utils/__init__.py +46 -0
  205. package/src/cds/math_utils/calculus.py +40 -0
  206. package/src/cds/math_utils/linalg.py +496 -0
  207. package/src/cds/math_utils/special.py +167 -0
  208. package/src/cds/math_utils/svd.py +261 -0
  209. package/src/cds/ml/__init__.py +60 -0
  210. package/src/cds/ml/boosting.py +304 -0
  211. package/src/cds/ml/clustering.py +190 -0
  212. package/src/cds/ml/decomposition.py +172 -0
  213. package/src/cds/ml/ensemble.py +152 -0
  214. package/src/cds/ml/linear_models.py +225 -0
  215. package/src/cds/ml/metrics.py +227 -0
  216. package/src/cds/ml/model_selection.py +150 -0
  217. package/src/cds/ml/naive_bayes.py +179 -0
  218. package/src/cds/ml/neighbors.py +162 -0
  219. package/src/cds/ml/neural.py +204 -0
  220. package/src/cds/ml/preprocessing.py +131 -0
  221. package/src/cds/ml/tree.py +228 -0
  222. package/src/cds/ml/voting.py +175 -0
  223. package/src/cds/modeling/__init__.py +44 -0
  224. package/src/cds/modeling/_base.py +210 -0
  225. package/src/cds/modeling/_nodes.py +526 -0
  226. package/src/cds/modeling/expression.py +81 -0
  227. package/src/cds/modeling/fitting.py +477 -0
  228. package/src/cds/modeling/model.py +134 -0
  229. package/src/cds/modeling/solver.py +187 -0
  230. package/src/cds/montecarlo/__init__.py +24 -0
  231. package/src/cds/montecarlo/markov.py +112 -0
  232. package/src/cds/montecarlo/methods.py +294 -0
  233. package/src/cds/nlp/__init__.py +170 -0
  234. package/src/cds/nlp/attention.py +285 -0
  235. package/src/cds/nlp/autograd/__init__.py +70 -0
  236. package/src/cds/nlp/autograd/_grad.py +120 -0
  237. package/src/cds/nlp/autograd/ops.py +133 -0
  238. package/src/cds/nlp/autograd/tensor.py +298 -0
  239. package/src/cds/nlp/bpe.py +449 -0
  240. package/src/cds/nlp/data.py +70 -0
  241. package/src/cds/nlp/embed.py +190 -0
  242. package/src/cds/nlp/layers.py +259 -0
  243. package/src/cds/nlp/model.py +456 -0
  244. package/src/cds/nlp/optim.py +163 -0
  245. package/src/cds/nlp/training.py +167 -0
  246. package/src/cds/nlp/viz.py +254 -0
  247. package/src/cds/numerical_integration/__init__.py +31 -0
  248. package/src/cds/numerical_integration/quadrature.py +480 -0
  249. package/src/cds/optimization/__init__.py +26 -0
  250. package/src/cds/optimization/_metaheuristics.py +287 -0
  251. package/src/cds/optimization/constrained.py +212 -0
  252. package/src/cds/optimization/minimize.py +425 -0
  253. package/src/cds/pde/__init__.py +266 -0
  254. package/src/cds/plot/__init__.py +49 -0
  255. package/src/cds/plot/_backend.py +32 -0
  256. package/src/cds/plot/charts.py +462 -0
  257. package/src/cds/probability/__init__.py +65 -0
  258. package/src/cds/probability/_advanced.py +283 -0
  259. package/src/cds/probability/distributions.py +236 -0
  260. package/src/cds/probability/extra_distributions.py +199 -0
  261. package/src/cds/provenance/__init__.py +25 -0
  262. package/src/cds/provenance/manifest.py +355 -0
  263. package/src/cds/py.typed +0 -0
  264. package/src/cds/quantum/__init__.py +51 -0
  265. package/src/cds/quantum/circuit.py +122 -0
  266. package/src/cds/quantum/multi_qubit.py +310 -0
  267. package/src/cds/quantum/simulator.py +53 -0
  268. package/src/cds/scientific/__init__.py +34 -0
  269. package/src/cds/scientific/constants.py +35 -0
  270. package/src/cds/scientific/formulas.py +116 -0
  271. package/src/cds/sensitivity.py +204 -0
  272. package/src/cds/signals/__init__.py +59 -0
  273. package/src/cds/signals/filters.py +449 -0
  274. package/src/cds/signals/processing.py +224 -0
  275. package/src/cds/signals/stft.py +177 -0
  276. package/src/cds/signals/wavelet.py +146 -0
  277. package/src/cds/stats/__init__.py +99 -0
  278. package/src/cds/stats/_distributions.py +102 -0
  279. package/src/cds/stats/bootstrap.py +188 -0
  280. package/src/cds/stats/descriptive.py +172 -0
  281. package/src/cds/stats/hypothesis_tests.py +294 -0
  282. package/src/cds/stats/nonparametric.py +141 -0
  283. package/src/cds/stats/power.py +290 -0
  284. package/src/cds/stats/regression.py +51 -0
  285. package/src/cds/stats/time_series.py +420 -0
  286. package/src/cds/tools/__init__.py +29 -0
  287. package/src/cds/tools/adapters.py +218 -0
  288. package/src/cds/tools/registry.py +181 -0
  289. package/src/cds/uncertainty/__init__.py +17 -0
  290. package/src/cds/uncertainty/propagation.py +233 -0
  291. package/src/cds/units/__init__.py +45 -0
  292. package/src/cds/units/core.py +199 -0
  293. package/src/cds/validation/__init__.py +41 -0
  294. package/src/cds/validation/adequacy.py +157 -0
  295. package/src/cds/validation/checks.py +485 -0
  296. package/src/cds/validation/report.py +50 -0
  297. package/src/cds/wavelets/__init__.py +5 -0
  298. package/src/cds/wavelets/haar.py +219 -0
  299. package/src/cds/workflow/__init__.py +77 -0
  300. package/src/cds/workflow/engine.py +116 -0
  301. package/src/cds/workflow/gates.py +120 -0
  302. package/src/cds/workflow/orchestrator.py +431 -0
  303. package/src/cds/workflow/selection.py +454 -0
  304. package/src/cds/workflow/tooling.py +155 -0
  305. package/src/cds/workflow/types.py +107 -0
  306. package/tests/__init__.py +0 -0
  307. package/tests/conftest.py +109 -0
  308. package/tests/test_advanced_fitting.py +247 -0
  309. package/tests/test_audit_completion_coverage.py +183 -0
  310. package/tests/test_audit_guard_coverage.py +115 -0
  311. package/tests/test_audit_hardening.py +138 -0
  312. package/tests/test_audit_hardening_coverage.py +111 -0
  313. package/tests/test_bayes_v2.py +208 -0
  314. package/tests/test_benchmarks.py +111 -0
  315. package/tests/test_bootstrap.py +135 -0
  316. package/tests/test_cli.py +51 -0
  317. package/tests/test_cli_color.py +114 -0
  318. package/tests/test_cli_extended.py +239 -0
  319. package/tests/test_cli_system_info.py +36 -0
  320. package/tests/test_constrained_opt.py +174 -0
  321. package/tests/test_core.py +273 -0
  322. package/tests/test_data_analysis.py +146 -0
  323. package/tests/test_data_analysis_lazy_bridge.py +68 -0
  324. package/tests/test_data_analysis_pandas_io.py +119 -0
  325. package/tests/test_data_io.py +149 -0
  326. package/tests/test_dataset.py +91 -0
  327. package/tests/test_diffeq.py +186 -0
  328. package/tests/test_diffeq_implicit.py +173 -0
  329. package/tests/test_domain_validation.py +66 -0
  330. package/tests/test_edge_misc_numerical.py +666 -0
  331. package/tests/test_edge_ml_quantum_linalg.py +191 -0
  332. package/tests/test_edge_nlp.py +229 -0
  333. package/tests/test_edge_quantum_evaluator_cli.py +601 -0
  334. package/tests/test_edge_stats_optimization_signals.py +406 -0
  335. package/tests/test_extra_distributions.py +206 -0
  336. package/tests/test_fft2.py +67 -0
  337. package/tests/test_fitting_bootstrap.py +202 -0
  338. package/tests/test_fractals.py +387 -0
  339. package/tests/test_genetics.py +159 -0
  340. package/tests/test_graph.py +380 -0
  341. package/tests/test_hardening_privacy_provenance.py +306 -0
  342. package/tests/test_hypothesis.py +216 -0
  343. package/tests/test_hypothesis_engine.py +59 -0
  344. package/tests/test_hypothesis_mining.py +247 -0
  345. package/tests/test_hypothesis_tests.py +277 -0
  346. package/tests/test_infotheory.py +302 -0
  347. package/tests/test_interpolate.py +189 -0
  348. package/tests/test_knowledge.py +1149 -0
  349. package/tests/test_layering.py +112 -0
  350. package/tests/test_linalg_extended.py +179 -0
  351. package/tests/test_linalg_qr_cholesky.py +68 -0
  352. package/tests/test_markov.py +155 -0
  353. package/tests/test_math_utils.py +157 -0
  354. package/tests/test_ml_boosting.py +148 -0
  355. package/tests/test_ml_clustering.py +92 -0
  356. package/tests/test_ml_ensemble.py +103 -0
  357. package/tests/test_ml_knn.py +95 -0
  358. package/tests/test_ml_linreg.py +70 -0
  359. package/tests/test_ml_logreg.py +84 -0
  360. package/tests/test_ml_metrics.py +125 -0
  361. package/tests/test_ml_model_selection.py +108 -0
  362. package/tests/test_ml_naive_bayes.py +183 -0
  363. package/tests/test_ml_pca.py +98 -0
  364. package/tests/test_ml_preprocessing.py +104 -0
  365. package/tests/test_ml_tree.py +89 -0
  366. package/tests/test_ml_viz.py +58 -0
  367. package/tests/test_ml_voting.py +219 -0
  368. package/tests/test_modeling.py +726 -0
  369. package/tests/test_modeling_fit_validation.py +46 -0
  370. package/tests/test_montecarlo.py +245 -0
  371. package/tests/test_multi_qubit.py +466 -0
  372. package/tests/test_nlp_attention.py +335 -0
  373. package/tests/test_nlp_autograd.py +435 -0
  374. package/tests/test_nlp_bpe.py +463 -0
  375. package/tests/test_nlp_embed.py +240 -0
  376. package/tests/test_nlp_layers.py +276 -0
  377. package/tests/test_nlp_model.py +172 -0
  378. package/tests/test_nlp_training.py +262 -0
  379. package/tests/test_nlp_viz.py +188 -0
  380. package/tests/test_numerical_integration.py +374 -0
  381. package/tests/test_numerical_invariants.py +768 -0
  382. package/tests/test_numerical_oracles.py +241 -0
  383. package/tests/test_optimization.py +139 -0
  384. package/tests/test_optimization_metaheuristics.py +221 -0
  385. package/tests/test_pde.py +294 -0
  386. package/tests/test_plot_charts.py +247 -0
  387. package/tests/test_plot_lazy.py +48 -0
  388. package/tests/test_power.py +226 -0
  389. package/tests/test_probability.py +274 -0
  390. package/tests/test_probability_advanced.py +226 -0
  391. package/tests/test_property_invariants.py +277 -0
  392. package/tests/test_provenance.py +215 -0
  393. package/tests/test_provenance_audit_hardening.py +45 -0
  394. package/tests/test_public_api.py +75 -0
  395. package/tests/test_quantum.py +195 -0
  396. package/tests/test_release_contract.py +105 -0
  397. package/tests/test_retrieval.py +255 -0
  398. package/tests/test_scientific.py +185 -0
  399. package/tests/test_selection_audit_hardening.py +55 -0
  400. package/tests/test_sensitivity.py +59 -0
  401. package/tests/test_sensitivity_global.py +73 -0
  402. package/tests/test_signals.py +146 -0
  403. package/tests/test_signals_filters.py +460 -0
  404. package/tests/test_special_invariants.py +222 -0
  405. package/tests/test_special_numerics.py +44 -0
  406. package/tests/test_statistical_audit.py +75 -0
  407. package/tests/test_stats.py +206 -0
  408. package/tests/test_stats_audit_coverage.py +17 -0
  409. package/tests/test_stats_nonparametric.py +87 -0
  410. package/tests/test_stats_time_series.py +352 -0
  411. package/tests/test_stft.py +208 -0
  412. package/tests/test_streaming_analytics.py +128 -0
  413. package/tests/test_svd.py +170 -0
  414. package/tests/test_symplectic.py +200 -0
  415. package/tests/test_tool_adapters.py +197 -0
  416. package/tests/test_tools_registry.py +132 -0
  417. package/tests/test_uncertainty.py +171 -0
  418. package/tests/test_units.py +139 -0
  419. package/tests/test_validation.py +100 -0
  420. package/tests/test_validation_adequacy.py +129 -0
  421. package/tests/test_validation_advanced.py +110 -0
  422. package/tests/test_wavelet.py +170 -0
  423. package/tests/test_wavelets_v2.py +119 -0
  424. package/tests/test_workflow.py +173 -0
  425. package/tests/test_workflow_gates.py +144 -0
  426. package/tests/test_workflow_orchestrator.py +516 -0
  427. package/tests/test_workflow_orchestrator_blocked_review.py +95 -0
  428. package/tests/test_workflow_selection.py +312 -0
  429. package/tests/test_workflow_selection_coverage.py +114 -0
  430. package/tests/test_workflow_tooling.py +190 -0
@@ -0,0 +1,94 @@
1
+ # Statistics Tutorial
2
+
3
+ `cds.stats` covers descriptive statistics, linear regression, and a set of
4
+ classic hypothesis tests (t-tests, ANOVA, chi-square). Tests return a
5
+ `TestResult` dataclass carrying the test statistic, p-value, and degrees of
6
+ freedom.
7
+
8
+ ## 1. Descriptive statistics
9
+
10
+ ```python
11
+ from cds.stats import mean, median, variance, stdev
12
+
13
+ data = [23.1, 27.5, 19.8, 31.2, 25.6, 28.3, 22.0, 30.1]
14
+ print(f"Mean={mean(data):.2f} Median={median(data):.2f}") # 25.95 26.55
15
+ print(f"Var={variance(data):.2f} StdDev={stdev(data):.2f}") # 16.34 4.04
16
+ ```
17
+
18
+ ## 2. Correlation and linear regression
19
+
20
+ Pearson correlation between two samples, and ordinary least-squares regression.
21
+ The `RegressionResult` exposes `slope`, `intercept`, `r_squared`, and a
22
+ `predict(x)` helper.
23
+
24
+ ```python
25
+ from cds.stats import correlation, linear_regression
26
+
27
+ x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
28
+ y = [2.1, 4.3, 5.8, 8.1, 9.7, 12.2, 13.8, 16.1]
29
+
30
+ print(f"r = {correlation(x, y):.4f}") # r = 0.9991
31
+
32
+ reg = linear_regression(x, y)
33
+ print(f"y = {reg.slope:.2f}x + {reg.intercept:.2f}") # y = 1.98x + 0.10
34
+ print(f"R² = {reg.r_squared:.4f}") # R² = 0.9981
35
+ print(f"predict(10) = {reg.predict(10):.2f}") # 19.90
36
+ ```
37
+
38
+ ## 3. Hypothesis tests
39
+
40
+ All tests return a `TestResult` with `.statistic`, `.p_value`, and `.df`.
41
+
42
+ ### One-sample t-test
43
+
44
+ Is the sample mean different from a hypothesized population mean?
45
+
46
+ ```python
47
+ from cds.stats import one_sample_ttest
48
+
49
+ r = one_sample_ttest([2.1, 2.4, 1.9, 2.2, 2.0, 2.3], popmean=2.0)
50
+ print(f"t={r.statistic:.4f}, p={r.p_value:.4f}, df={r.df}") # t=1.9640, p=0.1067, df=5
51
+ # p > 0.05 → do not reject H0 (mean ≈ 2.0)
52
+ ```
53
+
54
+ ### Two-sample t-test
55
+
56
+ Do two independent samples have equal means?
57
+
58
+ ```python
59
+ from cds.stats import two_sample_ttest
60
+
61
+ r = two_sample_ttest([1.0, 2.0, 3.0, 4.0], [2.0, 3.0, 4.0, 5.0])
62
+ print(f"t={r.statistic:.4f}, p={r.p_value:.4f}") # t=-1.0954, p=0.3153
63
+ ```
64
+
65
+ ### One-way ANOVA
66
+
67
+ Do three or more groups share the same mean? Pass each group as a positional
68
+ argument.
69
+
70
+ ```python
71
+ from cds.stats import one_way_anova
72
+
73
+ r = one_way_anova([1.0, 2.0, 3.0], [2.0, 3.0, 4.0], [3.0, 4.0, 5.0])
74
+ print(f"F={r.statistic:.4f}, p={r.p_value:.4f}") # F=3.0000, p=0.1250
75
+ ```
76
+
77
+ ### Chi-square tests
78
+
79
+ Goodness-of-fit (observed vs expected counts) and independence (a 2-D
80
+ contingency table).
81
+
82
+ ```python
83
+ from cds.stats import chi_square_gof, chi_square_independence
84
+
85
+ r = chi_square_gof([10.0, 20.0, 30.0], [15.0, 20.0, 25.0])
86
+ print(f"chi2={r.statistic:.4f}, p={r.p_value:.4f}") # chi2=2.6667, p=0.2636
87
+
88
+ r = chi_square_independence([[10.0, 20.0], [30.0, 40.0]])
89
+ print(f"chi2={r.statistic:.4f}, p={r.p_value:.4f}") # chi2=0.7937, p=0.3730
90
+ ```
91
+
92
+ ---
93
+
94
+ Run the full demo with `python examples/stats_demo.py`.
@@ -0,0 +1,84 @@
1
+ # Stiff ODE Solvers Tutorial
2
+
3
+ `cds.diffeq._implicit` adds two A-stable implicit methods to the explicit
4
+ solvers: **backward Euler** (θ = 1) and the **trapezoidal / Crank–Nicolson
5
+ method** (θ = ½). Both solve their implicit stage equation with Newton
6
+ iteration, using an analytic Jacobian when you supply one and central
7
+ differences otherwise.
8
+
9
+ ## 1. Why implicit? The stiff decay problem
10
+
11
+ For `dy/dt = -1000·(y − 1)` any explicit method diverges unless
12
+ `dt < 2/1000`. Backward Euler stays stable at the same step:
13
+
14
+ ```python
15
+ from cds.diffeq import backward_euler
16
+
17
+ k = 1000.0
18
+ sol = backward_euler(lambda t, y: -k * (y - 1.0), t0=0.0, y0=0.0, t_end=0.05, dt=0.001)
19
+ print(f"{sol.y[-1]:.6f}") # ≈ 1.000000 — exact is 1 − e⁻⁵⁰ ≈ 1.0
20
+ ```
21
+
22
+ ## 2. Trapezoid (Crank–Nicolson): stable AND second-order
23
+
24
+ Backward Euler buys stability with only first-order accuracy. The trapezoidal
25
+ rule averages the explicit and implicit slopes for O(dt²) error while staying
26
+ A-stable, on smooth problems its error shrinks ~4× when you halve `dt`.
27
+
28
+ ```python
29
+ import math
30
+ from cds.diffeq import backward_euler, trapezoid_method
31
+
32
+ f = lambda t, y: -y
33
+ be = backward_euler(f, 0.0, 1.0, 2.0, dt=0.05).y[-1]
34
+ cn = trapezoid_method(f, 0.0, 1.0, 2.0, dt=0.05).y[-1]
35
+ exact = math.exp(-2.0)
36
+ print(abs(cn - exact) < abs(be - exact)) # True
37
+ ```
38
+
39
+ ## 3. Systems: the harmonic oscillator
40
+
41
+ The `_system` variants take vector states and return `(t_values, y_values)`
42
+ just like :func:`cds.diffeq.solve_system`.
43
+
44
+ ```python
45
+ import math
46
+ from cds.diffeq import trapezoid_method_system
47
+
48
+
49
+ def harmonic(t, y):
50
+ return [y[1], -y[0]] # x'' = -x as a system
51
+
52
+
53
+ ts, ys = trapezoid_method_system(harmonic, 0.0, [1.0, 0.0], t_end=4 * math.pi, dt=0.01)
54
+ amplitude = math.hypot(ys[-1][0], ys[-1][1])
55
+ print(abs(amplitude - 1.0) < 0.01) # True — energy nearly conserved
56
+ ```
57
+
58
+ ## 4. Supplying an analytic Jacobian
59
+
60
+ Newton converges in one step on linear problems either way, but a Jacobian
61
+ removes the finite-difference evaluations:
62
+
63
+ ```python
64
+ from cds.diffeq import backward_euler_system
65
+
66
+ jac = lambda t, y: [[-1000.0]] # df/dy
67
+ ts, ys = backward_euler_system(
68
+ lambda t, y: [-1000.0 * (y[0] - 1.0)],
69
+ t0=0.0,
70
+ y0=[0.0],
71
+ t_end=0.05,
72
+ dt=0.001,
73
+ jac=jac,
74
+ )
75
+ ```
76
+
77
+ ## Notes
78
+
79
+ - Direction follows `sign(t_end - t0)` exactly like the explicit solvers;
80
+ `dt` is always a magnitude.
81
+ - Newton failures raise `ValueError` with a clear message ("singular
82
+ Jacobian" / "did not converge within max_iter") instead of returning
83
+ garbage.
84
+ - Rule of thumb: use RK45 until stiffness hurts, then reach for these.
@@ -0,0 +1,145 @@
1
+ # Time-Series Analysis Tutorial
2
+
3
+ `cds.stats` provides a classical toolkit for ordered, equally-spaced
4
+ observations: autocorrelation, partial autocorrelation, moving-average
5
+ smoothing, differencing, a KPSS-style stationarity test, seasonal
6
+ decomposition, and the Ljung-Box portmanteau test. All routines are pure
7
+ Python with no external dependencies.
8
+
9
+ ```python
10
+ from cds.stats import (
11
+ autocorrelation,
12
+ autocorrelation_function,
13
+ partial_autocorrelation,
14
+ moving_average,
15
+ exponential_smoothing,
16
+ difference,
17
+ kpss_statistic,
18
+ seasonal_decompose,
19
+ ljung_box,
20
+ )
21
+ ```
22
+
23
+ ## 1. Autocorrelation (ACF)
24
+
25
+ The sample autocorrelation at lag `k` measures how correlated a series is
26
+ with a delayed copy of itself. A trending series shows high positive
27
+ autocorrelation; an alternating series shows strong negative autocorrelation.
28
+
29
+ ```python
30
+ # A linear ramp: each point is close to its predecessor -> r_1 near 1.
31
+ trend = [float(i) for i in range(20)]
32
+ print(f"r_1 = {autocorrelation(trend, lag=1):.3f}") # ~0.95
33
+ print(f"r_5 = {autocorrelation(trend, lag=5):.3f}") # still high
34
+
35
+ # Full ACF for lags 0..4 (r_0 is always 1.0).
36
+ acf = autocorrelation_function(trend, max_lag=4)
37
+ print(acf) # [1.0, 0.95, 0.90, 0.85, 0.79]
38
+ ```
39
+
40
+ ## 2. Partial autocorrelation (PACF)
41
+
42
+ The PACF isolates the *direct* correlation at each lag, removing the effect
43
+ of intermediate lags via the Durbin-Levinson recursion. For a pure AR(1)
44
+ process `x_t = 0.8·x_{t-1}`, the PACF spikes at lag 1 then cuts off to ~0,
45
+ the hallmark signature for choosing ARIMA order `p`.
46
+
47
+ ```python
48
+ # Deterministic AR(1) with phi = 0.8.
49
+ ar1 = [1.0]
50
+ for _ in range(200):
51
+ ar1.append(0.8 * ar1[-1])
52
+
53
+ pacf = partial_autocorrelation(ar1, max_lag=4)
54
+ print(f"phi_11 = {pacf[1]:.3f}") # ~0.80
55
+ print(f"phi_22 = {pacf[2]:.3f}") # ~0.00 (cutoff)
56
+ ```
57
+
58
+ ## 3. Smoothing: moving average & exponential smoothing
59
+
60
+ Smoothing reveals the underlying signal in noisy data. The centered moving
61
+ average uses a fixed window; exponential smoothing weights recent
62
+ observations more heavily via `alpha ∈ (0, 1]`.
63
+
64
+ ```python
65
+ noisy = [10.0, 0.0, 10.0, 0.0, 10.0, 0.0, 10.0, 0.0]
66
+
67
+ ma = moving_average(noisy, window=2) # centered SMA
68
+ ses = exponential_smoothing(noisy, alpha=0.3) # weight recent points
69
+ print(f"SMA variance = {sum((x - 5) ** 2 for x in ma) / len(ma):.2f}")
70
+ print(f"SES variance = {sum((x - 5) ** 2 for x in ses) / len(ses):.2f}")
71
+ ```
72
+
73
+ ## 4. Differencing
74
+
75
+ Differencing removes trend and seasonality, the standard Box-Jenkins
76
+ preprocessing step before fitting ARIMA models. `order=k` applies the
77
+ difference repeatedly.
78
+
79
+ ```python
80
+ ramp = [1.0, 3.0, 5.0, 7.0, 9.0] # y = 2t + 1
81
+ print(difference(ramp, lag=1, order=1)) # [2.0, 2.0, 2.0, 2.0] (constant)
82
+
83
+ quad = [float(i * i) for i in range(6)] # 0,1,4,9,16,25
84
+ print(difference(quad, lag=1, order=2)) # [2.0, 2.0, 2.0, 2.0] (2nd diff constant)
85
+
86
+ seasonal = [1.0, 2.0, 3.0, 1.0, 2.0, 3.0] # period 3
87
+ print(difference(seasonal, lag=3, order=1)) # [0.0, 0.0, 0.0]
88
+ ```
89
+
90
+ ## 5. Stationarity test (KPSS-style)
91
+
92
+ The KPSS statistic tests the **null of stationarity** (the opposite of the
93
+ ADF test). A small statistic means the series looks stationary; a large one
94
+ suggests a unit root. `kpss_statistic` returns a heuristic decision and an
95
+ approximate p-value, for formal inference consult the published asymptotic
96
+ critical values.
97
+
98
+ ```python
99
+ # Oscillating around a mean -> stationary.
100
+ stationary = [0.1, -0.2, 0.15, -0.1, 0.2, -0.15] * 4
101
+ res = kpss_statistic(stationary)
102
+ print(f"eta = {res.statistic:.4f}, stationary = {res.is_stationary}") # True
103
+
104
+ # A random walk (cumulative sum) -> non-stationary.
105
+ rw = [0.0]
106
+ for _ in range(200):
107
+ rw.append(rw[-1] + (1.0 if _ % 2 else -1.0) + 0.3)
108
+ res2 = kpss_statistic(rw)
109
+ print(f"eta = {res2.statistic:.4f}") # large
110
+ ```
111
+
112
+ ## 6. Seasonal decomposition
113
+
114
+ Classical additive decomposition splits a series into **trend + seasonal +
115
+ residual**. Pass the seasonal `period` (e.g. 12 for monthly data with annual
116
+ cycle). The seasonal component is normalized to sum to zero over one period.
117
+
118
+ ```python
119
+ base = [10.0, 20.0, 30.0, 40.0] # one seasonal period
120
+ data = base * 5 # 5 full periods
121
+ trend, seasonal, residual = seasonal_decompose(data, period=4)
122
+
123
+ print(f"seasonal sums to ~0: {sum(seasonal[:4]):.2f}") # 0.00
124
+ print(f"max |residual| = {max(abs(r) for r in residual):.2f}")
125
+ ```
126
+
127
+ ## 7. Ljung-Box test for autocorrelation
128
+
129
+ The Ljung-Box Q statistic tests whether *any* of the first `lags`
130
+ autocorrelations differ from zero. A low p-value rejects independence,
131
+ useful for checking whether ARIMA residuals are white noise.
132
+
133
+ ```python
134
+ # A clean trend has strong autocorrelation.
135
+ strong = [float(i) for i in range(100)]
136
+ lb = ljung_box(strong, lags=10)
137
+ print(f"Q = {lb.statistic:.2f}, p = {lb.p_value:.4f}")
138
+ print(f"autocorrelated? {lb.has_autocorrelation}") # True
139
+ ```
140
+
141
+ ---
142
+
143
+ These tools compose naturally: smooth a noisy signal, difference away a
144
+ trend, test the result for stationarity, then decompose any remaining
145
+ seasonality, all from `cds.stats`, no NumPy required.
@@ -0,0 +1,40 @@
1
+ """Core data-models demo — Domain, Hypothesis, HypothesisStatus."""
2
+
3
+ # Import directly from the defining module (not the cds.core re-export) to
4
+ # give static analyzers the clearest possible view of these types.
5
+ from cds.core.models import Domain, Hypothesis, HypothesisStatus
6
+
7
+
8
+ def main() -> None:
9
+ print("=== Domains ===")
10
+ # __members__.values() is the Enum API's explicit member-collection view
11
+ # (a Mapping's ValuesView). Functionally identical to iterating the
12
+ # EnumType itself (same 6 members, same order), but the return type is an
13
+ # unambiguously iterable mapping view — CodeQL's non-iterable-in-for-loop
14
+ # query can resolve it where the EnumType iterator could not.
15
+ for d in Domain.__members__.values():
16
+ print(f" {d.name} = {d.value}")
17
+
18
+ print("\n=== Constructing a Hypothesis ===")
19
+ h = Hypothesis(
20
+ id="H-001",
21
+ domain=Domain.COSMOLOGY,
22
+ research_question="Why is the Hubble expansion accelerating?",
23
+ statement="A cosmological constant (Λ) drives late-time acceleration.",
24
+ status=HypothesisStatus.TESTABLE,
25
+ confidence=0.62,
26
+ rationale="Type Ia supernova data favours accelerated expansion.",
27
+ assumptions=["GR holds on cosmological scales", "Λ > 0"],
28
+ predictions=["(m-M) vs z curve bends downward vs matter-only"],
29
+ tags=["dark-energy", "lambda"],
30
+ )
31
+ print(repr(h))
32
+ print("\n--- Markdown render ---")
33
+ print(h.to_markdown())
34
+
35
+ print("\n--- JSON serialisation ---")
36
+ print(h.model_dump_json(indent=2)[:200] + " ...")
37
+
38
+
39
+ if __name__ == "__main__":
40
+ main()
@@ -0,0 +1,60 @@
1
+ """Data analysis demo — loading, transforming, and plotting tabular data."""
2
+
3
+ import os
4
+ import tempfile
5
+
6
+ from cds.data_analysis import (
7
+ DataSet,
8
+ load_csv,
9
+ moving_average,
10
+ normalize,
11
+ plot_bar,
12
+ plot_line,
13
+ z_score,
14
+ )
15
+ from cds.data_analysis.dataset import Scalar
16
+
17
+
18
+ def main() -> None:
19
+ # Build a tiny CSV in a temp file so the demo needs no fixtures.
20
+ csv_text = "day,temperature,sales\n1,18.0,100\n2,19.5,110\n3,22.0,140\n4,21.5,135\n5,23.0,160\n"
21
+ path = os.path.join(tempfile.gettempdir(), "_cds_demo.csv")
22
+ with open(path, "w", encoding="utf-8") as f:
23
+ f.write(csv_text)
24
+
25
+ print("=== Loading CSV ===")
26
+ table = load_csv(path)
27
+ print(f"headers: {table.headers}")
28
+ print(f"rows: {len(table.rows)}")
29
+
30
+ # Extract numeric columns (DataTable stores everything as strings).
31
+ temps = [float(row[1]) for row in table.rows]
32
+ sales = [float(row[2]) for row in table.rows]
33
+
34
+ print("\n=== Normalisation ===")
35
+ norm = normalize(temps)
36
+ z = z_score(temps)
37
+ print(f"normalized temps: {[round(v, 3) for v in norm]}")
38
+ print(f"z-score temps : {[round(v, 3) for v in z]}")
39
+
40
+ print("\n=== Smoothing ===")
41
+ ma = moving_average(sales, window=2)
42
+ print(f"2-day moving avg of sales: {[round(v, 3) for v in ma]}")
43
+
44
+ print("\n=== ASCII Visualisation ===")
45
+ plot_line(temps, title="temperature")
46
+ plot_bar({"Mon": 100.0, "Tue": 110.0, "Wed": 140.0, "Thu": 135.0, "Fri": 160.0})
47
+
48
+ print("\n=== DataSet helper ===")
49
+ # DataSet expects a list of row-dicts; annotate so mypy widens the
50
+ # value type to Scalar (int | float | str | bool | None) instead of
51
+ # narrowing it to float, which would clash with the invariant list.
52
+ data: list[dict[str, Scalar]] = [{"day": i, "temp": float(t)} for i, t in enumerate(temps)]
53
+ ds = DataSet(data=data)
54
+ print(f"columns: {ds.columns}")
55
+ print(f"shape: {ds.shape}")
56
+ print(ds.head(3))
57
+
58
+
59
+ if __name__ == "__main__":
60
+ main()
@@ -0,0 +1,34 @@
1
+ """Ordinary differential equation solver demo."""
2
+
3
+ from cds.diffeq import euler_method, midpoint_method, rk4, rk45, solve_system
4
+
5
+
6
+ def main() -> None:
7
+ # dy/dt = -y -> exact solution y(t) = e^-t, so y(1) = e^-1 ≈ 0.3679
8
+ f = lambda t, y: -y # noqa: E731
9
+ t0, y0, t_end = 0.0, 1.0, 1.0
10
+
11
+ print("=== Solving dy/dt = -y, y(0)=1, evaluate at t=1 (exact = e^-1 ≈ 0.3679) ===")
12
+ sol_euler = euler_method(f, t0=t0, y0=y0, t_end=t_end, dt=0.01)
13
+ sol_mid = midpoint_method(f, t0=t0, y0=y0, t_end=t_end, dt=0.01)
14
+ sol_rk4 = rk4(f, t0=t0, y0=y0, t_end=t_end, dt=0.1)
15
+ sol_rk45 = rk45(f, t0=t0, y0=y0, t_end=t_end, rtol=1e-6)
16
+ print(f"Euler (dt=0.01): {sol_euler.y[-1]:.6f}")
17
+ print(f"Midpoint(dt=0.01): {sol_mid.y[-1]:.6f}")
18
+ print(f"RK4 (dt=0.1) : {sol_rk4.y[-1]:.6f}")
19
+ print(f"RK45 adaptive : {sol_rk45.y[-1]:.6f}")
20
+
21
+ print("\n=== System: predator-prey (Lotka-Volterra) ===")
22
+ alpha, beta, gamma, delta = 1.1, 0.4, 0.4, 0.1
23
+
24
+ def lotka(t: float, state: list[float]) -> list[float]:
25
+ x, y = state
26
+ return [alpha * x - beta * x * y, delta * x * y - gamma * y]
27
+
28
+ ts, ys = solve_system(lotka, t0=0.0, y0=[10.0, 5.0], t_end=15.0, dt=0.05)
29
+ print(f"Final prey/predator state: {ys[-1]}")
30
+ print(f"Trajectory length: {len(ts)} points")
31
+
32
+
33
+ if __name__ == "__main__":
34
+ main()
@@ -0,0 +1,57 @@
1
+ """Discovery pipeline demo — mine correlation hypotheses, then evaluate one statistically."""
2
+
3
+ import random
4
+
5
+ from cds.hypothesis import EvaluationData, HypothesisEvaluator, mine_correlations
6
+
7
+
8
+ def main() -> None:
9
+ # --- Synthetic dataset: one strong relationship plus pure-noise columns ---
10
+ rng = random.Random(42)
11
+ n_rows = 120
12
+ dose = [rng.uniform(0.0, 10.0) for _ in range(n_rows)]
13
+ response = [2.0 * d + rng.gauss(0.0, 1.5) for d in dose]
14
+ data: dict[str, list[float]] = {
15
+ "dose": dose,
16
+ "response": response,
17
+ "lab_temperature": [rng.gauss(21.0, 1.0) for _ in range(n_rows)],
18
+ "instrument_drift": [rng.gauss(0.0, 2.0) for _ in range(n_rows)],
19
+ }
20
+
21
+ print("=== Mining correlation hypotheses ===")
22
+ mined = mine_correlations(data)
23
+ print(f"{len(mined)} hypothesis(ies) survived the |r| >= 0.3 and p < 0.05 filters:\n")
24
+ for hit in mined:
25
+ print(
26
+ f"[{hit.strength}] {hit.feature_a} ~ {hit.feature_b}: "
27
+ f"r={hit.correlation:+.4f}, p={hit.p_value:.3e}"
28
+ )
29
+ print(f" {hit.hypothesis.statement}")
30
+ print(f" confidence: {hit.hypothesis.confidence:.2f}\n")
31
+
32
+ # --- Evaluate the strongest mined hypothesis ---
33
+ print("=== Evaluating the strongest mined hypothesis ===")
34
+ print("The evaluator runs classical tests (t-test/ANOVA/chi-square), so the")
35
+ print("association is translated into a group comparison: mean response below")
36
+ print("vs above the median dose.")
37
+ top = mined[0]
38
+ doses = data[top.feature_a]
39
+ responses = data[top.feature_b]
40
+ median_dose = sorted(doses)[len(doses) // 2]
41
+ low_group = [r for d, r in zip(doses, responses) if d <= median_dose]
42
+ high_group = [r for d, r in zip(doses, responses) if d > median_dose]
43
+
44
+ evaluator = HypothesisEvaluator(alpha=0.05)
45
+ payload: EvaluationData = {"groups": [low_group, high_group]}
46
+ result = evaluator.evaluate(top.hypothesis, payload)
47
+ print(f"Test : {result.test_name}")
48
+ print(f"Statistic : {result.statistic:.4f}")
49
+ print(f"p-value : {result.p_value:.3e}")
50
+ print(f"Effect size : {result.effect_size_label} = {result.effect_size:.3f}")
51
+ print(f"Significant : {result.is_significant}")
52
+ print(f"Conclusion : {result.conclusion}")
53
+ print(f"Hypothesis status after evaluation: {top.hypothesis.status.value}")
54
+
55
+
56
+ if __name__ == "__main__":
57
+ main()
@@ -0,0 +1,81 @@
1
+ """Ensemble showcase — forest, boosting, naive Bayes and voting on seeded blobs."""
2
+
3
+ import random
4
+
5
+ from cds.ml import (
6
+ GaussianNaiveBayes,
7
+ GradientBoostingClassifier,
8
+ RandomForestClassifier,
9
+ accuracy,
10
+ )
11
+ from cds.ml.model_selection import SupervisedModel
12
+ from cds.ml.voting import VotingClassifier
13
+
14
+
15
+ def make_dataset(n_per_class: int, seed: int) -> tuple[list[list[float]], list[str]]:
16
+ """Two Gaussian blobs in 2-D: class A around (-1, -1), class B around (1, 1)."""
17
+ rng = random.Random(seed)
18
+ X: list[list[float]] = []
19
+ y: list[str] = []
20
+ for _ in range(n_per_class):
21
+ X.append([rng.gauss(-1.0, 0.9), rng.gauss(-1.0, 0.9)])
22
+ y.append("A")
23
+ X.append([rng.gauss(1.0, 0.9), rng.gauss(1.0, 0.9)])
24
+ y.append("B")
25
+ return X, y
26
+
27
+
28
+ def report(name: str, model: SupervisedModel, X_test: list[list[float]], y_test: list[str]) -> None:
29
+ y_pred = [model.predict(row) for row in X_test]
30
+ acc = accuracy(y_test, y_pred)
31
+ print(f" {name:<28} accuracy = {acc:.3f}")
32
+
33
+
34
+ def main() -> None:
35
+ X, y = make_dataset(n_per_class=60, seed=42)
36
+
37
+ indices = list(range(len(X)))
38
+ random.Random(7).shuffle(indices)
39
+ split = 80
40
+ train_idx = indices[:split]
41
+ test_idx = indices[split:]
42
+ X_train = [X[i] for i in train_idx]
43
+ y_train = [y[i] for i in train_idx]
44
+ X_test = [X[i] for i in test_idx]
45
+ y_test = [y[i] for i in test_idx]
46
+
47
+ print(f"=== Ensemble showcase on {len(X_train)} train / {len(X_test)} test samples ===\n")
48
+ print("Individual models:")
49
+
50
+ forest = RandomForestClassifier(n_trees=30, max_depth=4, seed=42)
51
+ boost = GradientBoostingClassifier(n_estimators=40, learning_rate=0.3, max_depth=2)
52
+ bayes = GaussianNaiveBayes()
53
+ individuals: list[tuple[str, SupervisedModel]] = [
54
+ ("RandomForest", forest),
55
+ ("GradientBoosting", boost),
56
+ ("GaussianNaiveBayes", bayes),
57
+ ]
58
+ for name, model in individuals:
59
+ model.fit(X_train, y_train)
60
+ report(name, model, X_test, y_test)
61
+
62
+ # --- Voting ensembles over fresh members with the same hyperparameters ---
63
+ print("\nVoting ensembles:")
64
+ hard_members: list[tuple[str, SupervisedModel]] = [
65
+ ("forest", RandomForestClassifier(n_trees=30, max_depth=4, seed=42)),
66
+ ("boost", GradientBoostingClassifier(n_estimators=40, learning_rate=0.3, max_depth=2)),
67
+ ("bayes", GaussianNaiveBayes()),
68
+ ]
69
+ soft_members: list[tuple[str, SupervisedModel]] = [
70
+ ("forest", RandomForestClassifier(n_trees=30, max_depth=4, seed=42)),
71
+ ("boost", GradientBoostingClassifier(n_estimators=40, learning_rate=0.3, max_depth=2)),
72
+ ("bayes", GaussianNaiveBayes()),
73
+ ]
74
+ hard_vote = VotingClassifier(hard_members, voting="hard").fit(X_train, y_train)
75
+ soft_vote = VotingClassifier(soft_members, voting="soft").fit(X_train, y_train)
76
+ report("VotingClassifier (hard)", hard_vote, X_test, y_test)
77
+ report("VotingClassifier (soft)", soft_vote, X_test, y_test)
78
+
79
+
80
+ if __name__ == "__main__":
81
+ main()
@@ -0,0 +1,32 @@
1
+ """2-D FFT demo (row-column Cooley-Tukey)."""
2
+
3
+ from cds.signals import fft2, ifft2
4
+
5
+ # A small 4x4 "image"
6
+
7
+
8
+ def main() -> None:
9
+ image: list[list[float | complex]] = [
10
+ [1.0, 2.0, 3.0, 4.0],
11
+ [2.0, 3.0, 4.0, 5.0],
12
+ [3.0, 4.0, 5.0, 6.0],
13
+ [4.0, 5.0, 6.0, 7.0],
14
+ ]
15
+
16
+ print("=== 2-D FFT ===")
17
+ spectrum = fft2(image)
18
+ print("DC component (sum of all pixels):")
19
+ print(f" F[0][0] = {spectrum[0][0].real:.1f} (expected {sum(sum(r) for r in image):.1f})")
20
+
21
+ print("\nMagnitude spectrum |F[u][v]|:")
22
+ for row in spectrum:
23
+ print(" " + " ".join(f"{abs(x):6.2f}" for x in row))
24
+
25
+ print("\n=== Inverse 2-D FFT (round-trip) ===")
26
+ recovered = ifft2(spectrum)
27
+ max_err = max(abs(recovered[i][j].real - image[i][j]) for i in range(4) for j in range(4))
28
+ print(f"Max reconstruction error: {max_err:.2e}")
29
+
30
+
31
+ if __name__ == "__main__":
32
+ main()
@@ -0,0 +1,49 @@
1
+ """Graph algorithms demo — BFS/DFS, Dijkstra, Kruskal MST, topo sort, cycle detection."""
2
+
3
+ from cds.graph import (
4
+ Graph,
5
+ bfs,
6
+ dfs,
7
+ dijkstra,
8
+ has_cycle,
9
+ kruskal_mst,
10
+ topological_sort,
11
+ )
12
+
13
+
14
+ def main() -> None:
15
+ # Undirected weighted graph (integer nodes).
16
+ g = Graph(n_vertices=6, directed=False)
17
+ edges = [(0, 1, 4), (0, 2, 2), (1, 2, 1), (1, 3, 5), (2, 3, 8), (2, 4, 10), (3, 4, 2)]
18
+ for u, v, w in edges:
19
+ g.add_edge(u, v, weight=w)
20
+
21
+ print("=== Traversal ===")
22
+ print(f"BFS from 0: {bfs(g, 0)}")
23
+ print(f"DFS from 0: {dfs(g, 0)}")
24
+
25
+ print("\n=== Shortest Paths (Dijkstra) ===")
26
+ dists, prev = dijkstra(g, 0)
27
+ for node in sorted(dists):
28
+ print(f" dist(0 -> {node}) = {dists[node]:.1f}")
29
+
30
+ print("\n=== Minimum Spanning Tree (Kruskal) ===")
31
+ mst_edges, total = kruskal_mst(g)
32
+ for e in mst_edges:
33
+ print(f" {e.src} -- {e.dst} (w={e.weight})")
34
+ print(f" MST total weight = {total}")
35
+
36
+ print("\n=== Cycle Detection (undirected) ===")
37
+ print(f"has_cycle: {has_cycle(g)}")
38
+
39
+ print("\n=== Topological Sort (DAG) ===")
40
+ dag = Graph(n_vertices=3, directed=True)
41
+ dag.add_edge(0, 1, weight=1)
42
+ dag.add_edge(1, 2, weight=1)
43
+ dag.add_edge(0, 2, weight=1)
44
+ order = topological_sort(dag)
45
+ print(f"order: {order}")
46
+
47
+
48
+ if __name__ == "__main__":
49
+ main()