Metadata-Version: 2.1
Name: whobrain-bench
Version: 0.3.0
Summary: A community benchmark for whole-brain dynamical inference frameworks from M/EEG
Author: Prejaas Tewarie
Author-email: Victor Oswald <victor.oswald@umontreal.ca>
License: MIT
Project-URL: Homepage, https://github.com/LIKACT/whobrain-bench
Project-URL: Documentation, https://whobrain-bench.readthedocs.io
Project-URL: Issues, https://github.com/LIKACT/whobrain-bench/issues
Keywords: whole-brain,neural mass,EEG,MEG,benchmark,Jansen-Rit,Wilson-Cowan,Stuart-Landau,Wong-Wang,WhoBPyT,VBI,TVB,DCM,HMC
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Provides-Extra: real-data
Provides-Extra: dev
License-File: LICENSE

# WhoBrain-Bench

A community benchmark for identifiability of whole-brain dynamical inference
frameworks from resting-state M/EEG.

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/)

## What it does

WhoBrain-Bench standardises and qualifies the inference of brain-wide
neural-mass parameters from resting-state M/EEG by running **five inference
frameworks** on **five node-model classes** under controlled conditions:

| Frameworks                                                   | Node-model classes                              |
| ------------------------------------------------------------ | ----------------------------------------------- |
| WhoBPyT — Adam + log-PSD + alpha-AEC                         | Jansen-Rit (classical, 3 populations)           |
| Virtual Brain Inference (VBI) — SBI with MDN                 | Jansen-Rit + inhibitory synaptic plasticity     |
| TVB-AD — L-BFGS + spectral coherence                         | Wilson-Cowan (two populations)                  |
| Precision DDM — Adam + autocovariance                        | Stuart-Landau (Hopf normal form)                |
| Hamiltonian Monte Carlo — NUTS over differentiable simulator | Wong-Wang reduced mean-field                    |

DCM (variational Laplace) and MPR (Montbrió-Pazó-Roxin) are also implemented in
the codebase but excluded from the default benchmark (DCM after empirical
evaluation; MPR pending a higher-order integrator).

For each (framework × model × parameter) combination the benchmark reports:

- **parameter recovery** Pearson(truth, estimate) on synthetic ground truth,
- **inter-seed reliability** (ICC(2,1), Shrout–Fleiss),
- **goodness-of-fit** on PSD and alpha-AEC observables,
- **recommendation**: `reliably recoverable / recoverable-but-unstable /
  degenerate / missing`.

Validated across four datasets: a synthetic battery (150 cells, 100% completion),
the full HCP-MEG resting-state release (2,225 cells, n=89 subjects), the ReDLat
source-localised EEG (1,150 cells, n=46 recordings, Latin America), and the
LEMON EEG release (1,250 cells, n=50 recordings, Germany) — **4,775 fits
total** with **100% cross-dataset replication of the alpha-AEC missing-dynamics
gap**.

## Install

```bash
pip install whobrain-bench
# or from source:
git clone https://github.com/LIKACT/whobrain-bench.git
cd whobrain-bench
pip install -e ".[real-data]"   # 'real-data' extra adds MNE + nilearn
```

## Quick CLI

```bash
# What's available
whobrain-bench list

# Is parameter A recoverable in HMC × Jansen-Rit?
whobrain-bench check --framework hmc --model jansen_rit --param A

# How long will my planned inference take?
whobrain-bench feasibility --framework hmc --model wilson_cowan \
    --duration 60 --n-regions 78

# Summary table of any battery output
whobrain-bench report --input outputs/MERGED/all.json
```

The `check` command falls back on **bundled reference results** from the
published benchmark (~4,775 cells from synth + HCP + ReDLat + LEMON) when
`--results` is omitted. Pass `--results path/to/my.json` to query your own benchmark output.

## Python API

```python
import whobrain_bench as wb

# Generate a synthetic scenario with known truth
scenario = wb.Scenario(model_name="jansen_rit",
                       pattern_label="smooth_all",
                       noise_sigma=1.0, duration_s=30.0,
                       n_regions=24)
ground_truth = wb.build_ground_truth(scenario)

# Run any framework on it
fw = wb.get_framework("hmc")(node_model="jansen_rit",
                              n_warmup=200, n_samples=500)
fw.fit(ground_truth.observables,
       sc=ground_truth.sc,
       region_names=ground_truth.region_names)

# Inspect recovery
estimates = fw.get_parameters()
recovery = wb.compute_recovery(ground_truth.truth, estimates)
print(recovery)
```

## Key findings

- **HMC is the strongest framework on classical Jansen-Rit** (r = +0.48),
  partially overcoming the JR+ISP degeneracy that defeats point-estimate
  methods.
- **Wong-Wang is the most recoverable model** across frameworks (Precision DDM
  r = +0.67, WhoBPyT r = +0.58, TVB-AD r = +0.32).
- **Wilson-Cowan `c_ei` is universally anti-correlated** with truth across all
  5 frameworks — an intrinsic property of the inverse problem, not a
  methodology artefact.
- **Alpha-AEC is a missing component** across all 25 (framework × model)
  combinations, replicated on HCP-MEG and ReDLat-EEG — a representation gap
  in current whole-brain models, not a fitting issue.

## Pipeline architecture

```
extended/
├── eeg_benchmark/          # Core library
│   ├── node_models/        # 5 + 1 experimental neural-mass models
│   ├── whobpyt_framework.py, vbi_framework.py, tvb_ad_framework.py,
│   ├── precision_ddm_framework.py, hmc_framework.py, dcm_framework.py
│   ├── observables.py      # PSD, AEC, autocovariance, coherence
│   ├── validation.py       # Battery driver + scenario grid
│   ├── synthetic.py        # Ground-truth generator
│   └── data.py             # HCP / ReDLat / LEMON loaders
├── whobrain_bench/         # Public package + CLI
│   ├── cli.py              # `whobrain-bench {list,check,feasibility,report}`
│   └── data/               # Bundled reference results
├── scripts/                # Runners (synth / HCP / ReDLat / LEMON)
└── slurm/                  # SLURM array jobs for Compute Canada
```

## Citation

If you use WhoBrain-Bench in your research, please cite:

> Oswald V., Tewarie P.K.B. et al. *WhoBrain-Bench: a community benchmark for
> identifiability of whole-brain dynamical inference from resting-state M/EEG*.
> [in preparation]

A machine-readable citation is in [`CITATION.cff`](CITATION.cff).

## Acknowledgements

This work used resources from:
- the Digital Research Alliance of Canada (Narval cluster)
- the OHBA Analysis Group for the HCP-MEG virtual-electrode pipeline
  ([Colclough et al. 2016](https://doi.org/10.1016/j.neuroimage.2016.06.002))
- the Coronel-Oliveros et al. 2026 ReDLat EEG release

## License

MIT — see [LICENSE](LICENSE).
