I was trying to understand the loss function of GANs, while I found a little mis-match between different papers.

This is the screen-shot from the original paper of Goodfellow at https://arxiv.org/pdf/1406.2661.pdf: Goodfellow,

And equation (1) in this version of pix2pix paper at https://arxiv.org/pdf/1611.07004.pdf enter image description here

Putting aside the fact that pix2pix is using conditional GAN, which introduces a second term $y$, the 2 formulas are quite resemble, except that in the pix2pix paper, they try to get minimax of ${\cal{L}}_{cGAN}(G, D)$, which is defined to be $E_{x,y}[...] + E_{x,z}[...]$, whereas in the original paper, they define $\min\max V(G, D) = E[...] + E[...]$.

I am not coming from a good math background, so I am quite confused. I'm not sure where the mistake is, but assuming that $E$ is expectation (correct me if I'm wrong), the version in pix2pix makes more sense to me, although I think it's quite less likely that Goodfellow could make this mistake in his amazing paper. Maybe there's no mistake at all and it's me who do not understand them correctly.


What is meant by both papers is that we have two agents (generator and discriminator) playing a game with the value function V defined as a sum of the expectations (i.e. an expectation of the outcome value defined as a sum of two terms, or actually a logarithm of a product...). The generator uses a strategy G encoded in the parameters of its neural network (θg), the discriminator uses a strategy D encoded in the parameters of its neural network (θd). Our goal is to (hopefully) find such a pair of strategies (a pair of parameter sets θgmin and θdmax) that produce the minimax value.

While trying to find the (θgmin, θdmax) pair using gradient descent, we actually have two loss functions: one is the loss function for G, parameterized by θg, another is the loss function for D, parameterized by θd, and we train them alternatively on minibatches together.

If you look at the Algorithm 1 in the original paper, the loss function for the discriminator is -log(D(x; θd)) - log(1 - D(G(z); θd), and the loss function for the generator is log(1 - D(G(z; θg)) (in both cases, in the original paper, x is sampled from the reference data distribution and z is sampled from noise):

The ideal value for the loss function of the discriminator is 0, otherwise it's greater than 0. The "loss" function of the generator is actually negative, but, for better gradient descent behavior, can be replaced with -log(D(G(z; θg)), which also has the ideal value for the generator at 0. It is impossible to reach zero loss for both generator and discriminator in the same GAN at the same time. However, the idea of the GAN is not to reach zero loss for any of the game agents (this is actually counterproductive), but to use that "double gradient descent" to "converge" the distribution of G(z) to the distribution of x.

  • $\begingroup$ Thanks for your reply. Yet, I am more concerned of the whole equations themselves. The pix2pix paper wants to minimize the expectation while the GAN paper shows that the expectation is the result of the minimization. $\endgroup$
    – AugLe
    Jan 15 '19 at 10:05
  • $\begingroup$ Yes, and they are different that one is defined to be the min of max of expectation (pix2pix) while the other is defined as the min of max of value function (GAN paper). Does that make sense? $\endgroup$
    – AugLe
    Jan 15 '19 at 10:37
  • 1
    $\begingroup$ So let me rephrase the question like this: what is the target function to be optimize for a general GAN? In the GAN paper, Goodfellow uses $V(D, G)$, but what is $V(D, G)$ exactly? Is it $V(D,G) = E(\log(D(y)) + E(1-\log(D(G(x, z))$ $\endgroup$
    – AugLe
    Jan 17 '19 at 11:04
  • $\begingroup$ @AugLe Edited again. Hopefully now it's clearer what is actually optimized in GANs. $\endgroup$
    – Kit.
    Jan 17 '19 at 20:39

The question is about a mismatch between the loss function in two papers on GANs. The first paper is Generative Adversarial Nets Ian J. Goodfellow et. al., 2014, and the excerpt image in the question is this.

The adversarial modeling framework is most straightforward to apply when the models are both multilayer perceptrons. To learn the generator’s distribution $p_g$ over data $x$, we define a prior on input noise variables $p_z (z)$, then represent a mapping to data space as $G (z; \theta_g)$, where $G$ is a differentiable function represented by a multilayer perceptron with parameters $\theta_g$. We also define a second multilayer perceptron $D (x; \theta_d)$ that outputs a single scalar. $D (x)$ represents the probability that $x$ came from the data rather than pg. We train $D$ to maximize the probability of assigning the correct label to both training examples and samples from $G$. We simultaneously train $G$ to minimize $\log (1 − D(G(z)))$:

In other words, $D$ and $G$ play the following two-player minimax game with value function $V (G, D)$:

$$ \min_G \, \max_D V (D, G) = \mathbb{E}_{x∼p_{data}(x)} \, [\log \, D(x)] \\ \quad\quad\quad\quad\quad\quad\quad + \, \mathbb{E}_{z∼p_z(z)} \, [\log \, (1 − D(G(z)))] \, \text{.} \quad \text{(1)} $$

The second paper is Image-to-Image Translation with Conditional Adversarial Networks, Phillip Isola Jun-Yan Zhu Tinghui Zhou Alexei A. Efros, 2018, and the excerpt image in the question is this.

The objective of a conditional GAN can be expressed as

$$ \mathcal{L}_{cGAN} (G, D) = \mathbb{E}_{x, y} \, [\log D(x, y)] \\ \quad\quad\quad\quad\quad\quad\quad + \mathbb{E}_{x, z} \, [\log \, (1 − D(x, G(x, z))], \quad \text{(1)} $$

where $G$ tries to minimize this objective against an adversarial $D$ that tries to maximize it, i.e.

$$ G^{∗} = \arg \, \min_G \, \max_D \mathcal{L}_{cGAN} (G, D) \, \text{.} $$

To test the importance of conditioning the discriminator, we also compare to an unconditional variant in which the discriminator does not observe $x$:

$$ \mathcal{L}_{GAN} (G, D) = \mathbb{E}_y \, [\log \, D(y)] \\ \quad\quad\quad\quad\quad\quad\quad + \mathbb{E}_{x, z} \, [\log \, (1 − D(G(x, z))] \, \text{.} \quad \text{(2)} $$

In the above $G$ refers to the generative network, $D$ refers to the discriminative network, and $G^{*}$ refers to the minimum with respect to $G$ of the maximum with respect to $D$. As the question author tentatively put forward, $\mathbb{E}$ is the expectation with respect to its subscripts.

The question of discrepancy is that the right hand sides do not match between the first paper's equation (1) and the second paper's equation (2) which is absent of the condition involving $y$.

First paper:

$$ \mathbb{E}_{x∼p_{data}(x)} \, [\log \, D(x)] \\ \quad\quad\quad\quad\quad\quad\quad + \, \mathbb{E}_{z∼p_z(z)} \, [\log \, (1 − D(G(z)))] \, \text{.} \quad \text{(1)} $$

Second paper:

$$ \mathbb{E}_y \, [\log \, D(y)] \\ \quad\quad\quad\quad\quad\quad\quad + \mathbb{E}_{x, z} \, [\log \, (1 − D(G(x, z))] \, \text{.} \quad \text{(2)} $$

The second later paper further states this.

GANs are generative models that learn a mapping from random noise vector $z$ to output image $y, G : z \rightarrow y$. In contrast, conditional GANs learn a mapping from observed image $x$ and random noise vector $z$, to $y, G : {x, z} \rightarrow y$.

Notice that there is no $y$ in the first paper and the removal of the condition in the second paper corresponds to the removal of $x$ as the first parameter of $D$. This is one of the causes of confusion when comparing the right hand sides. The others are use of variables and degree of explicitness in notation.

The tilda $~$ means drawn according to. The right hand side in the first paper indicates that the expectation involving $x$ is based on a drawing according to the probability distribution of the data with respect to $x$ and the expectation involving $z$ is based on a drawing according to the probability distribution of $z$ with respect to $z$.

The removal of the observation of $x$ from the second right hand term of the second paper's equation (2), which is the first parameter of $G$, the replacement of that equation's $y$ variable with the now freed up $x$ variable, and the acceptance of the abbreviation of the tilda notation used in the first paper then brings both papers into exact agreement.

  • $\begingroup$ Thank you for your reply and sorry for the late response. Regarding this paragraph: "The question of discrepancy is that the right hand sides do not match between the first paper's equation (1) and the second paper's equation (2) which is absent of the condition involving 𝑦." No, it is not what confuses me. The question of discrepancy is the mismatch of the left hand sides of the 2 papers: the first paper defines the Expectations to be the results of the min-max operation, where as the second paper suggests to take the min-max of the Expections. $\endgroup$
    – AugLe
    Feb 25 '19 at 10:39

I'm not sure I understand your question. However responding to your question in the comments. The difference between the two objectives is that:

In an ordinary GAN, we want to push $p(G)$ to be as close as possible to $p(data)$

In a conditional GAN, we have a context $c$. If we imagine for ease of understanding that $c=[1,2,3]$ is a discrete variable where all the data can be categorised under one of these c values , then we want to: push $p(G|c=1)$ as close as possible to $p(data|c=1)$ push $p(G|c=2)$ as close as possible to $p(data|c=2)$ push $p(G|c=3)$ as close as possible to $p(data|c=3)$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.