BernoulliEncoder#
- class braintools.spike.BernoulliEncoder(scale=1.0, normalize=True, min_val=None, max_val=None)#
Encode inputs using independent Bernoulli processes.
Each input value is converted to a probability \(p = \text{clip}(x \cdot \text{scale}, 0, 1)\), and spikes are generated independently at each time step with that probability. The probability is per step, independent of the time step
dt: the same input gives a higher rate in Hz whendtis smaller.- Parameters:
See also
RateEncoderFires with probability
rate * dtfor a rate in Hz.PoissonEncoderPoisson spike trains from rates in Hz.
Examples
>>> import brainstate >>> import jax.numpy as jnp >>> import braintools >>> brainstate.random.seed(0) >>> encoder = braintools.spike.BernoulliEncoder() >>> spikes = encoder(jnp.array([0.1, 0.5, 0.9]), n_time=1000) >>> spikes.shape (1000, 3) >>> p = spikes.mean(axis=0) # approximately [0.1, 0.5, 0.9] per step