Implement a function to compute the Pointwise Mutual Information (PMI) given the joint occurrence count of two events, their individual counts, and the total number of samples. PMI measures how much the actual joint occurrence of events differs from what we would expect by chance.
Examples
Example 1:
Input:
compute_pmi(50, 200, 300, 1000)Output:
-0.263Explanation: The PMI calculation compares the actual joint probability (50/1000 = 0.05) to the product of the individual probabilities (200/1000 * 300/1000 = 0.06). Thus, PMI = log₂(0.05 / (0.2 * 0.3)) ≈ -0.263, indicating the events co-occur slightly less than expected by chance.
Starter Code
import numpy as np
def compute_pmi(joint_counts, total_counts_x, total_counts_y, total_samples):
# Implement PMI calculation here
passPython3
ReadyLines: 1Characters: 0
Ready