poisson_input

Contents

poisson_input#

class brainpy.state.poisson_input(freq, num_input, weight, target, indices=None, refractory=None)#

Generates Poisson-distributed input spikes to a target state variable.

This function simulates Poisson input to a given state, updating the target variable with generated spikes based on the specified frequency, number of inputs, and synaptic weight. The input can be applied to specific indices of the target or to the entire target if indices are not provided.

The function uses two different methods to generate the Poisson-distributed input: 1. For large numbers of inputs (a > 5 and b > 5), a normal approximation is used 2. For smaller numbers, a direct binomial sampling approach is used

Mathematical model for Poisson input:

\[ P(\text{spike}) = \text{freq} \cdot \text{dt} \]

For the normal approximation (when a > 5 and b > 5):

\[ \text{inputs} \sim \mathcal{N}(a, b \cdot p) \]
where:
\[ a = \text{num\_input} \cdot p \]
\[ b = \text{num\_input} \cdot (1 - p) \]
\[ p = \text{freq} \cdot \text{dt} \]

For direct binomial sampling (when a ≤ 5 or b ≤ 5):

\[ \text{inputs} \sim \text{Binomial}(\text{num\_input}, p) \]

Parameters:
  • freq (u.Quantity[u.Hz]) – The frequency of the Poisson input in Hertz.

  • num_input (int) – The number of input channels or neurons generating the Poisson spikes.

  • weight (u.Quantity) – The synaptic weight applied to each spike.

  • target (State) – The target state variable to which the Poisson input is applied.

  • indices (Optional[Union[np.ndarray, jax.Array]], optional) – Specific indices of the target to apply the input. If None, the input is applied to the entire target.

  • refractory (Optional[Union[jax.Array]], optional) – A boolean array indicating which parts of the target are in a refractory state and should not be updated. Should be the same length as the target.

See also

PoissonInput

Object-oriented wrapper around this function.

PoissonSpike

Poisson spike generator as a neuron group.

Notes

  • The function automatically switches between normal approximation and binomial sampling based on the input parameters to optimize computation efficiency.

  • For large numbers of inputs, the normal approximation provides significant performance improvements.

  • The weight parameter is applied uniformly to all generated spikes.

  • When refractory is provided, the corresponding target elements are not updated.

Examples

>>> import brainpy
>>> import brainstate
>>> import saiunit as u
>>> import numpy as np
>>>
>>> # Create a membrane potential state
>>> V = brainstate.HiddenState(np.zeros(100) * u.mV)
>>>
>>> # Add Poisson input to all neurons at 50 Hz
>>> brainpy.state.poisson_input(
...     freq=50 * u.Hz,
...     num_input=200,
...     weight=0.1 * u.mV,
...     target=V
... )
>>>
>>> # Apply Poisson input only to a subset of neurons
>>> indices = np.array([0, 10, 20, 30])
>>> brainpy.state.poisson_input(
...     freq=100 * u.Hz,
...     num_input=50,
...     weight=0.2 * u.mV,
...     target=V,
...     indices=indices
... )
>>>
>>> # Apply input with refractory mask
>>> refractory = np.zeros(100, dtype=bool)
>>> refractory[40:60] = True  # neurons 40-59 are in refractory period
>>> brainpy.state.poisson_input(
...     freq=75 * u.Hz,
...     num_input=100,
...     weight=0.15 * u.mV,
...     target=V,
...     refractory=refractory
... )