Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Neuron voltage subtraction reset for accuracy #276

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions nengo_loihi/emulator/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,32 @@ def update(self, rng):
u2[self.noise.target_u] += noise[self.noise.target_u]
self._overflow(u2, bits=U_BITS, name="u2")

self.voltage[:] = self._decay_voltage(self.voltage, u2)
# We have not been able to create V overflow on the chip, so we do
# not include it here. See github.com/nengo/nengo-loihi/issues/130
# self.overflow(self.v, bits=V_BIT, name="V")

np.clip(self.voltage, self.vmin, self.vmax, out=self.voltage)
self.voltage[self.ref_count > 0] = 0
# TODO^: don't zero voltage in case neuron is saving overshoot

self.spiked[:] = (self.voltage > self.vth)
self.voltage[self.spiked] = 0
self.ref_count[self.spiked] = self.ref[self.spiked]
if 0:
self.voltage[:] = self._decay_voltage(self.voltage, u2)
# We have not been able to create V overflow on the chip, so we do
# not include it here. See github.com/nengo/nengo-loihi/issues/130
# self.overflow(self.v, bits=V_BIT, name="V")

np.clip(self.voltage, self.vmin, self.vmax, out=self.voltage)
self.voltage[self.ref_count > 0] = 0
# TODO^: don't zero voltage in case neuron is saving overshoot

self.spiked[:] = (self.voltage > self.vth)
self.voltage[self.spiked] = 0
self.ref_count[self.spiked] = self.ref[self.spiked]
else:
v = self._decay_voltage(self.voltage, u2)
self.voltage[self.ref_count <= 0] = v[self.ref_count <= 0]
# We have not been able to create V overflow on the chip, so we do
# not include it here. See github.com/nengo/nengo-loihi/issues/130
# self.overflow(self.v, bits=V_BIT, name="V")

np.clip(self.voltage, self.vmin, self.vmax, out=self.voltage)

self.spiked[:] = (self.voltage > self.vth) & (self.ref_count <= 0)
self.voltage[self.spiked] -= self.vth[self.spiked]
self.ref_count[self.spiked] = self.ref[self.spiked]

# decrement ref_count
np.clip(self.ref_count - 1, 0, None, out=self.ref_count)

Expand Down
6 changes: 4 additions & 2 deletions nengo_loihi/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def loihi_lif_rates(neuron_type, x, gain, bias, dt):
j = neuron_type.current(x, gain, bias) - 1
out = np.zeros_like(j)
period = tau_ref + tau_rc * np.log1p(1. / j[j > 0])
out[j > 0] = (neuron_type.amplitude / dt) / np.ceil(period / dt)
# out[j > 0] = (neuron_type.amplitude / dt) / np.ceil(period / dt)
out[j > 0] = neuron_type.amplitude / period
return out


Expand All @@ -52,7 +53,8 @@ def loihi_spikingrectifiedlinear_rates(neuron_type, x, gain, bias, dt):

out = np.zeros_like(j)
period = 1. / j[j > 0]
out[j > 0] = (neuron_type.amplitude / dt) / np.ceil(period / dt)
# out[j > 0] = (neuron_type.amplitude / dt) / np.ceil(period / dt)
out[j > 0] = neuron_type.amplitude / period
return out


Expand Down
2 changes: 1 addition & 1 deletion nengo_loihi/tests/test_neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_loihi_rates(dt, neuron_type, Simulator, plt, allclose):
x = np.linspace(-0.1, 1, n)

encoders = np.ones((n, 1))
max_rates = 400 * np.ones(n)
max_rates = 300 * np.ones(n)
intercepts = 0 * np.ones(n)
gain, bias = neuron_type.gain_bias(max_rates, intercepts)
j = x * gain + bias
Expand Down