Created
September 5, 2012 00:54
-
-
Save mindbound/3628656 to your computer and use it in GitHub Desktop.
Compact implementation of the Izhikevich neuron model
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
import numpy | |
class IzhikevichNeuron(object): | |
def __init__(self, a, b, c, d, v, u = None): | |
self.a = a | |
self.b = b | |
self.c = c | |
self.d = d | |
self.v = v | |
self.u = u if u is not None else b * v | |
class IzhikevichSim(object): | |
def __init__(self, nrn, t, dt = 0.25): | |
self.neuron = nrn | |
self.dt = dt | |
self.t = t = numpy.arange(0, t + dt, dt) | |
self.stim = numpy.zeros(len(t)) | |
self.x = 5 | |
self.y = 140 | |
self.du = lambda a, b, v, u: a * (b * v - u) | |
def integrate(self): | |
trace = numpy.zeros((2, len(self.t))) | |
for i in enumerate(self.stim): | |
self.neuron.v += self.dt * (0.04 * self.neuron.v ** 2 + self.x * self.neuron.v + self.y - self.neuron.u + self.stim[i[0]]) | |
self.neuron.u += self.dt * self.du(self.neuron.a, self.neuron.b, self.neuron.v, self.neuron.u) | |
if self.neuron.v >= 30: | |
trace[0, i[0]] = 30 | |
self.neuron.v = self.neuron.c | |
self.neuron.u += self.neuron.d | |
else: | |
trace[0, i[0]] = self.neuron.v | |
trace[1, i[0]] = self.neuron.u | |
return trace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment