All problems
Loss-Landscape Curvature
Problem
The curvature of the quadratic loss f(w) = 0.5 * w^T A w along the unit direction u is the Rayleigh quotient u^T A u / (u^T u).
For A = [[a, b], [b, c]] and direction (d1, d2), return (a*d1^2 + 2*b*d1*d2 + c*d2^2) / (d1^2 + d2^2).
Hint
The Rayleigh quotient lies between the smallest and largest Hessian eigenvalues.
Test cases
case 1
in: [2,0,2,1,1]
expected: 2
case 2
in: [4,0,1,1,1]
expected: 2.5
case 3
in: [1,2,1,1,-1]
expected: -1
case 4
in: [3,0,3,3,4]
expected: 3
Starter codePython
def landscape_curvature(a, b, c, d1, d2):
# Your code here
pass4 test cases · run your code against them in the editor