- Thu 02 November 2017
- Machine-Learning
- #ML
- en

It has now been accepted as common wisdom that Generative Adversarial Networks (GAN) minimise the Jensen divergence between the real data distribution and the generated one (Goodfellow et al, 2014). In this article I'm going to study a little more closely the interpretation of these losses in terms of minimization of divergences.

## Recap of the GAN game

The original GAN game can be described by the following fomula, where \(D(x)\) is the discriminator model, \(\mathcal{P}(x)\) is the real data discribution, and \(\mathcal{Q}(x)\) is the generated data distribution (note that we are not making any assumption about how \(D\) and \(\mathcal{Q}\) are computed):

From this we can prove that the first step (maximizing over \(D\)) is solved by:

Plugging this solution back into the original equation, solving for \(\mathcal{Q}\) then comes to:

Which we can reformulate as

Or

And from this, like Goodfellow et al, 2014, we can conclude that the GAN game does indeed minimize the Jensen divergence between \(\mathcal{P}\) and \(\mathcal{Q}\).

## The devil is in the details

If we want to implement this with a parametric generative model for \(\mathcal{Q}\), say we have a \(\mathcal{Q}_{\theta}\), and want to train this by gradient descent.

For example, this \(\mathcal{Q}_{\theta}\) could be implemented using a neural network \(G_{\theta}(z)\): \(\mathcal{Q}_{\theta}(\hat{x})\) would then be the density distribution of the generated samples \(\hat{x} = G_{\theta}(z)\) with \(z\) sampled from some prior \(\rho(z)\).

Let's assume further that we manage to create this optimal discriminator in a way that makes it helpful to train a generator without vanishing the gradients (which as we know is actually one of the biggest challenges of GANs, as detailed by Arjovsky et al, 2017):

Note here that this optimal discriminator depends on \(\mathcal{Q}_{\theta}\), and thus on \(\theta\), the parameters of our generator model.

We now have to minimize the following loss to train our generator:

This loss seems very familiar, it is the loss used to train the generator network in a GAN. Except, when actually training the network, we drop the first term, and optimize the following loss:

We have very good reasons for doing so: mostly the first term's gradient relative to \(\theta\) is not really computable, as it would require backpropagating through the whole training process of the discriminator.

We also have bad reasons for doing so: implicitly assuming that this term does not depend on \(\theta\) and that its gradient is thus \(0\).

In both cases, as a result we are not actually training our generator to minimize the Jensen divergence any more but rather the following divergence:

With half of the Jensen divergence missing, we end up half way between \(\operatorname{JSD}\left[\mathcal{Q}_{\theta}\|\mathcal{P}\right]\) and \(\operatorname{D}_{KL}\left[\mathcal{Q}_{\theta}\|\mathcal{P}\right]\). This may explain some of the observed dynamics of GANs: this \(\widetilde{\mathcal{L}}\) loss is more forgiving than the Jensen divergence regarding mode dropping (it's the \(\operatorname{D}_{KL}\left[\mathcal{P} \middle\| \frac{\mathcal{P}+\mathcal{Q}_{\theta}}{2}\right]\) half of the Jensen divergence that becomes big if \(\mathcal{Q}(x)=0\) while \(\mathcal{P}(x) > 0\), not the one we've kept).

## Playing with the generator's loss

Other losses for the generator can be considered, depending on the properties and dynamics we want:

- The alternative already suggested by Goodfellow et al, 2014 of using

which tends to provide better gradients to the generator, but does not clearly express a divergence. Though, by doing the same work with \(D^{\star}_{\theta}\) as before, we can re-express it like this:

And using the convexity of the Kullback-Leibler divergence, we can show that \(\operatorname{D}_{KL}\left[\mathcal{Q}_{\theta} \middle\| \frac{\mathcal{P}+\mathcal{Q}_{\theta}}{2}\right] \leq \frac{1}{2} \operatorname{D}_{KL}\left[\mathcal{Q}_{\theta} \middle\| \mathcal{P} \right]\), and thus:

which is much less forgiving than the original \(\widetilde{\mathcal{L}}\) regarding the generation on non-realistic samples, and might explain why it gives better gradients to the generator.

- An other alternative suggested by Ferenc Huszár on an article on his blog:

which is then equivalent to the KL divergence: \(\widetilde{\mathcal{L}_3}(\theta) = \operatorname{D}_{KL}\left[\mathcal{Q}_{\theta}\middle\|\mathcal{P}\right]\), so possibly a better version of the previous one.