Skip to content

NoisyLeaky behaviour: spiking and membrane potential reset independently stochastic #366

@leoauri

Description

@leoauri

From what I observe of NoisyLeaky neurons, spiking and membrane potential reset are independently stochastic.

I am not at all experienced with SNNs, but wouldn't the expected behaviour be: iff a spike is emitted, membrane potential reset occurs?

Here is code where I observe this. I'm using reset mechanism "zero" here, but "subtract" produces similar behaviour:

import snntorch as snn
from snntorch import NoisyLeaky
import torch

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

Example output:

[(tensor([[1.]]), tensor([[1.]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[1.]]), tensor([[1.]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[0.]]), tensor([[1.]])),
 (tensor([[1.]]), tensor([[1.5000]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[1.]]), tensor([[1.]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[0.]]), tensor([[1.]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[1.]]), tensor([[1.]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[1.]]), tensor([[1.]])),
 (tensor([[0.]]), tensor([[1.5000]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[1.]]), tensor([[1.]])),
 (tensor([[1.]]), tensor([[1.5000]])),
 (tensor([[0.]]), tensor([[0.]])),
 (tensor([[1.]]), tensor([[1.]]))]

You can see here that the spikes and the reset do not generally coincide!

Here's a plot of that:

Image

I also adapted one of the tutorials trying to figure this out:

lif2 = snn.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]

# Simulation run across 100 time steps.
for step in range(num_steps):
  spk_out, mem = lif2(cur_in[step], 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, 
                 title="Lapicque Neuron Model With Step Input")

Image

If I have my head screwed on wrong, someone please correct that. Otherwise, it would be great if the authors of the pull request #230 @genema could shed light on this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions