Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Doubling, again and again
One bacterium splits into 2. Each of those splits, making 4. Then 8, 16, 32… After just 20 splits there are more than a million. Growing by multiplying again and again is called exponential growth, and it gets huge very fast.
Fold a piece of paper in half: 2 layers. Fold again: 4 layers. Again: 8. Each fold doubles the layers.
Going backwards: “how many doublings?”
Now ask the opposite question. You see 32 bacteria. How many times did they double, starting from 1? Count: 1 → 2 → 4 → 8 → 16 → 32. That’s 5 doublings. Answering “how many times did I multiply?” is what a logarithm does. It’s like a counter of doublings.
Logarithms turn huge numbers into small, friendly ones. The number 1,000,000 is just “6 zeros”, and that 6 is a logarithm. AI systems use logarithms all the time so their numbers don’t get too big or too small.
- 1. A plant doubles its leaves every week. It starts with 1 leaf. How many after 4 weeks?
- 2. How many times must you double 1 to reach 64?
- 3. Which grows faster in the long run: adding 100 each day, or doubling each day (starting at 1)?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Powers and their rules
means multiplied by itself times. is the base, and is the exponent.
| Rule | Example |
|---|---|
Logarithms undo powers
because . because . Three bases matter most:
| Base | Written | Used for |
|---|---|---|
| 10 | Orders of magnitude, decibels, pH | |
| 2 | Bits, binary search, information theory | |
| Calculus, probability, ML (the “natural” log) |
Where does e come from?
Put ₹1 in a bank paying 100% interest a year. Paid once, you end with ₹2. Paid twice (50% each half-year), you get . Paid monthly, . As the payments get more frequent, the total approaches a special number:
The log rules
| Rule | Why |
|---|---|
| multiplying adds exponents | |
| dividing subtracts exponents | |
| a power multiplies the exponent | |
Drag the slider to change the base . The exponential and the log are mirror images across the line :
- 1. What is log₂(64)?
- 2. Simplify log(5) + log(20) in base 10.
- 3. What is 2⁻²?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.The functions eˣ and ln x
is defined for all real , is always positive, and is strictly increasing. Its inverse is defined only for . Their special properties in calculus (A3) are:
Change of base. Any log can be computed with :
Solving for an exponent. gives , so .
The sigmoid and softmax
The sigmoid squashes any real number into . It turns a score into a probability for binary classification:
Softmax does the same for many classes. It turns a vector of scores (logits) into probabilities that are positive and sum to 1:
Log-sum-exp and numerical stability
The denominator’s log is the log-sum-exp function:
A computer can’t evaluate : float64 overflows above about . The fix is to subtract the maximum first, which doesn’t change the result:
Now every exponent is , so nothing overflows, and at least one term equals , so the sum doesn’t underflow to 0. Softmax is shift-invariant for the same reason: .
Logs everywhere in ML and data science
| Use | Formula |
|---|---|
| Cross-entropy loss | . Confident and wrong is punished heavily |
| Log-likelihood | , a product turned into a sum (A1-3) |
| Log-transformed features | for skewed data such as income or population |
| Log scales on plots | Exponential growth looks like a straight line |
| Learning rates | Searched on a log grid, such as |
| Decibels | for signal power in sensors |
- 1. softmax([3, 3, 3]) is…
- 2. Why subtract max(z) before computing softmax?
- 3. σ(z) = 0.5 when z equals…
Level 3: Advanced
★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.Defining eˣ properly
Three equivalent definitions:
From the series: . The law of exponents follows by multiplying the two series and grouping terms with the binomial theorem. The log rules then follow from it, because is the inverse of .
Two inequalities you’ll use constantly
For all real : . For all : . Equality holds only at and respectively.
Proof. Let . Then , which is negative for and positive for . So has its minimum at 0, where . Hence . For the second, put into the first to get . ∎
These give , the step used in the PAC bound (A1-1), and they’re behind the proof that KL divergence is never negative (A7).
Log-sum-exp is a smooth maximum
For : . With temperature : as .
Proof. Let . The sum contains the term and has terms, each , so . Take logs. For the temperature version, apply the same bounds to and multiply by : . ∎
, and LSE is convex.
Proof. . The Hessian is with . For any , , which is the variance of under , so it’s . ∎ (Convexity is covered in A6.)
A useful consequence: the cross-entropy loss with softmax is , and its gradient is the beautifully simple , “prediction minus truth”.
Exercise 3.1: Prove that σ’(z) = σ(z)(1 − σ(z))
, so . ∎
Exercise 3.2: Show that the sigmoid is a 2-class softmax
. Logistic regression is the 2-class case of softmax regression.
- 1. LSE([5, 5, 5, 5]) equals…
- 2. Which is the gradient of cross-entropy with softmax, with respect to the logits?
- 3. As the temperature T → 0, softmax(z/T) tends to…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Where softmax came from
The softmax form is the Boltzmann distribution of statistical physics (Boltzmann, 1868): states with lower energy are more probable, and the temperature controls how sharp the preference is. Bridle (1990) gave the name “softmax” to its use as the output layer of neural networks. The physics language survives in ML: “temperature” in LLM sampling, “energy-based models” (H6), and as a free energy.
Numerics: the details that matter in practice
- float64 overflows at . float32 overflows at , which a single bad logit can reach, so mixed-precision training keeps softmax and loss computations in float32.
- For small , and lose accuracy. Use
log1pandexpm1. - Blanchard, Higham and Higham (2021) analysed exactly how accurate the shifted LSE and softmax algorithms are. They’re stable, but the details of the algorithm matter.
- Log-domain algorithms. Hidden Markov models, CTC speech recognition (Graves et al., 2006), and particle filters in robot localization (T1) multiply long chains of probabilities. They work entirely with logs and combine them with
logaddexp.
The Gumbel-max trick: sampling as an argmax
If are independent samples from the Gumbel distribution, with , then
This result comes from extreme-value theory (Gumbel, 1954). Replacing the argmax with a softmax at temperature gives the Gumbel-softmax (Concrete) relaxation (Jang et al., 2017; Maddison et al., 2017). It lets gradients flow through discrete choices, which is used in discrete latent-variable models and some robot-learning policies.
Temperature as a research tool
- Knowledge distillation (Hinton, Vinyals and Dean, 2015) trains a small model on a large model’s softmax outputs at a high temperature, so the “dark knowledge” in the small probabilities is visible.
- LLM sampling uses temperature to trade off diversity against accuracy.
- Contrastive learning (InfoNCE, E16) uses a temperature in the softmax over similarities, and the choice strongly affects the learned representations.
Exponentials in robotics
Rotations in 3D are produced by a matrix exponential: a rotation by angle about the unit axis is . The “log map” goes back from a rotation to an axis and angle. These maps, on Lie groups, are the foundation of modern state estimation and SLAM (R2, T3).
References
- J. Napier (1614). Mirifici Logarithmorum Canonis Descriptio. (The invention of logarithms.)
- L. Euler (1748). Introductio in analysin infinitorum. (e, the exponential series, and e^x as a limit.)
- L. Boltzmann (1868). “Studien über das Gleichgewicht der lebendigen Kraft zwischen bewegten materiellen Punkten.” Wiener Berichte, 58.
- E. Gumbel (1954). Statistical Theory of Extreme Values and Some Practical Applications. US National Bureau of Standards, Applied Mathematics Series 33.
- J. Bridle (1990). “Probabilistic interpretation of feedforward classification network outputs, with relationships to statistical pattern recognition.” In Neurocomputing, Springer.
- A. Graves, S. Fernández, F. Gomez, J. Schmidhuber (2006). “Connectionist temporal classification.” ICML.
- G. Hinton, O. Vinyals, J. Dean (2015). “Distilling the knowledge in a neural network.” arXiv:1503.02531.
- E. Jang, S. Gu, B. Poole (2017). “Categorical reparameterization with Gumbel-softmax.” ICLR.
- C. Maddison, A. Mnih, Y. W. Teh (2017). “The Concrete distribution: a continuous relaxation of discrete random variables.” ICLR.
- P. Blanchard, D. Higham, N. Higham (2021). “Accurately computing the log-sum-exp and softmax functions.” IMA Journal of Numerical Analysis, 41(4).