Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

GANs as a Minimax Game

Introduction

In our previous lessons on Variational Autoencoders, we explored a powerful method for generative modeling based on probabilistic principles. We learned to map data to a structured latent space and then sample from that space to generate new data, optimizing an explicit objective function called the Evidence Lower Bound (ELBO). This approach, rooted in variational inference, provides an elegant way to approximate an intractable data distribution.

Today, we pivot to a completely different and revolutionary paradigm for generative modeling: Generative Adversarial Networks (GANs). Instead of defining an explicit probability distribution or a direct loss function like reconstruction error, GANs learn to generate data through a competitive, game-theoretic process. This lesson will introduce the core framework of GANs, breaking down the roles of its two key components and formalizing their interaction as a two-player minimax game, a concept central to the original 2014 paper by Goodfellow et al.

The Adversarial Game

At the heart of a GAN are two neural networks locked in a contest:

  1. The Generator (G): This network's goal is to create synthetic data that is indistinguishable from real data. It takes a random vector from a simple noise distribution (e.g., a Gaussian), denoted , and transforms it into a sample, , that has the same structure as the real data (e.g., an image). The generator is akin to a counterfeiter trying to produce fake currency that looks perfectly genuine.

  2. The Discriminator (D): This network's goal is to act as a detective, distinguishing real data from the generator's fakes. It takes a sample, , and outputs a single scalar, , representing the probability that is a real sample from the training data, not a fake one produced by .

The training process pits these two networks against each other. The discriminator is trained on a mix of real images (from the dataset) and fake images (from the generator). The generator is trained based on the discriminator's feedback: if the discriminator successfully identifies its output as fake, the generator must adjust its parameters to produce more convincing fakes. Over time, this adversarial dynamic drives the generator to produce samples of remarkable fidelity.

The video below offers an excellent intuition for this setup using the counterfeiter-and-police analogy.

Understanding GANs (Generative Adversarial Networks)

The video "Understanding GANs" from the channel DeepBean provides a great high-level introduction.

Watch the first minute of the video, from the beginning to the introduction, to solidify the core concept of the generator and discriminator as two competing agents.

Formalizing the Game: The Minimax Objective

To turn this intuitive idea into a trainable system, we need to define a mathematical objective. The entire framework can be expressed as a single value function, , which represents the "payoff" in this game. The discriminator tries to maximize this payoff, while the generator tries to minimize it.

Let's derive this from first principles.

The Discriminator's Objective

The discriminator's task is a standard binary classification problem. For any given input , it outputs , the probability that is real.

  • For a real sample drawn from the true data distribution , the ideal output is .
  • For a fake sample , where is drawn from a noise distribution , the ideal output is . The probability of it being real is zero.

Given this, what loss function would we use to train a binary classifier? As we saw in Module 4, the binary cross-entropy is the natural choice. The discriminator wants to maximize the log-probability of correctly classifying both real and fake samples. This translates to:

  1. Maximizing for real samples.
  2. Maximizing for fake samples (since is the probability of the sample being fake).

Averaging over all possible real and fake samples, the discriminator's goal is to maximize the following value function:

The Generator's Objective

The generator has the opposite goal. It wants to fool the discriminator. A successful generator produces samples that the discriminator classifies as real, meaning is close to 1. Looking at the value function , the generator has no control over the first term, , as it doesn't involve . Its sole focus is on the second term.

To fool the discriminator, the generator wants to be high. This is equivalent to making very low (i.e., a large negative number). Therefore, the generator's objective is to minimize the same value function that the discriminator is trying to maximize.

The Minimax Equation

Combining these two opposing goals gives us the central equation of GANs—a minimax game:

This elegant equation captures the entire adversarial process. The generator tries to minimize the objective, while the discriminator simultaneously tries to maximize it. This is a zero-sum game where one player's gain is the other's loss.

This diagram illustrates the complete GAN framework. Noise is fed to the Generator to produce "Fake" samples. The Discriminator receives both "Real" and "Fake" samples and predicts their authenticity. The discriminator's loss (D loss) encourages correct classification. The generator's loss (G loss) encourages it to produce samples that the discriminator misclassifies as real. Gradients from these losses are used to update both networks.

To see this mathematical formulation developed from the ground up, the following resources are excellent.

Minimax Game for Training Generative Adversarial Networks - Lei Mao

This blog post by Lei Mao provides a concise and clear explanation of the minimax objective.

First, read the introductory section, which presents the full minimax equation upfront. Then, jump to the section Mathematical Motivations, which explains how the opposing goals of the generator and discriminator lead to this single objective.

[Classic] Generative Adversarial Networks (Paper Explained)

This video by Yannic Kilcher breaks down the original GAN paper. This segment focuses on the introduction of the minimax game.

Watch from the discussion of the two-player game. The video explains how the value function is constructed and how the generator and discriminator have conflicting goals with respect to it.

The Theoretical Optimum: Reaching Equilibrium

The brilliance of the minimax formulation is not just its elegance, but its theoretical properties. The original paper proved that this game has a unique equilibrium point. Let's think about what happens when the system reaches this equilibrium.

The generator gets so good that its generated distribution, , is identical to the real data distribution, . At this point, the discriminator can no longer tell the difference between real and fake samples. For any input , the sample is equally likely to have come from the real dataset or the generator.

What does this imply for the discriminator's output? If it cannot distinguish the two, its best strategy is to guess. Thus, for any sample , . The discriminator is completely confused, outputting a 50% probability for every input.

This is the Nash Equilibrium of the game. At this point:

  1. The generator's distribution perfectly matches the data distribution: .
  2. The discriminator outputs everywhere.
  3. Neither player can improve its outcome by unilaterally changing its strategy.

The minimax objective, when optimized perfectly, is equivalent to minimizing the Jensen-Shannon Divergence (JSD) between the real data distribution and the generated data distribution. The JSD is a symmetric and smoothed version of the KL divergence we've seen before. It is zero if and only if the two distributions are identical. Therefore, by playing this minimax game, the generator is implicitly driven to make its output distribution match the true data distribution perfectly.

The following resources dive into the mathematical proof that shows the connection between the GAN objective and Jensen-Shannon Divergence, providing the formal justification for why this adversarial game works.

Understanding GANs (Generative Adversarial Networks)

This is a continuation of the "Understanding GANs" video. It provides the proof of optimality.

Watch the segment from the minimax game explanation to see the value function framed in game theory terms. Then, continue with the mathematical proof from the Nash equilibrium analysis, which demonstrates that the optimal state corresponds to the generator matching the data distribution and minimizing the Jensen-Shannon Divergence.

[PDF] Generative Adversarial Networks (GAN) - David I. Inouye

These lecture slides from David I. Inouye provide a compact mathematical treatment of the GAN objective.

Review slide 17, which presents the derivation for the optimal discriminator D^*. Then, study slide 18, which explains that with an optimal discriminator, the objective becomes equivalent to minimizing the JSD. Finally, examine slide 19, which walks through the full derivation.

Conclusion

In this lesson, we have laid the foundation for understanding Generative Adversarial Networks. We have moved from the probabilistic approach of VAEs to a game-theoretic framework where two networks, a generator and a discriminator, compete to improve each other.

Key Takeaways:

  • GANs consist of two networks: A Generator that creates data from noise, and a Discriminator that classifies data as real or fake.
  • Training is an adversarial process: The generator tries to fool the discriminator, and the discriminator tries to get better at catching the generator's fakes. This competition drives the generator to produce highly realistic data.
  • The objective is a minimax game: The entire process is captured by a single value function that the discriminator aims to maximize and the generator aims to minimize.
  • The theoretical optimum is a Nash Equilibrium: At the point of equilibrium, the generator's output distribution is identical to the real data distribution (), and the discriminator is maximally confused (). This corresponds to minimizing the Jensen-Shannon Divergence between the two distributions.

Preview of the Next Lesson:

While the theory of GANs is elegant, their practical training is notoriously difficult. The beautiful equilibrium we discussed is hard to reach. In the next lesson, we will investigate the common failure modes of GAN training, such as mode collapse (where the generator produces only a limited variety of samples) and training instability (where the generator and discriminator fail to converge). Understanding these challenges is the first step toward exploring the many architectural innovations designed to make GANs more stable and powerful.

Can't find a good explanation? Sign up and we'll make it for you

Sign up