Train a Simple GAN on 1D Gaussian Data
Sequence Models & Generative Models DS practice problem on Onlearn.
Difficulty: medium.
Topics: Train a Simple GAN on 1D Gaussian Data, Gaussian Mixture Modeling, Minimax Objective Function, Backpropagation Through Time, Jensen-Shannon Divergence, Latent Space Sampling, Probability Theory, Optimization Theory, Generative Modeling, Neural Network Architecture, Statistical Evaluation, Probability Density Estimation, Stochastic Gradient Descent, Adversarial Training Dynamics, Multi-Layer Perceptron Design, Distribution Divergence Metrics.
In this task, you will train a Generative Adversarial Network (GAN) to learn a one dimensional Gaussian distribution. The GAN consists of a generator that produces samples from latent noise and a discriminator that estimates the probability that a given sample is real. Both networks should have one hidden layer with ReLU activation in the hidden layer. The generator’s output layer is linear, while the discriminator's output layer uses a sigmoid activation. You must train the GAN using the standard non saturating GAN loss for the generator and binary cross entropy loss for the discriminator. In the NumPy version, parameters should be updated using vanilla gradient descent. In the PyTorch version, parameters should be updated using stochastic gradient descent (SGD) with the specified learning rate. The training loop should alternate between updating the discriminator and the generator each iteration. Your function must return the trained generator forward function gen forward(z), which produces generated samples given latent noise.