SpikeCountEncoder

SpikeCountEncoder#

class braintools.spike.SpikeCountEncoder(max_spikes=10, distribution='random', normalize=True)#

Encode inputs as exact spike counts over time windows.

Each feature fires exactly \(\lfloor x \cdot \text{max_spikes} \rfloor\) times in the window (at most n_time, since a step holds at most one spike), spread evenly or at random distinct time steps.

Parameters:
  • max_spikes (int) – Number of spikes for an input value of 1.0.

  • distribution (str) – How to distribute the spikes: at random distinct steps, or evenly over the window.

  • normalize (bool) – Whether to clip inputs to [0, 1].

Raises:

ValueError – If distribution is not 'uniform' or 'random'.

See also

LatencyEncoder

One spike per feature, timed by its value.

Examples

>>> import brainstate
>>> import jax.numpy as jnp
>>> import braintools
>>> brainstate.random.seed(0)
>>> encoder = braintools.spike.SpikeCountEncoder(max_spikes=10, distribution='uniform')
>>> spikes = encoder(jnp.array([0.2, 0.5, 1.0]), n_time=100)
>>> spikes.sum(axis=0)
Array([ 2.,  5., 10.], dtype=float32)