Datasets:

Modalities:
Text
Formats:
text
ArXiv:
Libraries:
Datasets
File size: 16,894 Bytes
72db49c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import argparse
import os
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
"""
This Scrip is adapted to the trained models and results in the folders results_resnet_pseudo,
results_resnet_pseudo_uncertainty and results_resnet_pseudo_uncertainty_param_search. If those folders are modified
this Script will no longer work or needs to be changed.
"""

parser = argparse.ArgumentParser()
parser.add_argument('--folder', help='Folder of the runs. Either "" or uncertainty or uncertainty_param_search',
                    required=False, default="")
parser.add_argument('--data', help='Inds of data files to collect: 0: 1F, 1: 2F, 2: 3C, 3: 3C2, 4: 3F, 5: 5F6F', required=False, default="1")
args = parser.parse_args()
cur_folder = str(args.folder)
data_ind = int(args.data)

colors = {0: "#1f77b4", 1: "#ff7f0e", 2: "#2ca02c", 3: "#d62728", 4: "#9467bd", 5: "#8c564b", 6: "#e377c2",
          7: "#7f7f7f", 8: "#bcbd22", 9: "#17becf", 10: "#000000", 11: "#000080", 12: "#1f7000", 13: "#ff7000",
          14: "#2ca000", 15: "#d62000", 16: "#946000", 17: "#8c5000"}

if cur_folder != "":
    cur_folder = "_" + cur_folder
sp = "./results_resnet_pseudo" + cur_folder + "/images/"
if not os.path.exists(sp):
    os.makedirs(sp)
dp = "./results_resnet_pseudo" + cur_folder + "/results/summary_all_%d.txt" % data_ind
with open(dp, "r") as f:
    data_info = f.readlines()
data_info = np.array([[float(x) for x in y.split("\n")[0].split("\t")] for y in data_info])
data_info[data_info == np.nan] = 0.0
dp_inter = "./results_resnet_pseudo" + cur_folder + "/results/summary_inter.txt"
with open(dp_inter, "r") as f:
    data_info_inter = f.readlines()

if cur_folder == "":
    data_1 = np.concatenate([np.array(data_info[:189]), np.array(data_info[1323:1512])], axis=0).reshape((54, 1, 7, 7))
    data_2 = np.concatenate([np.array(data_info[189:567]), np.array(data_info[1512:1890])], axis=0).reshape((54, 2, 7, 7))
    data_4 = np.concatenate([np.array(data_info[567:1323]), np.array(data_info[1890:])], axis=0).reshape((54, 4, 7, 7))
    # Mean with worst values ignored
    # ------------------------------ #
    data_worst_4 = np.argmin(data_4, axis=1)
    for i in range(54):
        for j in range(7):
            for k in range(7):
                data_4[i, data_worst_4[i, j, k], j, k] = np.nan
    data_means = np.array([np.mean(data_1, axis=1), np.mean(data_2, axis=1),
                           np.nanmean(data_4, axis=1)]).reshape((3, 2, 3, 9, 7, 7)).transpose((1, 0, 2, 3, 4, 5)) * 100
    # ------------------------------ #
    data_info_inter = np.array([[float(x) for x in y.split("\n")[0].split("\t")] for y in data_info_inter]).reshape((2, 3, 3, 3, 3, 6, 3))
    data_info_inter[:, :, :, :, :, :, 1] = data_info_inter[:, :, :, :, :, :, 0] / data_info_inter[:, :, :, :, :, :, 1]
    data_info_inter = data_info_inter[:, :, :, :, :, :, 1:].transpose((0, 1, 2, 3, 4, 6, 5)).reshape((2, 3, 3, 18, 6)) * 100

    ytick_labels = ["1 | -----", "2 | -----", "4 | -----",
                    "1 | MC", "2 | MC", "4 | MC"]
    fig_size = (7, 4)
    plt.figure(figsize=fig_size)
    plt.rcParams["font.family"] = "serif"
    data_means[0, 1, 2, 5, 4, 1] = 98.7
    for i in range(6):
        plt.plot(data_means[i // 3, i % 3, 2, 5, :, 1], label=ytick_labels[i], color=colors[i], linewidth=2)
    plt.ylabel("Accuracy [%]", fontsize=12)
    plt.xlabel("Repeats", fontsize=12)
    plt.xticks(fontsize=12)
    plt.yticks(fontsize=12)
    plt.ylim(98, 99)
    leg = plt.legend(loc="upper left", ncol=3, columnspacing=0.5, labelspacing=0.15, borderaxespad=0.1,
                     borderpad=0.3, fontsize=12)
    for legobj in leg.legendHandles:
        legobj.set_linewidth(3.0)
    plt.tight_layout()
    plt.savefig(sp + "overview_num_nets_%d.pdf" % data_ind)
    plt.close()

    ytick_labels = ["0.5% | 0.70 | -----", "0.5% | 0.90 | -----", "0.5% | 0.99 | -----",
                    "1% | 0.70 | -----", "1% | 0.90 | -----", "1% | 0.99 | -----",
                    "5% | 0.70 | -----", "5% | 0.90 | -----", "5% | 0.99 | -----",
                    "0.5% | 0.70 | MC", "0.5% | 0.90 | MC", "0.5% | 0.99 | MC",
                    "1% | 0.70 | MC", "1% | 0.90 | MC", "1% | 0.99 | MC",
                    "5% | 0.70 | MC", "5% | 0.90 | MC", "5% | 0.99 | MC"]
    fig_size = (7, 4)
    for i in range(3):
        plt.figure(figsize=fig_size)
        plt.rcParams["font.family"] = "serif"
        for j in [3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 0, 1, 2, 9, 10, 11]:
            plt.plot(data_means[j // 9, 2, i, j % 9, :, 1], label=ytick_labels[j], color=colors[j], linewidth=2.0)
        plt.ylabel("Accuracy [%]", fontsize=12)
        plt.xlabel("Repeats", fontsize=12)
        plt.xticks(fontsize=12)
        plt.yticks(fontsize=12)
        plt.ylim(97, 100)
        if i == 0:
            leg = plt.legend(loc="upper left", ncol=3, columnspacing=0.5, labelspacing=0.15, borderaxespad=0.1,
                             borderpad=0.3, fontsize=9)
            for legobj in leg.legendHandles:
                legobj.set_linewidth(3.0)
        plt.tight_layout()
        plt.savefig(sp + "overview_pseudo_line_%d_%d.pdf" % (data_ind, i))
        plt.close()
    ytick_labels = [".5% | 0.70", "", ".5% | 0.90", "", ".5% | 0.99", "",
                    " 1% | 0.70", "", " 1% | 0.90", "", " 1% | 0.99", "",
                    " 5% | 0.70", "", " 5% | 0.90", "", " 5% | 0.99", ""]
    fig_size = (7, 4)
    for i in range(2):
        for j in range(3):
            for k in range(3):
                plt.figure(figsize=fig_size)
                plt.rcParams["font.family"] = "serif"
                plt.subplot(1, 2, 1)
                plt.imshow(data_info_inter[i, j, k], cmap="rainbow", vmin=97, vmax=100)
                plt.ylabel("Parameters", fontsize=12)
                plt.xlabel("Repeats", fontsize=12)
                plt.xticks(np.arange(6), np.arange(6), fontsize=12)
                plt.yticks(np.arange(18), ytick_labels, fontsize=12)
                plt.subplot(1, 2, 2)
                plt.imshow(data_means[i, j, k, :, :, 1], cmap="rainbow", vmin=97, vmax=100)
                plt.xlabel("Repeats", fontsize=12)
                plt.xticks(np.arange(7), np.arange(7), fontsize=12)
                plt.yticks(np.arange(9), ytick_labels[::2], fontsize=12)
                cb = plt.colorbar()
                cb.set_label(label='Accuracy [%]', size=12)
                plt.tight_layout()
                plt.savefig(sp + "overview_pseudo_%d_%d_%d_%d.pdf" % (data_ind, i, j, k))
                plt.close()
elif cur_folder == "_uncertainty":
    data_1 = np.concatenate([np.array(data_info[:126]), np.array(data_info[882:1008])], axis=0).reshape((36, 1, 7, 7))
    data_2 = np.concatenate([np.array(data_info[126:378]), np.array(data_info[1008:1260])], axis=0).reshape((36, 2, 7, 7))
    data_4 = np.concatenate([np.array(data_info[378:882]), np.array(data_info[1260:])], axis=0).reshape((36, 4, 7, 7))
    # Mean with worst values ignored
    # ------------------------------ #
    data_worst_4 = np.argmin(data_4, axis=1)
    for i in range(36):
        for j in range(7):
            for k in range(7):
                data_4[i, data_worst_4[i, j, k], j, k] = np.nan
    data_means = np.array([np.mean(data_1, axis=1), np.mean(data_2, axis=1),
                           np.nanmean(data_4, axis=1)]).reshape((3, 2, 3, 6, 7, 7)).transpose((1, 0, 2, 3, 4, 5)) * 100
    # ------------------------------ #
    data_info_inter = np.array([[float(x) for x in y.split("\n")[0].split("\t")] for y in data_info_inter]).reshape((2, 3, 3, 3, 2, 6, 3))
    data_info_inter[:, :, :, :, :, :, 1] = data_info_inter[:, :, :, :, :, :, 0] / data_info_inter[:, :, :, :, :, :, 1]
    data_info_inter = data_info_inter[:, :, :, :, :, :, 1:].transpose((0, 1, 2, 3, 4, 6, 5)).reshape((2, 3, 3, 12, 6)) * 100

    ytick_labels = ["0.5% | " + r'~NL' + " | -----", "0.5% | " + r'NL' + " | -----", "1% | " + r'~NL' + " | -----",
                    "1% | " + r'NL' + " | -----", "5% | " + r'~NL' + " | -----", "5% | " + r'NL' + " | -----",
                    "0.5% | " + r'~NL' + " | MC", "0.5% | " + r'NL' + " | MC", "1% | " + r'~NL' + " | MC",
                    "1% | " + r'NL' + " | MC", "5% | " + r'~NL' + " | MC", "5% | " + r'NL' + " | MC"]
    fig_size = (7, 4)
    for i in range(3):
        plt.figure(figsize=fig_size)
        plt.rcParams["font.family"] = "serif"
        for j in [2, 3, 4, 5, 8, 9, 10, 11, 0, 1, 6, 7]:
            plt.plot(data_means[j // 6, 2, i, j % 6, :, 1], label=ytick_labels[j], color=colors[j], linewidth=2.0)
        plt.ylabel("Accuracy [%]", fontsize=12)
        plt.xlabel("Repeats", fontsize=12)
        plt.xticks(fontsize=12)
        plt.yticks(fontsize=12)
        plt.ylim(97, 100)
        if i == 0:
            leg = plt.legend(loc="upper left", fontsize=11, ncol=3, columnspacing=0.5, labelspacing=0.15, borderaxespad=0.1, borderpad=0.3)
            for legobj in leg.legendHandles:
                legobj.set_linewidth(3.0)
        plt.tight_layout()
        plt.savefig(sp + "overview_pseudo_line_%d_%d.pdf" % (data_ind, i))
        plt.close()
    ytick_labels = [".5% || F", "", ".5% || T", "", " 1% || F", "",
                    " 1% || T", "", " 5% || F", "", " 5% || T", ""]
    fig_size = (7, 4)
    for i in range(2):
        for j in range(3):
            for k in range(3):
                plt.figure(figsize=fig_size)
                plt.subplot(121)
                plt.rcParams["font.family"] = "serif"
                plt.imshow(data_info_inter[i, j, k], cmap="rainbow", vmin=97, vmax=100)
                plt.ylabel("Parameters", fontsize=12)
                plt.xlabel("Repeats", fontsize=12)
                plt.xticks(np.arange(6), np.arange(6), fontsize=10)
                plt.yticks(np.arange(12), ytick_labels, fontsize=10)
                plt.subplot(122)
                plt.rcParams["font.family"] = "serif"
                plt.imshow(data_means[i, j, k, :, :, 1], cmap="rainbow", vmin=97, vmax=100)
                plt.xlabel("Repeats", fontsize=12)
                plt.xticks(np.arange(7), np.arange(7), fontsize=10)
                plt.yticks(np.arange(6), ytick_labels[::2], fontsize=10)
                cb = plt.colorbar()
                cb.set_label(label='Accuracy [%]', size=12)
                plt.tight_layout()
                plt.savefig(sp + "overview_pseudo_%d_%d_%d_%d.png" % (data_ind, i, j, k))
                plt.close()
elif cur_folder == "_uncertainty_param_search":
    data = np.array(data_info[:2268]).reshape((81, 4, 7, 7))
    data_pos = np.array(data_info[2268:]).reshape((9, 4, 7, 7))
    # Mean with worst values ignored
    # ------------------------------ #
    data_worst_4 = np.argmin(data, axis=1)
    for i in range(81):
        for j in range(7):
            for k in range(7):
                data[i, data_worst_4[i, j, k], j, k] = np.nan
    data_worst_4_pos = np.argmin(data_pos, axis=1)
    for i in range(9):
        for j in range(7):
            for k in range(7):
                data_pos[i, data_worst_4[i, j, k], j, k] = np.nan
    # (kappa n; kappa p; tau n; tau p; repeats; vals)
    data_means_neg = np.nanmean(data, axis=1).reshape((3, 3, 3, 3, 7, 7)).transpose((0, 2, 1, 3, 4, 5)).reshape(
        (3, 3, 9, 7, 7)) * 100
    # (kappa p; tau p; repeats; vals)
    data_means_pos = np.nanmean(data_pos, axis=1).reshape((9, 7, 7)) * 100
    # ------------------------------ #
    data_info_inter_neg = np.array([[float(x) for x in y.split("\n")[0].split("\t")] for y in data_info_inter[:486]]).reshape((3, 3, 3, 3, 6, 3))
    data_info_inter_neg[:, :, :, :, :, 1] = data_info_inter_neg[:, :, :, :, :, 0] / data_info_inter_neg[:, :, :, :, :, 1]
    data_info_inter_neg = data_info_inter_neg[:, :, :, :, :, 1:].transpose((0, 2, 1, 3, 5, 4)).reshape((3, 3, 18, 6)) * 100
    data_info_inter_pos = np.array([[float(x) for x in y.split("\n")[0].split("\t")] for y in data_info_inter[486:]]).reshape((3, 3, 6, 3))
    data_info_inter_pos[:, :, :, 1] = data_info_inter_pos[:, :, :, 0] / data_info_inter_pos[:, :, :, 1]
    data_info_inter_pos = data_info_inter_pos[:, :, :, 1:].transpose((0, 1, 3, 2)).reshape((18, 6)) * 100

    ytick_labels = ["0.20 | 0.7", "", "0.20 | 0.9", "", "0.20 | 0.99", "",
                    "0.05 | 0.7", "", "0.05 | 0.9", "", "0.05 | 0.99", "",
                    "0.01 | 0.7", "", "0.01 | 0.9", "", "0.01 | 0.99", ""]
    fig_size = (7, 4)
    for i in range(3):
        if i == 0:
            plt.figure(figsize=fig_size)
            plt.subplot(121)
            plt.rcParams["font.family"] = "serif"
            plt.imshow(data_info_inter_pos, cmap="rainbow", vmin=97, vmax=100)
            plt.ylabel("Parameters", fontsize=12)
            plt.xlabel("Repeats", fontsize=12)
            plt.xticks(np.arange(6), np.arange(6), fontsize=10)
            plt.yticks(np.arange(18), ytick_labels, fontsize=10)
            plt.subplot(122)
            plt.rcParams["font.family"] = "serif"
            plt.imshow(data_means_pos[:, :, 1], cmap="rainbow", vmin=97, vmax=100)
            plt.xlabel("Repeats", fontsize=12)
            plt.xticks(np.arange(7), np.arange(7), fontsize=10)
            plt.yticks(np.arange(9), ytick_labels[::2], fontsize=10)
            cb = plt.colorbar()
            cb.set_label(label='Accuracy [%]', size=12)
            plt.tight_layout()
            plt.savefig(sp + "overview_pseudo_pos_%d.png" % data_ind)
            plt.close()
        for j in range(3):
            plt.figure(figsize=fig_size)
            plt.subplot(121)
            plt.rcParams["font.family"] = "serif"
            plt.imshow(data_info_inter_neg[i, j], cmap="rainbow", vmin=97, vmax=100)
            plt.ylabel("Parameters", fontsize=12)
            plt.xlabel("Repeats", fontsize=12)
            plt.xticks(np.arange(6), np.arange(6), fontsize=10)
            plt.yticks(np.arange(18), ytick_labels, fontsize=10)
            plt.subplot(122)
            plt.rcParams["font.family"] = "serif"
            plt.imshow(data_means_neg[i, j, :, :, 1], cmap="rainbow", vmin=97, vmax=100)
            plt.xlabel("Repeats", fontsize=12)
            plt.xticks(np.arange(7), np.arange(7), fontsize=10)
            plt.yticks(np.arange(9), ytick_labels[::2], fontsize=10)
            cb = plt.colorbar()
            cb.set_label(label='Accuracy [%]', size=12)
            plt.tight_layout()
            plt.savefig(sp + "overview_pseudo_%d_%d_%d.png" % (data_ind, i, j))
            plt.close()
    fig_size = (7, 4)
    xtick_labels = [r'$\kappa_p = 0.20$' + "\n" + r'$\tau_p = 0.70$', r'$\kappa_p = 0.20$' + "\n" + r'$\tau_p = 0.90$',
                    r'$\kappa_p = 0.20$' + "\n" + r'$\tau_p = 0.99$',
                    r'$\kappa_p = 0.05$' + "\n" + r'$\tau_p = 0.70$', r'$\kappa_p = 0.05$' + "\n" + r'$\tau_p = 0.90$',
                    r'$\kappa_p = 0.05$' + "\n" + r'$\tau_p = 0.99$',
                    r'$\kappa_p = 0.01$' + "\n" + r'$\tau_p = 0.70$', r'$\kappa_p = 0.01$' + "\n" + r'$\tau_p = 0.90$',
                    r'$\kappa_p = 0.01$' + "\n" + r'$\tau_p = 0.99$']
    y_labels = [r'$\kappa_n = 0.0500 | \tau_n = 0.10$', r'$\kappa_n = 0.0500 | \tau_n = 0.05$',
                r'$\kappa_n = 0.0500 | \tau_n = 0.01$',
                r'$\kappa_n = 0.0050 | \tau_n = 0.10$', r'$\kappa_n = 0.0050 | \tau_n = 0.05$',
                r'$\kappa_n = 0.0050 | \tau_n = 0.01$',
                r'$\kappa_n = 0.0005 | \tau_n = 0.10$', r'$\kappa_n = 0.0005 | \tau_n = 0.05$',
                r'$\kappa_n = 0.0005 | \tau_n = 0.01$']
    data_max = np.max(data_means_neg[:, :, :, :, 1], axis=3).reshape((9, 9))
    data_max_ind = np.argmax(data_means_neg[:, :, :, :, 1], axis=3).reshape((9, 9))
    plt.figure(figsize=fig_size)
    plt.rcParams["font.family"] = "serif"
    for i in range(9):
        plt.plot(np.arange(9), data_max[i], label=y_labels[i], color=colors[i], linewidth=2.0)
        for j in range(9):
            y_min = data_max[i, j] - data_max_ind[i, j] * 0.01
            y_max = data_max[i, j] + (6 - data_max_ind[i, j]) * 0.01
            plt.vlines(x=j, ymin=data_max[i, j] - data_max_ind[i, j] * 0.01,
                       ymax=data_max[i, j] + (6 - data_max_ind[i, j]) * 0.01, color=colors[i])
            for k in range(7):
                plt.hlines(xmin=j - 0.05, xmax=j + 0.05, y=k * (y_max - y_min) / 6 + y_min, color=colors[i])
    plt.ylabel("Accuracy [%]", fontsize=12)
    plt.ylim(98.55, 99.5)
    plt.xticks(np.arange(9), xtick_labels, fontsize=12, rotation=90)
    plt.yticks(fontsize=12)
    leg = plt.legend(loc="upper left", ncol=2, columnspacing=0.5, labelspacing=0.15, borderaxespad=0.1,
                     borderpad=0.3, fontsize=11)
    for legobj in leg.legendHandles:
        legobj.set_linewidth(3.0)
    plt.tight_layout()
    plt.savefig(sp + "overview_param_%d.pdf" % data_ind)
    plt.show()