Mathematics for Deep Learning
Throughout the main chapters of this book, we introduce mathematical tools just in time—stating each result alongside its geometric, statistical, or physical intuition so that you can build and train working models without losing momentum. Yet anyone who wants to move beyond applying existing recipes to diagnosing subtle training failures, reading frontier research papers critically, or inventing new methods eventually needs to look inside the mathematical engine. Why does the learning rate of gradient descent have a hard ceiling set by the largest eigenvalue of the Hessian? Why does minimizing cross-entropy estimate the true conditional distribution, and why does the Jensen–Shannon divergence saturate when two distributions fail to overlap? How does adding Gaussian noise to an image day by day define a reverse-time differential equation that turns pure noise back into a photograph?
This six-chapter appendix answers those questions in full. It is designed to serve two complementary purposes:
- A companion reference for the main text. Whenever a chapter in Basics or Advanced uses a mathematical theorem or identity and focuses on its practical consequences, it points to the corresponding section here for the complete derivation, proof, and boundary conditions. If you are already comfortable with a topic, you can skip its chapter here and dip in only when a cross-reference piques your curiosity.
- A self-contained textbook for a course on the mathematics of deep learning. Read from start to finish, these six chapters form a coherent, modern mathematical curriculum tailored specifically to deep learning—developing each subject from first principles as far as modern machine learning actually uses it, without getting bogged down in pathology for its own sake.
Just like the rest of the book, every section in this appendix pairs its mathematical derivations with runnable code and computational experiments (implemented in PyTorch, JAX, TensorFlow, and MXNet), turning abstract theorems into concrete numerical phenomena that you can inspect, plot, and test for yourself:
- Linear Algebra (33 Linear Algebra). Deep networks represent data and parameters as vectors, matrices, and tensors, and every layer transforms the geometry of space. Beginning with lengths, angles, inner products, projections, and vector/matrix norms, this chapter treats matrices as active linear transformations that rotate, stretch, and collapse subspaces. We then develop the spectral decompositions that govern high-dimensional dynamics: eigendecomposition (showing how repeated matrix multiplication in recurrences or optimization is controlled by eigenvalues), spectra in practice (from Gershgorin circles and condition numbers to random matrix theory and the Marchenko–Pastur law), and the singular value decomposition (SVD), Moore–Penrose pseudoinverse, and Eckart–Young low-rank approximation that underlie parameter-efficient fine-tuning (LoRA) and spectral normalization.
- Calculus (34 Calculus and Automatic Differentiation). Training a neural network with billions of parameters rests entirely on our ability to compute how a scalar loss changes when every parameter is perturbed simultaneously. Starting from single-variable derivatives, Taylor series, and numerical differentiation pitfalls, we move to multivariable gradients, directional derivatives, Jacobian matrices, and Hessian curvature. We then trace the multivariate chain rule through computation graphs to demystify automatic differentiation—contrasting forward-mode and reverse-mode (backpropagation) accumulation and showing why reverse-mode computes the exact gradient with respect to millions of parameters at the cost of a single forward pass.
- Optimization (35 Optimization). This chapter supplies the formal proofs behind the empirical phenomena observed in 9 Optimization Algorithms. We establish the geometry of convex sets and convex functions (Jensen’s inequality, first- and second-order convexity characterizations), prove how \(L\)-smoothness and \(\mu\)-strong convexity govern the convergence rate and step-size stability of gradient descent via the condition number \(\kappa = L/\mu\), analyze momentum and Newton/quasi-Newton preconditioning on ill-conditioned quadratic models, and develop constrained optimization via Lagrange multipliers, Karush–Kuhn–Tucker (KKT) optimality conditions, and Lagrangian duality.
- Probability and Statistics (36 Probability and Statistical Learning). Machine learning reasons under uncertainty at every stage, from noisy data generation and stochastic minibatch sampling to out-of-sample generalization. We build from probability spaces, conditional distributions, Bayes’ rule, expectations, and key parametric families (Bernoulli, categorical, Gaussian, Laplace, exponential) to the classical concentration inequalities (Markov, Chebyshev, Hoeffding) that bound rare deviations of empirical averages. We then develop statistical inference and learning theory: maximum likelihood estimation (MLE), Fisher information, the Cramér–Rao lower bound, Bayesian maximum a posteriori (MAP) estimation, sufficient statistics, hypothesis testing, confidence intervals, and the theoretical foundations of generalization (empirical risk minimization, uniform convergence, Rademacher complexity, VC dimension, and the bias–variance trade-off).
- Information Theory (37 Information Theory and Divergences). Nearly every classification, language-modeling, and generative objective in deep learning descends from information theory. Starting from Claude Shannon’s axioms of self-information and entropy, we show how cross-entropy and Kullback–Leibler (KL) divergence measure the coding inefficiency of using an approximate model distribution \(Q\) in place of the true data distribution \(P\), and extend these concepts to continuous random variables via differential entropy and the maximum-entropy principle. We then broaden the lens to compare probability distributions when KL divergence fails: \(f\)-divergences, the variational dual representations behind GANs, and Wasserstein optimal transport distances that respect the underlying geometry of the sample space. The chapter closes with mutual information, the data processing inequality, the variational information bottleneck, and the InfoNCE lower bound that drives modern contrastive representation learning.
- Dynamics, Flows, and Diffusion (38 Dynamics: Differential Equations and Generative Flows). Many of the most powerful ideas in modern deep learning—from continuous normalizing flows and state space models to denoising diffusion and flow matching—are most naturally understood in continuous time. This final chapter builds the dynamical toolkit from the ground up: systems of ordinary differential equations (ODEs), vector fields, phase portraits, linear stability, numerical integrators (Euler, Runge–Kutta, and symplectic leapfrog), and Neural ODEs trained via the continuous adjoint sensitivity method. We then track how a velocity field transports an entire probability density via the continuity equation and Hutchinson’s trace estimator, before introducing randomness: Brownian motion, Itô stochastic differential equations (SDEs), Itô’s lemma, the Ornstein–Uhlenbeck process, the Fokker–Planck equation, and Anderson’s reverse-time SDE and the probability-flow ODE, which reveal how learning the score function \(\nabla_{\mathbf{x}} \log p_t(\mathbf{x})\) allows a neural network to turn pure Gaussian noise into samples from any target distribution.