Skip to content
DeepForgeby svx
All problems
MediumCalculusca-319

Linear Residual Gradient Vector

Problem

For f(x) = ||A x - b||^2 with constant matrix A, the gradient with respect to x is 2 * A^T (A x - b).

Given A as nested rows, x, and b, return the gradient list.

Hint

Residual first, then multiply by twice the transpose of A.

Test cases

case 1
in: [[[1,0],[0,1]],[1,2],[0,0]]
expected: [2,4]
case 2
in: [[[2],[4]],[1],[2,4]]
expected: [0]
case 3
in: [[[1,2],[3,4]],[1,1],[1,1]]
expected: [40,56]
Starter codePython
def linear_residual_gradient_vector(a, x, b):
    # Your code here
    pass

3 test cases · run your code against them in the editor