-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
140 lines (104 loc) · 4.33 KB
/
test.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
from dcnn import *
import matplotlib.pyplot as plt
def generate_test_sets():
sir_db = 10
test_rho_list = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
for test_rho in test_rho_list:
print("Generating data sets, rho={:.1f} sir={}".format(test_rho, sir_db))
test_set = DataSet(flag=2, rho=test_rho, sir=sir_db)
test_set.produce_all()
def benchmark(k):
sir_db = 10
test_rho_list = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
sir_list = []
rho_list = []
ber_mld_list = []
ber_baseline_list = []
ber_improved_list = []
mse_baseline_list = []
mse_improved_list = []
jb_baseline_list = []
jb_improved_list = []
for rho in test_rho_list:
test_io = DataSet(flag=2, rho=rho, sir=sir_db)
baseline_dcnnmld = DCNNMLD(rho, sir_db, is_improved=False)
improved_dcnnmld = DCNNMLD(rho, sir_db, is_improved=True)
baseline_dcnnmld.load()
improved_dcnnmld.load()
err_mld = 0
err_baseline = 0
err_improved = 0
r_baseline = None
r_improved = None
total = 0
idx = 0
for y, h, s, one_hot, w, hat_s, hat_w in test_io.fetch():
print("Testing rho={:.1f} sir={} batch={}/{}".format(rho, sir_db, idx + 1, TEST_TOTAL_BATCH), end="\r")
bits = get_bits(s)
total += bits.size
bits_mld = get_bits(hat_s)
err_mld += len(np.argwhere(bits_mld != bits))
bits_baseline, w_baseline = baseline_dcnnmld.detect_bits_batch(y, h, hat_w, k)
err_baseline += len(np.argwhere(bits_baseline != bits))
r_baseline = concatenate(r_baseline, w - w_baseline)
bits_improved, w_improved = improved_dcnnmld.detect_bits_batch(y, h, hat_w, k)
err_improved += len(np.argwhere(bits_improved != bits))
r_improved = concatenate(r_improved, w - w_improved)
idx += 1
print()
baseline_dcnnmld.close()
improved_dcnnmld.close()
ber_mld = err_mld / total
ber_baseline = err_baseline / total
ber_improved = err_improved / total
mse_baseline = np.mean(r_baseline ** 2)
mse_improved = np.mean(r_improved ** 2)
jb_baseline = jbtest(r_baseline)
jb_improved = jbtest(r_improved)
print("rho={:.1f}".format(rho))
print("sir={}".format(sir_db))
print("ber_mld={:e}".format(ber_mld))
print("ber_baseline={:e}".format(ber_baseline))
print("ber_improved={:e}".format(ber_improved))
print("mse_baseline={:e}".format(mse_baseline))
print("mse_improved={:e}".format(mse_improved))
print("jbtest_baseline={:e}".format(jb_baseline))
print("jbtest_improved={:e}".format(jb_improved))
print()
rho_list.append(rho)
sir_list.append(sir_db)
ber_mld_list.append(ber_mld)
ber_baseline_list.append(ber_baseline)
ber_improved_list.append(ber_improved)
mse_baseline_list.append(mse_baseline)
mse_improved_list.append(mse_improved)
jb_baseline_list.append(jb_baseline)
jb_improved_list.append(jb_improved)
print("BENCHMARK RESULT")
print("K={} NORMALIZED_DOPPLER_FREQUENCY={}".format(k, NORMALIZED_DOPPLER_FREQUENCY))
print("rho\tsir_db\tber_mld\t\tber_baseline\tber_improved\tmse_baseline\tmse_improved\tjbtest_baseline\tjbtest_improved")
for i in range(len(rho_list)):
rho = rho_list[i]
sir_db = sir_list[i]
ber_mld = ber_mld_list[i]
ber_baseline = ber_baseline_list[i]
ber_improved = ber_improved_list[i]
mse_improved = mse_improved_list[i]
mse_baseline = mse_baseline_list[i]
jb_baseline = jb_baseline_list[i]
jb_improved = jb_improved_list[i]
print("{:.1f}\t{}\t{:e}\t{:e}\t{:e}\t{:e}\t{:e}\t{:e}\t{:e}".format(
rho,
sir_db,
ber_mld, ber_baseline, ber_improved,
mse_baseline, mse_improved,
jb_baseline, jb_improved))
# 画个小图图
plt.semilogy(rho_list, ber_mld_list)
plt.semilogy(rho_list, ber_baseline_list)
plt.semilogy(rho_list, ber_improved_list)
plt.legend(["Standard MLD", "Baseline DCNN-MLD(K={})".format(k), "Improved DCNN-MLD(K={})".format(k)])
plt.show()
if __name__ == "__main__":
generate_test_sets()
benchmark(k=1)