PathUntruncation¶
-
class passengersim.rm.untruncation.PathUntruncation(*, carrier: str =
'', minimum_sample: int =10, cfg: Config | None =None, algorithm: 'em' | 'em_py' | 'none' | 'naive1' | 'naive2' | 'naive3' | 'pd' | 'mfem' ='em', which_data: 'total' | 'yieldable' | 'priceable' ='total', maxiter: int =20, tolerance: float =0.01, initialization_method: 'default' | 'pods' ='default', minimum_mu: float =0.01, minimum_sigma: float =0.1)[source]¶ Bases:
RmActionPath-level demand untruncation tool.
Methods
__init__(*[, carrier, minimum_sample, cfg, ...])apply_snapshot_filters(sim, days_prior, ...)Apply this action's snapshot filters, if any, and return the resulting instruction.
configure([fixed])Create an RmActionFactory for this action with the given configuration.
get_dcp_index(days_prior[, allow_between])init(sim)Initialize the action for the given simulation.
run(sim, days_prior)Execute the action for the given simulation.
should_run(sim, days_prior)Determine if the action should run on the given days_prior.
Attributes
The frequency with which to run this action.
Which data to use for untruncation.
Untruncation algorithm.
Maximum number of iterations for the EM and PD algorithms.
Tolerance for the EM and PD algorithms.
Method for initializing the EM algorithm.
Minimum value for the mean of the demand distribution.
Minimum value for the standard deviation of the demand distribution.
Set of days prior to departure on which to run this action.
The carrier upon which to apply this action.
The minimum sample number before this action will run.
-
produces : set[str] =
{'path_demand'}¶
-
frequency : Literal['dcp', 'daily', 'daily_pre_dep', 'non_dcp', 'begin_sample', 'end_sample', 'weekly'] =
'begin_sample'¶ The frequency with which to run this action.
This can be one of the following values: - “dcp”: run only on the specified DCPs. - “daily”: run every day. - “daily_pre_dep”: run every day prior to departure (i.e., days_prior > 0).” - “non_dcp”: run on days that are not in the specified DCPs. - “begin_sample”: run only on the first DCP (i.e., the maximum days_prior). - “end_sample”: run only on the day of departure (i.e., days_prior == 0). - “weekly”: run every 7 days (i.e. when days_prior is a multiple of 7).
The run method of RM actions is actually called every day (as it is implemented as a daily callback), but the first thing the run method should do is check whether it should actually execute on that day, using the should_run method, which uses this frequency setting to determine whether to proceed.
- apply_snapshot_filters(sim: Simulation, days_prior: int, *args, **kwargs) SnapshotInstruction | None¶
Apply this action’s snapshot filters, if any, and return the resulting instruction.
If there are no snapshot filters, or if none of the filters trigger, then this returns None.
-
classmethod configure(fixed: dict[str, Any] | None =
None, **kwargs) RmActionFactory¶ Create an RmActionFactory for this action with the given configuration.
Each keyword argument name should correspond to a parameter in the RmAction subclass’s __init__ method. The value of each keyword argument will be the keyword argument used in the RmSys that uses this factory.
Fixed values can be provided via the fixed parameter, which is a dictionary of parameter names to fixed values. These values will always be passed to the RmAction constructor, and cannot be overridden via the RmSys.
-
get_dcp_index(days_prior: int, allow_between: bool =
False) int¶
- init(sim: Simulation)¶
Initialize the action for the given simulation.
This is a hook called once at the beginning of the simulation, after the entire network and all core data structures have been set up but before any simulation samples have been run. It can be used to perform any necessary setup before the first call to run. By default, this does nothing, but subclasses can override it if needed.
-
requires : set[str] =
{}¶
- should_run(sim: Simulation, days_prior: int) bool¶
Determine if the action should run on the given days_prior.
-
snapshot_filter_type : type[GenericSnapshotFilter] =
None¶
- which_data¶
Which data to use for untruncation.
- dcps : set[int]¶
Set of days prior to departure on which to run this action.
- carrier¶
The carrier upon which to apply this action.
- minimum_sample¶
The minimum sample number before this action will run.
- algorithm¶
Untruncation algorithm.
There are several available algorithms:
- none
applies no untruncation, and assumes that demand was the same as sales. Applying this algorithm is still important even if no detruncation is desired, as PassengerSim tracks historical demand separately from sales and without “none” the historical demand used in forecasting would be zero.
- em
is an expectation-maximization model.
- em_py
is an expectation-maximization model implemented in Python. It is slow but useful for educational purposes.
- naive1
is not recommended for use.
- naive2
is not recommended for use.
- naive3
is not recommended for use.
- pd
is a projection-detruncation model, based on the method developed by Hopperstad and described by Weatherford & Polt.
- mfem
Multi-Flight Expectation Maximization. Takes into account spill and recapture across multiple departures
- maxiter¶
Maximum number of iterations for the EM and PD algorithms.
- tolerance¶
Tolerance for the EM and PD algorithms.
- initialization_method¶
Method for initializing the EM algorithm.
The default method is to use all available data on the first EM iteration. The pods method is to use only the data from unclosed observations on the first EM iteration.
- minimum_mu¶
Minimum value for the mean of the demand distribution.
If the computed mean is less than this value, untruncation will result in zero demand. Setting this to a very small but non-zero value can help avoid thin-path problems, where untruncation results in some non-zero demand on every path-class, even though many path-classes have zero historical sales and probably will stay that way.
- minimum_sigma¶
Minimum value for the standard deviation of the demand distribution.
If the computed sigma is less than this value, this value is used instead.
- run(sim: Simulation, days_prior: int)[source]¶
Execute the action for the given simulation.
Subclasses must implement this method.
-
produces : set[str] =