Answers.Body: <p>I think I understand what's happening with the loss functions now.</p>
  <p>Notation:</p>
  <ul>
  <li>D = discriminator/critic</li>
  <li>G = generator</li>
  <li>D(x) - Critic score on real data</li>
  <li>D(G(z)) - Critic score on fake data</li>
  <li>∇_D - Critic loss gradients</li>
  <li>D_p - Critic parameters</li>
  <li>∇_G - Generator loss gradients</li>
  <li>G_p - Generator parameters</li>
  </ul>
  <p>The loss for D essentially is as follows:
  <a href="https://i.sstatic.net/1DIa1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1DIa1.png" alt="enter image description here" /></a></p>
  <ul>
  <li>In this case, D wants to maximize this loss (as the + indicates in the second line above). This means that D wants to make the difference as large as possible. How can it do this?
  <ul>
  <li>If D(x) is as high as possible and D(G(z)) is as low as possible, then the loss will be as high as possible.</li>
  <li>D is effectively maximizing its score on real data (D(x))</li>
  <li>D is also minimizing its score on fake data (D(G(z))) or maximizing its score on the flipped score on the fake data (-D(G(z)))</li>
  </ul>
  </li>
  <li>So, D wants a high score for real data and a low score for fake data</li>
  </ul>
  <p>The loss for G is as follows:
  <a href="https://i.sstatic.net/WYay2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WYay2.png" alt="enter image description here" /></a></p>
  <ul>
  <li>In this case, G wants to minimize its loss which is -D(G(z)). This means that G wants to make the opposite of the discriminator score as low as possible. Let me break this down as it confused me a lot at first.
  <ul>
  <li>Since the loss is negative, the score is basically flipped.</li>
  <li>Due to the flipped score, if D gives a positive value meaning it thinks the data is real, then the loss will be negative which G wants.</li>
  <li>If D gives a negative value meaning it thinks the data is fake, then the loss will be positive which G does not want.</li>
  </ul>
  </li>
  <li>Due to the double negative, this loss basically means G wants to maximize the output of the discriminator on fake data, which makes sense.</li>
  </ul>
  <p>With all this in mind, I would expect the graph to look something like the following:
  <a href="https://i.sstatic.net/Wt3fm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Wt3fm.png" alt="enter image description here" /></a></p>
  <ul>
  <li>D_real [maximizing D(x)] - The critic wants to produce an output that's as high as possible on real data. So, I would expect this value to be a high positive value.</li>
  <li>D_fake [maximizing -D(G(z))] - The critic wants to produce an output that's as low as possible on fake data. So, I would expect this value to be as high as possible. Note, I would expect D(G(z)) to be as low as possible, but due to the negative, I would expect this value to be pretty high.</li>
  <li>G [minimizing -D(G(z))] - The generator wants the critic to produce an output that's as high as possible. But, if you look at the loss function, you will notice the generator loss is the exact same as the discriminator loss's second term (the difference is the discriminator is maximizing its term while the generator is minimizing its term). With this in mind, I would expect the value to almost be exactly the same as D_fake (with little variation due to gradient updates).</li>
  <li>D - The critic wants to make its loss as high as possible, so I would expect this curve to be much higher than the rest due to it being the sum of two positive values, D_real and D_fake where D_fake is equal to G.</li>
  <li>So, D_fake should be fighting to make its loss higher (effectively minimizing D(G(z))) while G should be fighting to make its loss smaller (effectively maximizing D(G(z)))</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-25T03:14:15.543Z
Answers.LastActivityDate: 2022-06-25T03:48:32.117Z
Answers.LastEditDate: 2022-06-25T03:48:32.117Z
Answers.UserDisplayName: Gabriel Mongaras
Body: <p>I am kind of new to the field of GANs and decided to develop a WGAN. All of the information online seems to be kind of contradicting itself. The more I read, the more I become confused, so I'm hoping y'all can clarify my misunderstanding with WGAN loss.</p>
  <p>Critic loss function:
  <a href="https://i.sstatic.net/lxKWj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lxKWj.png" alt="enter image description here" /></a></p>
  <p>Generator loss function:<br />
  <a href="https://i.sstatic.net/a6agf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/a6agf.png" alt="enter image description here" /></a></p>
  <p>g_w are the parameters for the critic and g_θ are the parameters for the generator</p>
  <p>From my understanding, the loss functions show that:</p>
  <ul>
  <li>The critic wants to minimize its loss. Splitting the loss function up, this means it wants to:
  <ul>
  <li>minimize its score on real data</li>
  <li>maximize its score on fake data</li>
  </ul>
  </li>
  <li>The generator wants to maximize the critic score on fake data. So it wants to make the data it generates seem more fake to the critic?</li>
  </ul>
  <p>Since the critic gives a high score to fake data and a low score to real data, why would the generator want to maximize its score? Wouldn't that mean the generator wants to make its data appear more &quot;fake&quot; to the critic? I would think the generator would want to minimize its loss to make it look more real (since real data has a low score)</p>
  
Tags: <generative-adversarial-networks><loss><wasserstein-gan>
Title: What is being optimized with WGAN loss? Is the generator maximizing or minimizing the critic value?
UserDisplayName: Gabriel Mongaras
ThreadText: # What is being optimized with WGAN loss? Is the generator maximizing or minimizing the critic value?
  
  (Asked by: username_0 on 2022-06-24)
  
  I am kind of new to the field of GANs and decided to develop a WGAN. All of the information online seems to be kind of contradicting itself. The more I read, the more I become confused, so I'm hoping y'all can clarify my misunderstanding with WGAN loss.
  
  Critic loss function:
  [![enter image description here](https://i.sstatic.net/lxKWj.png)](https://i.sstatic.net/lxKWj.png)
  
  Generator loss function:  
  [![enter image description here](https://i.sstatic.net/a6agf.png)](https://i.sstatic.net/a6agf.png)
  
  g\_w are the parameters for the critic and g\_θ are the parameters for the generator
  
  From my understanding, the loss functions show that:
  
  * The critic wants to minimize its loss. Splitting the loss function up, this means it wants to:
    + minimize its score on real data
    + maximize its score on fake data
  * The generator wants to maximize the critic score on fake data. So it wants to make the data it generates seem more fake to the critic?
  
  Since the critic gives a high score to fake data and a low score to real data, why would the generator want to maximize its score? Wouldn't that mean the generator wants to make its data appear more "fake" to the critic? I would think the generator would want to minimize its loss to make it look more real (since real data has a low score)
  
  **Tags:** generative-adversarial-networks, loss, wasserstein-gan
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-06-25. Score: 1
  
  I think I understand what's happening with the loss functions now.
  
  Notation:
  
  * D = discriminator/critic
  * G = generator
  * D(x) - Critic score on real data
  * D(G(z)) - Critic score on fake data
  * ∇\_D - Critic loss gradients
  * D\_p - Critic parameters
  * ∇\_G - Generator loss gradients
  * G\_p - Generator parameters
  
  The loss for D essentially is as follows:
  [![enter image description here](https://i.sstatic.net/1DIa1.png)](https://i.sstatic.net/1DIa1.png)
  
  * In this case, D wants to maximize this loss (as the + indicates in the second line above). This means that D wants to make the difference as large as possible. How can it do this?
    + If D(x) is as high as possible and D(G(z)) is as low as possible, then the loss will be as high as possible.
    + D is effectively maximizing its score on real data (D(x))
    + D is also minimizing its score on fake data (D(G(z))) or maximizing its score on the flipped score on the fake data (-D(G(z)))
  * So, D wants a high score for real data and a low score for fake data
  
  The loss for G is as follows:
  [![enter image description here](https://i.sstatic.net/WYay2.png)](https://i.sstatic.net/WYay2.png)
  
  * In this case, G wants to minimize its loss which is -D(G(z)). This means that G wants to make the opposite of the discriminator score as low as possible. Let me break this down as it confused me a lot at first.
    + Since the loss is negative, the score is basically flipped.
    + Due to the flipped score, if D gives a positive value meaning it thinks the data is real, then the loss will be negative which G wants.
    + If D gives a negative value meaning it thinks the data is fake, then the loss will be positive which G does not want.
  * Due to the double negative, this loss basically means G wants to maximize the output of the discriminator on fake data, which makes sense.
  
  With all this in mind, I would expect the graph to look something like the following:
  [![enter image description here](https://i.sstatic.net/Wt3fm.png)](https://i.sstatic.net/Wt3fm.png)
  
  * D\_real [maximizing D(x)] - The critic wants to produce an output that's as high as possible on real data. So, I would expect this value to be a high positive value.
  * D\_fake [maximizing -D(G(z))] - The critic wants to produce an output that's as low as possible on fake data. So, I would expect this value to be as high as possible. Note, I would expect D(G(z)) to be as low as possible, but due to the negative, I would expect this value to be pretty high.
  * G [minimizing -D(G(z))] - The generator wants the critic to produce an output that's as high as possible. But, if you look at the loss function, you will notice the generator loss is the exact same as the discriminator loss's second term (the difference is the discriminator is maximizing its term while the generator is minimizing its term). With this in mind, I would expect the value to almost be exactly the same as D\_fake (with little variation due to gradient updates).
  * D - The critic wants to make its loss as high as possible, so I would expect this curve to be much higher than the rest due to it being the sum of two positive values, D\_real and D\_fake where D\_fake is equal to G.
  * So, D\_fake should be fighting to make its loss higher (effectively minimizing D(G(z))) while G should be fighting to make its loss smaller (effectively maximizing D(G(z)))
  
  
  ---
  
  