File size: 5,268 Bytes
edee4ad |
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 |
import numpy as np
import matplotlib
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import colors
def plot_loss(metrics,expName):
plt.figure()
plt.plot(metrics['train'],color='blue',label='train')
plt.plot(metrics['val'],color='red',label='val')
plt.xlabel('iterations')
plt.ylabel('L2 Loss')
#plt.yscale('log')
plt.legend(loc="best")
plt.tight_layout()
plt.savefig('loss_%s.pdf' %expName)
def plot_error(y_pred,y_from_ds,expName):
plt.figure()
plt.hist([y_pred[:,0],y_from_ds[:,0]],label=['estimate','true'],bins=int(np.sqrt(len(y_pred[:,0]))),color=['red','blue'],alpha=0.5)
#plt.hist(y_from_ds[:,0], label='true', bins=int(np.sqrt(len(y_from_ds[:,0]))),color='blue',alpha=0.5)
plt.xlabel('x coord')
plt.ylabel('frequency')
plt.xlim([0.4,0.55])
plt.legend()
plt.tight_layout()
plt.savefig('x_coord_kde_%s.pdf' %expName)
plt.figure()
plt.hist([y_pred[:,1],y_from_ds[:,1]],label=['estimate','true'],bins=int(np.sqrt(len(y_pred[:,1]))),color=['red','blue'],alpha=0.5)
#plt.hist(y_from_ds[:,1], label='true', bins=int(np.sqrt(len(y_from_ds[:,1]))),color='blue',alpha=0.5)
plt.xlabel('y coord')
plt.ylabel('frequency')
plt.xlim([0.4,0.55])
plt.legend()
plt.tight_layout()
plt.savefig('y_coord_kde_%s.pdf' %expName)
plt.figure()
plt.hist(y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),bins=int(np.sqrt(len(y_from_ds[:,0]))),label='error')
plt.xlabel('X Coordinate Absolute Error')
plt.ylabel('frequency')
plt.xlim([-0.005,0.005])
#plt.yscale('log')
plt.tight_layout()
plt.savefig('x_coord_mse_%s.pdf' %expName)
plt.figure()
plt.hist(y_from_ds[:,1].squeeze()-y_pred[:,1].squeeze(),bins=int(np.sqrt(len(y_from_ds[:,1]))),label='error')
plt.xlabel('Y Coordinate Absolute Error')
plt.ylabel('frequency')
plt.xlim([-0.005,0.005])
#plt.yscale('log')
plt.tight_layout()
plt.savefig('y_coord_mse_%s.pdf' %expName)
plt.figure()
plt.hist(np.sqrt(np.power(y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),2)),bins=int(np.sqrt(len(y_from_ds[:,0]))),label='error')
plt.xlabel('X Coordinate RMSE')
plt.ylabel('frequency')
#plt.yscale('log')
plt.tight_layout()
plt.savefig('x_coord_rmse_%s.pdf' %expName)
plt.figure()
plt.hist(np.sqrt(np.power(y_from_ds[:,1].squeeze()-y_pred[:,1].squeeze(),2)),bins=int(np.sqrt(len(y_from_ds[:,1]))),label='error')
plt.xlabel('Y Coordinate RMSE')
plt.ylabel('frequency')
#plt.yscale('log')
plt.tight_layout()
plt.savefig('y_coord_rmse_%s.pdf' %expName)
plt.figure()
plt.scatter(y_from_ds[:,0],np.power(y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),2))
plt.xlabel('X Coordinate')
plt.ylabel('Absolute Error')
#plt.yscale('log')
plt.tight_layout()
plt.savefig('x_coord_positional_mse_%s.pdf' %expName)
plt.figure()
plt.scatter(y_from_ds[:,1],np.power(y_from_ds[:,1].squeeze()-y_pred[:,1].squeeze(),2))
plt.xlabel('Y Coordinate')
plt.ylabel('Absolute Error')
#plt.yscale('log')
plt.tight_layout()
plt.savefig('y_coord_positional_mse_%s.pdf' %expName)
plt.figure()
plt.hist2d(y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),y_from_ds[:,1].squeeze()-y_pred[:,1].squeeze(),bins=int(np.sqrt(len(y_from_ds[:,0]))),norm=colors.LogNorm())
plt.xlabel('X Coordinate Absolute Error')
plt.ylabel('Y Coordinate Absolute Error')
plt.colorbar()
plt.tight_layout()
plt.savefig('error_map_mse_%s.pdf' %expName)
data_range_x = np.arange(0.42,0.52,50)
data_range_y = np.arange(0.42,0.52,50)
x,y = np.meshgrid(data_range_x,data_range_y)
error = np.zeros(shape=(50,50))
i,j=0,0
for x_val in x:
print(np.where(y_from_ds[:,0]==x_val))
'''
for y_val in y:
error[i][j] = y_from_ds[np.where(y_from_ds[:,0]==x_val)[0],0] - y_pred[np.where(y_from_ds[:,0]==x_val)[0],0] + \
y_from_ds[np.where(y_from_ds[:,1]==y_val)[0],1] - y_pred[np.where(y_from_ds[:,1]==y_val)[0],1]
j +=1
i+=1
plt.figure()
plt.contourf(x,y,error)
plt.tight_layout()
plt.savefig('test_%s.pdf' %expName)
'''
data_range_x = np.linspace(min(y_from_ds[:,0]),max(y_from_ds[:,0]),len(y_from_ds[:,0]))
data_range_y = np.linspace(min(y_from_ds[:,1]),max(y_from_ds[:,1]),len(y_from_ds[:,1]))
x,y = np.meshgrid(data_range_x,data_range_y)
error = np.zeros(shape=(len(y_from_ds[:,0]),len(y_from_ds[:,1])))
print(np.shape(error))
print(np.shape(data_range_x))
print(np.shape(data_range_y))
i,j=0,0
for i in range(len(x)):
for j in range(len(y)):
error[i][j] = y_from_ds[i,0] - y_pred[i,0] + \
y_from_ds[j,1] - y_pred[j,1]
plt.figure()
plt.contourf(x,y,error)
plt.tight_layout()
plt.savefig('test_%s.pdf' %expName)
plt.figure()
plt.scatter(y_from_ds[:,0],y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),bins=int(np.sqrt(len(y_from_ds[:,0]))),norm=colors.NoNorm())
plt.xlabel('X Coordinate Absolute Error')
plt.ylabel('Y Coordinate Absolute Error')
plt.colorbar()
plt.tight_layout()
plt.savefig('error_map_mse_no_norm_%s.pdf' %expName)
|