Skip to content

Commit 6340ca8

Browse files
committed
neuromodulation with vogels_2011 additive
1 parent 25ebc6e commit 6340ca8

2 files changed

Lines changed: 155 additions & 6 deletions

File tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
"""
16+
Simple test for neuromodulated-STDP
17+
We take 10 populations of 5 stimuli neurons and connect to each
18+
10 post-synaptic populations of 5 neurons. The spiking of stimuli causes some
19+
spikes in post-synaptic neurons initially.
20+
We then inject reward signals from dopaminergic neurons
21+
periodically to reinforce synapses that are active. This
22+
is followed by increased weights of some synapses and thus
23+
increased response to the stimuli.
24+
We then proceed to inject punishment signals from dopaminergic
25+
neurons which causes an inverse effect to reduce response of
26+
post-synaptic neurons to the same stimuli.
27+
"""
28+
29+
import pyNN.spiNNaker as sim
30+
import pylab
31+
32+
timestep = 1.0
33+
stim_rate = 50
34+
duration = 12000
35+
plastic_weights = 1.5
36+
n_neurons = 5
37+
n_pops = 10
38+
39+
# Times of rewards and punishments
40+
rewards = [x for x in range(2000, 2010)] + \
41+
[x for x in range(3000, 3020)] + \
42+
[x for x in range(4000, 4100)]
43+
punishments = [x for x in range(6000, 6010)] + \
44+
[x for x in range(7000, 7020)] + \
45+
[x for x in range(8000, 8100)]
46+
47+
cell_params = {'cm': 0.25,
48+
'i_offset': 0.0,
49+
'tau_m': 20.0,
50+
'tau_refrac': 2.0,
51+
'tau_syn_E': 1.0,
52+
'tau_syn_I': 1.0,
53+
'v_reset': -70.0,
54+
'v_rest': -65.0,
55+
'v_thresh': -50.0
56+
}
57+
58+
sim.setup(timestep=timestep)
59+
60+
# Create a population of dopaminergic neurons for reward and punishment
61+
reward_pop = sim.Population(n_neurons, sim.SpikeSourceArray,
62+
{'spike_times': rewards}, label='reward')
63+
punishment_pop = sim.Population(n_neurons, sim.SpikeSourceArray,
64+
{'spike_times': punishments},
65+
label='punishment')
66+
67+
pre_pops = []
68+
stimulation = []
69+
post_pops = []
70+
reward_projections = []
71+
punishment_projections = []
72+
plastic_projections = []
73+
stim_projections = []
74+
75+
# Create synapse dynamics with neuromodulated STDP.
76+
synapse_dynamics = sim.STDPMechanism(
77+
timing_dependence=sim.extra_models.Vogels2011Rule(
78+
alpha=0.12, tau=20.0, A_plus=0.05),
79+
weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=20),
80+
weight=plastic_weights)
81+
82+
for i in range(n_pops):
83+
stimulation.append(sim.Population(n_neurons, sim.SpikeSourcePoisson,
84+
{'rate': stim_rate, 'duration': duration}, label="pre"))
85+
post_pops.append(sim.Population(
86+
n_neurons, sim.IF_curr_exp, cell_params, label='post'))
87+
plastic_projections.append(
88+
sim.Projection(stimulation[i], post_pops[i],
89+
sim.OneToOneConnector(),
90+
synapse_type=synapse_dynamics,
91+
receptor_type='excitatory',
92+
label='Pre-post projection'))
93+
post_pops[i].record('spikes')
94+
reward_projections.append(sim.Projection(
95+
reward_pop, post_pops[i], sim.OneToOneConnector(),
96+
synapse_type=sim.extra_models.Neuromodulation(
97+
weight=0.05, tau_c=100.0, tau_d=5.0, w_max=20.0),
98+
receptor_type='reward', label='reward synapses'))
99+
punishment_projections.append(sim.Projection(
100+
punishment_pop, post_pops[i], sim.OneToOneConnector(),
101+
synapse_type=sim.extra_models.Neuromodulation(
102+
weight=0.05, tau_c=100.0, tau_d=5.0, w_max=20.0),
103+
receptor_type='punishment', label='punishment synapses'))
104+
105+
sim.run(duration)
106+
107+
# Graphical diagnostics
108+
109+
110+
def plot_spikes(_spikes, _title, _n_neurons):
111+
"""
112+
Plots the spikes if there are any.
113+
114+
:param list([int, quantity]) _spikes:
115+
:param str _title:
116+
:param int _n_neurons:
117+
"""
118+
if _spikes is not None:
119+
pylab.figure(figsize=(15, 5))
120+
pylab.xlim((0, duration))
121+
pylab.ylim((0, (10 * _n_neurons) + 1))
122+
pylab.plot([i[1] for i in _spikes], [i[0] for i in _spikes], ".")
123+
pylab.xlabel('Time/ms')
124+
pylab.ylabel('spikes')
125+
pylab.title(_title)
126+
else:
127+
print("No spikes received")
128+
129+
130+
post_spikes = []
131+
weights = []
132+
133+
for i in range(n_pops):
134+
weights.append(plastic_projections[i].get('weight', 'list'))
135+
spikes = post_pops[i].get_data('spikes').segments[0].spiketrains
136+
for j in range(n_neurons):
137+
for x in spikes[j]:
138+
post_spikes.append([(i*n_neurons)+j+1, x])
139+
140+
plot_spikes(post_spikes, "post-synaptic neuron activity", n_neurons)
141+
pylab.plot(rewards, [0.5 for x in rewards], 'g^')
142+
pylab.plot(punishments, [0.5 for x in punishments], 'r^')
143+
pylab.show()
144+
145+
print("Weights(Initial {plastic_weights})")
146+
for x in weights:
147+
print(x)
148+
149+
sim.end()

integration_tests/test_scripts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ def test_examples_split_examples_pynnBrunnelSplit(self):
5151
def test_examples_split_examples_va_benchmark_split(self):
5252
self.check_script("examples/split_examples/va_benchmark_split.py")
5353

54-
def test_examples_balanced_random_balanced_random(self):
55-
self.check_script("examples/balanced_random/balanced_random.py")
56-
57-
def test_examples_balanced_random_split_balanced_random_split(self):
58-
self.check_script("examples/balanced_random/split/balanced_random_split.py")
59-
6054
def test_examples_synfire_if_curr_exp_random(self):
6155
self.check_script("examples/synfire_if_curr_exp_random.py")
6256

@@ -162,6 +156,9 @@ def test_examples_extra_models_examples_vogel_2011_vogels_2011_live(self):
162156
def test_examples_extra_models_examples_vogel_2011_vogels_2011(self):
163157
self.check_script("examples/extra_models_examples/vogel_2011/vogels_2011.py")
164158

159+
def test_examples_extra_models_examples_stdp_neuromodulated_vogels(self):
160+
self.check_script("examples/extra_models_examples/stdp_neuromodulated_vogels.py")
161+
165162
def test_examples_extra_models_examples_stdp_associative_memory(self):
166163
self.check_script("examples/extra_models_examples/stdp_associative_memory.py")
167164

@@ -186,6 +183,9 @@ def test_examples_extra_models_examples_IF_curr_exp_ca2_adaptive(self):
186183
def test_examples_extra_models_examples_IF_cond_exp_stoc(self):
187184
self.check_script("examples/extra_models_examples/IF_cond_exp_stoc.py")
188185

186+
def test_examples_wta_example(self):
187+
self.check_script("examples/wta_example.py")
188+
189189
def test_balanced_random_balanced_random(self):
190190
self.check_script("balanced_random/balanced_random.py")
191191

0 commit comments

Comments
 (0)