-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.py
47 lines (36 loc) · 1.13 KB
/
eval.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 numpy as np
import pandas as pd
import torch
import torch.nn as nn
SCALE = 10000
device = torch.device('mps')
model = nn.Sequential(
nn.Linear(2, 12),
nn.ReLU(),
nn.Linear(12, 12),
nn.ReLU(),
nn.Linear(12, 6),
nn.ReLU(),
nn.Linear(6, 1)
)
model.load_state_dict(torch.load("orc/A3/weights.pt", map_location=device, weights_only=True))
model.eval()
if __name__ == "__main__":
df_rand = pd.read_csv('orc/A3/single_pendulum_cost_rand.csv')
X_rand = df_rand[["q0", "dq0"]].values
y_rand = df_rand["cost"].values
# y_rand = y_rand / SCALE
pred_rand = model(torch.tensor(X_rand, dtype=torch.float32)).detach().numpy() * SCALE
np.clip(pred_rand, 0.0, None, out=pred_rand)
# print(pred)
pred_rand = pred_rand.reshape(-1)
errors = np.abs((y_rand - pred_rand)) / np.mean(y_rand)
for i in range(len(y_rand)):
x0 = X_rand[i]
real_y = y_rand[i]
predicted_y = pred_rand[i]
error = errors[i]
print(x0, "\t", real_y, "\t", predicted_y, "\t", error)
print("max error", max(errors))
errors = np.sort(errors, axis=0)
print(errors[-10:])