This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_gamma_benchmark.py
201 lines (188 loc) · 10.6 KB
/
evaluate_gamma_benchmark.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2020-2021 Adrian Wöltche
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import seaborn as sns
df = pd.read_csv("benchmark_all.csv")
df = df.dropna()
df = df[df['value_iteration_error_fraction'] < float('inf')]
df = df[df['qlearning_intelligent_error_fraction'] < float('inf')]
df = df[df['qlearning_greedy_error_fraction'] < float('inf')]
df = df[df['qlearning_epsilon_error_fraction'] < float('inf')]
df = df[df['qlearning_epsilon_decay_error_fraction'] < float('inf')]
df = df[df['expected_sarsa_error_fraction'] < float('inf')]
df = df[df['expected_sarsa_decay_error_fraction'] < float('inf')]
df = df[df['greedy_error_fraction'] < float('inf')]
df = df[df['nearest_error_fraction'] < float('inf')]
count = df.count()[0]
# error fraction comparison
fig, ax = plt.subplots()
ax.xaxis.grid()
ax.yaxis.grid()
ax.xaxis.set_major_formatter(mtick.PercentFormatter(count))
# plt.xlim(-10, 1 * count)
plt.ylim(-0.1, 1)
# plt.xscale('log')
# plt.yscale('symlog')
ax.plot(df['value_iteration_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_intelligent_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_greedy_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_epsilon_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_epsilon_decay_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['expected_sarsa_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['expected_sarsa_decay_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['greedy_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['nearest_error_fraction'].sort_values(ascending=False).reset_index(drop=True))
ax.legend(['value_iteration', 'qlearning_intelligent', 'qlearning_greedy', 'qlearning_epsilon', 'qlearning_epsilon_decay', 'expected_sarsa', 'expected_sarsa_decay', 'greedy', 'nearest'], loc='upper right')
plt.ylabel('error fraction')
plt.xlabel('percentile of results')
plt.savefig('stats_error_fraction.png', dpi=300)
plt.show()
plt.close(fig)
# duration comparison
fig, ax = plt.subplots()
ax.xaxis.grid()
ax.yaxis.grid()
ax.xaxis.set_major_formatter(mtick.PercentFormatter(count))
# plt.xlim(-10, 1 * count)
plt.ylim(-0.1, 10)
# plt.xscale('log')
# plt.yscale('symlog')
ax.plot(df['value_iteration_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_intelligent_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_greedy_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_epsilon_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_epsilon_decay_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['expected_sarsa_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['expected_sarsa_decay_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['greedy_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['nearest_duration'].sort_values(ascending=False).reset_index(drop=True))
ax.legend(['value_iteration', 'qlearning_intelligent', 'qlearning_greedy', 'qlearning_epsilon', 'qlearning_epsilon_decay', 'expected_sarsa', 'expected_sarsa_decay', 'greedy', 'nearest'], loc='upper right')
plt.ylabel('duration in seconds')
plt.xlabel('percentile of results')
plt.savefig('stats_duration.png', dpi=300)
plt.show()
plt.close(fig)
# states comparison
fig, ax = plt.subplots()
ax.xaxis.grid()
ax.yaxis.grid()
ax.xaxis.set_major_formatter(mtick.PercentFormatter(count))
# plt.xlim(-10, 1 * count)
plt.ylim(-0.01, 1.01)
# plt.xscale('log')
# plt.yscale('symlog')
ax.plot(df['value_iteration_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_intelligent_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_greedy_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_epsilon_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['qlearning_epsilon_decay_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['expected_sarsa_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['expected_sarsa_decay_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['greedy_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.plot(df['nearest_states_percentage'].sort_values(ascending=False).reset_index(drop=True))
ax.legend(['value_iteration', 'qlearning_intelligent', 'qlearning_greedy', 'qlearning_epsilon', 'qlearning_epsilon_decay', 'expected_sarsa', 'expected_sarsa_decay', 'greedy', 'nearest'], loc='upper right')
plt.ylabel('states percentage')
plt.xlabel('percentile of results')
plt.savefig('stats_states_percentage.png', dpi=300)
plt.show()
plt.close(fig)
# states and error regression comparison
fig, ax = plt.subplots()
ax.xaxis.grid()
ax.yaxis.grid()
plt.xlim(-0.05, 1.05)
plt.ylim(-0.5, 10.5)
ax.scatter(df['qlearning_intelligent_states_percentage'], df['qlearning_intelligent_error_fraction'], zorder=5)
ax.scatter(df['qlearning_greedy_states_percentage'], df['qlearning_greedy_error_fraction'], zorder=5)
ax.scatter(df['qlearning_epsilon_states_percentage'], df['qlearning_epsilon_error_fraction'], zorder=4)
ax.scatter(df['qlearning_epsilon_decay_states_percentage'], df['qlearning_epsilon_decay_error_fraction'], zorder=3)
ax.scatter(df['expected_sarsa_states_percentage'], df['expected_sarsa_error_fraction'], zorder=4)
ax.scatter(df['expected_sarsa_decay_states_percentage'], df['expected_sarsa_decay_error_fraction'], zorder=3)
ax.scatter(df['greedy_states_percentage'], df['greedy_error_fraction'], zorder=2)
ax.scatter(df['nearest_states_percentage'], df['nearest_error_fraction'], zorder=1)
ax.legend(['qlearning_intelligent', 'qlearning_greedy', 'qlearning_epsilon', 'qlearning_epsilon_decay', 'expected_sarsa', 'expected_sarsa_decay', 'greedy', 'nearest'], loc='upper right')
plt.ylabel('error fraction')
plt.xlabel('states percentage')
plt.savefig('stats_states_error_regression.png', dpi=300)
plt.show()
plt.close(fig)
# comparison of error derivation
fig, ax = plt.subplots()
ax.xaxis.grid()
ax.yaxis.grid()
# plt.xlim(-0.05, 1.05)
# plt.ylim(-0.5, 3)
ax.boxplot([df['qlearning_intelligent_error_fraction'],
df['qlearning_greedy_error_fraction'],
df['qlearning_epsilon_error_fraction'],
df['qlearning_epsilon_decay_error_fraction'],
df['expected_sarsa_error_fraction'],
df['expected_sarsa_decay_error_fraction'],
df['greedy_error_fraction'],
df['nearest_error_fraction']], showfliers=False)
ax.legend(['1 = qlearning_intelligent', '2 = qlearning_greedy', '3 = qlearning_epsilon', '4 = qlearning_epsilon_decay', '5 = expected_sarsa', '6 = expected_sarsa_decay', '7 = greedy', '8 = nearest'], loc='upper left', handletextpad=0, handlelength=0)
plt.ylabel('error fraction')
plt.xlabel('dataset')
plt.savefig('stats_states_derivation.png', dpi=300)
plt.show()
plt.close(fig)
# comparison of error derivation only for qlearning
fig, ax = plt.subplots()
ax.xaxis.grid()
ax.yaxis.grid()
# plt.xlim(-0.05, 1.05)
# plt.ylim(-0.5, 3)
ax.boxplot([df['qlearning_intelligent_error_fraction'],
df['qlearning_greedy_error_fraction'],
df['qlearning_epsilon_error_fraction'],
df['qlearning_epsilon_decay_error_fraction'],
df['expected_sarsa_error_fraction']], showfliers=False)
ax.legend(['1 = qlearning_intelligent', '2 = qlearning_greedy', '3 = qlearning_epsilon', '4 = qlearning_epsilon_decay', '5 = expected_sarsa'], loc='upper left', handletextpad=0, handlelength=0)
plt.ylabel('error fraction')
plt.xlabel('dataset')
plt.savefig('stats_states_derivation_qlearning.png', dpi=300)
plt.show()
plt.close(fig)
# regression plots
fig, ax = plt.subplots()
sns.regplot(df['qlearning_intelligent_states_percentage'],
df['qlearning_intelligent_error_fraction'], order=2, ci=100, x_bins=10, x_estimator=np.mean, ax=ax)
sns.regplot(df['qlearning_greedy_states_percentage'],
df['qlearning_greedy_error_fraction'], order=2, ci=100, x_bins=10, x_estimator=np.mean, ax=ax)
sns.regplot(df['qlearning_epsilon_states_percentage'],
df['qlearning_epsilon_error_fraction'], order=2, ci=100, x_bins=10, x_estimator=np.mean, ax=ax)
sns.regplot(df['qlearning_epsilon_decay_states_percentage'],
df['qlearning_epsilon_decay_error_fraction'], order=2, ci=100, x_bins=10, x_estimator=np.mean, ax=ax)
sns.regplot(df['expected_sarsa_states_percentage'],
df['expected_sarsa_error_fraction'], order=2, ci=100, x_bins=10, x_estimator=np.mean, ax=ax)
plt.savefig('stats_regression_qlearning.png', dpi=300)
plt.show()
plt.close(fig)
print("Error Max:")
print(df.filter(regex='.*_error_fraction', axis=1).max())
print("")
print("Q-Learning Intelligent Difference:", 1 - (df[df['qlearning_intelligent_error_fraction'] <= 0.0].count()[0] / count))
print("Q-Learning Greedy Difference:", 1 - (df[df['qlearning_greedy_error_fraction'] <= 0.0].count()[0] / count))
print("Q-Learning Epsilon Difference:", 1 - (df[df['qlearning_epsilon_error_fraction'] <= 0.0].count()[0] / count))
print("Q-Learning Decay Difference:", 1 - (df[df['qlearning_epsilon_decay_error_fraction'] <= 0.0].count()[0] / count))
print("Expected SARSA Difference:", 1 - (df[df['expected_sarsa_error_fraction'] <= 0.0].count()[0] / count))
print("Expected SARSA Decay Difference:", 1 - (df[df['expected_sarsa_decay_error_fraction'] <= 0.0].count()[0] / count))
print("Greedy Difference:", 1 - (df[df['greedy_error_fraction'] <= 0.0].count()[0] / count))
print("Nearest Difference:", 1 - (df[df['nearest_error_fraction'] <= 0.0].count()[0] / count))