---
description: Chapter 5.2
---

# The Izhikevich neuron model

### Python demonstration

Imports:

```
import numpy as np
import matplotlib.pyplot as plt
```

Model and simulation parameters for three response dynamics:

```
x  = 5
y  = 140

titles = ['Regular Spiking', 'Chattering', 'Fast spiking']
a  = [0.02, 0.02, 0.1]
b  = [0.2 , 0.2 , 0.2]
c  = [-65, -50  , -65]
d  = [8   , 2   , 2  ]

v0 = -70         # Resting potential        [mV]
T       = 200    # Simulation time          [mSec]
dt      = 0.25   # Simulation time interval [mSec]

time    = np.arange(0, T + dt, dt)  # Time array
```

Defining the stimulus (a step function):

```
stim = np.zeros(len(time))
for i,t in enumerate(stim):
    if i > 20:
        stim[i] = 15
```

Simulating:

```
trace = np.zeros((2,len(time))) # Tracing du and dv

for exp in range(len(a)):
    v  = v0
    u  = b[exp]*v
    spikes = []
    for i, j in enumerate(stim):
        v += dt * (0.04*v**2 + x*v + y - u + stim[i]) 
        u += dt * a[exp]*(b[exp]*v-u)
        if v > 30:
            trace[0,i] = 30
            v = c[exp] 
            u += d[exp]
        else:
            trace[0,i] = v 
            trace[1,i] = u
```

Plotting:

```
    plt.figure(figsize=(10,5))
    plt.title('Izhikevich Model: {}'.format(titles[exp]), fontsize=15) 
    plt.ylabel('Membrane Potential (mV)', fontsize=15) 
    plt.xlabel('Time (msec)', fontsize=15)
    plt.plot(time, trace[0], linewidth=2, label = 'Vm')
    plt.plot(time, trace[1], linewidth=2, label = 'Recovery', color='green')
    plt.plot(time, stim + v0, label = 'Stimuli (Scaled)', color='sandybrown', linewidth=2)
    plt.legend(loc=1)
```

Resulted regular spiking dynamic:

![](https://1487620879-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiS7NytljlKs-2Yccqw%2F-Mj3Pn40cVKvnK_XvIak%2F-Mj3RYeaZBWGnF2hVc_4%2FScreen%20Shot%202021-09-08%20at%2011.06.21.png?alt=media\&token=5f50af9d-9609-40ca-bce1-6ced993723fd)

Resulted chattering dynamic:

![](https://1487620879-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiS7NytljlKs-2Yccqw%2F-Mj3RdUOSBFe1NLbug1X%2F-Mj3Rwna0j14zYmj4Ejg%2FScreen%20Shot%202021-09-08%20at%2011.08.03.png?alt=media\&token=79095670-96ca-4400-a2b9-1627b49e3bc2)

Resulted fast-spiking dynamic:

![](https://1487620879-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MiS7NytljlKs-2Yccqw%2F-Mj3RdUOSBFe1NLbug1X%2F-Mj3S-I1KCGJBS-KrCTk%2FScreen%20Shot%202021-09-08%20at%2011.08.12.png?alt=media\&token=080062f2-639d-488d-a334-252f83d89cf4)

