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()
> <mailto:briansupport+unsub...@googlegroups.com>.