CMPUT 366 — Assignment #3 1 CMPUT 366, Winter 2022 Assignment #3 Due: Friday, March 25, 2022, 11:59pm Total points: 68 For this assignment use the following consultation model: 1. you can discuss...

1 answer below »
Neural Networks - See attachments


CMPUT 366 — Assignment #3 1 CMPUT 366, Winter 2022 Assignment #3 Due: Friday, March 25, 2022, 11:59pm Total points: 68 For this assignment use the following consultation model: 1. you can discuss assignment questions and exchange ideas with other current CMPUT 366 students; 2. you must list all members of the discussion in your solution; 3. you may not share/exchange/discuss written material and/or code; 4. you must write up your solutions individually; 5. you must fully understand and be able to explain your solution in any amount of detail as requested by the instructor and/or the TAs. Anything that you use in your work and that is not your own creation must be properly cited by listing the original source. Failing to cite others’ work is plagiarism and will be dealt with as an academic offence. First name: Last name: CCID: @ualberta.ca Collaborators: CMPUT 366 — Assignment #3 2 1. (Neural Networks) The MNIST dataset is a set of images of handwritten digits labelled by their actual digit. We will operate on two versions of this dataset: one with the images shifted 2 pixels to the upper-left, and one with the images shifted 2 pixels to the bottom-right. This question requires the use of TensorFlow. The example code was tested using Tensorflow version 2.8.0 and Python version 3.9. You may need to install TensorFlow using the following command: pip3 install tensorflow (a) [10 points] Implement a fully-connected feed-forward neural network for classifying MNIST images according to the digit that they represent by editing the mlp2 function in the provided cnn.py file. The network should have two hidden layers: one with 128 rectified linear (‘relu’) units, and one with 64 rectified linear units. The output should be a fully-connected layer of 10 units with the softmax activation. The cnn.py file contains an example implementation of a network with a single hidden layer in the mlp1 function that you may template from. The main function will test your program for you; you may add any tests that you like. It will also create a file called examples.png that contains examples images from the two test sets. The function should train the network using the training features train_x and labels train_y, and then evaluate the accuracy of the trained network on two different test sets: test1_x, test1_y, and test2_x, test2_y. This is demonstrated in mlp1. We will run your code by importing the cnn module and calling mlp2, so it is important that your code follow these naming conventions. Submit all of your code for this question and question 1 (including provided boilerplate files) in a single zip file. (b) [30 points] Implement a convolutional neural network for classifying MNIST images by editing the cnn function in the provided cnn.py file. The network should have the following architecture: • A layer of 32 convolutional units with a kernel size of 5× 5 and a stride of 1, 1. • A max-pooling layer with a pool size of 2× 2 and a stride of 2, 2. • A layer of 64 convolutional units with a kernel size of 5× 5 and the default stride. • A max-pooling layer with a pool size of 2× 2 and the default stride. • A Flatten layer (to reshape the image from a 2D matrix into a single long vector) • A layer of 512 fully-connected relu units • A layer of 10 fully-connected softmax units (the output layer) Submit all of your code for this question and question 1 (including provided boilerplate files) in a single zip file. (c) [2 points] What was the accuracy of your trained 2-hidden-layer feedforward network on the two test sets? (d) [2 points] What was the accuracy of your trained convolutional neural network on the two test sets? (e) [10 points] Did one of your implementations perform substantially better on one of the test sets than the other implementation did? If so, why? If not, why not? CMPUT 366 — Assignment #3 3 2. (Bayesian Learning) Suppose that you have three models (θ1, θ2, θ3) of changes in the price of a single stock. You know that one of these models is the true model. Each model gives the probability that tomorrow’s price will be higher than today’s price (yt+1), based on whether today’s price was higher than the price the day before (yt). So you can make money on average by buying the stock when p(yt+1 | yt, θ∗) > .5 and selling when p(yt+1 | yt, θ∗) < .5, where θ∗ is the true model. your prior belief is that θ1 and θ2 are equally likely to be true, and θ3 is three times more likely than θ1 to be true. you have a dataset d of past observations, and you have computed that p(d | θ1) = .00084 p(d | θ2) = .00105 p(d | θ3) = .00007. 3. [6 points] what are the posterior probabilities of each model being the true model? 4. [4 points] now suppose that you have run each model, and they make the following predic- tions: p(yt+1 | yt, θ1) = .75 p(yt+1 | yt, θ2) = .4 p(yt+1 | yt, θ3) = .6. what is the maximum a posterior estimate for p(yt+1 | yt)? based on the maximum a posteriori (map) estimate, would you be better off buying or selling? 5. [4 points] what is the estimate according to the posterior predictive distribution for p(yt+1 | yt)? (i.e., using model averaging.) based on the posterior predictive distribution (ppd), would you be better off buying or selling? cmput 366 — assignment #3 4 submission the assignment you downloaded from eclass is a single zip archive which includes this document as a pdf and its latex source as well as python files needed for the coding questions. you are to unzip the archive into an empty directory, work on the problems and then zip the directory into a new single zip archive for submission. each assignment is to be submitted electronically via eclass by the due date. your submission must be a single zip file containing: 1. a single pdf file with your answers; 2. file(s) with your python code. to generate the pdf file with your answers you can do any of the following: • insert your answers into the provided latex source file between \begin{answer} and \end{answer}. then run the source through latex to produce a pdf file; • print out the provided pdf file and legibly write your answers in the blank spaces under each question. make sure you write as legibly as possible for we cannot give you any points if we cannot read your hand-writing. then scan the pages and include the scan in your zip submission to be uploaded on eclass; • use your favorite text processor and type up your answers there. make sure you number your answers in the same way as the questions are numbered in this assignment. .5,="" where="" θ∗="" is="" the="" true="" model.="" your="" prior="" belief="" is="" that="" θ1="" and="" θ2="" are="" equally="" likely="" to="" be="" true,="" and="" θ3="" is="" three="" times="" more="" likely="" than="" θ1="" to="" be="" true.="" you="" have="" a="" dataset="" d="" of="" past="" observations,="" and="" you="" have="" computed="" that="" p(d="" |="" θ1)=".00084" p(d="" |="" θ2)=".00105" p(d="" |="" θ3)=".00007." 3.="" [6="" points]="" what="" are="" the="" posterior="" probabilities="" of="" each="" model="" being="" the="" true="" model?="" 4.="" [4="" points]="" now="" suppose="" that="" you="" have="" run="" each="" model,="" and="" they="" make="" the="" following="" predic-="" tions:="" p(yt+1="" |="" yt,="" θ1)=".75" p(yt+1="" |="" yt,="" θ2)=".4" p(yt+1="" |="" yt,="" θ3)=".6." what="" is="" the="" maximum="" a="" posterior="" estimate="" for="" p(yt+1="" |="" yt)?="" based="" on="" the="" maximum="" a="" posteriori="" (map)="" estimate,="" would="" you="" be="" better="" off="" buying="" or="" selling?="" 5.="" [4="" points]="" what="" is="" the="" estimate="" according="" to="" the="" posterior="" predictive="" distribution="" for="" p(yt+1="" |="" yt)?="" (i.e.,="" using="" model="" averaging.)="" based="" on="" the="" posterior="" predictive="" distribution="" (ppd),="" would="" you="" be="" better="" off="" buying="" or="" selling?="" cmput="" 366="" —="" assignment="" #3="" 4="" submission="" the="" assignment="" you="" downloaded="" from="" eclass="" is="" a="" single="" zip="" archive="" which="" includes="" this="" document="" as="" a="" pdf="" and="" its="" latex="" source="" as="" well="" as="" python="" files="" needed="" for="" the="" coding="" questions.="" you="" are="" to="" unzip="" the="" archive="" into="" an="" empty="" directory,="" work="" on="" the="" problems="" and="" then="" zip="" the="" directory="" into="" a="" new="" single="" zip="" archive="" for="" submission.="" each="" assignment="" is="" to="" be="" submitted="" electronically="" via="" eclass="" by="" the="" due="" date.="" your="" submission="" must="" be="" a="" single="" zip="" file="" containing:="" 1.="" a="" single="" pdf="" file="" with="" your="" answers;="" 2.="" file(s)="" with="" your="" python="" code.="" to="" generate="" the="" pdf="" file="" with="" your="" answers="" you="" can="" do="" any="" of="" the="" following:="" •="" insert="" your="" answers="" into="" the="" provided="" latex="" source="" file="" between="" \begin{answer}="" and="" \end{answer}.="" then="" run="" the="" source="" through="" latex="" to="" produce="" a="" pdf="" file;="" •="" print="" out="" the="" provided="" pdf="" file="" and="" legibly="" write="" your="" answers="" in="" the="" blank="" spaces="" under="" each="" question.="" make="" sure="" you="" write="" as="" legibly="" as="" possible="" for="" we="" cannot="" give="" you="" any="" points="" if="" we="" cannot="" read="" your="" hand-writing.="" then="" scan="" the="" pages="" and="" include="" the="" scan="" in="" your="" zip="" submission="" to="" be="" uploaded="" on="" eclass;="" •="" use="" your="" favorite="" text="" processor="" and="" type="" up="" your="" answers="" there.="" make="" sure="" you="" number="" your="" answers="" in="" the="" same="" way="" as="" the="" questions="" are="" numbered="" in="" this="">
Answered 1 days AfterMar 26, 2022

Answer To: CMPUT 366 — Assignment #3 1 CMPUT 366, Winter 2022 Assignment #3 Due: Friday, March 25, 2022,...

Sathishkumar answered on Mar 27 2022
102 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here