Skip to content

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