Explore Library
Code QuizIntermediate

KL Divergence Direction

Identify the inverted ratio that breaks this KL divergence implementation.

Codepython
import math

def kl_divergence(p, q):
    # KL(p || q)
    return sum(pi * math.log(qi / pi) for pi, qi in zip(p, q))

print(kl_divergence([0.9, 0.1], [0.5, 0.5]))

What is the bug in this KL divergence computation?