From c21d4264a7a576d31a519ff9eadbdb2e57e974f5 Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Tue, 24 Sep 2024 09:00:56 +0100 Subject: [PATCH 1/3] WTA connector example --- examples/wta_example.py | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 examples/wta_example.py diff --git a/examples/wta_example.py b/examples/wta_example.py new file mode 100644 index 0000000..3af66d7 --- /dev/null +++ b/examples/wta_example.py @@ -0,0 +1,70 @@ +# Copyright (c) 2017 The University of Manchester +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Demonstration of the WTA connector in use. There are two populations both +# receiving input from the same Poisson source. One population has a +# self-connection with a WTA connector, which will attempt to ensure that only +# one neuron in the population spikes at a time. As neuron 2 has a higher rate +# of input than the others, it will be the "winner" more often than the others. + +# Note that SpiNNaker does not send "instantaneous" spikes, so there can be +# times where two neurons spike in the same time step. + +# The output graph shows the difference in the outputs of the two populations. + +import pyNN.spiNNaker as sim +import matplotlib.pyplot as plt +import numpy + +sim.setup(1.0) + +pop = sim.Population(10, sim.IF_curr_exp(), label="pop") +wta = sim.Population(10, sim.IF_curr_exp(), label="wta") +stim = sim.Population( + 10, sim.SpikeSourcePoisson( + rate=[10, 10, 20, 10, 10, 10, 10, 10, 10, 10]), + label="stim") +pop.record("spikes") +wta.record("spikes") + +sim.Projection( + stim, pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=5.0)) +sim.Projection( + stim, wta, sim.OneToOneConnector(), sim.StaticSynapse(weight=5.0)) +sim.Projection( + wta, wta, sim.extra_models.WTAConnector(), sim.StaticSynapse(weight=10.0), + receptor_type="inhibitory") + +sim.run(10000) + +pop_spikes = pop.get_data("spikes").segments[0].spiketrains +wta_spikes = wta.get_data("spikes").segments[0].spiketrains + +sim.end() + +# Plot the spikes +for spiketrain in pop_spikes: + y = numpy.ones_like(spiketrain) * spiketrain.annotations["source_index"] + line, = plt.plot(spiketrain, y.magnitude * 2, "r|", + label="Without WTA") +for spiketrain in wta_spikes: + y = numpy.ones_like(spiketrain) * spiketrain.annotations["source_index"] + line_2, = plt.plot(spiketrain, (y.magnitude * 2) + 1, "b|", + label="With WTA") +plt.xlabel("Time (ms)") +plt.title("Simple example") +plt.legend(handles=[line, line_2], loc=9) +plt.ylim(-2, 24) +plt.yticks([], []) +plt.show() From af683b8eaf61191bbb7187bef708ddb1ad45d702 Mon Sep 17 00:00:00 2001 From: Andrew Rowley Date: Tue, 24 Sep 2024 09:10:48 +0100 Subject: [PATCH 2/3] Fix "spelling" --- examples/wta_example.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/wta_example.py b/examples/wta_example.py index 3af66d7..6375b14 100644 --- a/examples/wta_example.py +++ b/examples/wta_example.py @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Demonstration of the WTA connector in use. There are two populations both -# receiving input from the same Poisson source. One population has a -# self-connection with a WTA connector, which will attempt to ensure that only -# one neuron in the population spikes at a time. As neuron 2 has a higher rate -# of input than the others, it will be the "winner" more often than the others. +# Demonstration of the winner-takes-all connector in use. There are two +# populations both receiving input from the same Poisson source. One +# population has a self-connection with a winner-takes-all connector, which +# will attempt to ensure that only one neuron in the population spikes at a +# time. As neuron 2 has a higher rate of input than the others, it will be +# the "winner" more often than the others. # Note that SpiNNaker does not send "instantaneous" spikes, so there can be # times where two neurons spike in the same time step. From 370f963e152a9288f2e29094540c44714aa78cf8 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 24 Sep 2024 11:40:59 +0100 Subject: [PATCH 3/3] refactor to AllButMeConnector --- examples/wta_example.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/wta_example.py b/examples/wta_example.py index 6375b14..e7e6eef 100644 --- a/examples/wta_example.py +++ b/examples/wta_example.py @@ -44,8 +44,8 @@ sim.Projection( stim, wta, sim.OneToOneConnector(), sim.StaticSynapse(weight=5.0)) sim.Projection( - wta, wta, sim.extra_models.WTAConnector(), sim.StaticSynapse(weight=10.0), - receptor_type="inhibitory") + wta, wta, sim.extra_models.AllButMeConnector(), + sim.StaticSynapse(weight=10.0), receptor_type="inhibitory") sim.run(10000) @@ -58,11 +58,11 @@ for spiketrain in pop_spikes: y = numpy.ones_like(spiketrain) * spiketrain.annotations["source_index"] line, = plt.plot(spiketrain, y.magnitude * 2, "r|", - label="Without WTA") + label="Without AllButMe") for spiketrain in wta_spikes: y = numpy.ones_like(spiketrain) * spiketrain.annotations["source_index"] line_2, = plt.plot(spiketrain, (y.magnitude * 2) + 1, "b|", - label="With WTA") + label="With AllButMe") plt.xlabel("Time (ms)") plt.title("Simple example") plt.legend(handles=[line, line_2], loc=9)