-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_graphs.py
More file actions
37 lines (30 loc) · 1.01 KB
/
Copy pathplot_graphs.py
File metadata and controls
37 lines (30 loc) · 1.01 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
import os
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
root = "saved_models/"
algorithms = ["DQN", "duellingDQN", "doubleDQN", "duelling_doubleDQN"]
file_paths = [root + a + "_stats.log" for a in algorithms]
labels = []
rewards = []
losses = []
for f in file_paths:
if os.path.exists(f):
df = pd.read_csv(f, header=None)
labels.append(df.loc[0][0])
reward = np.asarray(df.iloc[0, 2:].values)
rewards.append(reward)
loss = np.asarray(df.iloc[1, 2:].values)
losses.append(loss)
def plot_graph(y_vals, x_label, y_label, f_name):
for i in range(len(y_vals)):
Y = y_vals[i][::10]
X = list(range(len(Y)))
plt.plot(X, Y, label=labels[i])
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.legend()
plt.savefig(f_name)
plt.show()
plot_graph(rewards, "Number of Episodes", "Reward obtained", "images/reward_comparision.png")
plot_graph(losses, "Number of Episodes", "Training loss", "images/loss_comparision.png")