-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathplot_agent_reward.py
More file actions
30 lines (24 loc) · 821 Bytes
/
Copy pathplot_agent_reward.py
File metadata and controls
30 lines (24 loc) · 821 Bytes
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
import argparse
import os
import pickle
import sys
import numpy as np
import matplotlib.pylab as plt
def plot_agent_reward(rewards):
""" Function to plot agent's accumulated reward vs. iteration """
plt.plot(np.cumsum(rewards))
plt.title('Agent Cumulative Reward vs. Iteration')
plt.ylabel('Reward')
plt.xlabel('Episode')
plt.show()
if __name__ == "__main__":
# Parse command line arguments
parser = argparse.ArgumentParser(description="Plot agent reward.")
parser.add_argument("-p", "--path", type=str, required=True)
args = parser.parse_args()
if not os.path.isfile(args.path):
print("Cannot load agent: file does not exist. Quitting.")
sys.exit(0)
with open(args.path, 'rb') as f:
agent = pickle.load(f)
plot_agent_reward(agent.rewards)