-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc.py
144 lines (113 loc) · 5.05 KB
/
proc.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
from numpy import mean
metrics = ["accuracy", "spd", "aaod", "eod"]
baselines = ["rew", "adv", "roc", "care", "supp"]
methods = ["single", "dual"]
tasks = ["adult_race", "adult_sex", "bank_age", "compas_race", "compas_sex", "german_age", "german_sex"]
def get_metrics(filename):
with open(filename, "r", encoding="UTF-8") as f:
lines = f.readlines()
for line in lines:
if "accuracy" in line and "change" not in line:
accuracy = float(line.strip().split("\t")[-2])
if "spd" in line and "change" not in line:
spd = float(line.strip().split("\t")[-2])
if "aaod" in line and "change" not in line:
aaod = float(line.strip().split("\t")[-2])
if "eod" in line and "change" not in line:
eod = float(line.strip().split("\t")[-2])
return accuracy, spd, aaod, eod
def get_metric_changes(filename):
with open(filename, "r", encoding="UTF-8") as f:
lines = f.readlines()
for line in lines:
if "accuracy change:" in line:
accuracy = float(line.strip().split("accuracy change: ")[1])
if "spd change:" in line:
spd = float(line.strip().split("spd change: ")[1])
if "aaod change:" in line:
aaod = float(line.strip().split("aaod change: ")[1])
if "eod change:" in line:
eod = float(line.strip().split("eod change: ")[1])
return accuracy, spd, aaod, eod
def table9():
results = {}
for baseline in baselines:
results[baseline] = {}
for metric in metrics:
results[baseline][metric] = {}
for task in tasks:
results[baseline][metric][task] = {}
for baseline in baselines:
for metric in metrics:
for task in tasks:
for method in methods:
base_accuracy, base_spd, base_aaod, base_eod = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
accuracy, spd, aaod, eod = get_metrics(f"./RQ5_results/fmt/fmt_{method}_{task}.txt")
results[baseline]["accuracy"][task][method] = (accuracy-base_accuracy) * 100
results[baseline]["spd"][task][method] = (base_spd-spd) * 100
results[baseline]["aaod"][task][method] = (base_aaod-aaod) * 100
results[baseline]["eod"][task][method] = (base_eod-eod) * 100
for baseline in baselines:
for metric in metrics:
print("")
print(baseline, metric)
print("")
for task in tasks:
for method in methods:
print(task, method)
print("%.2f" % (results[baseline][metric][task][method]))
def fmt_s_aaod():
results = []
for baseline in baselines:
for task in tasks:
_, _, base_aaod, _ = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
_, _, aaod, _ = get_metrics(f"./RQ5_results/fmt/fmt_single_{task}.txt")
results.append((base_aaod-aaod) / base_aaod)
print("%.2f" % (mean(results) * 100))
def fmt_s_eod():
results = []
for baseline in baselines:
for task in tasks:
_, _, _, base_eod = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
_, _, _, eod = get_metrics(f"./RQ5_results/fmt/fmt_single_{task}.txt")
results.append((base_eod-eod) / base_eod)
print("%.2f" % (mean(results) * 100))
def fmt_d_aaod():
results = []
for baseline in baselines:
for task in tasks:
_, _, base_aaod, _ = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
_, _, aaod, _ = get_metrics(f"./RQ5_results/fmt/fmt_dual_{task}.txt")
results.append((base_aaod-aaod) / base_aaod)
print("%.2f" % (mean(results) * 100))
def fmt_d_eod():
results = []
for baseline in baselines:
for task in tasks:
_, _, _, base_eod = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
_, _, _, eod = get_metrics(f"./RQ5_results/fmt/fmt_dual_{task}.txt")
results.append((base_eod-eod) / base_eod)
print("%.2f" % (mean(results) * 100))
def fmt_s_acc():
results = []
for baseline in baselines:
for task in tasks:
base_acc, _, _, _ = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
acc, _, _, _ = get_metrics(f"./RQ5_results/fmt/fmt_single_{task}.txt")
results.append((acc-base_acc) / base_acc)
print("%.2f" % (mean(results) * 100))
def fmt_d_acc():
results = []
for baseline in baselines:
for task in tasks:
base_acc, _, _, _ = get_metrics(f"./RQ5_results/{baseline}/{baseline}_{task}.txt")
acc, _, _, _ = get_metrics(f"./RQ5_results/fmt/fmt_dual_{task}.txt")
results.append((acc-base_acc) / base_acc)
print("%.2f" % (mean(results) * 100))
if __name__ == "__main__":
# fmt_s_aaod()
# fmt_s_eod()
# fmt_d_aaod()
# fmt_d_eod()
fmt_s_acc()
fmt_d_acc()