Skip to content
Snippets Groups Projects
Commit 47b015aa authored by Didi Hou's avatar Didi Hou Committed by Administrator
Browse files

/

parent 3ac823ad
No related branches found
No related tags found
1 merge request!35Pre-release MAM v1.1.0
%% Cell type:markdown id:b1331599 tags:
# Down-scaled multi-area model
%% Cell type:markdown id:3e163b35-5330-48ca-8c7e-9e0a884520ca tags:
## Import dependencies
%% 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:1d440c07-9b69-4e52-8573-26b13493bc5a tags:
``` python
%%html
<style>
table {float:left}
</style>
```
%% Output
%% Cell type:markdown id:98555af1-a5c5-4db6-85dc-6d07e40f38cc tags:
## Create config file
%% Cell type:code id:72c170e4 tags:
``` python
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:df83f5ea-1c4b-44d3-9926-01786aa46e14 tags:
## Specify paramters of model
%% Cell type:markdown id:2cedd26b tags:
### 1. Scaling parameter
**Scaling parameter** (scale_down_to) is the parameter defines the the ratio of the full scale multi-area model being down-scaled to a model with fewer neurons and indegrees so as to be simulated on machines with lower computational ability and the simulation results can be obtained in relative shorter period of time.<br> <br>
Neurons and indegrees are both scaled down to 0.5%, where the model can usually be simulated on a local machine.<br> **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:d53f1eab tags:
### 2. Model and simulation parameters
%% Cell type:markdown id:14bac1ce-4ba0-47ec-84b2-9d3c72bc96ec tags:
#### 2.1 Connection parameters (conn_params)
%% Cell type:markdown id:41d80271-f60e-49f4-9759-f8ad26097b2d tags:
| Parameter | Parameter description | Variable | Value | Value description |
|:---------:|:----------------------|:---------------------------:|:------------------:|:------------------|
| | | 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. | |
%% Cell type:code id:7af3a191 tags:
``` python
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.}
```
%% Cell type:markdown id:1688ef55-2fdb-4800-97af-7ea62442c684 tags:
#### 2.2 Input parameters (input_params)
%% Cell type:markdown id:5127920c-2a89-42d0-9d87-889f7b7474d9 tags:
| Parameter | Parameter description | Variable | Value | Value description |
|:---------:|:----------------------|:-----------------------------:|:--------------------:|:------------------|
| | | rate_ext | 10. | |
%% Cell type:code id:2195cddb-bd82-47a8-ba74-cf0169a6801d tags:
``` python
input_params = {'rate_ext': 10.}
```
%% Cell type:markdown id:aefa84c8-baaa-4afa-96c6-5d57d174b286 tags:
#### 2.3 Neuron parameters (neuron_params)
%% Cell type:markdown id:ab5eb287-e638-401f-9e2c-892f88c3ee90 tags:
| Parameter | Parameter description | Variable | Value | Value description |
|:---------:|:----------------------|:---------------------------:|:------------------:|:------------------|
| | | V0_mean | -150. | |
| | | V0_sd | 50. | |
%% Cell type:code id:f69ad836-70b8-4ebe-b46a-25f48dc3ca7c tags:
``` python
neuron_params = {'V0_mean': -150.,
'V0_sd': 50.}
```
%% Cell type:markdown id:cdb50fb3-4bb9-446a-ab1c-d008b7e5bfa4 tags:
#### 2.4 Network parameters (network_params)
%% Cell type:markdown id:3e437aca-1fd0-4296-a0f6-a346b1319903 tags:
| Parameter | Parameter description | Variable | Value | Value description |
|:---------:|:----------------------|:---------------------:|:-----------------------------:|:------------------|
| | | 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 | |
%% Cell type:code id:0aa9a9bf-b95d-4643-82a0-e29a49bb58df tags:
``` python
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}
```
%% Cell type:markdown id:a0730f70-ed9b-4664-b677-3dda965a01ef tags:
### 3. Simulation paramters
### 3. Simulation paramters (sim_params)
%% Cell type:markdown id:c989ee79-fa3d-405c-a1bf-da8ec884d878 tags:
| Parameter | Parameter description | Variable | Value | Value description |
|:---------:|:----------------------|:--------------------:|:------------------:|:------------------|
| | |t_sim |2000. | |
| | |num_processes |1 | |
| | |local_num_threads |1 | |
| | |recording_dict |input_params | |
| | |record_vm |False | |
%% Cell type:code id:21484ed3-295f-4d06-b757-2969aac429a4 tags:
``` python
sim_params = {'t_sim': 2000.,
'num_processes': 1,
'local_num_threads': 1,
'recording_dict': {'record_vm': False}}
```
%% Cell type:markdown id:79596d77-c105-45d0-9a57-2d15e31f1189 tags:
### 4. Theory paramters (theory_params)
%% Cell type:markdown id:18e0deda-1dec-4df8-b994-ef641b3c5aac tags:
| Parameter | Parameter description | Variable | Value | Value description |
|:---------:|:----------------------|:---------------------:|:-----------------------------:|:------------------|
| | | dt | 0.1 | |
%% Cell type:code id:41edb350-36c3-4e19-829e-40d6ca9633a0 tags:
``` python
theory_params = {'dt': 0.1}
```
%% Cell type:markdown id:de4a6703 tags:
## Instantiate a multi-area model, predict firing rates from theroy
%% 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:markdown id:0c1cad59-81d0-4e24-ac33-13c4ca8c6dec tags:
## Run the simulation
%% Cell type:code id:15778e9c tags:
``` python
M.simulation.simulate()
```
%% Cell type:markdown id:9be9287d-4891-4b4b-bd19-cfc2ebed02ac tags:
## Load and process simulation results data
%% Cell type:markdown id:8726a93d tags:
### 1. Load spike data
%% Cell type:code id:cb8e3edd tags:
``` python
data = np.loadtxt(M.simulation.data_dir + '/recordings/' + M.simulation.label + "-spikes-1-0.dat", skiprows=3)
```
%% Cell type:markdown id:8793e033 tags:
### 2. 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:markdown id:57ff902c-d6ce-4f96-9e4f-8e3e7166ab66 tags:
## Simulation results visualization
%% Cell type:markdown id:38ddd973 tags:
### 1. Instantaneous and mean rate
%% Cell type:code id:bea30fc8 tags:
``` python
fig, ax = plt.subplots()
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()
```
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment