Wasserstein Critic: The Real vs Fake Score Gap

Loss FunctionsEasy+10 XP+10

Wasserstein Critic: The Real vs Fake Score Gap

In a Wasserstein GAN, the critic doesn't output a probability — it outputs an unbounded score, trained to score real data high and generated (fake) data low. The gap between those two averages is what the generator is fighting to close.

L=E[D(xfake)]−E[D(xreal)]L = \mathbb{E}[D(x_{\text{fake}})] - \mathbb{E}[D(x_{\text{real}})]L=E[D(xfake​)]−E[D(xreal​)]

Task: write wasserstein_critic_loss(real_scores, fake_scores), rounded to 4 decimal places.

  • A well-trained critic scores real data higher than fake data, so this loss is negative when the critic is doing its job.
  • There's no sigmoid or log here — WGAN scores are raw and can be any real number.

Examples

real_scores = [1.2, 0.8, 1.5]
fake_scores = [-0.3, -0.5, 0.1]
returns -1.4
real_scores = [2.0, 2.0]
fake_scores = [2.0, 2.0]
returns 0.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run