PoissonIntervalEncoder

class PoissonIntervalEncoder(steps: int, step_time: float, frequency: float, *, generator: Generator | None = None)[source]

Bases: GeneratorMixin, StepMixin, Module

Encoder to generate spike trains with intervals sampled from a Poisson distribution.

This is included to replicate BindsNET’s Poisson spike generation. The intervals between spikes follow the Poisson distribution parameterized with the inverse of the expected rate (i.e. the scale is given as the rate).

Parameters:
  • steps (int) – number of steps for which to generate spikes, \(S\).

  • step_time (float) – length of time between outputs, \(\Delta t\), in \(\text{ms}\).

  • frequency (float) – maximum spike frequency (associated with an input of 1), \(f\), in \(\text{Hz}\).

  • generator (torch.Generator | None, optional) – pseudorandom number generator for sampling. Defaults to None.

forward(inputs: Tensor, online: bool = False) Tensor | Iterator[Tensor][source]

Generates a spike train from inputs.

The spike trains are generated with frequencies scaled linearly by the input, with a maximum frequency equal to the hyperparameter defined on initialization.

Parameters:
  • inputs (torch.Tensor) – intensities, scaled \([0, 1]\), for spike frequencies.

  • online (bool, optional) – if spike generation should be computed separately at each time step. Defaults to False.

Returns:

tensor spike train (if not online) otherwise a generator which yields time slices of the spike train.

Return type:

torch.Tensor | Iterator[torch.Tensor]

Shape

inputs:

\(B \times N_0 \times \cdots\)

return (online=False):

\(S \times B \times N_0 \times \cdots\)

yield (online=True):

\(B \times N_0 \times \cdots\)

Where:
  • \(B\) is the batch size.

  • \(N_0, \ldots\) are the dimensions of the spikes being generated.

  • \(S\) is the number of steps for which to generate spikes, steps.

property frequency: float

Expected frequency of spikes by which inputs are scaled, in hertz.

Parameters:

value (float) – new frequency scale for inputs.

Returns:

present frequency scale for inputs.

Return type:

float