Using Data Generator Stepper¶
Stepper is the core of the data generators. In EERILY, we create iterators called steppers which we can iterate over to get the samples. In this tutorial we generate some neuronal spiking time series.
In [1]:
Copied!
import matplotlib.pyplot as plt
from eerily.generators.spiking import SpikingEventParams, SpikingEventStepper
from eerily.generators.utils.events import PoissonEvent
from eerily.generators.utils.noises import LogNormalNoise
seed = 42
import matplotlib.pyplot as plt
from eerily.generators.spiking import SpikingEventParams, SpikingEventStepper
from eerily.generators.utils.events import PoissonEvent
from eerily.generators.utils.noises import LogNormalNoise
seed = 42
We first create the spiking event timing using a PoissonEvent.
In [2]:
Copied!
spiking_rate = 0.1
spiking_level_mu = 0.1
spiking_level_std = 0.05
spiking = PoissonEvent(rate=spiking_rate, seed=seed)
spiking_rate = 0.1
spiking_level_mu = 0.1
spiking_level_std = 0.05
spiking = PoissonEvent(rate=spiking_rate, seed=seed)
spiking
is only the indicator of the time where a spike happens as it can only take values 0 or 1. We have to specify the level of such spikes. Here we use a log normal distribution.
In [3]:
Copied!
spiking_level = LogNormalNoise(mu=spiking_level_mu, std=spiking_level_std, seed=seed)
spiking_level = LogNormalNoise(mu=spiking_level_mu, std=spiking_level_std, seed=seed)
To create realistic data, we also need some background noise. We create such background values using log normal distributions.
In [4]:
Copied!
background_mu = 1
background_std = 0.1
background = LogNormalNoise(mu=background_mu, std=background_std, seed=seed)
background_mu = 1
background_std = 0.1
background = LogNormalNoise(mu=background_mu, std=background_std, seed=seed)
We assemble these configurations for the spiking stepper.
In [5]:
Copied!
se_params = SpikingEventParams(
spike=spiking,
spike_level=spiking_level,
background=background,
variable_names=["event"],
initial_state=0,
)
se_params = SpikingEventParams(
spike=spiking,
spike_level=spiking_level,
background=background,
variable_names=["event"],
initial_state=0,
)
We create the spiking stepper using the above configuration.
In [6]:
Copied!
se = SpikingEventStepper(se_params)
se = SpikingEventStepper(se_params)
In this example, we create a time series with 100 steps.
In [7]:
Copied!
length = 100
se_data = [next(se) for _ in range(length)]
length = 100
se_data = [next(se) for _ in range(length)]
2023-11-11 11:59:30.996 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:30.997 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:30.998 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:30.999 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.000 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.001 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.002 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.003 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.003 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.004 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.005 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.005 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.011 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.011 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.012 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.013 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.014 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.014 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.015 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.016 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.016 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.017 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.018 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.018 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.019 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.020 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.020 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.021 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.021 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.022 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.023 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.023 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.024 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.024 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.025 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.026 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.027 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.027 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.028 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.028 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.029 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.030 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.030 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.031 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.032 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.032 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.033 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.034 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.035 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.035 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.036 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.037 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.038 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.039 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.040 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.040 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.041 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.041 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.042 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.042 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.043 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.043 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.044 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.045 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.045 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.046 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.046 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.047 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.047 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.048 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.049 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.049 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.050 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.050 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.051 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.051 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.052 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.052 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.053 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.054 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.054 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.055 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.055 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.056 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.056 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.057 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.057 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.058 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.059 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.059 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.060 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.060 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.061 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.061 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.062 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.062 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.063 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.064 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.064 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set 2023-11-11 11:59:31.065 | WARNING | eerily.generators.utils.stepper:__next__:59 - length is not set
In [8]:
Copied!
fig, ax = plt.subplots(figsize=(10, 6.18))
ax.plot(range(length), se_data, color="k", marker="o")
ax.set_xlabel("Time Step")
ax.set_ylabel("Potential")
ax.set_title("Spiking Example")
fig, ax = plt.subplots(figsize=(10, 6.18))
ax.plot(range(length), se_data, color="k", marker="o")
ax.set_xlabel("Time Step")
ax.set_ylabel("Potential")
ax.set_title("Spiking Example")
Out[8]:
Text(0.5, 1.0, 'Spiking Example')