-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_single_block_results.py
114 lines (107 loc) · 3.45 KB
/
draw_single_block_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
from draw_ppo_results import parse, filter_nan, get_termination
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
if __name__ == '__main__':
os.makedirs("results", exist_ok=True)
sns.set("talk", "darkgrid")
colors = sns.color_palette()[:4]
colors[2], colors[3] = colors[3], colors[2]
# ===== Draw the single-block agent's results =====
# Get data
sbdf = parse("data/single_block_agent", True)
# Draw training performance
new_df = get_termination(sbdf, evaluate=False)
sns.set("paper", "darkgrid")
new_df["Termination"] = new_df["done way"]
plt.figure(figsize=(4, 2))
ax = sns.histplot(
new_df,
x="timesteps_total",
hue="Termination",
weights="value",
multiple="fill",
element="poly",
bins=50,
palette=colors,
linewidth=.5,
legend=None
)
ax.set_ylabel("Proportion")
ax.set_title("Single-block (Training)", size=14)
ax.set_xticklabels([])
ax.set_xlabel("")
plt.savefig("results/single-block-result-up.pdf", dpi=300, format="pdf", bbox_inches="tight")
# Draw test performance
new_df = get_termination(filter_nan(sbdf), evaluate=True, num_points=60)
sns.set("paper", "darkgrid")
plt.figure(figsize=(4, 2))
new_df["Termination"] = new_df["done way"]
ax = sns.histplot(
new_df,
x="timesteps_total",
hue="Termination",
weights="value",
multiple="fill",
element="poly",
bins=50,
palette=colors,
linewidth=.5,
legend=None
)
ax.set_ylabel("Proportion")
ax.set_title("Single-block Agent (Test)", size=14)
ax.set_xlabel("Training Steps")
plt.savefig("results/single-block-result-down.pdf", dpi=300, format="pdf", bbox_inches="tight")
# ===== Draw the PG agent's results =====
# Get data
pgdf = parse("data/main_ppo", True)
pgdf = pgdf[pgdf["config/env_config/environment_num"] == 100]
# Draw training performance
new_df = get_termination(pgdf, evaluate=False)
new_df["Termination"] = new_df["done way"]
sns.set("paper", "darkgrid")
plt.figure(figsize=(4, 2))
ax = sns.histplot(
new_df,
x="timesteps_total",
hue="Termination", # So that the legend will show Termination
weights="value",
multiple="fill",
element="poly",
bins=50,
palette=colors,
linewidth=.5,
legend=None
)
ax.set_ylabel("") # Hide
ax.set_title("PG Agent (Training)", size=14)
ax.set_xticklabels([])
ax.set_xlabel("")
plt.savefig("results/pg-agent-result-up.pdf", dpi=300, format="pdf", bbox_inches="tight")
# Draw test performance
new_df = get_termination(filter_nan(pgdf), evaluate=True, num_points=60)
sns.set("paper", "darkgrid")
new_df["Termination"] = new_df["done way"]
plt.figure(figsize=(4, 2))
ax = sns.histplot(
new_df,
x="timesteps_total",
hue="Termination",
weights="value",
multiple="fill",
element="poly",
bins=50,
palette=colors,
linewidth=.5,
# legend=None
)
l = ax.legend_
l._loc = 4
ax.set_ylabel("") # Hide
ax.set_title("PG Agent Agent (Test)", size=14)
ax.set_xlabel("Training Steps")
plt.savefig("results/pg-agent-result-down.pdf", dpi=300, format="pdf", bbox_inches="tight")