Jensen-Shannon Divergence

Probability Theory DS practice problem on Onlearn.

Difficulty: medium.

Topics: Understanding Jensen-Shannon Divergence (JSD) for Probability Distributions, Midpoint distribution M, Log-sum inequality, Non-negativity of JSD, Symmetry of divergence, Boundedness between 0 and 1 (log 2), Probability Theory, Information Theory, Statistical Distance Metrics, Numerical Analysis, Vector Calculus, Probability Distributions, Entropy, Kullback-Leibler Divergence, Information Geometry, Relative Entropy.

Given two discrete probability distributions P and Q represented as lists of floats, implement a function that calculates the Jensen Shannon Divergence. The JSD is defined as the average of the KL divergence of each distribution from their midpoint distribution M = 0.5 (P + Q). Ensure the function handles potential log(0) cases by treating 0 log(0) as 0.