Implemented Izhikevich's 2003 paper in Brian2, want to contribute to the "Brian2 Documentation"

Description of problem

I have implemented a paper (Simple Model of Spiking Neurons) in Brian2 (GitHub - aesagtekin/simplemodelofspikingneurons: One thousand randomly connected neurons are simulated. Source: "Simple Model of Spiking Neurons (E. M. Izhikevich, 2003)" Tool: Python, Brian2). I just thought that maybe I could contribute the “Brian2 Documentation” by suggesting adding the code to the “Examples” section. (Currently implementing some other papers too)

Should I open a pull request on GitHub, and how to do so appropriately? I hope I have opened the topic in the relevant forum section.

1 Like

Hi!

Thanks! Yes, just make a pull request and put your file (as plain Python, not as a notebook) under examples/from_papers.

Best,

Sebastian

1 Like

Thanks! Yet, I didn’t use GitHub before for open-source projects, and don’t know how to make a pull request and put my code into the file. Guess I need to select the branch first (not sure though), can you explain it a little bit more, or maybe there is a documentation for this?

1 Like

Hi!

I recommend using the CLI tool: GitHub - cli/cli: GitHub’s official command line tool

git clone https://github.com/brian-team/brian2
cd brian2
git checkout -b Izhikevich_2003
# put your file at examples/from_papers/Izhikevich_2003.py
git add examples/from_papers/Izhikevich_2003.py
git commit -m "Izhikevich (2003)"
gh pr create

(Untested)

Cheers,

Sebastian

Thanks! I guess I have done it: Izhikevich 2003 by aesagtekin · Pull Request #1415 · brian-team/brian2 · GitHub

1 Like

Hi!

I’ve finally got it running with the original parameters.

grafik

The culprit is the interplay of the noise and the synaptic/recurrent stimulus.

I needed to separate the two and use multiple synaptic pathways to have a rectangular (1 ms long) PSP.

If you like, you can update your PR accordingly.

Cheers,

Sebastian

#!/usr/bin/env python3
"""
Fig. 3 of

Simple Model of Spiking Neurons
IEEE Transactions on Neural Networks ( Volume: 14, Issue: 6, Nov. 2003)
Eugene M. Izhikevich

based on

net.m by Eugene M. Izhikevich
and Izhikevich_2003.py by Akif Erdem Sağtekin

Sebastian Schmitt, 2022
"""
import matplotlib.pyplot as plt
import numpy as np

from brian2 import NeuronGroup, Synapses, SpikeMonitor
from brian2 import ms
from brian2 import defaultclock, run

tfinal = 1000 * ms
Ne = 800
Ni = 200

re = np.random.uniform(size=Ne)
ri = np.random.uniform(size=Ni)
weights = np.hstack(
    [
        0.5 * np.random.uniform(size=(Ne + Ni, Ne)),
        -np.random.uniform(size=(Ne + Ni, Ni)),
    ]
).T

defaultclock.dt = 1 * ms

eqs = """dv/dt = (0.04*v**2 + 5*v + 140 - u + I + I_noise )/ms : 1
         du/dt = (a*(b*v - u))/ms  : 1
         I : 1
         I_noise : 1
         a : 1
         b : 1
         c : 1
         d : 1
       """

N = NeuronGroup(Ne + Ni, eqs, threshold="v>=30", reset="v=c; u+=d", method="euler")
N.v = -65

N_exc = N[:Ne]
N_inh = N[Ne:]

spikemon = SpikeMonitor(N)

N_exc.a = 0.02
N_exc.b = 0.2
N_exc.c = -65 + 15 * re**2
N_exc.d = 8 - 6 * re**2

N_inh.a = 0.02 + 0.08 * ri
N_inh.b = 0.25 - 0.05 * ri
N_inh.c = -65
N_inh.d = 2

N_exc.u = "b*v"
N_inh.u = "b*v"

S = Synapses(
    N,
    N,
    "w : 1",
    on_pre={"up": "I += w", "down": "I -= w"},
    delay={"up": 0 * ms, "down": 1 * ms},
)
S.connect()
S.w[:] = weights.flatten()

N_exc.run_regularly("I_noise = 5*randn()", dt=1 * ms)
N_inh.run_regularly("I_noise = 2*randn()", dt=1 * ms)

run(tfinal)

fig, ax = plt.subplots()

ax.scatter(spikemon.t / ms, spikemon.i[:], marker="_", color="k", s=10)

ax.set_xlim(0, tfinal / ms)
ax.set_ylim(0, len(N))
ax.set_xlabel("time, ms")
ax.set_ylabel("neuron number")
ax.set_xticks(np.arange(0, tfinal / ms, 100))
ax.set_yticks(np.arange(0, len(N), 100))

ax.axhline(Ne, color="k")

plt.show()