Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-254

Bernoulli Entropy from Natural Parameter

Problem

Return the Shannon entropy of a Bernoulli distribution in nats given its natural parameter eta:

p = 1 / (1 + exp(-eta)) H = -p * ln(p) - (1 - p) * ln(1 - p)

Hint

Entropy is symmetric around eta = 0, where the coin is fair.

Test cases

case 1
in: [0]
expected: 0.6931471805599453
case 2
in: [1]
expected: 0.5822031088882179
case 3
in: [-2]
expected: 0.36533385508720767
case 4
in: [2]
expected: 0.36533385508720784
Starter codePython
import math
def bernoulli_entropy_from_eta(eta):
    # Your code here
    pass

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