All problems
Entropy of a Geometric Distribution
Problem
Compute the entropy in bits of a geometric distribution on {1, 2, 3, ...} with success probability p:
H = (-(1 - p) * log2(1 - p) - p * log2(p)) / p
Return 0.0 when p = 1.
Hint
For p = 1/2 the numerator is 1, so H = 1 / p = 2 bits.
Test cases
case 1
in: [0.5]
expected: 2
case 2
in: [0.25]
expected: 3.2451124978365313
case 3
in: [0.1]
expected: 4.689955935892812
case 4
in: [1]
expected: 0
Starter codePython
import math
def geometric_entropy(p):
# Your code here
pass4 test cases · run your code against them in the editor