Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit



COM00041H

 

BSc, BEng and MEng Degree Examinations 2021–22

DEPARTMENT OF COMPUTER SCIENCE

Intelligent Systems 3: Probabilistic and Deep Learning


Rubric:

•  All data and any other additional files are available at the INT3 VLE site in the Assessment section. Your submission should be a single zip file named after your exam number, Yxxxxxxx.zip, which contains a single Jupyter notebook int3.ipynb (combining code and explanations), and a PDF int3.pdf of the state of the same notebook after all of its code has been executed (in the same way in which PDFs of Jupyter notebooks were provided with most lectures). In case of any discrepancies between the contents and output of the Jupyter notebook and the PDF, the former will be used for marking. Make sure you do not use archive formats other than zip. Your code    should assume all data files are in the same folder as the notebook from which they are  accessed.



•  All Python code should be in Python3. Your Jupyter notebook must run correctly when run on Google Colab as practised in the practicals.

•  Unless otherwise indicated there are no word limits on your answers.

 

 

1  Using regression (35 marks)

 

Download the file data.csv from the Assessment section of the INT3 VLE site. The comma- separated file contains time series data on four variables, A, B, C and D. The label for each     column will be given in the first, header row of the file. The remaining rows contain all data points. Each row corresponds to a different moment in time; time grows downwards; the time interval   between each pair of consecutive rows is the same. For example:

 

Your task here is to use scikit-learn to create a regression model to predict the value of variable D one step/time interval/row ahead based on some of the previous values of all four variables.  (Yes, you are allowed to use previous values of D to predict what comes next.) To clarify, your   model can use any past data, but none of the data for the point in time for which you are making a prediction (e.g. you can’t use the value of variable A at time t to predict the value of D at the same time t), your final equations do not have to include all available variables, and they could  make use of time-lagged data and additional variables derived through the use of basis functions. The following marks will be awarded for a well-designed, fully functional and well-argued for      implementation that selects the best model from a range of models, such that each of the          following features appears in one or more of the models: 

(7 marks) Basic linear regression based on variables A, B and C as well as on time-lagged copies of all four variables;

(7 marks) One or more types of regularisation (e.g. L1, L2, Elastic Net);

(7 marks) Polynomial regression;

(7 marks) Piecewise regression.

(7 marks) The remaining part of the marks for this task will be awarded for selecting what you  deem to be the model that would perform best on unseen data with the same distribution as your training data. Here, as for all previous parts of this question, marks will be awarded for your      choice of design and implementation, as well as how well you make the case for the chosen     approach. So, you need to provide a brief and clear explanation of how you validate your results on the available data to select the best model, and why this is a good way of doing it. Please    alternate portions of your code with appropriate text. Make sure you comment on the inter-       mediate results and explain how they inform your decisions.

The result of the previous steps is that you will have selected a single regression model (of fixed type and parameters), which will be tested by the markers on an unseen test set to compute the R2 value of the predictions. Your goal is for this R2 value to be as close to 1 as possible. You do not have access to the test set, but you need to include a code tile at the end of this section of  your Jupyter notebook that attempts to test your model on a data set stored in a file                   unseendata.csv and compute R2 for it. The file will have exactly the same format as file    data.csv, including the header, but possibly a different overall number of rows. This means  you can use a renamed copy of data.csv to debug that part of your code, and to produce the corresponding content for your PDF file (in order to demonstrate that this part of the code is in  working order).




2  Descriptive statistics and dimensionality reduction (15 marks)

Starting with the same data.csv file from Q1, extend the table with 8 additional columns    consisting of (t − 1) and (t − 2) time-lagged copies of variables A, B, C and D, and remove the first 2 lines containing incomplete data from the table.

(6 marks) Apply principal component analysis (PCA) with a number of principal components     (PCs) equal to the number of variables, i.e. p = 12. Label the resulting principal components in decreasing order of variance as PC1. . .PC12 and list the variance for each principal component. Now compare the sum of the variances of all PCs to the sum of all variances of the 12 original  variables and comment on the result.

(9 marks) For PC1 to PC4, list the linear equations showing how each of them is calculated from the 12 input variables. Describe which variables align most strongly with each of the 4 principal components, highlighting any notable findings and providing plausible explanations for them.





3  Predicting light source direction from face images with a CNN (25 marks)

3.1 The dataset

We have provided you with a dataset of face images ( faces_dataset.zip on the VLE).    Once unzipped, this comprises two folders: train and validate. Each folder contains a     series of numbered jpeg images (1,838 training images and 256 validation) of different people, with each person under a number of different lighting conditions. Each image is of size H = 192, W = 160 and they are grayscale (i.e. only one colour channel). Each image contains a face in a frontal pose and has been carefully aligned and cropped so that the eye centres are always at  the same location.

Each image in the face dataset shows a face illuminated by light from a single point, i.e. a point light source. The direction of the light source is known and is represented by a 3D unit vector,  S ∈ Ⅸ3 with |S | = 1. Each image in the training and validation sets are provided with a label, i.e. you are provided with Si for each image i. These are stored in the CSV file labels.csv in the training and validation folders respectively. Each row of the CSV file contains the image      filename in the first column and the three components of Si in columns 2-4. You may notice that light sources are from one of 64 different directions included in the dataset.

 

3.2 The task

The task in this part of the assessment is to estimate the light source direction from the image. i.e. if xi is the ith image and Si the light source direction in that image, your task is to train a     CNN, f , such that f (xi) ≈ Si . You should implement your network in PyTorch.

You are free to preprocess input images however you like. For example, you do not need to use the images at the full resolution provided. You need to decide on an appropriate architecture for the network, choose an appropriate loss function, train it on the training set and use the            validation set to evaluate performance so that you can improve your design or tune                    hyperparameters. Note: this task could be tackled as either a regression or a classification       problem so long as your code ultimately outputs a unit vector for each input image.

I will be testing your network on an unseen test set and computing the mean angular error of  your light source direction predictions. Your goal is for this value to be as close to 0 as possible. You do not have access to the test set, but you need to include a code tile at the end of your      Jupyter notebook that tests your model on the validation data and displays the mean angular     error of the predictions. I will replace the validation folder with a test folder with the same           contents (i.e. a series of jpeg files and a labels.csv file containing labels). So your code tile should read all labels and filenames from the CSV file and then process all images (i.e. don’t    hard-code the filenames of the validation data).



Your notebook must include your training code but you should also submit your saved network

weights and a code tile to load them so that I can test your network performance without re-running your training code.

 

Mark distribution for this question:

10 marks   Correctness of your Python code

5 marks   Appropriate network architecture chosen with justification

5 marks   Appropriate loss function chosen with justification and hyperparameters chosen appropriately (your notebook should include a print out of training and validation loss during training of your network)

5 marks   Mean angular error on test set ≤ 10◦ (full marks for ≤ 10◦, partial marks awarded for lower accuracy).



4  Generating face images (25 marks)

The final task uses the same dataset as Question 3. However, this time you will only use the     images, not the labels. The goal is to train a Generative Adversarial Network (GAN) to create   face images. You must choose an appropriate architecture for the generator and discriminator, decide on the dimensionality of the latent space and train your GAN in order to learn a generator for face images. If you wish, you may combine the train and validation sets from Question 3to  provide more images for training. Again, you may preprocess the images however you like so do not need to train your GAN at full resolution.

You should include a code tile that generates 8 random samples from your generative model.   i.e. randomly sample from your latent space 8 times, pass these through your generator network and display the resulting images.

You should also include a code tile that performs latent space interpolation between two samples. Generate two random samples from the latent space as before, then linearly interpolate 5          intermediate latent vectors and display all 7 resulting images in order (i.e. the first randomly       sampled face, then the 5 interpolated samples, then finally the second randomly sampled face). You would expect that the middle image looks something like an average between the start and end images.

Your notebook must include your training code but you should also submit your saved network

weights and a code tile to load them so that I can test your network performance without re-running your training code.

 

Mark distribution for this question:

10 marks   Correctness of your Python code

5 marks   Appropriate network architecture chosen with justification

5 marks   Successfully generate 8 random face images

5 marks   Successfully interpolate between two random face images in latent space.