-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_tables_mvs.py
49 lines (38 loc) · 1.84 KB
/
05_tables_mvs.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
from config import *
import numpy as np
from tabulate import tabulate
from sklearn.base import BaseEstimator
CLF = 0
ovs_names = []
for ovs_i, _ovs in enumerate(RESAMPLING):
if isinstance(_ovs, BaseEstimator):
osv_name = type(_ovs).__name__
else:
osv_name = _ovs.__name__
ovs_names.append(osv_name)
# len(DATASETS), len(BASE_CLASSIFIERS), len(RESAMPLING), SPLIT.get_n_splits()
METRICS = [
("ED", np.load(os.path.join("_results", "ed_scores.npy")), lambda x: f"{x:.2f}"),
("HV", np.load(os.path.join("_results", "hv_scores.npy")), lambda x: f"{x * 1000:.2f}"),
("DR", np.load(os.path.join("_results", "dr_scores.npy")), lambda x: f"{x:.2f}"),
("SDR", np.load(os.path.join("_results", "sdr_scores.npy")), lambda x: f"{x:.2f}"),
]
for m_name, m_table, m_str in METRICS:
mean_v = np.mean(m_table, axis=-1)[:, CLF, :].T
std_v = np.std(m_table, axis=-1)[:, CLF, :].T
index = np.array(ovs_names)
header = ['Sampling'] + [f'$\\mathcal{{DS}}_{{{_}}}$' for _ in range(1, len(DS_NAMES) + 1)]
mean_s = np.vectorize(lambda x: f"\makecell{{{m_str(x)} \\\\")(mean_v)
std_s = np.vectorize(lambda x: f" \\tiny{{ \\color{{gray}} ({m_str(x)})}}}}")(std_v)
table_data = np.char.add(mean_s, std_s)
table_data = np.concatenate([index[:, None], table_data], axis=1)
table = tabulate(table_data, tablefmt="latex_raw", headers=header)
with open(os.path.join("_tables", f'{m_name}.tex'), 'w') as fp:
fp.write(table)
mean_s = np.vectorize(lambda x: f"{m_str(x)}")(mean_v)
std_s = np.vectorize(lambda x: f"\n({m_str(x)})")(std_v)
table_data = np.char.add(mean_s, std_s)
table_data = np.concatenate([index[:, None], table_data], axis=1)
table = tabulate(table_data, tablefmt="grid", headers=header)
with open(os.path.join("_tables", f'{m_name}.tbl'), 'w') as fp:
fp.write(table)