-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting_reward.py
More file actions
85 lines (67 loc) · 3.19 KB
/
plotting_reward.py
File metadata and controls
85 lines (67 loc) · 3.19 KB
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
import numpy as np
import matplotlib.pyplot as plt
def reduce_noise(list, elements_per_point=10):
newlist = []
for i in range(len(list)):
low = max(0, i-elements_per_point)
high = min(len(list), i+elements_per_point)
# print(low, high, len(list[low:high]))
newlist.append(np.mean(list[low:high+1]))
return newlist
def average(list, elements_per_point=10):
avglist = []
for i in range(int(np.floor(len(list)/min(elements_per_point, len(list))))):
avglist.append(np.mean(list[i*elements_per_point:(i+1)*elements_per_point]))
return avglist
def show_all(stored_filename, noise_elements_per_point, avg_elements_per_point):
add_plot('Rewards', stored_filename, noise_elements_per_point, avg_elements_per_point, 1)
add_plot('Percentage', stored_filename, noise_elements_per_point, avg_elements_per_point, 2, True)
add_plot('Looping_kicks', stored_filename, noise_elements_per_point, avg_elements_per_point, 3)
plt.show()
def add_plot(type, stored_filename, noise_elements_per_point, avg_elements_per_point, index=1, reverse=False):
try:
reward = np.load('Stored_results/{0}_{1}.npy'.format(type, stored_filename))
except FileNotFoundError:
print("No data found about '{0}'".format(type))
return
plt.figure(index)
loop = range(2) if not reverse else range(1, -1, -1)
for i in loop:
graph = average(reduce_noise(reward[i].tolist(), noise_elements_per_point), avg_elements_per_point)
positions = np.linspace(0, len(reward[i].tolist()), len(graph))
if len(graph) == 1:
positions = [0, len(reward[i].tolist())]
graph = [graph[0], graph[0]]
ai_number = (i + 1) if not reverse else (2 - i)
plt.plot(positions, graph, label="AI {0}".format(ai_number))
plt.legend()
# plt.ylim([0, 20])
plt.ylabel(type)
plt.xlabel('Episode')
def add_scatterplot(type, stored_filename, avg_elements_per_point, index=1, reverse=False):
try:
reward = np.load('Stored_results/{0}_{1}.npy'.format(type, stored_filename))
except FileNotFoundError:
print("No data found about '{0}'".format(type))
return
plt.figure(index)
loop = range(2) if not reverse else range(1, -1, -1)
for i in loop:
graph = average(reward[i].tolist(),avg_elements_per_point)
positions = np.linspace(0, len(reward[i].tolist()), len(graph))
if len(graph) == 1:
positions = [0, len(reward[i].tolist())]
graph = [graph[0], graph[0]]
plt.scatter(positions, graph, label="AI {0}".format(i + 1))
plt.legend()
# plt.ylim([0, 20])
plt.ylabel(type)
plt.xlabel('Episode')
'''
The value of noise_elements_per_point will be used to reduce the noisiness of the graph, by setting each element to be
equal to the mean of the previous n elements + this element + the next n elements.
The value of avg_elements_per_point will be used make each point an average of the n closest points, further increasing
readability of the graph. This will reduce the amount of points by a factor of n.
'''
if __name__ == '__main__':
show_all(stored_filename='18kv4', noise_elements_per_point=0, avg_elements_per_point=1)