Skip to content

Commit 21a6e92

Browse files
committed
merged in master
2 parents 4d35621 + 29b8e79 commit 21a6e92

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

examples/wta_example.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2017 The University of Manchester
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Demonstration of the winner-takes-all connector in use. There are two
16+
# populations both receiving input from the same Poisson source. One
17+
# population has a self-connection with a winner-takes-all connector, which
18+
# will attempt to ensure that only one neuron in the population spikes at a
19+
# time. As neuron 2 has a higher rate of input than the others, it will be
20+
# the "winner" more often than the others.
21+
22+
# Note that SpiNNaker does not send "instantaneous" spikes, so there can be
23+
# times where two neurons spike in the same time step.
24+
25+
# The output graph shows the difference in the outputs of the two populations.
26+
27+
import pyNN.spiNNaker as sim
28+
import matplotlib.pyplot as plt
29+
import numpy
30+
31+
sim.setup(1.0)
32+
33+
pop = sim.Population(10, sim.IF_curr_exp(), label="pop")
34+
wta = sim.Population(10, sim.IF_curr_exp(), label="wta")
35+
stim = sim.Population(
36+
10, sim.SpikeSourcePoisson(
37+
rate=[10, 10, 20, 10, 10, 10, 10, 10, 10, 10]),
38+
label="stim")
39+
pop.record("spikes")
40+
wta.record("spikes")
41+
42+
sim.Projection(
43+
stim, pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=5.0))
44+
sim.Projection(
45+
stim, wta, sim.OneToOneConnector(), sim.StaticSynapse(weight=5.0))
46+
sim.Projection(
47+
wta, wta, sim.extra_models.AllButMeConnector(),
48+
sim.StaticSynapse(weight=10.0), receptor_type="inhibitory")
49+
50+
sim.run(10000)
51+
52+
pop_spikes = pop.get_data("spikes").segments[0].spiketrains
53+
wta_spikes = wta.get_data("spikes").segments[0].spiketrains
54+
55+
sim.end()
56+
57+
# Plot the spikes
58+
for spiketrain in pop_spikes:
59+
y = numpy.ones_like(spiketrain) * spiketrain.annotations["source_index"]
60+
line, = plt.plot(spiketrain, y.magnitude * 2, "r|",
61+
label="Without AllButMe")
62+
for spiketrain in wta_spikes:
63+
y = numpy.ones_like(spiketrain) * spiketrain.annotations["source_index"]
64+
line_2, = plt.plot(spiketrain, (y.magnitude * 2) + 1, "b|",
65+
label="With AllButMe")
66+
plt.xlabel("Time (ms)")
67+
plt.title("Simple example")
68+
plt.legend(handles=[line, line_2], loc=9)
69+
plt.ylim(-2, 24)
70+
plt.yticks([], [])
71+
plt.show()

0 commit comments

Comments
 (0)