topoconscious 0.1.10__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 (29) hide show
  1. topoconscious-0.1.10/LICENSE +83 -0
  2. topoconscious-0.1.10/MANIFEST.in +3 -0
  3. topoconscious-0.1.10/PKG-INFO +427 -0
  4. topoconscious-0.1.10/README.md +374 -0
  5. topoconscious-0.1.10/pyproject.toml +85 -0
  6. topoconscious-0.1.10/setup.cfg +4 -0
  7. topoconscious-0.1.10/setup.py +27 -0
  8. topoconscious-0.1.10/tests/test_hmm.py +34 -0
  9. topoconscious-0.1.10/tests/test_metrics.py +80 -0
  10. topoconscious-0.1.10/tests/test_topology.py +56 -0
  11. topoconscious-0.1.10/tests/test_transfer_entropy.py +42 -0
  12. topoconscious-0.1.10/topoconscious/__init__.py +20 -0
  13. topoconscious-0.1.10/topoconscious/ext/topo_te.cpp +115 -0
  14. topoconscious-0.1.10/topoconscious/hmm.py +77 -0
  15. topoconscious-0.1.10/topoconscious/localization.py +245 -0
  16. topoconscious-0.1.10/topoconscious/metrics.py +217 -0
  17. topoconscious-0.1.10/topoconscious/pipeline.py +244 -0
  18. topoconscious-0.1.10/topoconscious/preprocessing.py +61 -0
  19. topoconscious-0.1.10/topoconscious/run_pipeline.py +27 -0
  20. topoconscious-0.1.10/topoconscious/topology.py +185 -0
  21. topoconscious-0.1.10/topoconscious/transfer_entropy.py +117 -0
  22. topoconscious-0.1.10/topoconscious/validation.py +184 -0
  23. topoconscious-0.1.10/topoconscious/visualization.py +151 -0
  24. topoconscious-0.1.10/topoconscious.egg-info/PKG-INFO +427 -0
  25. topoconscious-0.1.10/topoconscious.egg-info/SOURCES.txt +27 -0
  26. topoconscious-0.1.10/topoconscious.egg-info/dependency_links.txt +1 -0
  27. topoconscious-0.1.10/topoconscious.egg-info/entry_points.txt +2 -0
  28. topoconscious-0.1.10/topoconscious.egg-info/requires.txt +26 -0
  29. topoconscious-0.1.10/topoconscious.egg-info/top_level.txt +1 -0
@@ -0,0 +1,83 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity.
18
+
19
+ "You" (or "Your") shall mean an individual or Legal Entity
20
+ exercising permissions granted by this License.
21
+
22
+ "Source" form shall mean the preferred form for making modifications.
23
+
24
+ "Object" form shall mean any form resulting from mechanical
25
+ transformation or translation of a Source form.
26
+
27
+ "Work" shall mean the work of authorship made available under
28
+ the License, as indicated by a copyright notice included in or
29
+ attached to the work.
30
+
31
+ "Derivative Works" shall mean any work that is based on the Work.
32
+
33
+ "Contribution" shall mean any work submitted to the Licensor for
34
+ inclusion in the Work.
35
+
36
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
37
+ whom a Contribution has been received by the Licensor.
38
+
39
+ 2. Grant of Copyright License. Subject to the terms and conditions of
40
+ this License, each Contributor hereby grants to You a perpetual,
41
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
42
+ copyright license to reproduce, prepare Derivative Works of,
43
+ publicly display, publicly perform, sublicense, and distribute the
44
+ Work and such Derivative Works in Source or Object form.
45
+
46
+ 3. Grant of Patent License. Subject to the terms and conditions of
47
+ this License, each Contributor hereby grants to You a perpetual,
48
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
49
+ patent license to make, use, sell, offer for sale, import, and
50
+ otherwise transfer the Work.
51
+
52
+ 4. Redistribution. You may reproduce and distribute copies of the
53
+ Work or Derivative Works thereof provided You meet the conditions
54
+ of this License.
55
+
56
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
57
+ any Contribution submitted for inclusion in the Work shall be under
58
+ the terms and conditions of this License.
59
+
60
+ 6. Trademarks. This License does not grant permission to use the
61
+ trade names, trademarks, service marks, or product names of the
62
+ Licensor.
63
+
64
+ 7. Disclaimer of Warranty. Unless required by applicable law or
65
+ agreed to in writing, the Work is provided on an "AS IS" BASIS,
66
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
67
+
68
+ 8. Limitation of Liability. In no event shall any Contributor be
69
+ liable for any damages arising from this License or use of the Work.
70
+
71
+ 9. Accepting Warranty or Additional Liability. You may offer
72
+ additional warranty or liability obligations consistent with this
73
+ License, at Your own risk.
74
+
75
+ END OF TERMS AND CONDITIONS
76
+
77
+ Copyright 2026 Chege-N.
78
+
79
+ Licensed under the Apache License, Version 2.0 (the "License");
80
+ you may not use this file except in compliance with the License.
81
+ You may obtain a copy of the License at
82
+
83
+ http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,3 @@
1
+ include README.md
2
+ include LICENSE
3
+ recursive-include topoconscious/ext *.cpp
@@ -0,0 +1,427 @@
1
+ Metadata-Version: 2.4
2
+ Name: topoconscious
3
+ Version: 0.1.10
4
+ Summary: Persistent homology pipeline for detecting neural correlates of consciousness from fMRI
5
+ Author: Felix Chege Ng'ang'a
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Chege-N/TopoConscious
8
+ Project-URL: Repository, https://github.com/Chege-N/TopoConscious
9
+ Project-URL: Documentation, https://github.com/Chege-N/TopoConscious
10
+ Project-URL: Issues, https://github.com/Chege-N/TopoConscious/issues
11
+ Project-URL: Paper, https://joss.theoj.org
12
+ Keywords: persistent-homology,topological-data-analysis,neuroscience,fmri,consciousness,tda,hidden-markov-model,transfer-entropy
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
23
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: numpy>=1.24
28
+ Requires-Dist: scipy>=1.10
29
+ Requires-Dist: matplotlib>=3.7
30
+ Requires-Dist: pandas>=2.0
31
+ Requires-Dist: scikit-learn>=1.3
32
+ Requires-Dist: ripser>=0.6
33
+ Requires-Dist: gudhi>=3.8
34
+ Requires-Dist: POT>=0.9.0
35
+ Requires-Dist: hmmlearn>=0.3
36
+ Requires-Dist: nilearn>=0.10
37
+ Requires-Dist: nibabel>=5.0
38
+ Requires-Dist: pybids>=0.16
39
+ Requires-Dist: persim>=0.3
40
+ Requires-Dist: fastapi>=0.100.0
41
+ Requires-Dist: uvicorn>=0.23.0
42
+ Requires-Dist: networkx>=3.0
43
+ Provides-Extra: gpu
44
+ Requires-Dist: cupy-cuda12x>=12.0; extra == "gpu"
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest>=7.0; extra == "dev"
47
+ Requires-Dist: pytest-cov; extra == "dev"
48
+ Requires-Dist: flake8; extra == "dev"
49
+ Requires-Dist: twine; extra == "dev"
50
+ Requires-Dist: build; extra == "dev"
51
+ Dynamic: license-file
52
+ Dynamic: requires-python
53
+
54
+ # 🧠 TopoConscious
55
+
56
+ > **Persistent Homology Pipeline for Neural Correlates of Consciousness**
57
+
58
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue)](https://python.org)
59
+ [![License](https://img.shields.io/badge/license-Apache%202.0-green)](LICENSE)
60
+ [![GUDHI](https://img.shields.io/badge/topology-GUDHI%203.8%2B-purple)](https://gudhi.inria.fr)
61
+ [![Ripser](https://img.shields.io/badge/homology-Ripser%200.6%2B-orange)](https://ripser.scikit-tda.org)
62
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.20101572.svg)](https://doi.org/10.5281/zenodo.20101572)
63
+ [!PyPI](https://img.shields.io/pypi/v/topoconscious.svg)
64
+
65
+ TopoConscious is a Python package that mathematically distinguishes **conscious** from **unconscious** brain states using topological data analysis of fMRI time series. It models each sliding time window of fMRI activity as a point cloud in high-dimensional space, computes persistent homology (Hβ‚€, H₁, Hβ‚‚), and tracks topological changes over time to decode consciousness probability.
66
+
67
+ ---
68
+
69
+ ## πŸ”¬ The Problem
70
+
71
+ The neural correlates of consciousness (NCC) remain one of neuroscience's deepest unsolved problems. Existing approaches use static functional connectivity matrices or power spectra β€” they miss the **dynamic topological reorganisation** that may underlie conscious experience.
72
+
73
+ **The hypothesis:** Conscious states exhibit greater persistence of 1-dimensional cycles (loops) in the functional connectivity manifold β€” reflecting dynamic integration β€” while unconscious states are dominated by 0-dimensional clusters (segregation).
74
+
75
+ ---
76
+
77
+ ## πŸ—οΈ Architecture
78
+
79
+ ```
80
+ fMRI NIfTI (BIDS)
81
+ β”‚
82
+ β–Ό
83
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
84
+ β”‚ Preprocessing β”‚ Atlas parcellation (AAL-90 / Schaefer-100 / Destrieux)
85
+ β”‚ β”‚ Band-pass 0.01–0.1 Hz, detrend, smooth 6mm FWHM
86
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
87
+ β”‚ (n_volumes Γ— n_regions) time-series matrix
88
+ β–Ό
89
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
90
+ β”‚ Sliding Windows β”‚ window=30 TRs, step=5 TRs β†’ ~54 windows per scan
91
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
92
+ β”‚ list of (30 Γ— n_regions) point clouds
93
+ β–Ό
94
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
95
+ β”‚ MaxMin Sampling β”‚ Farthest-point landmark selection β†’ 200 pts
96
+ β”‚ β”‚ Reduces O(nΒ²) to O(kΒ²), keeps topology intact
97
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
98
+ β”‚
99
+ β–Ό
100
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
101
+ β”‚ Persistent β”‚ Vietoris-Rips filtration via GUDHI + Ripser
102
+ β”‚ Homology Engine β”‚ Hβ‚€ (clusters), H₁ (loops), Hβ‚‚ (voids)
103
+ β”‚ β”‚ PCA pre-projection for 90-dim β†’ 30-dim approximation
104
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
105
+ β”‚ persistence diagrams {dim: [(birth, death), ...]}
106
+ β–Ό
107
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
108
+ β”‚ Topological Metrics β”‚
109
+ β”‚ β”‚
110
+ β”‚ Wasserstein Wβ‚‚ β€” standard diagram distance β”‚
111
+ β”‚ MΓΌller-Lyer β€” scale + location aware metric β”‚ ← Novel
112
+ β”‚ Current β€” persistence-weighted OT β”‚
113
+ β”‚ Persistence β€” functional LΒ² landscape β”‚
114
+ β”‚ Landscape β€” k-th largest tent functions β”‚
115
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
116
+ β”‚ distance timelines
117
+ β–Ό
118
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
119
+ β”‚ Signature β”‚ 7-feature vector per window:
120
+ β”‚ Vectors β”‚ total_pers H0/H1/H2, max_pers H1,
121
+ β”‚ β”‚ n_bars H1, birth/death ratio, entropy H1
122
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
123
+ β”‚
124
+ β–Ό
125
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
126
+ β”‚ Gaussian HMM β”‚ 2-state (conscious / unconscious)
127
+ β”‚ β”‚ Viterbi decoding + posterior P(conscious)
128
+ β”‚ β”‚ Covariance fallback: full β†’ diag β†’ spherical
129
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
130
+ β”‚ P(conscious) time course
131
+ β–Ό
132
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
133
+ β”‚ Topological β”‚ TE(Xβ†’Y) = H(Yβ‚œ|Yβ‚œβ‚‹β‚) - H(Yβ‚œ|Yβ‚œβ‚‹β‚,Xβ‚œβ‚‹β‚)
134
+ β”‚ Transfer β”‚ C++/OpenMP extension for O(nΒ²) region pairs
135
+ β”‚ Entropy β”‚ Measures directional information flow
136
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
137
+ β”‚
138
+ β–Ό
139
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
140
+ β”‚ Cycle β”‚ GUDHI SimplexTree cocycle representatives
141
+ β”‚ Localization β”‚ Maps H₁ generators β†’ anatomical regions
142
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
143
+ β”‚
144
+ β–Ό
145
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
146
+ β”‚ Output β”‚ P(conscious).csv, wasserstein_timeline.npy,
147
+ β”‚ β”‚ ml_timeline.npy, pl_timeline.npy, te_matrix.npy
148
+ β”‚ β”‚ consciousness_timeline.png, te_matrix.png
149
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
150
+ ```
151
+
152
+ ---
153
+
154
+ ## πŸ“¦ Installation
155
+
156
+ ### Requirements
157
+ - Python 3.9+
158
+ - C++ compiler with OpenMP support (GCC 9+ recommended)
159
+ - Optional: CUDA 12 + cupy for GPU acceleration
160
+
161
+ ```bash
162
+ # Clone the repository
163
+ git clone https://github.com/Chege-N/TopoConscious.git
164
+ cd TopoConscious
165
+
166
+ # Create and activate virtual environment
167
+ python -m venv venv
168
+ source venv/bin/activate # Linux/macOS
169
+ # venv\Scripts\activate # Windows
170
+
171
+ # Install dependencies
172
+ pip install -r requirements.txt
173
+
174
+ # Install TopoConscious (builds the C++ extension)
175
+ pip install -e .
176
+ ```
177
+
178
+ ### GPU Support (Optional)
179
+ ```bash
180
+ # Uncomment in requirements.txt:
181
+ # cupy-cuda12x>=12.0
182
+ pip install cupy-cuda12x
183
+ ```
184
+
185
+ ---
186
+
187
+ ## πŸš€ Quick Start
188
+
189
+ ### Python API
190
+
191
+ ```python
192
+ from topoconscious import TopoConsciousPipeline
193
+
194
+ pipe = TopoConsciousPipeline(
195
+ bids_dir="data/ds002345",
196
+ output_dir="results/",
197
+ window_size=30, # TRs per window
198
+ step=5, # TR step between windows
199
+ n_landmarks=200, # MaxMin landmark count
200
+ max_homology_dim=2, # Compute H0, H1, H2
201
+ tr=2.0, # Repetition time (seconds)
202
+ atlas="aal", # aal | schaefer100 | destrieux
203
+ use_gpu=False,
204
+ )
205
+
206
+ results = pipe.run()
207
+ # results["sub-01"]["hmm"]["p_conscious"] β†’ array of shape (n_windows,)
208
+ ```
209
+
210
+ ### Command Line Interface
211
+
212
+ ```bash
213
+ topoconscious \
214
+ --bids-dir data/ds002345 \
215
+ --output-dir results/ \
216
+ --window-size 30 \
217
+ --step 5 \
218
+ --landmarks 200 \
219
+ --atlas aal \
220
+ --max-dim 2 \
221
+ --tr 2.0 \
222
+ --gpu # optional
223
+ ```
224
+
225
+ ### FastAPI Backend
226
+
227
+ ```bash
228
+ # Start the REST server
229
+ uvicorn backend.app:app --reload --port 8000
230
+
231
+ # Trigger pipeline run
232
+ curl -X POST http://localhost:8000/run
233
+ ```
234
+
235
+ ---
236
+
237
+ ## πŸ”­ Key Innovations
238
+
239
+ ### 1. MΓΌller-Lyer Current Metric
240
+ Standard Wasserstein distance is permutation-invariant but loses information about *where* features live in the birth-death plane. The MΓΌller-Lyer current adds:
241
+
242
+ ```
243
+ ML(D₁, Dβ‚‚) = Wβ‚‚α΅–α΅‰Κ³Λ’β»Κ·α΅‰β±α΅Κ°α΅—α΅‰α΅ˆ(D₁, Dβ‚‚)
244
+ + Ξ± Β· |Ξ£pers(D₁) βˆ’ Ξ£pers(Dβ‚‚)| ← scale penalty
245
+ + Ξ² Β· β€–centroid(D₁) βˆ’ centroid(Dβ‚‚)β€– ← location penalty
246
+ ```
247
+
248
+ This makes transitions between *many short loops* (unconscious) and *few long loops* (conscious) maximally discriminative.
249
+
250
+ ### 2. Persistence Landscape (Landscape Current)
251
+ The k-th landscape function Ξ»β‚–(t) is the k-th largest tent value at parameter t across all H₁ bars. Lives in LΒ² β€” supports averaging, statistical testing, and inner products:
252
+
253
+ ```python
254
+ from topoconscious.metrics import PersistenceLandscape
255
+ pl = PersistenceLandscape(n_landscapes=5, resolution=100)
256
+ vec = pl.vectorize(diagram) # (500,) feature vector
257
+ dist = pl.distance(dgm1, dgm2) # LΒ² landscape distance
258
+ ```
259
+
260
+ ### 3. Topological Transfer Entropy (C++/OpenMP)
261
+ Directional information flow between brain regions' H₁ persistence time series, parallelised across all O(nΒ²) region pairs:
262
+
263
+ ```
264
+ TE(Xβ†’Y) = H(Yβ‚œ | Yβ‚œβ‚‹β‚) βˆ’ H(Yβ‚œ | Yβ‚œβ‚‹β‚, Xβ‚œβ‚‹β‚)
265
+ ```
266
+
267
+ The C++ extension computes the full 90Γ—90 matrix in milliseconds vs. minutes in Python.
268
+
269
+ ### 4. Full Cycle Localization
270
+ Using GUDHI `SimplexTree` cocycle representatives, each significant H₁ generator is traced back to the specific brain regions forming its boundary β€” enabling anatomical interpretation of which regions are responsible for each consciousness transition.
271
+
272
+ ---
273
+
274
+ ## πŸ“Š Validation
275
+
276
+ Three public datasets target the success criterion of **AUC > 0.90** (vs. static FC baseline ~0.75):
277
+
278
+ | Dataset | Condition | Source |
279
+ |---------|-----------|--------|
280
+ | Propofol | Awake vs. anaesthesia | MIT/Tufts (OpenNeuro ds002898) |
281
+ | Sleep | REM vs. NREM | OpenNeuro ds000201 |
282
+ | Disorders of Consciousness | MCS vs. UWS | Liège dataset |
283
+
284
+ ```python
285
+ from topoconscious.validation import ValidationRunner
286
+
287
+ runner = ValidationRunner(output_dir="results/validation")
288
+ results = runner.evaluate_dataset(ts_list, labels, "propofol")
289
+ # results["auc_topo"] β†’ e.g. 0.94
290
+ # results["auc_fc"] β†’ e.g. 0.76
291
+ runner.plot_roc_curves(results)
292
+ ```
293
+
294
+ ---
295
+
296
+ ## πŸ““ Notebooks
297
+
298
+ | Notebook | Description |
299
+ |----------|-------------|
300
+ | `01_demo_pipeline.ipynb` | End-to-end run on synthetic 300-volume fMRI data |
301
+ | `02_widget_explorer.ipynb` | Interactive ipywidgets scrubber for persistence diagrams |
302
+ | `03_validation_roc.ipynb` | ROC/AUC evaluation with synthetic labelled datasets |
303
+ | `04_real_bids_data.ipynb` | Full walkthrough: DataLad download β†’ BIDS β†’ results |
304
+
305
+ ---
306
+
307
+ ## πŸ§ͺ Tests
308
+
309
+ ```bash
310
+ # Run full test suite
311
+ pytest tests/ -v
312
+
313
+ # Run specific module tests
314
+ pytest tests/test_topology.py -v
315
+ pytest tests/test_metrics.py -v # includes ValidationRunner smoke test
316
+ pytest tests/test_transfer_entropy.py -v
317
+ ```
318
+
319
+ Test coverage:
320
+ - `test_topology.py` β€” landmark sampling, diagram shapes, Wasserstein timeline
321
+ - `test_hmm.py` β€” fit/decode shapes, p_conscious bounds, score() after fit
322
+ - `test_transfer_entropy.py` β€” matrix shape, diagonal=0, non-negativity
323
+ - `test_metrics.py` β€” ML current correctness, self-distance=0, ValidationRunner
324
+
325
+ ---
326
+
327
+ ## πŸ“ Project Structure
328
+
329
+ ```
330
+ TopoConscious/
331
+ β”œβ”€β”€ topoconscious/
332
+ β”‚ β”œβ”€β”€ __init__.py # Package exports
333
+ β”‚ β”œβ”€β”€ pipeline.py # Main orchestrator
334
+ β”‚ β”œβ”€β”€ preprocessing.py # NIfTI/BIDS loader, atlas parcellation
335
+ β”‚ β”œβ”€β”€ topology.py # PersistenceEngine (GUDHI + Ripser)
336
+ β”‚ β”œβ”€β”€ hmm.py # TopologicalHMM (Gaussian, 2-state)
337
+ β”‚ β”œβ”€β”€ transfer_entropy.py # TopologicalTransferEntropy
338
+ β”‚ β”œβ”€β”€ localization.py # CycleLocalizer (GUDHI SimplexTree)
339
+ β”‚ β”œβ”€β”€ visualization.py # TopoVisualizer (matplotlib + ipywidgets)
340
+ β”‚ β”œβ”€β”€ metrics.py # MuellerLyerCurrent + PersistenceLandscape
341
+ β”‚ β”œβ”€β”€ validation.py # ValidationRunner (ROC/AUC)
342
+ β”‚ β”œβ”€β”€ run_pipeline.py # Convenience entry script
343
+ β”‚ └── ext/
344
+ β”‚ └── topo_te.cpp # C++17/OpenMP transfer entropy extension
345
+ β”œβ”€β”€ backend/
346
+ β”‚ └── app.py # FastAPI REST endpoint (POST /run)
347
+ β”œβ”€β”€ notebooks/
348
+ β”‚ β”œβ”€β”€ 01_demo_pipeline.ipynb
349
+ β”‚ β”œβ”€β”€ 02_widget_explorer.ipynb
350
+ β”‚ β”œβ”€β”€ 03_validation_roc.ipynb
351
+ β”‚ └── 04_real_bids_data.ipynb
352
+ β”œβ”€β”€ tests/
353
+ β”‚ β”œβ”€β”€ conftest.py # Shared session-scoped fixtures
354
+ β”‚ β”œβ”€β”€ test_topology.py
355
+ β”‚ β”œβ”€β”€ test_hmm.py
356
+ β”‚ β”œβ”€β”€ test_transfer_entropy.py
357
+ β”‚ └── test_metrics.py
358
+ β”œβ”€β”€ data/ # Place BIDS datasets here
359
+ β”œβ”€β”€ results/ # Pipeline outputs written here
360
+ β”œβ”€β”€ CITATION.cff # Academic citation metadata
361
+ β”œβ”€β”€ LICENSE # Apache 2.0
362
+ β”œβ”€β”€ requirements.txt
363
+ └── setup.py
364
+ ```
365
+
366
+ ---
367
+
368
+ ## βš™οΈ Configuration Reference
369
+
370
+ | Parameter | Default | Description |
371
+ |-----------|---------|-------------|
372
+ | `bids_dir` | β€” | Path to BIDS dataset root |
373
+ | `output_dir` | β€” | Where results are written |
374
+ | `window_size` | `30` | TRs per sliding window |
375
+ | `step` | `5` | TR step between windows |
376
+ | `n_landmarks` | `200` | MaxMin landmark count |
377
+ | `max_homology_dim` | `2` | Max homology dim (0=Hβ‚€, 1=H₁, 2=Hβ‚‚) |
378
+ | `tr` | `2.0` | Repetition time in seconds |
379
+ | `atlas` | `aal` | `aal` / `schaefer100` / `destrieux` |
380
+ | `use_gpu` | `False` | Use cupy-accelerated Ripser |
381
+
382
+ ---
383
+
384
+ ## πŸ“– References
385
+
386
+ 1. Edelsbrunner, H. & Harer, J. (2010). *Computational Topology: An Introduction.* AMS.
387
+ 2. Bauer, U. (2021). Ripser: efficient computation of Vietoris-Rips persistence barcodes. *J. Applied & Computational Topology.*
388
+ 3. Divol, V. & Lacombe, T. (2021). Understanding topology and geometry of persistence diagrams via optimal partial transport. *J. Applied & Computational Topology.*
389
+ 4. Bubenik, P. (2015). Statistical topological data analysis using persistence landscapes. *JMLR 16.*
390
+ 5. GUDHI Project. *Geometry Understanding in Higher Dimensions.* https://gudhi.inria.fr
391
+ 6. Schreiber, T. (2000). Measuring information transfer. *Physical Review Letters 85(2).*
392
+
393
+ ---
394
+
395
+ ## πŸ“„ Citation
396
+
397
+ If you use TopoConscious in your research, please cite:
398
+
399
+ ```bibtex
400
+ @software{topoconscious2026,
401
+ title = {TopoConscious: Persistent Homology Pipeline for Neural Correlates of Consciousness},
402
+ author = {Chege, N.},
403
+ year = {2026},
404
+ version = {0.1.0},
405
+ license = {Apache-2.0},
406
+ url = {https://github.com/Chege-N/TopoConscious}
407
+ }
408
+ ```
409
+
410
+ ---
411
+
412
+ ## 🀝 Contributing
413
+
414
+ Pull requests are welcome. For major changes please open an issue first.
415
+
416
+ ```bash
417
+ # Run tests before submitting
418
+ pytest tests/ -v
419
+ # Check code style
420
+ flake8 topoconscious/ --max-line-length=100
421
+ ```
422
+
423
+ ---
424
+
425
+ ## πŸ“œ License
426
+
427
+ Apache License 2.0 β€” see [LICENSE](LICENSE) for details.