All problems
Collision Entropy
Problem
Return the collision entropy (Renyi entropy of order 2) in bits:
H2 = -log2(sum(p_i^2))
A larger collision probability means lower entropy.
Hint
The sum of squared probabilities is the probability that two independent draws collide.
Test cases
case 1
in: [[0.5,0.5]]
expected: 1
case 2
in: [[1]]
expected: 0
case 3
in: [[0.25,0.25,0.25,0.25]]
expected: 2
case 4
in: [[0.5,0.25,0.25]]
expected: 1.415037499278844
Starter codePython
import math
def collision_entropy(probs):
# Your code here
pass4 test cases · run your code against them in the editor