-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.py
65 lines (51 loc) · 2.19 KB
/
draw.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
import numpy as np
import matplotlib.pyplot as plt
import os
import json
import argparse
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "3"
plt.rcParams['axes.unicode_minus'] = False
parser = argparse.ArgumentParser(description="test drawer")
parser.add_argument('--resultpath', type=str, required=True,
help='path to the npz file directory')
parser.add_argument('--output_folder', type=str, required=True,
help='path to the logs file directory')
parser.add_argument('--num-batches', type=int, required=True, default=10,
help= 'the number of batches during the test')
parser.add_argument('--num-traj', type=int, required=True, default=20,
help='the number of trajectories per batch')
args = parser.parse_args()
Results = np.load(os.path.dirname(os.path.realpath(__file__)) + '/' + args.resultpath + '/results.npz', allow_pickle = True)
returns = Results['train_returns']
if args.output_folder is not None:
if not os.path.exists(args.output_folder):
os.makedirs(args.output_folder)
log_filename = os.path.join(args.output_folder, 'logs.txt')
logs={}
logs["Name"] = args.resultpath
valid_returns = Results['valid_returns']
# print(returns)
mean_return = np.mean(returns, axis=1)
mean_valid_return = np.mean(valid_returns, axis=1)
results, valid_results = [], []
for i in range(args.num_batches):
valid_results.append(np.mean(mean_valid_return[i*args.num_traj:(i+1)*args.num_traj]))
results.append(np.mean(mean_return[i*args.num_traj:(i+1)*args.num_traj]))
valid_results, results = np.array(valid_results), np.array(results)
print("Valid mean", np.mean(valid_results), "Valid var", np.var(valid_results))
logs["Valid mean"] = np.mean(valid_results).tolist()
logs["Valid var"] = np.var(valid_results).tolist()
# plt.plot((valid_results), 'g^')
# plt.title('valid results')
# plt.show()
print("Mean", np.mean(results), "Var", np.var(results))
logs["Mean"] = np.mean(results).tolist()
logs["Var"] = np.var(results).tolist()
if args.output_folder is not None:
with open(log_filename, 'a') as f:
json.dump(logs, f, indent=2)
f.close()
# plt.plot((results), 'r^')
# plt.title('fast adaptation train results')
# plt.show()