Last active
November 15, 2016 13:56
-
-
Save DaisukeMiyamoto/3e7f1d98434bdfb9a5671b0969d9af0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Simulate Izhikevich model and draw graph | |
Created on Tue Mar 01 04:21:25 2016 | |
@author: nebula | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
class Iz(): | |
def __init__(self, tmax=200, dt=0.1, stimarray=None, | |
a = 0.02, b = 0.2, c=-50.0, d= 2.0, title='Izhikevich Model'): | |
self.maxstep = int(tmax/dt) | |
self.record = {} | |
self.record['t'] = np.linspace(0, tmax, self.maxstep) | |
self.record['v'] = -65.0 * np.ones(self.maxstep) | |
self.dt = dt | |
self.t = 0.0 | |
self.v = -65.0 | |
self.a = a | |
self.b = b | |
self.c = c | |
self.d = d | |
self.i = 10.0 | |
self.u = self.v * self.b | |
self.finish_init = 20 | |
self.title = title | |
def _delta_v(self, i=0.0): | |
return 0.04 * self.v * self.v + 5 * self.v + 140 - self.u + i | |
def _delta_u(self): | |
return self.a * (self.b * self.v - self.u) | |
def run(self): | |
for i in range(self.maxstep): | |
self.t = self.dt * i | |
if self.t < self.finish_init: | |
delta_v = self._delta_v(i=0) | |
else: | |
delta_v = self._delta_v(i=self.i) | |
delta_u = self._delta_u() | |
self.v += delta_v * self.dt | |
self.u += delta_u * self.dt | |
if self.v > 30: | |
self.v = self.c | |
self.u = self.u + self.d | |
self.record['t'][i] = i*self.dt | |
self.record['v'][i] = self.v | |
self.plot() | |
def show(self): | |
print(self.record['t']) | |
print(self.record['v']) | |
def plot(self): | |
plt.figure(figsize=(20, 10)) | |
plt.plot(self.record['t'], self.record['v'], color='black') | |
if self.title is not None: | |
plt.title(self.title) | |
plt.ylim(-80, 40) | |
plt.xlabel('$t$ [msec]') | |
plt.ylabel('$V$ [mV]') | |
plt.rcParams['font.size'] = 28 | |
plt.grid(True) | |
plt.show() | |
if __name__ == '__main__': | |
# regular spiking (RS) | |
iz = Iz(a= 0.02, b=0.2, c=-65, d=8, title='Regular Spiking (RS)\n$a=0.02,\, b=0.2,\, c=-65.0,\, d=8$') | |
iz.run() | |
# Intrinsically bursting (IB) | |
iz = Iz(a= 0.02, b=0.2, c=-55, d=4.0, title='Intrinsically Bursting (IB)\n$a=0.02,\, b=0.2,\, c=-55,\, d=4.0$') | |
iz.run() | |
# Chattering (CH) | |
iz = Iz(a= 0.02, b=0.2, c=-50, d=2.0, title='Chattering (CH)\n$a=0.02,\, b=0.2,\, c=-50.0,\, d=2.0$') | |
iz.run() | |
# fast spiking (FS) | |
iz = Iz(a= 0.1, b=0.2, c=-65, d=2.0, title='Fast Spiking (FS)\n$ a=0.1,\, b=0.2,\, c=-65.0,\, d=2.0$') | |
iz.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment