Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-006

Conditional Entropy H(X|Y)

Problem

Given a 2D joint distribution joint[x][y], compute the conditional entropy H(X|Y) in bits using

H(X|Y) = H(X, Y) - H(Y)

where H(Y) is the entropy of the column marginals. Skip zero terms.

Hint

H(X|Y) = H(X, Y) - H(Y) because entropy is additive over the chain rule.

Test cases

case 1
in: [[[0.25,0.25],[0.25,0.25]]]
expected: 1
case 2
in: [[[0.5,0],[0,0.5]]]
expected: 0
case 3
in: [[[0.1,0.2],[0.3,0.4]]]
expected: 0.8754887502163469
case 4
in: [[[0.5,0.25],[0,0.25]]]
expected: 0.5
Starter codePython
import math
def conditional_entropy(joint):
    # Your code here
    pass

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