Skip to main content

Import

Encoders convert raw input data into spike rasters suitable for THRINDEX models. Every encoder produces a tensor of shape [batch, T, n_features] with values in .

enc.rate_encode

Encodes real-valued input as a Poisson spike process over T timesteps.
Parameters Behavior Each input value x[b, i] is treated as a probability: at each timestep t, neuron i fires with probability x[b, i]. The output is a Bernoulli sample over [batch, T, n_features].

enc.temporal_contrast

Encodes a temporal signal (audio, sensor) using temporal contrast: a spike is emitted when the signal changes by more than a threshold, with separate ON (increase) and OFF (decrease) channels.
Parameters Output channels The output has 2 × n_features channels:
  • Channels 0..n: ON events (signal increased by ≥ threshold)
  • Channels n..2n: OFF events (signal decreased by ≥ threshold)
This matches the DVS event camera polarity convention.

enc.cochlear_encode

Encodes an audio waveform through a bank of bandpass filters (cochlear model) into a spike raster. Produces the SHD-compatible encoding used in the keyword-spotting tutorial.
Parameters Notes
  • Frequency bands are spaced logarithmically between freq_min and freq_max.
  • Each channel fires when the bandpass-filtered signal exceeds its local threshold (set at 2σ from the silence baseline).
  • This encoder is consistent with the SHD dataset’s cochlear model but is independently implemented.

enc.SHDLoader

A dataset loader that returns pre-encoded SHD spike rasters directly.
SHDLoader downloads and caches the dataset from the official source on first use. It returns pre-binned spike rasters in the THRINDEX-native format.