-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_test.py
46 lines (37 loc) · 3.03 KB
/
random_test.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
import gym
import matplotlib.pyplot as plt
import numpy as np
def main():
env = gym.make('CarRacing-v0')
env.reset()
done = False
score = 0
counter = 0
n_episodes = 100
ep = 0
ep_hist = []
while ep < n_episodes:
env.render()
s, r, done, info = env.step(env.action_space.sample()) # take a random action
score += r
if done:
print(score)
ep_hist.append(score)
env.reset()
done = False
ep += 1
score = 0
print('********** Evaluation Results **********')
print(ep_hist)
def plot_random_agent():
scores =[-36.908517350158256, -33.55481727574802, -36.7088607594943, -28.315412186380286, -31.74061433447147, -25.37313432835851, -33.99339933993451, -28.327645051194978, -29.57746478873288, -31.972789115646716, -31.596091205212133, -35.275080906149334, -36.507936507937096, -38.70967741935545, -35.81081081081139, -29.824561403509133, -26.070038910505964, -19.84732824427484, -36.50793650793711, -31.97278911564674, -20.318725099601618, -34.853420195440286, -21.875000000000163, -31.407942238267616, -39.68253968254025, -32.43243243243286, -40.11976047904261, -41.17647058823596, -25.490196078431588, -32.862190812721344, -45.558739255015, -34.21052631578994, -31.740614334471438, -28.3154121863803, -23.95437262357446, -35.593220338983635, -36.30573248407699, -37.30407523511029, -25.373134328358475, -37.50000000000057, -33.9933993399345, -33.11036789297705, -21.875000000000142, -41.71779141104361, -34.85342019544024, -32.885906040268914, -38.31168831168885, -30.795847750865477, -37.50000000000064, -33.110367892977045, -34.02777777777824, -36.026936026936504, -28.838951310861773, -31.972789115646755, -39.68253968254032, -29.32862190812757, -30.402930402930778, -36.24161073825557, -30.55555555555602, -29.368029739777285, -28.82562277580103, -36.305732484076984, -37.88819875776456, -32.88590604026894, -37.10691823899428, -35.897435897436466, -34.93150684931554, -25.92592592592623, -21.933085501858866, -29.577464788732836, -33.11036789297712, -31.740614334471484, -27.00729927007331, -37.30407523511024, -36.84210526315841, -25.65055762081803, -34.02777777777826, -31.27147766323061, -36.30573248407695, -27.797833935018303, -26.739926739927064, -33.55481727574795, -27.335640138408685, -32.20338983050901, -39.39393939394003, -36.24161073825551, -20.634920634920775, -29.629629629630013, -29.078014184397553, -25.266903914591026, -34.70790378006925, -27.272727272727508, -33.11036789297707, -32.43243243243286, -41.34897360703871, -33.11036789297705, -31.899641577061345, -39.10256410256468, -28.315412186380343, -35.064935064935604]
fig, ax = plt.subplots(1,1, figsize=(10,5))
ax.scatter([*range(len(scores))],scores, label=f'Episode Score')
ax.plot(np.ones_like(scores)*np.mean(scores), '--', color='red',label=f'Mean Score: {np.mean(scores):.2f}')
ax.set_xlabel('Episodes')
ax.set_ylabel('Score')
ax.set_title('Random Agent')
ax.legend()
plt.show()
if __name__ == '__main__':
plot_random_agent()