Everything below is math you will use directly when reading papers, implementing algorithms, and understanding why things work. Table of contents Linear algebra Calculus and analysis Probability theory Statistics Information theory 1. Linear algebra 1.1 Vectors A column vector x ∈ R n \mathbf{x} \in \mathbb{R}^n x ∈ R n is a list of n n n real numbers. Row vector = x ⊤ \mathbf{x}^\top x ⊤ .
Inner product (dot product):
⟨ x , y ⟩ = x ⊤ y = ∑ i = 1 n x i y i . \langle \mathbf{x}, \mathbf{y} \rangle = \mathbf{x}^\top \mathbf{y} = \sum_{i=1}^n x_i y_i. ⟨ x , y ⟩ = x ⊤ y = i = 1 ∑ n x i y i . Euclidean (L2) norm:
∥ x ∥ 2 = x ⊤ x = ∑ i = 1 n x i 2 . \|\mathbf{x}\|_2 = \sqrt{\mathbf{x}^\top \mathbf{x}} = \sqrt{\sum_{i=1}^n x_i^2}. ∥ x ∥ 2 = x ⊤ x = i = 1 ∑ n x i 2 . L1 norm: ∥ x ∥ 1 = ∑ ∣ x i ∣ \|\mathbf{x}\|_1 = \sum |x_i| ∥ x ∥ 1 = ∑ ∣ x i ∣ . Induces sparsity in optimization.
L∞ norm: ∥ x ∥ ∞ = max i ∣ x i ∣ \|\mathbf{x}\|_\infty = \max_i |x_i| ∥ x ∥ ∞ = max i ∣ x i ∣ .
Cauchy–Schwarz inequality: ∣ x ⊤ y ∣ ≤ ∥ x ∥ ∥ y ∥ |\mathbf{x}^\top \mathbf{y}| \leq \|\mathbf{x}\|\,\|\mathbf{y}\| ∣ x ⊤ y ∣ ≤ ∥ x ∥ ∥ y ∥ . Equality iff x = c y \mathbf{x} = c\mathbf{y} x = c y . This is the foundation of cosine similarity.
Cosine similarity: cos θ = x ⊤ y ∥ x ∥ ∥ y ∥ ∈ [ − 1 , 1 ] \cos\theta = \frac{\mathbf{x}^\top \mathbf{y}}{\|\mathbf{x}\|\,\|\mathbf{y}\|} \in [-1,1] cos θ = ∥ x ∥ ∥ y ∥ x ⊤ y ∈ [ − 1 , 1 ] .
1.2 Matrices A matrix A ∈ R m × n \mathbf{A} \in \mathbb{R}^{m \times n} A ∈ R m × n has m m m rows and n n n columns.
Transpose: ( A ⊤ ) i j = A j i (\mathbf{A}^\top)_{ij} = A_{ji} ( A ⊤ ) ij = A ji . Matrix product: ( A B ) i k = ∑ j A i j B j k (\mathbf{AB})_{ik} = \sum_j A_{ij} B_{jk} ( AB ) ik = ∑ j A ij B jk (row-times-column). Properties: ( A B ) ⊤ = B ⊤ A ⊤ (\mathbf{AB})^\top = \mathbf{B}^\top \mathbf{A}^\top ( AB ) ⊤ = B ⊤ A ⊤ , ( A B ) C = A ( B C ) \;(\mathbf{AB})\mathbf{C} = \mathbf{A}(\mathbf{BC}) ( AB ) C = A ( BC ) .
Symmetric matrix: A = A ⊤ \mathbf{A} = \mathbf{A}^\top A = A ⊤ . Covariance matrices are always symmetric.
Trace: tr ( A ) = ∑ i A i i \operatorname{tr}(\mathbf{A}) = \sum_i A_{ii} tr ( A ) = ∑ i A ii . Cyclic: tr ( A B C ) = tr ( C A B ) \operatorname{tr}(\mathbf{ABC}) = \operatorname{tr}(\mathbf{CAB}) tr ( ABC ) = tr ( CAB ) .
Determinant: scalar that captures volume scaling. det ( A B ) = det ( A ) det ( B ) \det(\mathbf{AB}) = \det(\mathbf{A})\det(\mathbf{B}) det ( AB ) = det ( A ) det ( B ) .
Rank: dimension of column space (= row space). Full rank ⇒ invertible (for square matrices).
Frobenius norm: ∥ A ∥ F = ∑ i j A i j 2 = tr ( A ⊤ A ) \|\mathbf{A}\|_F = \sqrt{\sum_{ij} A_{ij}^2} = \sqrt{\operatorname{tr}(\mathbf{A}^\top\mathbf{A})} ∥ A ∥ F = ∑ ij A ij 2 = tr ( A ⊤ A ) .
1.3 Systems of linear equations A x = b \mathbf{Ax} = \mathbf{b} Ax = b : if A \mathbf{A} A is square and invertible, unique solution x = A − 1 b \mathbf{x} = \mathbf{A}^{-1}\mathbf{b} x = A − 1 b . In practice, use Gaussian elimination or numpy.linalg.solve (never explicitly invert).
Overdetermined (m > n m > n m > n ): no exact solution in general → least-squares min x ∥ A x − b ∥ 2 \min_\mathbf{x}\|\mathbf{Ax}-\mathbf{b}\|^2 min x ∥ Ax − b ∥ 2 → normal equations A ⊤ A x = A ⊤ b \mathbf{A}^\top\mathbf{Ax} = \mathbf{A}^\top\mathbf{b} A ⊤ Ax = A ⊤ b .
1.4 Eigendecomposition For square A ∈ R n × n \mathbf{A} \in \mathbb{R}^{n\times n} A ∈ R n × n :
A v = λ v \mathbf{A}\mathbf{v} = \lambda \mathbf{v} Av = λ v λ \lambda λ is an eigenvalue and v ≠ 0 \mathbf{v} \neq \mathbf{0} v = 0 is its eigenvector .
Spectral theorem: a real symmetric matrix has all real eigenvalues and an orthonormal basis of eigenvectors:
A = Q Λ Q ⊤ , Q ⊤ Q = I , \mathbf{A} = \mathbf{Q}\boldsymbol{\Lambda}\mathbf{Q}^\top, \quad \mathbf{Q}^\top\mathbf{Q}=\mathbf{I}, A = Q Λ Q ⊤ , Q ⊤ Q = I , where Λ = diag ( λ 1 , … , λ n ) \boldsymbol{\Lambda} = \operatorname{diag}(\lambda_1,\ldots,\lambda_n) Λ = diag ( λ 1 , … , λ n ) .
Positive semidefinite (PSD): all λ i ≥ 0 \lambda_i \geq 0 λ i ≥ 0 . Equivalent: x ⊤ A x ≥ 0 ∀ x \mathbf{x}^\top\mathbf{A}\mathbf{x} \geq 0\; \forall \mathbf{x} x ⊤ Ax ≥ 0 ∀ x . Covariance matrices are always PSD.
Use in ML: PCA uses eigendecomposition of the sample covariance to find principal directions.
1.5 Singular value decomposition (SVD) For any A ∈ R m × n \mathbf{A} \in \mathbb{R}^{m \times n} A ∈ R m × n :
A = U Σ V ⊤ , \mathbf{A} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top, A = U Σ V ⊤ , where:
U ∈ R m × m \mathbf{U} \in \mathbb{R}^{m\times m} U ∈ R m × m : left singular vectors (columns orthonormal).Σ ∈ R m × n \boldsymbol{\Sigma} \in \mathbb{R}^{m\times n} Σ ∈ R m × n : diagonal with singular values σ 1 ≥ σ 2 ≥ ⋯ ≥ 0 \sigma_1 \geq \sigma_2 \geq \cdots \geq 0 σ 1 ≥ σ 2 ≥ ⋯ ≥ 0 .V ∈ R n × n \mathbf{V} \in \mathbb{R}^{n\times n} V ∈ R n × n : right singular vectors (columns orthonormal).Thin SVD: keep only r = rank ( A ) r = \operatorname{rank}(\mathbf{A}) r = rank ( A ) nonzero singular values. A = ∑ i = 1 r σ i u i v i ⊤ \mathbf{A} = \sum_{i=1}^r \sigma_i \mathbf{u}_i \mathbf{v}_i^\top A = ∑ i = 1 r σ i u i v i ⊤ (outer product expansion).
Rank-k k k approximation: truncate to first k k k singular values — best rank-k k k approximation in Frobenius and spectral norm (Eckart–Young theorem).
Connections:
Singular values of A \mathbf{A} A = square roots of eigenvalues of A ⊤ A \mathbf{A}^\top\mathbf{A} A ⊤ A . Right singular vectors = eigenvectors of A ⊤ A \mathbf{A}^\top\mathbf{A} A ⊤ A (used in PCA). SVD is the computational workhorse behind PCA, matrix factorization in recommenders, pseudoinverse. Pseudoinverse: A + = V Σ + U ⊤ \mathbf{A}^+ = \mathbf{V}\boldsymbol{\Sigma}^+\mathbf{U}^\top A + = V Σ + U ⊤ where Σ + \Sigma^+ Σ + inverts nonzero entries. Gives minimum-norm least-squares solution when A \mathbf{A} A is rank-deficient.
1.6 Matrix calculus (gradients) Gradient of a scalar w.r.t. a vector w ∈ R n \mathbf{w} \in \mathbb{R}^n w ∈ R n :
∇ w f ( w ) = [ ∂ f / ∂ w 1 ⋮ ∂ f / ∂ w n ] . \nabla_\mathbf{w} f(\mathbf{w}) = \begin{bmatrix} \partial f/\partial w_1 \\ \vdots \\ \partial f/\partial w_n \end{bmatrix}. ∇ w f ( w ) = ∂ f / ∂ w 1 ⋮ ∂ f / ∂ w n . Key identities (denominator layout, a \mathbf{a} a constant):
Hessian: matrix of second partials H i j = ∂ 2 f / ∂ w i ∂ w j \mathbf{H}_{ij} = \partial^2 f / \partial w_i \partial w_j H ij = ∂ 2 f / ∂ w i ∂ w j . PSD Hessian everywhere ⇒ convex function.
2. Calculus and analysis 2.1 Derivative rules recap Chain rule (scalar): ( f ( g ( x ) ) ) ′ = f ′ ( g ( x ) ) ⋅ g ′ ( x ) (f(g(x)))' = f'(g(x)) \cdot g'(x) ( f ( g ( x )) ) ′ = f ′ ( g ( x )) ⋅ g ′ ( x ) .
Chain rule (vector): if z = f ( y ) \mathbf{z} = f(\mathbf{y}) z = f ( y ) and y = g ( x ) \mathbf{y} = g(\mathbf{x}) y = g ( x ) , then:
∂ z ∂ x = ∂ z ∂ y ⋅ ∂ y ∂ x ( Jacobian multiplication ) . \frac{\partial \mathbf{z}}{\partial \mathbf{x}} = \frac{\partial \mathbf{z}}{\partial \mathbf{y}} \cdot \frac{\partial \mathbf{y}}{\partial \mathbf{x}} \quad (\text{Jacobian multiplication}). ∂ x ∂ z = ∂ y ∂ z ⋅ ∂ x ∂ y ( Jacobian multiplication ) . This is the backbone of backpropagation .
Product rule: ( f g ) ′ = f ′ g + f g ′ (fg)' = f'g + fg' ( f g ) ′ = f ′ g + f g ′ . Quotient rule: ( f / g ) ′ = ( f ′ g − f g ′ ) / g 2 (f/g)' = (f'g - fg')/g^2 ( f / g ) ′ = ( f ′ g − f g ′ ) / g 2 .
2.2 Taylor expansion f ( x + δ ) ≈ f ( x ) + f ′ ( x ) δ + 1 2 f ′ ′ ( x ) δ 2 + ⋯ f(x + \delta) \approx f(x) + f'(x)\delta + \frac{1}{2}f''(x)\delta^2 + \cdots f ( x + δ ) ≈ f ( x ) + f ′ ( x ) δ + 2 1 f ′′ ( x ) δ 2 + ⋯ Multivariate version:
f ( w + δ ) ≈ f ( w ) + ∇ f ( w ) ⊤ δ + 1 2 δ ⊤ H ( w ) δ . f(\mathbf{w} + \boldsymbol{\delta}) \approx f(\mathbf{w}) + \nabla f(\mathbf{w})^\top \boldsymbol{\delta} + \frac{1}{2}\boldsymbol{\delta}^\top \mathbf{H}(\mathbf{w})\boldsymbol{\delta}. f ( w + δ ) ≈ f ( w ) + ∇ f ( w ) ⊤ δ + 2 1 δ ⊤ H ( w ) δ . Used in Newton's method (second-order optimization) and understanding convergence of gradient descent.
2.3 Convexity A set C C C is convex if ∀ x , y ∈ C , t ∈ [ 0 , 1 ] : t x + ( 1 − t ) y ∈ C \forall \mathbf{x},\mathbf{y} \in C,\; t\in[0,1]:\; t\mathbf{x}+(1-t)\mathbf{y}\in C ∀ x , y ∈ C , t ∈ [ 0 , 1 ] : t x + ( 1 − t ) y ∈ C .
A function f : C → R f: C \to \mathbb{R} f : C → R is convex if:
f ( t x + ( 1 − t ) y ) ≤ t f ( x ) + ( 1 − t ) f ( y ) . f(t\mathbf{x}+(1-t)\mathbf{y}) \leq t f(\mathbf{x}) + (1-t) f(\mathbf{y}). f ( t x + ( 1 − t ) y ) ≤ t f ( x ) + ( 1 − t ) f ( y ) . Equivalently: H ( w ) ⪰ 0 \mathbf{H}(\mathbf{w}) \succeq 0 H ( w ) ⪰ 0 (PSD Hessian) everywhere.
Why it matters: any local minimum of a convex function is a global minimum .
Strictly convex: H ≻ 0 \mathbf{H} \succ 0 H ≻ 0 (positive definite) ⇒ unique global minimum.
Examples in ML:
MSE loss (linear regression): convex (Hessian = 2 n X ⊤ X \frac{2}{n}\mathbf{X}^\top\mathbf{X} n 2 X ⊤ X , PSD). Cross-entropy (logistic regression): convex in w \mathbf{w} w . Ridge objective: strictly convex. Neural network losses: non-convex in general. 2.4 Lagrangian optimization and KKT conditions Constrained optimization: min f ( w ) \min f(\mathbf{w}) min f ( w ) s.t. g i ( w ) ≤ 0 g_i(\mathbf{w}) \leq 0 g i ( w ) ≤ 0 , h j ( w ) = 0 h_j(\mathbf{w}) = 0 h j ( w ) = 0 .
Lagrangian: L ( w , α , ν ) = f ( w ) + ∑ i α i g i ( w ) + ∑ j ν j h j ( w ) \mathcal{L}(\mathbf{w}, \boldsymbol{\alpha}, \boldsymbol{\nu}) = f(\mathbf{w}) + \sum_i \alpha_i g_i(\mathbf{w}) + \sum_j \nu_j h_j(\mathbf{w}) L ( w , α , ν ) = f ( w ) + ∑ i α i g i ( w ) + ∑ j ν j h j ( w ) .
KKT conditions (necessary at optimum under constraint qualifications):
Stationarity: ∇ w L = 0 \nabla_\mathbf{w} \mathcal{L} = \mathbf{0} ∇ w L = 0 . Primal feasibility: g i ( w ⋆ ) ≤ 0 g_i(\mathbf{w}^\star) \leq 0 g i ( w ⋆ ) ≤ 0 . Dual feasibility: α i ≥ 0 \alpha_i \geq 0 α i ≥ 0 . Complementary slackness: α i g i ( w ⋆ ) = 0 \alpha_i g_i(\mathbf{w}^\star) = 0 α i g i ( w ⋆ ) = 0 . SVM is derived directly from KKT conditions on the margin-maximization problem.
3. Probability theory 3.1 Foundations Sample space Ω \Omega Ω : set of all outcomes. Event A ⊆ Ω A \subseteq \Omega A ⊆ Ω . Probability measure P P P : P ( Ω ) = 1 P(\Omega)=1 P ( Ω ) = 1 , P ( A ) ≥ 0 P(A) \geq 0 P ( A ) ≥ 0 , countably additive.
Conditional probability: P ( A ∣ B ) = P ( A ∩ B ) / P ( B ) P(A|B) = P(A \cap B)/P(B) P ( A ∣ B ) = P ( A ∩ B ) / P ( B ) .
Independence: P ( A ∩ B ) = P ( A ) P ( B ) P(A \cap B) = P(A)P(B) P ( A ∩ B ) = P ( A ) P ( B ) .
Bayes' theorem:
P ( A ∣ B ) = P ( B ∣ A ) P ( A ) P ( B ) . \boxed{P(A|B) = \frac{P(B|A)\,P(A)}{P(B)}}. P ( A ∣ B ) = P ( B ) P ( B ∣ A ) P ( A ) . In ML: P ( hypothesis ∣ data ) ∝ P ( data ∣ hypothesis ) ⋅ P ( hypothesis ) P(\text{hypothesis}|\text{data}) \propto P(\text{data}|\text{hypothesis})\cdot P(\text{hypothesis}) P ( hypothesis ∣ data ) ∝ P ( data ∣ hypothesis ) ⋅ P ( hypothesis ) — this is the foundation of Bayesian learning.
3.2 Random variables and distributions PMF (discrete): P ( X = x ) P(X=x) P ( X = x ) . PDF (continuous): f ( x ) = d F / d x f(x) = dF/dx f ( x ) = d F / d x . CDF: F ( x ) = P ( X ≤ x ) F(x) = P(X \leq x) F ( x ) = P ( X ≤ x ) .
Expectation: E [ X ] = ∑ x P ( X = x ) \mathbb{E}[X] = \sum x P(X=x) E [ X ] = ∑ x P ( X = x ) or ∫ x f ( x ) d x \int x f(x)dx ∫ x f ( x ) d x . Variance: Var ( X ) = E [ ( X − μ ) 2 ] = E [ X 2 ] − ( E [ X ] ) 2 \text{Var}(X) = \mathbb{E}[(X-\mu)^2] = \mathbb{E}[X^2] - (\mathbb{E}[X])^2 Var ( X ) = E [( X − μ ) 2 ] = E [ X 2 ] − ( E [ X ] ) 2 . Standard deviation: σ = Var ( X ) \sigma = \sqrt{\text{Var}(X)} σ = Var ( X ) . Covariance: Cov ( X , Y ) = E [ ( X − μ X ) ( Y − μ Y ) ] \text{Cov}(X,Y) = \mathbb{E}[(X-\mu_X)(Y-\mu_Y)] Cov ( X , Y ) = E [( X − μ X ) ( Y − μ Y )] .
Linearity of expectation: E [ a X + b Y ] = a E [ X ] + b E [ Y ] \mathbb{E}[aX+bY] = a\mathbb{E}[X]+b\mathbb{E}[Y] E [ a X + bY ] = a E [ X ] + b E [ Y ] (always, no independence needed).
3.3 Key distributions in ML Bernoulli: X ∈ { 0 , 1 } X \in \{0,1\} X ∈ { 0 , 1 } , P ( X = 1 ) = p P(X=1)=p P ( X = 1 ) = p . Mean = p p p , Var = p ( 1 − p ) p(1-p) p ( 1 − p ) . Binary classification labels.
Binomial Bin ( n , p ) \text{Bin}(n,p) Bin ( n , p ) : number of successes in n n n Bernoulli trials.
Categorical / Multinoulli: P ( X = k ) = p k P(X=k) = p_k P ( X = k ) = p k , ∑ p k = 1 \sum p_k = 1 ∑ p k = 1 . Multi-class labels; output of softmax.
Gaussian N ( μ , σ 2 ) \mathcal{N}(\mu,\sigma^2) N ( μ , σ 2 ) :
f ( x ) = 1 2 π σ 2 exp ( − ( x − μ ) 2 2 σ 2 ) . f(x) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right). f ( x ) = 2 π σ 2 1 exp ( − 2 σ 2 ( x − μ ) 2 ) . Properties: symmetric, unimodal, characterized by mean and variance, 68-95-99.7 rule.
Multivariate Gaussian N ( μ , Σ ) \mathcal{N}(\boldsymbol{\mu},\boldsymbol{\Sigma}) N ( μ , Σ ) :
f ( x ) = 1 ( 2 π ) d / 2 ∣ Σ ∣ 1 / 2 exp ( − 1 2 ( x − μ ) ⊤ Σ − 1 ( x − μ ) ) . f(\mathbf{x}) = \frac{1}{(2\pi)^{d/2}|\boldsymbol{\Sigma}|^{1/2}} \exp\!\left(-\frac{1}{2}(\mathbf{x}-\boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu})\right). f ( x ) = ( 2 π ) d /2 ∣ Σ ∣ 1/2 1 exp ( − 2 1 ( x − μ ) ⊤ Σ − 1 ( x − μ ) ) . Used in GMMs, Gaussian processes, LDA.
Uniform: constant density. Used in random initialization.
Exponential: f ( x ) = λ e − λ x f(x) = \lambda e^{-\lambda x} f ( x ) = λ e − λ x , x ≥ 0 x \geq 0 x ≥ 0 . Memoryless property.
Beta Beta ( α , β ) \text{Beta}(\alpha,\beta) Beta ( α , β ) : distribution over [ 0 , 1 ] [0,1] [ 0 , 1 ] ; conjugate prior to Bernoulli/Binomial.
Dirichlet Dir ( α ) \text{Dir}(\boldsymbol{\alpha}) Dir ( α ) : distribution over probability simplices; conjugate prior to Categorical.
3.4 Maximum likelihood estimation (MLE) Given i.i.d. data { x i } i = 1 n \{x_i\}_{i=1}^n { x i } i = 1 n and a parameterized model p ( x ∣ θ ) p(x|\theta) p ( x ∣ θ ) , find θ \theta θ to maximize the likelihood :
L ( θ ) = ∏ i = 1 n p ( x i ∣ θ ) . \mathcal{L}(\theta) = \prod_{i=1}^n p(x_i|\theta). L ( θ ) = i = 1 ∏ n p ( x i ∣ θ ) . Equivalently maximize the log-likelihood (avoids underflow, same argmax):
ℓ ( θ ) = ∑ i = 1 n log p ( x i ∣ θ ) . \ell(\theta) = \sum_{i=1}^n \log p(x_i|\theta). ℓ ( θ ) = i = 1 ∑ n log p ( x i ∣ θ ) . Example — Gaussian MLE: ℓ ( μ , σ 2 ) = − n 2 log ( 2 π σ 2 ) − 1 2 σ 2 ∑ i ( x i − μ ) 2 \ell(\mu,\sigma^2) = -\frac{n}{2}\log(2\pi\sigma^2) - \frac{1}{2\sigma^2}\sum_i(x_i-\mu)^2 ℓ ( μ , σ 2 ) = − 2 n log ( 2 π σ 2 ) − 2 σ 2 1 ∑ i ( x i − μ ) 2 . Setting ∂ ℓ / ∂ μ = 0 \partial\ell/\partial\mu = 0 ∂ ℓ / ∂ μ = 0 : μ ^ = x ˉ \hat{\mu} = \bar{x} μ ^ = x ˉ . Setting ∂ ℓ / ∂ σ 2 = 0 \partial\ell/\partial\sigma^2 = 0 ∂ ℓ / ∂ σ 2 = 0 : σ ^ 2 = 1 n ∑ ( x i − x ˉ ) 2 \hat{\sigma}^2 = \frac{1}{n}\sum(x_i-\bar{x})^2 σ ^ 2 = n 1 ∑ ( x i − x ˉ ) 2 (biased).
Example — Bernoulli MLE: p ^ = ∑ x i n \hat{p} = \frac{\sum x_i}{n} p ^ = n ∑ x i (fraction of 1s).
MLE and OLS connection: If y i = x i ⊤ w + ε i y_i = \mathbf{x}_i^\top\mathbf{w} + \varepsilon_i y i = x i ⊤ w + ε i with ε i ∼ N ( 0 , σ 2 ) \varepsilon_i \sim \mathcal{N}(0,\sigma^2) ε i ∼ N ( 0 , σ 2 ) , then MLE for w \mathbf{w} w = minimize ∑ ( y i − x i ⊤ w ) 2 \sum(y_i - \mathbf{x}_i^\top\mathbf{w})^2 ∑ ( y i − x i ⊤ w ) 2 = OLS.
3.5 Maximum a posteriori (MAP) Incorporate a prior p ( θ ) p(\theta) p ( θ ) via Bayes:
θ MAP = arg max θ log p ( θ ∣ D ) ⏟ posterior = arg max θ [ log p ( D ∣ θ ) + log p ( θ ) ] . \theta_\text{MAP} = \arg\max_\theta \underbrace{\log p(\theta|\mathcal{D})}_{\text{posterior}} = \arg\max_\theta \left[ \log p(\mathcal{D}|\theta) + \log p(\theta) \right]. θ MAP = arg θ max posterior log p ( θ ∣ D ) = arg θ max [ log p ( D ∣ θ ) + log p ( θ ) ] . MAP vs regularization: Gaussian prior θ ∼ N ( 0 , 1 λ I ) \theta \sim \mathcal{N}(\mathbf{0},\frac{1}{\lambda}\mathbf{I}) θ ∼ N ( 0 , λ 1 I ) gives MAP = Ridge regression. Laplace prior gives MAP = Lasso.
3.6 Law of large numbers and central limit theorem LLN: X ˉ n → P E [ X ] \bar{X}_n \xrightarrow{P} \mathbb{E}[X] X ˉ n P E [ X ] as n → ∞ n\to\infty n → ∞ . Basis for Monte Carlo.
CLT: n ( X ˉ n − μ ) → d N ( 0 , σ 2 ) \sqrt{n}(\bar{X}_n - \mu) \xrightarrow{d} \mathcal{N}(0,\sigma^2) n ( X ˉ n − μ ) d N ( 0 , σ 2 ) . Why Gaussian distribution appears everywhere.
4. Statistics 4.1 Estimators and their properties An estimator θ ^ ( D ) \hat{\theta}(\mathcal{D}) θ ^ ( D ) is a function of the data.
Bias: Bias ( θ ^ ) = E [ θ ^ ] − θ ⋆ \text{Bias}(\hat\theta) = \mathbb{E}[\hat\theta] - \theta^\star Bias ( θ ^ ) = E [ θ ^ ] − θ ⋆ . Zero bias = unbiased. Variance: Var ( θ ^ ) = E [ ( θ ^ − E [ θ ^ ] ) 2 ] \text{Var}(\hat\theta) = \mathbb{E}[(\hat\theta - \mathbb{E}[\hat\theta])^2] Var ( θ ^ ) = E [( θ ^ − E [ θ ^ ] ) 2 ] . Mean squared error: MSE ( θ ^ ) = Bias 2 ( θ ^ ) + Var ( θ ^ ) \text{MSE}(\hat\theta) = \text{Bias}^2(\hat\theta) + \text{Var}(\hat\theta) MSE ( θ ^ ) = Bias 2 ( θ ^ ) + Var ( θ ^ ) .
This is the bias-variance decomposition of an estimator's error — mirrors the ML bias-variance tradeoff exactly.
Consistency: θ ^ n → P θ ⋆ \hat\theta_n \xrightarrow{P} \theta^\star θ ^ n P θ ⋆ as n → ∞ n \to \infty n → ∞ .
Efficiency: estimator with minimum variance among unbiased estimators (Cramér-Rao bound).
4.2 Hypothesis testing Framework: null hypothesis H 0 H_0 H 0 , alternative H 1 H_1 H 1 . Test statistic T T T , reject H 0 H_0 H 0 if T > t α T > t_\alpha T > t α .
p-value: probability of observing data at least as extreme as seen, *assuming H 0 H_0 H 0 true*. Small p-value = evidence against H 0 H_0 H 0 .
Type I error (false positive): reject H 0 H_0 H 0 when it is true. Controlled at level α \alpha α . Type II error (false negative): fail to reject H 0 H_0 H 0 when it is false. Related to power .
t-test, chi-squared test, ANOVA: standard tests for means, proportions, group comparisons.
4.3 Confidence intervals A 95 % 95\% 95% CI [ L , U ] [L,U] [ L , U ] means: if we repeated the experiment many times, 95 % 95\% 95% of such intervals would contain the true θ ⋆ \theta^\star θ ⋆ . For large n n n (CLT):
X ˉ n ± 1.96 ⋅ σ ^ n . \bar{X}_n \pm 1.96 \cdot \frac{\hat\sigma}{\sqrt{n}}. X ˉ n ± 1.96 ⋅ n σ ^ . 4.4 Experimental design Randomized controlled trial (A/B test): gold standard for causal inference. Random assignment breaks confounding.
Confounding: a variable Z Z Z affects both the treatment T T T and outcome Y Y Y , creating spurious correlation. Models can detect correlation but cannot automatically infer causation from observational data.
Stratification: ensure both groups have similar distributions of known confounders. Used in stratified k-fold CV .
5. Information theory 5.1 Entropy Shannon entropy of a discrete distribution p p p :
H ( p ) = − ∑ k p k log p k . H(p) = -\sum_k p_k \log p_k. H ( p ) = − k ∑ p k log p k . Measures uncertainty / minimum expected bits to encode a sample. Max entropy = uniform distribution. H = 0 H=0 H = 0 when distribution is deterministic.
5.2 Cross-entropy and KL divergence Cross-entropy between true p p p and model distribution q q q :
H ( p , q ) = − ∑ k p k log q k . H(p, q) = -\sum_k p_k \log q_k. H ( p , q ) = − k ∑ p k log q k . Used as classification loss: true labels are p p p (one-hot), model output is q q q (probabilities).
KL divergence (Kullback–Leibler):
D KL ( p ∥ q ) = ∑ k p k log p k q k = H ( p , q ) − H ( p ) . D_\text{KL}(p \| q) = \sum_k p_k \log \frac{p_k}{q_k} = H(p,q) - H(p). D KL ( p ∥ q ) = k ∑ p k log q k p k = H ( p , q ) − H ( p ) . Always ≥ 0 \geq 0 ≥ 0 (Gibbs' inequality); equals 0 iff p = q p = q p = q . Not symmetric.
Minimizing cross-entropy ≡ minimizing KL divergence (since H ( p ) H(p) H ( p ) is fixed w.r.t. model parameters).
5.3 Mutual information I ( X ; Y ) = D KL ( p ( X , Y ) ∥ p ( X ) p ( Y ) ) = H ( X ) + H ( Y ) − H ( X , Y ) . I(X;Y) = D_\text{KL}(p(X,Y) \| p(X)p(Y)) = H(X) + H(Y) - H(X,Y). I ( X ; Y ) = D KL ( p ( X , Y ) ∥ p ( X ) p ( Y )) = H ( X ) + H ( Y ) − H ( X , Y ) . Measures statistical dependence (= 0 iff independent). Used in feature selection, information bottleneck.
5.4 Gini impurity (decision trees) G = 1 − ∑ k p k 2 . G = 1 - \sum_k p_k^2. G = 1 − k ∑ p k 2 . Alternative impurity to entropy (computationally faster, similar results). The CART algorithm minimizes weighted Gini after each split.
*File: notes/01_math_foundations.md — next: notes/02_learning_theory.md*