为什么许多实现中变分自编码器的损失与论文的符号相反?

Why the loss of Variational Autoencoder in many implementations have opposite sign from paper?

我想我看懂了Auto-Encoding Variational Bayes那篇论文。我正在阅读一些实现本文的张量流代码。但是我不明白他们在那些代码中的损失函数。由于很多代码都是以相同的方式编写的,所以我可能错了。

问题是这样的。以下等式来自AEVB paper 损失函数就像这个等式。这个方程可以分为两个:Regularization term和Reconstruction term。因此,就变成了

Loss_function = Regularization_term + Reconstruction_term

然而,很多代码以负号实现这个正则化项,比如

Loss_function = -Regularization_term + Reconstruction_term 

例如,在this code中,第79行显示正则化项为

KLD = -.5 * tf.reduce_sum(1. + enc_logsd - tf.pow(enc_mu, 2) - tf.exp(enc_logsd), reduction_indices=1)

然后,它只是增加了重建术语。

loss = tf.reduce_mean(KLD + BCE)

我不明白。 KLD 的符号与论文中的等式相反。有很多这样的代码。我想我错了,但我不知道错在哪里。你能解释一下为什么会这样吗?

参考代码:code1, code2, code3

等式(10)是我们想要最大化的对数似然损失。它等效于最小化负对数似然 (NLL)。这就是优化函数在实践中所做的。请注意 Reconstruction_term 已在 tf.nn.sigmoid_cross_entropy_with_logits 中取反(参见 https://github.com/tegg89/VAE-Tensorflow/blob/master/model.py#L96)。我们还需要否定 Regularization_term

所以代码实现了Loss_function = -Regularization_term + -Reconstruction_term.