← Machine Learning

SVD and PCA

1. Eigenvalues and Eigenvectors

(1) Definition

For an n×nn\times n matrix AA, λ\lambda satisfying Av⃗=λv⃗A\vec{v}=\lambda \vec{v} is called an eigenvalue, and v⃗≠0⃗\vec{v}\neq\vec{0} is called an eigenvector.

(2) Derivation

1.1. Find eigenvalue λ\lambda satisfying Det(A−λI)=0Det(A-\lambda I)=0.

2.2. Substitute the obtained eigenvalue into (A−λI)v⃗=0(A-\lambda I)\vec{v}=0 to find eigenvector v⃗\vec{v}.

3.3. For eigenvalue λ\lambda and eigenvector v⃗\vec{v} of n×nn\times n matrix AA, Eλ=Span(v⃗)E_\lambda=Span(\vec{v}) is called the eigenspace.

(3) Theorems

1.1. The eigenvalues of a triangular matrix are its diagonal elements.

2.2. Let the distinct eigenvalues of an n×nn\times n matrix be λ1,λ2,⋯ ,λk\lambda_1, \lambda_2, \cdots, \lambda_k, and let the eigenvectors corresponding to each eigenvalue be v⃗1,v⃗2,⋯ ,v⃗k\vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k. Then {v⃗1,v⃗2,⋯ ,v⃗k}\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} is linearly independent.


2. Gram-Schmidt Orthogonalization

1) Orthogonality of Two Vectors

(1) Definition

For elements u⃗,v⃗\vec{u},\vec{v} in an inner product space VV, u⃗\vec{u} and v⃗\vec{v} are orthogonal means their inner product is 00. That is, u⃗⊥v⃗⇔ <u⃗,v⃗>=0.\vec{u}\perp \vec{v} \Leftrightarrow \ <\vec{u},\vec{v}>=0.

2) Norm of a Vector

(1) Definition

For element u⃗\vec{u} in an inner product space VV, the norm of vector u⃗\vec{u} is defined as ∥u⃗∥=<u⃗,u⃗>\|\vec{u}\|=\sqrt{<\vec{u},\vec{u}>}.

(2) Theorems

1. ∥u⃗+v⃗∥2=∥u⃗∥2+∥v⃗∥2+2<u⃗,v⃗>1.\ \|\vec{u}+\vec{v}\|^2=\|\vec{u}\|^2+\|\vec{v}\|^2+2<\vec{u},\vec{v}>

2. ∥u⃗+v⃗∥2+∥u⃗−v⃗∥2=2∥u⃗∥2+2∥v⃗∥22.\ \|\vec{u}+\vec{v}\|^2+\|\vec{u}-\vec{v}\|^2=2\|\vec{u}\|^2+2\|\vec{v}\|^2

3. <u⃗,v⃗>=14∥u⃗+v⃗∥2−14∥u⃗−v⃗∥23.\ <\vec{u},\vec{v}>=\dfrac{1}{4}\|\vec{u}+\vec{v}\|^2-\dfrac{1}{4}\|\vec{u}-\vec{v}\|^2

4. 4.\ A necessary and sufficient condition for u⃗,v⃗\vec{u}, \vec{v} to be orthogonal is ∥u⃗+v⃗∥2=∥u⃗∥2+∥v⃗∥2\|\vec{u}+\vec{v}\|^2=\|\vec{u}\|^2+\|\vec{v}\|^2.

5. ∥<u⃗,v⃗>∥≤∥u⃗∥∥v⃗∥5.\ \|<\vec{u}, \vec{v}>\| \le \|\vec{u}\| \|\vec{v}\| (equality holds when u⃗\vec{u} and v⃗\vec{v} are parallel)

6. ∥u⃗+v⃗∥≤∥u⃗∥+∥v⃗∥6.\ \|\vec{u}+\vec{v}\| \le \|\vec{u}\| + \|\vec{v}\|

  • The dot product u⃗⋅v⃗=u⃗Tv⃗\vec{u}\cdot \vec{v}=\vec{u}^T\vec{v} defined in Rn\mathbb{R}^n is also an inner product.
  • Therefore, orthogonality can be discussed for the dot product defined in Rn\mathbb{R}^n.
  • The following content also holds for general inner product spaces, but is described limited to the dot product defined in Rn\mathbb{R}^n.

3) Orthogonal Set

(1) Definition

For v⃗1, v⃗2, ⋯ , v⃗k∈Rn\vec{v}_1,\ \vec{v}_2,\ \cdots,\ \vec{v}_k \in \mathbb{R}^n with respect to the dot product defined in Rn\mathbb{R}^n, {v⃗1, v⃗2, ⋯ , v⃗k}\{ \vec{v}_1,\ \vec{v}_2,\ \cdots,\ \vec{v}_k \} being an orthogonal set means v⃗i⋅v⃗j=0,i≠j\vec{v}_i \cdot \vec{v}_j=0, \quad i\neq j.

(2) Theorems

1.1. For any vector u⃗∈V\vec{u} \in V in the subspace VV of Rn\mathbb{R}^n generated by orthogonal set B={v⃗1,v⃗2,⋯ ,v⃗k}B=\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} (i.e., V=Span(B)⊆RnV=Span(B) \subseteq \mathbb{R}^n),

u⃗=u⃗⋅v⃗1v⃗1⋅v⃗1v⃗1+u⃗⋅v⃗2v⃗2⋅v⃗2v⃗2+⋯+u⃗⋅v⃗kv⃗k⋅v⃗kv⃗k\quad \vec{u}=\dfrac{\vec{u} \cdot \vec{v}_1}{\vec{v}_1 \cdot \vec{v}_1}\vec{v}_1 + \dfrac{\vec{u} \cdot \vec{v}_2}{\vec{v}_2 \cdot \vec{v}_2}\vec{v}_2 + \cdots + \dfrac{\vec{u} \cdot \vec{v}_k}{\vec{v}_k \cdot \vec{v}_k}\vec{v}_k can be represented.

2.2. If orthogonal set {v⃗1,v⃗2,⋯ ,v⃗k}\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} does not contain the zero vector, then {v⃗1,v⃗2,⋯ ,v⃗k}\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} is linearly independent.

4) Orthogonal Basis

(1) Definition

For subspace VV of Rn\mathbb{R}^n, if B={v⃗1,v⃗2,⋯ ,v⃗k}B=\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} is both ①a basis of VV and ②an orthogonal set, then BB is an orthogonal basis of VV.

5) Orthonormal Set

(1) Definition

{v⃗1, v⃗2, ⋯ , v⃗k}\{ \vec{v}_1,\ \vec{v}_2,\ \cdots,\ \vec{v}_k \} being an orthonormal set means ① <v⃗i,v⃗j>=0,i≠j<\vec{v}_i, \vec{v}_j>=0, \quad i\neq j ② ∥v⃗i∥=1,∀i\|\vec{v}_i\|=1, \quad \forall{i}

Note: The standard basis of Rn\mathbb{R}^n is an orthonormal set.

6) Orthonormal Basis

(1) Definition

For subspace VV of Rn\mathbb{R}^n, if B={v⃗1,v⃗2,⋯ ,v⃗k}B=\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} is both ①a basis of VV and ②an orthonormal set, then BB is an orthogonal basis of WW.

(2) Theorems

1.1. For any vector u⃗∈V\vec{u} \in V in the subspace VV of Rn\mathbb{R}^n generated by orthonormal set B={v⃗1,v⃗2,⋯ ,v⃗k}B=\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \}, u⃗ = (u⃗⋅v⃗1)v⃗1 + (u⃗⋅v⃗2)v⃗2 + ⋯ + (u⃗⋅v⃗k)v⃗k\quad \vec{u} \ = \ (\vec{u} \cdot \vec{v}_1)\vec{v}_1 \ + \ (\vec{u} \cdot \vec{v}_2)\vec{v}_2 \ + \ \cdots \ + \ (\vec{u} \cdot \vec{v}_k)\vec{v}_k can be represented.

2.2. If the column vectors of m×n (m≥n)m\times n \ (m\ge n) matrix AA are orthonormal, then ATA=InA^TA=I_n.

7) Orthogonal Matrix

(1) Definition

AA being an orthogonal matrix means ① A:n×nA: n \times n matrix, ② The column vectors of AA form an orthonormal set.

(2) Theorems

1.1. A necessary and sufficient condition for square matrix AA to be an orthogonal matrix is ATA=IA^TA=I, i.e., AT=A−1A^T=A^{-1}. 2.2. From AT=A−1A^T=A^{-1}, we also have AAT=IAA^T=I, which means that if square matrix AA is an orthogonal matrix, the set of row vectors of AA is also an orthonormal set.

8) Orthogonal Projection

(1) Derivation

[1] Orthogonal Projection in R2\mathbb{R}^2

For linearly independent u⃗,v⃗∈R2\vec{u},\vec{v} \in \mathbb{R}^2 (i.e., u⃗,v⃗\vec{u},\vec{v} form a basis of R2\mathbb{R}^2)

① upr⃗=u⃗⋅v⃗v⃗⋅v⃗v⃗\vec{u_{pr}}=\dfrac{\vec{u} \cdot \vec{v}}{\vec{v} \cdot \vec{v}}\vec{v}\qquad: Orthogonal projection of u⃗\vec{u} onto v⃗\vec{v} (vector projection)

② uc⃗=u⃗−upr⃗\vec{u_c}=\vec{u}-\vec{u_{pr}} \qquad : Vector component of u⃗\vec{u} orthogonal to v⃗\vec{v}

(i) upr⃗+uc⃗=u⃗\vec{u_{pr}}+\vec{u_c}=\vec{u} \qquad(ii) upr⃗∥v⃗\vec{u_{pr}} \parallel \vec{v} \qquad (iii) uc⃗⊥v⃗\vec{u_c} \perp \vec{v}

SVD_orthogonal_projection_r2
[2] Orthogonal Projection in R3\mathbb{R}^3

For linearly independent u⃗,v⃗1,v⃗2∈R3\vec{u},\vec{v}_1,\vec{v}_2 \in \mathbb{R}^3, orthogonal vectors v⃗1,v⃗2\vec{v}_1,\vec{v}_2

① u1⃗=u⃗⋅v⃗1v⃗1⋅v⃗1v⃗1\vec{u_{1}}=\dfrac{\vec{u} \cdot \vec{v}_1}{\vec{v}_1 \cdot \vec{v}_1}\vec{v}_1\qquad: Orthogonal projection of u⃗\vec{u} onto v⃗1\vec{v}_1

② u2⃗=u⃗⋅v⃗2v⃗2⋅v⃗2v⃗2\vec{u_{2}}=\dfrac{\vec{u} \cdot \vec{v}_2}{\vec{v}_2 \cdot \vec{v}_2}\vec{v}_2\qquad: Orthogonal projection of u⃗\vec{u} onto v⃗2\vec{v}_2

③ upr⃗=u1⃗+u2⃗=u⃗⋅v⃗1v⃗1⋅v⃗1v⃗1+u⃗⋅v⃗2v⃗2⋅v⃗2v⃗2\vec{u_{pr}}= \vec{u_{1}} + \vec{u_{2}} = \dfrac{\vec{u} \cdot \vec{v}_1}{\vec{v}_1 \cdot \vec{v}_1}\vec{v}_1 + \dfrac{\vec{u} \cdot \vec{v}_2}{\vec{v}_2 \cdot \vec{v}_2}\vec{v}_2 \qquad : Orthogonal projection of u⃗\vec{u} onto Span(v⃗1,v⃗2)Span(\vec{v}_1,\vec{v}_2)

④ uc⃗=u⃗−upr⃗=u⃗−u⃗⋅v⃗1v⃗1⋅v⃗1v⃗1−u⃗⋅v⃗2v⃗2⋅v⃗2v⃗2\vec{u_c}=\vec{u}-\vec{u_{pr}}=\vec{u}-\dfrac{\vec{u} \cdot \vec{v}_1}{\vec{v}_1 \cdot \vec{v}_1}\vec{v}_1 - \dfrac{\vec{u} \cdot \vec{v}_2}{\vec{v}_2 \cdot \vec{v}_2}\vec{v}_2 \qquad : Vector component of u⃗\vec{u} orthogonal to Span(v⃗1,v⃗2)Span(\vec{v}_1,\vec{v}_2)

SVD_orthogonal_projection_r3
[3] Orthogonal Projection in Rn\mathbb{R}^n

Given an orthogonal basis B={v⃗1,v⃗2,⋯ ,v⃗k}B=\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} for subspace VV of Rn\mathbb{R}^n, for any vector u⃗\vec{u} in VV

① upr⃗=u⃗⋅v⃗1v⃗1⋅v⃗1v⃗1+u⃗⋅v⃗2v⃗2⋅v⃗2v⃗2+⋯+u⃗⋅v⃗kv⃗k⋅v⃗kv⃗k\vec{u_{pr}}=\dfrac{\vec{u} \cdot \vec{v}_1}{\vec{v}_1 \cdot \vec{v}_1}\vec{v}_1 + \dfrac{\vec{u} \cdot \vec{v}_2}{\vec{v}_2 \cdot \vec{v}_2}\vec{v}_2 + \cdots + \dfrac{\vec{u} \cdot \vec{v}_k}{\vec{v}_k \cdot \vec{v}_k}\vec{v}_k \qquad : Orthogonal projection of u⃗\vec{u} onto VV

② uc⃗=u⃗−upr⃗=u⃗−u⃗⋅v⃗1v⃗1⋅v⃗1v⃗1−u⃗⋅v⃗2v⃗2⋅v⃗2v⃗2−⋯−u⃗⋅v⃗kv⃗k⋅v⃗kv⃗k\vec{u_c}=\vec{u}-\vec{u_{pr}}=\vec{u}-\dfrac{\vec{u} \cdot \vec{v}_1}{\vec{v}_1 \cdot \vec{v}_1}\vec{v}_1 - \dfrac{\vec{u} \cdot \vec{v}_2}{\vec{v}_2 \cdot \vec{v}_2}\vec{v}_2 - \cdots - \dfrac{\vec{u} \cdot \vec{v}_k}{\vec{v}_k \cdot \vec{v}_k}\vec{v}_k \qquad : Vector component of u⃗\vec{u} orthogonal to VV

(2) Theorem: Gram-Schmidt Orthogonalization Process

For subspace VV of Rn\mathbb{R}^n, when B={v⃗1,v⃗2,⋯ ,v⃗k}B=\{ \vec{v}_1, \vec{v}_2, \cdots, \vec{v}_k \} is a basis of VV, an orthogonal basis C={u⃗1,u⃗2,⋯ ,u⃗k}C=\{ \vec{u}_1, \vec{u}_2, \cdots, \vec{u}_k \} and orthonormal basis D={w⃗1,w⃗2,⋯ ,w⃗k}D=\{ \vec{w}_1, \vec{w}_2, \cdots, \vec{w}_k \} also exist. Here, CC and DD can be obtained as follows:

u⃗1=v⃗1\vec{u}_1=\vec{v}_1 u⃗2=v⃗2−v⃗2⋅u⃗1u⃗1⋅u⃗1u⃗1\vec{u}_2=\vec{v}_2-\dfrac{\vec{v}_2 \cdot \vec{u}_1}{\vec{u}_1 \cdot \vec{u}_1}\vec{u}_1 u⃗3=v⃗3−v⃗3⋅v⃗1u⃗1⋅u⃗1u⃗1−v⃗3⋅u⃗2u⃗2⋅u⃗2u⃗2\vec{u}_3=\vec{v}_3-\dfrac{\vec{v}_3 \cdot \vec{v}_1}{\vec{u}_1 \cdot \vec{u}_1}\vec{u}_1-\dfrac{\vec{v}_3 \cdot \vec{u}_2}{\vec{u}_2 \cdot \vec{u}_2}\vec{u}_2 ⋯\cdots u⃗k=v⃗k−v⃗k⋅u⃗1u⃗1⋅u⃗1u⃗1−v⃗k⋅u⃗2u⃗2⋅u⃗2u⃗2−⋯−v⃗k⋅u⃗k−1u⃗k−1⋅u⃗k−1u⃗k−1\vec{u}_k=\vec{v}_k-\dfrac{\vec{v}_k \cdot \vec{u}_1}{\vec{u}_1 \cdot \vec{u}_1}\vec{u}_1-\dfrac{\vec{v}_k \cdot \vec{u}_2}{\vec{u}_2 \cdot \vec{u}_2}\vec{u}_2 - \cdots -\dfrac{\vec{v}_k \cdot \vec{u}_{k-1}}{\vec{u}_{k-1} \cdot \vec{u}_{k-1}}\vec{u}_{k-1} w⃗1=u⃗∥u1∥,w⃗2=u⃗∥u2∥,⋯ ,w⃗k=u⃗∥uk∥\vec{w}_1=\dfrac{\vec{u}}{\|u_1\|}, \quad \vec{w}_2=\dfrac{\vec{u}}{\|u_2\|}, \quad \cdots, \quad \vec{w}_k=\dfrac{\vec{u}}{\|u_k\|}

① u⃗1=v⃗1\vec{u}_1=\vec{v}_1\qquadNow that we've created u⃗1\vec{u}_1, we don't use v⃗1\vec{v}_1 anymore. ② Since we want to find vector u⃗2\vec{u}_2 orthogonal to u⃗1\vec{u}_1,

u⃗2=v⃗2c=v⃗2−v⃗2pr=v⃗2−v⃗2⋅u⃗1u⃗1⋅u⃗1u⃗1\quad \vec{u}_2=\vec{v}_{2c}=\vec{v}_2-\vec{v}_{2pr}=\vec{v}_2-\dfrac{\vec{v}_2 \cdot \vec{u}_1}{\vec{u}_1 \cdot \vec{u}_1}\vec{u}_1
SVD_gram_schmidt_r2

\quad Now that we've created u⃗2\vec{u}_2, we don't use v⃗2\vec{v}_2 anymore.

③ Since we made u⃗1\vec{u}_1 and u⃗2\vec{u}_2 orthogonal above, to find u⃗3\vec{u}_3 orthogonal to Span(u⃗1,u⃗2)Span(\vec{u}_1,\vec{u}_2)

u⃗2=v⃗3c=v⃗3−v⃗3pr=v⃗3−v⃗3⋅u⃗1u⃗1⋅u⃗1u⃗1−v⃗3⋅u⃗2u⃗2⋅u⃗2u⃗2\quad \vec{u}_2=\vec{v}_{3c}=\vec{v}_3-\vec{v}_{3pr}=\vec{v}_3-\dfrac{\vec{v}_3 \cdot \vec{u}_1}{\vec{u}_1 \cdot \vec{u}_1}\vec{u}_1-\dfrac{\vec{v}_3 \cdot \vec{u}_2}{\vec{u}_2 \cdot \vec{u}_2}\vec{u}_2
SVD_gram_schmidt_r3

\quad Now that we've created u⃗3\vec{u}_3, we don't use v⃗3\vec{v}_3 anymore.

④ Repeating this,

u⃗k=v⃗k−v⃗k⋅u⃗1u⃗1⋅u⃗1u⃗1−v⃗k⋅u⃗2u⃗2⋅u⃗2u⃗2−⋯−v⃗k⋅u⃗k−1u⃗k−1⋅u⃗k−1u⃗k−1\quad \vec{u}_k=\vec{v}_k-\dfrac{\vec{v}_k \cdot \vec{u}_1}{\vec{u}_1 \cdot \vec{u}_1}\vec{u}_1-\dfrac{\vec{v}_k \cdot \vec{u}_2}{\vec{u}_2 \cdot \vec{u}_2}\vec{u}_2 - \cdots -\dfrac{\vec{v}_k \cdot \vec{u}_{k-1}}{\vec{u}_{k-1} \cdot \vec{u}_{k-1}}\vec{u}_{k-1}

3. Singular Value Decomposition (SVD)

(1) Definition

For m×nm\times n matrix AA, it can be expressed in the form A=UΣVTA=U\Sigma V^T. Here V:n×nV: n\times n orthogonal matrix, Σ:m×n\quad \Sigma: m\times n matrix. In particular

Σ=[D000],D=[σ10⋯00σ2⋯0⋯⋯⋯⋯00⋯σr]\Sigma=\begin{bmatrix} D & 0 \\ 0 & 0 \end{bmatrix} , D=\begin{bmatrix} \sigma_1 & 0 & \cdots & 0 \\ 0 & \sigma_2 &\cdots & 0 \\ \cdots & \cdots & \cdots &\cdots \\ 0 & 0 & \cdots & \sigma_r\end{bmatrix}
SVD_SVD

(2) Derivation

① Find symmetric matrix ATAA^TA (can be orthogonally diagonalized)

② Find eigenvalues λ1,λ2,⋯ ,λn\lambda_1,\lambda_2,\cdots,\lambda_n of ATAA^TA

③ Find eigenvectors corresponding to eigenvalues λ1,λ2,⋯ ,λn\lambda_1,\lambda_2,\cdots,\lambda_n, then convert them to orthonormal eigenvectors v⃗1,v⃗2,⋯ ,v⃗n\vec{v}_1,\vec{v}_2,\cdots,\vec{v}_n

  • Eigenvectors from different eigenvalues are guaranteed to be orthogonal, but if there are multiple eigenvectors from one eigenvalue due to multiplicity, they are not guaranteed to be orthogonal to each other, so orthogonality must be achieved through the Gram-Schmidt orthogonalization process.

④ Find singular values σ1=λ1≥σ2=λ2≥⋯≥σn=λn≥0\quad \sigma_1=\sqrt{\lambda_1} \quad \ge \quad \sigma_2=\sqrt{\lambda_2} \quad \ge \quad \cdots \quad \ge \quad \sigma_n=\sqrt{\lambda_n} \quad \ge \quad 0 \quad Let σ1≥σ2≥⋯≥σr>0,σr+1=σr+2=⋯=σn=0\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_r > 0, \quad \sigma_{r+1}=\sigma_{r+2}=\cdots=\sigma_n=0.

⑤ Find u⃗i=1σiAv⃗i(i=1,2,⋯ ,r)\vec{u}_i=\dfrac{1}{\sigma_i}A\vec{v}_i \quad (i=1,2,\cdots,r)

⑥ From orthonormal set {u⃗1,u⃗2,⋯ ,u⃗r}⊂Rn\{\vec{u}_1,\vec{u}_2,\cdots,\vec{u}_r\} \subset{\mathbb{R}^n}, find an orthonormal basis for Rm\mathbb{R}^m

{u⃗1,u⃗2,⋯ ,u⃗r,u⃗r+1,⋯ ,u⃗m}\{\vec{u}_1, \vec{u}_2, \cdots, \vec{u}_r,\vec{u}_{r+1}, \cdots, \vec{u}_m\}
  • Can be found through Gram-Schmidt orthogonalization by finding standard basis vectors of Rn\mathbb{R}^n that are linearly independent from orthonormal set {u⃗1,u⃗2,⋯ ,u⃗r}\{\vec{u}_1,\vec{u}_2,\cdots,\vec{u}_r\}.

⑦ U=[u⃗1u⃗2⋯u⃗m],V=[v⃗1v⃗2⋯v⃗n]U=[\vec{u}_1 \quad \vec{u}_2 \quad \cdots \quad \vec{u}_m], \qquad V=[\vec{v}_1 \quad \vec{v}_2 \quad \cdots \quad \vec{v}_n]

(3) Theorems

For m×nm\times n matrix AA, let V,Σ,UV, \Sigma, U be the singular value decomposition matrices, and let σ1,σ2,⋯ ,σr\sigma_1, \sigma_2, \cdots, \sigma_r be all non-zero singular values of AA

V=[v⃗1v⃗2⋯v⃗r∣v⃗r+1v⃗r+2⋯v⃗n]V=\begin{bmatrix} \vec{v}_1 & \vec{v}_2 & \cdots & \vec{v}_r & | &\vec{v}_{r+1} & \vec{v}_{r+2} & \cdots & \vec{v}_n \end{bmatrix} U=[u⃗1u⃗2⋯u⃗r∣u⃗r+1u⃗r+2⋯u⃗m]U=\begin{bmatrix} \vec{u}_1 & \vec{u}_2 & \cdots & \vec{u}_r & | &\vec{u}_{r+1} & \vec{u}_{r+2} & \cdots & \vec{u}_m \end{bmatrix}

(i) rank(A)=r rank(A)=r

(ii) {u⃗1,u⃗2,⋯ ,u⃗r}\{\vec{u}_1,\vec{u}_2,\cdots,\vec{u}_r\} \quad orthonormal basis of Col(A)\text{Col}(A)

(iii) {ur+1⃗,ur+2⃗,⋯ ,u⃗m}\{\vec{u_{r+1}},\vec{u_{r+2}},\cdots,\vec{u}_m\} \quad orthonormal basis of Null(AT)\text{Null}(A^T)

(iv) {v⃗1,v⃗2,⋯ ,v⃗r}\{\vec{v}_1,\vec{v}_2,\cdots,\vec{v}_r\} \quad orthonormal basis of Row(A)\text{Row}(A)

(v) {vr+1⃗,vr+2⃗,⋯ ,v⃗n}\{\vec{v_{r+1}},\vec{v_{r+2}},\cdots,\vec{v}_n\} \quad orthonormal basis of Null(A)\text{Null}(A)

(4) Pseudo Inverse (Moore-Penrose Inverse)

For m×nm\times n matrix AA, let V,Σ,UV, \Sigma, U be the singular value decomposition matrices. That is, A=UΣVTA=U\Sigma V^T. Then A+=UΣ+VTA^+=U\Sigma^+ V^T is called the pseudo inverse of AA. Here Σ+\Sigma^+ is as follows:

Σ+=[D−1000]n×m,D−1=[σ1−10⋯00σ2−1⋯0⋯⋯⋯⋯00⋯σr−1]r×r\Sigma^+=\begin{bmatrix} D^{-1} & 0 \\ 0 & 0 \end{bmatrix}_{n\times m}, \qquad D^{-1}=\begin{bmatrix} \sigma_1^{-1} & 0 & \cdots & 0 \\ 0 & \sigma_2^{-1} &\cdots & 0 \\ \cdots & \cdots & \cdots &\cdots \\ 0 & 0 & \cdots & \sigma_r^{-1}\end{bmatrix}_{r\times r}

If AA is an invertible matrix, then A−1=A+A^{-1}=A^+.


4. Principal Component Analysis (PCA)

(1) Purpose

  • To project high-dimensional data into lower dimensions while minimizing information loss.
  • The greater the variance, the better it can explain the data.
  • Therefore, the key is finding the direction (principal component) with the greatest variance in the data.

(2) Method

Transform the coordinate axes representing existing input variables to other coordinate axes, then select only a few dimensions that best explain the data (with greatest variance) to reduce dimensions.

Example

Step 1. Two features X, Y exist

PCA_pca1

Step 2. Find the coordinate axis with the greatest variance and a new axis orthogonal to that axis → V1 (coordinate axis with greatest variance), V2

PCA_pca2

Step 3. Make V1, V2 into new coordinate axes PC1, PC2, and keep only coordinate axis PC1 that best explains the data.

PCA_pca3 Principal Component Analysis Guide & Example

(2) Detailed Steps Using Formulas

[1] Data Normalization (Mean Removal)

Let XX be data with nn observations and pp features: X∈Rn×pX \in \mathbb{R}^{n\times p} First, perform centering for each feature so that the mean of each feature becomes 0. For each observation i=1,2,⋯ ,ni=1,2,\cdots,n and feature j=1,2,⋯ ,pj=1,2,\cdots,p

① Calculate column-wise mean

μj=1n∑i=1nXij,for j=1,2,…,p\mu_j = \dfrac{1}{n} \sum_{i=1}^n X_{ij}, \quad \text{for } j = 1, 2, \dots, p

Expressed as a vector,

μ⃗=1nX⊤1n\vec{\mu} = \dfrac{1}{n} X^\top \mathbf{1}_n, 1n∈Rn×1\quad \mathbf{1}_n \in \mathbb{R}^{n\times 1} is a column vector with all elements 1.

Therefore μ⃗=[μ1 μ2 ⋮ μp]∈Rp×1\vec{\mu} = \begin{bmatrix} \mu_1 \\\ \mu_2 \\\ \vdots \\\ \mu_p \end{bmatrix} \in \mathbb{R}^{p\times 1} is a p-dimensional column vector.

② Remove mean

Xij~=Xij−μj,for i=1,…,n, j=1,…,p\tilde{X_{ij}} = X_{ij} - \mu_j, \quad \text{for } i = 1, \dots, n,\ j = 1, \dots, p

Expressed as a vector,

X~=X−1nμ⃗⊤,X~∈Rn×p\tilde{X} = X - \mathbf{1}_n \vec{\mu}^\top ,\quad \tilde{X} \in \mathbb{R}^{n\times p}

[2] Perform SVD

X~=UΣV⊤\tilde{X} = U \Sigma V^\top

At this time ① VV is an orthogonal matrix, so the column vectors of VV are orthonormal, and ② From each singular value (standard deviation) σ1=λ1≥σ2=λ2≥⋯≥σn=λn≥0\sigma_1=\sqrt{\lambda_1} \ge \sigma_2=\sqrt{\lambda_2} \ge \cdots \ge \sigma_n=\sqrt{\lambda_n} \ge 0, the orthonormal vectors are arranged in corresponding order in matrix V=[v⃗1v⃗2⋯v⃗n]V=[\vec{v}_1 \quad \vec{v}_2 \quad \cdots \quad \vec{v}_n]. \quad That is, the column vectors of VV are sorted in descending order by the square of singular values (=variance).

Covariance Matrix and SVD

  • For data centered with mean 0, the covariance matrix of matrix X~∈Rn×p\tilde{X} \in \mathbb{R}^{n\times p} is Cov(X~)=1nX~⊤X~Cov(\tilde{X}) = \frac{1}{n} \tilde{X}^\top \tilde{X}, and eigenvalue decomposition of this covariance matrix gives Cov(X~)=VΛV⊤Cov(\tilde{X}) = V \Lambda V^\top (Λ=diag(λ1,⋯ ,λp)\Lambda = diag(\lambda_1,\cdots,\lambda_p) : eigenvalues (variance size, descending order), V∈Rp×pV \in \mathbb{R}^{p\times p} : eigenvectors corresponding to each λ\lambda).

  • Now substituting SVD decomposition of X~\tilde{X}, X~=UΣV⊤\tilde{X} = U \Sigma V^\top, since U=[u⃗1u⃗2⋯u⃗n]U=[\vec{u}_1 \quad \vec{u}_2 \quad \cdots \quad \vec{u}_n] is an orthogonal matrix ({u⃗1,⋯ ,u⃗n}\{\vec{u}_1, \cdots,\vec{u}_n\} is an orthonormal set)

X~⊤X~=(UΣV⊤)⊤(UΣV⊤)=VΣ⊤U⊤UΣV⊤=VΣ2V⊤\tilde{X}^\top \tilde{X} = (U \Sigma V^\top)^\top (U \Sigma V^\top) = V \Sigma^\top U^\top U \Sigma V^\top = V \Sigma^2 V^\top

∴\qquad \therefore Eigenvalues of X~⊤X~\tilde{X}^\top \tilde{X}: Diagonal elements of Σ2\Sigma^2 (i.e., variance) \qquad \quad Eigenvectors of X~⊤X~\tilde{X}^\top \tilde{X}: Column vectors of VV

[3] Select Principal Components

V=[v⃗1v⃗2⋯v⃗n]∈Rp×pV=[\vec{v}_1 \quad \vec{v}_2 \quad \cdots \quad \vec{v}_n] \in \mathbb{R}^{p \times p} Select top kk principal components: W=[v⃗1v⃗2⋯v⃗k]∈Rp×kW = [\vec{v}_1 \quad \vec{v}_2 \quad \cdots \quad \vec{v}_k] \in \mathbb{R}^{p \times k}

[4] Dimensionality Reduction

Z=X~W∈Rn×kZ = \tilde{X} W \in \mathbb{R}^{n \times k} → This is the result of projecting original data XX onto the kk-dimensional principal component space.

[5] Reconstruction to Original Dimensions (Optional)

X^=ZW⊤+XˉwhereXˉ=1nμ⃗⊤∈Rn×p\hat{X} = Z W^\top + \bar{X} \qquad \text{where} \quad \bar{X} = \mathbf{1}_n \vec{\mu}^\top \in \mathbb{R}^{n\times p} (column mean vector of data, i.e., mean value before centering) → Reconstructed data X^∈Rn×p\hat{X} \in \mathbb{R}^{n \times p}

Note: Standardization in [1] Data Normalization (mean 0, variance 1) Not essential for PCA, but performed when the scale of each feature is very different: standardized X~=Xij−μjσj\qquad \qquad \qquad \qquad \text{standardized } \tilde{X} = \dfrac{X_{ij}-\mu_j}{\sigma_j} Vector expression: Xstd=(X−μ⃗)⊘σ⃗X^{std} = (X - \vec{\mu}) \oslash \vec{\sigma} μ⃗∈R1×p:\qquad \qquad \qquad \qquad \vec{\mu} \in \mathbb{R}^{1 \times p} : mean vector σ⃗∈R1×p:\qquad \qquad \qquad \qquad \vec{\sigma} \in \mathbb{R}^{1 \times p} : standard deviation vector ⊘:\qquad \qquad \qquad \qquad \oslash : broadcasting operation that divides column-wise (element-wise division)

  • When standardizing, now in [2] we perform eigendecomposition of the correlation matrix rather than the covariance matrix.
  • The principal component directions found are obtained in the same way, but they are simply the maximum variance directions on normalized axes.

(3) PCA as Linear Transformation

PCA projection: Z=X~WW=[v⃗1,…,v⃗k]∈Rp×k,Z∈Rn×kZ = \tilde{X} W \qquad W = [\vec{v}_1, \dots, \vec{v}_k] \in \mathbb{R}^{p\times k}, \quad Z \in \mathbb{R}^{n\times k}

⇒\Rightarrow Therefore, PCA is a linear transformation that passes through the origin and rotates and reduces the basis.

Let the transpose of the ii-th row vector (sample) of X~\tilde{X} be x~i\tilde{x}_i. (x~i⃗∈Rp\vec{\tilde{x}_i} \in \mathbb{R}^{p} is a pp-dimensional column vector) Also, let z⃗i\vec{z}_i be the transpose of the ii-th row vector (sample) of ZZ, For each sample x~i⃗\vec{\tilde{x}_i}, z⃗i=W⊤x~i⃗∈Rk\vec{z}_i = W^\top\vec{\tilde{x}_i} \in \mathbb{R}^{k} (kk-dimensional column vector), This means PCA is a transformation that sends x~i⃗\vec{\tilde{x}_i} to low-dimensional vector z⃗i\vec{z}_i by multiplying matrix W⊤W^\top.


5. Truncated SVD

Rewriting the original SVD:

SVD:

A=UΣVTA=U\Sigma V^T
  • A∈Rm×nA \in \mathbb{R}^{m\times n}
  • U∈Rn×nU \in \mathbb{R}^{n\times n}
  • Σ∈Rn×p\Sigma \in \mathbb{R}^{n\times p}
  • V∈Rp×pV \in \mathbb{R}^{p\times p}

Meanwhile, in PCA, we select only the top kk principal components from V=[v⃗1v⃗2⋯v⃗n]∈Rp×pV=[\vec{v}_1 \quad \vec{v}_2 \quad \cdots \quad \vec{v}_n] \in \mathbb{R}^{p \times p}. Correspondingly, we can select the top kk singular values (=principal components with large information content) from Σ\Sigma, and also select only the corresponding first kk column vectors from UU to rewrite SVD as follows. This is called Truncated SVD.

Truncated SVD:

A≈UkΣkVkTA\approx U_k\Sigma_k V_{k}^T
  • A∈Rm×nA \in \mathbb{R}^{m\times n}
  • Uk∈Rm×kU_k \in \mathbb{R}^{m\times k} : Matrix with only kk corresponding column vectors from the front
  • Σk∈Rk×k\Sigma_k \in \mathbb{R}^{k\times k} : Diagonal matrix with only top kk singular values
  • Vk∈Rn×kV_k \in \mathbb{R}^{n\times k} : Matrix with only kk corresponding column vectors from the front

Therefore, if you're going to do SVD for PCA, you can compute Truncated SVD from the start.

X~≈UkΣkVk⊤⇒Z=X~W=X~Vk(=UkΣk   Vk⊤Vk)=UkΣK\tilde{X} \approx U_k \Sigma_k V_{k}^\top \qquad \Rightarrow \qquad Z = \tilde{X} W = \tilde{X} V_k (= U_k \Sigma_k \,\,\, V_{k}^\top V_k) = U_k \Sigma_K

Source: Lecture Notes from undergraduate and graduate courses - Linear Algebra, Linear Regression, Macroeconometrics, Advanced Machine Learning