✓ تم التحقق من المنهج الرسميمعايير الجودة والصرامة ↗
8

تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA)

🤖 AI Math Unit 8 — Dimensionality Reduction & PCA Applied 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.

▲ مبرهنة 8.1 — PCA via Spectral Decomposition
Let X \in \mathbb{R}^{N times d} be a zero-centered data matrix (mean \mathbf{\bar{x}} = 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.
● الفهم المفاهيمي العميق — تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (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\)).

يوجه تحليل المركبات الرئيسية المحور \(\text{PC}_1\) باتجاه المتجه الذاتي الأكبر لمصفوفة التغاير \(\Sigma\) لالتقاط أقصى تباين مسقط \(\lambda_1\).
⊙ مستكشف تفاعلي · تحليل المركبات الأساسية (PCA): المحور الرئيسي v₁ والإسقاطات المتعامدة \(v_{1}\)
تفاعلي
متوقع التباين على طول \(u(\theta)\)Var_\(\theta = 1.752\)
Optimal الأول المتجه الذاتي \(\theta\)*\(\theta * = 45.0^\circ\)
Explained التباين النسبة\(EVR_{1} = 90.0\%\)

تدوير الوحدة الاتجاه متجه \(u(\theta)\) خلال centered 2D بيانات cloud. PCA chooses زاوية \(\theta\)* أن maximizes التباين من متعامد المساقط (و minimizes العمودي reconstruction خطأ).

نسبة التباين المفسَّر لكل مركبة رئيسية متعامدة لتحديد عدد الأبعاد الكافية لضغط البيانات.
Covariance Entry (تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA))
\( \text{Cov}(X, Y) = \frac{1}{N-1}\sum (x_i - \bar{x})(y_i - \bar{y}) \)
Characteristic المعادلة
\( \det(\mathbf{\Sigma} - \lambda \mathbf{I}) = 0 \)
Explained Variance (تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA))
\( \text{Ratio}_k = \frac{\lambda_k}{\sum_{j=1}^d \lambda_j} \)
Projection (تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA))
\(\mathbf{z} = \mathbf{V}_k^T \mathbf{x} \in \mathbb{R}^k\) (reduced representation) (تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA))
◆ لماذا تعمل هذه القاعدة — الاشتقاق الرياضي (تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA))

Why Orthogonal Projection & Eigenvalue Characteristic Equations Work: Decompose \(\mathbf{u} = c\mathbf{v} + \mathbf{w}\) where \(\mathbf{w} \perp \mathbf{v}\). Taking the dot product with \(\mathbf{v}\) uses \(\mathbf{w}\cdot\mathbf{v} = 0\) to isolate \(c\):

\[ \mathbf{u}\cdot\mathbf{v} = c(\mathbf{v}\cdot\mathbf{v}) + 0 \implies c = \frac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{v}\|^2} \]

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
المسألة. 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?
▸ عرض خطوات الحل بالتفصيل


(a) Characteristic equation \( \det(\mathbf{\Sigma} - \lambda\mathbf{I}) = 0 \):
\[ \det \begin{pmatrix} 4 - \lambda & 2 \\ 2 & 1 - \lambda \end{pmatrix} = (4 - \lambda)(1 - \lambda) - (2)(2) = 0 \]
\[ \lambda^2 - 5\lambda + 4 - 4 = 0 \implies \lambda^2 - 5\lambda = 0 \implies \lambda(\lambda - 5) = 0 \].
Eigenvalues are \( \lambda_1 = 5 \) and \( \lambda_2 = 0 \).

(b) For \( \lambda_1 = 5 \):
\[ (\mathbf{\Sigma} - 5\mathbf{I})\mathbf{v} = \begin{pmatrix} -1 & 2 \\ 2 & -4 \end{pmatrix} \begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix} \implies -v_1 + 2v_2 = 0 \implies v_1 = 2v_2 \].
A directional vector is \( \begin{pmatrix} 2 \\ 1 \end{pmatrix} \). Normalizing to unit length:
\[ \|\mathbf{v}\| = \sqrt{2^2 + 1^2} = \sqrt{5} \implies \mathbf{v}_1 = \frac{1}{\sqrt{5}}\begin{pmatrix} 2 \\ 1 \end{pmatrix} = \begin{pmatrix} 2/\sqrt{5} \\ 1/\sqrt{5} \end{pmatrix} \approx \begin{pmatrix} 0.894 \\ 0.447 \end{pmatrix} \].

(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)
المسألة. 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?
▸ عرض خطوات الحل بالتفصيل

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)
المسألة. 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} \).
▸ عرض خطوات الحل بالتفصيل

Summing \( \text{TP} + \text{TN} = 68 + 80 = 148 \).

Worked Example \(D\) — Dimensionality Reduction, Covariance & PCA (Hard Application)
المسألة. 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' \)?
▸ عرض خطوات الحل بالتفصيل

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) \).

⚠️ أخطاء شائعة في الاختبار — تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (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\)).

تشخيص الأخطاء — مقارنة الخطأ الشائع بالطريقة الصحيحة (تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA))
الخطأ الشائع للطالبالسبب الرياضي للخطأالطريقة الصحيحة المعتمدة
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}\).
▲ استراتيجية الحل السريع والتحقق — تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA)

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 \).

تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA) — مسألة مهيكلة من ٦ درجات

6 نقاط الآلة الحاسبة مسموحة
في موضوع تقليل الأبعاد ومصفوفة التباين المشترك وتحليل المكونات الرئيسية (PCA)، ادرس الدالة \(f(x) = 5x^2 - 5x + 1\) على الفترة \([0, 3]\).
  1. (a)2 نقطة
    احسب قيمتي \(f(0)\) و \(f(2)\).
    معيار التصحيح والإجابة النموذجية
    • [M1] يعوّض القيمتين في الدالة (1 نقطة)
    • [A1] يحصل على 1 و 11 (1 نقطة)
  2. (b)2 نقطة
    أوجد المشتقة \(f'(x)\) والنقطة الحرجة \(x_c\).
    معيار التصحيح والإجابة النموذجية
    • [M1] يشتق الدالة التربيعية (1 نقطة)
    • [A1] يحل لإيجاد النقطة الحرجة (1 نقطة)
  3. (c)2 نقطة
    احسب متوسط معدل التغيّر من \(x = 0\) إلى \(x = 2\).
    معيار التصحيح والإجابة النموذجية
    • [M1] يطبّق قانون متوسط معدل التغيّر (1 نقطة)
    • [A1] يبسّط الناتج إلى 5 (1 نقطة)
الحل الكامل التفصيلي
(أ) \(f(0)=1\) و \(f(2)=11\). (ب) \(f'(x)=10x-5\). (ج) متوسط معدل التغيّر يساوي \(5\).
📝 اختبار الفصل