"* Build a brain network model using subject-specific structural connectivity,\n",
"* Build a brain network model using subject-specific structural connectivity,\n",
"* Simulate resting-state activity,\n",
"* Simulate resting-state activity,\n",
"* Characterize the resting-state activity by calculating the functional connectivity (FC),\n",
"* Characterize the resting-state activity by calculating the functional connectivity (FC)."
"* Extract the resting-state networks (RSNs)."
]
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "329f9428",
"id": "48605a2c",
"metadata": {},
"metadata": {},
"source": [
"source": [
"# How to do it with TVB?\n",
"# How to do it with TVB?\n",
...
@@ -71,7 +70,7 @@
...
@@ -71,7 +70,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2,
"execution_count": 2,
"id": "bac045da",
"id": "48088d0e",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -89,7 +88,7 @@
...
@@ -89,7 +88,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "8dd86a7b",
"id": "1a410d7a",
"metadata": {},
"metadata": {},
"source": [
"source": [
"A basic simulation of TVB consists of **5 main components**. Each of these components is an object within TVB:"
"A basic simulation of TVB consists of **5 main components**. Each of these components is an object within TVB:"
...
@@ -97,7 +96,7 @@
...
@@ -97,7 +96,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "ec330e11",
"id": "ae302f73",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### Connectivity\n",
"### Connectivity\n",
...
@@ -109,7 +108,7 @@
...
@@ -109,7 +108,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 3,
"execution_count": 3,
"id": "6c563ce4",
"id": "710d21e4",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -124,7 +123,7 @@
...
@@ -124,7 +123,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "229ebbef",
"id": "de6dafab",
"metadata": {},
"metadata": {},
"source": [
"source": [
"*Take a look at some of the properties of the `conn` object: `weights`, `delays`, `region_labels`, etc.*"
"*Take a look at some of the properties of the `conn` object: `weights`, `delays`, `region_labels`, etc.*"
...
@@ -133,7 +132,7 @@
...
@@ -133,7 +132,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 4,
"execution_count": 4,
"id": "8e7e9be7",
"id": "a301f70b",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -174,7 +173,7 @@
...
@@ -174,7 +173,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 5,
"execution_count": 5,
"id": "04438045",
"id": "c82cd475",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -196,7 +195,7 @@
...
@@ -196,7 +195,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "ae6af06e",
"id": "e4d3660a",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### Model"
"### Model"
...
@@ -204,7 +203,7 @@
...
@@ -204,7 +203,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "96407494",
"id": "0adf2b72",
"metadata": {},
"metadata": {},
"source": [
"source": [
"A set of differential equations describing the local neural dynamics. There are a number of predefined models available in TVB, as an example here we will use the **Generic 2-dimensional Oscillator** model:\n",
"A set of differential equations describing the local neural dynamics. There are a number of predefined models available in TVB, as an example here we will use the **Generic 2-dimensional Oscillator** model:\n",
...
@@ -217,7 +216,7 @@
...
@@ -217,7 +216,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "431f293c",
"id": "e3f828d7",
"metadata": {},
"metadata": {},
"source": [
"source": [
"We can explore it using the **phase-plane** tool in TVB."
"We can explore it using the **phase-plane** tool in TVB."
...
@@ -226,7 +225,7 @@
...
@@ -226,7 +225,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 6,
"execution_count": 6,
"id": "4ccbd26b",
"id": "a7ae0fec",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -270,7 +269,7 @@
...
@@ -270,7 +269,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "f806ac21",
"id": "9e915bee",
"metadata": {},
"metadata": {},
"source": [
"source": [
"For our simulation we set it to the limit-cycle regime."
"For our simulation we set it to the limit-cycle regime."
...
@@ -278,7 +277,7 @@
...
@@ -278,7 +277,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "2174002c",
"id": "939696ba",
"metadata": {},
"metadata": {},
"source": [
"source": [
"*Note that the parameters of the `Model` class has to be set as numpy arrays.*"
"*Note that the parameters of the `Model` class has to be set as numpy arrays.*"
...
@@ -287,7 +286,7 @@
...
@@ -287,7 +286,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 7,
"execution_count": 7,
"id": "2950caad",
"id": "1b8ffc60",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -357,7 +356,7 @@
...
@@ -357,7 +356,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "c4d3b0d1",
"id": "5045a18b",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### Coupling function\n",
"### Coupling function\n",
...
@@ -368,7 +367,7 @@
...
@@ -368,7 +367,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 8,
"execution_count": 8,
"id": "966e422c",
"id": "27292c27",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -379,7 +378,7 @@
...
@@ -379,7 +378,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "8a0e4549",
"id": "d491e8c4",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### Integrator\n",
"### Integrator\n",
...
@@ -392,7 +391,7 @@
...
@@ -392,7 +391,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 9,
"execution_count": 9,
"id": "57e730bc",
"id": "8b205225",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -410,7 +409,7 @@
...
@@ -410,7 +409,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "83b1f05a",
"id": "23c2a35c",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### Monitors\n",
"### Monitors\n",
...
@@ -426,7 +425,7 @@
...
@@ -426,7 +425,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 10,
"execution_count": 10,
"id": "a2512904",
"id": "66d578cd",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -440,7 +439,7 @@
...
@@ -440,7 +439,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "f15d3c85",
"id": "e3f3da9b",
"metadata": {},
"metadata": {},
"source": [
"source": [
"*** "
"*** "
...
@@ -448,7 +447,7 @@
...
@@ -448,7 +447,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "818487e4",
"id": "1a20a9a7",
"metadata": {},
"metadata": {},
"source": [
"source": [
"### Go! Simulate\n",
"### Go! Simulate\n",
...
@@ -459,7 +458,7 @@
...
@@ -459,7 +458,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 11,
"execution_count": 11,
"id": "0a98d0ab",
"id": "95deeaa2",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -506,7 +505,7 @@
...
@@ -506,7 +505,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "7f418030",
"id": "4b408895",
"metadata": {},
"metadata": {},
"source": [
"source": [
"Now, we can run the simulation. All we need to do is iterate for some length, which we provide in *ms*, and collect the output. \n",
"Now, we can run the simulation. All we need to do is iterate for some length, which we provide in *ms*, and collect the output. \n",
"**Functional Connectivity (FC)** describes the connectedness of two brain regions by means of the covariance between their time series. The classic and most widely used method to infer the strength of network interactions or functional connections consists in estimating the linear (Pearson) correlation coefficient between temporal signals. If two regions activate and deactivate at the same time, there is likely a functional connection. \n",
"**Functional Connectivity (FC)** describes the connectedness of two brain regions by means of the covariance between their time series. The classic and most widely used method to infer the strength of network interactions or functional connections consists in estimating the linear (Pearson) correlation coefficient between temporal signals. If two regions activate and deactivate at the same time, there is likely a functional connection. \n",
...
@@ -710,7 +709,7 @@
...
@@ -710,7 +709,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 17,
"execution_count": 17,
"id": "24706c44",
"id": "3e7ecaf9",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -719,7 +718,7 @@
...
@@ -719,7 +718,7 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "2412634a",
"id": "76165909",
"metadata": {},
"metadata": {},
"source": [
"source": [
"And now we display the resulting FC matrix:"
"And now we display the resulting FC matrix:"
...
@@ -728,7 +727,7 @@
...
@@ -728,7 +727,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 18,
"execution_count": 18,
"id": "1c4d17b3",
"id": "6220213a",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -759,10 +758,14 @@
...
@@ -759,10 +758,14 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "b3811ffc",
"id": "2189b99b",
"metadata": {},
"metadata": {},
"source": [
"source": [
"# What is next?"
"# What is next?\n",
"\n",
"* take a look at the BOLD monitor\n",
"* introduce external stimulus\n",
"* epilepsy use case"
]
]
}
}
],
],
...
...
%% Cell type:code id:ec97e74a tags:
%% Cell type:code id:68ccd22b tags:
``` python
``` python
%load_ext autoreload
%load_ext autoreload
%autoreload 2
%autoreload 2
```
```
%% Cell type:markdown id:e8fd8f47 tags:
%% Cell type:markdown id:e5a89d1a tags:
# First steps using TVB
# First steps using TVB
**Summer School in Nonlinear Dynamics for the Life Sciences with Applications to Neuroscience and Psychology May 31-June 11, 2021**
**Summer School in Nonlinear Dynamics for the Life Sciences with Applications to Neuroscience and Psychology May 31-June 11, 2021**
%% Cell type:markdown id:3f6bc59a tags:
%% Cell type:markdown id:c669ec16 tags:
# Brain network modeling with TVB
# Brain network modeling with TVB
***
***
Components to be covered
Components to be covered
* node dynamics
* node dynamics
* connectivity
* connectivity
* coupling functions
* coupling functions
* monitors
* monitors
* integrator
* integrator
* stimulus
* stimulus
%% Cell type:markdown id:dfe4517d tags:
%% Cell type:markdown id:727cf9bf tags:
# Objectives
# Objectives
Here we:
Here we:
* Build a brain network model using subject-specific structural connectivity,
* Build a brain network model using subject-specific structural connectivity,
* Simulate resting-state activity,
* Simulate resting-state activity,
* Characterize the resting-state activity by calculating the functional connectivity (FC),
* Characterize the resting-state activity by calculating the functional connectivity (FC).
* Extract the resting-state networks (RSNs).
%% Cell type:markdown id:329f9428 tags:
%% Cell type:markdown id:48605a2c tags:
# How to do it with TVB?
# How to do it with TVB?
***
***
In the first part of this tutorial, we presents the basic anatomy of a region simulation using The Virtual Brain's scripting interface.
In the first part of this tutorial, we presents the basic anatomy of a region simulation using The Virtual Brain's scripting interface.
The first thing we want to do is to import the modules we will need for a simulation.
The first thing we want to do is to import the modules we will need for a simulation.
%% Cell type:code id:bac045da tags:
%% Cell type:code id:48088d0e tags:
``` python
``` python
%%capture
%%capture
import os
import os
import time as tm
import time as tm
import numpy as np
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
from tvb.simulator.lab import *
from tvb.simulator.lab import *
from utils import plot_connectivity
from utils import plot_connectivity
from phase_plane import phase_plane_interactive
from phase_plane import phase_plane_interactive
```
```
%% Cell type:markdown id:8dd86a7b tags:
%% Cell type:markdown id:1a410d7a tags:
A basic simulation of TVB consists of **5 main components**. Each of these components is an object within TVB:
A basic simulation of TVB consists of **5 main components**. Each of these components is an object within TVB:
%% Cell type:markdown id:ec330e11 tags:
%% Cell type:markdown id:ae302f73 tags:
### Connectivity
### Connectivity
We start by loading and visualizing the structural connectivity matrix that represents the set of all existing connections between brain areas. Having loaded the default dataset, we can then alter the speed of signal propagation through the network:
We start by loading and visualizing the structural connectivity matrix that represents the set of all existing connections between brain areas. Having loaded the default dataset, we can then alter the speed of signal propagation through the network:
%% Cell type:code id:6c563ce4 tags:
%% Cell type:code id:710d21e4 tags:
``` python
``` python
# Import the anatomical structural connectivity.
# Import the anatomical structural connectivity.
conn = connectivity.Connectivity().from_file(
conn = connectivity.Connectivity().from_file(
os.path.abspath('dataset/connectivity_76.zip')
os.path.abspath('dataset/connectivity_76.zip')
)
)
nregions = len(conn.region_labels) # Number of regions
nregions = len(conn.region_labels) # Number of regions
conn.speed = np.array(np.inf) # Set the conduction speed
conn.speed = np.array(np.inf) # Set the conduction speed
conn.configure()
conn.configure()
```
```
%% Cell type:markdown id:229ebbef tags:
%% Cell type:markdown id:de6dafab tags:
*Take a look at some of the properties of the `conn` object: `weights`, `delays`, `region_labels`, etc.*
*Take a look at some of the properties of the `conn` object: `weights`, `delays`, `region_labels`, etc.*
%% Cell type:code id:8e7e9be7 tags:
%% Cell type:code id:a301f70b tags:
``` python
``` python
conn
conn
```
```
%% Output
%% Output
<tvb.datatypes.connectivity.Connectivity at 0x7fb69414a6d8>
<tvb.datatypes.connectivity.Connectivity at 0x7fb69414a6d8>
%% Cell type:code id:04438045 tags:
%% Cell type:code id:c82cd475 tags:
``` python
``` python
plot_connectivity(conn)
plot_connectivity(conn)
```
```
%% Output
%% Output
%% Cell type:markdown id:ae6af06e tags:
%% Cell type:markdown id:e4d3660a tags:
### Model
### Model
%% Cell type:markdown id:96407494 tags:
%% Cell type:markdown id:0adf2b72 tags:
A set of differential equations describing the local neural dynamics. There are a number of predefined models available in TVB, as an example here we will use the **Generic 2-dimensional Oscillator** model:
A set of differential equations describing the local neural dynamics. There are a number of predefined models available in TVB, as an example here we will use the **Generic 2-dimensional Oscillator** model:
\begin{align}
\begin{align}
\dot{V} &= d \, \tau (-f V^3 + e V^2 + g V + \alpha W + \gamma I), \\
\dot{V} &= d \, \tau (-f V^3 + e V^2 + g V + \alpha W + \gamma I), \\
\dot{W} &= \dfrac{d}{\tau}\,\,(c V^2 + b V - \beta W + a).
\dot{W} &= \dfrac{d}{\tau}\,\,(c V^2 + b V - \beta W + a).
\end{align}
\end{align}
%% Cell type:markdown id:431f293c tags:
%% Cell type:markdown id:e3f828d7 tags:
We can explore it using the **phase-plane** tool in TVB.
We can explore it using the **phase-plane** tool in TVB.
%% Cell type:code id:4ccbd26b tags:
%% Cell type:code id:a7ae0fec tags:
``` python
``` python
# Create and launch the phase-plane tool
# Create and launch the phase-plane tool
g2d = models.Generic2dOscillator() # The model to investigate
g2d = models.Generic2dOscillator() # The model to investigate
heunint = integrators.HeunDeterministic(dt=1.0) # Integrator to use.
heunint = integrators.HeunDeterministic(dt=1.0) # Integrator to use.
<tvb.simulator.models.oscillator.Generic2dOscillator at 0x7fb64c430b38>
<tvb.simulator.models.oscillator.Generic2dOscillator at 0x7fb64c430b38>
%% Cell type:markdown id:c4d3b0d1 tags:
%% Cell type:markdown id:5045a18b tags:
### Coupling function
### Coupling function
It is a function that is used to join the local `Model` dynamics at distinct spatial locations over the connections described in `Connectivity`. Proper setting of the parameters for this function requires some knowledge of the properties of both the model being used and the structure through which it is connected. For our present purposes, we happen to know that for this configuration of parameters of TVB's `Generic2dOscillator` connected through TVB's default connectivity matrix, a linear function with a slope of 0.0075 is a reasonable thing to use.
It is a function that is used to join the local `Model` dynamics at distinct spatial locations over the connections described in `Connectivity`. Proper setting of the parameters for this function requires some knowledge of the properties of both the model being used and the structure through which it is connected. For our present purposes, we happen to know that for this configuration of parameters of TVB's `Generic2dOscillator` connected through TVB's default connectivity matrix, a linear function with a slope of 0.0075 is a reasonable thing to use.
%% Cell type:code id:966e422c tags:
%% Cell type:code id:27292c27 tags:
``` python
``` python
# Initialise a Coupling function.
# Initialise a Coupling function.
G = np.array(0.0075)
G = np.array(0.0075)
con_coupling = coupling.Scaling(a=G)
con_coupling = coupling.Scaling(a=G)
```
```
%% Cell type:markdown id:8a0e4549 tags:
%% Cell type:markdown id:d491e8c4 tags:
### Integrator
### Integrator
Now that we have defined our structure and dynamics, we need to select an integration scheme. While TVB supports a number of schemes, for most purposes you should use either `HeunDeterministic` or `HeunStochastic`.
Now that we have defined our structure and dynamics, we need to select an integration scheme. While TVB supports a number of schemes, for most purposes you should use either `HeunDeterministic` or `HeunStochastic`.
Note that the most important thing here is to use a step size that is small enough for the integration to be numerically stable.
Note that the most important thing here is to use a step size that is small enough for the integration to be numerically stable.
The last component is `Monitor`: observer models. Although there are Monitors which apply a biophysical measurement process to the simulated neural activity, such as EEG, MEG, etc, here we will select two simple monitors to get the time series of the model state variables:
The last component is `Monitor`: observer models. Although there are Monitors which apply a biophysical measurement process to the simulated neural activity, such as EEG, MEG, etc, here we will select two simple monitors to get the time series of the model state variables:
* the `Raw` monitor takes no arguments and simply returns all the simulated data at the time resolution of the integration step,
* the `Raw` monitor takes no arguments and simply returns all the simulated data at the time resolution of the integration step,
* the `TemporalAverage` monitor averages over a time window of length period returning one time point every period (given in ms).
* the `TemporalAverage` monitor averages over a time window of length period returning one time point every period (given in ms).
*Note: as a general rule, the `Raw` monitor shouldn't be used for anything but very short simulations as the amount of data returned can become prohibitively large*
*Note: as a general rule, the `Raw` monitor shouldn't be used for anything but very short simulations as the amount of data returned can become prohibitively large*
%% Cell type:code id:a2512904 tags:
%% Cell type:code id:66d578cd tags:
``` python
``` python
# Initialise some Monitors with period in physical time.
# Initialise some Monitors with period in physical time.
The last step is to bring all these components together into a `Simulator` object. We then need to run the configure method, which basically just acts to calculate information necessary for the simulation that draws on specific combinations of the components.
The last step is to bring all these components together into a `Simulator` object. We then need to run the configure method, which basically just acts to calculate information necessary for the simulation that draws on specific combinations of the components.
%% Cell type:code id:0a98d0ab tags:
%% Cell type:code id:95deeaa2 tags:
``` python
``` python
# Initialise the Simulator.
# Initialise the Simulator.
sim = simulator.Simulator(model=g2d,
sim = simulator.Simulator(model=g2d,
connectivity=conn,
connectivity=conn,
conduction_speed=np.float(conn.speed),
conduction_speed=np.float(conn.speed),
coupling=con_coupling,
coupling=con_coupling,
integrator=heunint,
integrator=heunint,
monitors=what_to_watch)
monitors=what_to_watch)
sim.configure()
sim.configure()
```
```
%% Output
%% Output
<tvb.simulator.simulator.Simulator at 0x7fb64c70bc18>
<tvb.simulator.simulator.Simulator at 0x7fb64c70bc18>
%% Cell type:markdown id:7f418030 tags:
%% Cell type:markdown id:4b408895 tags:
Now, we can run the simulation. All we need to do is iterate for some length, which we provide in *ms*, and collect the output.
Now, we can run the simulation. All we need to do is iterate for some length, which we provide in *ms*, and collect the output.
The data returned by the simulator is in the form of a list of arrays. For most subsequent purposes it is much easier to deal with the data if it exists as a single contiguous array, hence the enumeration of the return values for the `sim.run`.
The data returned by the simulator is in the form of a list of arrays. For most subsequent purposes it is much easier to deal with the data if it exists as a single contiguous array, hence the enumeration of the return values for the `sim.run`.
**Functional Connectivity (FC)** describes the connectedness of two brain regions by means of the covariance between their time series. The classic and most widely used method to infer the strength of network interactions or functional connections consists in estimating the linear (Pearson) correlation coefficient between temporal signals. If two regions activate and deactivate at the same time, there is likely a functional connection.
**Functional Connectivity (FC)** describes the connectedness of two brain regions by means of the covariance between their time series. The classic and most widely used method to infer the strength of network interactions or functional connections consists in estimating the linear (Pearson) correlation coefficient between temporal signals. If two regions activate and deactivate at the same time, there is likely a functional connection.
To calculate the FC, we ignore the first second of the simulation which might be affected by the initial conditions.
To calculate the FC, we ignore the first second of the simulation which might be affected by the initial conditions.