-
Notifications
You must be signed in to change notification settings - Fork 0
/
fairnessIndexAnalyze.py
82 lines (62 loc) · 1.83 KB
/
fairnessIndexAnalyze.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
from gen_dataset import *
import numpy as np
import pdb
import matplotlib
import matplotlib.pyplot as plt
def computeFairnessIndex(data,n):
phiNode0 = 1/n
phiOtherNodes = 1-phiNode0
fIndex = (data[0]/phiNode0)/(data[1]/phiOtherNodes)
return fIndex
def fairPolicy(fIndex,C,currCWMin):
nextCWMin = currCWMin
if fIndex > C:
nextCWMin = 2*currCWMin
elif fIndex < (1/C):
nextCWMin = int(currCWMin/2)
return nextCWMin
n = 10
dataDict = genDataset(n)
otherCWList = [32,128]
node0CWList = [32,64,128]
fIndexList = dict()
numSamples = 500
for i in range(len(node0CWList)):
for j in range(len(otherCWList)):
node0CW = node0CWList[i]
otherCW = otherCWList[j]
key = str(node0CW)+'+'+str(otherCW)
data = dataDict[key]
fIndex = []
for k in range(numSamples):
fIndex.append(computeFairnessIndex(data[k],n))
fIndexList[key] =fIndex
plotData = []
plotData.append(fIndexList['32+32'])
plotData.append(fIndexList['64+32'])
plotData.append(fIndexList['128+32'])
labels = ['32+32','64+32','128+32']
fig, ax = plt.subplots()
ax.boxplot(plotData,showfliers=False,showmeans=True)
ax.set_xticklabels(labels,fontsize=10)
ax.set_ylabel('Fairness Index',fontsize = 10)
# ax.set_ylim([0,1])
ax.set_title('N = '+str(n)+', Others = 32',fontsize = 16)
ax.grid()
plt.tight_layout()
plt.savefig('./fairnessIndex/base32-'+str(n)+'Node.png')
plotData = []
plotData.append(fIndexList['32+128'])
plotData.append(fIndexList['64+128'])
plotData.append(fIndexList['128+128'])
labels = ['32+128','64+128','128+128']
fig, ax = plt.subplots()
ax.boxplot(plotData,showfliers=False,showmeans=True)
ax.set_xticklabels(labels,fontsize=10)
ax.set_ylabel('Fairness Index',fontsize = 10)
# ax.set_ylim([0,1])
ax.set_title('N = '+str(n)+', Others = 128',fontsize = 16)
ax.grid()
plt.tight_layout()
plt.savefig('./fairnessIndex/base128-'+str(n)+'Node.png')
# pdb.set_trace()