-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtabulate_rca_opt_param.py
71 lines (59 loc) · 1.9 KB
/
tabulate_rca_opt_param.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tabulate RCA results computed by script compute_rca_opt_param.py.
"""
import os
import numpy as np
from sporco import plot
# Function for tabulating results
def print_table(shpnum, ppsnum, tblval, textbl=False):
shpstr = list(map(lambda x: x[0], sorted(list(shpnum.items()),
key=lambda x: x[1])))
if textbl:
print(' ' * 10 + '& ' + ' & '.join(ppsnum.keys()) +
r' \\ \hline')
else:
print(' ' * 12 + ' '.join(ppsnum.keys()))
for n in range(len(shpnum)):
if textbl:
print(('%-10s' % shpstr[n]) + '& ' +
' & '.join(['%5.2f' % x for x in tblval[n]]) +
r' \\ \hline')
else:
print(('%-12s' % shpstr[n]) +
' '.join(['%5.2f' % x for x in tblval[n]]))
# Load data
rsltpath = 'data/rca_results'
rsltfile = os.path.join(rsltpath, 'rca_opt_param.npz')
npz = np.load(rsltfile, allow_pickle=True)
results = npz['results'].item()
paramranges = npz['paramranges'].item()
# Select output format (if true, insert LaTeX formatting in table)
textbl = False
# Define mappings from parameter strings to index values
shpnum = {
'narrow': 0,
'wide': 1,
'elong': 2,
'complex': 3
}
ppsnum = {
'd001': 0,
'd010': 1,
'd025': 2,
'd050': 3,
'd100': 4
}
# Construct array of best SNR values
maxsnr = np.zeros((len(shpnum), len(ppsnum)))
for key in sorted(results.keys()):
keycmpnt = key[:-4].split('_')
shape = keycmpnt[0]
pps = keycmpnt[1]
maxsnr[shpnum[shape], ppsnum[pps]] = results[key]['sfvl']
# Display table of results
print('Results recorded during parameter optimization (SNR in dB):')
print_table(shpnum, ppsnum, maxsnr, textbl)
print('Min: %5.2f Mean: %5.2f Median: %5.2f Max: %5.2f' %
(maxsnr.min(), maxsnr.mean(), np.median(maxsnr), maxsnr.max()))