-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd.py
More file actions
47 lines (45 loc) · 3.29 KB
/
add.py
File metadata and controls
47 lines (45 loc) · 3.29 KB
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
import numpy as np
init_dict = {"fednova":
{"mnist":{1:[0.0892, 0.0892, 0.0892], 2:[0.0892, 0.0892, 0.0892], 3:[0.0892, 0.0892, 0.0892]},
"cifar10":{1:[0.0997, 0.0997, 0.0997], 2:[0.0997, 0.0997, 0.0997], 3:[0.0997, 0.0997, 0.0997]},
"fmnist":{1:[0.1, 0.1, 0.1], 2:[0.1, 0.1, 0.1], 3:[0.1, 0.1, 0.1]},
"a9a":{1:[0.3749155457281494, 0.3749155457281494, 0.3749155457281494]},
"rcv1":{1:[0.48745307251531317, 0.48745307251531317, 0.48745307251531317]},
"covtype":{1:[0.5119894253474971, 0.5119894253474971, 0.5119894253474971]}},
"fedprox": {"mnist":{1:[0.0997, 0.0997, 0.0997], 2:[0.0997, 0.0997, 0.0997], 3:[0.0997, 0.0997, 0.0997]},
"cifar10":{1:[0.0997, 0.1, 0.0997], 2:[0.0997, 0.0997, 0.0997], 3:[0.0997, 0.0997, 0.0997]},
"fmnist":{1:[0.1, 0.1, 0.1], 2:[0.1, 0.1, 0.1], 3:[0.1, 0.1, 0.1]},
"a9a":{1:[0.3749155457281494, 0.7392666298138935, 0.31908359437380995]},
"rcv1":{1:[0.48745307251531317, 0.48745307251531317, 0.48745307251531317]},
"covtype":{1:[0.5119894253474971, 0.5119894253474971, 0.5119894253474971]}},
"fedavg": {"mnist":{1:[0.0892, 0.1009, 0.0892], 2:[0.1009, 0.0892, 0.0892], 3:[0.0892, 0.1009, 0.0892]},
"cifar10":{1:[0.0997, 0.1, 0.0997], 2:[0.1, 0.1, 0.0997], 3:[0.0997, 0.1, 0.1]},
"fmnist":{1:[0.1, 0.1, 0.1], 2:[0.1, 0.1, 0.1], 3:[0.1, 0.1, 0.1]},
"a9a":{1:[0.3749155457281494, 0.7392666298138935, 0.31908359437380995]},
"rcv1":{1:[0.48745307251531317, 0.5107686228018178, 0.48745307251531317]},
"covtype":{1:[0.5119894253474971, 0.5118517345596992, 0.5119894253474971]}},
"scaffold":{"mnist":{1:[0.0892, 0.0892, 0.1009], 2:[0.0892, 0.0892, 0.0892], 3:[0.0892, 0.0892, 0.0892]},
"cifar10":{1:[0.0997, 0.1, 0.0997], 2:[0.1, 0.0997, 0.0997], 3:[0.0997, 0.1, 0.0997]},
"fmnist":{1:[0.1, 0.1, 0.1], 2:[0.1, 0.1, 0.1], 3:[0.1, 0.1, 0.1]},
"a9a":{1:[0.3749155457281494, 0.7392666298138935, 0.31908359437380995]},
"rcv1":{1:[0.48745307251531317, 0.5107686228018178, 0.48863860897055916]},
"covtype":{1:[0.5119894253474971, 0.5118517345596992, 0.5129326072439123]}}}
for m in ("fedavg", "fednova", "fedprox", "scaffold"):
for d in ("mnist", "cifar10", "fmnist", "a9a"):#, "rcv1", "covtype"):
for t in range(1, 4):
if d in ("mnist", "cifar10", "fmnist"):
for c in range(1,4):
if t == 1:
data = np.load("/home/txy/NIID-Bench/acc_npy/" + d + "/10 party/" + m + "_noniid-#label"+ str(c) +"_test_acc.npy")
else:
data = np.load("/home/txy/NIID-Bench/acc_npy/" + d + "/10 party/"+str(t) + "_"+ m +"_noniid-#label"+ str(c) +"_test_acc.npy")
print(init_dict[m][d][c][t-1])
data = np.insert(data, 0, init_dict[m][d][c][t-1])
np.save("/home/txy/NIID-Bench/acc_npy/" + d + "/10/" + str(m) + "/" + str(c) + "/" + str(t) + ".npy", data)
else:
if t == 1:
data = np.load("/home/txy/NIID-Bench/acc_npy/" + d + "/10 party/" + m + "_noniid-#label1_test_acc.npy")
else:
data = np.load("/home/txy/NIID-Bench/acc_npy/" + d + "/10 party/"+str(t) + "_"+ m +"_noniid-#label1_test_acc.npy")
np.insert(data, 0, init_dict[m][d][1][t-1])
np.save("/home/txy/NIID-Bench/acc_npy/" + d + "/10/" + str(m) + "/" + str(c) + "/" + str(t) + ".npy", data)