All problems
Mutual Information of Adjacent Letters
Problem
Given a 2D matrix of adjacent-letter counts, normalize it into a joint distribution and return the mutual information in bits:
I = sum p(i, j) * log2(p(i, j) / (p(i) * p(j)))
Skip cells with zero count.
Hint
Perfectly correlated letters carry one bit; independent letters carry none.
Test cases
case 1
in: [[[1,1],[1,1]]]
expected: 0
case 2
in: [[[4,0],[0,4]]]
expected: 1
case 3
in: [[[1,2],[3,4]]]
expected: 0.005802149014345649
case 4
in: [[[1,0],[0,1]]]
expected: 1
Starter codePython
import math
def adjacent_letter_mi(counts):
# Your code here
pass4 test cases · run your code against them in the editor