Track 01 · Foundation
Math & Physics Foundations for ML
The math that deep learning actually uses — linear algebra, multivariable calculus, probability, optimisation, information theory — plus the physics ideas (energy, statistical mechanics, diffusion) behind modern generative models.
- Last updated
- Total effort
- 630 h · ≈ 63 weeks
Overview
Every ML system is a few mathematical ideas wearing engineering clothes. A neural network is a chain of matrix multiplications (linear algebra), trained by following gradients (calculus) of a loss that is really a negative log-likelihood (probability), using an optimiser whose behaviour depends on curvature (optimisation), and judged by quantities like cross-entropy and KL divergence (information theory). Diffusion models, Hopfield networks and Boltzmann machines borrow directly from statistical physics. This track teaches that math in service of ML: each topic is paired with the exact place it appears in a model you'll build, so you learn it once, for a reason, and it sticks.
Why it matters heading into 2027
As AI tools write more of the routine code, the scarce skill is understanding — reading a new paper, debugging a training run, judging whether an eval result is real. All three depend on math. Research-heavy roles (training, post-training, inference optimisation, interpretability) explicitly screen for it, and the 2024 Nobel Prize in Physics, awarded to Hopfield and Hinton, recognised how deeply ML is rooted in physics. You don't need a math degree; you need fluent, working intuition for about a dozen ideas, and the ability to follow a derivation in a paper.
- AI skills now appear in 2.5% of all US job postings, up 55% in a year; Python and ML frameworks lead the specialised skills. — Lightcast for the Stanford AI Index 2026
- The 2024 Nobel Prize in Physics went to Hopfield and Hinton for foundational discoveries enabling machine learning with artificial neural networks. — Nobel Prize press release, 2024
Prerequisites
- High-school algebra and functions. Comfort with summation notation is not needed yet — we build it.
- Python and NumPy, so every idea can be checked numerically.
- Patience: work problems with pen and paper, then verify them in code.
Learning path
How the stages build on each other, and where this track hands off to others.
flowchart TB
P["Prereqs: algebra · Python · NumPy"] --> B
subgraph B["1 · Beginner — the working toolkit"]
direction LR
B1["vectors & matrices"] --> B2["derivatives & chain rule"] --> B3["probability basics"]
end
subgraph I["2 · Intermediate — math of training"]
direction LR
I1["gradients & Jacobians"] --> I2["MLE · MAP · Bayes"] --> I3["SVD & eigenvalues"] --> I4["gradient descent"]
end
subgraph A["3 · Advanced — reading papers"]
direction LR
A1["entropy · KL"] --> A2["convexity & curvature"] --> A3["matrix calculus"] --> A4["sampling & Monte Carlo"]
end
subgraph E["4 · Expert — physics of generative models"]
direction LR
E1["energy-based models"] --> E2["statistical mechanics"] --> E3["SDEs & diffusion"] --> E4["flow matching"]
end
B --> I --> A --> E
I -.-> ML["ML Engineering"]
A -.-> DL["Deep Learning"]
E -.-> DL
Stages
Tick items as you go — progress is saved in this browser only. Times are focused hours (reading + building); the week estimates follow the study time you pick above.
01Beginner110 h · ≈ 11 weeksBuild a working toolkit: vectors, matrices, derivatives and basic probability — always connected to a line of NumPy you can run.
Key concepts
Build these
Ready for the next stage when…
02Intermediate150 h · ≈ 15 weeksThe math of training: gradients of vector functions, likelihood-based losses, matrix decompositions and gradient descent.
Key concepts
Build these
Ready for the next stage when…
03Advanced170 h · ≈ 17 weeksRead ML papers comfortably: information theory, convexity and curvature, matrix calculus, and sampling.
Key concepts
Build these
Ready for the next stage when…
04Expert200 h · ≈ 20 weeksThe physics behind modern generative models: energy-based models, statistical mechanics, stochastic differential equations and diffusion.
Key concepts
Build these
Ready for the next stage when…
Field guide
The ideas behind the checklist, with diagrams and the math where it helps.
The concept map
You don’t need all of mathematics. You need these ideas, and you need to see where each one lives in a model. Read the map left to right: each box is something you learn, and the arrow points to where it shows up in ML.
flowchart LR
subgraph LA["Linear algebra"]
direction TB
la1["dot product · norms"]
la2["matrix multiply"]
la3["eigen · SVD · rank"]
end
subgraph CA["Calculus"]
direction TB
ca1["chain rule"]
ca2["gradients · Jacobians"]
ca3["Hessian · curvature"]
end
subgraph PR["Probability & stats"]
direction TB
pr1["distributions · expectation"]
pr2["MLE · MAP · Bayes"]
pr3["sampling · Monte Carlo"]
end
subgraph IT["Information theory"]
direction TB
it1["entropy · cross-entropy"]
it2["KL divergence"]
end
subgraph PH["Physics"]
direction TB
ph1["energy · Boltzmann"]
ph2["Langevin · SDEs"]
end
la1 --> E1["embeddings · attention scores"]
la2 --> E2["every layer of a network"]
la3 --> E3["LoRA · PCA · conditioning"]
ca1 --> E4["backpropagation"]
ca3 --> E5["optimisers · learning rates"]
pr2 --> E6["loss functions · weight decay"]
pr3 --> E7["VAEs · RL policy gradients"]
it1 --> E8["LM training loss · perplexity"]
it2 --> E9["RLHF · DPO · distillation"]
ph1 --> E10["softmax · temperature · Hopfield"]
ph2 --> E11["diffusion models"]
Linear algebra: the language of layers
A dense layer is a matrix–vector product plus a bias:
Why it matters — embeddings and attention. An embedding is a vector, and “similar meaning” is measured with the dot product or cosine similarity:
That is the whole of vector search in AI Engineering, and attention scores are just a matrix of dot products between queries and keys.
Why it matters — SVD and LoRA. Any matrix factorises as , where the singular values in say how much each direction matters. Keeping only the top gives the best rank- approximation (Eckart–Young). LoRA bets that the change needed to fine-tune a model is low-rank too:
For a matrix and , that’s about trainable numbers instead of , a 128× reduction.
Why it matters — eigenvalues and conditioning. For a symmetric matrix, the eigen-decomposition tells you how it stretches space. The condition number of a loss surface’s curvature decides how fast gradient descent converges: high means a long, narrow valley and zig-zagging steps. This is why normalisation layers and adaptive optimisers like Adam exist.
Calculus: the chain rule is backpropagation
For a composition the chain rule says
A neural network is a long composition of layers, so the gradient of the loss with respect to any weight is a product of local derivatives. Backpropagation is just computing that product right to left, reusing intermediate results. That’s why it costs about as much as one forward pass, rather than one pass per parameter.
With vectors, each local derivative becomes a Jacobian matrix , and backprop multiplies vectors by Jacobians (“vector–Jacobian products”). The single most useful result to derive yourself is the softmax cross-entropy gradient. With logits , probabilities and one-hot target :
It’s beautifully simple, and it’s the gradient at the top of every language model.
Second order. The Hessian describes curvature. Near a minimum, ; the largest eigenvalue of caps the stable learning rate at about . Learning-rate warmup and “edge of stability” effects are about this number.
Probability: every loss is a likelihood
Maximum likelihood. Given data and a model , MLE picks
Why it matters. If the model outputs a categorical distribution, the NLL is cross-entropy, the loss of every classifier and language model. If it outputs a Gaussian mean with fixed variance, the NLL is (up to constants) mean-squared error. Choosing a loss means choosing a noise model.
MAP and weight decay. Adding a prior and maximising the posterior gives MAP:
With a Gaussian prior , , which is exactly L2 weight decay. A Laplace prior gives L1 (sparsity).
Statistics for evals. A benchmark score is an estimate. With questions and accuracy , the standard error is ; on 500 questions at 70%, that’s about ±2 points (95% interval ≈ ±4). Many “improvements” on small eval sets are noise.
Optimisation: from gradient descent to Adam
Plain gradient descent is . Stochastic gradient descent uses a mini-batch estimate of , which is noisy but cheap and, helpfully, acts as a regulariser.
Adam keeps running averages of the gradient and its square:
Dividing by rescales each coordinate. It’s a cheap, diagonal stand-in for curvature, which helps on the ill-conditioned surfaces from the linear algebra section.
Convexity. For convex problems (linear and logistic regression, SVMs) every local minimum is global, and theory guarantees convergence. Deep networks aren’t convex, but convex ideas still guide practice: Lagrange multipliers explain constrained objectives like the KL-constrained RLHF problem, and duality explains why some losses have closed-form optima.
Information theory: entropy, cross-entropy and KL
The entropy of a distribution is its average surprise, . The cross-entropy of model under true distribution is , and the gap between them is the KL divergence:
Why it matters — three places you’ll meet KL:
- Language-model training. of the data is fixed, so minimising cross-entropy minimises . Perplexity is “how many tokens the model is effectively choosing between”.
- RLHF and DPO. The objective rewards good answers but charges for drifting from the reference model. DPO’s loss comes straight from the closed-form optimum of this objective (see Deep Learning).
- Distillation and VAEs. Knowledge distillation minimises KL between teacher and student distributions; a VAE’s ELBO contains a KL term that keeps the latent code close to a prior.
KL is asymmetric. (“forward”, mass-covering) punishes for missing modes of ; (“reverse”, mode-seeking) punishes for putting mass where has none. The direction you choose changes the behaviour you get.
Physics I: energy, temperature and the Boltzmann distribution
Statistical mechanics says a system in equilibrium at temperature occupies state with probability
Why it matters — softmax is a Boltzmann distribution. Set the energy to the negative logit, , and you get : softmax with temperature. That’s why sampling “temperature” behaves like physical temperature. freezes into the single lowest-energy (highest-logit) token; large melts toward uniform randomness.
Energy-based models define with a learned energy. The hard part is always the partition function , a sum over every possible . Much of generative modelling is clever ways to avoid computing it: contrastive losses, score matching, and diffusion.
Physics II: Hopfield networks and attention
A Hopfield network stores patterns as low points of an energy function over binary states :
Updating each neuron to lower slides the state downhill into the nearest stored memory . That is associative memory, and it’s part of why Hopfield shared the 2024 Nobel Prize in Physics.
Modern Hopfield networks (Ramsauer et al., 2020) use an exponential energy with continuous states, and their one-step update for a query against stored patterns is
which is exactly Transformer attention with . Attention can be read as one step of energy minimisation that retrieves the stored pattern best matching the query.
Physics III: diffusion as a stochastic process
Brownian motion adds Gaussian noise continuously. A diffusion model defines a forward process that gradually turns data into noise, in discrete form (DDPM):
or in continuous time as a stochastic differential equation, . Remarkably, the process has a reverse-time SDE that turns noise back into data, and it needs only the score :
A neural network learns that score, which in practice is the same as predicting the added noise. DDPM’s training loss is then strikingly simple:
Langevin dynamics is the physics behind sampling. Follow the score uphill while adding noise,
and the particles end up distributed according to . Flow matching (2022) learns a deterministic velocity field instead, so generation becomes solving an ODE with fewer steps.
flowchart LR
X0["data x₀"] -- "add noise (forward SDE)" --> XT["pure noise x_T"]
XT -- "denoise with learned score (reverse SDE)" --> XS["new sample"]
NN["network ε_θ(x_t, t)<br/>≈ −σ·score"] -.-> XS
How to study this track
- Intuition, then formalism, then code. Watch the 3Blue1Brown video, read the MML chapter, then verify the result numerically in NumPy.
- Derive the six workhorse results yourself: softmax cross-entropy gradient, MSE as Gaussian NLL, L2 as a Gaussian prior, the DPO loss, the ELBO, and the DDPM loss.
- Interleave with building. Study Beginner math alongside the Deep Learning Beginner stage, so each idea has a model to live in.
- Keep a “math I used this week” log in your notes. Retrieval practice beats rereading.
How this track connects
- Deep LearningBackprop is the chain rule; attention is softmax over dot products; DPO, RLHF and GRPO are written in the language of KL divergence and expectations.
- ML Eng.MLE, regularisation, bias–variance and evaluation statistics (confidence intervals, A/B tests) underpin every classical model you ship.
- Inference & GPUQuantisation is numerical analysis; rooflines are arithmetic intensity; low-rank and sparsity come straight from linear algebra.
- AI Eng.Embeddings, cosine similarity and nearest-neighbour search are linear algebra; eval statistics decide whether a prompt change really helped.
- AI SecurityInterpretability (superposition, sparse autoencoders) is applied linear algebra; adversarial examples are optimisation against the model.
References
Original sources first: arXiv, official docs, university courses and lab blogs. Every link was checked on 7 Nov 2026.
Foundational & seminal papers(12)
- Neural networks and physical systems with emergent collective computational abilities
J. J. Hopfield · 1982 · doi.org
Memory as minima of an energy function — the start of physics-inspired neural nets.
- A Learning Algorithm for Boltzmann Machines
Ackley, Hinton & Sejnowski · 1985 · doi.org
Learning with the Boltzmann distribution; statistical mechanics meets neural networks.
- A Tutorial on Energy-Based Learning
LeCun et al. · 2006 · yann.lecun.com
One framework that covers many losses as shaping an energy landscape.
- Deep Unsupervised Learning using Nonequilibrium Thermodynamics
Sohl-Dickstein et al. · 2015 · arxiv.org
The origin of diffusion models, explicitly built on non-equilibrium physics.
- The Matrix Calculus You Need For Deep Learning
Parr & Howard · 2018 · arxiv.org
Gradients of vector and matrix functions, explained for practitioners.
- Generative Modeling by Estimating Gradients of the Data Distribution
Song & Ermon · 2019 · arxiv.org
Score matching plus Langevin dynamics as a generative model.
- Denoising Diffusion Probabilistic Models
Ho et al. · 2020 · arxiv.org
DDPM — the simple noise-prediction loss behind modern image models.
- Hopfield Networks is All You Need
Ramsauer et al. · 2020 · arxiv.org
Modern Hopfield networks' update rule is the Transformer's attention.
- Score-Based Generative Modeling through Stochastic Differential Equations
Song et al. · 2020 · arxiv.org
Unifies diffusion and score models as forward and reverse-time SDEs.
- Statistical Mechanics of Deep Learning
Bahri et al. · 2020 · doi.org
Survey of what physics says about loss landscapes, generalisation and dynamics.
- Flow Matching for Generative Modeling
Lipman et al. · 2022 · arxiv.org
Simulation-free training of continuous flows; the successor to diffusion in many systems.
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model
Rafailov et al. · 2023 · arxiv.org
A clean, readable derivation that uses KL, Bradley–Terry and a closed-form optimum — great Advanced-stage practice.
Courses & videos(6)
- Essence of Linear Algebra
3Blue1Brown · youtube.com
Geometric intuition first. Watch before any textbook.
- Essence of Calculus
3Blue1Brown · youtube.com
Derivatives and the chain rule as pictures.
- Neural Networks
3Blue1Brown · youtube.com
Backprop and Transformers visualised — the bridge from math to models.
- MIT 18.06 Linear Algebra
Gilbert Strang, MIT OpenCourseWare · 2010 · ocw.mit.edu
The classic course; do the problem sets for the Intermediate stage.
- MIT 18.02SC Multivariable Calculus
MIT OpenCourseWare · 2010 · ocw.mit.edu
Partial derivatives, gradients, Jacobians and Lagrange multipliers.
- Stat 110: Probability
Joe Blitzstein, Harvard · stat110.hsites.harvard.edu
The best introductory probability course, with a free textbook.
Books(9)
- Mathematics for Machine Learning
Deisenroth, Faisal & Ong · 2020 · mml-book.github.io
The core text for this track — free, and written exactly for ML.
- Linear Algebra and Learning from Data
Gilbert Strang · 2019 · math.mit.edu
SVD, low-rank approximation and optimisation aimed at deep learning.
- Convex Optimization
Boyd & Vandenberghe · 2004 · web.stanford.edu
Chapters 2–5 for convexity, duality and Lagrange multipliers; free PDF.
- Elements of Information Theory (2nd ed.)
Cover & Thomas · 2006 · wiley.com
The standard reference on entropy, KL divergence and coding.
- Information Theory, Inference, and Learning Algorithms
David MacKay · 2003 · inference.org.uk
Information theory and Bayesian inference together, with wit; free.
- Pattern Recognition and Machine Learning
Christopher Bishop · 2006 · microsoft.com
The probabilistic view of ML: MLE, MAP, Bayesian models; free PDF.
- Probabilistic Machine Learning (Introduction and Advanced Topics)
Kevin Murphy · 2022 · probml.github.io
Comprehensive modern reference, including diffusion and EBMs; free.
- Understanding Deep Learning
Simon J. D. Prince · 2023 · udlbook.github.io
Clear chapters on diffusion, flows and VAEs with just the math you need.
- The Matrix Cookbook
Petersen & Pedersen · math.uwaterloo.ca
A lookup table of matrix identities and derivatives — keep it open.
Articles, blogs & official docs(5)
- Calculus on Computational Graphs: Backpropagation
Chris Olah · 2015 · colah.github.io
Why reverse-mode autodiff is efficient, in one short read.
- The Matrix Calculus You Need For Deep Learning (HTML)
Terence Parr & Jeremy Howard · explained.ai
The readable web version of the paper above.
- Generative Modeling by Estimating Gradients of the Data Distribution (blog)
Yang Song · 2021 · yang-song.net
The clearest introduction to score-based models and SDEs.
- What are Diffusion Models?
Lilian Weng · 2021 · lilianweng.github.io
Diffusion math derived step by step, with all the notation in one place.
- The Nobel Prize in Physics 2024 — press release
The Royal Swedish Academy of Sciences · 2024 · nobelprize.org
A short, accessible account of how Hopfield networks and Boltzmann machines came from physics.