def weighted_mse_grad(w, X, y, V): """ Calculate gradient of the weight MSE loss in the given point w Parameters ---------- w: array_like Current point, in which we want to evaluate gradient (vector with k+1 elements) X: array_like Design matrix with N rows and k+1 columns y: array_like Vector with N observations of the target variable V: array_like Diagonal matrix N x N, with the weights Returns ---------- out: ndarray vector of gradient, k+1 """ # your code here       # TEST weighted_mse_grad() w = np.zeros(5) X = np.random.randn(10, 5) y = np.ones(10) V = np.diag(np.ones(10)) L_grad = weighted_mse_grad(w, X, y, V) assert(L_grad.shape == (5,)) w = np.zeros(5) X = np.eye(5) y = np.ones(5) V = np.diag(np.ones(5)) L_grad = weighted_mse_grad(w, X, y, V) assert(L_grad.shape == (5,)), 'The shape of the output on the test case is wrong' assert(np.allclose(5 * L_grad,- y * 2)), 'The values of the output on the test case is wrong'

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

def weighted_mse_grad(w, X, y, V):
"""
Calculate gradient of the weight MSE loss in the given point w

Parameters
----------
w: array_like
Current point, in which we want to evaluate gradient (vector with k+1 elements)
X: array_like
Design matrix with N rows and k+1 columns
y: array_like
Vector with N observations of the target variable
V: array_like
Diagonal matrix N x N, with the weights

Returns
----------
out: ndarray
vector of gradient, k+1
"""
# your code here

 

 

 

# TEST weighted_mse_grad()
w = np.zeros(5)
X = np.random.randn(10, 5)
y = np.ones(10)
V = np.diag(np.ones(10))

L_grad = weighted_mse_grad(w, X, y, V)
assert(L_grad.shape == (5,))


w = np.zeros(5)
X = np.eye(5)
y = np.ones(5)
V = np.diag(np.ones(5))
L_grad = weighted_mse_grad(w, X, y, V)
assert(L_grad.shape == (5,)), 'The shape of the output on the test case is wrong'
assert(np.allclose(5 * L_grad,- y * 2)), 'The values of the output on the test case is wrong'

Calculate gradient of the weighted MSE loss with respect to parameters for the model
V„L = Vµ||V12 (y – Xw)||? =?
w N
-
Hints: You can use formulas from the lecture.
kxn
Given vector x E R" and matrix A E R*
V||x||} = 2x
V,AX = A"
Using the formula frm the gradient, implement the function weighted_mse_grad , which calculates gradient for any given vector w.
Transcribed Image Text:Calculate gradient of the weighted MSE loss with respect to parameters for the model V„L = Vµ||V12 (y – Xw)||? =? w N - Hints: You can use formulas from the lecture. kxn Given vector x E R" and matrix A E R* V||x||} = 2x V,AX = A" Using the formula frm the gradient, implement the function weighted_mse_grad , which calculates gradient for any given vector w.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY