Answers.Body: <p>I'll answer your questions one by one:</p>
  
  <blockquote>
    <p>In this equation are the <span class="math-container">$E_{z \sim p_z(z)}$</span> and <span class="math-container">$E_{x \sim p_{data}(x)}$</span> the means of the distributions of the mini batch samples?</p>
  </blockquote>
  
  <p>So let's take the first part <span class="math-container">$E_{x \sim p_{data}(x)}[log \,D(x)]$</span>. This is read as the "expected value of <span class="math-container">$log \, D(x)$</span>, where <span class="math-container">$x$</span> is sampled from <span class="math-container">$p_{data}(x)$</span>". So, in simpler terms this means that:</p>
  
  <ul>
  <li>You have a distribution <span class="math-container">$p_{data}(x)$</span>.</li>
  <li>You sample a batch of samples <span class="math-container">$x$</span> from this distribution.</li>
  <li>You feed the batch to the discriminator and get its output <span class="math-container">$D(x)$</span>.</li>
  <li>You compute the log for the batch of predictions.</li>
  <li>You average over the samples in the batch.</li>
  </ul>
  
  <blockquote>
    <p>Also is the optimal case for the discriminator a maximum value of 0?</p>
  </blockquote>
  
  <p>Yes, the goal of the discriminator is to <strong>maximize</strong> <span class="math-container">$V(D, G)$</span>. This is achieved when <span class="math-container">$D(x) = 1$</span> and <span class="math-container">$D(z) = 0$</span>, where <span class="math-container">$V(D, G)=0$</span>.</p>
  
  <blockquote>
    <p>the optimal case for the generator a minimum value of log(small value) {basically a massive negative value}?</p>
  </blockquote>
  
  <p>Yes, the generator wants to <strong>minimize</strong> <span class="math-container">$V(D, G)$</span>, so it wants <span class="math-container">$D(x)$</span> and <span class="math-container">$D(z)$</span> to be as small as possible (though it can affect only the second term). The minimum value for <span class="math-container">$D(z)$</span> is <span class="math-container">$1 / M$</span>, where <span class="math-container">$M$</span> is the number of classes in the dataset. So the minimum value for <span class="math-container">$V(D, G)$</span> is <span class="math-container">$\log{[(M-1) / M^2]}$</span> (I think).</p>
  
  <blockquote>
    <p>If so, what happens to the first term during the training of the generator - is it taken as a constant or is the discriminator performing badly considered optimal for the generator?</p>
  </blockquote>
  
  <p>The first term is of no consequence to the Generator, because the generator can't affect it somehow (i.e. like you say it is taken as a constant). Consider the generator <span class="math-container">$G_{\theta}$</span> has parameters <span class="math-container">$\theta$</span> and the discriminator <span class="math-container">$D_{\phi}$</span> has parameters <span class="math-container">$\phi$</span>. When training <span class="math-container">$G$</span>:</p>
  
  <p><span class="math-container">$$
  \frac{\log{D_{\phi}(x)}}{\partial \theta} = 0
  $$</span></p>
  
  <p>So the generator is trained of <span class="math-container">$V$</span>.</p>
  
  <blockquote>
    <p>While putting this in code, for every step is the discriminator trained first for one step, keeping the generator constant, followed by the generator being trained for the same step, with the discriminator kept constant?</p>
  </blockquote>
  
  <p>In theory, yes. In practice for every step the Generator takes, we train the Discriminator for more steps (e.g. <span class="math-container">$5$</span> steps).</p>
  
  <blockquote>
    <p>In every step of training are there multiple latent vectors sampled to produce multiple generator outputs for each step? If so is the loss function an average or sum of all V(D,G) for that step.?</p>
  </blockquote>
  
  <p>Yes, at every step we sample a batch of latent vectors. The equation indicates that we average over these (i.e. the expectation) but in practice it doesn't have any difference (the average is the sum divided by a constant number, which doesn't affect the optimization very much).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-23T23:04:00.393Z
Answers.LastActivityDate: 2019-07-23T23:04:00.393Z
Answers.UserDisplayName: Djib2011
Body: <p>Just needed a clarification on the training procedure for a standard GAN.
  Of my understanding the loss function to optimize is a min max (max min causing mode collapse due to focus on one class generation) problem where the loss function</p>
  
  <p><img src="https://miro.medium.com/max/695/1*PI-Qb7CvbMYy_XJCIX07mw.png" alt="as follows"></p>
  
  <p>needs to maximized for the discriminator and minimized for the generator networks -</p>
  
  <p>1.) In this equation are the <span class="math-container">$E_{z~p_{z(z)}}$</span> and <span class="math-container">$E_{x~p_{data(x)}}$</span> the means of the distributions of the mini batch samples? Also is the optimal case for the discriminator a maximum value of 0? and the optimal case for the generator a minimum value of <span class="math-container">$log(small~value)$</span> {basically a massive negative value}? If so, what happens to the first term during the training of the generator - is it taken as a constant or is the discriminator performing badly considered optimal for the generator? </p>
  
  <p>2.) While putting this in code, for every step is the discriminator trained first for one step, keeping the generator constant, followed by the generator being trained for the same step, with the discriminator kept constant?</p>
  
  <p>3.) In every step of training are there multiple latent vectors sampled to produce multiple generator outputs for each step? If so is the loss function an average or sum of all <span class="math-container">$V(D, G)$</span> for that step</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-24T08:02:35.477Z
Comments.Text: Hi. Please, ask one question per post next time!!
Comments.UserDisplayName: nbro
Tags: <neural-networks><deep-learning><optimization><generative-adversarial-networks><generative-model>
Title: Query regarding the minmax loss function formulation of the training of a Generative Adversarial Network (GAN)
UserDisplayName: ashenoy
ThreadText: # Query regarding the minmax loss function formulation of the training of a Generative Adversarial Network (GAN)
  
  (Asked by: username_0 on 2019-07-23)
  
  Just needed a clarification on the training procedure for a standard GAN.
  Of my understanding the loss function to optimize is a min max (max min causing mode collapse due to focus on one class generation) problem where the loss function
  
  ![as follows](https://miro.medium.com/max/695/1*PI-Qb7CvbMYy_XJCIX07mw.png)
  
  needs to maximized for the discriminator and minimized for the generator networks -
  
  1.) In this equation are the $E\_{z~p\_{z(z)}}$ and $E\_{x~p\_{data(x)}}$ the means of the distributions of the mini batch samples? Also is the optimal case for the discriminator a maximum value of 0? and the optimal case for the generator a minimum value of $log(small~value)$ {basically a massive negative value}? If so, what happens to the first term during the training of the generator - is it taken as a constant or is the discriminator performing badly considered optimal for the generator?
  
  2.) While putting this in code, for every step is the discriminator trained first for one step, keeping the generator constant, followed by the generator being trained for the same step, with the discriminator kept constant?
  
  3.) In every step of training are there multiple latent vectors sampled to produce multiple generator outputs for each step? If so is the loss function an average or sum of all $V(D, G)$ for that step
  
  **Tags:** neural-networks, deep-learning, optimization, generative-adversarial-networks, generative-model
  > **Comments:**
  > **username_1**: Hi. Please, ask one question per post next time!!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-07-23. Score: 2 | Accepted answer
  
  I'll answer your questions one by one:
  
  > In this equation are the $E\_{z \sim p\_z(z)}$ and $E\_{x \sim p\_{data}(x)}$ the means of the distributions of the mini batch samples?
  
  So let's take the first part $E\_{x \sim p\_{data}(x)}[log \,D(x)]$. This is read as the "expected value of $log \, D(x)$, where $x$ is sampled from $p\_{data}(x)$". So, in simpler terms this means that:
  
  * You have a distribution $p\_{data}(x)$.
  * You sample a batch of samples $x$ from this distribution.
  * You feed the batch to the discriminator and get its output $D(x)$.
  * You compute the log for the batch of predictions.
  * You average over the samples in the batch.
  
  > Also is the optimal case for the discriminator a maximum value of 0?
  
  Yes, the goal of the discriminator is to **maximize** $V(D, G)$. This is achieved when $D(x) = 1$ and $D(z) = 0$, where $V(D, G)=0$.
  
  > the optimal case for the generator a minimum value of log(small value) {basically a massive negative value}?
  
  Yes, the generator wants to **minimize** $V(D, G)$, so it wants $D(x)$ and $D(z)$ to be as small as possible (though it can affect only the second term). The minimum value for $D(z)$ is $1 / M$, where $M$ is the number of classes in the dataset. So the minimum value for $V(D, G)$ is $\log{[(M-1) / M^2]}$ (I think).
  
  > If so, what happens to the first term during the training of the generator - is it taken as a constant or is the discriminator performing badly considered optimal for the generator?
  
  The first term is of no consequence to the Generator, because the generator can't affect it somehow (i.e. like you say it is taken as a constant). Consider the generator $G\_{\theta}$ has parameters $\theta$ and the discriminator $D\_{\phi}$ has parameters $\phi$. When training $G$:
  
  $$
  \frac{\log{D\_{\phi}(x)}}{\partial \theta} = 0
  $$
  
  So the generator is trained of $V$.
  
  > While putting this in code, for every step is the discriminator trained first for one step, keeping the generator constant, followed by the generator being trained for the same step, with the discriminator kept constant?
  
  In theory, yes. In practice for every step the Generator takes, we train the Discriminator for more steps (e.g. $5$ steps).
  
  > In every step of training are there multiple latent vectors sampled to produce multiple generator outputs for each step? If so is the loss function an average or sum of all V(D,G) for that step.?
  
  Yes, at every step we sample a batch of latent vectors. The equation indicates that we average over these (i.e. the expectation) but in practice it doesn't have any difference (the average is the sum divided by a constant number, which doesn't affect the optimization very much).
  
  
  ---
  
  