dennistrujillo commited on
Commit
edee4ad
·
1 Parent(s): beef824

added plot.py

Browse files
Files changed (1) hide show
  1. plot.py +140 -0
plot.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import matplotlib
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ from matplotlib import colors
6
+
7
+ def plot_loss(metrics,expName):
8
+ plt.figure()
9
+ plt.plot(metrics['train'],color='blue',label='train')
10
+ plt.plot(metrics['val'],color='red',label='val')
11
+ plt.xlabel('iterations')
12
+ plt.ylabel('L2 Loss')
13
+ #plt.yscale('log')
14
+ plt.legend(loc="best")
15
+ plt.tight_layout()
16
+ plt.savefig('loss_%s.pdf' %expName)
17
+
18
+ def plot_error(y_pred,y_from_ds,expName):
19
+ plt.figure()
20
+ 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)
21
+ #plt.hist(y_from_ds[:,0], label='true', bins=int(np.sqrt(len(y_from_ds[:,0]))),color='blue',alpha=0.5)
22
+ plt.xlabel('x coord')
23
+ plt.ylabel('frequency')
24
+ plt.xlim([0.4,0.55])
25
+ plt.legend()
26
+ plt.tight_layout()
27
+ plt.savefig('x_coord_kde_%s.pdf' %expName)
28
+
29
+ plt.figure()
30
+ 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)
31
+ #plt.hist(y_from_ds[:,1], label='true', bins=int(np.sqrt(len(y_from_ds[:,1]))),color='blue',alpha=0.5)
32
+ plt.xlabel('y coord')
33
+ plt.ylabel('frequency')
34
+ plt.xlim([0.4,0.55])
35
+ plt.legend()
36
+ plt.tight_layout()
37
+ plt.savefig('y_coord_kde_%s.pdf' %expName)
38
+
39
+ plt.figure()
40
+ plt.hist(y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),bins=int(np.sqrt(len(y_from_ds[:,0]))),label='error')
41
+ plt.xlabel('X Coordinate Absolute Error')
42
+ plt.ylabel('frequency')
43
+ plt.xlim([-0.005,0.005])
44
+ #plt.yscale('log')
45
+ plt.tight_layout()
46
+ plt.savefig('x_coord_mse_%s.pdf' %expName)
47
+
48
+ plt.figure()
49
+ plt.hist(y_from_ds[:,1].squeeze()-y_pred[:,1].squeeze(),bins=int(np.sqrt(len(y_from_ds[:,1]))),label='error')
50
+ plt.xlabel('Y Coordinate Absolute Error')
51
+ plt.ylabel('frequency')
52
+ plt.xlim([-0.005,0.005])
53
+ #plt.yscale('log')
54
+ plt.tight_layout()
55
+ plt.savefig('y_coord_mse_%s.pdf' %expName)
56
+
57
+ plt.figure()
58
+ 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')
59
+ plt.xlabel('X Coordinate RMSE')
60
+ plt.ylabel('frequency')
61
+ #plt.yscale('log')
62
+ plt.tight_layout()
63
+ plt.savefig('x_coord_rmse_%s.pdf' %expName)
64
+
65
+ plt.figure()
66
+ 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')
67
+ plt.xlabel('Y Coordinate RMSE')
68
+ plt.ylabel('frequency')
69
+ #plt.yscale('log')
70
+ plt.tight_layout()
71
+ plt.savefig('y_coord_rmse_%s.pdf' %expName)
72
+
73
+ plt.figure()
74
+ plt.scatter(y_from_ds[:,0],np.power(y_from_ds[:,0].squeeze()-y_pred[:,0].squeeze(),2))
75
+ plt.xlabel('X Coordinate')
76
+ plt.ylabel('Absolute Error')
77
+ #plt.yscale('log')
78
+ plt.tight_layout()
79
+ plt.savefig('x_coord_positional_mse_%s.pdf' %expName)
80
+
81
+ plt.figure()
82
+ plt.scatter(y_from_ds[:,1],np.power(y_from_ds[:,1].squeeze()-y_pred[:,1].squeeze(),2))
83
+ plt.xlabel('Y Coordinate')
84
+ plt.ylabel('Absolute Error')
85
+ #plt.yscale('log')
86
+ plt.tight_layout()
87
+ plt.savefig('y_coord_positional_mse_%s.pdf' %expName)
88
+
89
+ plt.figure()
90
+ 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())
91
+ plt.xlabel('X Coordinate Absolute Error')
92
+ plt.ylabel('Y Coordinate Absolute Error')
93
+ plt.colorbar()
94
+ plt.tight_layout()
95
+ plt.savefig('error_map_mse_%s.pdf' %expName)
96
+
97
+ data_range_x = np.arange(0.42,0.52,50)
98
+ data_range_y = np.arange(0.42,0.52,50)
99
+ x,y = np.meshgrid(data_range_x,data_range_y)
100
+ error = np.zeros(shape=(50,50))
101
+ i,j=0,0
102
+ for x_val in x:
103
+ print(np.where(y_from_ds[:,0]==x_val))
104
+ '''
105
+ for y_val in y:
106
+ 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] + \
107
+ 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]
108
+ j +=1
109
+ i+=1
110
+ plt.figure()
111
+ plt.contourf(x,y,error)
112
+ plt.tight_layout()
113
+ plt.savefig('test_%s.pdf' %expName)
114
+ '''
115
+ data_range_x = np.linspace(min(y_from_ds[:,0]),max(y_from_ds[:,0]),len(y_from_ds[:,0]))
116
+ data_range_y = np.linspace(min(y_from_ds[:,1]),max(y_from_ds[:,1]),len(y_from_ds[:,1]))
117
+ x,y = np.meshgrid(data_range_x,data_range_y)
118
+ error = np.zeros(shape=(len(y_from_ds[:,0]),len(y_from_ds[:,1])))
119
+ print(np.shape(error))
120
+ print(np.shape(data_range_x))
121
+ print(np.shape(data_range_y))
122
+ i,j=0,0
123
+ for i in range(len(x)):
124
+ for j in range(len(y)):
125
+ error[i][j] = y_from_ds[i,0] - y_pred[i,0] + \
126
+ y_from_ds[j,1] - y_pred[j,1]
127
+ plt.figure()
128
+ plt.contourf(x,y,error)
129
+ plt.tight_layout()
130
+ plt.savefig('test_%s.pdf' %expName)
131
+
132
+
133
+ plt.figure()
134
+ 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())
135
+ plt.xlabel('X Coordinate Absolute Error')
136
+ plt.ylabel('Y Coordinate Absolute Error')
137
+ plt.colorbar()
138
+ plt.tight_layout()
139
+ plt.savefig('error_map_mse_no_norm_%s.pdf' %expName)
140
+