Skip to content
Snippets Groups Projects

Code, comment and displlay enhancements for the jupyter notebook

Merged Didi Hou requested to merge github/fork/didi-hou/Code_enhance_notebook into master
1 file
+ 90
127
Compare changes
  • Side-by-side
  • Inline
+ 90
127
@@ -35,7 +35,14 @@
"\n",
"3. Schmidt M, Bakker R, Shen K, Bezgin B, Diesmann M & van Albada SJ (2018)\n",
" A multi-scale layer-resolved spiking network model of\n",
" resting-state dynamics in macaque cortex. PLOS Computational Biology, 14(9): e1006359. [https://doi.org/10.1371/journal.pcbi.1006359](https://doi.org/10.1371/journal.pcbi.1006359)\n",
" resting-state dynamics in macaque cortex. PLOS Computational Biology, 14(9): e1006359. [https://doi.org/10.1371/journal.pcbi.1006359](https://doi.org/10.1371/journal.pcbi.1006359)"
]
},
{
"cell_type": "markdown",
"id": "813785da-2cf2-46d3-a120-55de9760b37e",
"metadata": {},
"source": [
"<br>"
]
},
@@ -46,7 +53,7 @@
"tags": []
},
"source": [
"#### Notebook structure <a class=\"anchor\" id=\"toc\"></a>\n",
"## Notebook Structure <a class=\"anchor\" id=\"toc\"></a>\n",
"* [S0. Configuration](#section_0)\n",
"* [S1. Parameterization](#section_1)\n",
" * [1.1. Parameters to tune](#section_1_1)\n",
@@ -123,9 +130,6 @@
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import os\n",
"import nest\n",
"import json\n",
"import sys\n",
"from IPython.display import display, HTML\n",
"import warnings\n",
@@ -181,7 +185,7 @@
"id": "27160ba8",
"metadata": {},
"source": [
"Go back to [Notebook structure](#toc)"
"Go back to [Notebook Structure](#toc)"
]
},
{
@@ -241,9 +245,9 @@
"outputs": [],
"source": [
"# Downscaling factor\n",
"# Value range/options: (0, 1.]\n",
"# Value range/options: (0, 1.], change it to 1. to run the fullscale network\n",
"# Value assigned: 0.005\n",
"scale_down_to = 0.005 # Change it to 1. for running the fullscale network\n",
"scale_down_to = 0.005\n",
"\n",
"# Scaling factor for cortico-cortical connections (chi) \n",
"# Value range/options: [1., 2.5]\n",
@@ -254,7 +258,6 @@
"# Value range/options: any sublist of complete_area_list\n",
"# where complete_area_list = ['V1', 'V2', 'VP', 'V3', 'V3A', 'MT', 'V4t', 'V4', 'VOT', 'MSTd', 'PIP', 'PO', 'DP', 'MIP', 'MDP', 'VIP', 'LIP', 'PITv', 'PITd', 'MSTl', 'CITv', 'CITd', 'FEF', 'TF', 'AITv', 'FST', '7a', 'STPp', 'STPa', '46', 'AITd', 'TH']\n",
"# Value assigned: complete_area_list\n",
"# Note: at this pre-released multi-area model v2.0.0, the areas_similated has to be complete_area_list\n",
"areas_simulated = ['V1', 'V2', 'VP', 'V3', 'V3A', 'MT', 'V4t', 'V4', 'VOT', 'MSTd', 'PIP', 'PO', 'DP', 'MIP', 'MDP', 'VIP', 'LIP', 'PITv', 'PITd', 'MSTl', 'CITv', 'CITd', 'FEF', 'TF', 'AITv', 'FST', '7a', 'STPp', 'STPa', '46', 'AITd', 'TH']\n",
"# areas_simulated = ['V1', 'V2']\n",
"\n",
@@ -292,50 +295,50 @@
"\n",
"# Connection parameters\n",
"conn_params = {\n",
" 'replace_non_simulated_areas': replace_non_simulated_areas, # Whether to replace non-simulated areas by Poisson sources with the same global rate, by default: None\n",
" 'g': -11., # It sets the relative inhibitory synaptic strength, by default: -16.\n",
" 'K_stable': 'K_stable.npy', # Whether to apply the stabilization method of Schuecker, Schmidt et al. (2017), by default: None\n",
" 'fac_nu_ext_TH': 1.2, # Increase the external input to 2/3E and 5E in area TH\n",
" 'fac_nu_ext_5E': 1.125, # Increase the external Poisson indegree onto 5E\n",
" 'fac_nu_ext_6E': 1.41666667, # Increase the external Poisson indegree onto 6E\n",
" 'av_indegree_V1': 3950., # Adjust the average indegree in V1 based on monkey data\n",
" 'replace_cc_input_source': replace_cc_input_source\n",
" 'replace_non_simulated_areas': replace_non_simulated_areas, # Whether to replace non-simulated areas by Poisson sources with the same global rate, by default: None\n",
" 'g': -11., # It sets the relative inhibitory synaptic strength, by default: -16.\n",
" 'K_stable': 'K_stable.npy', # Whether to apply the stabilization method of Schuecker, Schmidt et al. (2017), by default: None\n",
" 'fac_nu_ext_TH': 1.2, # Increase the external input to 2/3E and 5E in area TH\n",
" 'fac_nu_ext_5E': 1.125, # Increase the external Poisson indegree onto 5E\n",
" 'fac_nu_ext_6E': 1.41666667, # Increase the external Poisson indegree onto 6E\n",
" 'av_indegree_V1': 3950., # Adjust the average indegree in V1 based on monkey data\n",
" 'replace_cc_input_source': replace_cc_input_source # Specify the data used to replace non-simulated areas\n",
"}\n",
"\n",
"# Input parameters\n",
"input_params = {\n",
" 'rate_ext': 10. # Rate of the Poissonian spike generator (in spikes/s)\n",
" 'rate_ext': 10. # Rate of the Poissonian spike generator (in spikes/s)\n",
"} \n",
"\n",
"# Neuron parameters\n",
"neuron_params = {\n",
" 'V0_mean': -150., # Mean for the distribution of initial membrane potentials, by default: -100.\n",
" 'V0_sd': 50. # Standard deviation for the distribution of initial membrane potentials, by default: 50.\n",
" 'V0_mean': -150., # Mean for the distribution of initial membrane potentials, by default: -100.\n",
" 'V0_sd': 50. # Standard deviation for the distribution of initial membrane potentials, by default: 50.\n",
"}\n",
"\n",
"# Network parameters\n",
"network_params = {\n",
" 'N_scaling': scale_down_to, # Scaling of population sizes, by default: 1.\n",
" 'K_scaling': scale_down_to, # Scaling of indegrees, by default: 1.\n",
" 'fullscale_rates': 'tests/fullscale_rates.json', # Absolute path to the file holding full-scale rates for scaling synaptic weights, by default: None\n",
" 'input_params': input_params, # Input parameters\n",
" 'connection_params': conn_params, # Connection parameters\n",
" 'neuron_params': neuron_params # Neuron parameters\n",
" 'N_scaling': scale_down_to, # Scaling of population sizes, by default: 1.\n",
" 'K_scaling': scale_down_to, # Scaling of indegrees, by default: 1.\n",
" 'fullscale_rates': 'tests/fullscale_rates.json', # Absolute path to the file holding full-scale rates for scaling synaptic weights, by default: None\n",
" 'input_params': input_params, # Input parameters\n",
" 'connection_params': conn_params, # Connection parameters\n",
" 'neuron_params': neuron_params # Neuron parameters\n",
"} \n",
"\n",
"# Simulation parameters\n",
"sim_params = {\n",
" 'areas_simulated': areas_simulated,\n",
" 't_sim': 2000., # Simulated time (in ms), by default: 10.0\n",
" 'num_processes': 1, # The number of MPI processes, by default: 1\n",
" 'local_num_threads': 1, # The number of threads per MPI process, by default: 1\n",
" 't_sim': 2000., # Simulated time (in ms), by default: 10.0\n",
" 'num_processes': 1, # The number of MPI processes, by default: 1\n",
" 'local_num_threads': 1, # The number of threads per MPI process, by default: 1\n",
" 'recording_dict': {'record_vm': False},\n",
" 'rng_seed': 1 # global random seed\n",
" 'rng_seed': 1 # global random seed\n",
"}\n",
"\n",
"# Theory paramters (theory_params)\n",
"theory_params = {\n",
" 'dt': 0.1 # The time step of the mean-field theory integration, by default: 0.01\n",
" 'dt': 0.1 # The time step of the mean-field theory integration, by default: 0.01\n",
"} "
]
},
@@ -344,7 +347,7 @@
"id": "1472e9c5",
"metadata": {},
"source": [
"Go back to [Notebook structure](#toc)"
"Go back to [Notebook Structure](#toc)"
]
},
{
@@ -407,6 +410,7 @@
],
"source": [
"p, r = M.theory.integrate_siegert()\n",
"\n",
"print(\"Mean-field theory predicts an average \"\n",
" \"firing rate of {0:.3f} spikes/s across all populations.\".format(np.mean(r[:, -1])))"
]
@@ -424,62 +428,22 @@
"id": "8a7c09e0",
"metadata": {},
"source": [
"The connectivity and neuron numbers are stored in the attributes of the model class. Neuron numbers are stored in `M.N` as a dictionary (and in `M.N_vec` as an array), indegrees in `M.K` as a dictionary (and in `M.K_matrix` as an array). Number of synapses can also be access via `M.synapses` (and in `M.syn_matrix` as an array). <br>"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "6316ac24",
"metadata": {},
"outputs": [],
"source": [
"# Neuron numbers\n",
"\n",
"# Dictionary of neuron numbers\n",
"# print(M.N)\n",
"\n",
"# Array of neuron numbers\n",
"# (M.N_vec)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8408d463-557b-481b-afc1-5fbbbd67306d",
"metadata": {},
"outputs": [],
"source": [
"# Indegrees\n",
"The connectivity and neuron numbers are stored in the attributes of the model class. \n",
"\n",
"# Dictionary of nodes indegrees organized as:\n",
"# {<source_area>: {<source_pop>: {<target_area>: {<target_pop>: indegree_values}}}}\n",
"# M.K\n",
"* Neuron numbers are stored in `M.N` as a dictionary (and in `M.N_vec` as an array).\n",
"\n",
"# Array of nodes indegrees\n",
"# M.K_matrix.shape"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "445a722a",
"metadata": {},
"outputs": [],
"source": [
"# Synapses\n",
"\n",
"# Dictionary of synapses that target neurons receive, it is organized as:\n",
"# {<source_area>: {<source_pop>: {<target_area>: {<target_pop>: number_of_synapses}}}}\n",
"# M.synapses\n",
"* Indegrees are stored in `M.K` as a dictionary (and in `M.K_matrix` as an array).<br>\n",
" Dictionary of nodes indegrees organized as:<br>\n",
" `{<source_area>: {<source_pop>: {<target_area>: {<target_pop>: indegree_values}}}}`\n",
"\n",
"# Array of \n",
"# M.syn_matrix"
"* Number of synapses can be access via `M.synapses` (and in `M.syn_matrix` as an array). <br>\n",
" Dictionary of synapses that target neurons receive, it is organized as:<br>\n",
" `{<source_area>: {<source_pop>: {<target_area>: {<target_pop>: number_of_synapses}}}}`"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"id": "05512922-26e5-425f-90a4-0df7c2279ccf",
"metadata": {},
"outputs": [
@@ -488,7 +452,7 @@
"output_type": "stream",
"text": [
"Initializing network from dictionary.\n",
"RAND_DATA_LABEL 9986\n",
"RAND_DATA_LABEL 4163\n",
"\n",
"\n",
"========================================\n",
@@ -530,7 +494,7 @@
"id": "e67f37e9-ec8d-4bb1-bd21-45e966f47ab6",
"metadata": {},
"source": [
"Go back to [Notebook structure](#toc)"
"Go back to [Notebook Structure](#toc)"
]
},
{
@@ -543,7 +507,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 9,
"id": "15778e9c",
"metadata": {},
"outputs": [
@@ -553,78 +517,77 @@
"text": [
"Prepared simulation in 0.00 seconds.\n",
"Rank 0: created area V1 with 0 local nodes\n",
"Memory after V1 : 1649.64 MB\n",
"Memory after V1 : 1649.71 MB\n",
"Rank 0: created area V2 with 0 local nodes\n",
"Memory after V2 : 1676.23 MB\n",
"Memory after V2 : 1676.30 MB\n",
"Rank 0: created area VP with 0 local nodes\n",
"Memory after VP : 1705.40 MB\n",
"Memory after VP : 1705.50 MB\n",
"Rank 0: created area V3 with 0 local nodes\n",
"Memory after V3 : 1733.67 MB\n",
"Memory after V3 : 1733.78 MB\n",
"Rank 0: created area V3A with 0 local nodes\n",
"Memory after V3A : 1753.64 MB\n",
"Memory after V3A : 1753.62 MB\n",
"Rank 0: created area MT with 0 local nodes\n",
"Memory after MT : 1779.16 MB\n",
"Memory after MT : 1779.11 MB\n",
"Rank 0: created area V4t with 0 local nodes\n",
"Memory after V4t : 1804.07 MB\n",
"Memory after V4t : 1804.10 MB\n",
"Rank 0: created area V4 with 0 local nodes\n",
"Memory after V4 : 1831.04 MB\n",
"Rank 0: created area VOT with 0 local nodes\n",
"Memory after VOT : 1856.21 MB\n",
"Memory after VOT : 1856.32 MB\n",
"Rank 0: created area MSTd with 0 local nodes\n",
"Memory after MSTd : 1877.78 MB\n",
"Memory after MSTd : 1877.81 MB\n",
"Rank 0: created area PIP with 0 local nodes\n",
"Memory after PIP : 1899.15 MB\n",
"Memory after PIP : 1899.18 MB\n",
"Rank 0: created area PO with 0 local nodes\n",
"Memory after PO : 1920.52 MB\n",
"Memory after PO : 1920.59 MB\n",
"Rank 0: created area DP with 0 local nodes\n",
"Memory after DP : 1940.81 MB\n",
"Memory after DP : 1940.85 MB\n",
"Rank 0: created area MIP with 0 local nodes\n",
"Memory after MIP : 1962.32 MB\n",
"Memory after MIP : 1962.39 MB\n",
"Rank 0: created area MDP with 0 local nodes\n",
"Memory after MDP : 1983.79 MB\n",
"Memory after MDP : 1983.74 MB\n",
"Rank 0: created area VIP with 0 local nodes\n",
"Memory after VIP : 2005.75 MB\n",
"Memory after VIP : 2005.70 MB\n",
"Rank 0: created area LIP with 0 local nodes\n",
"Memory after LIP : 2029.71 MB\n",
"Memory after LIP : 2029.05 MB\n",
"Rank 0: created area PITv with 0 local nodes\n",
"Memory after PITv : 2054.89 MB\n",
"Memory after PITv : 2054.36 MB\n",
"Rank 0: created area PITd with 0 local nodes\n",
"Memory after PITd : 2080.06 MB\n",
"Memory after PITd : 2079.55 MB\n",
"Rank 0: created area MSTl with 0 local nodes\n",
"Memory after MSTl : 2101.58 MB\n",
"Memory after MSTl : 2100.91 MB\n",
"Rank 0: created area CITv with 0 local nodes\n",
"Memory after CITv : 2120.78 MB\n",
"Memory after CITv : 2120.07 MB\n",
"Rank 0: created area CITd with 0 local nodes\n",
"Memory after CITd : 2140.06 MB\n",
"Memory after CITd : 2139.39 MB\n",
"Rank 0: created area FEF with 0 local nodes\n",
"Memory after FEF : 2161.43 MB\n",
"Memory after FEF : 2160.88 MB\n",
"Rank 0: created area TF with 0 local nodes\n",
"Memory after TF : 2177.05 MB\n",
"Memory after TF : 2176.50 MB\n",
"Rank 0: created area AITv with 0 local nodes\n",
"Memory after AITv : 2199.76 MB\n",
"Memory after AITv : 2199.09 MB\n",
"Rank 0: created area FST with 0 local nodes\n",
"Memory after FST : 2216.51 MB\n",
"Memory after FST : 2215.76 MB\n",
"Rank 0: created area 7a with 0 local nodes\n",
"Memory after 7a : 2237.66 MB\n",
"Memory after 7a : 2237.07 MB\n",
"Rank 0: created area STPp with 0 local nodes\n",
"Memory after STPp : 2255.65 MB\n",
"Memory after STPp : 2255.66 MB\n",
"Rank 0: created area STPa with 0 local nodes\n",
"Memory after STPa : 2274.89 MB\n",
"Memory after STPa : 2274.82 MB\n",
"Rank 0: created area 46 with 0 local nodes\n",
"Memory after 46 : 2290.25 MB\n",
"Memory after 46 : 2290.14 MB\n",
"Rank 0: created area AITd with 0 local nodes\n",
"Memory after AITd : 2312.82 MB\n",
"Memory after AITd : 2312.83 MB\n",
"Rank 0: created area TH with 0 local nodes\n",
"Memory after TH : 2325.52 MB\n",
"Created areas and internal connections in 2.02 seconds.\n",
"Created cortico-cortical connections in 20.42 seconds.\n",
"Simulated network in 72.63 seconds.\n"
"Memory after TH : 2325.57 MB\n",
"Created areas and internal connections in 1.97 seconds.\n",
"Created cortico-cortical connections in 20.03 seconds.\n",
"Simulated network in 69.00 seconds.\n"
]
}
],
"source": [
"# %%capture captured\n",
"# run the simulation, depending on the model parameter and downscale ratio, the running time varies largely.\n",
"# Run the simulation, depending on the model parameter and downscale ratio, the running time varies largely.\n",
"M.simulation.simulate()"
]
},
@@ -633,7 +596,7 @@
"id": "fd6e3232",
"metadata": {},
"source": [
"Go back to [Notebook structure](#toc)"
"Go back to [Notebook Structure](#toc)"
]
},
{
@@ -658,7 +621,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"id": "bea30fc8",
"metadata": {},
"outputs": [
@@ -687,7 +650,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 11,
"id": "ae19bcc3",
"metadata": {
"tags": []
@@ -705,11 +668,11 @@
}
],
"source": [
"# Choose 3 areas from the complete_area_list to show their sipking activity\n",
"# Choose at most 3 areas from the complete_area_list to show their sipking activities\n",
"# By default, it's set as ['V1', 'V2', 'FEF']\n",
"# Note: at this pre-released multi-area model v2.0.0, the areas_similated has to be \n",
"raster_areas = ['V1', 'V2', 'FEF']\n",
"# raster_areas = ['V1', 'V2']\n",
"\n",
"plot_resting_state(M, data_path, raster_areas)"
]
},
@@ -738,7 +701,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 12,
"id": "721d1f03-df25-468d-8075-a807025a9c58",
"metadata": {},
"outputs": [
@@ -762,7 +725,7 @@
"id": "ef74ca3e-98dc-49c9-a4a0-2c640e29b1d9",
"metadata": {},
"source": [
"Go back to [Notebook structure](#toc)"
"Go back to [Notebook Structure](#toc)"
]
}
],