All problems
Hessian Trace by Finite Differences
Problem
Estimate the trace of the Hessian of f(x) = sum(coeffs[i] * x_i^3) with central second differences.
Each diagonal entry is approximated by (f(x + h e_i) - 2 f(x) + f(x - h e_i)) / h^2, and the trace is their sum. Given the coefficients and the point x, return the estimate using h = 1e-3; the formula is exact for this cubic function.
Hint
The trace of the Hessian is the Laplacian, and the analytic value here is 6 * sum(coeffs[i] * x_i).
Test cases
case 1
in: [[1,1],[1,2]]
expected: 18
case 2
in: [[2,-1],[0,1]]
expected: -6
case 3
in: [[1],[0]]
expected: 0
case 4
in: [[1,2,3],[1,1,1]]
expected: 36
Starter codePython
def hessian_trace_fd(coeffs, x, h=1e-3):
# Your code here
pass4 test cases · run your code against them in the editor