基于TensorFlow的信道感知深度学习模型
with tf.name_scope('channel_sensing'):
# 定义四个可训练的权重矩阵和偏置向量,初始化方式为he_init
A1 = tf.get_variable('A1', shape=[2*tau, 1024], dtype=tf.float32, initializer=he_init)
# tf.get_variable: 用于获取一个已存在的变量或者创建一个新的变量。
A2 = tf.get_variable('A2', shape=[1024, 1024], dtype=tf.float32, initializer=he_init)
A3 = tf.get_variable('A3', shape=[1024, 1024], dtype=tf.float32, initializer=he_init)
A4 = tf.get_variable('A4', shape=[1024, 2 * N], dtype=tf.float32, initializer=he_init)
b1 = tf.get_variable('b1', shape=[1024], dtype=tf.float32, initializer=he_init)
b2 = tf.get_variable('b2', shape=[1024], dtype=tf.float32, initializer=he_init)
b3 = tf.get_variable('b3', shape=[1024], dtype=tf.float32, initializer=he_init)
b4 = tf.get_variable('b4', shape=[2 * N], dtype=tf.float32, initializer=he_init)
# 初始化空列表用于存储权重、后验概率和估计索引
w_dict = []
posterior_dict = []
idx_est_dict = []
# 计算信噪比(SNR)并进行归一化处理
snr = lay['P'] * tf.ones(shape=[batch_size, 1], dtype=tf.float32)
snr_dB = tf.log(snr) / np.log(10)
snr_normal = (snr_dB + 0.5) / np.sqrt(0.75) # Normalizing for the range -10dB to 30dB
W_uplink_np = np.random.normal(size=(1,tau, N), loc=0,scale=np.sqrt(0.5))+1j*np.random.normal(size=(1,tau, N), loc=0,scale=np.sqrt(0.5))
W_uplink_np = W_uplink_np/np.linalg.norm(W_uplink_np,axis=-1,keepdims=True)
W_uplink = tf.get_variable('W_uplink', dtype=tf.complex64, initializer=W_uplink_np.astype(np.complex64), trainable=False)
y_noiseless = W_uplink @ tf.reshape(a_phi,(-1,N,1))
noise = tf.complex(tf.random_normal(tf.shape(y_noiseless), mean=0.0, stddev=noiseSTD_per_dim), \
tf.random_normal(tf.shape(y_noiseless), mean=0.0, stddev=noiseSTD_per_dim))
y_complex = tf.complex(tf.sqrt(lay['P']), 0.0) * y_noiseless + noise
y_real = tf.concat([tf.real(y_complex), tf.imag(y_complex)], axis=1) / tf.sqrt(lay['P'])
y_real = tf.reshape(y_real,(-1,tau*2))
x1 = tf.nn.relu(y_real @ A1 + b1)
x1 = BatchNormalization()(x1)
x2 = tf.nn.relu(x1 @ A2 + b2)
x2 = BatchNormalization()(x2)
x3 = tf.nn.relu(x2 @ A3 + b3)
x3 = BatchNormalization()(x3)
w_her_data = x3 @ A4 + b4
w_norm_data = tf.reshape(tf.norm(w_her_data, axis=1), (-1, 1))
w_her_data = tf.divide(w_her_data, w_norm_data)
w_her_complex_data = tf.complex(w_her_data[:, 0:N], w_her_data[:, N:2 * N])
y_noiseless_data = tf.reduce_sum(tf.multiply(w_her_complex_data, a_phi), 1, keepdims=True)
bf_gain = tf.reduce_mean(tf.abs(y_noiseless_data)**2,axis=0)
原文地址: https://www.cveoy.top/t/topic/BD5 著作权归作者所有。请勿转载和采集!