0
$\begingroup$

The generator tries to maximise this function D(G(z)). That much I understand.

But how can the critic maximise D(x) - D(G(z)). This has two inputs: a real instance and a noise sample. The model takes an input in order to backprop, otherwise it wouldn't be able to update the first layer. So which input do I choose? Am I missing something or does this require multi-variable calculus?

$\endgroup$

1 Answer 1

1
$\begingroup$

A function can be optimized, even if it has two inputs!

First, note that the problem in question already occurs with traditional GANs as well. It might be easier to understand what is going on if you have an 'implementation' example. You can check my tutorial on GANs on GitHub.

Specifically, for training the discriminator we indeed take to inputs:

  1. A batch of synthetic samples $\hat x$. This we can create by taking a batch of noise vectors, which we pass through the generator ($\hat x = G(z)$).
  2. A batch of real training samples $x$ from the dataset.

Now we pass both through the discriminator. Obtaining both $D(\hat x)$ and $D(x)$.

Now we can calculate the loss for both outputs and combining them. For WGAN, this means taking the mean over the outputs, and subtracting them, so $mean(D(x)) - mean(D(\hat x))$. This we can backpropagate, as it is simply one number. Note that backpropagating one of these terms (i.e. just $mean(D(x))$ ) is very similar to backpropagating both of them, as it is only one addition operation different. You need just the same amount of calculus for the one as for the other.

$\endgroup$
2
  • $\begingroup$ Thank you for your efforts. I looked through your repo and found out that I can add two cost functions together for backwards propagation. After some more research I learned that this is equivalent to backwards propagating twice. e.g. (loss1 + loss2).backprop(); optimizer.step(); is the same as loss1.backprop(); loss2.backprop(); optimizer.step(); God bless. $\endgroup$
    – zacoons
    Commented Oct 8, 2023 at 21:32
  • $\begingroup$ They are approximately the same, but your second option will train 'faster' because the learning rate is 'doubled' (applied two times). Operationally, it is the same. $\endgroup$ Commented Oct 9, 2023 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .