How to simulate COBA synapse and Izhikevich neuron in Brian 2?

419 views
Skip to first unread message

Xu Zhang

unread,
Dec 18, 2015, 2:17:50 PM12/18/15
to Brian

I'm trying to build a simple SNN in Brian 2 using the same neuron model and synapse model in CarlSim, which is a C++ simulator of SNNs. But I can't make them to fire even fire with similar frequencies given the same inputs. Below is the synapse model described in CarlSim's Website. After that is my brian 2 code for modeling the 4 parameters Izhikevich neuron and this COBA synapse.  



 from brian2 import *

import numpy

import matplotlib

from matplotlib import pylab, mlab, pyplot

np = numpy

plt = pyplot

from IPython.display import display

from IPython.core.pylabtools import figsize, getfigs

from pylab import *

from numpy import *

from brian2 import PopulationRateMonitor

import timeit

plt.close('all')


start_scope()

start = timeit.default_timer()


dt = 0.5*ms # simulation time step

tauAP = 5*ms # synaptic time constant (ms)

tauNM=150*ms

vrevAMPA=0

vNMDArev=0

eqs = '''

dv/dt = (0.04*v**2 + 5*v + 140 - u -Ie+Iinj)/ms : 1

du/dt = a*(b*v - u)/ms : 1

dgAMPA/dt = -gAMPA/tauAP : 1

dgNMDA/dt = -gNMDA/tauNM : 1

Ie = gAMPA*(v-vrevAMPA)+gNMDA*((((v+80)/(60.0))**2/(1+((v+80)/(60.0))**2)))*(v-vNMDArev) : 1

Iinj : 1

a : 1

b : 1

c : 1

d : 1

'''


N = 7

G = NeuronGroup(N, eqs, clock=Clock(dt), threshold = 'v >= 30', reset = '''

v = c

u = u + d

''')

G.a = 0.02

G.b = 0.2

G.c = -65.0

G.d = 8.0

G.v = -65.0

G.u = G.b*(G.v)

G.gAMPA=0

G.gNMDA=0

'''inputcase=[[0,0,3,0],[0, 0, 0, 3],[0, 3, 3, 0],[0, 3, 0, 3],[3, 0, 3, 0],[3, 0, 0, 3]];

targOut=[[120,0],[0,120],[0,120],[0,120],[120,0],[120,0]]'''

N1pre=0

N2pre=0

N3pre=0

N4pre=0

N5pre=0

'''figure(figsize=(10,4))

plot(rmsetot[1:-1])

xlabel('Test epoch')

ylabel('RMSE')'''

N6pre=0

N7pre=0


'''print(inputcase[1][:])'''


S = Synapses(G, G,'w : 1', pre='''gAMPA+= w

gNMDA+=w''')


S.connect(0,2)

S.connect(1,2)

S.connect(2,3)

S.connect(2,4)

S.connect(0,5)

S.connect(1,6)

S.connect(3,5)

S.connect(4,6)

#S.w = '0.5'

S.delay[:] = '1*ms'


S.w=[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]


def visualise_connectivity(S):

figure(figsize=(10,4))

plot([2,5,3,4,2,5],[5,5,3,3,1,1],'ok',ms=20)

plot(3.5,4,'or',ms=20)

plot([2,3.5],[5,4],'-k')

plot([5,3.5],[5,4],'-k')

plot([3.5,3],[4,3],'-r')

plot([3.5,4],[4,3],'-r')

plot([3,2],[3,1],'-k')

plot([4,5],[3,1],'-k')

plot([2,2],[5,1],'-k')

plot([5,5],[5,1],'-k')

xlim(1,6)

ylim(0,6)

'''def visualise_connectivity(S):

Ns = len(S.source)

Nt = len(S.target)

figure(figsize=(10, 4))

subplot(121)

plot(zeros(Ns), arange(Ns), 'ok', ms=10)

plot(ones(Nt), arange(Nt), 'ok', ms=10)

for i, j in zip(S.i, S.j):

plot([0, 1], [i, j], '-k')

xticks([0, 1], ['Source', 'Target'])

ylabel('Neuron index')

xlim(-0.1, 1.1)

ylim(-1, max(Ns, Nt))

subplot(122)

plot(S.i, S.j, 'ok')

xlim(-1, Ns)

ylim(-1, Nt)

xlabel('Source neuron index')

ylabel('Target neuron index')'''

#visualise_connectivity(S)

#plt.show()


M = StateMonitor(G, 'v', record=True)

spikemon = SpikeMonitor(G)

R = PopulationRateMonitor(G)

rmsepre=[]

rmsepost=[]

rmsetot=[]

rmsePre=3000

learningR=0.15

Tmax=1000.0

G.Iinj=[0, 0, 0, 4, 0, 0, 0];

print('length of spikemon is %d',len(spikemon))

run(Tmax*ms)

print('length of spikemon is %d',len(spikemon))


stop = timeit.default_timer()


print stop - start

figure(1)

plot(spikemon.t/ms, spikemon.i, '.k')

xlabel('Time (ms)')

ylabel('Neuron index')

title('Excitatory Neurons')

show()

Dan Goodman

unread,
Dec 22, 2015, 12:58:24 PM12/22/15
to brians...@googlegroups.com
Hi,

If you have equivalent equations it should give the same results. One
thing that is difficult to get right with the Izhikevich neuron is the
units, since Brian insists on it being dimensionally consistent (which
the standard formulation of the Izhikevich neuron is not).

You might try this as a starting point (Brian 1 code, but easily
converted to Brian 2):

https://github.com/brian-team/brian/blob/master/dev/unfinished_examples/frompapers/Izhikevich_2006_Polychronization.py

Dan

On 18/12/2015 19:17, Xu Zhang wrote:
> I'm trying to build a simple SNN in Brian 2 using the same neuron model
> and synapse model in CarlSim, which is a C++ simulator of SNNs. But I
> can't make them to fire even fire with similar frequencies given the
> same inputs. Below is the synapse model described in CarlSim's Website.
> After that is my brian 2 code for modeling the 4 parameters Izhikevich
> neuron and this COBA synapse.
>
>
> <https://lh3.googleusercontent.com/-ctGBNJAok2g/VnRXbTx3KzI/AAAAAAAACKg/-_GvOLTKIj8/s1600/temp.png>
>
>
> from brian2 import *
>
> import numpy
>
> import matplotlib
>
> from matplotlib import pylab, mlab, pyplot
>
> np = numpy
>
> plt = pyplot
>
> from IPython.display import display
>
> from IPython.core.pylabtools import figsize, getfigs
>
> from pylab import *
>
> from numpy import *
>
> from brian2 import PopulationRateMonitor
>
> import timeit
>
> plt.close('all')
>
>
> start_scope()
>
> start = timeit.default_timer()
>
>
> dt = 0.5*ms# simulation time step
>
> tauAP = 5*ms# synaptic time constant (ms)
> --
> http://www.facebook.com/briansimulator
> https://twitter.com/briansimulator
>
> New paper about Brian 2: Stimberg M, Goodman DFM, Benichoux V, Brette R
> (2014).Equation-oriented specification of neural models for simulations.
> Frontiers Neuroinf, doi: 10.3389/fninf.2014.00006.
> ---
> You received this message because you are subscribed to the Google
> Groups "Brian" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to briansupport...@googlegroups.com
> <mailto:briansupport...@googlegroups.com>.
> To post to this group, send email to brians...@googlegroups.com
> <mailto:brians...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/briansupport.
> For more options, visit https://groups.google.com/d/optout.

Xu Zhang

unread,
Jan 5, 2016, 4:48:23 PM1/5/16
to Brian
Thank you for your reply. Yes, I implemented the neurons using the same equations. But the problem is that Brian 2 seems implement the alpha synapse using a differential equations while CarlSim directly use summation of exponentials, which is the analytical solution of the differential equation. This might lead to the problem. In other words, is there a way to simulate conductance as a exponential decay using \sum{e^{-t-tf}} other than write it as an ODE?

Dan Goodman

unread,
Jan 6, 2016, 10:00:57 AM1/6/16
to brians...@googlegroups.com
There's no way to do that, you'll need to write it as an ODE, but for an
alpha synapse it's a straightforward ODE. Just make sure the constants
are the same and the behaviour should be equivalent unless you're
getting numerical instability issues (in which case, try different
solvers and/or reducing the time step dt).

Dan
> <http://www.facebook.com/briansimulator>
> > https://twitter.com/briansimulator
> <https://twitter.com/briansimulator>
> >
> > New paper about Brian 2: Stimberg M, Goodman DFM, Benichoux V,
> Brette R
> > (2014).Equation-oriented specification of neural models for
> simulations.
> > Frontiers Neuroinf, doi: 10.3389/fninf.2014.00006.
> > ---
> > You received this message because you are subscribed to the Google
> > Groups "Brian" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to briansupport...@googlegroups.com <javascript:>
> > <mailto:briansupport...@googlegroups.com <javascript:>>.
> > To post to this group, send email to brians...@googlegroups.com
> <javascript:>
> > <mailto:brians...@googlegroups.com <javascript:>>.
> <https://groups.google.com/group/briansupport>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> http://www.facebook.com/briansimulator
> https://twitter.com/briansimulator
>
> New paper about Brian 2: Stimberg M, Goodman DFM, Benichoux V, Brette R
> (2014).Equation-oriented specification of neural models for simulations.
> Frontiers Neuroinf, doi: 10.3389/fninf.2014.00006.
> ---
> You received this message because you are subscribed to the Google
> Groups "Brian" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to briansupport...@googlegroups.com
> <mailto:briansupport...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages