-
Notifications
You must be signed in to change notification settings - Fork 0
/
b_Generate_Data.py
106 lines (83 loc) · 3.3 KB
/
b_Generate_Data.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
from cvxpy import *
import scipy as sp
import ecos
#import matplotlib.pyplot as plt
import time
import func_oht_alg as func_oht
# sp.random.seed(2035)
# ############################################################
# This code is loaded from Full_code_TH
# ############################################################
# Starting main code for EEmax UAV networks
# ############################################################
bandwidth = 1 # MHz
height = 100 # m
eta = 0.5 # EH efficiency
power_UAV = 5000
power_cir_UAV = 4000
atg_a = 11.95
atg_b = 0.136
noise_variance = sp.multiply(sp.multiply(sp.power(10, sp.divide(-130, 10)), bandwidth), 1e6)
d2d_max = 50
max_chan_realizaion = 10000
chan_model = sp.load('x_chan_model_train.npz')
max_uav_to_d2d_gains = chan_model['uav']
max_d2d_to_d2d_gains = chan_model['d2d']
num_d2d_pairs = 10
dimen_input = num_d2d_pairs + num_d2d_pairs*num_d2d_pairs
maximin_rate_sol_Mon = []
EE_sol_vec_Mon = []
tau_sol_vec_Mon = []
vec_chan = []
avg = {}
t0 = time.time()
num_infeasible = 0
# rmin = sp.multiply(0.2, sp.log(2))
print "building training dataset ..."
#time_sol = []
EE_sol = []
tau_sol = []
maximin_rate = []
for Mon in xrange(max_chan_realizaion):
try:
max_d2d_to_d2d_gains_diff = sp.copy(max_d2d_to_d2d_gains[:, :, Mon])
sp.fill_diagonal(max_d2d_to_d2d_gains_diff, 0)
max_d2d_to_d2d_gains_diag = sp.subtract(max_d2d_to_d2d_gains[:, :, Mon], max_d2d_to_d2d_gains_diff)
uav_to_d2d_gains = max_uav_to_d2d_gains[:num_d2d_pairs, Mon]
d2d_to_d2d_gains = max_d2d_to_d2d_gains[:num_d2d_pairs, :num_d2d_pairs, Mon]
d2d_to_d2d_gains_diff = max_d2d_to_d2d_gains_diff[:num_d2d_pairs, :num_d2d_pairs]
d2d_to_d2d_gains_diag = sp.subtract(d2d_to_d2d_gains, d2d_to_d2d_gains_diff)
# vectorize channel training
trained_chan = sp.zeros(dimen_input)
trained_chan[0:num_d2d_pairs] = uav_to_d2d_gains
trained_chan[num_d2d_pairs:dimen_input] = d2d_to_d2d_gains.ravel()
vec_chan.append(trained_chan)
# maximin sum-rate algorithm
iter_EE, theta_sol, iter_maximin_rate = func_oht.oht_alg(d2d_to_d2d_gains_diag, uav_to_d2d_gains, d2d_to_d2d_gains_diff, eta, power_UAV, power_cir_UAV)
EE_sol.append(iter_EE)
tau_sol.append(1 - 1/theta_sol)
maximin_rate.append(iter_maximin_rate)
except (SolverError, TypeError):
# pass
num_infeasible += 1
# Calculate the total time of training datdaset
time_sol = (time.time() - t0)
v1 = sp.array(EE_sol)
EE_sol_vec_Mon.append(sp.mean(v1))
v2 = sp.array(maximin_rate)
maximin_rate_sol_Mon.append(sp.mean(v2))
v3 = sp.array(tau_sol)
tau_sol_vec_Mon.append(sp.mean(v3))
vec_chan_training = sp.array(vec_chan)
vec_tau_training = sp.array(tau_sol)
print EE_sol
print tau_sol
print maximin_rate
print "Time for generate training dataset:", time_sol, "seconds"
print "Number of infeasible solving", num_infeasible
print "Size of vec_chan_training", sp.shape(vec_chan_training)
print "Size of vec_tau_training", sp.shape(vec_tau_training)
# test_vec_chan_training = vec_chan_training[1][1]
# Saving training dataset for DNN model
sp.savez('x_OHT_dataset', chan_dataset=vec_chan_training, tau_dataset=vec_tau_training)
print "Done. Saved"