All problems
Weighted Log-Sum-Exp Hessian Diagonal
Problem
For f(w) = log(sum_i exp(a_i w_i)), the diagonal of the Hessian with respect to w is p_i (1 - p_i) a_i^2, where p is the softmax of a_i w_i.
Given a and w, return the diagonal list.
Hint
Differentiate each softmax entry once more and apply the chain rule factor a_i^2.
Test cases
case 1
in: [[1,1],[0,0]]
expected: [0.25,0.25]
case 2
in: [[2,0.5],[1,2]]
expected: [0.7864477329659274,0.04915298331037046]
case 3
in: [[1,1,1],[1,2,3]]
expected: [0.08192506906499324,0.1848364465099787,0.2226954265346234]
Starter codePython
def weighted_logsumexp_hessian_diag(a, w):
# Your code here
pass3 test cases · run your code against them in the editor