CS589 – (Solution)

$ 29.99
Category:

Description

Homework 4: Bayesian Prediction

HW04
— HW04.pdf
— Data
— Submission
|–Code
|–Figures
The data files for each data set are in ‘Data’ directory respectively. You will write your code under the Submission/Code directory. Make sure to put the deliverables (explained below) into the respective directories.
Deliverables: This assignment has two types of deliverables:
• Report: The solution report will give your answers to the homework questions (listed below). Try to keep the maximum length of the report to 5 pages in 11 point font, including all figures and tables. Reports longer than five pages will only be graded up until the first five pages. You can use any software to create your report, but your report must be submitted in PDF format. You can use an additional two pages to answer extra credit questions only.
Submitting Deliverables: When you complete the assignment, you will upload your report and your code using the Gradescope.com service. Place your final code in Submission/Code. If you used Python to generate report figures, place them in Submission/Figures. Finally, create a zip file of your submission directory, Submission.zip (NO rar, tar or other formats). Upload this single zip file on Gradescope as your solution to the ’HW04-Bayesian-Programming’ assignment. Gradescope will run checks to determine if your submission contains the required files in the correct locations. Finally, upload your pdf report to the ’HW04Bayesian-Report’ assignment. When you upload your report please make sure to select the correct pages for each question respectively. Failure to select the correct pages will result in point deductions. The submission time for your assignment is considered to be the later of the submission timestamps of your code and report submissions.
Task: In this homework you will experiment with making Bayesian predictions in a simple toy model. The model contains inputs x in 1-d and outputs y in 1-d. The possible predictors are the functions
.
These are plotted below.
Candidate predictors f
We take the following prior over m ∈ {0,1,··· ,9}:
m 0 1 2 3 4 5 6 7 8 9
p(m) .2 .2 .2 .1 .1 .1 .025 .025 .025 .025
We take the following probabilistic model, with σ = .1 fixed:
.
1. Prior: Implement a function which returns the given prior p(m) for each value of m ∈ {0,··· ,9}. Make a bar chart of the values (with m on the x-axis) and plot it.
2. Likelihood: You are given a set of 10 training inputs and outputs, stored as x.csv and y.csv. Load this data and implement a function to compute the likelihood
10
p(Data|m) = Yp(yi|xi,m).
i=1
Make a bar chart of the values (with m on the x-axis) and plot it.
3. Posterior Equation: Give a mathematical equation for the posterior p(m|Data) in terms of the prior p(m) and the likelihood p(Data). Make sure that this equation is normalized.
4. Posterior Implementation. Implement a function to compute the posterior p(m|Data). Make sure that this is normalized (sums to one). Make a bar chart of the values (with m on the x-axis) and plot it.
5. MAP estimate: Implement a function to compute the “MAP” estimate mˆMAP = argmaxm p(m|Data). What value of m do you find, and what is the posterior probability of it? (Give numbers.)
6. MAP predictions: You are given a set of 100 test inputs and outputs, stored as x_test.csv. Using your map estimate mˆMAP plot your predicted outputs with fmˆMAP(xi) as circles. Then, load the 100 test outputs, stored as y_test.csv. Add these to the same plot, labeled with crosses. Show the plot. Make sure to label all axes, and to have a legend for the two types of markers.
7. MAP error: Compute the mean-squared error of your MAP estimate, MAP(xi))2 , where x and y represent test data. Give the final error as a number.
8. Bayes estimate: Implement a function to compute the Bayes predictions
9
fBayes(x) = X p(m|Data)fm(x).
m=0
Please note, p(m|Data) is the posterior you computed in (4). As in step (6) above, make a plot comparing these to the true outputs in the test data.
9. Bayes error: Compute the mean-squared error of your Bayes estimate, Bayes(xi))2 , where xi,yi ∈ test_data. Give the final error as a number.
10. Thoughts: Is the Bayes or the MAP error lower? Given your plot of the posterior from step (4), can you reason informally about why this might be the case?

Reviews

There are no reviews yet.

Be the first to review “CS589 – (Solution)”

Your email address will not be published. Required fields are marked *