Skip to content

Fix spike/membrane potential independence #368

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

Open
wants to merge 7 commits into
base: noisy_leaky
Choose a base branch
from

Conversation

leoauri
Copy link

@leoauri leoauri commented Feb 15, 2025

Here is a way that NoisyLeaky can work, resetting the membrane potential if and only if the neuron spikes.

Demo:

n = NoisyLeaky(beta=0.5, output=True, reset_mechanism="zero")

steps = 20
outs = []
mem = torch.zeros(1)
for t in range(steps):
    out, mem = n(torch.Tensor([[1.0]]), mem)
    outs.append((out, mem))

outs

image

lif2 = NoisyLeaky(beta=0.6)

# Initialize inputs and outputs
cur_in = torch.cat((torch.zeros(10, 1), torch.ones(190, 1)*0.2), 0)
mem = torch.zeros(1)
spk_out = torch.zeros(1) 
mem_rec = [mem]
spk_rec = [spk_out]

for ci in cur_in:
  spk_out, mem = lif2(ci, mem)
  mem_rec.append(mem)
  spk_rec.append(spk_out)

# convert lists to tensors
mem_rec = torch.stack(mem_rec)
spk_rec = torch.stack(spk_rec)

plot_cur_mem_spk(cur_in, mem_rec, spk_rec, thr_line=1, vline=109, ylim_max2=1.3)

image

That seems to make more sense to me.

I decided to change the mem output to reflect the value after spike/membrane reset in that step. Otherwise, I would have had to either make the class stateful or change the interface. Also, this just makes more sense to my brain. How does that play with the rest of the SNN world?

Cheers,
Leo

@leoauri
Copy link
Author

leoauri commented Feb 15, 2025

Fixes #366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant