Neuron Spiking Code in Python
Neuron Spiking Code in Python
import numpy as np
re=np.random.rand(Ne).astype(float_type)
ri=np.random.rand(Ni).astype(float_type)
#The parameter "a" describes the time scale of the recovery variable u
a=np.concatenate((0.02*np.ones(Ne),0.02+0.08*ri)).astype(float_type)
b=np.concatenate((0.2*np.ones(Ne),0.25-0.05*ri)).astype(float_type)
#parameter c describes the after-spike reset value of the membrane potential v caused by
the fast high-threshold K+ conductance
c=np.concatenate((-65+15*re**2,-65*np.ones(Ni))).astype(float_type)
#The parameter d describes after-spike reset of the recovery variable u caused by slow h
igh-threshold Na+ and K+ conductances
d=np.concatenate((8-6*re**2,2*np.ones(Ni))).astype(float_type)
firings_ids=np.empty((Nsteps,Ne+Ni),dtype=float_type)
voltages=np.empty((Nsteps,Ne+Ni),dtype=float_type)
voltages_cropped=np.empty((Nsteps,Ne+Ni),dtype=float_type)
I=np.concatenate((5*np.random.normal(loc=0,scale=1,size=Ne),\
2*np.random.normal(loc=0,scale=1,size=Ni))).astype(float_type) # t
halamic input
C:\Users\ankit\anaconda3\lib\site-packages\ipykernel_launcher.py:5: Deprecation
Warning: `np.float` is a deprecated alias for the builtin `float`. To silence t
his warning, use `float` by itself. Doing this will not modify any behavior and
is safe. If you specifically wanted the numpy scalar type, use `np.float64` her
e.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devd
ocs/release/1.20.0-notes.html#deprecations
"""
for t in range(Nsteps):
I=np.concatenate((5*np.random.normal(loc=0,scale=1,size=Ne),\
2*np.random.normal(loc=0,scale=1,size=Ni))).astype(float_
type) # thalamic noisy input
fired=(v>=30) # finds spiking neurons indices
firings_ids[t,:]=fired
voltages[t,:]=v # I'm saving before the cropping
v[fired]=c[fired]
voltages_cropped[t,:]=v # Here I'm saving after crop
u[fired]=u[fired]+d[fired]
I=I+S[:,fired].sum(axis=1)
# Integration
v+=step*(0.04*v**2+5*v+140-u+I)
u+=step*a*(b*v-u)
ids=np.arange(1,Ne+Ni+1)
pfired = []
tfired = []
for t,fired in zip(range(Nsteps),firings_ids):
res=ids[fired==1]
for fi in res:
pfired.append(fi)
tfired.append(t)
pfired = np.array(pfired)
tfired = np.array(tfired)