Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-010

Pointwise Mutual Information

Problem

Compute the pointwise mutual information in bits:

PMI = log2(P(x, y) / (P(x) * P(y)))

The joint and marginal probabilities are passed as separate arguments.

Hint

PMI is positive when the events co-occur more than chance would predict.

Test cases

case 1
in: [0.25,0.5,0.5]
expected: 0
case 2
in: [0.5,0.5,0.5]
expected: 1
case 3
in: [0.2,0.5,0.5]
expected: -0.3219280948873623
case 4
in: [0.125,0.5,0.5]
expected: -1
Starter codePython
import math
def pointwise_mi(pxy, px, py):
    # Your code here
    pass

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