SkillAgentSearch skills...

Neurolib

Easy whole-brain modeling for computational neuroscientists πŸ§ πŸ’»πŸ‘©πŸΏβ€πŸ”¬

Install / Use

/learn @neurolib-dev/Neurolib

README

<p align="center"> <img alt="Header image of neurolib - A Python simulation framework for easy whole-brain neural mass modeling." src="https://github.com/neurolib-dev/neurolib/raw/master/resources/readme_header.png" > </p> <p align="center"> <a href="https://github.com/neurolib-dev/neurolib/actions"> <img alt="Build" src="https://img.shields.io/github/workflow/status/neurolib-dev/neurolib/ci"></a> <a href="https://zenodo.org/badge/latestdoi/236208651"> <img alt="DOI" src="https://zenodo.org/badge/236208651.svg"></a> <a href="https://link.springer.com/article/10.1007%2Fs12559-021-09931-9"> <img alt="paper" src="https://img.shields.io/badge/DOI-10.1007%2Fs12559--021--09931--9-blue"></a> <a href="https://github.com/neurolib-dev/neurolib/releases"> <img alt="Release" src="https://img.shields.io/github/v/release/neurolib-dev/neurolib"></a> <br> <a href="https://codecov.io/gh/neurolib-dev/neurolib"> <img alt="codecov" src="https://codecov.io/gh/neurolib-dev/neurolib/branch/master/graph/badge.svg"></a> <a href="https://pepy.tech/project/neurolib"> <img alt="Downloads" src="https://pepy.tech/badge/neurolib"></a> <a href="https://github.com/psf/black"> <img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a> <a href="https://mybinder.org/v2/gh/neurolib-dev/neurolib.git/master?filepath=examples"> <img alt="Launch in binder" src="https://mybinder.org/badge_logo.svg"></a> </p> <!--include-in-documentation-->

What is neurolib?

neurolib is a simulation and optimization framework for whole-brain modeling. It allows you to implement your own neural mass models which can simulate fMRI BOLD activity. neurolib helps you to analyse your simulations, to load and handle structural and functional brain data, and to use powerful evolutionary algorithms to tune your model's parameters and fit it to empirical data.

You can chose from different neural mass models to simulate the activity of each brain area. The main implementation is a mean-field model of spiking adaptive exponential integrate-and-fire neurons (AdEx) called ALNModel where each brain area contains two populations of excitatory and inhibitory neurons. An analysis and validation of the ALNModel model can be found in our paper.

πŸ“š Please read the gentle introduction to neurolib for an overview of the basic functionality and the science behind whole-brain simulations or read the documentation for getting started.

To browse the source code of neurolib visit out GitHub repository.

πŸ“ <a href="#how-to-cite">Cite</a> the following paper if you use neurolib for your own research:

Cakan, C., Jajcay, N. & Obermayer, K. neurolib: A Simulation Framework for Whole-Brain Neural Mass Modeling. Cogn. Comput. (2021).

The figure below shows a schematic of how a brain network is constructed:

<p align="center"> <img src="https://github.com/neurolib-dev/neurolib/raw/master/resources/pipeline.jpg"> </p> <p align="center"> Examples: <a href="#single-node">Single node simulation</a> Β· <a href="#whole-brain-network">Whole-brain network</a> Β· <a href="#parameter-exploration">Parameter exploration</a> Β· <a href="#evolutionary-optimization">Evolutionary optimization</a> <br><br> </p>

Whole-brain modeling

Typically, in whole-brain modeling, diffusion tensor imaging (DTI) is used to infer the structural connectivity (the connection strengths) between different brain areas. In a DTI scan, the direction of the diffusion of molecules is measured across the whole brain. Using tractography, this information can yield the distribution of axonal fibers in the brain that connect distant brain areas, called the connectome. Together with an atlas that divides the brain into distinct areas, a matrix can be computed that encodes how many fibers go from one area to another, the so-called structural connectivity (SC) matrix. This matrix defines the coupling strengths between brain areas and acts as an adjacency matrix of the brain network. The fiber length determines the signal transmission delay between all brain areas. Combining the structural data with a computational model of the neuronal activity of each brain area, we can create a dynamical model of the whole brain.

The resulting whole-brain model consists of interconnected brain areas, with each brain area having their internal neural dynamics. The neural activity can also be used to simulate hemodynamic BOLD activity using the Balloon-Windkessel model, which can be compared to empirical fMRI data. Often, BOLD activity is used to compute correlations of activity between brain areas, the so called resting state functional connectivity, resulting in a matrix with correlations between each brain area. This matrix can then be fitted to empirical fMRI recordings of the resting-state activity of the brain.

Below is an animation of the neuronal activity of a whole-brain model plotted on a brain.

<p align="center"> <img src="https://github.com/neurolib-dev/neurolib/raw/master/resources/brain_slow_waves_small.gif"> </p>

Installation

The easiest way to get going is to install the pypi package using pip:

pip install neurolib

Alternatively, you can also clone this repository and install all dependencies with

git clone https://github.com/neurolib-dev/neurolib.git
cd neurolib/
pip install -r requirements.txt
pip install .

It is recommended to clone or fork the entire repository since it will also include all examples and tests.

Project layout

neurolib/	 				# Main module
β”œβ”€β”€ models/ 					# Neural mass models
	β”œβ”€β”€model.py 				# Base model class
	└── /.../ 				# Implemented mass models
β”œβ”€β”€ optimize/ 					# Optimization submodule
	β”œβ”€β”€ evolution/ 				# Evolutionary optimization
	└── exploration/ 			# Parameter exploration
β”œβ”€β”€ control/optimal_control/			# Optimal control submodule
	β”œβ”€β”€ oc.py 				# Optimal control base class
	β”œβ”€β”€ cost_functions.py 			# cost functions for OC
	β”œβ”€β”€ /.../ 				# Implemented OC models
β”œβ”€β”€ data/ 					# Empirical datasets (structural, functional)
β”œβ”€β”€ utils/					# Utility belt
	β”œβ”€β”€ atlases.py				# Atlases (Region names, coordinates)
	β”œβ”€β”€ collections.py			# Custom data types
	β”œβ”€β”€ functions.py 			# Useful functions
	β”œβ”€β”€ loadData.py				# Dataset loader
	β”œβ”€β”€ parameterSpace.py			# Parameter space
	β”œβ”€β”€ saver.py 				# Save simulation outputs
	β”œβ”€β”€ signal.py				# Signal processing functions
	└── stimulus.py 			# Stimulus construction
β”œβ”€β”€ examples/					# Example Jupyter notebooks
β”œβ”€β”€ docs/					# Documentation 
└── tests/					# Automated tests

Examples

Example IPython Notebooks on how to use the library can be found in the ./examples/ directory, don't forget to check them out! You can run the examples in your browser using Binder by clicking here or one of the following links:

  • Example 0.0 - Basic use of the aln model
  • Example 0.3 - Fitz-Hugh Nagumo model fhn on a brain network
  • Example 0.6 - Minimal example of how to implement your own model in neurolib
  • Example 1.2 - Parameter exploration of a brain network and fitting to BOLD data
  • Example 2.0 - A simple example of the evolutionary optimization framework
  • Example 5.2 - Example of optimal control of the noise-free Wilson-Cowan model

A basic overview of the functionality of neurolib is also given in the following.

Single node

This example is available in detail as a IPython Notebook.

To create a single aln model with the default parameters, simply run

from neurolib.models.aln import ALNModel

model = ALNModel()
model.params['sigma_ou'] = 0.1 # add some noise

model.run()

The results from this small simulation can be plotted easily:

import matplotlib.pyplot as plt
plt.plot(model.t, model.output.T)

<p align="left"> <img src="https://github.com/neurolib-dev/neurolib/raw/master/resources/single_timeseries.png"> </p>

Whole-brain network

A detailed example is available as a IPython Notebook.

To simulate a whole-brain network model, first we need to load a DTI and a resting-state fMRI dataset. neurolib already provides some example data for you:

from neurolib.utils.loadData import Dataset

ds = Dataset("gw")

The dataset that we just loaded, looks like this:

<p align="center"> <img src="https://github.com/neurolib-dev/neurolib/raw/master/resources/gw_data.png"> </p>

We initialize a model with the dataset and run it:

model = ALNModel(Cmat = ds.Cmat, Dmat = ds.Dmat)
model.params['duration'] = 5*60*1000 # in ms, simulates for 5 minutes

model.run(bold=
View on GitHub
GitHub Stars466
CategoryDevelopment
Updated2d ago
Forks93

Languages

Python

Security Score

100/100

Audited on Mar 25, 2026

No findings