Initializing playground…
← Back to roadmap

Information Theory

Shannon entropy, KL & Jensen-Shannon divergence, mutual information, Rényi and Tsallis entropy — mirrors scipy.stats.entropy and related utilities.

1 — Shannon entropy

entropy(pk) computes H(p) = −∑ pᵢ log pᵢ. Use base=2 for bits, omit base for nats.

JavaScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

2 — KL divergence and cross-entropy

entropy(pk, qk) computes D_KL(p‖q). klDivergence is an explicit alias. crossEntropy(p, q) = H(p) + D_KL(p‖q).

JavaScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

3 — Jensen-Shannon divergence and distance

JSD is a symmetric, bounded (0 ≤ JSD ≤ log 2) measure of similarity between distributions. jsDistance is the square root — a proper metric satisfying the triangle inequality.

JavaScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

4 — Mutual information from observations

mutualInformation(xy) accepts an array of [x, y] pairs and estimates I(X;Y) = H(X) + H(Y) − H(X,Y). Related: jointEntropy, conditionalEntropy.

JavaScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

5 — Normalised MI and variation of information

normalizedMI scales I(X;Y) to [0, 1]. Four normalisation methods available. variationOfInformation is a metric on partitions: VI = H(X|Y) + H(Y|X).

JavaScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

6 — Rényi and Tsallis entropy

Generalisations of Shannon entropy. Rényi: H_α(X) = (1/(1−α)) log(∑ pᵢ^α). Tsallis: S_q(X) = (1/(q−1))(1 − ∑ pᵢ^q). Both converge to Shannon at α/q → 1.

JavaScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent