-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_3d.py
More file actions
75 lines (65 loc) · 2.12 KB
/
Copy pathplot_3d.py
File metadata and controls
75 lines (65 loc) · 2.12 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
69
70
71
72
73
74
75
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
from matplotlib import cm
import config
import utils
import pandas as pd
from scipy.interpolate import griddata
def plot_3d(
csv_path,
save_path,
):
# Read data from CSV
df = pd.read_csv(csv_path)
offset_1 = df['offset_1']
offset_2 = df['offset_2']
episode_reward_mean = df['episode_reward_mean'].astype('int')
# Interpolate grid
x1 = np.linspace(offset_1.min(), offset_1.max(), len(offset_1))
y1 = np.linspace(offset_2.min(), offset_2.max(), len(offset_2))
X, Y = np.meshgrid(x1, y1)
Z = griddata((offset_1, offset_2), episode_reward_mean, (X, Y), method='cubic')
# Plot
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
surf = ax.plot_surface(X, Y, Z,
rstride=1,
cstride=1,
cmap=cm.coolwarm,
linewidth=0,
antialiased=False,
)
fig.colorbar(surf, shrink=0.5, aspect=5)
# Save plot
fig.savefig(
save_path,
dpi=1000,
bbox_inches='tight',
)
if __name__ == '__main__':
utils.mkdir(config.plot_path)
scheduler_names = [
# "eval_reward_surface_min_convex",
# "eval_reward_surface_max_convex",
# "eval_reward_surface_5",
# "eval_reward_surface_10",
# "eval_reward_surface_15",
# "eval_boost_min_convex",
# "eval_boost_max_convex",
# "eval_boost_5",
# "eval_boost_10",
# "eval_boost_15",
"eval_server_startup",
]
save_types = ["pdf", "png"]
for algo_name in config.algos:
for env_name in config.envs.keys():
for scheduler_name in scheduler_names:
for save_type in save_types:
csv_path = "{}/{}~{}~{}~surface.csv".format(config.log_path, scheduler_name, env_name, algo_name)
save_path = "{}/{}~{}~{}~surface.{}".format(config.plot_path, scheduler_name, env_name, algo_name, save_type)
plot_3d(
csv_path=csv_path,
save_path=save_path,
)