<commit_before>from brian import (Network, NeuronGroup, StateMonitor, SpikeMonitor,
                   Connection,
                   mV, ms, Hz)
import matplotlib.pyplot as plt
import spikerlib as sl
import numpy as np

sim = Network()
duration = 200*ms
dt = 0.1*ms
tau = 10*ms
Vth = 15*mV
Vreset = 0*mV
lifeq = "dV/dt = -V/tau : volt"

lifnrn = NeuronGroup(1, lifeq, threshold="V>=Vth", reset=Vreset)
lifnrn.V = Vreset
sim.add(lifnrn)

Nin = 300
fin = 50*Hz
Sin = 0.6
sigma = 0.5*ms
weight = 0.1*mV
inputs = sl.tools.fast_synchronous_input_gen(Nin, fin, Sin, sigma, duration)
connection = Connection(inputs, lifnrn, "V", weight=weight)
sim.add(inputs, connection)

vmon = StateMonitor(lifnrn, "V", record=True)
spikemon = SpikeMonitor(lifnrn)
sim.add(vmon, spikemon)

sim.run(duration)
vmon.insert_spikes(spikemon, 40*mV)

high, low = sl.tools.get_slope_bounds(spikemon[0], 0*mV, Vreset, Vth, tau, dt)

plt.figure()
plt.plot(vmon.times*1000, vmon[0]*1000)
plt.plot(vmon.times*1000, np.zeros_like(vmon[0])+Vth*1000, "k--")
plt.plot(np.arange(0*dt, len(high)*dt, dt)*1000, high*1000)
plt.plot(np.arange(0*dt, len(low)*dt, dt)*1000, low*1000)
plt.xlabel("t (ms)")
plt.ylabel("Membrane potential (mV)")
plt.show()
<commit_msg>Good to go with partial reset<commit_after>from brian import (Network, NeuronGroup, StateMonitor, SpikeMonitor,
                   Connection,
                   mV, ms, Hz)
import matplotlib.pyplot as plt
import spikerlib as sl
import numpy as np
import sys

sim = Network()
duration = 200*ms
dt = 0.1*ms
tau = 10*ms
Vth = 15*mV
Vreset = 0*mV
Vreset = 13.65*mV
lifeq = "dV/dt = -V/tau : volt"

lifnrn = NeuronGroup(1, lifeq, threshold="V>=Vth", reset=Vreset)
lifnrn.V = Vreset
sim.add(lifnrn)

Nin = 200
fin = 40*Hz
Sin = 0.6
sigma = 0.0*ms
weight = 0.1*mV
inputs = sl.tools.fast_synchronous_input_gen(Nin, fin, Sin, sigma, duration)
connection = Connection(inputs, lifnrn, "V", weight=weight)
sim.add(inputs, connection)

vmon = StateMonitor(lifnrn, "V", record=True)
spikemon = SpikeMonitor(lifnrn)
sim.add(vmon, spikemon)

sim.run(duration)
if spikemon.nspikes == 0:
    print("No spikes fired")
    sys.exit(1)

vmon.insert_spikes(spikemon, 40*mV)

high, low = sl.tools.get_slope_bounds(spikemon[0], 0*mV, Vreset, Vth, tau, dt)

plt.figure()
plt.plot(vmon.times*1000, vmon[0]*1000)
plt.plot(vmon.times*1000, np.zeros_like(vmon[0])+Vth*1000, "k--")
plt.plot(np.arange(0*dt, len(high)*dt, dt)*1000, high*1000, color="0.25")
plt.plot(np.arange(0*dt, len(low)*dt, dt)*1000,  low*1000,  color="0.25")

for sp in spikemon[0]:
    plt.plot([(sp-0.002)*1000]*2, [0*mV, Vth*1000], 'r-')

plt.xlabel("t (ms)")
plt.ylabel("Membrane potential (mV)")

plt.show()

{'fraction_non_alphanumeric': 0.16648002986188876, 'fraction_numerical': 0.056364315042926466, 'mean_word_length': 4.677966101694915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1341415', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1110, 'n_words': 244}