Skip to content

Module 19

Anurag Prasad edited this page Nov 7, 2026 · 8 revisions

Module 19: Generative Adversarial Networks and Variants

Curriculum part: Representation and Generative Learning
Study level: Advanced
Content status: Substantive introductory chapter; supporting exercises and implementations are maintained separately.

1. Why this module matters

GANs train a generator and discriminator/critic in an adversarial game. The learned signal can generate realistic samples but training may be unstable.

2. Learning objectives

After studying this module, you should be able to:

  • Explain the central problem and assumptions of the methods covered.
  • Interpret the principal mathematical objects, equations and tensor dimensions.
  • Work through a small numerical example without relying on a framework.
  • Implement or verify the central operation using NumPy or PyTorch.
  • Identify failure modes and select appropriate follow-up material.

3. Prerequisites and connections

Prerequisites: Modules 03, 06–10 and 16.

The module follows the principle write once, reference everywhere. Foundational derivations are maintained in their primary module; later modules focus on how those ideas are used rather than repeating the full derivation.

4. Core concepts and theory

The generator maps noise (and optional conditions) to samples. The discriminator distinguishes real from generated examples. The original minimax game has an optimal discriminator p_data/(p_data+p_g) for a fixed generator. A non-saturating generator loss gives stronger gradients early in training. DCGAN uses architectural guidance such as strided convolutions, transposed convolutions, batch normalization and ReLU/LeakyReLU. Mode collapse reduces diversity. WGAN uses an Earth-mover objective with a Lipschitz constraint; gradient penalty is one practical approach. Conditional GANs supply labels or other conditions to both networks.

5. Mathematical formulation

A compact form of the central operation is:

$$ \min_G\max_D\ \mathbb{E}_{x\sim p_{\mathrm{data}}}[\log D(x)]+\mathbb{E}_{z\sim p(z)}[\log(1-D(G(z)))] $$

Minimax E_real[logD(x)]+E_z[log(1−D(G(z)))]; non-saturating generator loss −E_z[logD(G(z))]. Ideal D*(x)=p_data(x)/(p_data(x)+p_g(x)).

The equations above define the main computational objects. When implementing them, specify tensor shapes, reduction axes, normalization conventions and whether a loss is summed or averaged. Those details determine the actual computation.

6. Worked numerical reasoning

If the discriminator is nearly perfect early, the saturating minimax generator gradient can be weak. The non-saturating loss changes the generator's gradient signal, though it does not eliminate all instability.

Use the example as a check on notation and implementation. Change one input at a time and verify how the output changes; this is often more informative than immediately moving to a large dataset.

7. Computational workflow

flowchart TD
    A[Define the problem and data] --> B[Identify mathematical objects]
    B --> C[Write equations and tensor shapes]
    C --> D[Work through a small numerical case]
    D --> E[Implement the operation]
    E --> F[Verify outputs and gradients]
    F --> G[Evaluate limitations and connect to later modules]
Loading

8. Implementation and verification

Train a small DCGAN and save fixed-noise samples every epoch. Track both losses and diversity; inspect nearest neighbours; repeat across seeds.

A good implementation sequence is:

  1. Write the operation in plain mathematical notation.
  2. Calculate a tiny example by hand.
  3. Implement the operation with NumPy.
  4. Compare against a trusted PyTorch operation.
  5. Add shape and numerical assertions.
  6. Only then run a larger experiment.

See the implementation roadmap for a module-specific progression.

9. Common misconceptions and failure modes

GAN losses are not perceptual-quality metrics. Sample grids can hide mode collapse. FID depends on preprocessing, sample size and implementation. BatchNorm and learning-rate balance affect both players.

10. Advanced directions

Study spectral normalization, gradient penalty, minibatch discrimination, unrolled GANs, StyleGAN and precision/recall for generative models.

These are extensions beyond the minimum conceptual foundation. Treat them as directions for further reading or experiments, not as claims that an implementation or benchmark is already complete.

11. Focused pages and practice

This module is best studied as one integrated chapter; the lesson map divides the reading sequence without duplicating the theory.

12. Where this concept is used

13. Scope and content provenance

The original course material is the primary basis for the course topics in this curriculum. Mathematical prerequisites are included to make the course topics understandable from first principles. Additional modern methods are identified as extensions where appropriate. The chapter does not imply that every proposed coding exercise or research experiment has already been executed.

15. Selected references

These sources provide canonical starting points for the concepts in this chapter. They are not a claim that every extension listed above is covered by the original course material.

  • Goodfellow, I., et al. (2014). Generative adversarial nets. NeurIPS.
  • Radford, A., Metz, L., & Chintala, S. (2016). Unsupervised representation learning with deep convolutional generative adversarial networks. ICLR.
  • Gulrajani, I., et al. (2017). Improved training of Wasserstein GANs. NeurIPS.

16. Completion criteria

  • Explain the main ideas in your own words.
  • Re-derive the central equations and check dimensions.
  • Solve the worked example independently.
  • Complete at least one numerical exercise.
  • Implement and verify the central operation.
  • Explain at least two limitations or failure modes.
  • Follow the cross-module links relevant to your learning path.

Next: Continue to the lesson map or return to the curriculum map.

🎓 Deep Learning Hub

🏠 Home · 🗺️ Curriculum · 🧭 Learning paths

❓ Question bank · 📖 Glossary · 📚 References

Jump to module:

01 02 03 04 05 06 07 08 09 10 11 12

13 14 15 16 17 18 19 20 21 22 23 24

Part 1 · Mathematical foundations
Part 2 · Neural network fundamentals
Part 3 · Training deep networks
Part 4 · Core architectures
Part 5 · Representation and generative learning
Part 6 · Specialised, modern and responsible deep learning
Reference and meta

Clone this wiki locally