sd_prim_flu.py

 1"""
 2
 3This file illustrated the use of the workbench for doing
 4a PRIM analysis.
 5
 6The data was generated using a system dynamics models implemented in Vensim.
 7See flu_example.py for the code.
 8
 9
10.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
11                chamarat <c.hamarat  (at) tudelft (dot) nl>
12
13"""
14
15import matplotlib.pyplot as plt
16
17import ema_workbench.analysis.prim as prim
18from ema_workbench import ema_logging, load_results
19
20ema_logging.log_to_stderr(level=ema_logging.INFO)
21
22
23def classify(data):
24    # get the output for deceased population
25    ooi = data["deceased_population_region_1"]
26    return ooi[:, -1] > 1000000
27
28
29# load data
30fn = r"./data/1000 flu cases no policy.tar.gz"
31results = load_results(fn)
32
33# perform prim on modified results tuple
34prim_obj = prim.setup_prim(results, classify, threshold=0.8, threshold_type=1)
35
36box_1 = prim_obj.find_box()
37box_1.show_ppt()
38box_1.show_tradeoff()
39# box_1.inspect([5, 6], style="graph", boxlim_formatter="{: .2f}")
40
41fig, axes = plt.subplots(nrows=2, ncols=1)
42
43box_1.inspect([5, 6], style="graph", boxlim_formatter="{: .2f}", ax=axes)
44plt.show()
45
46box_1.inspect(5)
47box_1.select(5)
48box_1.write_ppt_to_stdout()
49box_1.show_pairs_scatter(5)
50
51# print prim to std_out
52print(prim_obj.stats_to_dataframe())
53print(prim_obj.boxes_to_dataframe())
54
55# visualize
56prim_obj.show_boxes()
57plt.show()