DeltaEncoder#
- class braintools.spike.DeltaEncoder(threshold=0.1, positive_only=False, absolute=False, normalize=True)#
Encode a time series by send-on-delta (level-crossing) modulation.
The encoder keeps a reference level per feature, starting at the first sample. Whenever the signal has moved at least
thresholdaway from the reference, a spike is emitted and the reference is reset to the current value. Slow drifts are therefore encoded as well as sudden jumps: a ramp of total height \(h\) produces about \(h / \text{threshold}\) spikes.- Parameters:
threshold (
float) – Change relative to the reference that triggers a spike.positive_only (
bool) – Emit spikes only for increases (output 0/1). The reference still follows decreases.absolute (
bool) – If False, increases give+1and decreases-1(ON/OFF events). If True, every crossing gives1.normalize (
bool) – Rescale each feature to[0, 1]over time first, sothresholdis a fraction of the feature’s range.
See also
StepCurrentEncoderEncodes inputs as constant currents.
Examples
>>> import jax.numpy as jnp >>> import braintools >>> encoder = braintools.spike.DeltaEncoder(threshold=0.25, normalize=False) >>> encoder(jnp.array([0.0, 0.1, 0.2, 0.3, 0.3, 0.0])) Array([ 0., 0., 0., 1., 0., -1.], dtype=float32) >>> >>> absolute = braintools.spike.DeltaEncoder(threshold=0.25, normalize=False, absolute=True) >>> absolute(jnp.array([0.0, 0.1, 0.2, 0.3, 0.3, 0.0])) Array([0., 0., 0., 1., 0., 1.], dtype=float32)