Poisson Algorithm
- poisson(signal: ndarray, interval_length: int, seed: int = 0) ndarray[source]¶
Perform Poisson encoding on the input signal.
This function generates a spike train using a Poisson distribution, where the probability of emitting a spike in a given interval is determined by the normalized rate of the signal.
See the Poisson Encoding description for a detailed explanation of the Poisson encoding algorithm.
Note
If
interval_length == 1, each input value is treated directly as the firing rate (after normalization/clipping), resulting in a standard bin-by-bin approximation of Poisson encoding (at most one spike per time step).If
interval_length > 1, the average value over each interval block determines the constant firing rate for that block. Spikes are placed within the block using exponentially distributed inter-spike intervals, allowing multiple spikes per block (exact Poisson generation for the block’s constant rate).
Code Example:
import numpy as np from spikify.encoders.rate import poisson signal = np.array([0.2, 0.5, 0.8, 1.0]) np.random.seed(0) interval_length = 2 encoded_signal = poisson(signal, interval_length)
- Parameters:
signal (numpy.ndarray) – Input signal to encode (1D or 2D: timestamps × features).
interval_length (int) – Length of each time block for rate computation and spike placement. Must evenly divide the signal length.
interval_length=1uses the instantaneous value as rate (bin-by-bin); larger values use the block mean as constant rate (allows multiple spikes per block).seed (int) – Random seed for reproducibility. Default is 0.
- Returns:
A numpy array representing the encoded spike train.
- Return type:
- Raises:
ValueError – If the input signal is empty or if signal length is not divisible for the interval length
TypeError – If the signal is not a numpy.ndarray