Description of problem
I’m trying to test my understanding of some code:
import numpy as np
from brian2 import Synapses, NeuronGroup, ms, mV, Hz, SpikeMonitor, Network, PoissonInput
params = {
'v_0' : -52 * mV, # resting potential
'v_rst' : -52 * mV, # reset potential after spike
'v_th' : -45 * mV, # threshold for spiking
't_mbr' : 20 * ms, # membrane time scale (capacitance * resistance = .002 * uF * 10. * Mohm)
't_rfc' : 2.2 * ms,
'tau' : 5 * ms, # time constant
'r_poi' : 150 * Hz,
'f_poi' : 250,
'w_syn' :0.275 * mV,
"t_run": 1000 * ms, # duration of trial
}
if __name__ == '__main__':
connectivity_matrix = np.asarray([
[0, 5, 0],
[0, 0, -2],
[0, 0, 0],
])
eqs = '''
dv/dt = (v_0 - v + g) / t_mbr : volt (unless refractory)
dg/dt = -g / tau : volt (unless refractory)
rfc : second
'''
neu = NeuronGroup( # create neurons
N=len(connectivity_matrix),
model=eqs,
method='linear',
threshold='v > v_th',
reset='v = v_rst; w = 0; g = 0 * mV',
refractory='rfc',
name='default_neurons',
namespace=params
)
neu.v =-52 * mV
neu.g = 0
neu.rfc = 2.2 * ms
sources, targets = connectivity_matrix.nonzero()
syn = Synapses(neu, neu, 'w : volt', on_pre='g += w', delay=1.8 * ms, name='default_synapses')
syn.connect(i=sources, j=targets)
weight_per_synapse = 0.5*mV
syn.w[:] = connectivity_matrix[(sources, targets)] * weight_per_synapse
# Creating the poisson inputs
p_groups = []
for i in range(len(connectivity_matrix)):
p = PoissonInput(
target=neu[i],
target_var='v',
N=1,
rate=params['r_poi'],
weight=params['w_syn']*params['f_poi']
)
p_groups.append(p)
spike_monitor = SpikeMonitor(neu)
net = Network(neu, syn, spike_monitor, *p_groups)
net.run(duration=params['t_run'], report="stdout")
print(spike_monitor.spike_trains().values())
The above is saying
- create a collection (NeuronGroup) of 3 neurons
- create a collection of weighted synapses between the neuron groups and connect all of them according to the given connectivity matrix
- Set the weights according to the connectivity matrix
- create a
PoissonInput
where we apply a PoissonInput to each element in our circuit - create the network and join everything up
- run the network simulation
Question 1:
What’s the difference between doing
p_groups = []
for i in range(len(connectivity_matrix)):
p = PoissonInput(
target=neu[i],
target_var='v',
N=1,
rate=params['r_poi'],
weight=params['w_syn']*params['f_poi']
)
p_groups.append(p)
and doing
pois = [PoissonInput(
target=neu,
target_var='v',
N=len(neu),
rate=params['r_poi'],
weight=params['w_syn'] * params['f_poi']
)]
I came across Efficient Poisson inputs via PoissonInput and want to make sure that I’m doing things correctly…
1.1) In both cases we’re applying PoissonInputs to all elements in the network, right? The main difference is that the first method has an independent poisson process for each neuron, and the second one is using the same poisson process for all neurons? That’s my takeaway from the following quoted section
Note that the
PoissonInput
class is however more restrictive thanPoissonGroup
, it only allows for a constant rate across all neurons.
1.2) Assuming my understanding above is correct, it should be no surprise that all the neurons in my circuit have the exact spike times, right? If I want more “interesting” dynamics, I might want to create multiple PoissonInput
collections?
I ask because my connectivity matrix of interest is (3000, 3000) in size, and if I’m trying to simulate applying a current to each neuron, the for-loop
method is very slow. To be fair, the performance is pretty good when I’m doing the for-loop
method on 300 of the neurons in that (3k, 3k) connectivity matrix.
1.3) What is the purpose of the N
? I opened the documentation, but I don’t really understand it.
Question 2:
The code above also takes into account incoming signal from “upstream” neurons, right? i.e. if an upstream neuron spikes then we would have a correspondingly higher membrane potential than another neuron that didn’t have an upstream neuron spike?
Question 4:
brian2 can handle negative synapse weights, right? Where the negative indicates an inhibitory connection? My code should be fine?