Description of problem
How to change the weights to other neurons when a neuron fired?
The event-driven example on the Synapses page changes the weight of the neuron that fired, but not the weight to other neurons.
Minimal code to reproduce problem
So far I was able to achieve a similar goal by breaking down the simulation into smaller segments, and update the weight if the spike_mon detected spikes. But this is inaccurate and not event-driven.
from brian2 import *
eqs = '''
dv/dt = (I-v)/tau : 1
I : 1
tau : second
'''
G = NeuronGroup(3, eqs, threshold='v>1', reset='v = 0', method='exact')
G.I = [2, 0, 0]
G.tau = [10]*ms
S = Synapses(G, G, model='w : 1', on_pre='v_post += w')
S.connect(i=0,j=[1,2])
S.w = [0.5,1]
S.delay = [1, 0]*ms # add a delay to demonstrate the issue
state_mon = StateMonitor(G,'v', record=True)
spike_mon = SpikeMonitor(G)
net = Network(collect())
net.add(S)
net.add(state_mon)
net.add(spike_mon)
#total run=50ms, but break the run into 10ms segment
for seg in range(5):
net.run(10*ms)
# check if a neuron fired every 10ms
if(spike_mon.count[1] != 0 or spike_mon.count[2] != 0):
# if a neuron fired, set the other neuron's weight to 0
if(spike_mon.count[1] > spike_mon.count[2]):
S.w = [1,0]
else:
S.w = [0,1]
plt.figure(1)
plt.subplot(311)
plot(state_mon.t/ms, state_mon.v[0], label='Neuron 0')
ylim([0,1.5])
ylabel('Neuron_0')
plt.subplot(312)
plot(state_mon.t/ms, state_mon.v[1], label='Neuron 1')
ylim([0,1.5])
ylabel('Neuron_1')
plt.subplot(313)
plot(state_mon.t/ms, state_mon.v[2], label='Neuron 2')
ylim([0,1.5])
ylabel('Neuron_2')
xlabel('Time (ms)')
show()
What you have already tried
I was thinking to add a backward synapse (blue arrow in the figure) to trigger the neuron in blue to update the weight. But I couldn’t figure out what syntax I should put for the model