Confused by WGAN C1W3 assignment UNQ_C4

Hello,

In the function get_crit_loss, I am confused by the actual formula that works to validate the assignment.

To calculate the crit_loss, we are supposed to calculate the distance between the critic’s predictions on the real images and the predictions on the fake images while also adding a gradient penalty. But what actually works is the distance between the predictions on the fake images and the critic’s predictions on the real images while also adding a gradient penalty.

In the course, the W-loss is also shown as being the difference E(c(x)) - E(c(g(z))), expected value of the critic of reals minus expected value of the critic of fakes.

What would be the correct putting all together formula:

E(c(x)) - E(c(g(z))) + lambda * gradient penalty

or

E(c(g(z))) - E(c(x)) + lambda * gradient penalty?

I am very confused.

Thank you for your answer.

Hi Emma!
Welcome to the community :wave:. Hope you are doing well.

Both are correct.

From the image, you can understand how it works. The first equation is given in the lecture and the breakdown is used in the assignment. For the sake of clarity → we need to minimize a variable x = 7 to bring it down to zero whereas we need to maximize a variable x = -7 to bring it up to zero.

Hope you get the clarity now. If not, feel free to post your queries.

Regards,
Nithin

Hi Nithin,

Thank you for your answer.

I still need some time to think to understand everything correctly.

But what is this 7 or -7 number you are talking about?

In the exercice, for the two tests the difference E(c(x)) - E(c(g(z))) would give 1 and then -40 while E(c(g(z))) - E(c(x)) would give -1 and 40.

I think I dont understand the part in the code that does the actual minimizing or maximizing. I am trying to understand better while reading the “Improved Training of Wasserstein GANs” paper.

The 7 or -7 I’m talking about is just for an analogy. It’s not related to our work. What I’m trying to say is that minimizing a positive number is equivalent to maximizing a negative number.
7 > 0 → Minimize to get closer to zero
-7 < 0 → Maximize to get closer to zero

In the equation given in the lecture, we are trying to maximize E(c(x)) - E(c(g(z)) at the discriminator end. This is the equation. Maximizing E(c(x)) - E(c(g(z)) is equivalent to
minimizing -( E(c(x)) - E(c(g(z)) )
In the code , we will use loss.backward() to minimize the loss function, therefore we are taking
(- ( E(c(x)) - E(c(g(z)) ) ) there.

Hope that it gives you some clarity now. If not, feel free to post your queries.

Regards,
Nithin