Data Science & Machine Learning — Article 84
Conditional GAN (cGAN): A Comprehensive Guide
Explore detailed Conditional GAN (cGAN)
Introduction
Article 83’s optimal discriminator turned the GAN objective into a divergence between marginals.
Supplying a label to both networks turns it into an expectation of per-class divergences, V(D⋆,G) = 𝔼y[2 JSD(pd(·∣ y)‖ pg(·∣ y))] — 2log 2, verified against direct quadrature to 3.23×10⁻¹².
The gap between those two objectives is not a refinement. It is a hole, and its size can be constructed exactly.
Take two balanced classes and define generators that mix the two conditionals by a fraction t while leaving each class’s total mass intact.
Every member of that family has exactly the data marginal, while per-class JSD rises from 0 to 0.63272019 and label alignment falls from 0.977250 to 0.022750.
At t = 1 the classes are fully swapped, so every requested label yields a sample the Bayes classifier assigns to the other class while the sample distribution stays perfect.
An unconditional GAN at its global optimum cannot distinguish any of these from the correct generator.
Table of Contents
- Introduction
- Table of Contents
- What is a Conditional GAN
- Core Components of a Conditional GAN
- Mathematical Foundation
- Types of Conditional GAN
- Evaluation Metrics
- Selecting Evaluation Metrics
- Assumptions and Practical Considerations
What is a Conditional GAN
Definition
- A conditional GAN supplies a label y to both networks, so the generator produces samples from a requested class and the discriminator judges the pair:
- The discriminator now answers a harder question than “is this real”: it answers “is this a real sample of this class”.
- A sample that is individually plausible but carries the wrong label is now penalized.
What conditioning changes about the optimum
- The inner maximization is still pointwise, but now per class:
- so the outer problem minimizes an expectation of per-class divergences rather than a single divergence between marginals.
- Section 5 shows those are genuinely different objectives with different optima, not one being a sharpened version of the other.
Core Components of a Conditional GAN
The generator’s label input is not self-enforcing
- Nothing forces G to use y. If it ignores the label entirely then pg(·∣ y) = q(·) for every y, and Section 5 measures what each objective reports about that.
- The label must reach the discriminator for the objective to penalize it, which is why a cGAN that conditions only the generator degenerates to an unconditional GAN with a decorative extra input.
Mathematical Foundation
The construction: one marginal, many conditionals
With A = 𝒩(-2,1), B = 𝒩(+2,1) and balanced classes, define for t∈[0,1]:
The marginal is invariant in t, because the two halves exchange exactly the mass they receive:
The Bayes classifier for the true conditionals assigns x to class 0 iff x<0, so alignment has a closed form:
The marginal JSD column is numerically zero throughout, at the level of quadrature error.
So the unconditional objective assigns identical, optimal value to a family whose label alignment ranges from 0.977250 down to 0.022750.
At t = 1 the classes are fully swapped and the sample distribution is still exactly right.
This is stronger than saying conditioning helps. It says the unconditional objective has no preference at all among these generators, so no amount of optimizing it can select the correct one.
The information simply is not in the objective.
The conditional objective does see it
Verifying the per-class identity against direct quadrature:
Get Arko Sengupta’s stories in your inbox
Join Medium for free to get updates from this writer.
The floor -2log 2 = -1.38629436 is reached only at t=0, where every class conditional matches.
A label-ignoring generator, exactly scored
If G discards y and emits the exact data marginal:
Note that 0.19469964 is exactly the t = 0.5 entry above, which is the consistency check: emitting the marginal for both classes is the half-swapped member of the family.
The generator is a global optimum of the unconditional objective and scores chance alignment for two balanced classes.
Parameter cost of the two conditioning schemes
Concatenation embeds y into e dimensions and appends it to the input, widening the first layer by e c₁ k² weights plus an n(classes)× e table.
Projection adds y⊤ Vφ(x) to the output, costing one n(classes)× d(feat) table and leaving the trunk untouched:
Concatenation carries a fixed term e c₁k² independent of the class count, while projection grows linearly in it, so the crossover is at n⋆ = e c₁k²/(d(feat) — e):
The crossover is configuration-dependent and lands anywhere from about 20 to 220 classes.
Projection is cheaper below it and concatenation above, so neither dominates and the choice depends on e, c₁ and d(feat) rather than on the class count alone.
Types of Conditional GAN
AC-GAN conditions differently and it matters
- An auxiliary classifier adds a term rewarding D for predicting y correctly, which is not the same as the per-class objective in Section 5.
- The auxiliary term can be satisfied by a generator producing easily-classified samples, which is a weaker requirement than matching each conditional, and it introduces the same tension Article 83 measured between fixing one failure and creating another.
- This article measures the projection and concatenation costs but does not measure AC-GAN’s behavior, so I am noting the distinction rather than ranking them.
Conditioning only the generator is the failure mode to avoid
- The last row is worth stating explicitly because it looks like a cGAN in code.
- With the label reaching only G, the objective is exactly the unconditional one, and Section 5 shows that objective is indifferent across the entire swap family.
- The label input becomes decorative.
Evaluation Metrics
Alignment and per-class fidelity are different failures
- Constructing a case where alignment passes and fidelity does not.
- Class 0 is itself bimodal, 1/2𝒩(-3,0.7) + 1/2𝒩(-1,0.7), and the generator collapses it to a single component while fitting class 1 exactly:
Alignment is essentially perfect while class 0 has lost half its structure.
- A label-accuracy check passes cleanly, because every sample still falls on the correct side of the decision boundary
- The failure is entirely within class 0 and appears only in the per-class divergence.
- Note that here the marginal JSD does partially register the problem, at 0.07493062, so the aggregate is not fully blind in this construction. What is blind is alignment.
- The two metrics fail on different constructions, which is the reason to report both: Section 5’s swap family defeats the marginal while alignment catches it, and this construction defeats alignment while the divergence catches it.
Selecting Evaluation Metrics
A diagnosis table built from the two constructions
- The first two rows are the ones the unconditional objective cannot reach, and they are distinguished from each other only by alignment being at chance versus below it.
- Alignment below chance is diagnostic of a permutation rather than of indifference, since a generator that ignored the label would sit at exactly 0.500000.
On which metric to compute first
- Alignment is the cheapest, needing only a classifier and a batch of samples, and it detects the entire swap family that aggregate quality scores cannot.
- Per-class divergence needs enough real samples per class to estimate a distribution, so it is more expensive and more informative.
- Aggregate quality alone is the least useful of the three for a conditional model, since Section 5 exhibited a generator with a perfect aggregate score and 0.022750 alignment.
What none of these metrics address
- Article 83’s results carry over unchanged. The saturating gradient, the JSD saturation at log 2 once supports separate, and the purely imaginary Jacobian all apply per class, and conditioning does not touch any of them.
- Conditioning changes what the optimum is, not whether it can be reached. A cGAN can be blind-spot-free in objective and still orbit rather than converge, and the loss curve will look no different.
Assumptions and Practical Considerations
On the alignment classifier
- Alignment is measured with respect to some classifier, and in this article that classifier is Bayes-optimal because the true conditionals are known.
- In practice it is a trained model with its own errors, so a measured alignment of 0.95 conflates generator fidelity with classifier accuracy.
- The cleanest reading is comparative, against the same classifier’s accuracy on real held-out data, rather than absolute.
On what the construction does and does not show
- The swap family is one-dimensional with two Gaussian classes, chosen so the marginal invariance is exact and the alignment closed form is available.
- Nothing about the argument depends on those specifics: the construction works whenever two class conditionals can exchange mass without changing the mixture, which is generic.
- What is specific is the magnitude, 0.977250 to 0.022750, which depends on the class separation.










