All problems
Differential Entropy of Uniform
Problem
Return the differential entropy in bits of a uniform distribution on [a, b]:
h = log2(b - a)
Return 0.0 when b <= a.
Hint
Differential entropy can be negative for narrow supports; this support starts at width 1.
Test cases
case 1
in: [0,1]
expected: 0
case 2
in: [0,4]
expected: 2
case 3
in: [-1,1]
expected: 1
case 4
in: [2,10]
expected: 3
Starter codePython
import math
def de_uniform(a, b):
# Your code here
pass4 test cases · run your code against them in the editor