🤖 AI Math Unit 8 — Dimensionality Reduction & PCAApplied STEM · Curse of dimensionality in high-dimensional data · Sample covariance matrix Σ · Eigenvalues λ and Eigenvectors v · Principal Component Analysis (PCA) projection · Explained variance ratio and data compression
Real datasets frequently have hundreds or thousands of correlated features. Principal Component Analysis (PCA) identifies the orthogonal axes of maximum variance, compressing high-dimensional data while preserving essential information.
▲ Theorem 8.1 — PCA via Spectral Decomposition
Let X \in \mathbb{R}^{N times d}X∈RN×d be a zero-centered data matrix (mean \mathbf{\bar{x}} = 0xˉ=0). 1. The empirical covariance matrix is \( \mathbf{\Sigma} = \frac{1}{N-1} \mathbf{X}^T \mathbf{X} \in \mathbb{R}^{d \times d} \). 2. Because \( \mathbf{\Sigma} \) is symmetric positive semi-definite, it admits an orthonormal eigen-decomposition: \[ \mathbf{\Sigma} \mathbf{v}_i = \lambda_i \mathbf{v}_i, \quad \lambda_1 \ge \lambda_2 \ge \dots \ge \lambda_d \ge 0 \] 3. The first principal component \( \mathbf{v}_1 \) is the unit eigenvector associated with the largest eigenvalue \( \lambda_1 \), maximizing the variance of the projected data.
● Deep Conceptual Intuition — Dimensionality Reduction, Covariance & PCA
Linear Structure, Inner Products & Geometric Transformations: In \(\mathbb{R}^n\), the dot product \(\mathbf{u}\cdot\mathbf{v} = \|\mathbf{u}\|\|\mathbf{v}\|\cos\theta = \sum_{i=1}^n u_i v_i\) encodes orthogonality (\(\mathbf{u}\perp\mathbf{v} \iff \mathbf{u}\cdot\mathbf{v} = 0\)) and orthogonal projection \(\operatorname{proj}_{\mathbf{v}}\mathbf{u} = \dfrac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{v}\|^2}\mathbf{v}\). For a matrix transformation \(A \in \mathbb{R}^{n\times n}\), \(|\det(A)|\) measures the local volume scaling factor, and \(A\) is invertible if and only if \(\det(A) \ne 0\) (equivalently, all eigenvalues \(\lambda_i \ne 0\)).
Principal Component Analysis aligns \(\text{PC}_1\) with the dominant eigenvector of covariance matrix \(\Sigma\), capturing maximum projected variance \(\lambda_1\).
⊙ Explorer · PCA: Covariance Point Cloud, Principal Axis \(v_{1}\) & Projections
interactive
Live numerical table for PCA: Covariance Point Cloud, Principal Axis \(v_{1}\) & Projections
Parameter / Metric
Value
Projected Variance along \(u(\theta)\)Var_\(\theta = 1.752\)
Optimal First Eigenvector \(\theta\)*\(\theta * = 45.0^\circ\)
Explained Variance Ratio\(EVR_{1} = 90.0\%\)
Rotate unit direction vector \(u(\theta)\) through the centered 2D data cloud. PCA chooses the angle \(\theta\)* that maximizes the variance of the orthogonal projections (and minimizes perpendicular reconstruction error).
Proportion of total dataset variance captured across orthogonal components.
For eigenvalues, \(A\mathbf{v} = \lambda\mathbf{v}\) with \(\mathbf{v} \ne \mathbf{0}\) is equivalent to \((A - \lambda I)\mathbf{v} = \mathbf{0}\). A homogeneous linear system has a non-trivial nullspace vector \(\mathbf{v} \ne \mathbf{0}\) if and only if the matrix \(A - \lambda I\) is singular, yielding the characteristic polynomial \(\det(A - \lambda I) = 0\).
Worked Example 8.A — Finding Principal Components of 2D Data
Problem. A 2D centered dataset has sample covariance matrix: \[ \mathbf{\Sigma} = \begin{pmatrix} 4 & 2 \\ 2 & 1 \end{pmatrix} \] (a) Find the eigenvalues \( \lambda_1 \) and \( \lambda_2 \). (b) Find the unit eigenvector \( \mathbf{v}_1 \) corresponding to the principal component. (c) What percentage of total variance is explained by the first principal component?
(c) Total variance = \( \lambda_1 + \lambda_2 = 5 + 0 = 5 \). Percentage explained = \( \frac{5}{5} = 100\% \). (The data lies perfectly along a 1D line in 2D space!). Answer: \( \lambda_1 = 5, \, \lambda_2 = 0 \); \( \mathbf{v}_1 = [0.894, 0.447]^T \); 100% variance explained.
Worked Example \(B\) — Dimensionality Reduction, Covariance & PCA (Easy Application)
Problem. Consider a 2D data point \( \mathbf{v} = \begin{bmatrix} 3 \\ -4 \end{bmatrix} \). What is the squared Euclidean norm (or squared magnitude) of this vector?
▸ Show step-by-step solution
The squared Euclidean norm of a vector \( \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} \) is given by \( \|\mathbf{v}\|^2 = v_1^2 + v_2^2 \). For the given vector \( \mathbf{v} = \begin{bmatrix} 3 \\ -4 \end{bmatrix} \), the squared Euclidean norm is \( (3)^2 + (-4)^2 = 9 + 16 = 25 \).
Worked Example \(C\) — Dimensionality Reduction, Covariance & PCA (Medium Application)
Problem. A binary classifier \( p(t) \) produces the confusion matrix below with \( \text{TP} = 68 \), \( \text{FP} = 10 \), \( \text{FN} = 48 \), and \( \text{TN} = 80 \). Determine the total number of correct classifications \( q = \text{TP} + \text{TN} \).
Worked Example \(D\) — Dimensionality Reduction, Covariance & PCA (Hard Application)
Problem. Consider a 2D dataset represented by the points \( A = (1, 2) \), \( B = (4, 2) \), and \( C = (2, 5) \). If this dataset undergoes a linear transformation represented by the matrix \( M = \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} \), what are the coordinates of the transformed points \( A' \), \( B' \), and \( C' \)?
▸ Show step-by-step solution
The transformation of a point \( \mathbf{x} \) by a matrix \( M \) is given by \( M \mathbf{x} \). We apply the matrix \( M = \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} \) to each point:
For point \( A = (1, 2) \), the transformed point \( A' \) is:
\( \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 1 \\ 2 \end{pmatrix} = \begin{pmatrix} 2 \times 1 + 0 \times 2 \\ 0 \times 1 + 1 \times 2 \end{pmatrix} = \begin{pmatrix} 2 \\ 2 \end{pmatrix} \) So, \( A' = (2, 2) \).
For point \( B = (4, 2) \), the transformed point \( B' \) is:
\( \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 4 \\ 2 \end{pmatrix} = \begin{pmatrix} 2 \\ 2 \end{pmatrix} \) So, \( B' = (8, 2) \).
For point \( C = (2, 5) \), the transformed point \( C' \) is:
\( \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 2 \\ 5 \end{pmatrix} = \begin{pmatrix} 2 \times 2 + 0 \times 5 \\ 0 \times 2 + 1 \times 5 \end{pmatrix} = \begin{pmatrix} 4 \\ 5 \end{pmatrix} \) So, \( C' = (4, 5) \).
Therefore, the transformed points are \( A' = (2, 2) \), \( B' = (8, 2) \), and \( C' = (4, 5) \).
⚠️ Common Exam Traps — Dimensionality Reduction, Covariance & PCA
1. Non-Commutativity of Matrix Multiplication & Cross Products: On Mathematics for Artificial Intelligence & Machine Learning, assuming \(AB = BA\) (so expanding \((A+B)^2\) as \(A^2 + 2AB + B^2\) instead of \(A^2 + AB + BA + B^2\)) or forgetting \(\mathbf{u}\times\mathbf{v} = -(\mathbf{v}\times\mathbf{u})\) invalidates matrix proofs.
2. Using Position Vectors Instead of Direction Vectors for Angles: To find the angle at vertex \(B\) of triangle \(ABC\), you must use tail-to-tail vectors \(\overrightarrow{BA}\) and \(\overrightarrow{BC}\), never \(\overrightarrow{AB}\cdot\overrightarrow{BC}\) (which finds the exterior supplementary angle \(180^\circ - B\)).
Error Diagnosis — Common Student Traps vs. Exam-Board Method (Dimensionality Reduction, Covariance & PCA)
Common Student Trap
Why It Fails Mathematically
Correct Exam-Board Method
Computing angle at \(B\) using \(\overrightarrow{AB}\cdot\overrightarrow{BC}\)
Vectors are head-to-tail instead of tail-to-tail, giving \(180^\circ - \theta\).
Reverse \(\overrightarrow{AB}\) so both emanate from \(B\): use \(\overrightarrow{BA}\cdot\overrightarrow{BC}\).
Using the same parameter \(t\) for two intersecting 3D lines \(\mathbf{r}_1(t) = \mathbf{r}_2(t)\)
Tests for a simultaneous collision at time \(t\) rather than geometric intersection of paths.
Assign distinct parameters \(\lambda\) and \(\mu\) to the two lines before equating components.
Assuming \((AB)^{-1} = A^{-1}B^{-1}\)
Multiplying \((AB)(A^{-1}B^{-1})\) does not cancel inner factors when \(AB \ne BA\).
Use the shoe-sock reversal law: \((AB)^{-1} = B^{-1}A^{-1}\).
Fast Matrix & Vector Verification (Mathematics for Artificial Intelligence & Machine Learning): Check every \(2\times 2\) or \(3\times 3\) eigenvalue computation using the trace and determinant invariants: \(\sum \lambda_i = \operatorname{tr}(A)\) (sum of diagonal entries) and \(\prod \lambda_i = \det(A)\).
[Practice 1 · Easy] Consider a dataset of observations \(\{x_i\}_{i=1}^n\) where each \(x_i\) is a 2-dimensional vector. The sample covariance matrix for this dataset is given by:
\[ S = \begin{pmatrix} 4 & -2 \\ -2 & 1 \end{pmatrix} \]
Principal Component Analysis (PCA) is applied to this dataset. The first principal component corresponds to the direction with the largest variance. Let the direction vector of the first principal component be \(\mathbf{v}_1 = \begin{pmatrix} a \\ b \end{pmatrix}\). The variance explained by this principal component is given by the corresponding eigenvalue \(\lambda_1\).
If \(\mathbf{v}_1\) is a unit vector, what is the value of \(a^2+b^2\)?
💡 Hint 1 of 3
The first principal component direction vector \(\mathbf{v}_1\) is an eigenvector of the covariance matrix \(S\).
💡 Hint 2 of 3
The variance explained by this component is the corresponding eigenvalue \(\lambda_1\). The problem states that \(\mathbf{v}_1 = \begin{pmatrix} a \\ b \end{pmatrix}\) is a unit vector.
💡 Hint 3 of 3
The specific values of \(a\) and \(b\) and the eigenvalues of \(S\) are not needed to answer this question, as it directly asks for the property of a unit vector.
The first principal component direction vector \(\mathbf{v}_1\) is an eigenvector of the covariance matrix \(S\). The variance explained by this component is the corresponding eigenvalue \(\lambda_1\). The problem states that \(\mathbf{v}_1 = \begin{pmatrix} a \\ b \end{pmatrix}\) is a unit vector. By definition, a unit vector has a magnitude of 1. The squared magnitude of a vector \(\begin{pmatrix} a \\ b \end{pmatrix}\) is \(a^2 + b^2\). Therefore, if \(\mathbf{v}_1\) is a unit vector, its squared magnitude must be 1, which means \(a^2 + b^2 = 1\). The specific values of \(a\) and \(b\) and the eigenvalues of \(S\) are not needed to answer this question, as it directly asks for the property of a unit vector.
[Practice 2 · Medium] Consider a dataset of \( n \) data points, each residing in \( \mathbb{R}^D \). We are performing Principal Component Analysis (PCA) to reduce the dimensionality. The first three principal components capture \( 70\% \) of the total variance, the first six capture \( 85\% \), and the first ten capture \( 92\% \). You are tasked with selecting a subset of principal components for a downstream machine learning model. If the model requires that at least \( 90\% \) of the original variance be retained, and you want to use the minimum possible number of principal components, what is the dimensionality of the transformed data?
💡 Hint 1 of 3
The problem requires us to find the minimum number of principal components such that the cumulative explained variance is at least \( 90\% \). The provided information states: - The first 3 principal components capture \( 70\% \) of the variance.
💡 Hint 2 of 3
- The first 6 principal components capture \( 85\% \) of the variance. - The first 10 principal components capture \( 92\% \) of the variance.
💡 Hint 3 of 3
Therefore, the minimum number of principal components required to retain at least \(90\%\) of the variance is 10. When PCA reduces the dimensionality of data from \(\mathbb{R}^D\) to \(\mathbb{R}^k\) using the top \(k\) principal components, the dimension of each transformed data point is \(k\). In this case, \(k\).
The problem requires us to find the minimum number of principal components such that the cumulative explained variance is at least \( 90\% \). The provided information states:
- The first 3 principal components capture \( 70\% \) of the variance.
- The first 6 principal components capture \( 85\% \) of the variance.
- The first 10 principal components capture \( 92\% \) of the variance.
We need to find the smallest \( k \) such that the cumulative variance captured by the first \( k \) principal components is \( \ge 90\% \).
Checking the given values:
- For \( k = 3 \), variance captured = \( 70\% \), which is less than \( 90\% \).
- For \( k = 6 \), variance captured = \( 85\% \), which is less than \( 90\% \).
- For \( k = 10 \), variance captured = \( 92\% \), which is greater than or equal to \( 90\% \).
Therefore, the minimum number of principal components required to retain at least \( 90\% \) of the variance is 10. When PCA reduces the dimensionality of data from \( \mathbb{R}^D \) to \( \mathbb{R}^k \) using the top \( k \) principal components, the dimension of each transformed data point is \( k \). In this case, \( k=10 \).
[Practice 3 · Hard] In training a language model token predictor, a binary token occurs \( k = 6 \) times across \( n = 20 \) independent trials. What is the Maximum Likelihood Estimate \( \hat{p}_{\text{MLE}} \) of the token probability?
💡 Hint 1 of 3
For a Bernoulli likelihood \( L(p) = p^k (1-p)^{n-k} \), the log-likelihood is \( \ln L = k\ln p + (n-k)\ln(1-p) \).
💡 Hint 2 of 3
Setting derivative to zero: \(\frac{k}{p} - \frac{n-k}{1-p} = 0\). Substitute and simplify: \(\hat{p} = \frac{k}{n}\).
💡 Hint 3 of 3
Evaluate the simplified expression: \(\hat{p} = \frac{6}{20}\).
For a Bernoulli likelihood \( L(p) = p^k (1-p)^{n-k} \), the log-likelihood is \( \ln L = k\ln p + (n-k)\ln(1-p) \). Setting derivative to zero: \( \frac{k}{p} - \frac{n-k}{1-p} = 0 \implies \hat{p} = \frac{k}{n} = \frac{6}{20} = 0.300 \).
[Practice 4 · Easy] An Ordinary Least Squares linear model \( \hat{p}(t) = 2t + 11 \) is evaluated at \( t = 3 \). Determine the predicted response \( \hat{p}(3) \).
💡 Hint 1 of 3
Start from the given mathematical expression in the prompt: \(\hat{p}(t) = 2t + 11\).
💡 Hint 2 of 3
Write out the unsimplified expression: \(2(3) + 11\).
💡 Hint 3 of 3
Perform the arithmetic in \(2(3) + 11\) to find the final value.
Evaluating \( 2(3) + 11 = 17 \).
[Practice 5 · Medium] A machine learning diagnostic test has sensitivity \( P(\text{Positive} | \text{Defect}) = 0.90 \). If the defect rate in production is \( P(\text{Defect}) = 0.10 \), find the joint probability of a defect and a positive test result \( P(\text{Defect} \cap \text{Positive}) \).
💡 Hint 1 of 3
By the multiplication rule of conditional probability: \(P(\text{Defect} \cap \text{Positive}) = P(\text{Defect}) \times P(\text{Positive} | \text{Defect})\).
💡 Hint 2 of 3
Substitute and simplify: \(P(\text{Defect} \cap \text{Positive}) = 0.10 \times 0.90\).
💡 Hint 3 of 3
Compute the final value from: \(0.10 \times 0.90\).
By the multiplication rule of conditional probability: \( P(\text{Defect} \cap \text{Positive}) = P(\text{Defect}) \times P(\text{Positive} | \text{Defect}) = 0.10 \times 0.90 = 0.0900 \).
Dimensionality Reduction, Covariance & PCA — 6-Mark Structured Problem
6 pts
Calculator Active
For Dimensionality Reduction, Covariance & PCA, examine the quadratic-rate model \(f(x) = 5x^2 - 5x + 1\) on \(x \in [0, 3]\).
(a)2 pts
Compute \(f(0)\) and \(f(2)\).
Scoring Guideline & Justification
[M1]Substitutes x=0 and x=2(1 pt)
[A1]Obtains 1 and 11(1 pt)
(b)2 pts
Find the derivative/rate \(f'(x)\) and critical point \(x_c\).
Scoring Guideline & Justification
[M1]Differentiates to 10x - 5(1 pt)
[A1]Solves x_c = 5/10(1 pt)
(c)2 pts
Calculate the average rate of change from \(x = 0\) to \(x = 2\).