Skip to content

Commit 1a9f3c1

Browse files
authored
Merge pull request #28 from SpiNNakerManchester/sEMD_updates
Update sEMD example based on changes to new sEMD user's current scripts
2 parents 608de9b + 694cae1 commit 1a9f3c1

1 file changed

Lines changed: 56 additions & 57 deletions

File tree

examples/extra_models_examples/IF_curr_exp_sEMD.py

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,95 @@
1313
# You should have received a copy of the GNU General Public License
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16+
1617
"""
17-
Spiking Elementary Motion Detector (sEMD) example
18+
Spiking ELementary Motion Detector (sEMD) example
1819
See https://www.cit-ec.de/en/nbs/spiking-insect-vision for more details
1920
"""
2021

2122
# imports
2223
import spynnaker8 as p
23-
import datetime
24-
from pyNN.utility.plotting import Figure, Panel
2524
import matplotlib.pyplot as plt
25+
from pyNN.utility.plotting import Figure, Panel
2626

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
4631

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)
5136

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+
}
5248

5349
# 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)
6161

6262
# 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')
7169

7270
# 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'])
7772

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)
8375

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'])
8581

8682
# plots
8783
Figure(
88-
# raster plot of the presynaptic neuron spike times
84+
# raster plot of the neuron spike times
8985
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
9288
Panel(v.segments[0].filter(name='v')[0],
9389
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
9592
Panel(current_exc.segments[0].filter(name='gsyn_exc')[0],
9693
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
9896
Panel(current_inh.segments[0].filter(name='gsyn_inh')[0],
9997
xlabel="Time (ms)", xticks=True,
10098
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)),
102100
title="SEMD example",
103101
annotations="Simulated with {}".format(p.name())
104102
)
105103
plt.show()
104+
# plt.savefig('results.png')
106105

107106
# end
108107
p.end()

0 commit comments

Comments
 (0)