Skip to content
DeepForgeby svx
All problems

Preference Label Uncertainty

Problem

Compute the binary entropy of a preference vote split in bits.

With p = votes_a / (votes_a + votes_b), return -p * log2(p) - (1 - p) * log2(1 - p), skipping zero terms. A zero total returns 0.0.

Hint

Maximum uncertainty is one bit when annotators split evenly.

Test cases

case 1
in: [1,1]
expected: 1
case 2
in: [3,1]
expected: 0.8112781244591328
case 3
in: [5,0]
expected: 0
case 4
in: [0,0]
expected: 0
Starter codePython
import math
def preference_label_uncertainty(votes_a, votes_b):
    # Your code here
    pass

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