Skip to content
AI360XpertBeta
Core ML

Visual explainer

Generative Adversarial Networks

A generator learns through a discriminator. Trace alternating updates, compare two output modes and see how different inputs can collapse onto one sample.

A constant squared-error prediction falls between two real modes.
A constant squared-error prediction falls between two real modes.

A generative adversarial network (GAN) learns a sampling rule through a learned discriminator. Its generator turns a random latent input into a sample; the discriminator learns to distinguish generated samples from training data. Alternating their updates can improve generation, but does not guarantee convergence or variety.

Start with a synthetic scalar dataset: half its values are 2, half are 9. The circles mark these two modes, meaning concentrations of probability. A single constant predictor minimizing squared error returns their mean, 5.5. Its expected loss is (12.25 + 12.25) / 2 = 12.25; always returning 2 would cost (0 + 49) / 2 = 24.5. The mean optimizes that restricted objective but never occurs in the data. This is not a claim that every one-pass generative model must average its outputs.

Two Sample Sources

Real samples and generated samples reach the same discriminator.
Real samples and generated samples reach the same discriminator.

The upper circle is a real training sample. The lower diamond is a generated sample, G(z), where z is drawn from a chosen noise distribution. Both reach the same discriminator, D. In this vanilla unconditional setup, real samples are inputs to D, while z is the input to G. D's output is a source-classification score, not a universal test of truth or quality.

The original GAN paper defines these two objectives and the alternating training procedure. The following examples isolate each update rather than inventing a successful training history.

Update the Discriminator

A discriminator update separates scores while the generator stays fixed.
A discriminator update separates scores while the generator stays fixed.

Read both score axes from 0 to 1. Circles identify real samples; diamonds identify generated samples. Open markers are the previous scores, filled markers the new scores. In this constructed comparison, D changes a real score from 0.5 to 0.8 and a fake score from 0.5 to 0.2. G stays fixed.

For one real/fake pair, discriminator loss is −log D(real) − log(1 − D(fake)). It falls from 1.386294 to 0.446287. These scores illustrate an improving discriminator update; they are not measured results or a promise that every update improves.

Update the Generator

A generator update follows a gradient through a fixed discriminator.
A generator update follows a gradient through a fixed discriminator.

The solid arrow carries the generated sample forward. The dashed return lane carries a derivative backward. Freezing D's parameters still allows differentiation through D's input. G changes its own parameters using that derivative; it does not receive a real sample as a reconstruction target in this vanilla objective. This plumbing offers no privacy guarantee.

For a separate local calculation, let G(0) = w = 4 and D(x) = sigmoid(x − 5.5). Use the non-saturating generator loss L = −log D(G(0)). Then D(4) = 0.182426 and dL/dw = −(1 − D(4)) = −0.817574. A learning rate of 1 moves w to 4.817574, shown on a cropped x axis. This fixed local discriminator is illustrative; it is not the optimum for the two-point distribution. The backpropagation visual explains the derivative path.

Samples Preserve Alternatives

Sampling can retain both modes instead of returning their mean.
Sampling can retain both modes instead of returning their mean.

The aligned axes use the same positions as the first drawing. The lower row shows a possible batch with two generated values at 2 and two at 9. Vertical stacking counts samples, not a second feature. Each mode gets empirical mass 2/4, instead of every output being 5.5. A sampling rule can represent alternatives; adversarial training does not automatically produce this batch or guarantee sharp images.

Scores Depend on Coverage

An optimal discriminator scores the underrepresented mode higher.
An optimal discriminator scores the underrepresented mode higher.

Here solid bars show data probability and dashed bars generator probability. Bar length uses one common scale: 200 drawing units per probability unit. Data assigns (0.5, 0.5) to (2, 9), while G assigns (0.75, 0.25).

Under equal real/generated source priors and an optimal discriminator, D*(x) = p_data(x) / (p_data(x) + p_G(x)). Thus D*(2) = 0.4 and D*(9) = 2/3, rounded to 0.67. The underrepresented mode scores higher even though both values occur in real data. Scores depend on the competing distributions and discriminator capacity.

Sample After Training

Generation uses the trained generator without the discriminator.
Generation uses the trained generator without the discriminator.

After training, draw z and evaluate G to obtain a sample. D is disconnected because ordinary GAN generation does not require it. One generator evaluation can be useful when repeated sampling matters, at the cost of training two interacting networks. This picture makes no hardware timing comparison and establishes no sample-quality guarantee.

The Ideal Balance

At matched distributions the optimal discriminator returns one half.
At matched distributions the optimal discriminator returns one half.

Now both probability rows assign 0.5 to each mode. The same ratio gives 0.5 / (0.5 + 0.5) = 0.5 at both values. This is the ideal distribution-matching solution under the paper's assumptions. A weak D can also output 0.5 everywhere, so that score alone does not prove successful training. Finite neural networks and alternating optimization need not reach the ideal.

Check a Fresh Latent

A fresh latent value can land between the observed modes.
A fresh latent value can land between the observed modes.

To test interpolation, consider a separate illustrative map, G(z) = 5.5 + 3.5z, for z between −1 and 1. The endpoint inputs map to 2 and 9, but the fresh diamond at z = 0.5 maps to 7.25. The target dataset contains neither 7.25 nor any intermediate value. Endpoint checks cannot establish that the entire latent region generates valid data. This map is a counterexample, not a trained GAN result.

Where It Breaks

Distinct latent inputs can collapse onto one output and miss a real mode.
Distinct latent inputs can collapse onto one output and miss a real mode.

In the final counterexample, G(z) = 2 for every input. Different z values reach the same output; the dashed empty marker at 9 shows the missing mode. Sampling more often cannot recover a mode this generator never emits. This is mode collapse: plausible individual samples can coexist with lost diversity. The original paper identifies this many-inputs-to-one-output failure.

Inspect both samples and coverage against suitable held-out data. If coverage matters, a few appealing examples or a high discriminator score are insufficient. Likelihood-based alternatives also require evaluation; they do not guarantee every mode is covered.

The Quick Version

  • Constant squared-error predictions can fall between real data modes.
  • GANs compare real and generated samples using one discriminator.
  • Discriminator updates keep generator parameters fixed.
  • Generator updates differentiate through a discriminator with fixed parameters.
  • Sampling can preserve alternatives instead of averaging them.
  • Optimal discriminator scores depend on both competing distributions.
  • Ordinary generation evaluates G without D.
  • Matched distributions imply one-half scores for an optimal discriminator.
  • Latent interpolation can leave observed data support.
  • Mode collapse maps different latent inputs onto the same output.