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.18.1 passengersim.core 0.18.1
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 = pax.Config.from_yaml([
"network/08-untrunc-em.yaml",
])
InĀ [3]:
Copied!
cfg.simulation_controls.num_trials = 1
cfg.simulation_controls.num_trials = 1
InĀ [4]:
Copied!
sim = pax.Simulation(cfg)
baseline_summary = sim.run()
sim = pax.Simulation(cfg)
baseline_summary = sim.run()
Task Completed after 2.17 seconds
InĀ [5]:
Copied!
baseline_summary.fig_carrier_revenues()
baseline_summary.fig_carrier_revenues()
Out[5]:
Now we swap in our custom forecast algorithm.
InĀ [6]:
Copied!
from passengersim.extra.olympic_forecast import OlympicForecastStep
from passengersim.extra.olympic_forecast import OlympicForecastStep
InĀ [7]:
Copied!
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
airlines:
- 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
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
airlines:
- 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Ā [8]:
Copied!
sim = pax.Simulation(cfg)
sim = pax.Simulation(cfg)
InĀ [9]:
Copied!
summary = sim.run()
summary = sim.run()
Task Completed after 13.70 seconds
InĀ [10]:
Copied!
summary.fig_carrier_revenues()
summary.fig_carrier_revenues()
Out[10]:
Comparing ResultsĀ¶
InĀ [11]:
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Ā [12]:
Copied!
comp.fig_carrier_revenues()
comp.fig_carrier_revenues()
Out[12]:
InĀ [13]:
Copied!
comp.fig_carrier_load_factors()
comp.fig_carrier_load_factors()
Out[13]:
InĀ [14]:
Copied!
comp.fig_fare_class_mix()
comp.fig_fare_class_mix()
Out[14]:
InĀ [15]:
Copied!
comp.fig_bookings_by_timeframe(by_carrier="AL1", by_class=True, source_labels=True)
comp.fig_bookings_by_timeframe(by_carrier="AL1", by_class=True, source_labels=True)
Out[15]:
InĀ [16]:
Copied!
comp.fig_leg_forecasts(by_flt_no=101, of=["mu", "sigma"])
comp.fig_leg_forecasts(by_flt_no=101, of=["mu", "sigma"])
Out[16]:
InĀ [17]:
Copied!
comp.fig_leg_forecasts(by_flt_no=111, of=["mu", "sigma"])
comp.fig_leg_forecasts(by_flt_no=111, of=["mu", "sigma"])
Out[17]: