-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze_false_C.py
350 lines (341 loc) · 26.2 KB
/
analyze_false_C.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
"Ryan van Mastrigt, 29.07.2022"
"This script plots the unit cells falsely classified as C by a trained neural network"
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from matplotlib.backends.backend_pdf import PdfPages
def false_C_StripMode_bestnet(k):
"strip modes"
dat = np.load('.\\testPM_nfnh_{:d}x{:d}.npy'.format(k, k))
nhlist = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 30, 40, 50, 60, 70, 80, 90, 100])
nflist = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20])
PM_index = 3
CMs = []
if k < 4:
CMs.append(np.load('D:\\data\\cnniter_HP_GS_SKF_{:d}x{:d}_AB_5050_2\\testset_nfnhlrkfold_TP_FP_TN_FN.npy'.
format(k, k)))
elif k == 4:
CMs.append(
np.load('D:\\data\\cnniter_HP_GS_SKF_{:d}x{:d}_AB_5050_2\\testset_nfnhlrkfold_TP_FP_TN_FN.npy'.
format(k, k)))
else:
CMs.append(np.load('D:\\data\\cnniter_HP_GS_SKF_{:d}x{:d}_AB_5050\\testset_nfnhlrkfold_TP_FP_TN_FN.npy'.
format(k, k)))
if k == 3:
strings = [u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_3x3_AB_5050_2']
elif k == 4:
strings = [
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_4x4_AB_5050_2\\scratch\\output_dir\\cnniter_HP_GS_SKF_4x4_AB_5050_nh_0to5',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_4x4_AB_5050_2\\scratch\\output_dir\\cnniter_HP_GS_SKF_4x4_AB_5050_nh_5to9',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_4x4_AB_5050_2\\scratch\\output_dir\\cnniter_HP_GS_SKF_4x4_AB_5050_nh_9to13',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_4x4_AB_5050_2\\scratch\\output_dir\\cnniter_HP_GS_SKF_4x4_AB_5050_nh_13to17',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_4x4_AB_5050_2\\scratch\\output_dir\\cnniter_HP_GS_SKF_4x4_AB_5050_nh_17to18']
elif k == 5:
strings = [
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_0to2',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_2to4',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_4to6',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_6to8',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_8to10',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_10to12',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_12to14',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_14to17',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_5x5_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_5x5_AB_5050_nh_17to18'
]
elif k == 6:
strings = [
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_0to1',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_1to2',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_2to3',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_3to4',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_4to5',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_5to6',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_6to7',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_7to8',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_8to9',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_9to10',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_10to11',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_11to12',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_12to13',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_13to14',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_14to15',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_15to16',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_16to17',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_6x6_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_6x6_AB_5050_nh_17to18'
]
elif k == 7:
strings = [
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_0to1',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_1to2',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_2to3',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_3to4',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_4to5',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_5to6',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_6to7',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_7to8',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_8to9',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_9to10',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_10to11',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_11to12',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_12to13',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_13to14',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_14to15',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_15to16',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_16to17',
u'E:\\data\\cnniter_HP_GS_SKF_7x7_AB_5050_extended\\scratch\\output_dir\\cnniter_HP_GS_SKF_extended_7x7_AB_5050_nh_17to18'
]
elif k == 8:
strings = [
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_0to1',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_1to2',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_2to3',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_3to4',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_4to5',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_5to6',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_6to7',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_7to8',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_8to9',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_9to10',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_10to11',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_11to12',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_12to13',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_13to14',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_14to15',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_15to16',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_16to17',
u'C:\\Users\\ryanv\\PycharmProjects\\MetaCombiNN\\cnniter_HP_GS_SKF_8x8_AB_5050\\scratch\\output_dir\\cnniter_HP_GS_SKF_8x8_AB_5050_nh_17to18'
]
for parts in range(len(strings)):
resultstring = strings[parts]
if parts == 0:
KFres = np.loadtxt(resultstring + u'\\kfold_avg_val_results.txt', delimiter='\t')
else:
KFres = np.append(KFres, np.loadtxt(resultstring + u'\\kfold_avg_val_results.txt', delimiter='\t'),
axis=0)
arg = np.nanargmax(np.abs(KFres[:, PM_index]))
nf = KFres[arg, 0].astype(int)
nh = KFres[arg, 1].astype(int)
lr = KFres[arg, 2]
if k == 3:
stringind = 0
string = strings[stringind] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
elif k == 4:
stringind = np.argwhere(nhlist == nh)[0, 0]
string = strings[int(stringind / 4)] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
elif k == 5:
stringind = np.argwhere(nhlist == nh)[0, 0]
if stringind < 14:
string = strings[int(stringind / 2)] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
else:
if stringind < 17:
string = strings[-2] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
else:
string = strings[-1] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
elif k == 6:
stringind = np.argwhere(nhlist == nh)[0, 0]
string = strings[stringind] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
elif k == 7:
stringind = np.argwhere(nhlist == nh)[0, 0]
string = strings[stringind] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
elif k == 8:
stringind = np.argwhere(nhlist == nh)[0, 0]
string = strings[stringind] + u'\\logs\\nf={:d}_nh={:d}_lr={:.4f}\\'.format(nf, nh, lr)
n_kfolds = 10
res_kfolds = np.zeros((n_kfolds, 5))
for kfold in range(10):
res_kfolds[kfold] = np.loadtxt(string + u'kfold={:d}'.format(kfold) + u'\\results.txt', delimiter='\t')
"results.txt: val_loss.result(), val_accuracy.result(), val_prec, val_rec, val_f1"
bestkfold = np.argmax(res_kfolds[:, 1])
"test set results nf nh lr kfold"
testres = np.load('D:\\data\\cnniter_HP_GS_SKF_{:d}x{:d}_AB_5050\\testres_nf{:d}_nh{:d}_lr{:.4f}_kfold{:d}.npy'.
format(k, k, int(nf), int(nh), lr, int(bestkfold))
)
dataprek = np.load('.\\cnniter_HP_GS_SKF_{:d}x{:d}_AB_5050\\data_prek_xy_train_trainraw_test_{:d}x{:d}.npz'.
format(k, k, k, k))
y_pred = np.argmax(testres, axis=1)
indA = np.argwhere(dataprek['y_test'] == 0)
indB = np.argwhere(dataprek['y_test'] == 1)
indAB = np.append(indA, indB)
x_test = dataprek['x_test'][indAB]
y_test = dataprek['y_test'][indAB]
ind_FC = np.argwhere(np.logical_and(y_pred==1, y_test==0))
# nf_arg = np.argwhere(CMs[i][:, 0, 0, 0, 0] == nf)[0, 0]
# nh_arg = np.argwhere(CMs[i][0, :, 0, 0, 1] == nh)[0, 0]
# lr_arg = np.argwhere(CMs[i][0, 0, :, 0, 2] == lr)[0, 0]
# fold_arg = np.argwhere(CMs[i][0, 0, 0, :, 3] == bestkfold)[0, 0]
# "CM = [nf, nh, lr, kfold, TP, FP, TN, FN]"
# CM = np.zeros((2, 2), dtype=int)
# CM[0, 0] = CMs[i][nf_arg, nh_arg, lr_arg, fold_arg, 5]
# CM[1, 0] = CMs[i][nf_arg, nh_arg, lr_arg, fold_arg, 4]
# CM[0, 1] = CMs[i][nf_arg, nh_arg, lr_arg, fold_arg, 6]
# CM[1, 1] = CMs[i][nf_arg, nh_arg, lr_arg, fold_arg, 7]
fig, axes = plt.subplots(6, 5, figsize=(6.75, 6.75/6*5))
with PdfPages(u'.\\StripMode_best_class_False_C_PixRep_{:d}x{:d}_connections.pdf'.format(k, k)) as pdf:
for i, ind in enumerate(ind_FC[:, 0]):
ax_j = i%5
ax_i = int(i/5)
f, ax = plt.subplots()
ax.imshow(x_test[ind, 1:2*k+1, 1:2*k+1, 0], cmap='Greys', vmin=0, vmax=1)
axes[ax_i, ax_j].imshow(x_test[ind, 1:2*k+1, 1:2*k+1, 0], cmap='Greys', vmin=0, vmax=1)
for x in range(1, 2*k, 2):
ax.axvline(x-0.5, color='grey')
axes[ax_i, ax_j].axvline(x - 0.5, color='grey')
for y in range(1, 2*k, 2):
ax.axhline(y-0.5, color='grey')
axes[ax_i, ax_j].axhline(y - 0.5, color='grey')
drawmin = -0.5
drawmax = 2*k - 0.5
for x in range(k):
for y in range(k):
"draw circles and lines for connected pairs"
circle1 = plt.Circle((2*x+0.5, 2*y+0.5), 0.1, color='tab:red', zorder=5)
circle2 = plt.Circle((2 * x + 0.5, 2 * y + 0.5), 0.1, color='tab:red', zorder=5)
# axes[ax_i, ax_j].add_patch(circle1)
ax.add_patch(circle1)
axes[ax_i, ax_j].add_patch(circle2)
if (np.sum(np.multiply(x_test[ind, 2*x:2*(x+1), 1+2*y:1+2*(y+1), 0], np.array([[1, 0], [1, 0]])))
== 2) or (np.sum(np.multiply(x_test[ind, 2*x:2*(x+1), 1+2*y:1+2*(y+1), 0],
np.array([[0, 1], [0, 1]]))) == 2):
"vertical connection"
ystart = 2*y + 0.5
xstart = 2*(x-1) + 0.5
xend = 2*x + 0.5
if xstart < drawmin:
"draw two lines"
ax.vlines(ystart, drawmin, xend, color='tab:orange', zorder=4, lw=2)
ax.vlines(ystart, xstart + 2*k, drawmax, color='tab:orange', zorder=4, lw=2)
axes[ax_i, ax_j].vlines(ystart, drawmin, xend, color='tab:orange', zorder=4, lw=2)
axes[ax_i, ax_j].vlines(ystart, xstart + 2 * k, drawmax, color='tab:orange', zorder=4, lw=2)
else:
# axes[ax_i, ax_j].hlines(y-0.5, x-0.5, x+2-0.5, color='tab:orange', width=0.02)
ax.vlines(ystart, xstart, xend, color='tab:orange', zorder=4, lw=2)
axes[ax_i, ax_j].vlines(ystart, xstart, xend, color='tab:orange', zorder=4, lw=2)
if np.sum(np.multiply(x_test[ind, 1+2*x:1+2*(x+1), 2*y:2*(y+1), 0], np.array([[1, 1], [0, 0]]))) == 2\
or np.sum(np.multiply(x_test[ind, 1+2*x:1+2*(x+1), 2*y:2*(y+1), 0], np.array([[0, 0], [1, 1]]))) == 2:
"horizontal connection"
# axes[ax_i, ax_j].vlines(x - 0.5, y - 0.5, y + 2 - 0.5, color='tab:orange', width=0.02)
xstart = 2*x + 0.5
ystart = 2*(y-1)+0.5
yend = 2*y + 0.5
if ystart < drawmin:
ax.hlines(xstart, drawmin, yend, color='tab:orange', zorder=4, lw=2)
ax.hlines(xstart, ystart + 2*k, drawmax, color='tab:orange', zorder=4, lw=2)
axes[ax_i, ax_j].hlines(xstart, drawmin, yend, color='tab:orange', zorder=4, lw=2)
axes[ax_i, ax_j].hlines(xstart, ystart + 2 * k, drawmax, color='tab:orange', zorder=4, lw=2)
else:
ax.hlines(xstart, ystart, yend, color='tab:orange', zorder=4, lw=2)
axes[ax_i, ax_j].hlines(xstart, ystart, yend, color='tab:orange', zorder=4, lw=2)
# ax.hlines(2*(x) + 0.5, 2*(y-1) + 0.5, 2*y + 0.5, color='tab:orange',zorder=4, lw=2)
if np.sum(np.multiply(x_test[ind, 2*x:2*(x+1), 2*y:2*(y+1), 0], np.array([[1, 0], [0, 1]]))) == 2:
"upper diagonal"
ystart = 2*(x-1)+0.5
yend = 2*x+0.5
xstart = 2*(y-1)+0.5
xend = 2*y+0.5
if xstart < drawmin:
if ystart < drawmin:
line = Line2D([drawmin, xend], [drawmin, yend], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([xstart + 2*k, drawmax], [ystart+2*k, drawmax], color='tab:orange', zorder=4, lw=2)
line3 = Line2D([drawmin, xend], [drawmin, yend], color='tab:orange', zorder=4, lw=2)
line4 = Line2D([xstart + 2 * k, drawmax], [ystart + 2 * k, drawmax], color='tab:orange',
zorder=4, lw=2)
else:
line = Line2D([drawmin, xend], [ystart+1, yend], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([xstart + 2 * k, drawmax], [ystart, yend-1], color='tab:orange',
zorder=4, lw=2)
line3 = Line2D([drawmin, xend], [ystart + 1, yend], color='tab:orange', zorder=4, lw=2)
line4 = Line2D([xstart + 2 * k, drawmax], [ystart, yend - 1], color='tab:orange',
zorder=4, lw=2)
ax.add_line(line)
ax.add_line(line2)
axes[ax_i, ax_j].add_line(line3)
axes[ax_i, ax_j].add_line(line4)
elif ystart < drawmin:
line = Line2D([xstart+1, xend], [drawmin, yend], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([xstart, xend-1], [ystart+2*k, drawmax], color='tab:orange',
zorder=4, lw=2)
line3 = Line2D([xstart + 1, xend], [drawmin, yend], color='tab:orange', zorder=4, lw=2)
line4 = Line2D([xstart, xend - 1], [ystart + 2 * k, drawmax], color='tab:orange',
zorder=4, lw=2)
ax.add_line(line)
ax.add_line(line2)
axes[ax_i, ax_j].add_line(line3)
axes[ax_i, ax_j].add_line(line4)
else:
line = Line2D([xstart, xend], [ystart, yend], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([xstart, xend], [ystart, yend], color='tab:orange', zorder=4, lw=2)
# line = Line2D([2*(x-1)+0.5, 2*x+0.5], [2*(y-1)+0.5, 2*y+0.5], color='tab:orange', zorder=4, lw=2)
ax.add_line(line)
axes[ax_i, ax_j].add_line(line2)
# axes[ax_i, ax_j].add_line(line)
# ax.add_line(line)
if np.sum(np.multiply(x_test[ind, 2 * x:2 * (x + 1), 2 * y:2 * (y + 1), 0],
np.array([[0, 1], [1, 0]]))) == 2:
"lower diagonal"
yend = 2 * (x-1) + 0.5
ystart = 2 * (x) + 0.5
xend = 2 * (y) + 0.5
xstart = 2 * (y-1) + 0.5
if xstart < drawmin:
if yend < drawmin:
line = Line2D([xstart+2*k, drawmax], [ystart, drawmin], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([drawmin, xend], [drawmax, yend+2*k], color='tab:orange',
zorder=4, lw=2)
line3 = Line2D([xstart + 2 * k, drawmax], [ystart, drawmin], color='tab:orange',
zorder=4, lw=2)
line4 = Line2D([drawmin, xend], [drawmax, yend + 2 * k], color='tab:orange',
zorder=4, lw=2)
else:
line = Line2D([xstart+2*k, drawmax], [ystart, ystart-1], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([drawmin, xend], [ystart-1, yend], color='tab:orange',
zorder=4, lw=2)
line3 = Line2D([xstart + 2 * k, drawmax], [ystart, ystart - 1], color='tab:orange',
zorder=4, lw=2)
line4 = Line2D([drawmin, xend], [ystart - 1, yend], color='tab:orange',
zorder=4, lw=2)
ax.add_line(line)
ax.add_line(line2)
axes[ax_i, ax_j].add_line(line3)
axes[ax_i, ax_j].add_line(line4)
elif yend < drawmin:
line = Line2D([xstart, xstart+1], [ystart, drawmin], color='tab:orange', zorder=4, lw=2)
line2 = Line2D([xstart+1, xend], [drawmax, yend+2*k], color='tab:orange',
zorder=4, lw=2)
line3 = Line2D([xstart, xstart + 1], [ystart, drawmin], color='tab:orange', zorder=4, lw=2)
line4 = Line2D([xstart + 1, xend], [drawmax, yend + 2 * k], color='tab:orange',
zorder=4, lw=2)
ax.add_line(line)
ax.add_line(line2)
axes[ax_i, ax_j].add_line(line3)
axes[ax_i, ax_j].add_line(line4)
else:
line = Line2D([xstart, xend], [ystart, yend],
color='tab:orange', zorder=4, lw=2)
line2 = Line2D([xstart, xend], [ystart, yend],
color='tab:orange', zorder=4, lw=2)
ax.add_line(line)
axes[ax_i, ax_j].add_line(line2)
# line = Line2D([2*(x-1) + 0.5, 2*x + 0.5], [2*y + 0.5, 2*(y-1) + 0.5], color='tab:orange', zorder=4, lw=2)
# # axes[ax_i, ax_j].add_line(line)
# ax.add_line(line)
# plt.show()
pdf.savefig(f)
plt.close(f)
axes[ax_i, ax_j].axes.xaxis.set_visible(False)
axes[ax_i, ax_j].axes.yaxis.set_visible(False)
# axes[-1, -1].axes.xaxis.set_visible(False)
# axes[-1, -1].axes.yaxis.set_visible(False)
axes[-1, -1].axis('off')
fig.savefig(u'.\\figures\\Stripmode_best_class_FalseC_PixRep_{:d}x{:d}_gridfig_connections.svg'.format(k, k),
facecolor=fig.get_facecolor())
fig.savefig(u'.\\figures\\Stripmode_best_class_FalseC_PixRep_{:d}x{:d}_gridfig_connections.pdf'.format(k, k),
facecolor=fig.get_facecolor())
fig.savefig(u'.\\figures\\Stripmode_best_class_FalseC_PixRep_{:d}x{:d}_gridfig_connections.png'.format(k, k),
facecolor=fig.get_facecolor(),
dpi=400)
plt.show()
# d = pdf.infodict()
# d['Title'] = 'Class C Pixel Representation and Mode Scaling'
# d['Author'] = 'Ryan van Mastrigt'
return 0
false_C_StripMode_bestnet(5)