Description of problem
Dear all, I’m trying to simulate a neuron population receiving an external input. Specifically, neurons are all-to-all connected and have one state variable phi
evolving according to a differential model. In addition, I have an external input which is a 1-dimensional variable A
with a known value at every time instant.
To distribute this input to all neurons, at every integration step t
I want to sample one value per neuron from a normal distribution centered on A(t)
. One sampled value enters each neuron’s differential equation additively (see eq. below).
To implement this, I first create a TimedArray
of size NxT (n. neurons, n. time steps), which stores all sampled values to feed neurons at every integration step. The resulting simulation is (to the best of my knowledge) quite slow, does anybody have a better implementation to propose?
Minimal code to reproduce problem
import brian2 as br
dtime = 100*br.ms
T = 2000*br.ms
N = 5000
A = br.random.rand(int(T/dtime)) # test input
# configure
br.start_scope()
br.defaultclock.dt = dtime
# define external drive
# sample inputs to each neuron from a normal distribution centered in A[t]
samples = br.array([br.random.normal(size=N) for i in range(A.shape[0])])
A = br.TimedArray(br.tile(A,(samples.shape[1],1)).T * samples,dt=dtime)
# define equations
eqs = '''
dphi/dt = omega_int + a_int*sin(phi) + coupl + cos(phi)*A(t,i)*Hz + sigma_int*xi : 1
coupl : hertz
omega_int : hertz
a_int : hertz
sigma_int : hertz**0.5
'''
# define population
in_cond = 2*math.pi * br.np.random.uniform(size=(N))
neurons = br.NeuronGroup(N,eqs,method='heun')
neurons.phi = in_cond
neurons.omega_int = 1*br.Hz
neurons.a_int = 1*br.Hz
neurons.sigma_int = 1*br.Hz**0.5
# define connections
J = 1*br.Hz
conn = br.Synapses(neurons,neurons,'coupl_post = J/N_pre*sin(phi_pre-phi_post) : hertz (summed)')
conn.connect(p=1)
# define monitor
activity = br.StateMonitor(neurons,'phi',record=True,dt=dtime)
# run
br.run(T)
What you have aready tried
I have some ideas on what might be slowing down my simulation:
- Creating the whole TimedArray before simulating requires a slow access to each of its elements during the simulation?
- A StateMonitor recording a variable at every timestep is a slow operation?
I think I need a more educated opinion on how to efficiently use brian2.
Expected output (if relevant)
Simulating the same dynamical system, optimizing simulation time.