Home / Formulas / MLF
MLF formula sheet
Collected automatically from the lessons. Print it, or read it the night before.
Week 1 - What is machine learning, and which maths do we need?
- Norm: ∥v∥=v12+⋯+vn2
- Distance: ∥a−b∥
- Dot product: a⋅b=∑iaibi=∥a∥∥b∥cosθ; perpendicular ⟺a⋅b=0
- Cauchy-Schwarz: ∣a⋅b∣≤∥a∥∥b∥
- Unit vector: v^=v/∥v∥
- Squared loss: (y−y^)2; MSE =n1∑(yi−y^i)2
- 0-1 loss: 1 if y=y^, else 0; average = fraction of mistakes
Week 2 - Slopes, change and the steepest way up
- Derivative: f′(a)=limh→0hf(a+h)−f(a)
- Power: (xn)′=nxn−1; chain: (f(g))′=f′(g)g′; product: (fg)′=f′g+fg′
- Linear approximation: L(x)=f(a)+f′(a)(x−a)
- Two variables: L(x,y)=f(a,b)+fx(a,b)(x−a)+fy(a,b)(y−b)
- Gradient: ∇f=(fx,fy); directional derivative Duf=∇f⋅u, ∥u∥=1
- Steepest rate: ∥∇f∥ along ∇f
Week 3 - Vectors, matrices and the best-fit line
- Ax=x1col1+⋯+xncoln
- rank + nullity =n; left-null dimension =m−r
- Projection onto line: a⋅aa⋅xa; matrix aTaaaT
- Projection onto col(A): P=A(ATA)−1AT; P2=P=PT; rankP=traceP
- Normal equations: ATAw=ATy; w=(ATA)−1ATy
- rank(AB)≤min(rankA,rankB)
Week 4 - The special directions of a matrix
- Av=λv, det(A−λI)=0
- 2×2: λ2−(trA)λ+detA=0
- ∑λi=trA, ∏λi=detA
- A−1:1/λ; Ak:λk; A+cI:λ+c; AT:λ
- A=PDP−1, Ak=PDkP−1
Week 5 - Symmetric matrices: the well-behaved ones
- Spectral theorem: A=AT⇒A=QΛQT, QTQ=I, λi∈R
- Quadratic form q(x)=xTAx=∑λiyi2
- PD ⟺ all λ>0 ⟺ all leading minors >0; PSD ⟺ all λ≥0
- Orthogonal: QTQ=I, ∥Qx∥=∥x∥, detQ=±1
- Hermitian: A∗=A; unitary: U∗U=I; Schur: A=UTU∗
Week 6 - SVD and PCA: squeezing data
- A=UΣVT=∑iσiuiviT; σi=λi(ATA); rankA=#{σi=0}
- Rank-k storage: k(m+n+1); error ∥A−Ak∥F2=∑i>kσi2
- Covariance (centred): C=n1XXT; variance along unit u: uTCu
- Variance explained: ∑iλi∑i≤kλi; reconstruction error: ∑i>kλi
- λi(C)=σi2/n
Week 7 - Finding the lowest point: gradient descent
- Critical point: ∇f(x∗)=0; Hessian Hij=∂2f/∂xi∂xj
- Gradient descent: xt+1=xt−η∇f(xt)
- Quadratic bowl 2ax2: xt+1=(1−ηa)xt; stable iff 0<η<2/a
- Descent direction: ∇f⋅d<0
- Newton: xt+1=xt−H−1∇f
- Least squares gradient: ∇∥Xw−y∥2=2XT(Xw−y)
Week 8 - Bowls, not bumpy hills: convexity
- Convex set: θx+(1−θ)y∈S for θ∈[0,1]
- Convex function: f(θx+(1−θ)y)≤θf(x)+(1−θ)f(y)
- 1-D: f′′≥0; many variables: H⪰0 (PSD); strictly convex: H≻0
- First-order: f(y)≥f(x)+∇f(x)⋅(y−x)
- Jensen: f(E[X])≤E[f(X)]
- Epigraph: {(x,t):t≥f(x)} convex ⟺f convex
Week 9 - Optimising with rules: Lagrange and KKT
- Lagrange: ∇f=λ∇g, g=c; Lagrangian L=f−λ(g−c)
- KKT (g≤0): ∇f+μ∇g=0; g≤0; μ≥0; μg=0
- Distance2 from origin to aTx=b: b2/∥a∥2; closest point =∥a∥2ba
- LP: optimum at a vertex of the feasible region
- Sigmoid: σ(z)=1+e−z1; log-loss −n1∑[ylogp+(1−y)log(1−p)]; gradient n1∑(pi−yi)xi
Week 10 - Probability for machine learning
- P(A∣B)=P(B)P(A∩B); Bayes P(A∣B)=P(B)P(B∣A)P(A)
- VarX=E[X2]−(E[X])2; Cov(X,Y)=E[XY]−E[X]E[Y]
- Binomial: np, np(1−p); Uniform: 2a+b, 12(b−a)2; Exponential: λ1, λ21, P(X>t)=e−λt
- aX+b∼N(aμ+b,a2σ2); independent sum: means and variances add
- Markov: P(X≥a)≤E[X]/a; Chebyshev: P(∣X−μ∣≥kσ)≤1/k2
- Sample mean: E=μ, Var=σ2/n; WLLN: P(∣Xˉn−μ∣≥ε)≤nε2σ2
Week 11 - The exponential family
- p(x∣η)=h(x)exp(ηT(x)−A(η))
- E[T]=A′(η), Var[T]=A′′(η)
- MLE: A′(η^)=n1∑iT(xi)
- Bernoulli p^=xˉ; Poisson λ^=xˉ; Exponential λ^=1/xˉ
- Logit: η=ln1−pp; inverse: p=1+e−η1
Week 12 - Estimating parameters, and EM
- L(θ)=∏p(xi∣θ), ℓ=∑lnp(xi∣θ), ℓ′(θ^)=0
- Normal: μ^=xˉ, σ^MLE2=n1∑(xi−xˉ)2; unbiased n−11∑
- Uniform(0,θ): θ^=maxxi; Exponential: λ^=1/xˉ
- MAP: argmaxp(data∣θ)p(θ)
- EM: rik=∑jπjpj(xi)πkpk(xi); πk=n∑irik; μk=∑rik∑rikxi