forked from openai/random-network-distillation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_graphs.py
131 lines (102 loc) · 4.2 KB
/
plot_graphs.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
import os
import sys
import argparse
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser()
parser.add_argument("--base_path", type=str,
help="The common directory path to all runs")
parser.add_argument("--rnd_paths", type=str, nargs="+", default=[],
help="Paths to the RND directory where the progress.csv file exists")
parser.add_argument("--aarnd_paths", type=str, nargs="+", default=[],
help="Paths to the AA RND directory where the progress.csv file exists")
parser.add_argument("--egornd_paths", type=str, nargs="+", default=[],
help="Paths to the Ego RND directory where the progress.csv file exists")
args = parser.parse_args()
def read_from_csv(paths):
result = []
for path in paths:
expanded_path = os.path.join(args.base_path, path, "progress.csv")
if not os.path.exists(expanded_path):
raise Exception("Path: {} does not exist".format(expanded_path))
result.append(pd.read_csv(expanded_path))
return result
def clean_data(data):
for idx in range(len(data)):
if len(data[idx].columns) == 45:
data[idx] = data[idx].drop(columns=['Unnamed: 0'])
for idx in range(len(data)):
twomillion = 200000000
while True:
res = data[idx]['tcount'][data[idx]['tcount'] == twomillion]
if not res.empty:
data[idx] = data[idx][:res.index[0]]
break
else:
twomillion += 1
return data
def equalize_rows(data):
for dta in data:
min_len = len(dta[0])
for idx in range(len(dta)):
if len(dta[idx]) < min_len:
min_len = len(dta[idx])
for idx in range(len(dta)):
dta[idx] = dta[idx][:min_len]
return data
def calculate_mu_sigma(data, column):
all_data = []
for dta in data:
dta_val = dta[column].values
dta_val[np.isnan(dta_val)] = 0
dta_val[np.isinf(dta_val)] = 0
all_data.append(dta_val)
total = np.stack(all_data)
mu = total.mean(axis=0)
sigma = total.std(axis=0)
ci = sigma
tcount = data[0]['tcount'].values
return mu, ci, tcount
def plot_fill(data, column, ax, ylabel):
rnd_data = data[0]
aarnd_data = data[1]
egornd_data = data[2]
mu, ci, tcount = calculate_mu_sigma(rnd_data, column)
ax.plot(tcount, mu, lw=1, color='red', label='RND')
ax.fill_between(tcount, (mu-ci), (mu+ci), facecolor='red', alpha=0.25)
mu, ci, tcount = calculate_mu_sigma(aarnd_data, column)
ax.plot(tcount, mu, lw=1, color='green', label='AA RND')
ax.fill_between(tcount, (mu-ci), (mu+ci), facecolor='green', alpha=0.25)
mu, ci, tcount = calculate_mu_sigma(egornd_data, column)
ax.plot(tcount, mu, lw=1, color='blue', label='Ego RND')
ax.fill_between(tcount, (mu-ci), (mu+ci), facecolor='blue', alpha=0.25)
ax.set_xlabel('Frames')
ax.set_ylabel(ylabel)
ax.legend()
if not args.base_path or not args.rnd_paths or not args.aarnd_paths or not args.egornd_paths:
print("Command line arguments were not set properly")
sys.exit(1)
assert len(args.rnd_paths) == len(args.aarnd_paths) == len(args.egornd_paths), \
"Number of path not equal for all methods"
data_rnd = np.array(read_from_csv(args.rnd_paths))
data_aarnd = np.array(read_from_csv(args.aarnd_paths))
data_egornd = np.array(read_from_csv(args.egornd_paths))
data = np.concatenate((data_rnd, data_aarnd, data_egornd))
data = clean_data(data)
# fig, axes = plt.subplots(figsize=(19.20, 10.80), nrows=2, ncols=2)
fig, axes = plt.subplots(nrows=2, ncols=2)
# fig.suptitle("Montezuma's Revenge Ego vs AA-RND", fontsize=10,y=0.9,x=0.51)
"""
retextmean, retextstd, retintmean, retintstd, rewintmean_norm, rewintmean_unnorm,
vpredextmean, vpredintmean are interesting metrics
"""
data = data.reshape(3, -1)
data = equalize_rows(data)
plot_fill(data, 'rewtotal', axes[0, 0], 'Total Rewards')
plot_fill(data, 'n_rooms', axes[0, 1], 'No Rooms')
plot_fill(data, 'eprew', axes[1, 0], 'Episodic Rewards')
plot_fill(data, 'best_ret', axes[1, 1], 'Best Rewards')
plot_name = 'montezuma-all-three'
plt.tight_layout()
plt.savefig(f'{plot_name}.png')