CS181 Pset 0 (Solution)

$ 20.99
Category:

Description

The below problems were written so that you can self-assess your comfort with CS 181’s mathematical prerequisites. We strongly encourage students who have completed the prerequisites to still complete this optional HW to review concepts that are foundational to the course. The difficulty level of these problems is not intended to reflect the difficulty of future homework assignments but rather test background conceptual understanding.
The problems are divided up into two portions: Math and Programming.
1 Mathematical Problems
Problem 4
For an invertible matrix A show that where |A| is the determinant of A.

Problem 2
Assume matrix X has shape (n × d), and vector w has shape (d × 1).
(a) What shape is y = Xw?
(b) What shape is (XTX)−1?
(c) Using y from part (a), what shape is (XTX)−1XTy?
(d) Assume vector w′ = wT. What shape is y′ = Xw′T?
Problem 3
Write u = u∥ +u⊥ where u∥ = ⟨⟨uv,,vv⟩⟩v. is the projection of u onto v. Prove that ⟨u∥,u⊥⟩ = 0 and that u = u∥ if and only if u is a scaled multiple of v.
Problem 5
Hint: As a first step, you can expand x ), where x = (x1,…,xn).
(b) Let f(w,x) = (1 − wTx)2. Find
(c) Let A be a symmetric n-by-n matrix. If Ax + wTx, find
Problem 6
Solve the following:
(a) Verify that Var(aX + b) = a2Var(X).
Hint: As a first step, you can expand Var(aX +b) using the definition of variance. Simplify using properties of expectations.
(b) Suppose that X1,…,Xn are i.i.d., scalar random variables with mean µ and variance σ2. Let X¯ be the mean . Find E(X¯) and Var(X¯).
Problem 7
Prove or come up with counterexamples for the following statements:
(a) Random variables A and B are conditionally independent given C. Does this imply that A and B are unconditionally independent?
(b) Random variables A and B are independent. Does this imply that A and B are conditionally independent given some random variable C?
Problem 10
Using the probability density function (PDF) of X ∼ N(0,1) show that X has mean 0 and variance 1.
Hint: The PDF is . For the mean, you can reason about the properties of the PDF itself to get the answer without integration techniques. For the variance, use integration by parts with u = x and dv = xe−x2/2dx and the fact that the PDF itself integrates to 1.
Problem 8
Suppose you undergo a test for a disease whose frequency in the population is 1% (i.e. the probability of any given person having the disease is 1%). The test for the disease has a 5% false positive rate (i.e. given that you don’t have the disease, there’s a 5% chance you test positive) and a 10% false negative rate (i.e. given that you do have the disease, there’s a 10% chance that you test negative).
Suppose you take the test and it comes back positive. What is the probability that you have the disease?
Problem 9
Show that for scalar random variables X,Y that Var(X + Y ) = Var(X) + Var(Y ) + 2Cov(X,Y ).
Problem 11
(Optional) A random point (X,Y,Z) is chosen uniformly in the ball
B = {(x,y,z) : x2 + y2 + z2 ≤ 1}
(a) Find the joint PDF of (X,Y,Z).
(b) Find the joint PDF of (X,Y ) (this is the marginal distribution on X and Y ).
(c) Write an expression for the marginal PDF of X, as an integral.
Problem 12
Suppose that the below table represented the joint probability mass function (PMF) of X and Y :
Y = 1 Y = 0
X = 1
X = 0

(a) Calculate the marginal probability P(Y = 1). In the context of this problem, what does this probability represent?
(b) Calculate the conditional probability P(Y = 1|X = 1). In the context of this problem, what does this probability represent?
(c) Are X and Y independent? Why or why not? What is the interpretation of this?
Problem 13
In her most recent work-from-home shopping spree, Nari decided to buy several house plants. She would like for them to grow as tall as possible, but needs your calculus help to understand how to best take care of them.
(a) After perusing the internet, Nari learns that the height y in mm of her Weeping Fig plant can be directly modeled as a function of the oz of water x she gives it each week:
y = −3×2 + 72x + 70
Is this function concave, convex, or neither? Explain why or why not.
(b) Solve analytically for the critical points of this expression (i.e., where the derivative of the function is zero). For each critical point, use the second-derivative test to identify if each point is a max or min point, and use arguments about the global structure (e.g., concavity or convexity) of the function to argue whether this is a local or global optimum.
(c) How many oz per week should Nari water her plant to maximize its height? With this much water how tall will her plant grow?
(d) Nari also has a Money Tree plant. The height y in mm of her Money Tree can be directly modeled as a function of the oz of water x she gives it per week:
y = −x4 + 16×3 − 93×2 + 230x − 190
Is this function concave, convex, or neither? Explain why or why not.
Credits: Problems 11 and 12 were inspired by Exercise 7.19 and Example 7.1.5 in Blitzstein & Hwang’s “Introduction to Probability”.
2 Programming Exercises
We expect students to be familiar with Python and comfortable with writing non-trivial programs. Later homeworks in the course will often require working with data and matrices, where the numpy package will be helpful.
Problem 14
First, we have a Python data exercise.
1. Using the random seed 181, generate N = 20 data points (x,y) where x is uniformly sampled from (−10,10) and y is uniformly sampled from (20,80). (To get consistent answers with the staff solution, use numpy.)
2. (Optional) Save your data into two columns in a .csv file, and read it back out.
3. Let f(x,y) = (y+10)·x/5. Compute zi = f(xi,yi) for i ∈ 1…N. Report the mean and standard deviation of {z1,…,zN}.
4. Identify the data point (x,y) with the largest y-value in the data set.
5. Compute the sum of all the y-values of points with positive x-value.
Problem 15
Here, we will practice using the Python package numpy.
1. Using np.arange or np.linspace, create a numpy array of all the nonnegative integers starting at 0 and ending at 9.
2. Using np.reshape, reshape the array so it’s 2 dimensional with size (2,5). Hint: the first row should be [0,1,2,3,4].
3. Using np.vstack, add a row to the bottom of the matrix from the previous part so that the matrix contains all of the nonnegative integers starting from 0 and ending at 14 in ascending order left to right, then top to bottom.
4. Using np.ones, np.reshape, and np.hstack, add a column to the right of the matrix from the previous part that is all ones.
5. Using np.dot, perform a matrix-vector multiplication with the matrix from the previous part with the vector [0,1,0,0,0,0].
6. Using np.sum and some of your own logic, find the sum of all the numbers in the matrix from 4.
that are even.

Reviews

There are no reviews yet.

Be the first to review “CS181 Pset 0 (Solution)”

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