§3.10 Useful properties of common functions
Two functions recur constantly when building probability distributions. The logistic sigmoid logistic sigmoid σ(x) = 1/(1+e⁻ˣ) ∈ (0,1): produces Bernoulli φ; saturates at both extremes; σ' = σ(1−σ). defined in ch. 3 — open in glossary has range — exactly a Bernoulli — but saturates at both extremes (flat, insensitive to small input changes). The softplus softplus ζ(x) = log(1+eˣ) ∈ (0,∞): softened max(0,x); produces σ/β params; ζ' = σ. defined in ch. 3 — open in glossary has range — a valid or for a Gaussian — and is a smoothed (“softened”) version of the positive part :
The identities the book suggests memorizing (eqs 3.33–3.41) — click a row for why it matters:
| Identity | Reading | |
|---|---|---|
| 3.34 | σ'(x) = σ(x)(1−σ(x)) | self-referential derivative |
| 3.35 | 1 − σ(x) = σ(−x) | complement symmetry |
| 3.36 | log σ(x) = −ζ(−x) | log-sigmoid IS softplus |
| 3.37 | ζ'(x) = σ(x) | σ is the slope of ζ |
| 3.38 | σ⁻¹(x) = log(x/(1−x)) | the logit |
| 3.41 | ζ(x) − ζ(−x) = x | soft positive/negative parts |
§3.11 Bayes’ rule
Knowing but needing happens constantly; with the prior , Bayes’ rule bayes rule P(x|y) = P(x)P(y|x)/P(y), with P(y) = Σ_x P(y|x)P(x) — invert a conditional using the prior. defined in ch. 3 — open in glossary inverts the conditional:
Term by term
| the prior — belief before the observation | known | |
| the likelihood — how the observation behaves under each x | known | |
| usually not given, but computable: Σₓ P(y|x)P(x) — no extra knowledge needed | normalizer | |
| the posterior — belief after the observation | wanted |
(It follows directly from the conditional definition; Bayes found a special case, Laplace the general form.)
Worked example — the classic diagnostic surprise
Disease prevalence ; test sensitivity ; false-positive rate . Then , so — a positive test means only a 9 % chance of disease, because the prior is so small. Intuition fails here; the rule does not.
§3.12 Technical details of continuous variables
Rigorous continuous probability needs measure theory; the book keeps just three take-aways. (1) Pathological sets (fractal-like, built from the infinite precision of the reals) can break naive integration — measure theory characterizes the safe sets, and everything integrated in this book is safe. (2) A set of measure zero measure zero A set occupying no volume (points, lines in ℝ²); 'almost everywhere' = except on such a set. defined in ch. 3 — open in glossary occupies no volume (points, lines in , countable unions of such); a property holding almost everywhere holds except on such a set — good enough for most purposes. (3) The change-of-variables trap: for with invertible smooth , it is tempting but wrong to write .
Aside — the bug, with numbers
Let and … the book uses ‘s cousin: suppose . Then would be 1 on and 0 elsewhere — integrating to , not 1. The missing ingredient: distorts space, so density must be corrected by how much an infinitesimal interval stretches.
Preserving gives the correct rule — in higher dimensions the stretch factor is §2.11’s determinant, applied to the Jacobian matrix :
Term by term
| the invertible, continuous, differentiable transformation between the variables | ℝⁿ → ℝⁿ | |
| the Jacobian — the local linear map of the transformation | n×n | |
| how much g locally expands or contracts volume (§2.11) — the density correction | scalar ≥ 0 |
§3.13 Information theory
Born for optimal codes over noisy channels, information theory gives ML its tools for characterizing distributions and comparing them. The seed intuition: learning that an unlikely event occurred is more informative (“solar eclipse this morning” ≫ “the sun rose”). Three requirements — certain events carry zero information, less likely means more information, independent events add — force one definition:
Term by term
| the self-information of observing x | nats (log base e; bits if base 2) | |
| the only shape satisfying all three requirements: P=1 → 0 info; smaller P → more; products → sums | monotone ↓ |
Self-information self-information I(x) = −log P(x): rare events carry more information; units nats (base e) or bits (base 2). defined in ch. 3 — open in glossary covers one outcome; the Shannon entropy shannon entropy H(x) = E[I(x)] = −E[log P(x)]: expected information — the uncertainty of a whole distribution; max for uniform. defined in ch. 3 — open in glossary is its expectation — the uncertainty of the whole distribution, and the lower bound on average code length for symbols drawn from it: (continuous case: differential entropy; convention ).
To compare two distributions over the same variable, the Kullback-Leibler divergence kullback-leibler divergence D_KL(P‖Q) = E_{x∼P}[log P − log Q] ≥ 0, zero iff P = Q; asymmetric — NOT a distance. defined in ch. 3 — open in glossary :
Term by term
| the distribution reality samples from — expectations are taken under P | reference | |
| the distribution your code (or model) was designed for | approximation | |
| the EXTRA message length paid for using Q’s code on P’s data; ≥ 0, zero iff P = Q (a.e.) — but NOT symmetric, so not a distance | nats ≥ 0 |
The asymmetry has real consequences (fig 3.6): approximating a bimodal with a single Gaussian ,
Fig 3.6 (recreated) — which direction you minimize decides whether q blurs the modes together or commits to one. The choice is problem-dependent; ch. 19 lives inside this trade-off.
Finally, the cross-entropy cross-entropy H(P,Q) = H(P) + D_KL(P‖Q) = −E_{x∼P} log Q(x); minimizing over Q ≡ minimizing the KL. defined in ch. 3 — open in glossary : minimizing it over is the same as minimizing the KL (the omitted doesn’t involve ) — which is why “cross-entropy loss” and “KL minimization” name one procedure in ch. 5–6.
Check yourself — functions, Bayes, information
1.Why does the sigmoid 'saturate', and which identity quantifies it?
2.Disease prevalence 1%, sensitivity 90%, false-positive rate 9%. Your test is positive. Roughly what is P(disease | +), and why so low?
3.Why is p_y(y) = p_x(g⁻¹(y)) wrong for a change of variables y = g(x)?
4.In the entropy widget, where does H(p) peak and what does that mean?
5.You must approximate a well-separated bimodal p with a single Gaussian q. What does the direction of KL minimization decide?