You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyTorch implementation of (homogeneous / inhomogeneous) Poisson encoding #104
I think that bindsnet.encoding.poisson could easily be converted to use torch.distributions.Poisson. It would be a good way for us to reduce reliance on numpy, and perhaps improve readibility of the code.
Consider the poisson function:
poisson(datum: torch.Tensor, time: int, **kwargs) -> torch.Tensor:
# language=rst
"""
Generates Poisson-distributed spike trains based on input intensity. Inputs must be non-negative.
:param datum: Tensor of shape ``[n_1, ..., n_k]``.
:param time: Length of Bernoulli spike train per input variable.
:return: Tensor of shape ``[time, n_1, ..., n_k]`` of Poisson-distributed spikes.
"""
datum = np.copy(datum)
shape, size = datum.shape, datum.size
datum = datum.ravel()
# Invert inputs (firing rate inverse of inter-arrival time).
datum[datum != 0] = 1 / datum[datum != 0] * 1000
# Make spike data from Poisson sampling.
s_times = np.random.poisson(datum, [time, size])
s_times = np.cumsum(s_times, axis=0)
s_times[s_times >= time] = 0
# Create spike trains from spike times.
s = np.zeros([time, size])
for i in range(time):
s[s_times[i], np.arange(size)] = 1
s[0, :] = 0
s = s.reshape([time, *shape])
return torch.Tensor(s).byte()
There are a few things that are missing:
No concept of a time step. If we assume the data are coded as rates, with Hz units (which perhaps we should, and which is implicitly assumed in the current poisson implementation), then global time step should have an effect on interspike intervals.
No concept of time-varying input. @dsanghavi worked on a sort of overlapping Poisson encoding function, but we really need something that implements inhomogeneous Poisson processes. This would allow us to naturally encode time-varying input. This might implemented in a separate function (say, inhomogeneous_poisson), or by means of a boolean argument to poisson which signals that, say, the first dimension of the input is the time dimension. I'm leaning towards the latter.
I'd allow like to include this in a PoissonInput(Nodes) object, which would accept a rates parameter specifying the per-neuron firing rate (parametrizing their Poisson spike trains). This would optionally be time-varying. On each step of a PoissonInput instance, it would generate its output using the poisson function and its rates attribute.
The substantive requests here are done: bindsnet.encoding.poisson now uses torch.distributions.Poisson, no longer depends on numpy, and takes a dt time-step parameter. Closing as resolved. If time-varying-rate (inhomogeneous) Poisson is wanted, that's a separate feature — please open a new issue for it.
Activity
Hananel-Hazan commentedon Jun 15, 2026
The substantive requests here are done: bindsnet.encoding.poisson now uses torch.distributions.Poisson, no longer depends on numpy, and takes a dt time-step parameter. Closing as resolved. If time-varying-rate (inhomogeneous) Poisson is wanted, that's a separate feature — please open a new issue for it.