The Brain Activity Flow ("Actflow") Toolbox

Version 0.2.6 (beta)

View on GitHub


This toolbox facilitates linking brain connectivity with task-evoked activity and associated cognitive/behavioral functions. The primary focus is on activity flow mapping and related methods (Cole et al. (2016) & Ito et al. (2017)).

Activity flow mapping is based on core principles underlying brain network simulations, applying these principles to empirical neural/neuroimaging data. The core theoretical construct is that of activity flow — the movement of activity between neurons/neural populations. Activity flow mapping is a highly flexible framework that is constantly being improved via better connectivity methods and creative uses of the approach to better understand brain function.

Activity flow mapping can be used, for instance, to infer whether one or more brain connections are involved in producing a particular function. This method can also be used to relate multiple task-evoked activations to each other (e.g., predicting one neural population's activity from another's activity). More generally, activity flow mapping can be thought of as creating network coding models (Ito et al. (2020)), which are empirically-constrained neural network models.

Other methods included in the toolbox (which can optionally be used along with activity flow mapping) are advanced versions of resting-state functional connectivity and task-state functional connectivity. The primary focus (for now) is on fMRI data, but in principle these approaches can be applied to any kind of neural data.

This code repository was created by the Cole Neurocognition Lab at Rutgers University:
We are happy for others to contribute to the code as well.

See the example notebook to see the Actflow Toolbox in action
We provide 30 subjects' data from the Human Connectome Project for trying out the toolbox

Core algorithm and principles behind activity flow mapping

Activity flow mapping is a method validated and published in Nature Neuroscience in 2016 (see Cole et al. (2016)), with multiple follow-up studies further validating the approach.

Activity flow mapping has two basic steps:

1) Activity flow modeling: Simulating the flow (movement) of activity between neural populations, using empirical data to estimate activity levels and routes of flow (connectivity). This is done by running the standard "propagation rule" and "activation rule" steps used in most neural network simulations (see Ito et al. (2020)). In the standard approach each neural population's activity level is predicted based on the flow from every other recorded neural population (from Cole et al. (2016)):

2) Testing prediction accuracy: The predicted brain activity pattern is compared to the actual recorded activity, providing evidence for or against the activity flow model used to make the predictions. Predictions of multiple models can be compared to quantify model validity. Two examples of predicted-to-actual accuracy testing with fMRI data (from Cole et al. (2016)):

In principle, any measure of neural activity and any measure of neural connectivity (e.g., structural connectivity) can be used with activity flow mapping. Some modifications are necessary for fast temporal resolution data such as EEG/MEG or multi-unit recording, but these should be available soon (we are working on it!).

More background info on activity flow mapping can be found on an FAQ about the Cole et al. (2016) paper

Included connectivity mapping methods


Cite as:

  1. Cole MW, Ito T, Bassett DS, Schultz DH (2016). "Activity flow over resting-state networks shapes cognitive task activations". Nature Neuroscience. 19:1718–1726.
  3. and
  4. The article that describes the specific toolbox functions being used in most detail

How to install

git clone --recurse-submodules

Email list/forum

We strongly encourage you to join the ColeNeuroLab Users Group (!forum/coleneurolab_users), so you can be informed about major updates in this repository and others hosted by the Cole Neurocognition Lab.



A Jupyter Notebook with example analyses (and example data) is viewable here: HCP_example.ipynb

Example of calculating activity flow mapping predictions using multiple-regression FC and standard task-evoked activations with fMRI data (in Python 3; assumes task activations and resting-state fMRI data are already loaded):

import ActflowToolbox as actflow
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

for scount in np.arange(np.shape(restdata)[2]):

print("==Activity flow mapping results, multiple-regression-based resting-state FC, 24 task conditions==")
actflowOutput_restFCMReg_bycond = actflow.actflowcomp.actflowtest(activations_bycond, restFC_mreg)


==Activity flow mapping results, multiple-regression-based resting-state FC, 24 task conditions==
===Comparing prediction accuracies between models (similarity between predicted and actual brain activation patterns)===

==Comparisons between predicted and actual activation patterns, across all conditions and nodes:==
--Compare-then-average (calculating prediction accuracies before cross-subject averaging):
Each comparison based on 24 conditions across 360 nodes, p-values based on 30 subjects (cross-subject variance in comparisons)

Mean Pearson r = 0.78, t-value vs. 0: 62.27, p-value vs. 0: 1.9635597302245892e-32

Mean % variance explained (R^2 score, coeff. of determination) = 0.57

Mean MAE (mean absolute error) = 7.54

Note: Pearson r and Pearson r^2 are scale-invariant, while R^2 and MAE are not. R^2 units: percentage of the to-be-predicted data's unscaled variance, ranging from negative infinity (because prediction errors can be arbitrarily large) to positive 1. See for more info.

Visualizing the results:

#Visualize predicted and actual activation patterns, with multiple-regression FC
ax = sns.heatmap(np.mean(actflowOutput_restFCMReg_bycond['actPredVector_bytask_bysubj'],axis=2)[netorder,:],center=0,cmap='seismic',cbar=True,yticklabels=100,xticklabels=taskConditions)
ax.figure.suptitle('Predicted activations, multreg FC actflow')

ax = sns.heatmap(np.mean(activations_bycond,axis=2)[netorder,:],center=0,cmap='seismic',cbar=True,yticklabels=100,xticklabels=taskConditions)
ax.figure.suptitle('Actual activations (24 conditions)')


General guidelines for activity flow mapping

Software development guidelines

Publications that have used activity flow mapping and/or this toolbox

Using resting-state fMRI

Using task-state fMRI (often in addition to resting-state fMRI)

Using structural connectivity (diffusion MRI)

Using electroencephalography (EEG) or magnetoencephalography (MEG)