Use the below dataset for Task 1:
np.random.seed(45)
num_samples = 40
# Generate data
x1 = np.random.uniform(-1, 1, num_samples)
f_x = 3*x1 + 4
eps = np.random.randn(num_samples)
y = f_x + eps
-
Use
torch.autograd
to find the true gradient on the above dataset using linear regression (in the form$\theta_1x + \theta_0$ ) for any given values of$(\theta_0,\theta_1)$ . -
Using the same
$(\theta_0,\theta_1)$ as above, calculate the stochastic gradient for all points in the dataset. Then, find the average of all those gradients and show that the stochastic gradient is a good estimate of the true gradient. -
Implement full-batch, mini-batch and stochastic gradient descent. Calculate the average number of iterations required for each method to get sufficiently close to the optimal solution, where "sufficiently close" means within a distance of
$\epsilon$ (or$\epsilon$ -neighborhood) from the minimum value of the loss function. Visualize the convergence process for 15 epochs. Choose$\epsilon = 0.001$ for convergence criteria. Which optimization process takes a larger number of epochs to converge, and why? Show the contour plots for different epochs (or show an animation/GIF) for visualisation of optimisation process. Also, make a plot for Loss v/s epochs for all the methods. -
Explore the article here on gradient descent with momentum. Implement gradient descent with momentum for the dataset. Visualize the convergence process for 15 steps. Compare the average number of steps taken with gradient descent (for variants full batch and stochastic) with momentum to that of vanilla gradient descent to converge to an
$\epsilon$ -neighborhood for both dataset. Choose$\epsilon = 0.001$ . Write down your observations. Show the contour plots for different epochs for momentum implementation. Specifically, show all the vectors: gradient, current value of theta, momentum, etc.
Begin by exploring the instructor's notebook that introduces the application of Random Fourier Features (RFF) for image reconstruction.
-
Image Reconstruction - Choose any image you like. Use Random Fourier Features (RFF) and Linear Regression to learn the mapping from the image coordinates
$(X, Y)$ to the pixel colors$(R, G, B)$ . Here,$(X, Y)$ represents the coordinates of the pixels, and$(R, G, B)$ represents the color values at those coordinates. Display both the original image and the reconstructed image. Also, calculate and report the Root Mean Squared Error (MSE) and Peak Signal-to-Noise Ratio (PSNR) between the original and reconstructed images. -
Audio Reconstruction - Pick a 5-second audio sample of your liking. Use Random Fourier Features (RFF) and Linear Regression to learn the mapping from time
$(t)$ to amplitude$(A)$ , where$t$ is the time point, and$A$ is the audio amplitude at that time. Play the reconstructed audio and the original audio to demonstrate reconstruction. Calculate the Root Mean Squared Error (RMSE) and Signal-to-Noise Ratio (SNR) to evaluate the reconstruction.
Note : Please notice that generally PSNR is used for images while SNR is used for audio signals.
Use the instructor's notebook on matrix factorisation, and solve the following questions. Here, ground truth pixel values are missing for particular regions within the image- you don't have access to them.
-
Pick an image of your liking and reconstruct it using matrix factorization. Choose a suitable value for the rank
$r$ . Run Gradient Descent until it converges, plot the reconstructed image alongside the original image. Calculate and report the RMSE and PSNR metrics. -
Consider a case where 900 pixels (30x30) are randomly missing from an image. Reconstruct the image using matrix factorization, plot the reconstructed image, and calculate the RMSE and PSNR metrics. Next, reconstruct the same image with the missing pixels using Random Fourier Features (RFF) and Linear Regression. Compute the RMSE and PSNR for both methods, and compare the results to see which performs better.
You have an image patch of size (50x50) that you want to compress using matrix factorization. To do this, you'll split the patch
- Test different values for the low-rank
$r = [5, 10, 25, 50]$ . - Use Gradient Descent to learn the compressed matrices.
- Display the reconstructed image patches, keeping the original pixel values outside the patch unchanged, and use your compressed matrix for the patch to show how well the reconstruction works.
- Compute the RMSE and PSNR for each value of
$r$ .
Here is a reference set of patches that you can choose. You can chose an image of your liking and create patches. You can choose the image shown below as well.
- Present your results in a Jupyter Notebook or an MD file. If you choose to use an MD file, also include your code as a separate
.py
or.ipynb
file. - The assignment is worth 20 marks but will be scaled down to 10 marks.
- Carefully read the questions and make sure you answer all parts, as missing some could result in losing marks.
- Ensure your code is readable and submitted before the deadline.
- For any questions, use the #assignments channel on Slack.
- Be efficient by reusing code from previous tasks wherever possible to solve new problems. In a few question, some task can be used as a base to solve the next task.