Speaking of neuron simulators, NEURON made by Yale University is famous. This is a simulator from a neuroscience perspective, but from an engineering point of view, BRIAN and BindsNET .readthedocs.io /) and so on.
All the libraries work in Python and are very well done, but ** Wouldn't it be nice to have a library that could simulate neurons more easily? I thought **.
Therefore! I made! !! (Although there may not be much demand!)
All you need (for now) is NumPy and Matplotlib. Honestly, it is not so large as to be called a library, but SPINE can simulate the following models.
In the IF / LIF model, the spike response kernel can also be selected as single exponential or double exponential.
SPINE is neither engineering-specific nor science-specific. Anyway, I am making it with the hope of helping beginners in neuroscience and spiking neurons to start learning. The source is posted at the end of the article.
Well, just look at how it actually works.
** Simulate the activity of LIF neurons that receive input from 10 preneurons **. At this time, if the input spike sequence (output spike sequence of the previous neuron) is the Poisson spike sequence, it is coded as follows.
ref: Understanding while implementing in Python Poisson Spike-Qiita
from spine import LIF, PoissonSpike
from spine.tools.plotting import plot_spike_scatter
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
duration = 500 # [ms]Experiment time
dt = 0.1 # [ms] time step
time = int(duration / dt)
# Input data from Poisson Spike Gen.
#Generate a Poisson spike sequence to be input from a random number
spikes = PoissonSpike(np.random.random(10),
time=duration,
dt=dt).spikes
#Appropriate weight
weights = np.random.random(10) + 5.0
#Define LIF neurons(Double exp filter)
neu = LIF(duration,
dt,
k='double', # use double exponential filter
)
#Calculate the membrane potential by passing the input spike sequence and weight
#Returns membrane potential, output spike, ignition time
v, s, f = neu.calc_v((spikes, weights))
# Plot
t = np.arange(0, duration, dt)
plt.subplot(2, 1, 1)
plot_spike_scatter(spikes, duration, dt, title='input spike trains', xlabel=None)
plt.subplot(2, 1, 2)
plt.plot(t, v)
plt.plot(t, np.full_like(t, neu.th), linestyle='dashed')
plt.ylabel('Membrane Voltage [mV]')
plt.xlabel('time [ms]')
plt.xlim(0, duration)
plt.show()
It is like this.
Of course, hyperparameters such as firing threshold can be passed as arguments when generating LIF, so detailed experimental settings are possible.
For such people, some sample code is available on Github.
$ python if_sample.py #IF model
$ python lif_sample.py #LIF model
$ python hh_sample.py # Hodgkin-Huxley model
$ python fhn_sample.py # FitzHugh-Nagumo model
I think it is also an ant to change the necessary parts of this content and simulate it. The actually generated image is posted on Github.
Actually, this library has been around for a while, but since the code has been organized and it has become quite easy to use, I decided to introduce it on Qiita as well.
SPINE is a by-product of what I learned. So it's a really simple neuron simulator, but as I did at the beginning, I personally hope that this will help ** neuroscience and SNN beginners to learn **.
We will continue to update it from time to time, so if you think "yeah", please take a look at the Github source. I'm glad if you give me a star.
:warning: SPINE does not anticipate large-scale SNN construction. It is a simple neuron simulator for checking the operation. BindsNET is recommended for those who want to build SNN and perform image processing.
Source HiroshiARAKI/spine: SPINE is a simple Spiking Neuron simulator
Documentation https://spine.hirlab.net/
Recommended Posts