Generative adversarial network (GAN) spec #
This module gives TorchLean a small, total GAN interface:
Generatormaps latent noise to synthetic observations;Discriminatormaps observations to scalar "realness" scores; and- the default objective is least-squares GAN (LSGAN), written with existing MSE specs.
We choose LSGAN as the baseline spec because it is total, compact, and verifier-friendly. Classical
logistic GAN losses can be built on top of the same Generator/Discriminator records, but they
need additional domain discipline around log.
References:
- Goodfellow et al. (2014), "Generative Adversarial Nets".
- Mao et al. (2017), "Least Squares Generative Adversarial Networks".
Generator G_θ : z ↦ x_fake.
- forward : Spec.Tensor α latent → Spec.Tensor α obs
Produce a synthetic observation from latent noise.
Instances For
Discriminator/critic D_φ : x ↦ score, represented as a scalar tensor.
- forward : Spec.Tensor α obs → Spec.Tensor α Spec.Shape.scalar
Score an observation. For LSGAN, scores are regressed toward
0or1.
Instances For
GAN model pair.
- generator : Generator α latent obs
Latent-to-observation generator.
- discriminator : Discriminator α obs
Observation-to-score discriminator.
Instances For
Generate a fake sample.
Instances For
Discriminator score on a fake sample G(z).
Instances For
Discriminator score on a real sample.
Instances For
Scalar tensor filled with 1, the LSGAN "real" target.
Instances For
Scalar tensor filled with 0, the LSGAN "fake" target.
Instances For
Least-squares discriminator loss:
MSE(D(x_real), 1) + MSE(D(G(z)), 0).
Instances For
Least-squares generator loss:
MSE(D(G(z)), 1).
Instances For
Fake scoring expands to discriminator-after-generator.
The LSGAN discriminator objective is the sum of real and fake score-regression terms.