scenarios
Class to define and run scenarios
Classes
| Name | Description |
|---|---|
| Scenario | Store the specification for a single scenario (which may consist of multiple interventions). |
| Scenarios | Run different intervention scenarios. |
Scenario
scenarios.Scenario(
spec=None,
label=None,
pars=None,
year=None,
eff=None,
dur_use=None,
p_use=None,
par=None,
par_years=None,
par_vals=None,
interventions=None,
)Store the specification for a single scenario (which may consist of multiple interventions).
Note, this class may be deprecated. See the scripts in the examples folder and the tests in test_interventions for examples of how to define simulations with different parameters or interventions and run them in parallel.
Args (shared): spec (dict): a pre-made specification of a scenario; see keyword explanations below (optional) args (list): additional specifications (optional) label (str): the sim label to use for this scenario pars (dict): optionally supply additional sim parameters to use with this scenario (that take effect at the beginning of the sim, not at the point of intervention) year (float): the year at which to activate efficacy and probability scenarios eff (dict): a dictionary of method names and new efficacy values par (str): the parameter to modify par_years (float/list): the year(s) at which to apply the modifications par_vals (float/list): the value(s) of the parameter for each year interventions (Intervention/list): any custom intervention(s) to be applied to the scenario
Congratulations on making it this far.
Examples::
# Basic efficacy scenario
s1 = fp.make_scen(eff={'Injectables':0.99}, year=2020)
# Parameter scenario: halve exposure
s2 = fp.make_scen(par='exposure_factor', par_years=2010, par_vals=0.5)
# Custom scenario
def update_sim(sim): sim.updated = True
s3 = fp.make_scen(interventions=update_sim)
# Scenarios can be combined (although this is not necessarily recommended)
s4 = s1 + s2
Methods
| Name | Description |
|---|---|
| run | Shortcut for creating and running a Scenarios object based on the current scenario. |
| update_label | Ensure all specs have the correct label |
run
scenarios.Scenario.run(run_args=None, **kwargs)Shortcut for creating and running a Scenarios object based on the current scenario.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| run_args | dict | passed to scens.run() | None |
| kwargs | dict | passed to Scenarios() | {} |
update_label
scenarios.Scenario.update_label(label=None)Ensure all specs have the correct label
Scenarios
scenarios.Scenarios(repeats=None, scens=None)Run different intervention scenarios.
A “scenario” can be thought of as a list of sims, all with the same parameters except for the random seed. Usually, scenarios differ from each other only in terms of the interventions run (to compare other differences between sims, it’s preferable to use a MultiSim object).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pars | dict | parameters to pass to the sim | required |
| repeats | int | how many repeats of each scenario to run (default: 1) | None |
| scens | list | the list of scenarios to run; see also fp.make_scen() and Scenarios.add_scen() |
None |
| kwargs | dict | optional additional parameters to pass to the sim | required |
Example::
scen1 = fp.make_scen(label='Baseline')
scen2 = fp.make_scen(year=2002, eff={'Injectables':0.99}) # Basic efficacy scenario
scens = fp.Scenarios(location='test', repeats=2, scens=[scen1, scen2])
scens.run()
Methods
| Name | Description |
|---|---|
| add_scen | Add a scenario or scenarios to the Scenarios object |
| analyze_sims | Take a list of sims that have different labels and extrapolate statistics from each |
| check_run | Give a meaningful error message if the scenarios haven’t been run |
| make_scens | Convert a scenario specification into a list of sims |
| make_sims | Create a list of sims that are all identical except for the random seed |
| plot | Plot the scenarios with bands – see sim.plot() for args |
| plot_sims | Plot each sim as a separate line across all senarios – see sim.plot() for args |
| run | Actually run a list of sims |
add_scen
scenarios.Scenarios.add_scen(scen=None, label=None)Add a scenario or scenarios to the Scenarios object
analyze_sims
scenarios.Scenarios.analyze_sims(start=None, end=None)Take a list of sims that have different labels and extrapolate statistics from each
check_run
scenarios.Scenarios.check_run()Give a meaningful error message if the scenarios haven’t been run
make_scens
scenarios.Scenarios.make_scens()Convert a scenario specification into a list of sims
make_sims
scenarios.Scenarios.make_sims(scenlabel, **kwargs)Create a list of sims that are all identical except for the random seed
plot
scenarios.Scenarios.plot(to_plot=None, plot_sims=True, **kwargs)Plot the scenarios with bands – see sim.plot() for args
plot_sims
scenarios.Scenarios.plot_sims(to_plot=None, plot_sims=True, **kwargs)Plot each sim as a separate line across all senarios – see sim.plot() for args
run
scenarios.Scenarios.run(**kwargs)Actually run a list of sims
Functions
| Name | Description |
|---|---|
| make_scen | Alias for fp.Scenario(). |
make_scen
scenarios.make_scen(*args, **kwargs)Alias for fp.Scenario().