Back
ExamFull examExam paper only

07 02 2023 E T LAB

Full exam for Numerical Analysis for Machine Learning in the Mathematical Engineering degree programme at Politecnico di Milano. The document covers: Course: Numerical Analysis for Machine Learning Prof. E. Miglio - February 7th 2023 Duration of the exam: 2.5 hours. Exercise 1 Load the picture of Politecnico’s facade polimi compressed.jpg. Please notice that the RGB object is list of three matrices, each one corresponding to

Numerical Analysis for Machine LearningFull exam

Document information

What's included in this study material

Full exam for Numerical Analysis for Machine Learning in the Mathematical Engineering degree programme at Politecnico di Milano. The document covers: Course: Numerical Analysis for Machine Learning Prof. E. Miglio - February 7th 2023 Duration of the exam: 2.5 hours. Exercise 1 Load the picture of Politecnico’s facade polimi compressed.jpg. Please notice that the RGB object is list of three matrices, each one corresponding to

Import quality: text was extracted directly from the original document.

Extracted content from the document

Representative passages recognised in different parts of the material. The full extracted text remains available to search, while this compact preview makes the page easier to read.

Page 1

Course: Numerical Analysis for Machine Learning Prof. E. Miglio - February 7th 2023 Duration of the exam: 2.5 hours. Exercise 1 Load the picture of Politecnico’s facade polimi compressed.jpg. Please notice that the RGB object is list of three matrices, each one corresponding to a different ”channel” (i.e. red, greed, or blue). import numpy as np import matplotlib.pyplot as plt from matplotlib.image import imread image_path = 'polimi_compress.jpg' img = imread(image_path) img_RGB = [np.array(img[:,:,i], dtype = np.float64)/255 for i in range(3)] def plot_image(RGB, ax = None): if ax is None: _, ax = plt.subplots(1,1, figsize = (12,5)) ax.imshow(np.clip(np.stack(RGB, axis = 2),0,1)) plt.axis('off') plot_image(img_RGB) Now, randomly replace 70% of the pixels with random colors. damage_fraction = 0.7 np.random.seed(0) mask_remove = np.random.choice(a=[True, False], size=(img.shape[0],img.shape[1]), \ p=[damage_fraction, 1-damage_fraction]) mask_keep = np.logical_not(mask_remove) img_damaged_RGB = [img_RGB[i].copy() for i in range(3)] for i in range(3): img_damaged_RGB[i][mask_remove] = np.random.rand(np.sum(mask_remove)) 1. Display the damaged image. 2. Implement the singular value truncation (SVT) algorithm to reconstruct the picture fromimg damaged RGB. (Hint: apply the algorithm independently to each channel.) 3. Try to optimize by trial and error the threshold on the singular values. Run the algorithm for 20 iterations and plot the resulting image against the original and the damaged one. 4. Comment on the impact of the threshold on the results. Exercise 2 Explain how a perceptron works and how to apply the gradient descent method to optimize the parameters of the perceptron. Consider the following set of data x1 = (2, −1),y1 = 1, x2 = (−1, 1),y2 = 0, x3 = (2, 0.5),y3…

Preview

First page of the document.

First page: 07 02 2023 E T LAB