-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcartpole_experiments.py
More file actions
68 lines (65 loc) · 1.74 KB
/
cartpole_experiments.py
File metadata and controls
68 lines (65 loc) · 1.74 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
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
from typing import Deque
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("./results/cartpole_1/result.csv")
x1 = df.values[:,1]
y1 = df.values[:,2]
df = pd.read_csv("./results/cartpole_1_e1/result.csv")
x2 = df.values[:,1]
y2 = df.values[:,2]
df = pd.read_csv("./results/cartpole_1_e2/result.csv")
x3 = df.values[:,1]
y3 = df.values[:,2]
df = pd.read_csv("./results/cartpole_1_e3/result.csv")
x4 = df.values[:,1]
y4 = df.values[:,2]
# df = pd.read_csv("cartpole_1_1.csv")
# x1 = df.values[:,1]
# y1 = df.values[:,2]
# avg_y = np.convolve(y, np.ones(10)/10, mode='same') # https://stackoverflow.com/a/22621523
# q = Deque(maxlen=10)
# y_mean = []
# y_max = []
# y_min = []
# for item in y:
# q.append(item)
# mean = np.mean(q)
# y_mean.append(mean)
# std = np.std(q)
# print(std)
# # y_max.append(mean + std)
# # y_min.append(mean - std)
# y_max.append(np.max(q))
# y_min.append(np.min(q))
# avg_y = 0
# deq
# y = np.random.randint(0,100, (100,))
# y_max = y + np.random.randint(0,50, (100,))
# y_min = y - np.random.randint(0,50, (100,))
def smooth(y, q_size=10):
q = Deque(maxlen=q_size)
y_avg = []
for item in y:
q.append(item)
y_avg.append( np.mean(q) )
return y_avg
y1_smooth = smooth(y1)
y2_smooth = smooth(y2)
y3_smooth = smooth(y3)
y4_smooth = smooth(y4)
# plt.plot(x,y)
plt.plot(x1, y1, label="exp1")
plt.plot(x2, y2, label="exp2")
plt.plot(x3, y3_smooth, label="exp3")
plt.plot(x4, y4, label="exp4")
plt.legend()
# plt.fill_between(x,y_min, y_max)
plt.show()
plt.plot(x1, y1_smooth, label="exp1")
plt.plot(x2, y2_smooth, label="exp2")
plt.plot(x3, y3_smooth, label="exp3")
plt.plot(x4, y4, label="exp4")
plt.legend()
# plt.fill_between(x,y_min, y_max)
plt.show()