Skip to main content

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

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 data
  • example_param_exploration.py — parameter sweeps with the standalone NumPy simulator
  • example_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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neurofe-0.1.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neurofe-0.1.0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file neurofe-0.1.0.tar.gz.

File metadata

  • Download URL: neurofe-0.1.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for neurofe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 255e4bd508d27513f2758d3221685d17c37ca38a687f3ede4d0b149ff72c953c
MD5 1246e1a4f2c97607e7efde13dd994065
BLAKE2b-256 e67bfb1da293d8e5b6c5dbab71405140dcae53180666200c9415637b5259a950

See more details on using hashes here.

File details

Details for the file neurofe-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: neurofe-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for neurofe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9caf8c362cc417cc8dde5a7fe32fd04ca4761ac3bd46e5eebbbce1b64523ec63
MD5 90dd1d80c9b7af7792c1ef7a208c48a6
BLAKE2b-256 d09e4cd1bea814ba2382216017b49b1ed6fdabf0e0edcbda5a4c81de211633b7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page