TianLin0509/BF-design-with-DL

How to understand the loss function?

Opened this issue · 2 comments

Thank you very much for sharing the code! Would you mind answering a question?

I don't understand the
loss
Could you explain the difference between this way and traditional way such as mse? please!

As mentioned in this paper, we propose a self-defined loss function without requiring labels. However, in the keras framework, the default format of loss function is that:

define my_loss(y_true, y_pred):
       pass

y_true denotes the label, and y_pred denotes the output of the NN.

However, in my program, our loss function should not be written in such way. (y_true is not needed).
In many previous work, they have same problems. A well-used solution is that:

compute the real loss by a Lambda layer, and then use a simple Lambda function: lambda x,y:y as the loss function, so that the self-defined loss function will be the loss, and the NN will work. (the loss function, i.e., the simple lambda function, return the loss computed by the Lambda layer, and the y_true, is not returned or used).

In conclusion, due to the limited flexibility of keras, I use this method to achieve the same result. Also, 'y=H' makes no sense (because we not need label) and only avoids running error of keras.

就是我们需要在keras中自定义损失函数(本文的损失函数不是任何一种深度学习常见的损失函数),且不需要标签。 因此,我定义了一个Lambda层来计算真正的损失函数,并将之作为输出。 Keras默认的损失函数是接受标签和网络输出为参数,计算loss。 由于我们的输出本身就是我们想要的loss,因此只需要直接用lambda函数,扔掉标签,保留网络输出即可(真正想要的损失函数)。 属于在keras框架下的权宜变通。 fit函数中的y=H没有任何意义,这里的y只需要扔进一个维度一致避免keras自动检查报错的值就行了,因此方便起见扔入了H, 事实上H并不会被用到。

您好 我有个问题想请教下

For the simplification of implementation based on Keras, we use a lambda layer to compute the rate

Thus, the output of the model is actually the loss.

def Rate_func(temp):
h, v, SNR_input = temp
hv = backend.batch_dot(
tf.cast(h, tf.complex64), tf.transpose(a=v, perm=[1, 0]))
rate = tf.math.log(tf.cast(1 + SNR_input / Nt * tf.pow(tf.abs(hv), 2), tf.float32)) / tf.math.log(2.0)
return -rate
这里返回的 -rate就是 您论文里的 loss对吧 这一行里 rate = tf.math.log(tf.cast(1 + SNR_input / Nt * tf.pow(tf.abs(hv), 2), tf.float32)) / tf.math.log(2.0) 为什么最后又要除一个 lg(2.0)呢