forked from shak-94/Probabilistic-Graph-Networks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JCP_One_Step_Plotter.py
174 lines (150 loc) · 7.96 KB
/
JCP_One_Step_Plotter.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import matplotlib.pyplot as plt
import numpy as np
import math
import statistics
import os, sys
plt.rcParams['axes.labelsize'] = 26
plt.rcParams['axes.titlesize'] = 26
plt.rcParams['xtick.labelsize'] = 26
plt.rcParams['ytick.labelsize'] = 26
plt.rcParams['legend.fontsize'] = 16
plt.rcParams['legend.title_fontsize'] = 16
plt.rcParams['savefig.dpi'] = 300
def MSE_plotter(n, sim, dim, kk, lbk):
mses = []
mrse = []
# fig, axs = plt.subplots(1, 2, figsize=(12, 6))
for i in range(n):
if kk == 0:
# lbk = 3
model_mse = np.load("{}/LTS_{}_more/{}/LTS_{}_{}_non.npy".format(root_dir, lbk, sim, i, dim))
test_sol = np.load("{}/LTS_{}_more/{}/LTS_test_solution_{}_{}_non.npy".format(root_dir, lbk, sim, i, dim))
test_solved = np.load("{}/LTS_{}_more/{}/LTS_test_solved_{}_{}_non.npy".format(root_dir, lbk, sim, i, dim))
errors = []
relative_errors = []
for ii in range(970):
error = np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2, axis=(1))
error = np.sqrt(np.mean(error))
errors.append(error)
aa = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
ba = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]])**2,axis=(1)))
ca = np.sqrt(np.sum((test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
re = np.mean(aa/(ba+ca))
relative_errors.append(re)
errors = np.array(errors)
relative_errors = np.array(relative_errors)
elif kk == 1:
# lbk = 3
test_sol = np.load("{}/Autoregress_Vanilla_{}/{}/Autoregress_Vanilla_test_solution_{}_{}_non_pos_no_ln.npy".format(root_dir, lbk, sim, i, dim))
test_solved = np.load("{}/Autoregress_Vanilla_{}/{}/Autoregress_Vanilla_test_solved_{}_{}_non_pos_no_ln.npy".format(root_dir, lbk, sim, i, dim))
model_mse = np.load("{}/Autoregress_Vanilla_{}/{}/Autoregress_Vanilla_{}_{}_non_pos_no_ln.npy".format(root_dir, lbk, sim, i, dim))
errors = []
relative_errors = []
for ii in range(970):
error = np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2, axis=(1))
error = np.sqrt(np.mean(error))
errors.append(error)
aa = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
ba = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]])**2,axis=(1)))
ca = np.sqrt(np.sum((test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
re = np.mean(aa/(ba+ca))
relative_errors.append(re)
errors = np.array(errors)
relative_errors = np.array(relative_errors)
elif kk == 2:
# lbk = 4
test_sol = np.load("{}/Lagrangian_{}_more/{}/Lagrangian_test_solution_{}_{}_non_ln.npy".format(root_dir, lbk, sim, i, dim))
test_solved = np.load("{}/Lagrangian_{}_more/{}/Lagrangian_test_solved_{}_{}_non_ln.npy".format(root_dir, lbk, sim, i, dim))
model_mse = np.load("{}/Lagrangian_{}_more/{}/Lagrangian_{}_{}_non_ln.npy".format(root_dir, lbk, sim, i, dim))
errors = []
relative_errors = []
for ii in range(970):
error = np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2, axis=(1))
error = np.sqrt(np.mean(error))
errors.append(error)
aa = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
ba = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]])**2,axis=(1)))
ca = np.sqrt(np.sum((test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
re = np.mean(aa/(ba+ca))
relative_errors.append(re)
errors = np.array(errors)
relative_errors = np.array(relative_errors)
elif kk == 3:
# lbk = 5
test_sol = np.load("{}/Hamiltonian_{}_more/{}/Hamiltonian_test_solution_{}_{}_non_standard_layer_norm.npy".format(root_dir, lbk, sim, i, dim))
test_solved = np.load("{}/Hamiltonian_{}_more/{}/Hamiltonian_test_solved_{}_{}_non_standard_layer_norm.npy".format(root_dir, lbk, sim, i, dim))
model_mse = np.load("{}/Hamiltonian_{}_more/{}/Hamiltonian_{}_{}_non_standard_layer_norm.npy".format(root_dir, lbk, sim, i, dim))
errors = []
relative_errors = []
for ii in range(970):
error = np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2, axis=(1))
error = np.sqrt(np.mean(error))
errors.append(error)
aa = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]] - test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
ba = np.sqrt(np.sum((test_sol[ii+1,:,:dimensions[0]])**2,axis=(1)))
ca = np.sqrt(np.sum((test_solved[ii,:,:dimensions[0]])**2,axis=(1)))
re = np.mean(aa/(ba+ca))
relative_errors.append(re)
errors = np.array(errors)
relative_errors = np.array(relative_errors)
mses.append(errors)
mrse.append(relative_errors)
# axs[0].plot(model_mse)
# axs[1].plot(np.mean(mses, axis=0), label="Mean")
means = np.mean(mses, axis=0)
rmeans = np.mean(mrse, axis=0)
print(means[0])
# print(rmeans[-1])
stds = np.std(mses, axis=0, ddof=1)
upper = means + (1.96*stds)/np.sqrt(n-1)
lower = means - (1.96*stds)/np.sqrt(n-1)
x = np.arange(len(means))
return x, means, lower, upper
def combiner(params, cols, time, mnr, dimen, sim):
plt.figure(figsize=(10, 10))
for i in range(len(models)):
if i == 0:
plt.plot(params[i][1][:time], color=cols[i], label="Mean RMSE of GN", linewidth=3)
plt.fill_between(params[i][0][:time], params[i][2][:time], params[i][3][:time], alpha=0.2, color=cols[i])
elif i == 1:
plt.plot(params[i][1][:time], color=cols[i], label="Mean RMSE of GN-NF", linewidth=3)
plt.fill_between(params[i][0][:time], params[i][2][:time], params[i][3][:time], alpha=0.2, color=cols[i])
elif i == 2:
plt.plot(params[i][1][:time], color=cols[i], label="Mean RMSE of GLN", linewidth=3)
plt.fill_between(params[i][0][:time], params[i][2][:time], params[i][3][:time], alpha=0.2, color=cols[i])
elif i == 3:
plt.plot(params[i][1][:time], color=cols[i], label="Mean RMSE of GHN", linewidth=3)
plt.fill_between(params[i][0][:time], params[i][2][:time], params[i][3][:time], alpha=0.2, color=cols[i])
plt.legend(loc="upper left")
plt.xlabel("Timesteps")
plt.ylabel("RMSE")
if math.isnan(mnr[-1]) or math.isinf(mnr[-1]):
up = mnr[-2]
else:
up = mnr[-1]
plt.ylim(0.0, up)
plt.savefig('{}/ONE_step_multi_solver_{}_{}.png'.format(save_dir, sim, dimen))
plt.close()
s_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
root_dir = f'{s_dir}/MSE_JCP'
save_dir = f'{s_dir}/Solvers/Results'
models = ['Graph Network', 'Graph Network NF', 'Lagrangian', 'Hamiltonian']
colors = ['r', 'g', 'b', 'k', 'y', 'm', 'c', 'tab:brown', 'tab:purple']
### Change these parameters to generate required results
simulations = ['charge']
dimensions = [3]
look_back_length = [6]
num_simulations = 30
num_timesteps = 970
for simulation in simulations:
for dimension in dimensions:
plot_params = []
meaner = []
for kk, model in enumerate(models):
x, m, l, u = MSE_plotter(num_simulations, simulation, dimension, kk, look_back_length[0])
plot_params.append([x, m, l, u])
meaner.append(m[-1])
# print(model)
meaner.sort()
# print("##############")
# combiner(plot_params, colors, num_timesteps, meaner, dimension, simulation)