Skip to content
DeepForgeby svx
All problems

Entropy Bonus

Problem

Compute the entropy of an action distribution in nats: H = -sum p * ln(p).

Skip zero probabilities and return 0.0 for an empty distribution.

Hint

Maximum entropy is ln(n) for a uniform distribution over n actions.

Test cases

case 1
in: [[0.5,0.5]]
expected: 0.6931471805599453
case 2
in: [[1,0]]
expected: 0
case 3
in: [[0.25,0.25,0.25,0.25]]
expected: 1.3862943611198906
case 4
in: [[]]
expected: 0
Starter codePython
import math
def entropy_bonus(probs):
    # Your code here
    pass

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