Using Data Generator Utilities¶
In this tutorial, we explore some utilities for generating time series data. EERILY provides noise generators (eerily.generators.utils.noises
), event generators (eerily.generators.utils.events
), a basic stepper to help the users create iterators of time series (eerily.generators.utils.stepper
), and finally factories to unify them.
import matplotlib.pyplot as plt
seed = 42
length = 20
Noise¶
Noise is an important part of a real word dataset. To generate realistic time series data, we always add noise to the data points.
from eerily.generators.utils.noises import GaussianNoise
GaussianNoise requires a mean and a standard deviation.
gn_mu = 1
gn_std = 0.1
gn = GaussianNoise(mu=gn_mu, std=gn_std, seed=seed)
The Gaussian noise gn
is an iterator.
gn_data = [next(gn) for _ in range(length)]
gn_data
[1.030471707975443, 0.8960015893759504, 1.0750451195806456, 1.0940564716391215, 0.8048964811346163, 0.8697820493137682, 1.0127840403167285, 0.9683757407656418, 0.9983198842495711, 0.914695607242642, 1.0879397974862828, 1.0777791935428949, 1.0066030697561217, 1.1127241206968033, 1.0467509342252046, 0.9140707537116761, 1.0368750784082499, 0.9041117399171001, 1.0878450301307272, 0.9950074089013747]
fig, ax = plt.subplots(figsize=(10, 6.18))
ax.plot(range(length), gn_data, color="k", marker="o")
ax.set_xlabel("Time Step")
ax.set_ylabel("Noise")
ax.set_title("GaussianNoise Example")
Text(0.5, 1.0, 'GaussianNoise Example')
Events¶
Suppose we set a sensor on a road to record whether a car is passing. Assuming the traffic flow is sparse, we expect to see some spikes in this time series. A simple model is a Poisson process.
In this section, we demo the PoissonEvent
class.
from eerily.generators.utils.events import PoissonEvent
PoissonEvent
requires one argument rate
. We can also set the seed
for reproducibility.
pe_rate = 0.5
pe = PoissonEvent(rate=pe_rate, seed=seed)
The event defined pe
is an iterator. We iterate to get some data.
pe_data = [next(pe) for _ in range(length)]
pe_data
[0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0]
fig, ax = plt.subplots(figsize=(10, 6.18))
ax.plot(range(length), pe_data, color="k", marker="o")
ax.set_xlabel("Time Step")
ax.set_ylabel("Event")
ax.set_title("PoissonEvent Example")
Text(0.5, 1.0, 'PoissonEvent Example')