HomogeneousPoissonEncoder¶
- class HomogeneousPoissonEncoder(steps: int, step_time: float, frequency: float, *, refrac: float | None = None, compensate: bool = True, generator: Generator | None = None)[source]¶
Bases:
GeneratorMixin
,RefractoryStepMixin
,Module
Encoder to generate spike trains sampled from a Poisson distribution.
This method samples randomly from an exponential distribution (the interval between samples in a Poisson point process), adding an additional refractory period and compensating 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}\).
refrac (float | None, optional) – minimum interval between spikes set to the step time if
None
, in \(\text{ms}\). Defaults toNone
.compensate (bool, optional) – if the spike generation rate should be compensate for the refractory period. Defaults to
True
.generator (torch.Generator | None, optional) – pseudorandom number generator for sampling. Defaults to
None
.
Note
refrac
at its default still allows for a spike to be generated at every step (since the distance between is \(\Delta t\)). To get behavior where at most every \(n^\text{th}\) step is a spike, the refractory period needs to be set to \(n \Delta t\).- 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
.