|
13 | 13 | # You should have received a copy of the GNU General Public License |
14 | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
|
| 16 | + |
16 | 17 | """ |
17 | | -Spiking Elementary Motion Detector (sEMD) example |
| 18 | +Spiking ELementary Motion Detector (sEMD) example |
18 | 19 | See https://www.cit-ec.de/en/nbs/spiking-insect-vision for more details |
19 | 20 | """ |
20 | 21 |
|
21 | 22 | # imports |
22 | 23 | import spynnaker8 as p |
23 | | -import datetime |
24 | | -from pyNN.utility.plotting import Figure, Panel |
25 | 24 | import matplotlib.pyplot as plt |
| 25 | +from pyNN.utility.plotting import Figure, Panel |
26 | 26 |
|
27 | | -# parameters |
28 | | -datum = datetime.datetime.now() |
29 | | - |
30 | | -step = 0.1 |
31 | | -p.setup(timestep=step) |
32 | | -n_neurons = 1 |
33 | | -run_time = 150 |
34 | | -cm = 0.25 |
35 | | -i_offset = 0.0 |
36 | | -tau_m = 20.0 |
37 | | -tau_refrac = 1.0 |
38 | | -current_decay = tau_syn_E = tau_syn_I = 30 |
39 | | -v_reset = -85.0 |
40 | | -v_rest = -65.0 |
41 | | -v_thresh = -50.0 |
42 | | - |
43 | | -weight = 1 |
44 | | -delay1 = 0.1 |
45 | | -delay2 = 2.0 |
| 27 | +# variables |
| 28 | +weights = 1 |
| 29 | +spike_time_facilitation = 4 |
| 30 | +spike_time_trigger = 20 |
46 | 31 |
|
47 | | -cell_params_lif = {'cm': cm, 'i_offset': i_offset, 'tau_m': tau_m, |
48 | | - 'tau_refrac': tau_refrac, 'tau_syn_E': current_decay, |
49 | | - 'tau_syn_I': current_decay, 'v_reset': v_reset, |
50 | | - 'v_rest': v_rest, 'v_thresh': v_thresh} |
| 32 | +# set up simulation |
| 33 | +simulation_timestep = 1 # ms |
| 34 | +simulation_runtime = 100 # ms |
| 35 | +p.setup(timestep=simulation_timestep) |
51 | 36 |
|
| 37 | +# neuron parameters |
| 38 | +cell_params_semd = {'cm': 0.25, |
| 39 | + 'i_offset': 0, # offset current |
| 40 | + 'tau_m': 10, # membrane potential time constant |
| 41 | + 'tau_refrac': 1, # refractory period time constant |
| 42 | + 'tau_syn_E': 20, # excitatory current time constant |
| 43 | + 'tau_syn_I': 20, # inhibitory current time constant |
| 44 | + 'v_reset': -85, # reset potential |
| 45 | + 'v_rest': -60, # resting potential |
| 46 | + 'v_thresh': -50 # spiking threshold |
| 47 | + } |
52 | 48 |
|
53 | 49 | # neuron populations |
54 | | -sEMD = p.Population(1, p.extra_models.IF_curr_exp_sEMD(**cell_params_lif), |
55 | | - label="sEMD") |
56 | | -spikeArray = {'spike_times': [[0]]} |
57 | | -input_first = p.Population(1, p.SpikeSourceArray(**spikeArray), |
58 | | - label="input_first") |
59 | | -input_second = p.Population(1, p.SpikeSourceArray(**spikeArray), |
60 | | - label="input_second") |
| 50 | +# (population size, neuron type, cell parameters, label) |
| 51 | +sEMD = p.Population(1, p.extra_models.IF_curr_exp_sEMD, |
| 52 | + cell_params_semd, label="sEMD") |
| 53 | +input_facilitation = p.Population(1, p.SpikeSourceArray, |
| 54 | + {'spike_times': [[spike_time_facilitation]]}, |
| 55 | + label="input_facilitation") |
| 56 | +input_trigger = p.Population(1, p.SpikeSourceArray, |
| 57 | + {'spike_times': [[spike_time_trigger]]}, |
| 58 | + label="input_trigger") |
| 59 | + |
| 60 | +sEMD.initialize(v=-60.0) |
61 | 61 |
|
62 | 62 | # projections |
63 | | -p.Projection(input_first, sEMD, |
64 | | - p.OneToOneConnector(), |
65 | | - receptor_type="excitatory", |
66 | | - synapse_type=p.StaticSynapse(weight=weight, delay=delay1)) |
67 | | -p.Projection(input_second, sEMD, |
68 | | - p.OneToOneConnector(), |
69 | | - receptor_type="inhibitory", |
70 | | - synapse_type=p.StaticSynapse(weight=weight, delay=delay2)) |
| 63 | +p.Projection(input_facilitation, sEMD, p.OneToOneConnector(), |
| 64 | + p.StaticSynapse(weight=weights, delay=1), |
| 65 | + receptor_type='excitatory') |
| 66 | +p.Projection(input_trigger, sEMD, p.OneToOneConnector(), |
| 67 | + p.StaticSynapse(weight=weights, delay=1), |
| 68 | + receptor_type='excitatory2') |
71 | 69 |
|
72 | 70 | # records |
73 | | -sEMD.record(['v', 'gsyn_exc', 'gsyn_inh', 'spikes']) |
74 | | - |
75 | | -# run |
76 | | -p.run(run_time) |
| 71 | +sEMD.record(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) |
77 | 72 |
|
78 | | -# get data |
79 | | -spikes = sEMD.get_data(['spikes']) # read spikes |
80 | | -v = sEMD.get_data(['v']) # read membrane voltage |
81 | | -current_exc = sEMD.get_data(['gsyn_exc']) # read excitatory |
82 | | -current_inh = sEMD.get_data(['gsyn_inh']) # read inhibitory |
| 73 | +# run simulation |
| 74 | +p.run(simulation_runtime) |
83 | 75 |
|
84 | | -print(datum) |
| 76 | +# receive data from neurons |
| 77 | +spikes = sEMD.get_data(['spikes']) |
| 78 | +v = sEMD.get_data(['v']) |
| 79 | +current_exc = sEMD.get_data(['gsyn_exc']) |
| 80 | +current_inh = sEMD.get_data(['gsyn_inh']) |
85 | 81 |
|
86 | 82 | # plots |
87 | 83 | Figure( |
88 | | - # raster plot of the presynaptic neuron spike times |
| 84 | + # raster plot of the neuron spike times |
89 | 85 | Panel(spikes.segments[0].spiketrains, |
90 | | - yticks=True, markersize=1.5, xlim=(0, run_time)), |
91 | | - # membrane potential of the postsynaptic neuron |
| 86 | + yticks=True, markersize=4, xlim=(0, simulation_runtime)), |
| 87 | + # membrane potential |
92 | 88 | Panel(v.segments[0].filter(name='v')[0], |
93 | 89 | ylabel="Membrane potential (mV)", |
94 | | - data_labels=[sEMD.label], yticks=True, xlim=(0, run_time)), |
| 90 | + data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)), |
| 91 | + # excitatory current |
95 | 92 | Panel(current_exc.segments[0].filter(name='gsyn_exc')[0], |
96 | 93 | ylabel="gsyn excitatory (mV)", |
97 | | - data_labels=[sEMD.label], yticks=True, xlim=(0, run_time)), |
| 94 | + data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)), |
| 95 | + # inhibitory current |
98 | 96 | Panel(current_inh.segments[0].filter(name='gsyn_inh')[0], |
99 | 97 | xlabel="Time (ms)", xticks=True, |
100 | 98 | ylabel="gsyn inhibitory (mV)", |
101 | | - data_labels=[sEMD.label], yticks=True, xlim=(0, run_time)), |
| 99 | + data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)), |
102 | 100 | title="SEMD example", |
103 | 101 | annotations="Simulated with {}".format(p.name()) |
104 | 102 | ) |
105 | 103 | plt.show() |
| 104 | +# plt.savefig('results.png') |
106 | 105 |
|
107 | 106 | # end |
108 | 107 | p.end() |
0 commit comments