# Create excitatory and inhibitory populations in Brian2

Hello,
Thank you @mstimberg for the Brain2 tutorial projects yesterday !

I was trying to do the project on sustained activity, based on the code here: https://github.com/brian-team/brian-material/blob/master/2020-08-Brian-online-tutorial/project/project_start.ipynb.

I’d like to know if this approach for creating excitatory and inhibitory populations is ok:

``````tau = 10*ms # Membrane time constant of the neuron
sigma_noise = 0.5 # Noise strength
sigma_theta = pi/8 # stimulus sensitivity
N_E = 200 # number of excitatory neurons
N_I = 200 # number of inhibitory neurons
eqs = '''
dv/dt = (-v + I_stim)/tau + sigma_noise*xi*tau**-0.5: 1
theta : 1 (constant)
theta_stim: 1
amp_stim: 1
stimulus_diff = (theta - theta_stim + pi)%(2*pi) - pi : radian
I_stim = amp_stim*exp(-stimulus_diff**2/(2*sigma_theta)**2) : 1
'''
neurons = NeuronGroup(N_E+N_I, eqs, threshold='v>1', reset='v=0', method='euler')
neurons.v = 'rand()*0.5'

exc_neurons = neurons[:N_E]
inh_neurons = neurons[N_E:]

exc_neurons.theta_stim = 0
exc_neurons.amp_stim = 2
exc_neurons.theta = '-pi + 2*pi*i/N_E'

# inhibitory neurones are just like excitatory but don't receive stimulation
inh_neurons.amp_stim = 0

# general synapses (are all excitatory)
S = Synapses(neurons, neurons, 'w:1', on_pre="v+=w")

# synapses of the excitatory pop
exc_S = Synapses(exc_neurons, exc_neurons, 'w:1', on_pre="v+=w")

# synapses of the inhibitory pop decrease v of the excitatory pop
inh_S = Synapses(inh_neurons, exc_neurons, 'w:1', on_pre="v-=w")

S.connect(p=0.1, condition="i!=j") # general synapses

# excitatory synapses are preferentially connected with those of similar sensitivity
exc_S.connect(p="0.3*exp(-((theta_pre-theta_post+pi)%(2*pi)-pi)**2/(pi/4)**2)", condition="i!=j")

# neurones in the inhibitory pop connect with the excitatory pop
inh_S.connect(p=0.5)

# all synapses have a fixed weight
S.w = 0.02
``````

Hi @rto, the code looks mostly good to me! There’s always a bit of a trade-off when deciding how to implement several groups of neurons. Here, you use a single group and two subgroups which is in general more efficient than using two independent groups. On the other hand, I would rather tend to using two separate `NeuronGroup`s here, because I find it a bit unintuitive that the inhibitory neurons also include the equations for the input, but multiply it with 0 (which also means that they still need to perform the calculation). But this is mostly a matter of choice, I don’t think you’d see much difference performance-wise.
Similarly, since you have a single `NeuronGroup` for all of your neurons, you could have actually used a single `Synapses` object here for both excitatory and inhibitory neurons as well. `v += w` can be inhibitory if `w` is negative
I am not quite sure what the “general synapses” are, though? Oh, and it looks as if you are not setting the weights of `exc_S` and `inh_S` which means that they all have zero weight!