Skip to content

Commit 0142d91

Browse files
authored
Merge pull request #9 from gabrevaya/WC-getting-started
improve readability of WC eqs in Getting started
2 parents 5123ca7 + 8d98e08 commit 0142d91

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

Diff for: docs/src/getting_started.md

+50-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,37 @@
22

33
This tutorial will introduce you to simulating brain dynamics using Neuroblox.
44

5-
## Example 1 : Building an oscillating circuit from two Wilson-Cowan Neural Mass Models
5+
## Example 1: Creating a Simple Neural Circuit
6+
7+
In this example, we'll create a simple oscillating circuit using two Wilson-Cowan neural mass models [1]. The Wilson-Cowan model is one of the most influential models in computational neuroscience [2], describing the dynamics of interactions between populations of excitatory and inhibitory neurons.
8+
9+
### The Wilson-Cowan Model
10+
11+
Each Wilson-Cowan neural mass is described by the following equations:
612

7-
The Wilson–Cowan model describes the dynamics of interactions between populations of excitatory and inhibitory neurons. Each Wilson-Cowan Blox is described by the follwoing equations:
813

914
```math
10-
\frac{dE}{dt} = \frac{-E}{\tau_E} + \frac{1}{1 + \text{exp}(-a_E*(c_{EE}*E - c_{IE}*I - \theta_E + \eta*(\sum{jcn}))}\\[10pt]
11-
\frac{dI}{dt} = \frac{-I}{\tau_I} + \frac{1}{1 + exp(-a_I*(c_{EI}*E - c_{II}*I - \theta_I)}
15+
\begin{align}
16+
\nonumber
17+
\frac{dE}{dt} &= \frac{-E}{\tau_E} + S_E(c_{EE}E - c_{IE}I + \eta\sum{jcn})\\[10pt]
18+
\nonumber
19+
\frac{dI}{dt} &= \frac{-I}{\tau_I} + S_I(c_{EI}E - c_{II}I)
20+
\end{align}
1221
```
1322

14-
Our first example is to simply combine two Wilson-Cowan Blox to build an oscillatory circuit
23+
where $E$ and $I$ denote the activity levels of the excitatory and inhibitory populations, respectively. The terms $\frac{dE}{dt}$ and $\frac{dI}{dt}$ describe the rate of change of these activity levels over time. The parameters $\tau_E$ and $\tau_I$ are time constants analogous to membrane time constants in single neuron models, determining how quickly the excitatory and inhibitory populations respond to changes. The coefficients $c_{EE}$ and $c_{II}$ represent self-interaction (or feedback) within excitatory and inhibitory populations, while $c_{IE}$ and $c_{EI}$ represent the cross-interactions between the two populations. The term $\eta\sum{jcn}$ represents external input to the excitatory population from other brain regions or external stimuli, with $\eta$ acting as a scaling factor. While $S_E$ and $S_I$ are sigmoid functions that represent the responses of neuronal populations to input stimuli, defined as:
24+
25+
26+
```math
27+
S_k(x) = \frac{1}{1 + exp(-a_kx - \theta_k)}
28+
```
29+
30+
where $a_k$ and $\theta_k$ determine the steepness and threshold of the response, respectively.
31+
32+
### Building the Circuit
33+
34+
Let's create an oscillating circuit by connecting two Wilson-Cowan neural masses:
35+
1536

1637
```@example Wilson-Cowan
1738
using Neuroblox
@@ -20,34 +41,55 @@ using Graphs
2041
using MetaGraphs
2142
using Plots
2243
44+
# Create two Wilson-Cowan blox
2345
@named WC1 = WilsonCowan()
2446
@named WC2 = WilsonCowan()
2547
48+
# Create a graph to represent our circuit
2649
g = MetaDiGraph()
2750
add_blox!.(Ref(g), [WC1, WC2])
2851
52+
# Define the connectivity between the neural masses
2953
adj = [-1 6; 6 -1]
3054
create_adjacency_edges!(g, adj)
3155
3256
```
3357

34-
First, we create the two Wilson-Cowan Blox: WC1 and WC2. Next, we add the two Blox into a directed graph as nodes and then we are creating weighted edges between the two nodes using an adjacency matrix.
58+
Here, we've created two Wilson-Cowan Blox and connected them as nodes in a directed graph. The `adj` matrix defines the weighted edges between these nodes. Each entry `adj[i,j]` represents how the output of blox `j` influences the input of blox `i`:
3559

36-
Now we are ready to build the ModelingToolkit System. Structural simplify creates the final set of equations in which all substiutions are made.
60+
- Diagonal elements (`adj[1,1]` and `adj[2,2]`): Self-connections, adding feedback to each blox.
61+
- Off-diagonal elements (`adj[1,2]` and `adj[2,1]`): Inter-blox connections, determining how each blox influences the other.
62+
63+
By default, the output of each Wilson-Cowan blox is its excitatory activity (E). The negative self-connections (-1) provide inhibitory feedback, while the positive inter-blox connections (6) provide strong excitatory coupling. This setup creates an oscillatory dynamic between the two Wilson-Cowan units.
64+
65+
66+
### Creating the Model
67+
Now, let's build the complete model:
3768

3869
```@example Wilson-Cowan
3970
@named sys = system_from_graph(g)
4071
sys = structural_simplify(sys)
4172
```
4273

43-
To solve the system, we first create an ODEProblem and then solve it over the tspan of (0,100) using a stiff solver. The solution is saved every 0.1ms. The unit of time in Neuroblox is 1ms.
74+
This creates a differential equations system from our graph representation using ModelingToolkit and symbolically simplifies it for efficient computation.
75+
76+
### Simulating the Model
77+
78+
Finally, let's simulate our model. The following code creates and solves an `ODEProblem` for our system, simulating 100 time units of activity. In Neuroblox, the default time unit is milliseconds. We use `Rodas4`, a solver efficient for stiff problems. The solution is saved every 0.1 ms, allowing us to observe the detailed evolution of the system's behavior.
4479

4580
```@example Wilson-Cowan
4681
prob = ODEProblem(sys, [], (0.0, 100), [])
4782
sol = solve(prob, Rodas4(), saveat=0.1)
4883
plot(sol)
4984
```
5085

86+
87+
[[1] Wilson, H. R., & Cowan, J. D. (1972). Excitatory and inhibitory interactions in localized populations of model neurons. Biophysical journal, 12(1), 1-24.](https://www.cell.com/biophysj/fulltext/S0006-3495(72)86068-5)
88+
89+
[[2] Destexhe, A., & Sejnowski, T. J. (2009). The Wilson–Cowan model, 36 years later. Biological cybernetics, 101(1), 1-2.](https://link.springer.com/article/10.1007/s00422-009-0328-3)
90+
91+
92+
5193
## Example 2 : Building a Brain Circuit from literature using Neural Mass Models
5294

5395
In this example, we will construct a Parkinsons model from eight Jansen-Rit Neural Mass Models as described in Liu et al. (2020). DOI: 10.1016/j.neunet.2019.12.021. The Jansen-Rit Neural Mass model is defined by the following differential equations:

0 commit comments

Comments
 (0)