webmat.dk Machine Learning & Data Science

Matrix Calculus, SVD/PCA, Optimization & Information Theory • By Mads Frederik Toft

University Bridge High School (EN)

Mathematics for Machine Learning & Data Science

Modern machine learning is built directly on four mathematical pillars: multivariable chain rule (backpropagation), eigenvalues & SVD (dimensionality reduction and embeddings), convex optimization (gradient descent), and probability & information theory (cross-entropy loss and Bayesian inference).

Prerequisites

Uni Bridge

Uses Jacobians, Hessians, eigenvalues of symmetric matrices, and partial derivatives from University Bridge Chapters 3 & 4.

Core Algorithms

Interactive Labs

Hands-on intuition for backprop graphs, PCA variance maximization, learning rate stability $\eta$, and KL divergence.

Proofs & Theory

Derivations

Complete step-by-step proofs for Softmax-Cross-Entropy gradients, PCA variance optimality, step-size bound $\eta < 2/\lambda_{\max}$, and Gibbs' inequality.

How University Math Translates Directly Into Machine Learning 1. Chain Rule → Backpropagation: Training a neural network with millions of parameters is reverse-mode automatic differentiation on a computational graph.
2. Spectral Theorem → PCA & SVD: The covariance matrix $\Sigma = \frac{1}{n}X^T X$ is symmetric positive semi-definite — its top eigenvectors are the principal components!
3. Hessian Eigenvalues → Learning Rate $\eta$: The largest eigenvalue $\lambda_{\max}$ of the loss Hessian sets the strict speed limit $\eta < \frac{2}{\lambda_{\max}}$ before gradient descent explodes.

4-Chapter ML & Data Science Syllabus

Showing all 4 chapters (Complete with interactive labs, proofs & drill trainer).
Core Proofs
Chapter 1: Matrix Calculus & Backpropagation

Matrix derivatives, computational graphs, reverse-mode AD, Softmax + Cross-Entropy gradient proof, and the Backprop Graph Lab.

Core Proofs
Chapter 2: SVD & Principal Component Analysis (PCA)

Covariance matrices, Singular Value Decomposition $A = U\Sigma V^T$, variance maximization proof, and the 2D PCA Projection Lab.

Core Proofs
Chapter 3: Convex Optimization & Gradient Descent

Convexity, Hessian conditioning, gradient descent, momentum, stability bound $\eta < 2/\lambda_{\max}$ proof, and the Gradient Descent Lab.

Core Proofs
Chapter 4: Probability, Entropy & Bayesian Inference

Bayes' theorem, Maximum Likelihood (MLE), Shannon entropy, KL divergence & Gibbs' inequality proof, and the KL & Bayes Lab.

Chapter 1: Matrix Calculus & Backpropagation

Core: Gradients, Jacobians & Computational Graphs Proof: Softmax + Cross-Entropy Gradient

1.1 Essential Vector & Matrix Gradient Identities

Theorem (Core Matrix Calculus Identities • Numerator/Gradient Layout) For column vectors $\vec{x}, \vec{a} \in \mathbb{R}^d$ and symmetric matrix $A \in \mathbb{R}^{d \times d}$:
1. Linear form: $\nabla_{\vec{x}} (\vec{a}^T \vec{x}) = \vec{a}$
2. Quadratic form: $\nabla_{\vec{x}} (\vec{x}^T A \vec{x}) = 2A\vec{x}$ (for general $M$: $(M + M^T)\vec{x}$)
3. Squared Euclidean norm: $\nabla_{\vec{w}} \|X\vec{w} - \vec{y}\|_2^2 = 2X^T(X\vec{w} - \vec{y})$
4. Elementwise activation $\vec{h} = \sigma(\vec{z})$: $\frac{\partial L}{\partial \vec{z}} = \frac{\partial L}{\partial \vec{h}} \odot \sigma'(\vec{z})$ (Hadamard product $\odot$).

1.2 Computational Graphs & Reverse-Mode Automatic Differentiation

Algorithm (Forward Pass & Backward Pass / Backprop) Represent a composite loss $L = f_K \circ \cdots \circ f_2 \circ f_1(\vec{x})$ as a directed acyclic graph:
• Forward pass: Compute and cache intermediate activations $\vec{z}_1, \dots, \vec{z}_K$ from inputs to scalar loss $L$.
• Backward pass: Initialize $\bar{L} = \frac{\partial L}{\partial L} = 1$. Propagate adjoints $\bar{u} := \frac{\partial L}{\partial u}$ backward using the chain rule: $$\frac{\partial L}{\partial u} = \sum_{v \in \text{children}(u)} \frac{\partial L}{\partial v} \frac{\partial v}{\partial u}$$ Reverse-mode AD computes gradients with respect to all parameters in a single backward sweep!

1.3 Softmax + Cross-Entropy Gradient (Full Proof)

ML EXAM PROOF (Classification Loss Derivative) Theorem: For $p_i = \frac{e^{z_i}}{\sum_j e^{z_j}}$ and $L = -\sum_k y_k \ln p_k$ ($\sum_k y_k = 1$), $\frac{\partial L}{\partial z_i} = p_i - y_i$
The proof Step 1 (Derivative of Softmax $\frac{\partial p_k}{\partial z_i}$): Let $S = \sum_{j=1}^C e^{z_j}$, so $p_k = e^{z_k} / S$.
• If $k = i$: by the quotient rule, $$\frac{\partial p_i}{\partial z_i} = \frac{e^{z_i} S - e^{z_i} e^{z_i}}{S^2} = p_i(1 - p_i)$$ • If $k \neq i$: $$\frac{\partial p_k}{\partial z_i} = \frac{0 - e^{z_k} e^{z_i}}{S^2} = -p_k p_i$$ Step 2 (Chain rule on Cross-Entropy $L = -\sum_{k=1}^C y_k \ln p_k$): $$\frac{\partial L}{\partial z_i} = -\sum_{k=1}^C \frac{y_k}{p_k} \frac{\partial p_k}{\partial z_i} = -\frac{y_i}{p_i}\big(p_i(1 - p_i)\big) - \sum_{k \neq i} \frac{y_k}{p_k}(-p_k p_i)$$ Step 3 (Simplify using $\sum_{k=1}^C y_k = 1$): $$\frac{\partial L}{\partial z_i} = -y_i + y_i p_i + p_i \sum_{k \neq i} y_k = -y_i + p_i \underbrace{\sum_{k=1}^C y_k}_{=\,1} = p_i - y_i \qquad \blacksquare$$
Why every neural network classifier uses this pair The messy $1/p_k$ from $\ln p_k$ cancels the $p_k$ factor in Softmax's Jacobian! You are left with $\nabla_{\vec{z}} L = \vec{p} - \vec{y}$ — the predicted probability vector minus the one-hot target vector — preventing vanishing gradients when predictions are confident and wrong.

Interactive Backprop Lab: Computational Graph $L = \frac{1}{2}\big(\sigma(w x + b) - y\big)^2$

1.4 Exercises for Chapter 1

Core • Matrix Calculus

Exercise 1.1: Derive the Normal Equations for Ordinary Least Squares by setting $\nabla_{\vec{w}} \|X\vec{w} - \vec{y}\|_2^2 = \vec{0}$.

Hint: Expand $(X\vec{w} - \vec{y})^T(X\vec{w} - \vec{y}) = \vec{w}^T X^T X \vec{w} - 2\vec{y}^T X \vec{w} + \vec{y}^T\vec{y}$ and differentiate with respect to $\vec{w}$.
Full derivation: $\nabla_{\vec{w}} L = 2X^T X \vec{w} - 2X^T \vec{y} = \vec{0} \implies X^T X \vec{w} = X^T \vec{y}$. When $X$ has full column rank, $\hat{\vec{w}} = (X^T X)^{-1} X^T \vec{y}$.
Core • Softmax Gradient

Exercise 1.2: A 3-class classifier outputs logits $\vec{z} = (2, 1, 0)^T$ for true label $\vec{y} = (0, 1, 0)^T$. Using $e^2 \approx 7.39, e^1 \approx 2.72, e^0 = 1$, compute $\nabla_{\vec{z}} L = \vec{p} - \vec{y}$.

Hint: Normalize $(7.39, 2.72, 1)$ by their sum $11.11$ to get $\vec{p}$, then subtract $\vec{y} = (0, 1, 0)^T$.
Full solution: $\vec{p} \approx (0.665, 0.245, 0.090)^T \implies \nabla_{\vec{z}} L = \vec{p} - \vec{y} \approx (0.665, -0.755, 0.090)^T$.

Chapter 2: SVD & Principal Component Analysis (PCA)

Core: Covariance, SVD & Low-Rank Approximation Proof: Rayleigh Quotient / Variance Maximization

2.1 Centered Data & the Sample Covariance Matrix

Definition (Covariance Matrix • Core) Given $n$ data points in $\mathbb{R}^d$ stacked as rows of $X \in \mathbb{R}^{n \times d}$, first subtract the column means so $\tilde{X}$ has zero-mean columns. The $d \times d$ sample covariance matrix is: $$\Sigma = \frac{1}{n - 1}\tilde{X}^T \tilde{X}$$ $\Sigma$ is symmetric ($\Sigma^T = \Sigma$) and positive semi-definite ($\vec{u}^T \Sigma \vec{u} \ge 0$), so by the Spectral Theorem it has non-negative real eigenvalues $\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_d \ge 0$ and orthonormal eigenvectors $\vec{v}_1, \dots, \vec{v}_d$.

2.2 Singular Value Decomposition (SVD)

Theorem (SVD & Eckart-Young Low-Rank Approximation • Core) Every rectangular matrix $A \in \mathbb{R}^{m \times n}$ factors into: $$A = U \Sigma V^T = \sum_{i=1}^{r} \sigma_i \vec{u}_i \vec{v}_i^T$$ where $U \in \mathbb{R}^{m \times m}$ and $V \in \mathbb{R}^{n \times n}$ are orthogonal ($U^T U = I, V^T V = I$), and $\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_r > 0$ are the singular values (square roots of the non-zero eigenvalues of $A^T A$). Keeping only the top $k$ terms gives the best rank-$k$ approximation in Frobenius and spectral norms!

2.3 Why the Top Eigenvector Maximizes Projected Variance (Proof)

ML EXAM PROOF (Rayleigh Quotient & Lagrange Multipliers) Theorem: $\max_{\|\vec{u}\|_2 = 1} \vec{u}^T \Sigma \vec{u} = \lambda_1$, achieved at the top eigenvector $\vec{u} = \vec{v}_1$
The proof Step 1 (Projected variance): Projecting centered rows $\tilde{\vec{x}}_i$ onto unit vector $\vec{u}$ ($\vec{u}^T\vec{u} = 1$) gives scalar coordinates $z_i = \tilde{\vec{x}}_i \cdot \vec{u}$, with variance: $$\operatorname{Var}(z) = \frac{1}{n - 1}\sum_{i=1}^n (\tilde{\vec{x}}_i \cdot \vec{u})^2 = \vec{u}^T \left(\frac{1}{n - 1}\tilde{X}^T \tilde{X}\right) \vec{u} = \vec{u}^T \Sigma \vec{u}$$ Step 2 (Apply Lagrange Multipliers): Maximize $f(\vec{u}) = \vec{u}^T \Sigma \vec{u}$ subject to $g(\vec{u}) = \vec{u}^T\vec{u} = 1$. Setting $\nabla f(\vec{u}) = \lambda \nabla g(\vec{u})$ gives: $$2\Sigma \vec{u} = \lambda (2\vec{u}) \quad \Longleftrightarrow \quad \Sigma \vec{u} = \lambda \vec{u}$$ Thus any stationary unit vector $\vec{u}$ must be an eigenvector of $\Sigma$!
Step 3 (Evaluate objective at eigenvector): For $\Sigma \vec{u} = \lambda \vec{u}$ with $\|\vec{u}\|_2 = 1$: $$\operatorname{Var}(z) = \vec{u}^T (\Sigma \vec{u}) = \vec{u}^T (\lambda \vec{u}) = \lambda (\vec{u}^T \vec{u}) = \lambda$$ Therefore, the variance is maximized when $\lambda = \lambda_1$ (the largest eigenvalue) and $\vec{u} = \vec{v}_1$. The fraction of total variance explained is $\frac{\lambda_1}{\sum_{j=1}^d \lambda_j}$. $\blacksquare$
Connecting University Bridge Chapters 3 & 4 This proof combines the Spectral Theorem (Chapter 3) with Lagrange Multipliers (Chapter 4) in three clean steps — showing why PCA is an exact, closed-form eigendecomposition problem with no local minima.

Interactive 2D PCA Lab: Rotate Projection Axis $\vec{u}(\theta)$ & Watch Variance Peak

2.4 Exercises for Chapter 2

Core • Variance Explained

Exercise 2.1: A 4-dimensional dataset has covariance eigenvalues $\lambda_1 = 6.4,\ \lambda_2 = 2.6,\ \lambda_3 = 0.7,\ \lambda_4 = 0.3$. How much total variance is retained if we project onto the top $k = 2$ principal components?

Hint: Compute $\frac{\lambda_1 + \lambda_2}{\lambda_1 + \lambda_2 + \lambda_3 + \lambda_4}$.
Full solution: Total variance $= 6.4 + 2.6 + 0.7 + 0.3 = 10.0$. Top 2 components capture $\frac{6.4 + 2.6}{10.0} = \frac{9.0}{10.0} = 90\,\%$ of the variance.
Core • SVD Compression Ratio

Exercise 2.2: A $1000 \times 1000$ grayscale image matrix ($1{,}000{,}000$ numbers) is approximated by a rank-$k$ SVD ($k = 20$). How many numbers are stored in $U_k, \Sigma_k, V_k^T$?

Hint: $U_k$ has $1000 \times k$ entries, $\Sigma_k$ has $k$ singular values, and $V_k^T$ has $k \times 1000$ entries.
Full solution: $20(1000 + 1 + 1000) = 40{,}020$ numbers — a $25\times$ compression ratio ($96\,\%$ storage reduction)!

Chapter 3: Convex Optimization & Gradient Descent

Core: Convexity, Gradient Descent & Momentum Proof: Learning Rate Stability Bound

3.1 Convex Sets, Convex Functions & Global Optimality

Definition & Theorem (Convexity & Second-Order Condition • Core) A twice-differentiable function $L: \mathbb{R}^d \to \mathbb{R}$ is convex if for all $\vec{x}, \vec{y}$ and $\theta \in [0, 1]$: $$L\big(\theta\vec{x} + (1 - \theta)\vec{y}\big) \le \theta L(\vec{x}) + (1 - \theta)L(\vec{y})$$ Equivalently, its Hessian $H_L(\vec{x})$ is positive semi-definite ($\lambda_{\min}(H_L) \ge 0$) everywhere. If $\lambda_{\min}(H_L) \ge \mu > 0$, $L$ is $\mu$-strongly convex and every local minimum is the unique global minimum.

3.2 Gradient Descent, Stochastic GD & Momentum

Algorithm (Gradient Descent & Polyak Momentum • Core) • Vanilla Gradient Descent: $\vec{w}_{t+1} = \vec{w}_t - \eta \nabla L(\vec{w}_t)$, where $\eta > 0$ is the learning rate.
• Gradient Descent with Momentum ($\beta \in [0, 1)$): $$\vec{v}_{t+1} = \beta \vec{v}_t + \nabla L(\vec{w}_t), \qquad \vec{w}_{t+1} = \vec{w}_t - \eta \vec{v}_{t+1}$$ Momentum damps oscillations across steep ravines while accelerating progress along shallow valleys.

3.3 Learning Rate Stability Bound $\eta < \frac{2}{\lambda_{\max}}$ (Proof)

ML EXAM PROOF (Quadratic Convergence Analysis) Theorem: On $L(\vec{w}) = \frac{1}{2}\vec{w}^T A \vec{w}$ ($A = A^T \succ 0$), $\vec{w}_t \to \vec{0}$ iff $0 < \eta < \frac{2}{\lambda_{\max}(A)}$
The proof Step 1 (Gradient descent recurrence): Since $\nabla L(\vec{w}) = A\vec{w}$, one step gives: $$\vec{w}_{t+1} = \vec{w}_t - \eta A \vec{w}_t = (I - \eta A)\vec{w}_t = (I - \eta A)^{t+1}\vec{w}_0$$ Step 2 (Diagonalize via Spectral Theorem $A = Q \Lambda Q^T$): Transform to eigenbasis coordinates $\vec{z}_t = Q^T \vec{w}_t$: $$\vec{z}_{t+1} = (I - \eta \Lambda)\vec{z}_t \quad \Longrightarrow \quad z_{t, i} = (1 - \eta \lambda_i)^t z_{0, i}$$ Step 3 (Convergence criterion for geometric sequences): Each component $z_{t, i} \to 0$ as $t \to \infty$ (for arbitrary $\vec{w}_0$) if and only if every multiplier has magnitude strictly less than $1$: $$|1 - \eta \lambda_i| < 1 \quad \Longleftrightarrow \quad -1 < 1 - \eta \lambda_i < 1 \quad \Longleftrightarrow \quad 0 < \eta \lambda_i < 2$$ Since $\lambda_1 = \lambda_{\max} \ge \cdots \ge \lambda_d > 0$, this holds for all $i$ if and only if: $$0 < \eta < \frac{2}{\lambda_{\max}(A)} \qquad \blacksquare$$
Why ill-conditioned losses train slowly The condition number $\kappa = \frac{\lambda_{\max}}{\lambda_{\min}}$ controls convergence speed: $\eta$ is capped by $\frac{2}{\lambda_{\max}}$, so along the flattest direction ($\lambda_{\min}$) the contraction factor $1 - \eta\lambda_{\min} \approx 1 - \frac{2}{\kappa}$ stays close to $1$ when $\kappa \gg 1$!

Interactive Gradient Descent Lab: $L(x, y) = \frac{1}{2}(x^2 + 6y^2)$ ($\lambda_{\min}=1, \lambda_{\max}=6 \Rightarrow \eta_{\text{crit}} = \frac{2}{6} \approx 0.333$)

3.4 Exercises for Chapter 3

Core • Step-Size Bound

Exercise 3.1: Consider $L(w_1, w_2) = 2w_1^2 + 10w_2^2$. Find its Hessian $H_L$, eigenvalues $\lambda_{\min}, \lambda_{\max}$, condition number $\kappa$, and maximum stable learning rate $\eta_{\max}$.

Hint: Compute second partial derivatives $L_{w_1 w_1} = 4$ and $L_{w_2 w_2} = 20$, then use $\eta_{\max} = \frac{2}{\lambda_{\max}}$.
Full solution: $H_L = \begin{pmatrix} 4 & 0 \\ 0 & 20 \end{pmatrix}$, so $\lambda_{\min} = 4$, $\lambda_{\max} = 20$, $\kappa = \frac{20}{4} = 5$, and $\eta_{\max} = \frac{2}{20} = 0.10$.
Core • Single GD Step

Exercise 3.2: Starting at $\vec{w}_0 = (3, 1)^T$ on $L(w_1, w_2) = 2w_1^2 + 10w_2^2$ with $\eta = 0.05$, compute $\vec{w}_1$.

Hint: $\nabla L(w_1, w_2) = (4w_1, 20w_2)^T$. Evaluate at $(3, 1)^T$ and subtract $\eta \nabla L(\vec{w}_0)$.
Full solution: $\nabla L(3, 1) = (12, 20)^T \implies \vec{w}_1 = \begin{pmatrix} 3 \\ 1 \end{pmatrix} - 0.05\begin{pmatrix} 12 \\ 20 \end{pmatrix} = \begin{pmatrix} 2.4 \\ 0 \end{pmatrix}$.

Chapter 4: Probability, Entropy & Bayesian Inference

Core: Bayes' Rule, MLE, Shannon Entropy & KL Proof: Non-Negativity of KL Divergence

4.1 Bayesian Updating & Maximum Likelihood Estimation (MLE)

Theorems (Bayes' Rule & Log-Likelihood • Core) • Bayes' Theorem: Updating a prior belief $P(H)$ after observing data $D$: $$P(H \mid D) = \frac{P(D \mid H)\,P(H)}{P(D)} = \frac{P(D \mid H)\,P(H)}{\sum_i P(D \mid H_i)\,P(H_i)}$$ • Maximum Likelihood Estimation (MLE): Choose parameters $\theta$ maximizing $\ell(\theta) = \sum_{i=1}^n \ln p_\theta(x_i)$. Under Gaussian noise $y_i \sim N(f_\theta(x_i), \sigma^2)$, maximizing log-likelihood is mathematically identical to minimizing Mean Squared Error (MSE)!

4.2 Shannon Entropy, Cross-Entropy & KL Divergence

Definition (Information Theory Quantities • Core) For discrete probability distributions $P = (p_1, \dots, p_k)$ and $Q = (q_1, \dots, q_k)$:
• Shannon Entropy: $H(P) = -\sum_{i=1}^k p_i \ln p_i$ (or $\log_2$ for bits; measures average surprise/uncertainty).
• Cross-Entropy: $H(P, Q) = -\sum_{i=1}^k p_i \ln q_i$.
• Kullback-Leibler (KL) Divergence: $$D_{\text{KL}}(P \parallel Q) = \sum_{i=1}^k p_i \ln\!\left(\frac{p_i}{q_i}\right) = H(P, Q) - H(P)$$ Since $H(P)$ does not depend on model parameters, minimizing cross-entropy $H(P, Q_\theta)$ is identical to minimizing $D_{\text{KL}}(P \parallel Q_\theta)$!

4.3 Gibbs' Inequality: $D_{\text{KL}}(P \parallel Q) \ge 0$ (Full Proof)

ML EXAM PROOF (Information Theory & Loss Lower Bound) Theorem: $D_{\text{KL}}(P \parallel Q) \ge 0$, with equality if and only if $P = Q$
The proof (using the elementary tangent bound $\ln u \le u - 1$) Step 1 (Tangent inequality for $\ln u$): Because $f(u) = \ln u$ is strictly concave ($f''(u) = -1/u^2 < 0$), its graph lies strictly below its tangent line at $u = 1$ everywhere except at $u = 1$: $$\ln u \le u - 1 \quad \text{for all } u > 0 \qquad (\text{equality iff } u = 1)$$ Step 2 (Apply to $-D_{\text{KL}}(P \parallel Q)$): Assume $p_i > 0$ (terms with $p_i = 0$ contribute $0$). Set $u_i = \frac{q_i}{p_i}$: $$-D_{\text{KL}}(P \parallel Q) = \sum_{i=1}^k p_i \ln\!\left(\frac{q_i}{p_i}\right) \le \sum_{i=1}^k p_i \left(\frac{q_i}{p_i} - 1\right)$$ Step 3 (Use normalization $\sum p_i = \sum q_i = 1$): $$-D_{\text{KL}}(P \parallel Q) \le \sum_{i=1}^k (q_i - p_i) = \sum_{i=1}^k q_i - \sum_{i=1}^k p_i = 1 - 1 = 0$$ Multiplying by $-1$ reverses the inequality: $$D_{\text{KL}}(P \parallel Q) \ge 0$$ with equality iff $\frac{q_i}{p_i} = 1 \iff p_i = q_i$ for every $i$. $\blacksquare$
Why Cross-Entropy Loss has a unique minimum at $Q = P$ Because $H(P, Q) = H(P) + D_{\text{KL}}(P \parallel Q) \ge H(P)$, the lowest possible cross-entropy loss any classifier can ever achieve is the true data entropy $H(P)$, attained exclusively when the predicted distribution $Q$ matches the true distribution $P$!

Interactive KL Divergence Lab: True Distribution $P = (p, 1-p)$ vs. Model $Q = (q, 1-q)$

4.4 Exercises for Chapter 4

Core • Bayes' Theorem (Medical / Spam Screening)

Exercise 4.1: A rare defect occurs in $1\,\%$ of chips ($P(D) = 0.01$). A test detects a true defect with $99\,\%$ sensitivity ($P(+ \mid D) = 0.99$) and has a $2\,\%$ false-positive rate ($P(+ \mid \neg D) = 0.02$). If a chip tests positive, what is $P(D \mid +)$?

Hint: Compute $P(+) = P(+ \mid D)P(D) + P(+ \mid \neg D)P(\neg D) = 0.99(0.01) + 0.02(0.99)$.
Full solution: $P(+) = 0.0099 + 0.0198 = 0.0297 \implies P(D \mid +) = \frac{0.0099}{0.0297} = \frac{1}{3} \approx 33.3\,\%$.
Core • Shannon Entropy

Exercise 4.2: Compute the Shannon entropy in bits ($H_2(P) = -\sum p_i \log_2 p_i$) for a biased coin with $P = (\frac{3}{4}, \frac{1}{4})$ vs. a fair coin $U = (\frac{1}{2}, \frac{1}{2})$.

Hint: Use $\log_2(3/4) = \log_2 3 - 2 \approx 1.585 - 2 = -0.415$ and $\log_2(1/4) = -2$.
Full solution: $H_2(U) = 1.00\text{ bit}$; $H_2(P) = -\big(\frac{3}{4}(-0.415) + \frac{1}{4}(-2)\big) \approx 0.811\text{ bits}$ (lower uncertainty than the fair coin).

Mathematics for ML — Proof Index & Drill Trainer

Chapter Theorem / Derivation Shortcut
Chapter 1Softmax + Cross-Entropy Gradient ($\nabla_{\vec{z}} L = \vec{p} - \vec{y}$)
Chapter 2PCA Variance Maximization via Rayleigh Quotient & Lagrange Multipliers
Chapter 3Gradient Descent Learning Rate Stability Bound ($0 < \eta < 2/\lambda_{\max}$)
Chapter 4Gibbs' Inequality: Non-Negativity of KL Divergence ($D_{\text{KL}}(P \parallel Q) \ge 0$)

Interactive ML Mathematics Drill Trainer

Randomized ML Drills with Instant Feedback & Solutions

Correct streak: 0