PoissonEncoder

Contents

PoissonEncoder#

class braintools.spike.PoissonEncoder(time_window=None, normalize=False, max_rate=100.0)#

Encode inputs as Poisson spike trains.

The input sets the rate of a Poisson process. In each time step the number of events is drawn from a Poisson distribution with mean \(\lambda = \text{rate} \cdot dt\) (with \(dt\) the brainstate.environ time step), and the step spikes when that number is positive, i.e. with probability \(1 - e^{-\lambda}\).

Parameters:
  • time_window (float | None) – Deprecated since 0.4.0 and unused (removed in 1.0.0); passing it emits a BraintoolsDeprecationWarning. The rate is set by the input (Hz) and the brainstate time step.

  • normalize (bool) – If False, inputs are rates in Hz. If True, inputs are fractions of max_rate.

  • max_rate (float) – Rate in Hz for an input of 1 when normalize=True.

See also

RateEncoder

Maps inputs to rates and fires with probability rate * dt.

BernoulliEncoder

Sets the spike probability per time step directly.

Examples

>>> import brainstate
>>> import brainunit as u
>>> import jax.numpy as jnp
>>> import braintools
>>> brainstate.environ.set(dt=1. * u.ms)
>>> brainstate.random.seed(0)
>>> rates = jnp.array([10.0, 50.0, 100.0])  # Hz
>>> spikes = braintools.spike.PoissonEncoder()(rates, n_time=1000)  # 1 s
>>> spikes.shape
(1000, 3)
>>> counts = spikes.sum(axis=0)  # approximately [10, 50, 100] spikes