-
Notifications
You must be signed in to change notification settings - Fork 3
/
sim_rewiring_ex5.py
106 lines (81 loc) · 3.99 KB
/
sim_rewiring_ex5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
"""Shows effectiveness of post-spike plasticity. This time with non-disjoint input assemblies."""
import os
import time
import numpy as np
from core import core_global as core
from core.spike_monitor import SpikeMonitor
from core.voltage_monitor import VoltageMonitor
from core.weight_matrix_monitor import WeightMatrixMonitor
from layers.rewiring_connection import RewiringConnection
from models.mc_lif_group import McLifGroup
from models.poisson_pattern_group import PoissonPatternGroup
from utils import utils as utils
def main(args):
trial = args[0]
config = args[1]
input_params = config["input_parameters"]
connection_params = config["connection_parameters"]
neuron_params = config["neuron_parameters"]
# Directory for simulation results and log files.
output_directory = os.path.join("results", "rewiring_ex5", str(input_params["num_assembly_neurons"]),
time.strftime("%y%m%d_%H%M%S"), str(trial), "data")
# Initialize the simulation environment.
core.init(directory=output_directory)
# Write config file to the output directory.
utils.write_configuration(os.path.join(output_directory, "..", "config_rewiring_ex5.yaml"), config)
# Set the random seed.
core.kernel.set_master_seed(config["master_seed"])
# Create input neurons.
inp = PoissonPatternGroup(input_params["num_inputs"], input_params["rate"], input_params["rate_bg"],
params=input_params)
# Here we randomly chose the assembly neurons.
unique_size = input_params["assembly_size"] - input_params["shared_size"]
assembly_neurons_idc = [list(range(i * unique_size, (i + 1) * unique_size))
for i in range(input_params["num_assemblies"])]
shared_neurons = range(unique_size * input_params["num_assemblies"], input_params["num_inputs"])
for i in range(input_params["num_assemblies"]):
assembly_neurons_idc[i] += list(np.random.choice(shared_neurons, input_params["shared_size"],
replace=False))
assembly_neurons_idc = np.array(assembly_neurons_idc)
np.savetxt(os.path.join(output_directory, "assembly_neurons_idc"),
np.sort(assembly_neurons_idc), fmt="%d")
# Set the indices of the assembly neurons.
inp.set_assembly_neurons_idc(assembly_neurons_idc)
# Create the neuron.
neuron = McLifGroup(1, neuron_params["num_branches"], neuron_params)
# Connect input to neuron.
conn = RewiringConnection(inp, neuron, neuron.branch.syn_current, connection_params)
# Create some monitors which will record the simulation data.
WeightMatrixMonitor(conn, core.kernel.fn("weights", "dat"),
interval=config["sampling_interval_weights"])
SpikeMonitor(neuron, core.kernel.fn("output", "ras"))
sm_inp = SpikeMonitor(inp, core.kernel.fn("input", "ras"))
vm_nrn = VoltageMonitor(neuron.soma, 0, core.kernel.fn("soma", "mem"))
vm_br = []
for i in range(neuron_params["num_branches"]):
vm_br.append(VoltageMonitor(neuron.branch, (i, 0), core.kernel.fn("branch", "mem", i)))
# Now simulate the model.
simulation_time = config["simulation_time"]
core.kernel.run_chunk(20.0, 0, simulation_time)
sm_inp.active = False
vm_nrn.active = False
for vm in vm_br:
vm.active = False
core.kernel.run_chunk(simulation_time - 40, 0, simulation_time)
sm_inp.active = True
vm_nrn.active = True
for vm in vm_br:
vm.active = True
core.kernel.run_chunk(20.0, 0, simulation_time)
if __name__ == '__main__':
import copy
from scoop import futures
# Load the configuration file.
config = utils.load_configuration("config_rewiring_ex5.yaml")
configs = []
num_trials = 25
for trial in range(num_trials):
config["master_seed"] = 10 * (trial + 1)
configs.append(copy.deepcopy(config))
r = list(futures.map(main, [[trial, config] for trial, config in enumerate(configs)]))