Combining Data Generators¶
Steppers can be combined into one single generator. In this example, we reuse the concepts in the tutorial "Using Data Generator Stepper".
In eerily, we support two operators: &
and +
. The &
operator is used to merge two steppers, while the +
operator is used to concatenate two steppers.
Note that we need to use brackets to indicate that the merge has higher precedence,. i.e.
(stepper_1 & stepper_2) + stepper_3
instead of stepper_1 & stepper_2 + stepper_3
.
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_1 = PoissonEvent(rate=0.1, seed=seed)
spiking_2 = PoissonEvent(rate=0.9, seed=seed)
spiking_1 = PoissonEvent(rate=0.1, seed=seed)
spiking_2 = PoissonEvent(rate=0.9, seed=seed)
In [3]:
Copied!
spiking_level_1 = LogNormalNoise(mu=0.1, std=0.05, seed=seed)
spiking_level_2 = LogNormalNoise(mu=0.1, std=0.05, seed=seed)
spiking_level_1 = LogNormalNoise(mu=0.1, std=0.05, seed=seed)
spiking_level_2 = LogNormalNoise(mu=0.1, std=0.05, seed=seed)
In [4]:
Copied!
background_1 = LogNormalNoise(mu=1, std=0.1, seed=seed)
background_2 = LogNormalNoise(mu=1, std=0.1, seed=seed)
background_1 = LogNormalNoise(mu=1, std=0.1, seed=seed)
background_2 = LogNormalNoise(mu=1, std=0.1, seed=seed)
Create the spiking steppers:
In [5]:
Copied!
se_params_1 = SpikingEventParams(
spike=spiking_1,
spike_level=spiking_level_1,
background=background_1,
variable_names=["event"],
initial_state=0,
)
se_params_2 = SpikingEventParams(
spike=spiking_2,
spike_level=spiking_level_2,
background=background_2,
variable_names=["event"],
initial_state=0,
)
se_params_1 = SpikingEventParams(
spike=spiking_1,
spike_level=spiking_level_1,
background=background_1,
variable_names=["event"],
initial_state=0,
)
se_params_2 = SpikingEventParams(
spike=spiking_2,
spike_level=spiking_level_2,
background=background_2,
variable_names=["event"],
initial_state=0,
)
In [6]:
Copied!
se_1 = SpikingEventStepper(se_params_1, length=70)
se_2 = SpikingEventStepper(se_params_2, length=30)
se_1 = SpikingEventStepper(se_params_1, length=70)
se_2 = SpikingEventStepper(se_params_2, length=30)
We concat the two steppers.
In [7]:
Copied!
generator = se_1 + se_2
generator = se_1 + se_2
In [8]:
Copied!
fig, ax = plt.subplots(figsize=(10, 6.18))
ax.plot(range(100), list(generator), 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(100), list(generator), 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')
We can observe that the potential is higher after step 70. This is because we have a higher spiking rate in the second stepper.