-
Notifications
You must be signed in to change notification settings - Fork 3
/
plot.py
executable file
·159 lines (101 loc) · 4.47 KB
/
plot.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 5 14:27:36 2018
"""
import matplotlib.pyplot as plt
import os
from sklearn.externals import joblib
import numpy as np
def enumplot(res_folder, prefix,exp_prefix):
# experiments results urls
objectiveFunction_results = './%s/%s/%s/objectiveFunction.dump' %(res_folder,prefix,exp_prefix)
# files for train performances
unfairness_train_results = './%s/%s/%s/unfairness_train.dump' % (res_folder,prefix,exp_prefix)
accuracy_train_results = './%s/%s/%s/accuracy_train.dump' %(res_folder,prefix,exp_prefix)
# files for test performances
unfairness_test_results = './%s/%s/%s/unfairness_test.dump' %(res_folder,prefix,exp_prefix)
accuracy_test_results = './%s/%s/%s/accuracy_test.dump' %(res_folder,prefix,exp_prefix)
img_file = './%s/%s/%s/plot.png' %(res_folder,prefix,exp_prefix)
# objectives values
obj_ = joblib.load(objectiveFunction_results)
# unfairness and fidelity on training set
unfairness_train = joblib.load(unfairness_train_results)
fidelity_train = joblib.load(accuracy_train_results)
# unfairness and fidelity on test set
unfairness_test = joblib.load(unfairness_test_results)
fidelity_test = joblib.load(accuracy_test_results)
#print(sorted(obj_, reverse=True) == obj_)
#print("unfairness_train ", unfairness_train)
fig = plt.figure()
plt.subplot(2,2,1)
plt.plot(obj_,'o-b')
plt.ylabel('Objective function')
plt.subplot(2,2,2)
plt.plot(fidelity_test,'o-g', label='test')
plt.plot(fidelity_train,'-or', label='train')
plt.legend(loc='upper right')
plt.ylabel('Fidelity')
plt.subplots_adjust(wspace=0.98)
plt.subplot(2,2,3)
plt.plot(unfairness_test,'o-g', label='test')
plt.plot(unfairness_train,'-or', label='train')
plt.legend(loc='upper right')
plt.ylabel('Unfairness')
""" plt.subplot(2,2,4)
plt.plot(unfairness, acc, '+')
plt.axis([0, 1, 0, 1])
plt.ylabel('fidelity')
plt.xlabel('unfairness') """
fig.savefig(img_file)
# plt.show()
def enumplot_local(prefix,exp_prefix):
# experiments results urls
objectiveFunction_results = './res_local/%s/%s/objectiveFunction.dump' %(prefix,exp_prefix)
# files for train performances
unfairness_train_results = './res_local/%s/%s/unfairness_train.dump' % (prefix,exp_prefix)
accuracy_train_results = './res_local/%s/%s/accuracy_train.dump' %(prefix,exp_prefix)
img_file = './res_local/%s/%s/plot.png' %(prefix,exp_prefix)
# objectives values
obj_ = joblib.load(objectiveFunction_results)
# unfairness and fidelity on training set
unfairness_train = joblib.load(unfairness_train_results)
fidelity_train = joblib.load(accuracy_train_results)
#print(sorted(obj_, reverse=True) == obj_)
fig = plt.figure()
plt.subplot(2,2,1)
plt.plot(obj_,'o-b')
plt.ylabel('Objective function')
plt.subplot(2,2,2)
plt.plot(fidelity_train,'-or', label='train')
plt.ylabel('Fidelity')
plt.subplots_adjust(wspace=0.98)
plt.subplot(2,2,3)
plt.plot(unfairness_train,'-or', label='train')
plt.ylabel('Unfairness')
""" plt.subplot(2,2,4)
plt.plot(unfairness, acc, '+')
plt.axis([0, 1, 0, 1])
plt.ylabel('fidelity')
plt.xlabel('unfairness') """
fig.savefig(img_file)
# plt.show()
def best_unfairness(prefix,exp_prefix):
# files for train performances
unfairness_train_results = './res_local/%s/%s/unfairness_train.dump' % (prefix,exp_prefix)
accuracy_train_results = './res_local/%s/%s/accuracy_train.dump' %(prefix,exp_prefix)
# unfairness and fidelity on training set
unfairness_train = joblib.load(unfairness_train_results)
fidelity_train = joblib.load(accuracy_train_results)
# print(unfairness_train)
# print(fidelity_train)
out = None
all_val = [(unfairness_train[i], fidelity_train[i]) for i in range(len(unfairness_train))]
all_val = sorted(all_val, key=lambda x: x[0], reverse=False)
all_val_yes = [(x[0], x[1]) for x in all_val if x[1] ]
#print("<<<<<<>>>>>>"*5, all_val_yes)
if(len(all_val_yes) > 0):
out = (all_val_yes[0][0], all_val_yes[0][1])
else:
out = (all_val[0][0], all_val[0][1])
return out