Skip to content

generators.utils.events

Data - Generators - Events¤

PoissonEvent ¤

A Poisson process event generator.

See this notebook for more about a Poisson process.

rate = 0.1
pe = PoissonEvents(rate=rate)
next(pe)

:param lambda: the mean rate of the Poisson process :param seed: seed of the RNG for reproducibility

Source code in eerily/generators/utils/events.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class PoissonEvent:
    """A Poisson process event generator.

    See [this notebook](https://github.com/btel/python-in-neuroscience-tutorials/blob/master/poisson_process.ipynb) for more about a Poisson process.

    ```python
    rate = 0.1
    pe = PoissonEvents(rate=rate)
    next(pe)
    ```

    :param lambda: the mean rate of the Poisson process
    :param seed: seed of the RNG for reproducibility
    """

    def __init__(self, rate: float, seed: Optional[float] = None):
        self.rate = rate
        self.rng = np.random.default_rng(seed=seed)

    def __iter__(self):
        return self

    def __next__(self) -> float:
        random_state = self.rng.random() <= self.rate
        return int(random_state)