All problems
Joint Entropy from Counts
Problem
Compute the joint entropy H(X, Y) in bits from a 2D table of counts. Normalize by the grand total and skip zero entries in the sum. Return 0.0 for an empty or all-zero table.
Hint
Convert every cell to a probability and add -p log2 p.
Test cases
case 1
in: [[[1,1],[1,1]]]
expected: 2
case 2
in: [[[2,0],[0,2]]]
expected: 1
case 3
in: [[[1,2],[3,4]]]
expected: 1.8464393446710154
case 4
in: [[[0,0],[0,0]]]
expected: 0
case 5
in: [[[3]]]
expected: 0
Starter codePython
import math
def joint_entropy_counts(counts):
# Your code here
pass5 test cases · run your code against them in the editor