Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 56 additions & 57 deletions examples/extra_models_examples/IF_curr_exp_sEMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,96 +13,95 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


"""
Spiking Elementary Motion Detector (sEMD) example
Spiking ELementary Motion Detector (sEMD) example
See https://www.cit-ec.de/en/nbs/spiking-insect-vision for more details
"""

# imports
import spynnaker8 as p
import datetime
from pyNN.utility.plotting import Figure, Panel
import matplotlib.pyplot as plt
from pyNN.utility.plotting import Figure, Panel

# parameters
datum = datetime.datetime.now()

step = 0.1
p.setup(timestep=step)
n_neurons = 1
run_time = 150
cm = 0.25
i_offset = 0.0
tau_m = 20.0
tau_refrac = 1.0
current_decay = tau_syn_E = tau_syn_I = 30
v_reset = -85.0
v_rest = -65.0
v_thresh = -50.0

weight = 1
delay1 = 0.1
delay2 = 2.0
# variables
weights = 1
spike_time_facilitation = 4
spike_time_trigger = 20

cell_params_lif = {'cm': cm, 'i_offset': i_offset, 'tau_m': tau_m,
'tau_refrac': tau_refrac, 'tau_syn_E': current_decay,
'tau_syn_I': current_decay, 'v_reset': v_reset,
'v_rest': v_rest, 'v_thresh': v_thresh}
# set up simulation
simulation_timestep = 1 # ms
simulation_runtime = 100 # ms
p.setup(timestep=simulation_timestep)

# neuron parameters
cell_params_semd = {'cm': 0.25,
'i_offset': 0, # offset current
'tau_m': 10, # membrane potential time constant
'tau_refrac': 1, # refractory period time constant
'tau_syn_E': 20, # excitatory current time constant
'tau_syn_I': 20, # inhibitory current time constant
'v_reset': -85, # reset potential
'v_rest': -60, # resting potential
'v_thresh': -50 # spiking threshold
}

# neuron populations
sEMD = p.Population(1, p.extra_models.IF_curr_exp_sEMD(**cell_params_lif),
label="sEMD")
spikeArray = {'spike_times': [[0]]}
input_first = p.Population(1, p.SpikeSourceArray(**spikeArray),
label="input_first")
input_second = p.Population(1, p.SpikeSourceArray(**spikeArray),
label="input_second")
# (population size, neuron type, cell parameters, label)
sEMD = p.Population(1, p.extra_models.IF_curr_exp_sEMD,
cell_params_semd, label="sEMD")
input_facilitation = p.Population(1, p.SpikeSourceArray,
{'spike_times': [[spike_time_facilitation]]},
label="input_facilitation")
input_trigger = p.Population(1, p.SpikeSourceArray,
{'spike_times': [[spike_time_trigger]]},
label="input_trigger")

sEMD.initialize(v=-60.0)

# projections
p.Projection(input_first, sEMD,
p.OneToOneConnector(),
receptor_type="excitatory",
synapse_type=p.StaticSynapse(weight=weight, delay=delay1))
p.Projection(input_second, sEMD,
p.OneToOneConnector(),
receptor_type="inhibitory",
synapse_type=p.StaticSynapse(weight=weight, delay=delay2))
p.Projection(input_facilitation, sEMD, p.OneToOneConnector(),
p.StaticSynapse(weight=weights, delay=1),
receptor_type='excitatory')
p.Projection(input_trigger, sEMD, p.OneToOneConnector(),
p.StaticSynapse(weight=weights, delay=1),
receptor_type='excitatory2')

# records
sEMD.record(['v', 'gsyn_exc', 'gsyn_inh', 'spikes'])

# run
p.run(run_time)
sEMD.record(['spikes', 'v', 'gsyn_exc', 'gsyn_inh'])

# get data
spikes = sEMD.get_data(['spikes']) # read spikes
v = sEMD.get_data(['v']) # read membrane voltage
current_exc = sEMD.get_data(['gsyn_exc']) # read excitatory
current_inh = sEMD.get_data(['gsyn_inh']) # read inhibitory
# run simulation
p.run(simulation_runtime)

print(datum)
# receive data from neurons
spikes = sEMD.get_data(['spikes'])
v = sEMD.get_data(['v'])
current_exc = sEMD.get_data(['gsyn_exc'])
current_inh = sEMD.get_data(['gsyn_inh'])

# plots
Figure(
# raster plot of the presynaptic neuron spike times
# raster plot of the neuron spike times
Panel(spikes.segments[0].spiketrains,
yticks=True, markersize=1.5, xlim=(0, run_time)),
# membrane potential of the postsynaptic neuron
yticks=True, markersize=4, xlim=(0, simulation_runtime)),
# membrane potential
Panel(v.segments[0].filter(name='v')[0],
ylabel="Membrane potential (mV)",
data_labels=[sEMD.label], yticks=True, xlim=(0, run_time)),
data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)),
# excitatory current
Panel(current_exc.segments[0].filter(name='gsyn_exc')[0],
ylabel="gsyn excitatory (mV)",
data_labels=[sEMD.label], yticks=True, xlim=(0, run_time)),
data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)),
# inhibitory current
Panel(current_inh.segments[0].filter(name='gsyn_inh')[0],
xlabel="Time (ms)", xticks=True,
ylabel="gsyn inhibitory (mV)",
data_labels=[sEMD.label], yticks=True, xlim=(0, run_time)),
data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)),
title="SEMD example",
annotations="Simulated with {}".format(p.name())
)
plt.show()
# plt.savefig('results.png')

# end
p.end()