Custom Forecaster¶
In this example, we use a custom forecast algorithm, the "Olympic Average", implemented in Python. In this forecast, the mean (mu) forecast for any bucket is computed by taking the 26 historical values, discarding the highest and lowest, and taking the mean of the remaining 24 values.
In [1]:
Copied!
import passengersim as pax
pax.versions()
import passengersim as pax
pax.versions()
passengersim 0.51.dev11+g921f2a8 passengersim.core 0.51.dev2+g02d3ce20
We'll first run a simulation without the change as a baseline. As this tutorial is meant as a technology demonstration and not for serious statistical analysis, we'll only run one trial so it goes fast, and we won't worry about statistical validity.
In [2]:
Copied!
cfg = pax.Config.from_yaml("network/08-untrunc-em.yaml")
cfg.simulation_controls.num_trials = 1
cfg = pax.Config.from_yaml("network/08-untrunc-em.yaml")
cfg.simulation_controls.num_trials = 1
In [3]:
Copied!
sim = pax.Simulation(cfg)
baseline_summary = sim.run()
sim = pax.Simulation(cfg)
baseline_summary = sim.run()
Task Completed after 2.65 seconds
In [4]:
Copied!
baseline_summary.fig_carrier_revenues()
baseline_summary.fig_carrier_revenues()
Out[4]:
Now we swap in our custom forecast algorithm.
In [5]:
Copied!
from passengersim.extra.olympic_forecast import OlympicForecastStep # noqa: F401
extra_config = """
rm_systems:
rm_test2:
availability_control: leg
processes:
DCP:
- step_type: untruncation
algorithm: em
kind: leg
- step_type: olympicforecast
- step_type: emsr
algorithm: emsrb
carriers:
- name: AL1
rm_system: rm_test2
- name: AL2
rm_system: rm_test1
"""
cfg = pax.Config.from_yaml(
[
"network/08-untrunc-em.yaml",
extra_config,
]
)
cfg.simulation_controls.num_trials = 1
from passengersim.extra.olympic_forecast import OlympicForecastStep # noqa: F401
extra_config = """
rm_systems:
rm_test2:
availability_control: leg
processes:
DCP:
- step_type: untruncation
algorithm: em
kind: leg
- step_type: olympicforecast
- step_type: emsr
algorithm: emsrb
carriers:
- name: AL1
rm_system: rm_test2
- name: AL2
rm_system: rm_test1
"""
cfg = pax.Config.from_yaml(
[
"network/08-untrunc-em.yaml",
extra_config,
]
)
cfg.simulation_controls.num_trials = 1
In [6]:
Copied!
sim = pax.Simulation(cfg)
sim = pax.Simulation(cfg)
In [7]:
Copied!
summary = sim.run()
summary = sim.run()
Task Completed after 2.36 seconds
In [8]:
Copied!
summary.fig_carrier_revenues()
summary.fig_carrier_revenues()
Out[8]:
Comparing Results¶
In [9]:
Copied!
from passengersim.contrast import Contrast
comp = Contrast(Baseline=baseline_summary, Olympic=summary)
from passengersim.contrast import Contrast
comp = Contrast(Baseline=baseline_summary, Olympic=summary)
In [10]:
Copied!
comp.fig_carrier_revenues()
comp.fig_carrier_revenues()
Out[10]:
In [11]:
Copied!
comp.fig_carrier_load_factors()
comp.fig_carrier_load_factors()
Out[11]:
In [12]:
Copied!
comp.fig_fare_class_mix()
comp.fig_fare_class_mix()
Out[12]:
In [13]:
Copied!
comp.fig_segmentation_by_timeframe(
"bookings", by_carrier="AL1", by_class=True, source_labels=True
)
comp.fig_segmentation_by_timeframe(
"bookings", by_carrier="AL1", by_class=True, source_labels=True
)
Out[13]:
In [14]:
Copied!
comp.fig_leg_forecasts(by_leg_id=101, of=["mu", "sigma"])
comp.fig_leg_forecasts(by_leg_id=101, of=["mu", "sigma"])
Out[14]:
In [15]:
Copied!
comp.fig_leg_forecasts(by_leg_id=111, of=["mu", "sigma"])
comp.fig_leg_forecasts(by_leg_id=111, of=["mu", "sigma"])
Out[15]: