PoissonEncoder#

class brainpy.encoding.PoissonEncoder(min_val=None, max_val=None, gain=1.0, offset=0.0, first_spk_time=0.0)[source]#

Encode the rate input as the Poisson spike train.

Expected inputs should be between 0 and 1. If not, the input \(x\) will be normalized to \(x_{\text{normalize}}\) within [0, 1] according to \(x_{\text{normalize}} = \frac{x-\text{min_val}}{\text{max_val} - \text{min_val}}\).

Given the input \(x\), the poisson encoder will output spikes whose firing probability is \(x_{\text{normalize}}\).

Examples:

import brainpy as bp
import brainpy.math as bm

img = bm.random.random((10, 2))  # image to encode (normalized to [0., 1.])
encoder = bp.encoding.PoissonEncoder()  # the encoder

# encode the image at each time
for run_index in range(100):
  spike = encoder.single_step(img)
  # do something

# or, encode the image at multiple times once
spikes = encoder.multi_steps(img, n_time=10.)
Parameters:
  • min_val (Optional[float]) – float. The minimal value in the given data x, used to the data normalization.

  • max_val (Optional[float]) – float. The maximum value in the given data x, used to the data normalization.

  • gain (float) – float. Scale input features by the gain, defaults to 1.

  • offset (float) – float. Shift input features by the offset, defaults to 0.

  • first_spk_time (float) – float. The time to first spike, defaults to 0.

multi_steps(x, n_time)[source]#

Generate spikes at multiple steps according to the inputs.

Parameters:
  • x – Array. The rate input.

  • n_time (Optional[float]) –

    float. Encode rate values as spike trains in the given time length. n_time is converted into the n_step according to n_step = int(n_time / brainpy.math.dt). - If n_time=None, encode the rate values at the current time step.

    Users should repeatedly call it to encode x as a spike train.

    • Else, given the x with shape (S, ...), the encoded spike train is the array with shape (n_step, S, ...).

Returns:

Array. The encoded spike train.

Return type:

out

single_step(x, i_step=None)[source]#

Generate spikes at the single step according to the inputs.

Parameters:
  • x – Array. The rate input.

  • i_step (Optional[int]) – int. The time step to generate spikes.

Returns:

Array. The encoded spike train.

Return type:

out