dfc-kit 1.0.0__tar.gz

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 (167) hide show
  1. dfc_kit-1.0.0/CHANGELOG.md +22 -0
  2. dfc_kit-1.0.0/CITATION.cff +9 -0
  3. dfc_kit-1.0.0/CONTRIBUTING.md +31 -0
  4. dfc_kit-1.0.0/ENGINEERING_PLAN.md +42 -0
  5. dfc_kit-1.0.0/LICENSE +29 -0
  6. dfc_kit-1.0.0/MANIFEST.in +12 -0
  7. dfc_kit-1.0.0/PKG-INFO +184 -0
  8. dfc_kit-1.0.0/README.md +139 -0
  9. dfc_kit-1.0.0/ROADMAP.md +26 -0
  10. dfc_kit-1.0.0/SECURITY.md +12 -0
  11. dfc_kit-1.0.0/benchmarks/README.md +69 -0
  12. dfc_kit-1.0.0/benchmarks/profile_core.py +248 -0
  13. dfc_kit-1.0.0/docs/api.md +124 -0
  14. dfc_kit-1.0.0/docs/architecture.md +89 -0
  15. dfc_kit-1.0.0/docs/cli.md +115 -0
  16. dfc_kit-1.0.0/docs/correlation.md +29 -0
  17. dfc_kit-1.0.0/docs/datasets.md +68 -0
  18. dfc_kit-1.0.0/docs/getting_started.md +80 -0
  19. dfc_kit-1.0.0/docs/hmm.md +143 -0
  20. dfc_kit-1.0.0/docs/index.md +42 -0
  21. dfc_kit-1.0.0/docs/inference.md +74 -0
  22. dfc_kit-1.0.0/docs/inference_matching.md +81 -0
  23. dfc_kit-1.0.0/docs/information.md +134 -0
  24. dfc_kit-1.0.0/docs/instantaneous_edges.md +77 -0
  25. dfc_kit-1.0.0/docs/leida.md +76 -0
  26. dfc_kit-1.0.0/docs/lowrank.md +103 -0
  27. dfc_kit-1.0.0/docs/method_inventory.md +26 -0
  28. dfc_kit-1.0.0/docs/model_artifacts.md +16 -0
  29. dfc_kit-1.0.0/docs/nbs.md +123 -0
  30. dfc_kit-1.0.0/docs/partition_graphs.md +81 -0
  31. dfc_kit-1.0.0/docs/reference.md +95 -0
  32. dfc_kit-1.0.0/docs/release.md +33 -0
  33. dfc_kit-1.0.0/docs/state_alignment.md +129 -0
  34. dfc_kit-1.0.0/docs/state_scoring.md +21 -0
  35. dfc_kit-1.0.0/docs/state_selection.md +29 -0
  36. dfc_kit-1.0.0/docs/state_stability.md +39 -0
  37. dfc_kit-1.0.0/docs/states.md +256 -0
  38. dfc_kit-1.0.0/docs/storage.md +285 -0
  39. dfc_kit-1.0.0/docs/tutorial_xcpd_to_states.md +346 -0
  40. dfc_kit-1.0.0/docs/xcpd_input.md +92 -0
  41. dfc_kit-1.0.0/mkdocs.yml +46 -0
  42. dfc_kit-1.0.0/pyproject.toml +83 -0
  43. dfc_kit-1.0.0/setup.cfg +4 -0
  44. dfc_kit-1.0.0/src/dfc_kit.egg-info/PKG-INFO +184 -0
  45. dfc_kit-1.0.0/src/dfc_kit.egg-info/SOURCES.txt +165 -0
  46. dfc_kit-1.0.0/src/dfc_kit.egg-info/dependency_links.txt +1 -0
  47. dfc_kit-1.0.0/src/dfc_kit.egg-info/entry_points.txt +2 -0
  48. dfc_kit-1.0.0/src/dfc_kit.egg-info/requires.txt +31 -0
  49. dfc_kit-1.0.0/src/dfc_kit.egg-info/top_level.txt +1 -0
  50. dfc_kit-1.0.0/src/dfckit/__init__.py +11 -0
  51. dfc_kit-1.0.0/src/dfckit/_arrays.py +13 -0
  52. dfc_kit-1.0.0/src/dfckit/_preprocessing.py +46 -0
  53. dfc_kit-1.0.0/src/dfckit/_validation.py +87 -0
  54. dfc_kit-1.0.0/src/dfckit/artifacts/__init__.py +36 -0
  55. dfc_kit-1.0.0/src/dfckit/artifacts/_fields.py +67 -0
  56. dfc_kit-1.0.0/src/dfckit/artifacts/_json.py +92 -0
  57. dfc_kit-1.0.0/src/dfckit/artifacts/_numpy.py +55 -0
  58. dfc_kit-1.0.0/src/dfckit/artifacts/models.py +624 -0
  59. dfc_kit-1.0.0/src/dfckit/artifacts/state_alignment.py +106 -0
  60. dfc_kit-1.0.0/src/dfckit/artifacts/state_results.py +353 -0
  61. dfc_kit-1.0.0/src/dfckit/artifacts/state_scoring.py +509 -0
  62. dfc_kit-1.0.0/src/dfckit/artifacts/state_stability.py +207 -0
  63. dfc_kit-1.0.0/src/dfckit/cli.py +105 -0
  64. dfc_kit-1.0.0/src/dfckit/commands/__init__.py +1 -0
  65. dfc_kit-1.0.0/src/dfckit/commands/parser.py +354 -0
  66. dfc_kit-1.0.0/src/dfckit/commands/reporting.py +146 -0
  67. dfc_kit-1.0.0/src/dfckit/commands/source.py +245 -0
  68. dfc_kit-1.0.0/src/dfckit/commands/stability.py +288 -0
  69. dfc_kit-1.0.0/src/dfckit/commands/states.py +266 -0
  70. dfc_kit-1.0.0/src/dfckit/connectivity/__init__.py +68 -0
  71. dfc_kit-1.0.0/src/dfckit/connectivity/_edge_products.py +130 -0
  72. dfc_kit-1.0.0/src/dfckit/connectivity/correlation.py +61 -0
  73. dfc_kit-1.0.0/src/dfckit/connectivity/instantaneous.py +253 -0
  74. dfc_kit-1.0.0/src/dfckit/connectivity/leida.py +204 -0
  75. dfc_kit-1.0.0/src/dfckit/connectivity/lowrank.py +384 -0
  76. dfc_kit-1.0.0/src/dfckit/connectivity/partition.py +291 -0
  77. dfc_kit-1.0.0/src/dfckit/connectivity/windows.py +83 -0
  78. dfc_kit-1.0.0/src/dfckit/data.py +229 -0
  79. dfc_kit-1.0.0/src/dfckit/inference/__init__.py +55 -0
  80. dfc_kit-1.0.0/src/dfckit/inference/endpoints.py +194 -0
  81. dfc_kit-1.0.0/src/dfckit/inference/hc3.py +207 -0
  82. dfc_kit-1.0.0/src/dfckit/inference/matching.py +300 -0
  83. dfc_kit-1.0.0/src/dfckit/inference/multiple_testing.py +52 -0
  84. dfc_kit-1.0.0/src/dfckit/inference/nbs.py +586 -0
  85. dfc_kit-1.0.0/src/dfckit/inference/paired.py +157 -0
  86. dfc_kit-1.0.0/src/dfckit/inference/state_metrics.py +277 -0
  87. dfc_kit-1.0.0/src/dfckit/information/__init__.py +45 -0
  88. dfc_kit-1.0.0/src/dfckit/information/_artifact.py +440 -0
  89. dfc_kit-1.0.0/src/dfckit/information/estimators.py +536 -0
  90. dfc_kit-1.0.0/src/dfckit/information/fixed.py +660 -0
  91. dfc_kit-1.0.0/src/dfckit/information/summary.py +89 -0
  92. dfc_kit-1.0.0/src/dfckit/io/__init__.py +23 -0
  93. dfc_kit-1.0.0/src/dfckit/io/xcpd.py +470 -0
  94. dfc_kit-1.0.0/src/dfckit/reference.py +350 -0
  95. dfc_kit-1.0.0/src/dfckit/segments.py +44 -0
  96. dfc_kit-1.0.0/src/dfckit/states/__init__.py +97 -0
  97. dfc_kit-1.0.0/src/dfckit/states/alignment.py +364 -0
  98. dfc_kit-1.0.0/src/dfckit/states/cap.py +62 -0
  99. dfc_kit-1.0.0/src/dfckit/states/cross_validation.py +114 -0
  100. dfc_kit-1.0.0/src/dfckit/states/data.py +387 -0
  101. dfc_kit-1.0.0/src/dfckit/states/hmm.py +387 -0
  102. dfc_kit-1.0.0/src/dfckit/states/interpretation.py +273 -0
  103. dfc_kit-1.0.0/src/dfckit/states/kmeans.py +340 -0
  104. dfc_kit-1.0.0/src/dfckit/states/metrics.py +94 -0
  105. dfc_kit-1.0.0/src/dfckit/states/scoring.py +114 -0
  106. dfc_kit-1.0.0/src/dfckit/states/selection.py +516 -0
  107. dfc_kit-1.0.0/src/dfckit/states/stability.py +183 -0
  108. dfc_kit-1.0.0/src/dfckit/states/streaming.py +859 -0
  109. dfc_kit-1.0.0/src/dfckit/states/streaming_hmm.py +436 -0
  110. dfc_kit-1.0.0/src/dfckit/storage/__init__.py +29 -0
  111. dfc_kit-1.0.0/src/dfckit/storage/_statistics.py +80 -0
  112. dfc_kit-1.0.0/src/dfckit/storage/builders.py +330 -0
  113. dfc_kit-1.0.0/src/dfckit/storage/store.py +672 -0
  114. dfc_kit-1.0.0/src/dfckit/storage/summary.py +140 -0
  115. dfc_kit-1.0.0/tests/__init__.py +1 -0
  116. dfc_kit-1.0.0/tests/fixtures/audited_kernels.json +46 -0
  117. dfc_kit-1.0.0/tests/integration/__init__.py +1 -0
  118. dfc_kit-1.0.0/tests/integration/test_leida_state_pipeline.py +57 -0
  119. dfc_kit-1.0.0/tests/integration/test_model_artifact_pipeline.py +132 -0
  120. dfc_kit-1.0.0/tests/integration/test_xcpd_information.py +162 -0
  121. dfc_kit-1.0.0/tests/integration/test_xcpd_sliding_window.py +60 -0
  122. dfc_kit-1.0.0/tests/integration/test_xcpd_state_pipeline.py +92 -0
  123. dfc_kit-1.0.0/tests/regression/__init__.py +1 -0
  124. dfc_kit-1.0.0/tests/regression/test_audited_kernels.py +53 -0
  125. dfc_kit-1.0.0/tests/regression/test_information_reference.py +66 -0
  126. dfc_kit-1.0.0/tests/regression/test_nbs_independent_reference.py +262 -0
  127. dfc_kit-1.0.0/tests/regression/test_nbs_reference.py +155 -0
  128. dfc_kit-1.0.0/tests/unit/__init__.py +1 -0
  129. dfc_kit-1.0.0/tests/unit/test_artifact_helpers.py +55 -0
  130. dfc_kit-1.0.0/tests/unit/test_cli.py +172 -0
  131. dfc_kit-1.0.0/tests/unit/test_correlation.py +33 -0
  132. dfc_kit-1.0.0/tests/unit/test_cross_validation.py +58 -0
  133. dfc_kit-1.0.0/tests/unit/test_data.py +136 -0
  134. dfc_kit-1.0.0/tests/unit/test_endpoint_inference.py +89 -0
  135. dfc_kit-1.0.0/tests/unit/test_ets.py +106 -0
  136. dfc_kit-1.0.0/tests/unit/test_hmm.py +200 -0
  137. dfc_kit-1.0.0/tests/unit/test_inference.py +143 -0
  138. dfc_kit-1.0.0/tests/unit/test_inference_matching.py +146 -0
  139. dfc_kit-1.0.0/tests/unit/test_information.py +179 -0
  140. dfc_kit-1.0.0/tests/unit/test_information_io.py +396 -0
  141. dfc_kit-1.0.0/tests/unit/test_information_summary.py +76 -0
  142. dfc_kit-1.0.0/tests/unit/test_internal_helpers.py +76 -0
  143. dfc_kit-1.0.0/tests/unit/test_leida.py +136 -0
  144. dfc_kit-1.0.0/tests/unit/test_lowrank.py +161 -0
  145. dfc_kit-1.0.0/tests/unit/test_model_io.py +302 -0
  146. dfc_kit-1.0.0/tests/unit/test_mtd.py +127 -0
  147. dfc_kit-1.0.0/tests/unit/test_nbs.py +245 -0
  148. dfc_kit-1.0.0/tests/unit/test_outofcore.py +391 -0
  149. dfc_kit-1.0.0/tests/unit/test_outofcore_hmm.py +237 -0
  150. dfc_kit-1.0.0/tests/unit/test_partition_graph.py +144 -0
  151. dfc_kit-1.0.0/tests/unit/test_preprocessing.py +33 -0
  152. dfc_kit-1.0.0/tests/unit/test_public_api.py +56 -0
  153. dfc_kit-1.0.0/tests/unit/test_reference.py +179 -0
  154. dfc_kit-1.0.0/tests/unit/test_sliding_window.py +36 -0
  155. dfc_kit-1.0.0/tests/unit/test_stability.py +103 -0
  156. dfc_kit-1.0.0/tests/unit/test_state_alignment_io.py +56 -0
  157. dfc_kit-1.0.0/tests/unit/test_state_interpretation.py +206 -0
  158. dfc_kit-1.0.0/tests/unit/test_state_metric_inference.py +73 -0
  159. dfc_kit-1.0.0/tests/unit/test_state_results.py +151 -0
  160. dfc_kit-1.0.0/tests/unit/test_state_scoring_io.py +86 -0
  161. dfc_kit-1.0.0/tests/unit/test_state_selection.py +84 -0
  162. dfc_kit-1.0.0/tests/unit/test_state_selection_io.py +98 -0
  163. dfc_kit-1.0.0/tests/unit/test_state_stability_io.py +79 -0
  164. dfc_kit-1.0.0/tests/unit/test_states.py +592 -0
  165. dfc_kit-1.0.0/tests/unit/test_storage.py +369 -0
  166. dfc_kit-1.0.0/tests/unit/test_store_summary.py +105 -0
  167. dfc_kit-1.0.0/tests/unit/test_xcpd.py +182 -0
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 - 2026-08-24
4
+
5
+ - Moved MI/CMI estimators and fixed-window orchestration into
6
+ `dfckit.information`.
7
+ - Unified random sampling and frozen schedules through one fixed-window
8
+ estimation path.
9
+ - Simplified state-count selection to subject-disjoint held-out score
10
+ comparison with compact JSON output.
11
+ - Removed cryptographic data/model identities, workflow-directory loaders,
12
+ nested checkpointing, and legacy compatibility layers from the development
13
+ codebase.
14
+ - Kept model, prediction, alignment, and information artifacts pickle-free and
15
+ validated by explicit shapes, parameters, feature keys, and participant
16
+ metadata.
17
+ - ETS and MTD share the same segment-safe instantaneous-edge framework while
18
+ retaining their distinct sample generators.
19
+ - Paired NBS, HC3 inference, information estimates, and all censor-gap-safe
20
+ connectivity methods retain their numerical APIs.
21
+ - FeatureStore summaries support streaming acquisition-level mean, population
22
+ variance, standard deviation, minimum, and maximum endpoints.
@@ -0,0 +1,9 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use dfc-kit, cite this software and the original papers for the methods you apply."
3
+ title: "dfc-kit: Censor-aware dynamic functional connectivity tools"
4
+ type: software
5
+ authors:
6
+ - name: "dfc-kit contributors"
7
+ version: 1.0.0
8
+ date-released: 2026-08-24
9
+ license: BSD-3-Clause
@@ -0,0 +1,31 @@
1
+ # Contributing
2
+
3
+ Contributions should preserve the package boundary: production inputs begin at
4
+ XCP-D parcellated derivatives, while cohort rules, clinical semantics, figures,
5
+ and manuscript workflows remain in downstream applications.
6
+
7
+ ## Development setup
8
+
9
+ ```bash
10
+ python -m venv .venv
11
+ source .venv/bin/activate
12
+ python -m pip install -U pip
13
+ python -m pip install -e '.[all,dev,docs]'
14
+ python -m unittest discover
15
+ ruff check src tests
16
+ mkdocs build --strict
17
+ ```
18
+
19
+ ## Change requirements
20
+
21
+ - Temporal methods must prove that no operation crosses a censor gap.
22
+ - Learned methods must expose fit-subject identity and reject held-out overlap.
23
+ - Randomized methods must require or record a reproducible seed.
24
+ - Inferential APIs must identify the statistical unit, tail, and correction scope.
25
+ - New numerical kernels need known-value tests and, when migrated from a research
26
+ implementation, a small redistributable regression fixture.
27
+ - Public examples must not contain private participant data or project-specific
28
+ clinical semantics.
29
+
30
+ Use focused commits and explain any change to a mathematical or statistical
31
+ contract in both tests and user documentation.
@@ -0,0 +1,42 @@
1
+ # Engineering plan
2
+
3
+ `dfc-kit` is a numerical library, not an experiment scheduler. The design is
4
+ organized around a short path:
5
+
6
+ ```text
7
+ XCP-D derivatives
8
+ -> censor-safe feature estimator
9
+ -> FeatureStore or in-memory result
10
+ -> state model / information estimator
11
+ -> explicit score, summary, or inference result
12
+ ```
13
+
14
+ ## Design rules
15
+
16
+ 1. Preserve original frame indices and segment identities.
17
+ 2. Never calculate a temporal derivative, window, phase feature, or state
18
+ transition across a retained-frame gap.
19
+ 3. Keep fit and held-out subjects explicit in function arguments.
20
+ 4. Validate shapes, feature keys, finite values, model parameters, and duplicate
21
+ acquisition identities at the point of use.
22
+ 5. Prefer one direct computation path over resumable intermediate state.
23
+ 6. Store model parameters and human-readable metadata; do not add cryptographic
24
+ identities to numerical results.
25
+ 7. Keep MI/CMI in `dfckit.information`, separate from connectivity kernels.
26
+ 8. Keep the agent package separate from this toolkit.
27
+
28
+ ## State-count workflow
29
+
30
+ For each candidate K and subject-disjoint fold, fit on the training subjects and
31
+ score on the held-out subjects. Average repeated seeds inside each participant,
32
+ then average participants inside each fold. The validation module returns the
33
+ candidate table, best K, and one-standard-error K. A final refit is explicit and
34
+ does not require a workflow directory.
35
+
36
+ ## Verification
37
+
38
+ ```bash
39
+ python -m unittest discover
40
+ ruff check src tests
41
+ mkdocs build --strict
42
+ ```
dfc_kit-1.0.0/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, dfc-kit contributors
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,12 @@
1
+ include CHANGELOG.md
2
+ include CITATION.cff
3
+ include CONTRIBUTING.md
4
+ include ENGINEERING_PLAN.md
5
+ include LICENSE
6
+ include README.md
7
+ include ROADMAP.md
8
+ include SECURITY.md
9
+ include mkdocs.yml
10
+ recursive-include benchmarks *.md *.py
11
+ recursive-include docs *.md
12
+ recursive-include tests *.json *.py
dfc_kit-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: dfc-kit
3
+ Version: 1.0.0
4
+ Summary: Censor-aware tools for dynamic functional connectivity analysis
5
+ License-Expression: BSD-3-Clause
6
+ Project-URL: Homepage, https://github.com/yidao9518/dfc-kit
7
+ Project-URL: Repository, https://github.com/yidao9518/dfc-kit
8
+ Project-URL: Issues, https://github.com/yidao9518/dfc-kit/issues
9
+ Keywords: functional connectivity,dynamic functional connectivity,fMRI,neuroimaging,XCP-D
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy>=1.23
22
+ Provides-Extra: states
23
+ Requires-Dist: scikit-learn>=1.2; extra == "states"
24
+ Provides-Extra: phase
25
+ Requires-Dist: scipy>=1.10; extra == "phase"
26
+ Provides-Extra: inference
27
+ Requires-Dist: scipy>=1.10; extra == "inference"
28
+ Provides-Extra: hmm
29
+ Requires-Dist: hmmlearn>=0.3; extra == "hmm"
30
+ Requires-Dist: scikit-learn>=1.2; extra == "hmm"
31
+ Provides-Extra: information
32
+ Requires-Dist: scipy>=1.10; extra == "information"
33
+ Provides-Extra: all
34
+ Requires-Dist: hmmlearn>=0.3; extra == "all"
35
+ Requires-Dist: scikit-learn>=1.2; extra == "all"
36
+ Requires-Dist: scipy>=1.10; extra == "all"
37
+ Provides-Extra: dev
38
+ Requires-Dist: build>=1.2; extra == "dev"
39
+ Requires-Dist: pytest>=8; extra == "dev"
40
+ Requires-Dist: ruff>=0.6; extra == "dev"
41
+ Requires-Dist: twine>=5; extra == "dev"
42
+ Provides-Extra: docs
43
+ Requires-Dist: mkdocs<2,>=1.6; extra == "docs"
44
+ Dynamic: license-file
45
+
46
+ # dfc-kit
47
+
48
+ `dfc-kit` is an open-source Python toolkit for dynamic functional connectivity
49
+ analysis of XCP-D parcellated derivatives. It provides composable estimators,
50
+ state models, network summaries, statistical inference, and command-line
51
+ workflows for reproducible neuroimaging analysis.
52
+
53
+ ```text
54
+ BIDS -> fMRIPrep -> XCP-D -> dfc-kit
55
+ ```
56
+
57
+ ## Why dfc-kit
58
+
59
+ `dfc-kit` provides a unified workflow for estimating time-varying functional
60
+ connectivity, identifying recurring brain states, and testing paired or
61
+ between-group differences. Sliding-window FC, instantaneous edges generated
62
+ from ETS or MTD samples, LEiDA, CAP, KMeans, and Gaussian HMM analyses share
63
+ the same data structures and output conventions, making it easier to compare
64
+ methods without rebuilding data loading, state summaries, and statistical
65
+ inference for every analysis.
66
+
67
+ The toolkit supports both direct in-memory analysis and chunked feature stores
68
+ for larger datasets, with matching Python and command-line interfaces.
69
+
70
+ ## Features
71
+
72
+ - **Input and topology:** XCP-D discovery and validation, multi-atlas ROI
73
+ loading, acquisition identity, and censor-bounded sequences. Censored time
74
+ points retain their original frame indices, and temporal operations are
75
+ evaluated separately within contiguous retained segments.
76
+ - **Connectivity:** weighted sliding-window FC, instantaneous ETS/MTD edges,
77
+ LEiDA, low-rank covariance geometry, and fixed-length MI/CMI.
78
+ - **Connectivity and state analysis:** partition-based graph metrics, CAP, KMeans,
79
+ Gaussian HMMs, state alignment, occupancy/dwell/transition summaries, and
80
+ selection of the number of states using held-out participants.
81
+ - **Inference:** paired sign-flips, bootstrap intervals, HC3 models,
82
+ declared-family FDR, generic paired endpoint inference, paired NBS, and
83
+ within-subject motion matching.
84
+ - **Large-dataset workflows:** chunked, memory-mapped FeatureStores and
85
+ batch-wise fitting for MiniBatch KMeans and Incremental PCA.
86
+ - **Portable results:** models and held-out predictions stored as JSON and
87
+ NumPy arrays with explicit feature, subject, and parameter metadata.
88
+
89
+ The [method inventory](docs/method_inventory.md) maps each method family to its
90
+ public API and guide. Public data, connectivity, state, reference, and
91
+ inference objects are covered by the package test suite and documented
92
+ contracts.
93
+
94
+ ## Scope
95
+
96
+ The supported input boundary is XCP-D output. `dfc-kit` does not reimplement
97
+ fMRIPrep-to-XCP-D denoising, filtering, censoring, interpolation, or
98
+ parcellation. Callers provide ROI definitions, cohort labels, clinical
99
+ variables, and manuscript-specific analyses around the library's numerical
100
+ interfaces. The array API is also available for equivalently preprocessed ROI
101
+ time series that are not stored as XCP-D derivatives.
102
+
103
+ ## Installation
104
+
105
+ ```bash
106
+ python -m pip install dfc-kit
107
+ ```
108
+
109
+ Install only the optional method families required by an analysis:
110
+
111
+ ```bash
112
+ python -m pip install 'dfc-kit[phase,states,hmm,information,inference]'
113
+ ```
114
+
115
+ Python 3.10 or newer is required. See [Getting started](docs/getting_started.md)
116
+ for development installation and dependency details.
117
+
118
+ ## Quick start
119
+
120
+ ```python
121
+ from dfckit.connectivity import SlidingWindowFC
122
+ from dfckit.io import load_xcpd_run
123
+
124
+ loaded = load_xcpd_run(
125
+ "/path/to/xcp_d",
126
+ subject="sub-001",
127
+ session="01",
128
+ task="rest",
129
+ atlases=("Schaefer200",),
130
+ space="MNI152NLin2009cAsym",
131
+ minimum_coverage=0.5,
132
+ tr=0.8,
133
+ )
134
+
135
+ result = SlidingWindowFC(length=60, step=10, taper="hamming").transform(loaded.run)
136
+ print(result.features.shape)
137
+ print(result.start_frames, result.end_frames, result.segment_ids)
138
+ ```
139
+
140
+ The result contains Fisher-z upper-triangle edges and the original-frame bounds
141
+ of every valid window. For a complete path from XCP-D discovery through state
142
+ fitting, see the [XCP-D-to-state tutorial](docs/tutorial_xcpd_to_states.md).
143
+
144
+ ## Command line
145
+
146
+ The `dfc-kit` command exposes XCP-D inspection, FeatureStore construction,
147
+ state fitting, held-out prediction, scoring, alignment, and state-count
148
+ validation. Start with:
149
+
150
+ ```bash
151
+ dfc-kit --help
152
+ dfc-kit inspect-xcpd --help
153
+ dfc-kit build-store --help
154
+ dfc-kit fixed-information --help
155
+ dfc-kit describe-states --help
156
+ dfc-kit infer-state-metrics --help
157
+ dfc-kit summarize-store --help
158
+ dfc-kit summarize-information --help
159
+ dfc-kit infer-paired-endpoints --help
160
+ ```
161
+
162
+ See [Command-line workflows](docs/cli.md) for complete examples and arguments,
163
+ including fixed-length MI/CMI artifacts and frozen-window replay.
164
+
165
+ ## Documentation
166
+
167
+ - [Documentation home](docs/index.md)
168
+ - [XCP-D input contract](docs/xcpd_input.md)
169
+ - [Connectivity methods](docs/correlation.md)
170
+ - [State models and validation](docs/states.md)
171
+ - [API map](docs/api.md)
172
+ - [Release process](docs/release.md)
173
+
174
+ ## Development
175
+
176
+ ```bash
177
+ python -m pip install -e '.[all,dev,docs]'
178
+ python -m unittest discover
179
+ ruff check src tests
180
+ mkdocs build --strict
181
+ ```
182
+
183
+ `dfc-kit` is distributed under the BSD-3-Clause license. See `LICENSE` and
184
+ `CITATION.cff` for licensing and citation information.
@@ -0,0 +1,139 @@
1
+ # dfc-kit
2
+
3
+ `dfc-kit` is an open-source Python toolkit for dynamic functional connectivity
4
+ analysis of XCP-D parcellated derivatives. It provides composable estimators,
5
+ state models, network summaries, statistical inference, and command-line
6
+ workflows for reproducible neuroimaging analysis.
7
+
8
+ ```text
9
+ BIDS -> fMRIPrep -> XCP-D -> dfc-kit
10
+ ```
11
+
12
+ ## Why dfc-kit
13
+
14
+ `dfc-kit` provides a unified workflow for estimating time-varying functional
15
+ connectivity, identifying recurring brain states, and testing paired or
16
+ between-group differences. Sliding-window FC, instantaneous edges generated
17
+ from ETS or MTD samples, LEiDA, CAP, KMeans, and Gaussian HMM analyses share
18
+ the same data structures and output conventions, making it easier to compare
19
+ methods without rebuilding data loading, state summaries, and statistical
20
+ inference for every analysis.
21
+
22
+ The toolkit supports both direct in-memory analysis and chunked feature stores
23
+ for larger datasets, with matching Python and command-line interfaces.
24
+
25
+ ## Features
26
+
27
+ - **Input and topology:** XCP-D discovery and validation, multi-atlas ROI
28
+ loading, acquisition identity, and censor-bounded sequences. Censored time
29
+ points retain their original frame indices, and temporal operations are
30
+ evaluated separately within contiguous retained segments.
31
+ - **Connectivity:** weighted sliding-window FC, instantaneous ETS/MTD edges,
32
+ LEiDA, low-rank covariance geometry, and fixed-length MI/CMI.
33
+ - **Connectivity and state analysis:** partition-based graph metrics, CAP, KMeans,
34
+ Gaussian HMMs, state alignment, occupancy/dwell/transition summaries, and
35
+ selection of the number of states using held-out participants.
36
+ - **Inference:** paired sign-flips, bootstrap intervals, HC3 models,
37
+ declared-family FDR, generic paired endpoint inference, paired NBS, and
38
+ within-subject motion matching.
39
+ - **Large-dataset workflows:** chunked, memory-mapped FeatureStores and
40
+ batch-wise fitting for MiniBatch KMeans and Incremental PCA.
41
+ - **Portable results:** models and held-out predictions stored as JSON and
42
+ NumPy arrays with explicit feature, subject, and parameter metadata.
43
+
44
+ The [method inventory](docs/method_inventory.md) maps each method family to its
45
+ public API and guide. Public data, connectivity, state, reference, and
46
+ inference objects are covered by the package test suite and documented
47
+ contracts.
48
+
49
+ ## Scope
50
+
51
+ The supported input boundary is XCP-D output. `dfc-kit` does not reimplement
52
+ fMRIPrep-to-XCP-D denoising, filtering, censoring, interpolation, or
53
+ parcellation. Callers provide ROI definitions, cohort labels, clinical
54
+ variables, and manuscript-specific analyses around the library's numerical
55
+ interfaces. The array API is also available for equivalently preprocessed ROI
56
+ time series that are not stored as XCP-D derivatives.
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ python -m pip install dfc-kit
62
+ ```
63
+
64
+ Install only the optional method families required by an analysis:
65
+
66
+ ```bash
67
+ python -m pip install 'dfc-kit[phase,states,hmm,information,inference]'
68
+ ```
69
+
70
+ Python 3.10 or newer is required. See [Getting started](docs/getting_started.md)
71
+ for development installation and dependency details.
72
+
73
+ ## Quick start
74
+
75
+ ```python
76
+ from dfckit.connectivity import SlidingWindowFC
77
+ from dfckit.io import load_xcpd_run
78
+
79
+ loaded = load_xcpd_run(
80
+ "/path/to/xcp_d",
81
+ subject="sub-001",
82
+ session="01",
83
+ task="rest",
84
+ atlases=("Schaefer200",),
85
+ space="MNI152NLin2009cAsym",
86
+ minimum_coverage=0.5,
87
+ tr=0.8,
88
+ )
89
+
90
+ result = SlidingWindowFC(length=60, step=10, taper="hamming").transform(loaded.run)
91
+ print(result.features.shape)
92
+ print(result.start_frames, result.end_frames, result.segment_ids)
93
+ ```
94
+
95
+ The result contains Fisher-z upper-triangle edges and the original-frame bounds
96
+ of every valid window. For a complete path from XCP-D discovery through state
97
+ fitting, see the [XCP-D-to-state tutorial](docs/tutorial_xcpd_to_states.md).
98
+
99
+ ## Command line
100
+
101
+ The `dfc-kit` command exposes XCP-D inspection, FeatureStore construction,
102
+ state fitting, held-out prediction, scoring, alignment, and state-count
103
+ validation. Start with:
104
+
105
+ ```bash
106
+ dfc-kit --help
107
+ dfc-kit inspect-xcpd --help
108
+ dfc-kit build-store --help
109
+ dfc-kit fixed-information --help
110
+ dfc-kit describe-states --help
111
+ dfc-kit infer-state-metrics --help
112
+ dfc-kit summarize-store --help
113
+ dfc-kit summarize-information --help
114
+ dfc-kit infer-paired-endpoints --help
115
+ ```
116
+
117
+ See [Command-line workflows](docs/cli.md) for complete examples and arguments,
118
+ including fixed-length MI/CMI artifacts and frozen-window replay.
119
+
120
+ ## Documentation
121
+
122
+ - [Documentation home](docs/index.md)
123
+ - [XCP-D input contract](docs/xcpd_input.md)
124
+ - [Connectivity methods](docs/correlation.md)
125
+ - [State models and validation](docs/states.md)
126
+ - [API map](docs/api.md)
127
+ - [Release process](docs/release.md)
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ python -m pip install -e '.[all,dev,docs]'
133
+ python -m unittest discover
134
+ ruff check src tests
135
+ mkdocs build --strict
136
+ ```
137
+
138
+ `dfc-kit` is distributed under the BSD-3-Clause license. See `LICENSE` and
139
+ `CITATION.cff` for licensing and citation information.
@@ -0,0 +1,26 @@
1
+ # Roadmap
2
+
3
+ ## Current development target
4
+
5
+ - Keep the public API small and composable.
6
+ - Treat XCP-D derivatives and ROI definitions as the input boundary.
7
+ - Keep all temporal operations inside contiguous retained-frame segments.
8
+ - Keep KMeans/HMM fitting, decoding, held-out scoring, and stability summaries
9
+ independent from manuscript-specific workflows.
10
+ - Select K with subject-disjoint held-out scores and a compact in-memory
11
+ comparison.
12
+ - Maintain pickle-free JSON/NumPy artifacts with explicit numerical metadata.
13
+ - Expand numerical regression tests for MI/CMI, ETS/MTD, low-rank methods,
14
+ state alignment, and inference.
15
+
16
+ ## Deliberately out of scope
17
+
18
+ - Resumable workflow directories and nested state-count orchestration.
19
+ - Cryptographic identities for arrays, models, or result files.
20
+ - Parkinson-specific ROI definitions, clinical variables, figures, and
21
+ manuscript automation.
22
+
23
+ ## Release boundary
24
+
25
+ The independent `dfc-agent` project may orchestrate this toolkit, but remains
26
+ in a separate repository and package.
@@ -0,0 +1,12 @@
1
+ # Security policy
2
+
3
+ `dfc-kit` processes local derivative files and does not require network access.
4
+ Do not include participant data, access credentials, private server paths, or
5
+ authenticated URLs in bug reports or test fixtures.
6
+
7
+ For a suspected vulnerability, contact the repository maintainer privately
8
+ through the hosting platform rather than opening a public issue. Include the
9
+ affected version, a minimal synthetic reproducer, and the expected impact.
10
+
11
+ Only the latest minor release receives security fixes while the project remains
12
+ pre-1.0.
@@ -0,0 +1,69 @@
1
+ # Synthetic performance benchmarks
2
+
3
+ Run each method in a separate process so `ru_maxrss` has one clear scope:
4
+
5
+ ```bash
6
+ PYTHONPATH=src python benchmarks/profile_core.py \
7
+ --method window-fc --frames 600 --rois 100 --length 60 --step 5
8
+
9
+ PYTHONPATH=src python benchmarks/profile_core.py \
10
+ --method ets-full --frames 1000 --rois 200
11
+
12
+ PYTHONPATH=src python benchmarks/profile_core.py \
13
+ --method ets-rss --frames 1000 --rois 200
14
+
15
+ PYTHONPATH=src python benchmarks/profile_core.py \
16
+ --method ets-store --frames 1000 --rois 200
17
+
18
+ PYTHONPATH=src python benchmarks/profile_core.py \
19
+ --method window-kmeans-memory --frames 1200 --rois 200 \
20
+ --length 60 --step 5 --states 4 --n-init 3 --max-iter 3 --batch-size 64
21
+
22
+ PYTHONPATH=src python benchmarks/profile_core.py \
23
+ --method window-kmeans-store --frames 1200 --rois 200 \
24
+ --length 60 --step 5 --states 4 --n-init 3 --max-iter 3 --batch-size 64
25
+
26
+ PYTHONPATH=src python benchmarks/profile_core.py \
27
+ --method window-hmm-store --frames 1200 --rois 200 \
28
+ --length 60 --step 5 --states 4 --n-init 1 --max-iter 20 \
29
+ --batch-size 64 --pca-components 10
30
+ ```
31
+
32
+ The input is deterministic synthetic Gaussian data with a small shared latent
33
+ component and one explicit censor gap. The script reports elapsed wall time,
34
+ current RSS before/after the transform on Linux, process-lifetime peak RSS,
35
+ transform-scoped `tracemalloc` peak, and the size of arrays retained in the
36
+ result object. It is a developer benchmark, not a scientific result or a CI
37
+ pass/fail threshold.
38
+
39
+ `ETS().rss()` is expected to use substantially less memory than materializing
40
+ the complete frame-by-edge ETS matrix. High-dimensional sliding-window FC and
41
+ full ETS are the main targets for chunked feature output.
42
+
43
+ The two `window-kmeans-*` cases precompute identical sliding-window FC before
44
+ starting the measured region. They therefore compare only state fitting: the
45
+ in-memory path pools a `FeatureSequenceDataset`, while the store path estimates
46
+ the scaler, updates MiniBatchKMeans, scores all initializations, and emits labels
47
+ by traversing memory-mapped chunks. Feature construction time is intentionally
48
+ excluded from both measurements.
49
+
50
+ Reference run (`1200` frames, `200` ROIs, `60`-frame windows, step `5`, `4`
51
+ states, `3` initializations, `3` passes, batch size `64`) produced:
52
+
53
+ | State-fitting path | Peak RSS | Traced peak | Time |
54
+ |---|---:|---:|---:|
55
+ | In-memory `FeatureSequenceDataset` | 497.28 MiB | 279.89 MiB | 8.11 s |
56
+ | Memory-mapped `FeatureStore` | 294.03 MiB | 135.57 MiB | 8.44 s |
57
+
58
+ These are synthetic engineering measurements, not scientific results. The
59
+ stored path's files occupied `34.02 MiB`; its advantage is bounded memory, not
60
+ an assumption that disk I/O is free.
61
+
62
+ The `window-hmm-store` command above (`1` initialization, `20` HMM iterations,
63
+ and `10` PCA components) produced `218` windows with `19,900` original FC
64
+ features. The measured fit took `1.94 s`, reached `292.15 MiB` process-lifetime
65
+ peak RSS and `127.22 MiB` transform-scoped traced peak, and retained `2.60 MiB`
66
+ of result arrays. The memory-mapped feature files occupied `34.02 MiB`. The
67
+ compact fitted model does not retain a dense
68
+ `states x original_features x original_features` covariance tensor; an
69
+ original-space covariance is reconstructed explicitly for one requested state.