🧠 TopoConscious
Persistent Homology Pipeline for Neural Correlates of Consciousness
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.
🔬 The Problem
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.
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).
🏗️ Architecture
fMRI NIfTI (BIDS)
│
▼
┌─────────────────┐
│ Preprocessing │ Atlas parcellation (AAL-90 / Schaefer-100 / Destrieux)
│ │ Band-pass 0.01–0.1 Hz, detrend, smooth 6mm FWHM
└────────┬────────┘
│ (n_volumes × n_regions) time-series matrix
▼
┌─────────────────┐
│ Sliding Windows │ window=30 TRs, step=5 TRs → ~54 windows per scan
└────────┬────────┘
│ list of (30 × n_regions) point clouds
▼
┌─────────────────┐
│ MaxMin Sampling │ Farthest-point landmark selection → 200 pts
│ │ Reduces O(n²) to O(k²), keeps topology intact
└────────┬────────┘
│
▼
┌─────────────────┐
│ Persistent │ Vietoris-Rips filtration via GUDHI + Ripser
│ Homology Engine │ H₀ (clusters), H₁ (loops), H₂ (voids)
│ │ PCA pre-projection for 90-dim → 30-dim approximation
└────────┬────────┘
│ persistence diagrams {dim: [(birth, death), ...]}
▼
┌─────────────────────────────────────────────────────┐
│ Topological Metrics │
│ │
│ Wasserstein W₂ — standard diagram distance │
│ Müller-Lyer — scale + location aware metric │ ← Novel
│ Current — persistence-weighted OT │
│ Persistence — functional L² landscape │
│ Landscape — k-th largest tent functions │
└────────┬────────────────────────────────────────────┘
│ distance timelines
▼
┌─────────────────┐
│ Signature │ 7-feature vector per window:
│ Vectors │ total_pers H0/H1/H2, max_pers H1,
│ │ n_bars H1, birth/death ratio, entropy H1
└────────┬────────┘
│
▼
┌─────────────────┐
│ Gaussian HMM │ 2-state (conscious / unconscious)
│ │ Viterbi decoding + posterior P(conscious)
│ │ Covariance fallback: full → diag → spherical
└────────┬────────┘
│ P(conscious) time course
▼
┌─────────────────┐
│ Topological │ TE(X→Y) = H(Yₜ|Yₜ₋₁) - H(Yₜ|Yₜ₋₁,Xₜ₋₁)
│ Transfer │ C++/OpenMP extension for O(n²) region pairs
│ Entropy │ Measures directional information flow
└────────┬────────┘
│
▼
┌─────────────────┐
│ Cycle │ GUDHI SimplexTree cocycle representatives
│ Localization │ Maps H₁ generators → anatomical regions
└────────┬────────┘
│
▼
┌─────────────────┐
│ Output │ P(conscious).csv, wasserstein_timeline.npy,
│ │ ml_timeline.npy, pl_timeline.npy, te_matrix.npy
│ │ consciousness_timeline.png, te_matrix.png
└─────────────────┘
📦 Installation
Requirements
- Python 3.9+
- C++ compiler with OpenMP support (GCC 9+ recommended)
- Optional: CUDA 12 + cupy for GPU acceleration
# Clone the repository
git clone https://github.com/Chege-N/TopoConscious.git
cd TopoConscious
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Install TopoConscious (builds the C++ extension)
pip install -e .
GPU Support (Optional)
# Uncomment in requirements.txt:
# cupy-cuda12x>=12.0
pip install cupy-cuda12x
🚀 Quick Start
Python API
from topoconscious import TopoConsciousPipeline
pipe = TopoConsciousPipeline(
bids_dir="data/ds002345",
output_dir="results/",
window_size=30, # TRs per window
step=5, # TR step between windows
n_landmarks=200, # MaxMin landmark count
max_homology_dim=2, # Compute H0, H1, H2
tr=2.0, # Repetition time (seconds)
atlas="aal", # aal | schaefer100 | destrieux
use_gpu=False,
)
results = pipe.run()
# results["sub-01"]["hmm"]["p_conscious"] → array of shape (n_windows,)
Command Line Interface
topoconscious \
--bids-dir data/ds002345 \
--output-dir results/ \
--window-size 30 \
--step 5 \
--landmarks 200 \
--atlas aal \
--max-dim 2 \
--tr 2.0 \
--gpu # optional
FastAPI Backend
# Start the REST server
uvicorn backend.app:app --reload --port 8000
# Trigger pipeline run
curl -X POST http://localhost:8000/run
🔭 Key Innovations
1. Müller-Lyer Current Metric
Standard Wasserstein distance is permutation-invariant but loses information about where features live in the birth-death plane. The Müller-Lyer current adds:
ML(D₁, D₂) = W₂ᵖᵉʳˢ⁻ʷᵉⁱᵍʰᵗᵉᵈ(D₁, D₂)
+ α · |Σpers(D₁) − Σpers(D₂)| ← scale penalty
+ β · ‖centroid(D₁) − centroid(D₂)‖ ← location penalty
This makes transitions between many short loops (unconscious) and few long loops (conscious) maximally discriminative.
2. Persistence Landscape (Landscape Current)
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:
from topoconscious.metrics import PersistenceLandscape
pl = PersistenceLandscape(n_landscapes=5, resolution=100)
vec = pl.vectorize(diagram) # (500,) feature vector
dist = pl.distance(dgm1, dgm2) # L² landscape distance
3. Topological Transfer Entropy (C++/OpenMP)
Directional information flow between brain regions' H₁ persistence time series, parallelised across all O(n²) region pairs:
TE(X→Y) = H(Yₜ | Yₜ₋₁) − H(Yₜ | Yₜ₋₁, Xₜ₋₁)
The C++ extension computes the full 90×90 matrix in milliseconds vs. minutes in Python.
4. Full Cycle Localization
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.
📊 Validation
Three public datasets target the success criterion of AUC > 0.90 (vs. static FC baseline ~0.75):
| Dataset | Condition | Source |
|---|---|---|
| Propofol | Awake vs. anaesthesia | MIT/Tufts (OpenNeuro ds002898) |
| Sleep | REM vs. NREM | OpenNeuro ds000201 |
| Disorders of Consciousness | MCS vs. UWS | Liège dataset |
from topoconscious.validation import ValidationRunner
runner = ValidationRunner(output_dir="results/validation")
results = runner.evaluate_dataset(ts_list, labels, "propofol")
# results["auc_topo"] → e.g. 0.94
# results["auc_fc"] → e.g. 0.76
runner.plot_roc_curves(results)
📓 Notebooks
| Notebook | Description |
|---|---|
01_demo_pipeline.ipynb |
End-to-end run on synthetic 300-volume fMRI data |
02_widget_explorer.ipynb |
Interactive ipywidgets scrubber for persistence diagrams |
03_validation_roc.ipynb |
ROC/AUC evaluation with synthetic labelled datasets |
04_real_bids_data.ipynb |
Full walkthrough: DataLad download → BIDS → results |
🧪 Tests
# Run full test suite
pytest tests/ -v
# Run specific module tests
pytest tests/test_topology.py -v
pytest tests/test_metrics.py -v # includes ValidationRunner smoke test
pytest tests/test_transfer_entropy.py -v
Test coverage:
test_topology.py— landmark sampling, diagram shapes, Wasserstein timelinetest_hmm.py— fit/decode shapes, p_conscious bounds, score() after fittest_transfer_entropy.py— matrix shape, diagonal=0, non-negativitytest_metrics.py— ML current correctness, self-distance=0, ValidationRunner
📁 Project Structure
TopoConscious/
├── topoconscious/
│ ├── __init__.py # Package exports
│ ├── pipeline.py # Main orchestrator
│ ├── preprocessing.py # NIfTI/BIDS loader, atlas parcellation
│ ├── topology.py # PersistenceEngine (GUDHI + Ripser)
│ ├── hmm.py # TopologicalHMM (Gaussian, 2-state)
│ ├── transfer_entropy.py # TopologicalTransferEntropy
│ ├── localization.py # CycleLocalizer (GUDHI SimplexTree)
│ ├── visualization.py # TopoVisualizer (matplotlib + ipywidgets)
│ ├── metrics.py # MuellerLyerCurrent + PersistenceLandscape
│ ├── validation.py # ValidationRunner (ROC/AUC)
│ ├── run_pipeline.py # Convenience entry script
│ └── ext/
│ └── topo_te.cpp # C++17/OpenMP transfer entropy extension
├── backend/
│ └── app.py # FastAPI REST endpoint (POST /run)
├── notebooks/
│ ├── 01_demo_pipeline.ipynb
│ ├── 02_widget_explorer.ipynb
│ ├── 03_validation_roc.ipynb
│ └── 04_real_bids_data.ipynb
├── tests/
│ ├── conftest.py # Shared session-scoped fixtures
│ ├── test_topology.py
│ ├── test_hmm.py
│ ├── test_transfer_entropy.py
│ └── test_metrics.py
├── data/ # Place BIDS datasets here
├── results/ # Pipeline outputs written here
├── CITATION.cff # Academic citation metadata
├── LICENSE # Apache 2.0
├── requirements.txt
└── setup.py
⚙️ Configuration Reference
| Parameter | Default | Description |
|---|---|---|
bids_dir |
— | Path to BIDS dataset root |
output_dir |
— | Where results are written |
window_size |
30 |
TRs per sliding window |
step |
5 |
TR step between windows |
n_landmarks |
200 |
MaxMin landmark count |
max_homology_dim |
2 |
Max homology dim (0=H₀, 1=H₁, 2=H₂) |
tr |
2.0 |
Repetition time in seconds |
atlas |
aal |
aal / schaefer100 / destrieux |
use_gpu |
False |
Use cupy-accelerated Ripser |
📖 References
- Edelsbrunner, H. & Harer, J. (2010). Computational Topology: An Introduction. AMS.
- Bauer, U. (2021). Ripser: efficient computation of Vietoris-Rips persistence barcodes. J. Applied & Computational Topology.
- Divol, V. & Lacombe, T. (2021). Understanding topology and geometry of persistence diagrams via optimal partial transport. J. Applied & Computational Topology.
- Bubenik, P. (2015). Statistical topological data analysis using persistence landscapes. JMLR 16.
- GUDHI Project. Geometry Understanding in Higher Dimensions. https://gudhi.inria.fr
- Schreiber, T. (2000). Measuring information transfer. Physical Review Letters 85(2).
📄 Citation
If you use TopoConscious in your research, please cite:
@software{topoconscious2026,
title = {TopoConscious: Persistent Homology Pipeline for Neural Correlates of Consciousness},
author = {Chege, N.},
year = {2026},
version = {0.1.0},
license = {Apache-2.0},
url = {https://github.com/Chege-N/TopoConscious}
}
🤝 Contributing
Pull requests are welcome. For major changes please open an issue first.
# Run tests before submitting
pytest tests/ -v
# Check code style
flake8 topoconscious/ --max-line-length=100
📜 License
Apache License 2.0 — see LICENSE for details.
Metadata
Release files for topoconscious 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| topoconscious-0.1.10.tar.gz | 35.5 kB | Details |
Built distributions (wheels)
Total release size: 1.5 MB
Release files / topoconscious-0.1.10.tar.gz
| Download URL | topoconscious-0.1.10.tar.gz |
|---|---|
| Size | 35.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0d8248409c7f3f7d8a3d0f757ea1c29e005f3f46cd4ee9702ad77f0eb1d078d
|
|
BLAKE2b-256 checksum How to use checksums |
8ee31956004b44b93aaf4f43657c020dca24f8e78980f115182b22aca7a9374d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 215.6 kB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
76ae996dd42d6465400ebbbf442dd97953da45bb5c185887a32e50cd6d8793ac
|
|
BLAKE2b-256 checksum How to use checksums |
49cbea656aeee6d7b19ee8856c1b2364e089a3fd1b3edd7a42e0fc2d7ef2c4fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 214.2 kB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8d668fcb158d0a1c0a28c759bcc7d3f7526327b5e1a777f85317c70ef080e2ab
|
|
BLAKE2b-256 checksum How to use checksums |
422be04a575743194ddd71a14a6e2d3025cf3236f2ce7511a81d67cad6ca42eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 214.1 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
a53ab8f58ee86e21da1b25673d347eb3a522f182f51c3e4605681201edb54f33
|
|
BLAKE2b-256 checksum How to use checksums |
439bb2839bbc7e7988d914d5eea2f3d1e7af46be400819c0d5af12546f6aeee8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 214.0 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b160ac5a5dcede7676ff3901b992a8875a2a5ef925e8e0d0c0ab9cb62d2eef8b
|
|
BLAKE2b-256 checksum How to use checksums |
160bbe7587943592f73ddec594b58f89955a5426c6a698c8aae98c7e6925f41c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 213.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
a54c1a30dfdd233560cd3ffbe8ecd0f445768384b313c819d0e38022329cd623
|
|
BLAKE2b-256 checksum How to use checksums |
a1d1ae79834cd63bf507a22bb7516bc271ac9e00c24025855303f5a22f2f9d0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 211.8 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e101ddd1b48c25a352643da4bf40a4535e9ac0fcf5e3e534edc3f1887c6610d4
|
|
BLAKE2b-256 checksum How to use checksums |
e638e7e0956e06f86af88337ae001e2ca73a3ea127798f3880294b3007324eba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency logRelease files / topoconscious-0.1.10-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | topoconscious-0.1.10-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 211.6 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e890007bf4917fb47fd5c12e221da33aa07dff71d65674930a56db51f87e19e4
|
|
BLAKE2b-256 checksum How to use checksums |
9713d47779a7a508261f7470418903e445c3609802bbf45598caf5144b91fee9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 10, 2026.
Transparency log