Skip to content
DeepForgeby svx
All problems
MediumCalculusca-331

Weighted Log-Sum-Exp Gradient

Problem

For f(w) = log(sum_i exp(a_i w_i)), the gradient is p_i * a_i where p is the softmax of the values a_i w_i.

Given the weight vector a and parameters w, return the gradient list.

Hint

Chain rule: the log-sum-exp derivative is the softmax times the inner scale a_i.

Test cases

case 1
in: [[1,1],[0,0]]
expected: [0.5,0.5]
case 2
in: [[2,0.5],[1,2]]
expected: [1.4621171572600098,0.13447071068499755]
case 3
in: [[-1,3],[0,1]]
expected: [-0.04742587317756679,2.8577223804673]
Starter codePython
def weighted_logsumexp_gradient(a, w):
    # Your code here
    pass

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