Interactive Binary Entropy Explorer
Overview
Section titled “Overview”This demonstration lets you explore the binary entropy function interactively. See how entropy changes with probability, understand why it’s maximized at , and visualize the relationship between uncertainty and information.
Demonstrates Concepts
Section titled “Demonstrates Concepts”- [[Shannon Entropy]]
- [[Binary Entropy Function]]
- [[Maximum Entropy Principle]]
Interactive Elements
Section titled “Interactive Elements”| Control | Range | Default | Effect |
|---|---|---|---|
| Probability | 0.01 – 0.99 | 0.5 | Sets the bias of the coin |
| Show tangent | On/Off | On | Displays derivative at current point |
| Show area | On/Off | Off | Shades area under curve up to |
| Zoom level | 1x – 4x | 1x | Magnifies region around current |
How to Use
Section titled “How to Use”- Drag the probability slider to change the coin’s bias. Watch the entropy value update.
- Observe the symmetry: Notice that . A coin biased toward heads has the same entropy as one equally biased toward tails.
- Find the maximum: The peak at shows that maximum uncertainty (1 bit) occurs for a fair coin.
- Enable the tangent line: See how the derivative is positive for and negative for .
- Explore the edges: As or , entropy approaches 0 (certainty).
What to Notice
Section titled “What to Notice”[!tip] Key Observations
- At : Entropy equals exactly 1 bit. This is the “hardest” coin to predict.
- At and : Entropy is about 0.47 bits. You need less than half a question on average.
- The curve is concave: Mixing two distributions always increases entropy (Jensen’s inequality).
- Derivative at : The tangent is horizontal—this is the maximum.
Mathematical Background
Section titled “Mathematical Background”The binary entropy function:
Properties visualized:
- Domain: , with by convention
- Range: bits
- Symmetry:
- Maximum:
- Concavity: everywhere
The derivative:
This is positive when and negative when .
Manipulate[ Module[{h, dh, tangentLine, pRange, hRange}, (* Binary entropy function *) h[x_] := If[x == 0 || x == 1, 0, -x Log2[x] - (1 - x) Log2[1 - x]]; dh[x_] := Log2[(1 - x)/x];
(* Tangent line at current point *) tangentLine[x_] := h[p] + dh[p] (x - p);
(* Zoom handling *) pRange = If[zoom > 1, {Max[0.01, p - 0.5/zoom], Min[0.99, p + 0.5/zoom]}, {0.01, 0.99}]; hRange = If[zoom > 1, {Max[0, h[p] - 0.5/zoom], Min[1.1, h[p] + 0.5/zoom]}, {0, 1.1}];
Plot[ {h[x], If[showTangent, tangentLine[x], Nothing]}, {x, pRange[[1]], pRange[[2]]}, PlotRange -> {pRange, hRange}, PlotStyle -> {{Blue, Thickness[0.003]}, {Red, Dashed}}, AxesLabel -> {"p", "H(p)"}, PlotLabel -> Style[ StringForm["H(``) = `` bits", NumberForm[p, {2, 2}], NumberForm[h[p], {2, 4}] ], 14, Bold], Filling -> If[showArea, {1 -> {Axis, Opacity[0.2, Blue]}}, None], GridLines -> {{0.5}, {1}}, GridLinesStyle -> Directive[Gray, Dashed], Epilog -> { PointSize[Large], Red, Point[{p, h[p]}], If[showTangent, {Thin, Red, Line[{{pRange[[1]], tangentLine[pRange[[1]]]}, {pRange[[2]], tangentLine[pRange[[2]]]}}]}, {}] }, ImageSize -> 500 ] ], {{p, 0.5, "Probability p"}, 0.01, 0.99, Appearance -> "Labeled"}, {{showTangent, True, "Show tangent"}, {True, False}}, {{showArea, False, "Show area"}, {True, False}}, {{zoom, 1, "Zoom"}, {1 -> "1x", 2 -> "2x", 4 -> "4x"}}, ControlPlacement -> Top, TrackedSymbols :> {p, showTangent, showArea, zoom}]Extensions
Section titled “Extensions”- Add comparison with ternary entropy (3 outcomes)
- Show relationship to mutual information
- Animate through values to show the full curve being traced
- Add information about what “1 bit” means in practical terms
Related Demonstrations
Section titled “Related Demonstrations”- [[Rate-Distortion Explorer]]
- [[Channel Capacity Visualizer]]
- [[Entropy of English Text]]