Conditional Excitation of Neurons - Is it possible?

Description of problem

I’m not that experienced with Brian2, so this may be a stupid question, but I’m trying I want to know whether a neuron can excite conditionally, so I have 5 neurons, neuron 0 is connected to neurons 1, 2, 3, 4
I have a LIF model and I want it so when an input voltage is put into neuron 0 AND condition 1 == True, then neuron 1 is excited. If condition 2 is true, neuron 2 is excited etc.
I know what I want my system to do, but I’m not sure how to do it.
Sorry if this was explained badly. Do I need to change my equation?

Minimal code to reproduce problem

lif = '''
dv/dt = -(gl * (v - vl) + ge * (v - ve) + gi *(ve - vi) - I)/c : volt
dge/dt = -ge / ge_tau : siemens
dgi/dt = -gi / gi_tau : siemens
I : amp
'''

'''
If neuron 0 has an input voltage AND cell0 = True, excite neuron 1
If neuron 0 has an input voltage AND cell1 = True, excite neuron 2
If neuron 0 has an input voltage AND cell2 = True, excite neuron 3
If neuron 0 has an input voltage AND cell3 = True, excite neuron 4
'''

# 1st to 2nd layer
G = NeuronGroup(5, lif, threshold='v > -40*mV',
                reset='v = vl', refractory=3*ms, method='euler')
G.I = [0.7, 0, 0, 0, 0]*nA      # input current for 0, 1, 2, 3, 4 neurons
G.v = [-70, -70, -70, -70, -70]*mV    # intial voltage for 0, 1, 2, 3, 4 neurons (resting V)

# Se = excitory connection
# Si = inhibitory connection
Se = Synapses(G, G, on_pre='ge_post += w_ge')
Se.connect(i=0, j=1)
Se.connect(i=0, j=2)
Se.connect(i=0, j=3)
Se.connect(i=0, j=4)

What you have already tried

I’ve looked through the documentation thoroughly and found nothing that can help with my problem

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

Hi @Autopilot. Not a stupid question at all, and I’m fairly sure you can do this. The details depend on your condition – where does this condition come from, and how does it change whether it is fulfilled or not? For example, if your condition is just some kind of “selection flag” in each neuron, you could do something like this:

lif = '''
dv/dt = -(gl * (v - vl) + ge * (v - ve) - I)/c : volt
dge/dt = -ge / ge_tau : siemens
I : amp (constant)
selected : boolean
'''
G = NeuronGroup(5, lif, threshold='v > -40*mV',
                reset='v = vl', refractory=3*ms, method='euler')
G.I[0] = 0.7*nA  # input current for neuron 0
G.v = -70*mV
# every 20ms, select each neuron with 25% probability
G.run_regularly('selected = rand() < 0.25', dt=20*ms)
# Propagate spikes to all neurons, but multiply the weight with 0 or 1
# depending whether the neuron is selected or not
Se = Synapses(G, G, on_pre='ge_post += w_ge * int(selected_post)')
Se.connect(i=0, j=[1, 2, 3, 4])

This gives something like this:
select1

The above model will select each neuron independently, so there could be more than one selected at once. If you only want to have a single neuron selected at a time, you can instead draw a random index and compare to that:

lif = '''
dv/dt = -(gl * (v - vl) + ge * (v - ve) - I)/c : volt
dge/dt = -ge / ge_tau : siemens
I : amp (constant)
selected_index : integer (shared)  # single variable
'''
G = NeuronGroup(5, lif, threshold='v > -40*mV',
                reset='v = vl', refractory=3*ms, method='euler')
G.I[0] = 0.7*nA  # input current for neuron 0
G.v = -70*mV
# every 20ms, select a random index between 1 and 4
G.run_regularly('selected_index = 1 + int(rand()*4)', dt=20*ms)
# Propagate spikes to all neurons, but multiply the weight with 0 or 1
# depending whether the postsynaptic index ('j') equals the selected
# index
Se = Synapses(G, G, on_pre='ge_post += w_ge * int(selected_index_post == j)')
Se.connect(i=0, j=[1, 2, 3, 4])

Hope that was what you had in mind? Best
Marcel