Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
import math
def std_inverse(std,data):
original_shape = data.shape
try:
data = data.copy()
except Exception:
pass
inversed_data = std.inverse_transform(np.reshape(data,(-1,data.shape[-2]*data.shape[-1])))
inversed_data = inversed_data.reshape(original_shape)
return inversed_data
def compare_result(predict,real):
assert(predict.shape == real.shape)
original_shape = predict.shape
predict_flatten = np.reshape(predict,(-1,original_shape[-2]*original_shape[-1]))
real_flatten = np.reshape(real, (-1,original_shape[-2]*original_shape[-1]))
# assert(np.array_equal(predict_flatten.reshape(original_shape), predict))
print(mean_squared_error(predict_flatten,real_flatten))
return (mean_squared_error(predict_flatten,real_flatten))
def plot_result(predict,real,batch =0,in_out = 0,figure_name = None,time_c = None):
# vmin = min(predict[batch].min(), real[batch].min())
vmin = 0
vmax = max(predict[:,in_out].max(), real[:,in_out].max())
cmap = 'viridis'
fig, axs = plt.subplots(1, 3)
if time_c !=None:
month = round(float(time_c[0,0]*30))
day = round(np.arcsin(time_c[1,0])/(2*np.pi)*30)
hour = np.arcsin(time_c[2,0])
minute = round(float(time_c[3,0])*30)
fig.suptitle("2019-{:02}-{:02}".format(month,day))
axs[0].set_title("predict")
predict_fig = axs[0].imshow(predict[batch,in_out,:,:],cmap = cmap,vmin = vmin,vmax = vmax)
axs[1].set_title("real")
real_fig = axs[1].imshow(real[batch,in_out,:,:],cmap = cmap,vmin = vmin,vmax = vmax)
axs[2].set_title("diff")
diff_matrix = np.abs(predict[batch,in_out,:,:] - real[batch,in_out,:,:])
diff_fig = axs[2].imshow(diff_matrix, cmap = cmap,vmin = vmin,vmax = vmax)
plt.colorbar(predict_fig,ax=axs)
# plt.colorbar(real_fig,ax = axs)
print(diff_matrix.mean(),diff_matrix.shape)
if figure_name!=None:
plt.savefig(f"./figure/{figure_name}.png")
plt.show()