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

PyTorch implementation of (homogeneous / inhomogeneous) Poisson encoding #104

Open
djsaunde opened this issue Jul 27, 2018 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@djsaunde
Copy link
Collaborator

djsaunde commented Jul 27, 2018

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:

  1. 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.
  2. 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.

@djsaunde djsaunde added the enhancement New feature or request label Jul 27, 2018
@djsaunde djsaunde self-assigned this Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant