Skip to content
DeepForgeby svx
All problems
MediumCalculusca-370

Entropy Gradient in Probabilities

Problem

For the entropy H(p) = -sum_i p_i log(p_i), the partial derivative with respect to p_i is -log(p_i) - 1.

Given a strictly positive probability vector, return the gradient list.

Hint

Differentiate p log p with the product rule.

Test cases

case 1
in: [[0.5,0.5]]
expected: [-0.3068528194400547,-0.3068528194400547]
case 2
in: [[0.25,0.75]]
expected: [0.3862943611198906,-0.7123179275482191]
case 3
in: [[0.2,0.3,0.5]]
expected: [0.6094379124341003,0.20397280432593612,-0.3068528194400547]
Starter codePython
def entropy_gradient_in_probabilities(probs):
    # Your code here
    pass

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