neurofe
Fit neural mass models to empirical TMS-EEG data using gradient-based optimization.
Based on: Momi et al. (2022) Stimulation mapping and whole-brain modeling reveal gradients of excitability and recurrence in cortical networks.
Features
- Jansen-Rit neural mass model — full PyTorch implementation with conduction delays, structural connectivity, and leadfield projection
- Gradient-based fitting — fit model parameters to empirical TMS-EEG data using Adam optimizer with Bayesian priors
- Virtual dissection — lesion brain regions and observe the effect on simulated EEG
- Wong-Wang-Deco model — parameter framework defined (forward model contributions welcome)
- Standalone NumPy simulator — lightweight Jansen-Rit simulator for parameter exploration
Installation
pip install neurofe
From source:
git clone https://github.com/neurofe/neurofe.git
cd neurofe
pip install -e .
With optional dependencies:
pip install -e ".[examples]" # matplotlib, pandas for running examples
pip install -e ".[viz]" # mne, nibabel, etc. for brain surface visualization
pip install -e ".[dev]" # pytest for development
Quick start
import numpy as np
import neurofe
# Load your data as numpy arrays
sc = np.load("sc.npy") # (n_regions, n_regions) structural connectivity
lm = np.load("leadfield.npy") # (n_channels, n_regions) leadfield matrix
dist = np.load("dist.npy") # (n_regions, n_regions) distance matrix
eeg = np.load("eeg.npy") # (n_channels, n_timepoints) empirical EEG
# Create and fit the model
model = neurofe.JansenRit(sc=sc, leadfield=lm, dist=dist)
result = model.fit(eeg, epochs=120)
result = model.predict(eeg)
# Access results
result.eeg_test # simulated EEG
result.E_test # excitatory activity
result.I_test # inhibitory activity
result.loss # training loss history
Virtual dissection
Lesion specific brain regions and observe the effect on simulated EEG:
# Lesion nodes 5 and 10 — returns a new model, original is unchanged
lesioned_model = model.lesion(nodes=[5, 10])
result_lesioned = lesioned_model.predict(eeg)
Documentation
- Getting Started — installation, input data, and quick start
- Models — model API, parameters, and loss functions
- Virtual Dissection — lesion API, usage patterns, and interpretation
- Examples — walkthrough of all example scripts
Examples
See the examples/ directory:
example_synthetic_data.py— full pipeline with randomly generated data (no real data needed)example_train_jr.py— training on empirical TMS-EEG dataexample_param_exploration.py— parameter sweeps with the standalone NumPy simulatorexample_goodness_of_fit.py— evaluating model fit quality
Citation
If you use neurofe in your research, please cite:
@article{momi2022stimulation,
title={Stimulation mapping and whole-brain modeling reveal gradients of excitability and recurrence in cortical networks},
author={Momi, Davide and others},
journal={Nature Communications},
year={2022}
}
License
MIT. See LICENSE.
Metadata
Release files for neurofe 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neurofe-0.1.0.tar.gz | 23.3 kB | Without provenance | Details for neurofe-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neurofe-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for neurofe-0.1.0-py3-none-any.whl |
Total release size: 49.3 kB
Release files / neurofe-0.1.0.tar.gz
| Download URL | neurofe-0.1.0.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
255e4bd508d27513f2758d3221685d17c37ca38a687f3ede4d0b149ff72c953c
|
|
BLAKE2b-256 checksum How to use checksums |
e67bfb1da293d8e5b6c5dbab71405140dcae53180666200c9415637b5259a950
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / neurofe-0.1.0-py3-none-any.whl
| Download URL | neurofe-0.1.0-py3-none-any.whl |
|---|---|
| Size | 26.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9caf8c362cc417cc8dde5a7fe32fd04ca4761ac3bd46e5eebbbce1b64523ec63
|
|
BLAKE2b-256 checksum How to use checksums |
d09e4cd1bea814ba2382216017b49b1ed6fdabf0e0edcbda5a4c81de211633b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for neurofe 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.