Quant Memo
Advanced

Conditional GANs

Feeding a label to both the generator and discriminator turns an ordinary GAN, which produces an unpredictable sample from the whole data distribution, into one that generates exactly the category you ask for.

Prerequisites: The GAN Minimax Objective

An ordinary GAN's generator takes random noise zz and produces some sample from the data distribution — you don't get to choose which category it lands on. Train one on a mix of cats and dogs and each call to G(z)G(z) might give either, with no control. A conditional GAN (cGAN) fixes this the same way a conditional VAE does: hand a label yy to both networks, so the generator learns to produce samples of that label and the discriminator learns to check both realism and whether the sample actually matches the label it was told to be.

The analogy: a custom order versus a grab bag

An ordinary GAN is a grab bag: reach in, get a random item from whatever mix was in there. A conditional GAN is a custom order: you specify "dog" and the vendor (generator) produces a dog, while a quality inspector (discriminator) checks not only "is this a real-looking animal" but also "did they actually deliver a dog, not a cat wearing a dog costume." Both checks matter — a perfectly realistic cat delivered against a dog order should still fail inspection.

The objective, with yy threaded through

The cGAN objective is the ordinary minimax objective with yy conditioning every term:

minGmaxD  Ex,ypdata[logD(xy)]+Ez,y[log(1D(G(zy)y))]\min_G \max_D \; \mathbb{E}_{x,y \sim p_{\text{data}}}\big[\log D(x \mid y)\big] + \mathbb{E}_{z, y}\big[\log(1 - D(G(z \mid y) \mid y))\big]

In words: the discriminator now scores "is xx both real and consistent with label yy," and the generator, given zz and yy, tries to produce something that clears that bar. Practically, yy is concatenated into the generator's input noise and into whatever layer of the discriminator sees the sample, so both networks have access to the same label at every step.

Worked example 1: a discriminator that checks both things

Suppose the discriminator's score decomposes (illustratively) as D(xy)=Dreal(x)×Dmatch(x,y)D(x\mid y) = D_{\text{real}}(x) \times D_{\text{match}}(x,y), both in [0,1][0,1]. A real, correctly-labeled dog photo: Dreal=0.95D_{\text{real}}=0.95, Dmatch=0.9D_{\text{match}}=0.9, giving D=0.855D = 0.855 — high, as it should be. A realistic dog photo mislabeled as "cat": Dreal=0.95D_{\text{real}}=0.95 (still looks real) but Dmatch=0.05D_{\text{match}}=0.05 (clearly not a cat), giving D=0.0475D = 0.0475 — correctly rejected, even though the image itself is perfectly photorealistic. An unconditional GAN's discriminator has no DmatchD_{\text{match}} term at all and would have accepted this sample.

Worked example 2: sampling multiple classes from one model

Train a cGAN on ten digit classes with yy one-hot. To generate five 6's and five 9's from a single trained generator: draw ten noise vectors z1,,z10z_1,\dots,z_{10}, pair the first five with y=y=one-hot(6) and the rest with y=y=one-hot(9), and decode each pair through the same GG. Contrast with training ten separate unconditional GANs, one per digit — a cGAN gets all ten classes' worth of shared structure (stroke style, thickness) baked into one model, so a "6" and a "9" sampled with the same underlying zz tend to share the same handwriting style, something ten independent models could never guarantee.

z y Generator Discriminator real? + matches y?
Label $y$ feeds the generator directly and also reaches the discriminator alongside the sample, so a fake with the wrong label can be caught even if it looks perfectly realistic.

Strategy payoff
price at expiry →
net cost 10profit at 100 -10.02 legs

Change the strategy above and notice each preset is really the same payoff machinery conditioned on a different choice — the same relationship a cGAN has to its label: one shared network, steered by which condition you hand it.

A conditional GAN threads a label through both generator and discriminator, so the discriminator rejects samples that are realistic but mismatched to their label, and the generator learns to produce a chosen category on demand — turning an uncontrollable grab-bag sampler into a steerable one.

What this means in practice

Conditional GANs underlie most controllable image generation and are the natural template for finance use cases like generating synthetic order flow conditioned on a venue, or synthetic return paths conditioned on a volatility regime — the same generator can be asked for "calm regime" or "stressed regime" samples rather than needing a separate model per regime.

The common mistake is conditioning only the generator and leaving the discriminator unconditional — it still learns to reject unrealistic samples, but has no way to penalize a realistic sample delivered under the wrong label, so the generator is never actually pushed to respect yy and can quietly ignore it, the GAN analogue of posterior collapse.

Related concepts

Practice in interviews

Further reading

  • Mirza & Osindero, Conditional Generative Adversarial Nets (2014)
ShareTwitterLinkedIn