RankOrderEncoder

Contents

RankOrderEncoder#

class braintools.spike.RankOrderEncoder(use_values=True, normalize=True, invert=False)#

Encode inputs using rank order coding.

Orders input features by their values and generates one spike per feature in rank order. The most active features spike first, followed by less active ones, which preserves the relative ordering of the input features.

Parameters:
  • use_values (bool) – If True, the spike step is proportional to \(1 - x\) (equal values fire together). If False, only the rank matters and spikes are evenly spaced over the window.

  • normalize (bool) – Whether to rescale the input vector to [0, 1] first.

  • invert (bool) – Whether to invert the order (smallest first).

See also

LatencyEncoder

One spike per feature, timed by a linear or log code.

Examples

>>> import jax.numpy as jnp
>>> import braintools
>>> encoder = braintools.spike.RankOrderEncoder()
>>> spikes = encoder(jnp.array([0.1, 0.8, 0.3, 0.9, 0.2]), n_time=10)
>>> # Feature 3 (0.9) spikes first, then feature 1 (0.8), etc.
>>> jnp.argmax(spikes, axis=0)
Array([9, 1, 6, 0, 7], dtype=int32)