Generator with Covariates¶
Many dynamical systems have observable covariates. For example, the sales of an article are related to the discounts. In this tutorial we generate some time series data with different discounts.
In [1]:
Copied!
import matplotlib.pyplot as plt
from eerily.generators.elasticity import ElasticityStepper, LinearElasticityParams
from eerily.generators.naive import (
ConstantStepper,
ConstStepperParams,
SequenceStepper,
SequenceStepperParams,
)
import matplotlib.pyplot as plt
from eerily.generators.elasticity import ElasticityStepper, LinearElasticityParams
from eerily.generators.naive import (
ConstantStepper,
ConstStepperParams,
SequenceStepper,
SequenceStepperParams,
)
Elasticity Stepper¶
In [2]:
Copied!
length = 10
elasticity = iter([-3] * length)
log_prices = iter(range(length))
initial_condition = {"log_demand": 3, "log_price": 0.5, "elasticity": None}
lep = LinearElasticityParams(
initial_state=initial_condition,
log_prices=log_prices,
elasticity=elasticity,
variable_names=["log_demand", "log_price", "elasticity"],
)
es = ElasticityStepper(model_params=lep, length=length)
next(es)
length = 10
elasticity = iter([-3] * length)
log_prices = iter(range(length))
initial_condition = {"log_demand": 3, "log_price": 0.5, "elasticity": None}
lep = LinearElasticityParams(
initial_state=initial_condition,
log_prices=log_prices,
elasticity=elasticity,
variable_names=["log_demand", "log_price", "elasticity"],
)
es = ElasticityStepper(model_params=lep, length=length)
next(es)
Out[2]:
{'log_demand': 4.5, 'log_price': 0, 'elasticity': -3}
Combining Multiple Elasticity Steppers¶
In [3]:
Copied!
elasticity_1 = iter([-3] * length)
log_prices_1 = iter(range(length))
lep_1 = LinearElasticityParams(
initial_state=initial_condition,
log_prices=log_prices_1,
elasticity=elasticity_1,
variable_names=["log_demand", "log_price", "elasticity"],
)
es_1 = ElasticityStepper(model_params=lep_1, length=length)
elasticity_1 = iter([-3] * length)
log_prices_1 = iter(range(length))
lep_1 = LinearElasticityParams(
initial_state=initial_condition,
log_prices=log_prices_1,
elasticity=elasticity_1,
variable_names=["log_demand", "log_price", "elasticity"],
)
es_1 = ElasticityStepper(model_params=lep_1, length=length)
In [4]:
Copied!
ssp = SequenceStepperParams(initial_state=[0], variable_names=["steps"], step_sizes=[1])
ss = SequenceStepper(model_params=ssp, length=length)
ssp = SequenceStepperParams(initial_state=[0], variable_names=["steps"], step_sizes=[1])
ss = SequenceStepper(model_params=ssp, length=length)
In [5]:
Copied!
csp = ConstStepperParams(initial_state=["brand_1"], variable_names=["name"])
cs = ConstantStepper(model_params=csp, length=length)
csp = ConstStepperParams(initial_state=["brand_1"], variable_names=["name"])
cs = ConstantStepper(model_params=csp, length=length)
We can combine the two steppers using &
.
In [6]:
Copied!
generator = es_1 & ss & cs
list(generator)
generator = es_1 & ss & cs
list(generator)
Out[6]:
[{'log_demand': 4.5, 'log_price': 0, 'elasticity': -3, 'steps': 1, 'name': 'brand_1'}, {'log_demand': 1.5, 'log_price': 1, 'elasticity': -3, 'steps': 2, 'name': 'brand_1'}, {'log_demand': -1.5, 'log_price': 2, 'elasticity': -3, 'steps': 3, 'name': 'brand_1'}, {'log_demand': -4.5, 'log_price': 3, 'elasticity': -3, 'steps': 4, 'name': 'brand_1'}, {'log_demand': -7.5, 'log_price': 4, 'elasticity': -3, 'steps': 5, 'name': 'brand_1'}, {'log_demand': -10.5, 'log_price': 5, 'elasticity': -3, 'steps': 6, 'name': 'brand_1'}, {'log_demand': -13.5, 'log_price': 6, 'elasticity': -3, 'steps': 7, 'name': 'brand_1'}, {'log_demand': -16.5, 'log_price': 7, 'elasticity': -3, 'steps': 8, 'name': 'brand_1'}, {'log_demand': -19.5, 'log_price': 8, 'elasticity': -3, 'steps': 9, 'name': 'brand_1'}, {'log_demand': -22.5, 'log_price': 9, 'elasticity': -3, 'steps': 10, 'name': 'brand_1'}]
In [ ]:
Copied!