Package: npbrain
Note:NumpyBrain is a project under development.More features are coming soon. Contributions are welcome.Why to use NumpyBrainNumpyBrainis a microkernel framework for SNN (spiking neural network) simulation
purely based onnativepython. It only relies onNumPy.
However, if you want to get faster performance,you can additionally
installNumba. WithNumba, the speed of C or FORTRAN can
be obtained in the simulation.NumpyBrainwants to provide a highly flexible and efficient SNN simulation
framework for Python users. It endows the users with the fully data/logic flow control.
The core of the framework is a micro-kernel, and it’s easy to understand (seeHow NumpyBrain works).
Based on the kernel, the extension of the new models or the customization of the
data/logic flows are very simple for users. Ample examples (such as LIF neuron,
HH neuron, or AMPA synapse, GABA synapse and GapJunction) are also provided.
Besides the consideration offlexibility, for accelerating the runningspeedof NumPy codes,Numbais used. For most of the times,
models running onNumbabackend is very fast
(seeexamples/benchmark).More details about NumpyBrain please see ourdocument.InstallationInstallNumpyBrainusingpip:$> pip install git+https://github.com/PKU-NIP-Lab/NumpyBrainInstall from source code:$> python setup.py installThe following packages need to be installed to useNumpyBrain:Python >= 3.5NumPy >= 1.13Sympy >= 1.2Matplotlib >= 2.0autopep8Packages recommended to install:Numba >= 0.40.0JAX >= 0.1.0Define a Hodgkin–Huxley neuron modelimportnpbrain.numpyasnpimportnpbrainasnbdefHH(noise=0.,E_Na=50.,g_Na=120.,E_K=-77.,g_K=36.,E_Leak=-54.387,g_Leak=0.03,C=1.0,Vth=20.):ST=nb.types.NeuState({'V':-65.,'m':0.,'h':0.,'n':0.,'sp':0.,'inp':0.},help='Hodgkin–Huxley neuron state.\n''"V" denotes membrane potential.\n''"n" denotes potassium channel activation probability.\n''"m" denotes sodium channel activation probability.\n''"h" denotes sodium channel inactivation probability.\n''"sp" denotes spiking state.\n''"inp" denotes synaptic input.\n')@nb.integratedefint_m(m,t,V):alpha=0.1*(V+40)/(1-np.exp(-(V+40)/10))beta=4.0*np.exp(-(V+65)/18)returnalpha*(1-m)-beta*m@nb.integratedefint_h(h,t,V):alpha=0.07*np.exp(-(V+65)/20.)beta=1/(1+np.exp(-(V+35)/10))returnalpha*(1-h)-beta*h@nb.integratedefint_n(n,t,V):alpha=0.01*(V+55)/(1-np.exp(-(V+55)/10))beta=0.125*np.exp(-(V+65)/80)returnalpha*(1-n)-beta*n@nb.integrate(noise=noise/C)defint_V(V,t,m,h,n,Isyn):INa=g_Na*m**3*h*(V-E_Na)IK=g_K*n**4*(V-E_K)IL=g_Leak*(V-E_Leak)dvdt=(-INa-IK-IL+Isyn)/Creturndvdtdefupdate(ST,_t_):m=np.clip(int_m(ST['m'],_t_,ST['V']),0.,1.)h=np.clip(int_h(ST['h'],_t_,ST['V']),0.,1.)n=np.clip(int_n(ST['n'],_t_,ST['V']),0.,1.)V=int_V(ST['V'],_t_,m,h,n,ST['inp'])sp=np.logical_and(ST['V']<Vth,V>=Vth)ST['sp']=spST['V']=VST['m']=mST['h']=hST['n']=nST['inp']=0.returnnb.NeuType(requires={"ST":ST},steps=update,vector_based=True)Define an AMPA synapse modeldefAMPA(g_max=0.10,E=0.,tau_decay=2.0):requires=dict(ST=nb.types.SynState(['s'],help='AMPA synapse state.'),pre=nb.types.NeuState(['sp'],help='Pre-synaptic state must have "sp" item.'),post=nb.types.NeuState(['V','inp'],help='Post-synaptic neuron must have "V" and "inp" items.'))@nb.integrate(method='euler')defints(s,t):return-s/tau_decaydefupdate(ST,_t_,pre):s=ints(ST['s'],_t_)s+=pre['sp']ST['s']=s@nb.delayeddefoutput(ST,post):post_val=-g_max*ST['s']*(post['V']-E)post['inp']+=post_valreturnnb.SynType(requires=requires,steps=(update,output),vector_based=False)