Skip to content
Snippets Groups Projects
Unverified Commit 6d883048 authored by Johanna Senk's avatar Johanna Senk Committed by GitHub
Browse files

Fix inconsistency of `scale_down_to`

parent b5fa5c99
No related branches found
No related tags found
1 merge request!33Add Jupyter Notebook for EBRAINS with down-scaled MAM
%% Cell type:markdown id:b1331599 tags: %% Cell type:markdown id:b1331599 tags:
# Down-scaled multi-area model # Down-scaled multi-area model
%% Cell type:code id:96517739 tags: %% Cell type:code id:96517739 tags:
``` python ``` python
%matplotlib inline %matplotlib inline
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import os import os
``` ```
%% Cell type:code id:7e07b0d0 tags: %% Cell type:code id:7e07b0d0 tags:
``` python ``` python
!pip install nested_dict dicthash !pip install nested_dict dicthash
``` ```
%% Cell type:markdown id:0c6b6a3c tags: %% Cell type:markdown id:0c6b6a3c tags:
Create config file. Create config file.
%% Cell type:code id:72c170e4 tags: %% Cell type:code id:72c170e4 tags:
``` python ``` python
with open('config.py', 'w') as fp: with open('config.py', 'w') as fp:
fp.write( fp.write(
'''import os '''import os
base_path = os.path.abspath(".") base_path = os.path.abspath(".")
data_path = os.path.abspath("simulations") data_path = os.path.abspath("simulations")
jobscript_template = "python {base_path}/run_simulation.py {label}" jobscript_template = "python {base_path}/run_simulation.py {label}"
submit_cmd = "bash -c" submit_cmd = "bash -c"
''') ''')
``` ```
%% Cell type:code id:2784f76b tags: %% Cell type:code id:2784f76b tags:
``` python ``` python
from multiarea_model import MultiAreaModel from multiarea_model import MultiAreaModel
``` ```
%% Cell type:markdown id:2cedd26b tags: %% Cell type:markdown id:2cedd26b tags:
Neurons and indegrees are both scaled down to 1%. Neurons and indegrees are both scaled down to 0.5%.
Can usually be simulated on a local machine. Can usually be simulated on a local machine.
**Warning: This will not yield reasonable dynamical results from the **Warning: This will not yield reasonable dynamical results from the
network and is only meant to demonstrate the simulation workflow.** network and is only meant to demonstrate the simulation workflow.**
%% Cell type:code id:e940bb6b tags: %% Cell type:code id:e940bb6b tags:
``` python ``` python
scale_down_to = 0.005 scale_down_to = 0.005
``` ```
%% Cell type:markdown id:d53f1eab tags: %% Cell type:markdown id:d53f1eab tags:
Specify model and simulation parameters. Specify model and simulation parameters.
%% Cell type:code id:7af3a191 tags: %% Cell type:code id:7af3a191 tags:
``` python ``` python
conn_params = {'replace_non_simulated_areas': 'het_poisson_stat', conn_params = {'replace_non_simulated_areas': 'het_poisson_stat',
'g': -11., 'g': -11.,
'K_stable': 'K_stable.npy', 'K_stable': 'K_stable.npy',
'fac_nu_ext_TH': 1.2, 'fac_nu_ext_TH': 1.2,
'fac_nu_ext_5E': 1.125, 'fac_nu_ext_5E': 1.125,
'fac_nu_ext_6E': 1.41666667, 'fac_nu_ext_6E': 1.41666667,
'av_indegree_V1': 3950.} 'av_indegree_V1': 3950.}
input_params = {'rate_ext': 10.} input_params = {'rate_ext': 10.}
neuron_params = {'V0_mean': -150., neuron_params = {'V0_mean': -150.,
'V0_sd': 50.} 'V0_sd': 50.}
network_params = {'N_scaling': scale_down_to, network_params = {'N_scaling': scale_down_to,
'K_scaling': scale_down_to, 'K_scaling': scale_down_to,
'fullscale_rates': 'tests/fullscale_rates.json', 'fullscale_rates': 'tests/fullscale_rates.json',
'input_params': input_params, 'input_params': input_params,
'connection_params': conn_params, 'connection_params': conn_params,
'neuron_params': neuron_params} 'neuron_params': neuron_params}
sim_params = {'t_sim': 2000., sim_params = {'t_sim': 2000.,
'num_processes': 1, 'num_processes': 1,
'local_num_threads': 1, 'local_num_threads': 1,
'recording_dict': {'record_vm': False}} 'recording_dict': {'record_vm': False}}
theory_params = {'dt': 0.1} theory_params = {'dt': 0.1}
``` ```
%% Cell type:markdown id:de4a6703 tags: %% Cell type:markdown id:de4a6703 tags:
Instantiate a multi-area model, predict firing rates from theroy, and run the simulation. Instantiate a multi-area model, predict firing rates from theroy, and run the simulation.
%% Cell type:code id:d409be95 tags: %% Cell type:code id:d409be95 tags:
``` python ``` python
M = MultiAreaModel(network_params, simulation=True, M = MultiAreaModel(network_params, simulation=True,
sim_spec=sim_params, sim_spec=sim_params,
theory=True, theory=True,
theory_spec=theory_params) theory_spec=theory_params)
``` ```
%% Cell type:code id:918d907f tags: %% Cell type:code id:918d907f tags:
``` python ``` python
p, r = M.theory.integrate_siegert() p, r = M.theory.integrate_siegert()
print("Mean-field theory predicts an average " print("Mean-field theory predicts an average "
"rate of {0:.3f} spikes/s across all populations.".format(np.mean(r[:, -1]))) "rate of {0:.3f} spikes/s across all populations.".format(np.mean(r[:, -1])))
``` ```
%% Cell type:code id:15778e9c tags: %% Cell type:code id:15778e9c tags:
``` python ``` python
M.simulation.simulate() M.simulation.simulate()
``` ```
%% Cell type:markdown id:8726a93d tags: %% Cell type:markdown id:8726a93d tags:
Load spike data. Load spike data.
%% Cell type:code id:cb8e3edd tags: %% Cell type:code id:cb8e3edd tags:
``` python ``` python
data = np.loadtxt(M.simulation.data_dir + '/recordings/' + 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:markdown id:8793e033 tags: %% Cell type:markdown id:8793e033 tags:
Compute instantaneous rate per neuron across all populations. Compute instantaneous rate per neuron across all populations.
%% Cell type:code id:9590223b tags: %% Cell type:code id:9590223b tags:
``` python ``` python
tsteps, spikecount = np.unique(data[:,1], return_counts=True) tsteps, spikecount = np.unique(data[:,1], return_counts=True)
rate = spikecount / M.simulation.params['dt'] * 1e3 / np.sum(M.N_vec) rate = spikecount / M.simulation.params['dt'] * 1e3 / np.sum(M.N_vec)
``` ```
%% Cell type:markdown id:38ddd973 tags: %% Cell type:markdown id:38ddd973 tags:
Plot instantaneous and mean rate. Plot instantaneous and mean rate.
%% Cell type:code id:bea30fc8 tags: %% Cell type:code id:bea30fc8 tags:
``` python ``` python
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.plot(tsteps, rate) ax.plot(tsteps, rate)
ax.plot(tsteps, np.average(rate)*np.ones(len(tsteps)), label='mean') ax.plot(tsteps, np.average(rate)*np.ones(len(tsteps)), label='mean')
ax.set_title('instantaneous rate across all populations') ax.set_title('instantaneous rate across all populations')
ax.set_xlabel('time (ms)') ax.set_xlabel('time (ms)')
ax.set_ylabel('rate (spikes / s)') ax.set_ylabel('rate (spikes / s)')
ax.set_xlim(0, sim_params['t_sim']) ax.set_xlim(0, sim_params['t_sim'])
ax.set_ylim(0, 50) ax.set_ylim(0, 50)
ax.legend() 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