I made a neuron simulator with Python

0. Neuron simulator

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!)

  1. SPINE: Spiking Neuron Simulotor spine

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.

  1. IF: Integrate-and-Fire model
  2. LIF: Leaky IF model
  3. Hodgkin-Huxley model
  4. FitzHugh-Nagumo model
  5. Poisson spike generation

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.

2. Operation example

Well, just look at how it actually works.

2.1. LIF and Poisson Spike

** 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()

dlif.png

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.

2.2. For those who want to run all models anyway

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.

3. Postscript

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

I made a neuron simulator with Python
I made a fortune with Python.
I made a daemon with Python
I made a character counter with Python
I made a Hex map with Python
I made a roguelike game with Python
I made a configuration file with Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a python text
I made blackjack with Python.
I made wordcloud with Python.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Twitter BOT with GAE (python) (with a reference)
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I made a Line-bot using Python!
I made a simple typing game with tkinter in Python
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
I made a puzzle game (like) with Tkinter in Python
I made a payroll program in Python!
I tried a functional language with Python
What I did with a Python array
I made a life game with Numpy
I made a stamp generator with GAN
After studying Python3, I made a Slackbot
I made a WEB application with Django
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a library to easily read config files with Python
I made a Nyanko tweet form with Python, Flask and Heroku
I made a lot of files for RDP connection with Python
[Python] I made an image viewer with a simple sorting function.
I made a shuffle that can be reset (reverted) with Python
I made a poker game server chat-holdem using websocket with python
I made a segment tree with python, so I will introduce it
I made a stamp substitute bot with line
I made a python dictionary file for Neocomplete
I want to make a game with Python
Procedure for creating a LineBot made with Python
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I made a random number graph with Numpy
I want to write to a file with Python
I made a Caesar cryptographic program in Python.
I made a Python Qiita API wrapper "qiipy"
I made a QR code image with CuteR
I made a tool to automatically browse multiple sites with Selenium (Python)
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made a tool that makes decompression a little easier with CLI (Python3)
I made a module PyNanaco that can charge nanaco credit with python
[AWS] I made a reminder BOT with LINE WORKS
I tried fp-growth with python
I tried scraping with Python
I learned Python with a beautiful girl at Paiza # 02