Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multi-area-model
Manage
Activity
Members
Labels
Plan
Issues
7
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IAS-6
multi-area-model
Commits
7bc0b3be
Commit
7bc0b3be
authored
2 years ago
by
Johanna Senk
Browse files
Options
Downloads
Patches
Plain Diff
Write config file from nb, compute and plot inst rate, beautify
parent
38196fcc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!33
Add Jupyter Notebook for EBRAINS with down-scaled MAM
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
multi-area-model.ipynb
+91
-50
91 additions, 50 deletions
multi-area-model.ipynb
with
91 additions
and
50 deletions
multi-area-model.ipynb
+
91
−
50
View file @
7bc0b3be
{
"cells": [
{
"cell_type": "markdown",
"id": "b1331599",
"metadata": {},
"source": [
"# Down-scaled multi-area model"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96517739",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
...
...
@@ -10,16 +31,38 @@
"!pip install nested_dict dicthash"
]
},
{
"cell_type": "markdown",
"id": "0c6b6a3c",
"metadata": {},
"source": [
"Create config file."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61e83d47",
"id": "72c170e4",
"metadata": {},
"outputs": [],
"source": [
"with open('config.py', 'w') as fp:\n",
" fp.write(\n",
"'''import os\n",
"base_path = os.path.abspath(\".\")\n",
"data_path = os.path.abspath(\"simulations\")\n",
"jobscript_template = \"python {base_path}/run_simulation.py {label}\"\n",
"submit_cmd = \"bash -c\"\n",
"''')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2784f76b",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"\n",
"from multiarea_model import MultiAreaModel"
]
},
...
...
@@ -28,10 +71,11 @@
"id": "2cedd26b",
"metadata": {},
"source": [
"# Down-scaled model\n",
"\n",
"Neurons and indegrees are both scaled down to 1%.\n",
"Can usually be simulated on a local machine."
"Can usually be simulated on a local machine.\n",
"\n",
"**Warning: This will not yield reasonable dynamical results from the\n",
"network and is only meant to demonstrate the simulation workflow.**"
]
},
{
...
...
@@ -46,11 +90,10 @@
},
{
"cell_type": "markdown",
"id": "
241db524
",
"id": "
d53f1eab
",
"metadata": {},
"source": [
"**Warning: This will not yield reasonable dynamical results from the\n",
"network and is only meant to demonstrate the simulation workflow.**"
"Specify model and simulation parameters."
]
},
{
...
...
@@ -60,7 +103,6 @@
"metadata": {},
"outputs": [],
"source": [
"d = {}\n",
"conn_params = {'replace_non_simulated_areas': 'het_poisson_stat',\n",
" 'g': -11.,\n",
" \n",
...
...
@@ -88,110 +130,109 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d409be95",
"cell_type": "markdown",
"id": "de4a6703",
"metadata": {},
"outputs": [],
"source": [
"M = MultiAreaModel(network_params, simulation=True,\n",
" sim_spec=sim_params,\n",
" theory=True,\n",
" theory_spec=theory_params)\n",
"p, r = M.theory.integrate_siegert()\n",
"print(\"Mean-field theory predicts an average \"\n",
" \"rate of {0:.3f} spikes/s across all populations.\".format(np.mean(r[:, -1])))"
"Instantiate a multi-area model, predict firing rates from theroy, and run the simulation. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
15778
e9
c
",
"id": "
d409b
e9
5
",
"metadata": {},
"outputs": [],
"source": [
"M.simulation.simulate()"
"M = MultiAreaModel(network_params, simulation=True,\n",
" sim_spec=sim_params,\n",
" theory=True,\n",
" theory_spec=theory_params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
cb8e3edd
",
"id": "
918d907f
",
"metadata": {},
"outputs": [],
"source": [
"data = np.loadtxt(M.simulation.label + \"-spikes-1-0.dat\", skiprows=3)"
"p, r = M.theory.integrate_siegert()\n",
"print(\"Mean-field theory predicts an average \"\n",
" \"rate of {0:.3f} spikes/s across all populations.\".format(np.mean(r[:, -1])))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
84dc3bde
",
"id": "
15778e9c
",
"metadata": {},
"outputs": [],
"source": [
"
data
"
"
M.simulation.simulate()
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9590223b",
"cell_type": "markdown",
"id": "8726a93d",
"metadata": {},
"outputs": [],
"source": [
"
tsteps, spikecount = np.unique(data[:,1], return_counts=True)
"
"
Load spike data.
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
0c3fc302
",
"id": "
cb8e3edd
",
"metadata": {},
"outputs": [],
"source": [
"
import matplotlib.pyplot as plt
"
"
data = np.loadtxt(M.simulation.data_dir + '/recordings/' + M.simulation.label + \"-spikes-1-0.dat\", skiprows=3)
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9f21dd40",
"cell_type": "markdown",
"id": "8793e033",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ax.plot(tsteps, spikecount)"
"Compute instantaneous rate per neuron across all populations."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
41028d2c
",
"id": "
9590223b
",
"metadata": {},
"outputs": [],
"source": [
"plt.show()"
"tsteps, spikecount = np.unique(data[:,1], return_counts=True)\n",
"rate = spikecount / M.simulation.params['dt'] * 1e3 / np.sum(M.N_vec)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c6091457",
"cell_type": "markdown",
"id": "38ddd973",
"metadata": {},
"outputs": [],
"source": [
"
len(spikecount), np.average(spikecount)
"
"
Plot instantaneous and mean rate.
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
ad2bd7b2
",
"id": "
bea30fc8
",
"metadata": {},
"outputs": [],
"source": [
"np.average(spikecount[2000:])"
"fig, ax = plt.subplots()\n",
"ax.plot(tsteps, rate)\n",
"ax.plot(tsteps, np.average(rate)*np.ones(len(tsteps)), label='mean')\n",
"ax.set_title('instantaneous rate across all populations')\n",
"ax.set_xlabel('time (ms)')\n",
"ax.set_ylabel('rate (spikes / s)')\n",
"ax.set_xlim(0, sim_params['t_sim'])\n",
"ax.set_ylim(0, 50)\n",
"ax.legend()"
]
}
],
...
...
%% Cell type:markdown id:b1331599 tags:
# Down-scaled multi-area model
%% Cell type:code id:96517739 tags:
```
python
%
matplotlib
inline
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
os
```
%% Cell type:code id:7e07b0d0 tags:
```
python
!
pip
install
nested_dict
dicthash
```
%% Cell type:code id:61e83d47 tags:
%% Cell type:markdown id:0c6b6a3c tags:
Create config file.
%% Cell type:code id:72c170e4 tags:
```
python
import
numpy
as
np
import
os
with
open
(
'
config.py
'
,
'
w
'
)
as
fp
:
fp
.
write
(
'''
import os
base_path = os.path.abspath(
"
.
"
)
data_path = os.path.abspath(
"
simulations
"
)
jobscript_template =
"
python {base_path}/run_simulation.py {label}
"
submit_cmd =
"
bash -c
"
'''
)
```
%% Cell type:code id:2784f76b tags:
```
python
from
multiarea_model
import
MultiAreaModel
```
%% Cell type:markdown id:2cedd26b tags:
# Down-scaled model
Neurons and indegrees are both scaled down to 1%.
Can usually be simulated on a local machine.
**
Warning: This will not yield reasonable dynamical results from the
network and is only meant to demonstrate the simulation workflow.
**
%% Cell type:code id:e940bb6b tags:
```
python
scale_down_to
=
0.005
```
%% Cell type:markdown id:
241db524
tags:
%% Cell type:markdown id:
d53f1eab
tags:
**
Warning: This will not yield reasonable dynamical results from the
network and is only meant to demonstrate the simulation workflow.
**
Specify model and simulation parameters.
%% Cell type:code id:7af3a191 tags:
```
python
d
=
{}
conn_params
=
{
'
replace_non_simulated_areas
'
:
'
het_poisson_stat
'
,
'
g
'
:
-
11.
,
'
K_stable
'
:
'
K_stable.npy
'
,
'
fac_nu_ext_TH
'
:
1.2
,
'
fac_nu_ext_5E
'
:
1.125
,
'
fac_nu_ext_6E
'
:
1.41666667
,
'
av_indegree_V1
'
:
3950.
}
input_params
=
{
'
rate_ext
'
:
10.
}
neuron_params
=
{
'
V0_mean
'
:
-
150.
,
'
V0_sd
'
:
50.
}
network_params
=
{
'
N_scaling
'
:
scale_down_to
,
'
K_scaling
'
:
scale_down_to
,
'
fullscale_rates
'
:
'
tests/fullscale_rates.json
'
,
'
input_params
'
:
input_params
,
'
connection_params
'
:
conn_params
,
'
neuron_params
'
:
neuron_params
}
sim_params
=
{
'
t_sim
'
:
2000.
,
'
num_processes
'
:
1
,
'
local_num_threads
'
:
1
,
'
recording_dict
'
:
{
'
record_vm
'
:
False
}}
theory_params
=
{
'
dt
'
:
0.1
}
```
%% Cell type:markdown id:de4a6703 tags:
Instantiate a multi-area model, predict firing rates from theroy, and run the simulation.
%% Cell type:code id:d409be95 tags:
```
python
M
=
MultiAreaModel
(
network_params
,
simulation
=
True
,
sim_spec
=
sim_params
,
theory
=
True
,
theory_spec
=
theory_params
)
```
%% Cell type:code id:918d907f tags:
```
python
p
,
r
=
M
.
theory
.
integrate_siegert
()
print
(
"
Mean-field theory predicts an average
"
"
rate of {0:.3f} spikes/s across all populations.
"
.
format
(
np
.
mean
(
r
[:,
-
1
])))
```
%% Cell type:code id:15778e9c tags:
```
python
M
.
simulation
.
simulate
()
```
%% Cell type:markdown id:8726a93d tags:
Load spike data.
%% Cell type:code id:cb8e3edd tags:
```
python
data
=
np
.
loadtxt
(
M
.
simulation
.
label
+
"
-spikes-1-0.dat
"
,
skiprows
=
3
)
data
=
np
.
loadtxt
(
M
.
simulation
.
data_dir
+
'
/recordings/
'
+
M
.
simulation
.
label
+
"
-spikes-1-0.dat
"
,
skiprows
=
3
)
```
%% Cell type:
code id:84dc3bde
tags:
%% Cell type:
markdown id:8793e033
tags:
```
python
data
```
Compute instantaneous rate per neuron across all populations.
%% Cell type:code id:9590223b tags:
```
python
tsteps
,
spikecount
=
np
.
unique
(
data
[:,
1
],
return_counts
=
True
)
rate
=
spikecount
/
M
.
simulation
.
params
[
'
dt
'
]
*
1e3
/
np
.
sum
(
M
.
N_vec
)
```
%% Cell type:
code id:0c3fc302
tags:
%% Cell type:
markdown id:38ddd973
tags:
```
python
import
matplotlib.pyplot
as
plt
```
Plot instantaneous and mean rate.
%% Cell type:code id:
9f21dd40
tags:
%% Cell type:code id:
bea30fc8
tags:
```
python
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
(
tsteps
,
spikecount
)
```
%% Cell type:code id:41028d2c tags:
```
python
plt
.
show
()
```
%% Cell type:code id:c6091457 tags:
```
python
len
(
spikecount
),
np
.
average
(
spikecount
)
```
%% Cell type:code id:ad2bd7b2 tags:
```
python
np
.
average
(
spikecount
[
2000
:])
ax
.
plot
(
tsteps
,
rate
)
ax
.
plot
(
tsteps
,
np
.
average
(
rate
)
*
np
.
ones
(
len
(
tsteps
)),
label
=
'
mean
'
)
ax
.
set_title
(
'
instantaneous rate across all populations
'
)
ax
.
set_xlabel
(
'
time (ms)
'
)
ax
.
set_ylabel
(
'
rate (spikes / s)
'
)
ax
.
set_xlim
(
0
,
sim_params
[
'
t_sim
'
])
ax
.
set_ylim
(
0
,
50
)
ax
.
legend
()
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment