-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDetNet_Soft_16QAM.py
555 lines (475 loc) · 19.6 KB
/
DetNet_Soft_16QAM.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
#!/usr/bin/env python
import tensorflow as tf
import numpy as np
import time as tm
import math
import sys
import pickle as pkl
"""
This file is used to train and test the DetNet architecture in the soft decision output scenario.
The constellation used is 16PSK and the channel is complex
all parameters were optimized and trained over the 4X8 iid channel, changing the channel might require parameter tuning
Notice that the run time analysis presented in the paper was made on a numpy version of the tensorflow network.
The times presented in the paper differ from the ones obtained using this code.
writen by Neev Samuel based on the paper:
"Learning to detect, Neev Samuel,Tzvi Diskin,Ami Wiesel"
contact by neev.samuel@gmail.com
"""
def find_nearest_np(values):
values = values + 3
values = values/2
values = np.clip(values,0,3)
values = np.round(values)
values = values * 2
values = values - 3
return values
def find_nearest(values):
values = values + 3
values = values/2
values = tf.clip_by_value(values,0,3)
values = tf.round(values)
values = values * 2
values = values - 3
return values
def validate2(y, SNR, H, K, N):
final_probs_three = np.zeros((K))
final_probs_one = np.zeros((K))
final_probs_minus_one = np.zeros((K))
final_probs_minus_three = np.zeros((K))
sun_plus_three = 0
sum_plus = 0
sum_minus = 0
sum_minus_three = 0
tmp_snr = (H.T.dot(H)).trace()/ K
y = y/ np.sqrt(tmp_snr) * np.sqrt(SNR)
for i in range(np.power(2, K)):
binary1 = "{0:b}".format(i)
binary1 = binary1.zfill(K)
binary1 = [int(d) for d in binary1]
binary1 = np.array(binary1)
x1 = (binary1 * 2) - 1
for j in range(np.power(2, K)):
binary2 = "{0:b}".format(j)
binary2 = binary2.zfill(K)
binary2 = [int(d1) for d1 in binary2]
binary2 = np.array(binary2)
x2 = (binary2 * 2) - 1
x = np.zeros((K))
for jj in range(K):
if x1[jj] == -1 and x2[jj] == -1:
x[jj] = -3
if x1[jj] == -1 and x2[jj] == 1:
x[jj] = -1
if x1[jj] == 1 and x2[jj] == -1:
x[jj] = 1
if x1[jj] == 1 and x2[jj] == 1:
x[jj] = 3
H_tmp = H / np.sqrt(tmp_snr) * np.sqrt(SNR)
y_temp = H_tmp.dot(x)
prob = np.exp(-0.5 * (np.sum(np.power(y_temp[jj] - y[jj], 2) for jj in range(N))))
for ii in range(K):
if x[ii] == 3:
final_probs_three[ii] = final_probs_three[ii] + ((1.0 / np.power(2, K)) * prob)
sun_plus_three = sun_plus_three + 1
if x[ii] == 1:
final_probs_one[ii] = final_probs_one[ii] + ((1.0 / np.power(2, K)) * prob)
sum_plus = sum_plus + 1
if x[ii] == -1:
final_probs_minus_one[ii] = final_probs_minus_one[ii] + ((1.0 / np.power(2, K)) * prob)
sum_minus = sum_minus + 1
if x[ii] == -3:
final_probs_minus_three[ii] = final_probs_minus_three[ii] + ((1.0 / np.power(2, K)) * prob)
sum_minus_three = sum_minus_three + 1
for ii in range(K):
norm = final_probs_one[ii] + final_probs_minus_one[ii] + final_probs_minus_three[ii] + final_probs_three[ii]
final_probs_one[ii] = final_probs_one[ii] / norm
final_probs_minus_one[ii] = final_probs_minus_one[ii] / norm
final_probs_minus_three[ii] = final_probs_minus_three[ii]/norm
final_probs_three[ii] = final_probs_three[ii]/norm
return final_probs_one, final_probs_minus_one,final_probs_minus_three,final_probs_three
###start here
"""
Parameters
K - size of x
N - size of y
snrdb_low - the lower bound of noise db used during training
snr_high - the higher bound of noise db used during training
L - number of layers in DetNet
v_size = size of auxiliary variable at each layer
hl_size - size of hidden layer at each DetNet layer (the dimention the layers input are increased to
startingLearningRate - the initial step size of the gradient descent algorithm
decay_factor & decay_step_size - each decay_step_size steps the learning rate decay by decay_factor
train_iter - number of train iterations
train_batch_size - batch size during training phase
test_iter - number of test iterations
test_batch_size - batch size during testing phase
LOG_LOSS - equal 1 if loss of each layer should be sumed in proportion to the layer depth, otherwise all losses have the same weight
res_alpha- the proportion of the previuos layer output to be added to the current layers output (view ResNet article)
snrdb_low_test & snrdb_high_test & num_snr - when testing, num_snr different SNR values will be tested, uniformly spread between snrdb_low_test and snrdb_high_test
"""
sess = tf.InteractiveSession()
#parameters
K = 4
N = 8
snrdb_low = 7.0
snrdb_high = 14.0
snr_low = 10.0 ** (snrdb_low/10.0)
snr_high = 10.0 ** (snrdb_high/10.0)
L=30
v_size = 4*(2*K)
hl_size = 12*(2*K)
startingLearningRate1 = 0.0005
startingLearningRate2 = 0.0005
decay_factor1 = 0.97
decay_factor2 = 0.97
decay_step_size1 = 1000
decay_step_size2 = 1000
train_iter = 80000
train_iter_no_noise = 10000
train_batch_size = 5000
test_iter= 20
test_batch_size = 50
LOG_LOSS = 1
res_alpha=0.9
num_snr = 6
snrdb_low_test=8.0
snrdb_high_test=13.0
symbols = np.array([-3,-1,1,3])
normalize_dist = 1
print('16QAM soft with validation')
print(K)
print(N)
print(snrdb_low)
print(snrdb_high)
print(snr_low)
print(snr_high)
print(L)
print(v_size)
print(hl_size)
print(startingLearningRate1)
print(startingLearningRate2)
print(decay_factor1)
print(decay_factor2)
print(decay_step_size1)
print(decay_step_size2)
print(train_iter)
print(train_batch_size)
print(test_iter)
print(test_batch_size)
print(res_alpha)
print(num_snr)
print(snrdb_low_test)
print(snrdb_high_test)
print(normalize_dist)
"""Data generation for train and test phases
In this example, both functions are the same.
This duplication is in order to easily allow testing cases where the test is over different distributions of data than in the training phase.
e.g. training over gaussian i.i.d. channels and testing over a specific constant channel.
currently both test and train are over i.i.d gaussian channel.
"""
def generate_data(B,K,N,snr_low,snr_high,noise):
x_R = np.random.randint(4, size=(B, K))
x_R = x_R * 2
x_R = x_R - 3
x_I = np.random.randint(4, size=(B, K))
x_I = x_I * 2
x_I = x_I - 3
x_ind = np.zeros([B,K,16])
for i in range(B):
for ii in range(K):
if x_R[i,ii]==-3 and x_I[i,ii] == -3:
x_ind[i,ii,0] = 1
if x_R[i,ii]==-3 and x_I[i,ii] == -1:
x_ind[i,ii,1] = 1
if x_R[i,ii]==-3 and x_I[i,ii] == 1:
x_ind[i,ii,2] = 1
if x_R[i,ii]==-3 and x_I[i,ii] == 3:
x_ind[i,ii,3] = 1
if x_R[i,ii]==-1 and x_I[i,ii] == -3:
x_ind[i,ii,4] = 1
if x_R[i,ii]==-1 and x_I[i,ii] == -1:
x_ind[i,ii,5] = 1
if x_R[i,ii]==-1 and x_I[i,ii] == 1:
x_ind[i,ii,6] = 1
if x_R[i,ii]==-1 and x_I[i,ii] == 3:
x_ind[i,ii,7] = 1
if x_R[i,ii]==1 and x_I[i,ii] == -3:
x_ind[i,ii,8] = 1
if x_R[i,ii]==1 and x_I[i,ii] == -1:
x_ind[i,ii,9] = 1
if x_R[i,ii]==1 and x_I[i,ii] == 1:
x_ind[i,ii,10] = 1
if x_R[i,ii]==1 and x_I[i,ii] == 3:
x_ind[i,ii,11] = 1
if x_R[i,ii]==3 and x_I[i,ii] == -3:
x_ind[i,ii,12] = 1
if x_R[i,ii]==3 and x_I[i,ii] == -1:
x_ind[i,ii,13] = 1
if x_R[i,ii]==3 and x_I[i,ii] == 1:
x_ind[i,ii,14] = 1
if x_R[i,ii]==3 and x_I[i,ii] == 3:
x_ind[i,ii,15] = 1
x_ = np.concatenate((x_R, x_I), axis=1)
H_R = np.random.randn(B, N, K)
H_I = np.random.randn(B, N, K)
H_ = np.zeros([B, 2 * N, 2 * K])
y_ = np.zeros([B, 2 * N])
w_R = np.random.randn(B, N)
w_I = np.random.randn(B, N)
w = np.concatenate((w_R, w_I), axis=1)
Hy_ = x_ * 0
HH_ = np.zeros([B, 2 * K, 2 * K])
SNR_ = np.zeros([B])
for i in range(B):
# print i
SNR = np.random.uniform(low=snr_low, high=snr_high)
H = np.concatenate((np.concatenate((H_R[i, :, :], -1 * H_I[i, :, :]), axis=1),
np.concatenate((H_I[i, :, :], H_R[i, :, :]), axis=1)), axis=0)
tmp_snr = (H.T.dot(H)).trace() / (2 * K)
H_[i, :, :] = H
y_[i, :] = H.dot(x_[i, :]) + noise*w[i,:]*np.sqrt(tmp_snr) / np.sqrt(SNR)
Hy_[i, :] = H.T.dot(y_[i, :])
HH_[i, :, :] = H.T.dot(H_[i, :, :])
SNR_[i] = SNR
return y_,H_,Hy_,HH_,x_,SNR_,x_ind
def piecewise_linear_soft_sign(x):
t = tf.Variable(0.1)
y = -1+tf.nn.relu(x+t)/(tf.abs(t)+0.00001)-tf.nn.relu(x-t)/(tf.abs(t)+0.00001)
return y
def affine_layer(x,input_size,output_size,Layer_num):
W = tf.Variable(tf.random_normal([input_size, output_size], stddev=0.01))
w = tf.Variable(tf.random_normal([1, output_size], stddev=0.01))
y = tf.matmul(x, W)+w
return y
def relu_layer(x,input_size,output_size,Layer_num):
y = tf.nn.relu(affine_layer(x,input_size,output_size,Layer_num))
return y
def sign_layer(x,input_size,output_size,Layer_num):
y = affine_layer(x,input_size,output_size,Layer_num)
return y
#tensorflow placeholders, the input given to the model in order to train and test the network
HY = tf.placeholder(tf.float32,shape=[None,2*K])
X = tf.placeholder(tf.float32,shape=[None,2*K])
X_IND = tf.placeholder(tf.float32,shape=[None,K,16])
HH = tf.placeholder(tf.float32,shape=[None, 2*K , 2*K])
batch_size = tf.shape(HY)[0]
S1=[]
S1.append(tf.zeros([batch_size,2*K]))
S2=[]
S2.append(tf.zeros([batch_size,16*K]))
S4 = []
S4.append(tf.zeros([batch_size,K,4,2]))
V=[]
V.append(tf.zeros([batch_size,v_size]))
LOSS=[]
LOSS.append(tf.zeros([]))
BER=[]
BER.append(tf.zeros([]))
delta = tf.Variable(tf.zeros(L*2,1))
Z1 = []
ZZ1 = []
W11 = []
w11 = []
W22 = []
w22 = []
W33 = []
w33 = []
Z1_1 = []
temp1 = []
Z = []
first = []
second = []
#The architecture of DetNet
for i in range(1,L):
print('i')
print(i)
temp11 = tf.matmul(tf.expand_dims(S1[-1],1),HH)
temp1.append(tf.squeeze(temp11,1))
first.append(delta[(i-1) * 2]*HY)
second.append(delta[(i-1) * 2 + 1]*temp1[-1])
Z1.append(S1[-1] - (delta[(i-1) * 2]*HY) + (delta[(i-1) * 2 + 1]*temp1[-1]))
Z.append(tf.concat([Z1[-1], V[-1]], 1))
ZZ = relu_layer(Z[-1],(2*K) + v_size , hl_size,'relu'+str(i))
S2_temp = sign_layer(ZZ , hl_size , 16*K,'sign'+str(i))
S2.append(S2_temp)
S2[i]=(1-res_alpha)*S2[i]+res_alpha*S2[i-1]
S2[i] = tf.clip_by_value(S2[i],0,1)
V_temp = affine_layer(ZZ , hl_size , v_size,'aff'+str(i))
V.append(V_temp)
V[i]=(1-res_alpha)*V[i]+res_alpha*V[i-1]
S3 = tf.reshape(S2[i],[batch_size,K,16])
temp_0 = S3[:,:,0]
temp_1 = S3[:,:,1]
temp_2 = S3[:,:,2]
temp_3 = S3[:,:,3]
temp_4 = S3[:,:,4]
temp_5 = S3[:,:,5]
temp_6 = S3[:,:,6]
temp_7 = S3[:,:,7]
temp_8 = S3[:,:,8]
temp_9 = S3[:,:,9]
temp_10 = S3[:,:,10]
temp_11 = S3[:,:,11]
temp_12 = S3[:,:,12]
temp_13 = S3[:,:,13]
temp_14 = S3[:,:,14]
temp_15 = S3[:,:,15]
S1_real = -3.0*temp_0 +\
-3.0*temp_1 +\
-3.0*temp_2 +\
-3.0*temp_3 +\
-1.0*temp_4 +\
-1.0*temp_5 +\
-1.0*temp_6 +\
-1.0*temp_7 +\
1.0*temp_8 +\
1.0*temp_9 +\
1.0*temp_10 +\
1.0*temp_11 +\
3.0*temp_12 +\
3.0*temp_13 +\
3.0*temp_14 +\
3.0*temp_15
S1_im = -3.0*temp_0 +\
-1.0*temp_1 +\
1.0*temp_2 +\
3.0*temp_3 +\
-3.0*temp_4 +\
-1.0*temp_5 +\
1.0*temp_6 +\
3.0*temp_7 +\
-3.0*temp_8 +\
-1.0*temp_9 +\
1.0*temp_10 +\
3.0*temp_11 +\
-3.0*temp_12 +\
-1.0*temp_13 +\
1.0*temp_14 +\
3.0*temp_15
S1.append(tf.concat([S1_real, S1_im], 1))
S4_temp = tf.zeros([batch_size,K, 4, 2])
temp_0 = tf.expand_dims(temp_0,2)
temp_1 = tf.expand_dims(temp_1,2)
temp_2 = tf.expand_dims(temp_2,2)
temp_3 = tf.expand_dims(temp_3,2)
temp_4 = tf.expand_dims(temp_4,2)
temp_5 = tf.expand_dims(temp_5,2)
temp_6 = tf.expand_dims(temp_6,2)
temp_7 = tf.expand_dims(temp_7,2)
temp_8 = tf.expand_dims(temp_8,2)
temp_9 = tf.expand_dims(temp_9,2)
temp_10 = tf.expand_dims(temp_10,2)
temp_11 = tf.expand_dims(temp_11,2)
temp_12 = tf.expand_dims(temp_12,2)
temp_13 = tf.expand_dims(temp_13,2)
temp_14 = tf.expand_dims(temp_14,2)
temp_15 = tf.expand_dims(temp_15,2)
S4_temp1 = tf.concat([temp_0 + temp_1 + temp_2 + temp_3,temp_4 + temp_5 + temp_6 + temp_7,temp_8 + temp_9 + temp_10 + temp_11,temp_12 + temp_13 + temp_14 + temp_15],2)
S4_temp2 = tf.concat([temp_0 + temp_4 + temp_8 + temp_12,temp_1 + temp_5 + temp_9 + temp_13,temp_2 + temp_6 + temp_10 + temp_14,temp_3 + temp_7 + temp_11 + temp_15],2)
S4_temp1 = tf.expand_dims(S4_temp1,3)
S4_temp2 = tf.expand_dims(S4_temp2,3)
S4_temp3 = tf.concat([S4_temp1,S4_temp2],3)
S4.append(S4_temp3)
X_IND_reshaped = tf.reshape(X_IND,[batch_size,16*K])
if LOG_LOSS == 1:
LOSS.append(np.log(i)*tf.reduce_mean(tf.reduce_mean(tf.square(X_IND_reshaped - S2[-1]),1)))
else:
LOSS.append(tf.reduce_mean(tf.reduce_mean(tf.square(X_IND_reshaped - S2[-1]),1)))
BER.append(tf.reduce_mean(tf.cast(tf.not_equal(X_IND, tf.round(S3)), tf.float32)))
Max_Val = tf.reduce_max(S3,axis=2, keep_dims=True)
Greater = tf.greater_equal(S3,Max_Val)
BER2 = tf.round(tf.cast(Greater,tf.float32))
BER3 = tf.not_equal(BER2, X_IND)
BER4 = tf.reduce_sum(tf.cast(BER3,tf.float32),2)
BER5 = tf.cast(tf.greater(BER4,0),tf.float32)
SER = tf.reduce_mean(BER5)
TOTAL_LOSS=tf.add_n(LOSS)
saver = tf.train.Saver()
global_step1 = tf.Variable(0, trainable=False)
learning_rate1 = tf.train.exponential_decay(startingLearningRate1, global_step1, decay_step_size1, decay_factor1, staircase=True)
train_step1 = tf.train.AdamOptimizer(learning_rate1).minimize(TOTAL_LOSS)
global_step2 = tf.Variable(0, trainable=False)
learning_rate2 = tf.train.exponential_decay(startingLearningRate2, global_step2, decay_step_size2, decay_factor2, staircase=True)
train_step2 = tf.train.AdamOptimizer(learning_rate2).minimize(TOTAL_LOSS)
init_op=tf.initialize_all_variables()
sess.run(init_op)
for i in range(train_iter_no_noise): #num of train iter
batch_Y, batch_H, batch_HY, batch_HH, batch_X , SNR1, x_ind= generate_data(train_batch_size,K,N,snr_low,snr_high,0)
train_step1.run(feed_dict={HY: batch_HY, HH: batch_HH, X: batch_X ,X_IND: x_ind})
if i % 100== 0 :
sys.stderr.write(str(i)+' ')
batch_Y, batch_H, batch_HY, batch_HH, batch_X ,SNR1,x_ind= generate_data(train_batch_size,K,N,snr_low,snr_high,0)
results = sess.run([LOSS[L-1],SER], {HY: batch_HY, HH: batch_HH, X: batch_X,X_IND: x_ind})
print_string = [i]+results
print ' '.join('%s' % x for x in print_string)
for i in range(train_iter): #num of train iter
batch_Y, batch_H, batch_HY, batch_HH, batch_X , SNR1,x_ind= generate_data(train_batch_size,K,N,snr_low,snr_high,1)
train_step2.run(feed_dict={HY: batch_HY, HH: batch_HH, X: batch_X,X_IND: x_ind})
if i % 1000 == 0 :
sys.stderr.write(str(i)+ ' ')
batch_Y, batch_H, batch_HY, batch_HH, batch_X ,SNR1,x_ind= generate_data(train_batch_size,K,N,snr_low,snr_high,1)
results = sess.run([LOSS[L-1],SER], {HY: batch_HY, HH: batch_HH, X: batch_X,X_IND: x_ind})
print_string = [i]+results
print ' '.join('%s' % x for x in print_string)
#Testing the trained model
avg_val_error_last_layer = np.zeros((num_snr))
snrdb_list = np.linspace(snrdb_low_test,snrdb_high_test,num_snr)
snr_list = 10.0 ** (snrdb_list/10.0)
bers = np.zeros((1,num_snr))
times = np.zeros((1,num_snr))
tmp_bers = np.zeros((1,test_iter))
tmp_times = np.zeros((1,test_iter))
stat_distance = np.zeros((num_snr,2*K))
for j in range(num_snr):
new_dist_temp = np.zeros((2*K))
print('snr:')
print(snrdb_list[j])
for jj in range(test_iter):
if jj%100 == 0:
print('test iteration:')
print(jj)
batch_Y, batch_H, batch_HY, batch_HH, batch_X ,SNR1, BATCH_X_IND= generate_data(test_batch_size , K,N,snr_list[j],snr_list[j],1)
tic = tm.time()
tmp_bers[0,jj] = np.array(sess.run(SER, {HY: batch_HY, HH: batch_HH, X: batch_X, X_IND:BATCH_X_IND}))
toc = tm.time()
tmp_times[0][jj] = toc - tic
last_layer = np.array(sess.run(S4[-1], {HY: batch_HY, HH: batch_HH, X: batch_X, X_IND:BATCH_X_IND}))
last_layer = np.clip(last_layer, 0, 1)
for jjj in range(test_batch_size):
real_prob_one, real_prob_min_one ,real_prob_min_three,real_prob_three = validate2(batch_Y[jjj], SNR1[jjj], batch_H[jjj], 2*K, 2*N)
NN_lastLayer_minus3_Re = last_layer[jjj,:,0,0]
NN_lastLayer_minus3_Im = last_layer[jjj,:,0,1]
NN_lastLayer_minus1_Re = last_layer[jjj,:,1,0]
NN_lastLayer_minus1_Im = last_layer[jjj,:,1,1]
NN_lastLayer_1_Re = last_layer[jjj,:,2,0]
NN_lastLayer_1_Im = last_layer[jjj,:,2,1]
NN_lastLayer_3_Re = last_layer[jjj,:,3,0]
NN_lastLayer_3_Im = last_layer[jjj,:,3,1]
if normalize_dist:
Sum_Re = NN_lastLayer_minus3_Re + NN_lastLayer_minus1_Re + NN_lastLayer_1_Re + NN_lastLayer_3_Re
Sum_Im = NN_lastLayer_minus3_Im + NN_lastLayer_minus1_Im + NN_lastLayer_1_Im + NN_lastLayer_3_Im
NN_lastLayer_minus3_Re = NN_lastLayer_minus3_Re/Sum_Re
NN_lastLayer_minus1_Re = NN_lastLayer_minus1_Re/Sum_Re
NN_lastLayer_1_Re = NN_lastLayer_1_Re/Sum_Re
NN_lastLayer_3_Re = NN_lastLayer_3_Re/Sum_Re
NN_lastLayer_minus3_Im = NN_lastLayer_minus3_Im/Sum_Im
NN_lastLayer_minus1_Im = NN_lastLayer_minus1_Im/Sum_Im
NN_lastLayer_1_Im = NN_lastLayer_1_Im/Sum_Im
NN_lastLayer_3_Im = NN_lastLayer_3_Im/Sum_Im
NN_lastLayer_3 = np.concatenate([NN_lastLayer_3_Re,NN_lastLayer_3_Im],0)
NN_lastLayer_1 = np.concatenate([NN_lastLayer_1_Re,NN_lastLayer_1_Im],0)
NN_lastLayer_minus3 = np.concatenate([NN_lastLayer_minus3_Re,NN_lastLayer_minus3_Im],0)
NN_lastLayer_minus1 = np.concatenate([NN_lastLayer_minus1_Re,NN_lastLayer_minus1_Im],0)
new_dist_temp = new_dist_temp + np.absolute(NN_lastLayer_3 - real_prob_three) + np.absolute(NN_lastLayer_1 - real_prob_one) + np.absolute(NN_lastLayer_minus3 - real_prob_min_three) + np.absolute(NN_lastLayer_minus1 - real_prob_min_one)
stat_distance[j] = new_dist_temp/(test_batch_size*test_iter)
bers[:,j] = np.mean(tmp_bers,1)
times[:,j] = np.mean(tmp_times[0])/test_batch_size
print('snrdb_list')
print(snrdb_list)
print('bers')
print(bers)
print('times')
print(times)
print('stat_distance')
print(stat_distance)
save_path = saver.save(sess, "./DetNet_Soft_16QAM/16QAM_Soft_model.ckpt")