Loading content...
In this challenge, you will implement and train a Generative Adversarial Network (GAN) to synthesize samples from a one-dimensional Gaussian distribution. GANs, introduced by Ian Goodfellow in 2014, represent one of the most influential breakthroughs in generative modeling, enabling neural networks to learn complex data distributions through an elegant adversarial training paradigm.
A GAN consists of two competing neural networks engaged in a minimax game:
Generator Network (G): This network transforms random noise from a simple latent distribution (typically standard normal) into samples that should resemble the target data distribution. The generator's goal is to produce samples so realistic that the discriminator cannot distinguish them from real data.
Discriminator Network (D): This network acts as a binary classifier, estimating the probability that a given sample originated from the real data distribution rather than being synthesized by the generator. The discriminator's goal is to correctly identify real samples from fake ones.
Both networks should be implemented as simple feedforward neural networks with the following specifications:
Generator Architecture:
Discriminator Architecture:
The training follows the non-saturating GAN loss formulation:
Discriminator Loss (Binary Cross-Entropy): $$\mathcal{L}D = -\mathbb{E}{x \sim p_{data}}[\log D(x)] - \mathbb{E}_{z \sim p_z}[\log(1 - D(G(z)))]$$
Generator Loss (Non-Saturating): $$\mathcal{L}G = -\mathbb{E}{z \sim p_z}[\log D(G(z))]$$
The non-saturating formulation for the generator provides stronger gradients early in training compared to the original minimax objective, helping to avoid the vanishing gradient problem when the discriminator is too strong.
During training, you should alternate between:
Parameters should be updated using vanilla gradient descent with an appropriate learning rate.
Implement a function that:
The goal is for the trained generator to produce samples that match the target Gaussian distribution's statistical properties (mean and standard deviation).
mean = 4.0, std = 1.25, epochs = 1000, seed = 42[6.7367, 0.4511]The GAN is trained to learn a Gaussian distribution with mean 4.0 and standard deviation 1.25. After 1000 epochs of adversarial training, the generator forward function is called with 500 samples of standard normal latent noise. The generated samples have a mean of approximately 6.7367 and a standard deviation of approximately 0.4511. Note that GANs may not perfectly match the target distribution's statistics, especially with limited training and a simple architecture.
mean = 0.0, std = 1.0, epochs = 1000, seed = 42[-0.1011, 0.7642]Training to learn a standard normal distribution (mean=0, std=1). After training, the generator produces samples with mean approximately -0.1011 and standard deviation approximately 0.7642. The deviation from the target statistics demonstrates the challenges of GAN training, including mode collapse tendencies and optimization difficulties.
mean = -3.0, std = 2.0, epochs = 1000, seed = 42[-4.5289, 0.8108]The GAN is trained to learn a Gaussian distribution with negative mean (-3.0) and larger standard deviation (2.0). The trained generator produces samples with mean -4.5289 and standard deviation 0.8108. This example shows how the generator learns to shift its output distribution to match the target mean while capturing some of the target variance.
Constraints