def test_resonator(): p, s = izk.resonator ts = np.arange(0, 400, 0.25) T1 = ts[-1] / 10 T2 = T1 + 20 T3 = 0.7 * ts[-1] T4 = T3 + 40 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if ( ((t > T1) and (t < T1 + 4)) or ((t > T2) and (t < T2 + 4)) or ((t > T3) and (t < T3 + 4)) or ((t > T4) and (t < T4 + 4)) ): input_current = 0.65 * torch.ones(1) else: input_current = 0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_integrator(): p, s = izk.integrator ts = np.arange(0, 100, 0.25) T1 = ts[-1] / 11 T2 = T1 + 5 T3 = 0.7 * ts[-1] T4 = T3 + 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if ( ((t > T1) and (t < T1 + 2)) or ((t > T2) and (t < T2 + 2)) or ((t > T3) and (t < T3 + 2)) or ((t > T4) and (t < T4 + 2)) ): input_current = 9 * torch.ones(1) else: input_current = 0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def plot_izhikevich( behavior: IzhikevichSpikingBehavior, current: float = 1, time_print: int = 250, time_current: int = 20, timestep_print: float = 0.1, ): """ Computes and plots a 2D visualisation of the behavior of an Izhikevich neuron model. By default, the time window is 250ms with a time step of 0.1ms Example : >>> import torch >>> from norse.torch import tonic_spiking >>> from norse.torch.utils.plot import plot_izhikevich >>> plot_izhikevich(tonic_spiking) .. plot:: import torch from norse.torch import tonic_spiking from norse.torch.utils.plot import plot_izhikevich plot_izhikevich(tonic_spiking) Arguments : behavior (IzhikevichSpikingBehavior) : behavior of an Izhikevich neuron current (float) : strengh of the input current, defaults to 1 time_print (float) : size of the time window for simulation (in ms) time_current (float) : time at which the input current goes from 0 to current (in ms) timestep_print (float) : timestep of the simulation (in ms) """ p, s = behavior T1 = time_current vs = [] us = [] cs = [] time = [] for t in np.arange(0, time_print, timestep_print): vs.append(s.v.item()) us.append(s.u.item()) time.append(t * timestep_print) if t > T1: input_current = current * torch.ones(1) else: input_current = 0 * torch.ones(1) _, s = izhikevich_step(input_current, s, p) cs.append(input_current) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.set_ylabel("Membrane potential (mV)") ax1.set_xlabel("Time (ms)") ax1.plot(time, vs) ax1.plot(time, cs)
def test_phasic_bursting(): p, s = izk.phasic_bursting T1 = 20 vs = [] us = [] cs = [] for t in np.arange(0, 200, 0.25): vs.append(s.v) us.append(s.u) if t > T1: input_current = 0.6 * torch.ones(1) else: input_current = 0 * torch.ones(1) _, s = izhikevich_step(input_current, s, p) cs.append(input_current) return vs, cs
def test_inhibition_induced_spiking(): p, s = izk.inhibition_induced_spiking ts = np.arange(0, 350, 0.5) vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if t < 50 or t > 250: input_current = 80.0 * torch.ones(1) else: input_current = 75.0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_tonic_spiking(): p, s = izk.tonic_spiking ts = np.arange(0, 100, 0.25) T1 = ts[-1] / 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if t > T1: input_current = 14 * torch.ones(1) else: input_current = 0 * torch.ones(1) _, s = izhikevich_step(input_current, s, p) cs.append(input_current) return vs, cs
def test_mixed_mode(): p, s = izk.mixed_mode ts = np.arange(0, 160, 0.25) T1 = ts[-1] / 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if t > T1: input_current = 10 * torch.ones(1) else: input_current = 0 * torch.ones(1) _, s = izhikevich_step(input_current, s, p) cs.append(input_current) return vs, cs
def test_subthreshold_oscillation(): p, s = izk.subthreshold_oscillation ts = np.arange(0, 200, 0.25) T1 = ts[-1] / 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if (t > T1) and (t < T1 + 5): input_current = 2.0 * torch.ones(1) else: input_current = 0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_spike_latency(): p, s = izk.spike_latency ts = np.arange(0, 100, 0.2) T1 = ts[-1] / 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if (t > T1) and (t < T1 + 3): input_current = 7.4 * torch.ones(1) else: input_current = 0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_class_2_exc(): p, s = izk.class_2_exc ts = np.arange(0, 300, 0.25) T1 = 30 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if t > T1: input_current = (-0.5 + (0.015 * (t - T1))) * torch.ones(1) else: input_current = -0.5 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs
def test_spike_frequency_adaptation(): p, s = izk.spike_frequency_adaptation ts = np.arange(0, 85, 0.25) T1 = ts[-1] / 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if t > T1: input_current = 30 * torch.ones(1) else: input_current = 0 * torch.ones(1) _, s = izhikevich_step(input_current, s, p) cs.append(input_current) return vs, cs
def test_dap(): p, s = izk.dap ts = np.arange(0, 50, 0.1) T1 = 10 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if abs(t - T1) < 1: input_current = 20.0 * torch.ones(1) else: input_current = 0.0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_rebound_burst(): p, s = izk.rebound_burst ts = np.arange(0, 200, 0.2) T1 = 20 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if (t > T1) and (t < T1 + 5): input_current = -15 * torch.ones(1) else: input_current = 0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_bistability(): p, s = izk.bistability ts = np.arange(0, 300, 0.25) T1 = ts[-1] / 8 T2 = 216 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if ((t > T1) and (t < T1 + 5)) or ((t > T2) and (t < T2 + 5)): input_current = 1.24 * torch.ones(1) else: input_current = 0.24 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs
def test_threshhold_variability(): p, s = izk.threshhold_variability ts = np.arange(0, 100, 0.25) T1 = 10 T2 = 80 vs = [] us = [] cs = [] for t in ts: vs.append(s.v) us.append(s.u) if ((t > T1) and (t < T1 + 5)) or ((t > T2) and (t < T2 + 5)): input_current = 1 * torch.ones(1) elif (t > T2 - 10) and (t < T2 - 10 + 5): input_current = -6 * torch.ones(1) else: input_current = 0 * torch.ones(1) cs.append(input_current) _, s = izhikevich_step(input_current, s, p) return vs, cs