我的网络架构如下:
def net_one(message):
weight1 = np.random.normal(loc=0.0, scale=0.01, size=[16, 16])
init1 = tf.constant_initializer(weight1)
out1 = tf.layers.dense(inputs=message, units=16, activation=tf.nn.relu, kernel_initializer=init1)
weight2 = np.random.normal(loc=0.0, scale=0.01, size=[16, 7])
init2 = tf.constant_initializer(weight2)
out2 = tf.layers.dense(inputs=out1, units=7, activation=None, kernel_initializer=init2)
return out2
现在由于网络的输出是线性的(None在 tensorflow 中对应于线性激活函数),因此输出是无界的。我需要输出的平方2-norm是一个常数,n(出于能量约束的目的)。我不想使用sigmoid或tanh因为它们妨碍性能。我尝试了以下方法:
code = net_one(input_bits)
code = code * tf.sqrt(n) / tf.linalg.norm(code)
我有两个问题:
- 它是否达到了我期望它达到的效果?
- 有没有更好的方法(如果这确实是正确的)或任何替代方法来实现这一点?