File size: 1,725 Bytes
ebb75df 449b9e9 ebb75df 449b9e9 e64054f ebb75df 449b9e9 ebb75df 449b9e9 ebb75df e64054f ebb75df e64054f ebb75df e64054f 449b9e9 |
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 |
from numpy import load
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.axes
filepath = "agents/dqn_v2-7/evaluations.npz"
data = load(filepath)
lst = data.files # data.files lists the keys that are available for data
# print('ep_lengths: \n', data['ep_lengths'])
# results and ep_lengths are 2d arrays, because each evaluation is 5 episodes long.
# I want to plot the average of each evaluation.
print(data["results"])
print()
print(np.delete(np.sort(data["results"]), 0, 1))
# for i in range(len(data["results"])):
# print(np.average(data["results"][i]))
'''
# for each item in results, loop through the array and save the average
avg_ep_result_arr = []
for eval in data['results']:
result_sum = 0
for result in eval:
result_sum = result_sum + result
avg_ep_result = result_sum / len(eval)
avg_ep_result_arr.append(avg_ep_result)
avg_ep_len_arr = []
for eval in data['ep_lengths']:
max_len = 0
y_limit = 0
ep_len_sum = 0
for ep_length in eval:
ep_len_sum = ep_len_sum + ep_length
if ep_length > max_len:
max_len = ep_length
if ep_length > y_limit and y_limit < max_len:
y_limit = ep_length
avg_ep_len = ep_len_sum / len(eval)
avg_ep_len_arr.append(avg_ep_len)
y_limit = y_limit * 1.9
x = plt.plot(data['timesteps'], avg_ep_result_arr)
# plt.bar(data['timesteps'], avg_ep_len_arr, width=10000)
y = plt.plot(data['timesteps'], avg_ep_len_arr)
plt.ylim(top=y_limit)
# plt.ylabel("Avg ep score")
# lineObjects = plt.plot(x, y)
plt.legend(["avg ep result", "avg ep length"])
plt.title("result and length over steps\nfilepath: " + filepath)
plt.show()
''' |