tau*dv/dt = -v V(t) = V(0)e^-t/tau input spike .. V -> V + w if V > Vthresh the vire a spike and V -> Vreset for each time period t: Update V from value at time t to value at time t+dt Process any incoming spikes Check if V crossed the threshold If so: Emit a spike Reset V V (t _ dt) = V(t) e^-dt/tau --- Code --- # Function that runs the simulation # tau: time constant (in ms) # t0, t1, t2: time of three input spikes # w: input synapse weight # threshold: threshold value to produce a spike # reset: reset value after a spike def LIF(tau=10, t0=20, t1=40, t2=60, w=0.1, threshold=1.0, reset=0.0): # Spike times, keep sorted because it's more efficient to pop the last value off the list times = [t0, t1, t2] times.sort(reverse=True) # set some default parameters duration = 100 # total time in ms dt = 0.1 # timestep in ms alpha = np.exp(-dt/tau) # this is the factor by which V decays each time step V_rec = [] # list to record membrane potentials V = 0.0 # initial membrane potential T = np.arange(np.round(duration/dt))*dt # array of times spikes = [] # list to store spike times # run the simulation for t in T: V_rec.append(V) # record V = V * alpha # integrate equations if times and t>times[-1]: # (last e)if there has been an input spike V += w times.pop() # remove that spike from list V_rec.append(V) # record V before the reset so we can see the spike if V>threshold: # if there should be an output spike V = reset spikes.append(t)