Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-204

Hessian of Least Squares

Problem

Return the Hessian of the least squares objective f(x) = ||A*x - b||_2^2 with respect to x:

H = 2 * A^T A

The Hessian is independent of b and is positive semidefinite.

Hint

Expanding ||Ax - b||^2 gives x^T A^T A x minus linear terms, so the Hessian is 2 A^T A.

Test cases

case 1
in: [[[1,1],[1,2],[1,3]]]
expected: [[6,12],[12,28]]
case 2
in: [[[1,0],[0,1]]]
expected: [[2,0],[0,2]]
case 3
in: [[[1,0],[0,1],[0,0]]]
expected: [[2,0],[0,2]]
case 4
in: [[[2],[3]]]
expected: [[26]]
Starter codePython
def hessian_least_squares(A):
    # Your code here
    pass

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