PythiloLesson 5 of 12 · progress kept in this browser

Use a symmetric distribution divergence

Jensen-Shannon divergence compares two distributions through their midpoint. It is symmetric and remains finite for disjoint support, unlike a one-way KL divergence with a zero denominator. The logarithm base determines the scale; this exercise uses natural logs.

A value near zero means similar marginal proportions, not identical joint behavior or stable model quality. Counts must share the same bin vocabulary. Empty or negative histograms are invalid observations, rather than another form of drift. Keep feature construction and bin definitions versioned with the monitoring configuration.

import math
p=[1.,0.];q=[0.,1.];m=[.5,.5]
print(sum(x*math.log(x/y) for x,y in zip(p,m) if x))
Your task

Implement js_divergence(a,b), normalizing equal nonempty nonnegative finite count arrays with positive totals. Compute half KL(p||m)+half KL(q||m), skipping zero numerator terms.