DiffEncoder#
- class brainpy.encoding.DiffEncoder(threshold=0.1, padding=False, off_spike=False)[source]#
Generate spike only when the difference between two subsequent time steps meets a threshold.
Optionally include off_spikes for negative changes.
- Parameters:
threshold (
float) – Input features with a change greater than the thresold across one timestep will generate a spike, defaults to0.1.padding (
bool) – Used to change how the first time step of spikes are measured. IfTrue, the first time step will be repeated with itself resulting in0’s for the output spikes. IfFalse, the first time step will be padded with0’s, defaults toFalse.off_spike (
bool) – IfTrue, negative spikes for changes less than-threshold, defaults toFalse.
Examples
>>> a = bm.array([1, 2, 2.9, 3, 3.9]) >>> encoder = DiffEncoder(threshold=1) >>> encoder.multi_steps(a) Array([1., 0., 0., 0.]) >>> encoder = DiffEncoder(threshold=1, padding=True) >>> encoder.multi_steps(a) Array([0., 1., 0., 0., 0.]) >>> b = bm.array([1, 2, 0, 2, 2.9]) >>> encoder = DiffEncoder(threshold=1, off_spike=True) >>> encoder.multi_steps(b) Array([ 1., 1., -1., 1., 0.]) >>> encoder = DiffEncoder(threshold=1, padding=True, off_spike=True) >>> encoder.multi_steps(b) Array([ 0., 1., -1., 1., 0.])