Machine Learning

Generative Adversarial Network

Visualize the generator mapping latent noise to a target distribution while the discriminator learns to separate real from fake.

Generative Adversarial Network

Concept Overview

A Generative Adversarial Network (GAN) is an architecture in machine learning consisting of two neural networks—the Generator and the Discriminator—that compete against each other in a zero-sum game. The Generator attempts to produce fake data that is indistinguishable from real data, while the Discriminator attempts to correctly distinguish between the real and generated data. Over time, this adversarial training forces the Generator to learn the underlying distribution of the real data.

Mathematical Definition

The GAN objective is typically formulated as a minimax game involving a value function V(D, G). Let x be a real data point from the true distribution pdata(x), and z be a latent noise vector sampled from a prior distribution pz(z). The Generator G maps z to the data space as G(z), while the Discriminator D outputs a scalar D(x) representing the probability that x came from the real data rather than G.

minG maxD V(D, G) = Ex ∼ pdata[log(D(x))] + Ez ∼ pz[log(1 - D(G(z)))]

Where:

  • D(x) is the discriminator's estimate of the probability that real data x is real.
  • Ex is the expected value over all real data instances.
  • G(z) is the generator's output given noise z.
  • D(G(z)) is the discriminator's estimate of the probability that a fake instance is real.
  • Ez is the expected value over all random inputs to the generator.

Key Concepts

  • Generator (G): Learns to create fake data by mapping random noise (latent space) to the target data distribution. Its goal is to maximize the error of the Discriminator.
  • Discriminator (D): Acts as a binary classifier, learning to distinguish between true data samples and the fake samples produced by the Generator. Its goal is to minimize its classification error.
  • Adversarial Training: The networks are trained alternately. First, the Discriminator is trained on a batch of real and fake data. Then, the Generator is trained by attempting to fool the newly updated Discriminator.
  • Mode Collapse: A common failure mode where the Generator learns to map all noise vectors to a single point or a very limited subset of the true data distribution that fools the Discriminator. It fails to capture the full diversity of the real data.
  • Nash Equilibrium: The theoretical endpoint of training where neither network can improve given the other's fixed strategy. At this point, the Generator perfectly captures the data distribution, and the Discriminator outputs a probability of 0.5 for all inputs.

Historical Context

GANs were introduced in 2014 by Ian Goodfellow and his colleagues. Before GANs, generative models like Restricted Boltzmann Machines or early Variational Autoencoders either struggled to generate sharp, realistic images or involved intractable probability computations. The adversarial framework provided a clever way to implicitly model complex distributions without explicit probability density functions, sparking a massive wave of research in generative AI.

Since their inception, numerous variations have been developed to improve training stability and output quality, such as Deep Convolutional GANs (DCGANs), Wasserstein GANs (WGANs), and conditional GANs (cGANs), which allow for controlled generation.

Real-world Applications

  • Image Synthesis: Generating photorealistic images of faces, objects, and landscapes (e.g., StyleGAN).
  • Data Augmentation: Creating synthetic medical or training data to improve the performance of other machine learning models when real data is scarce.
  • Image-to-Image Translation: Converting sketches to photographs, altering seasons in images, or transferring artistic styles (e.g., Pix2Pix, CycleGAN).
  • Super-Resolution: Enhancing the resolution and recovering fine details in low-resolution images (e.g., SRGAN).
  • Drug Discovery: Generating novel molecular structures with desired chemical properties.

Related Concepts

  • Gradient Descent — The fundamental optimization algorithm used to update the weights of both the Generator and Discriminator.
  • Neural Networks — The underlying architecture used to build both G and D.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Generative Adversarial Network module.

Try Generative Adversarial Network on Riano →

More in Machine Learning