Premium problem130. KL Divergence

Easy Locked

Return DKL(P∥Q)D_{KL}(P \parallel Q) in bits.

DKL(P∥Q)=∑ipilog⁡2piqiD_{KL}(P \parallel Q) = \sum_i p_i \log_2 \frac{p_i}{q_i}

Skip terms where pi=0p_i = 0. It is not symmetric, and it is not a distance: DKL(P∥Q)D_{KL}(P \parallel Q) generally differs from DKL(Q∥P)D_{KL}(Q \parallel P), which is exactly why the direction matters when it appears in a loss.

Input

p = [0.5, 0.5]
q = [0.5, 0.5]

Output

0.0

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)