#singular value decomposition#principal component analysis#orthogonal matrix#gram schmidt#pseudo inverse#truncated svd#covariance matrix
1. Eigenvalues and Eigenvectors
(1) Definition
For an n×n matrix A, λ satisfying Av=λv is called an eigenvalue, and v=0 is called an eigenvector.
(2) Derivation
1. Find eigenvalue λ satisfying Det(A−λI)=0.
2. Substitute the obtained eigenvalue into (A−λI)v=0 to find eigenvector v.
3. For eigenvalue λ and eigenvector v of n×n matrix A, Eλ=Span(v) is called the eigenspace.
(3) Theorems
1. The eigenvalues of a triangular matrix are its diagonal elements.
2. Let the distinct eigenvalues of an n×n matrix be λ1,λ2,⋯,λk, and let the eigenvectors corresponding to each eigenvalue be v1,v2,⋯,vk. Then {v1,v2,⋯,vk} is linearly independent.
2. Gram-Schmidt Orthogonalization
1) Orthogonality of Two Vectors
(1) Definition
For elements u,v in an inner product space V, u and v are orthogonal means their inner product is 0.
That is, u⊥v⇔<u,v>=0.
2) Norm of a Vector
(1) Definition
For element u in an inner product space V, the norm of vector u is defined as ∥u∥=<u,u>.
(2) Theorems
1.∥u+v∥2=∥u∥2+∥v∥2+2<u,v>
2.∥u+v∥2+∥u−v∥2=2∥u∥2+2∥v∥2
3.<u,v>=41∥u+v∥2−41∥u−v∥2
4. A necessary and sufficient condition for u,v to be orthogonal is ∥u+v∥2=∥u∥2+∥v∥2.
5.∥<u,v>∥≤∥u∥∥v∥ (equality holds when u and v are parallel)
6.∥u+v∥≤∥u∥+∥v∥
The dot product u⋅v=uTv defined in Rn is also an inner product.
Therefore, orthogonality can be discussed for the dot product defined in Rn.
The following content also holds for general inner product spaces, but is described limited to the dot product defined in Rn.
3) Orthogonal Set
(1) Definition
For v1,v2,⋯,vk∈Rn with respect to the dot product defined in Rn,
{v1,v2,⋯,vk} being an orthogonal set means vi⋅vj=0,i=j.
(2) Theorems
1. For any vector u∈V in the subspace V of Rn generated by orthogonal set B={v1,v2,⋯,vk} (i.e., V=Span(B)⊆Rn),
u=v1⋅v1u⋅v1v1+v2⋅v2u⋅v2v2+⋯+vk⋅vku⋅vkvk can be represented.
2. If orthogonal set {v1,v2,⋯,vk} does not contain the zero vector, then {v1,v2,⋯,vk} is linearly independent.
4) Orthogonal Basis
(1) Definition
For subspace V of Rn, if B={v1,v2,⋯,vk} is both ①a basis of V and ②an orthogonal set, then B is an orthogonal basis of V.
5) Orthonormal Set
(1) Definition
{v1,v2,⋯,vk} being an orthonormal set means
① <vi,vj>=0,i=j
② ∥vi∥=1,∀i
Note: The standard basis of Rn is an orthonormal set.
6) Orthonormal Basis
(1) Definition
For subspace V of Rn, if B={v1,v2,⋯,vk} is both ①a basis of V and ②an orthonormal set, then B is an orthogonal basis of W.
(2) Theorems
1. For any vector u∈V in the subspace V of Rn generated by orthonormal set B={v1,v2,⋯,vk},
u=(u⋅v1)v1+(u⋅v2)v2+⋯+(u⋅vk)vk can be represented.
2. If the column vectors of m×n(m≥n) matrix A are orthonormal, then ATA=In.
7) Orthogonal Matrix
(1) Definition
A being an orthogonal matrix means ① A:n×n matrix, ② The column vectors of A form an orthonormal set.
(2) Theorems
1. A necessary and sufficient condition for square matrix A to be an orthogonal matrix is ATA=I, i.e., AT=A−1.
2. From AT=A−1, we also have AAT=I, which means that if square matrix A is an orthogonal matrix, the set of row vectors of A is also an orthonormal set.
8) Orthogonal Projection
(1) Derivation
[1] Orthogonal Projection in R2
For linearly independent u,v∈R2 (i.e., u,v form a basis of R2)
① upr=v⋅vu⋅vv: Orthogonal projection of u onto v (vector projection)
② uc=u−upr : Vector component of u orthogonal to v
(i) upr+uc=u(ii) upr∥v (iii) uc⊥v
[2] Orthogonal Projection in R3
For linearly independent u,v1,v2∈R3, orthogonal vectors v1,v2
① u1=v1⋅v1u⋅v1v1: Orthogonal projection of u onto v1
② u2=v2⋅v2u⋅v2v2: Orthogonal projection of u onto v2
③ upr=u1+u2=v1⋅v1u⋅v1v1+v2⋅v2u⋅v2v2 : Orthogonal projection of u onto Span(v1,v2)
④ uc=u−upr=u−v1⋅v1u⋅v1v1−v2⋅v2u⋅v2v2 : Vector component of u orthogonal to Span(v1,v2)
[3] Orthogonal Projection in Rn
Given an orthogonal basis B={v1,v2,⋯,vk} for subspace V of Rn, for any vector u in V
① upr=v1⋅v1u⋅v1v1+v2⋅v2u⋅v2v2+⋯+vk⋅vku⋅vkvk : Orthogonal projection of u onto V
② uc=u−upr=u−v1⋅v1u⋅v1v1−v2⋅v2u⋅v2v2−⋯−vk⋅vku⋅vkvk : Vector component of u orthogonal to V
(2) Theorem: Gram-Schmidt Orthogonalization Process
For subspace V of Rn, when B={v1,v2,⋯,vk} is a basis of V, an orthogonal basis C={u1,u2,⋯,uk} and
orthonormal basis D={w1,w2,⋯,wk} also exist. Here, C and D can be obtained as follows:
① Find symmetric matrix ATA (can be orthogonally diagonalized)
② Find eigenvalues λ1,λ2,⋯,λn of ATA
③ Find eigenvectors corresponding to eigenvalues λ1,λ2,⋯,λn, then convert them to orthonormal eigenvectors v1,v2,⋯,vn
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 Let σ1≥σ2≥⋯≥σr>0,σr+1=σr+2=⋯=σn=0.
⑤ Find ui=σi1Avi(i=1,2,⋯,r)
⑥ From orthonormal set {u1,u2,⋯,ur}⊂Rn, find an orthonormal basis for Rm
{u1,u2,⋯,ur,ur+1,⋯,um}
Can be found through Gram-Schmidt orthogonalization by finding standard basis vectors of Rn that are linearly independent from orthonormal set {u1,u2,⋯,ur}.
⑦ U=[u1u2⋯um],V=[v1v2⋯vn]
(3) Theorems
For m×n matrix A, let V,Σ,U be the singular value decomposition matrices, and let σ1,σ2,⋯,σr be all non-zero singular values of A
(iii) {ur+1,ur+2,⋯,um} orthonormal basis of Null(AT)
(iv) {v1,v2,⋯,vr} orthonormal basis of Row(A)
(v) {vr+1,vr+2,⋯,vn} orthonormal basis of Null(A)
(4) Pseudo Inverse (Moore-Penrose Inverse)
For m×n matrix A, let V,Σ,U be the singular value decomposition matrices. That is, A=UΣVT.
Then A+=UΣ+VT is called the pseudo inverse of A. Here Σ+ is as follows:
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
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
Step 3. Make V1, V2 into new coordinate axes PC1, PC2, and keep only coordinate axis PC1 that best explains the data.
Let X be data with n observations and p features: X∈Rn×p
First, perform centering for each feature so that the mean of each feature becomes 0.
For each observation i=1,2,⋯,n and feature j=1,2,⋯,p
① Calculate column-wise mean
μj=n1∑i=1nXij,for j=1,2,…,p
Expressed as a vector,
μ=n1X⊤1n, 1n∈Rn×1 is a column vector with all elements 1.
Therefore μ=μ1μ2⋮μp∈Rp×1 is a p-dimensional column vector.
② Remove mean
Xij~=Xij−μj,for i=1,…,n,j=1,…,p
Expressed as a vector,
X~=X−1nμ⊤,X~∈Rn×p
[2] Perform SVD
X~=UΣV⊤
At this time
① V is an orthogonal matrix, so the column vectors of V are orthonormal, and
② From each singular value (standard deviation)
σ1=λ1≥σ2=λ2≥⋯≥σn=λn≥0, the orthonormal vectors are arranged in corresponding order in matrix V=[v1v2⋯vn].
That is, the column vectors of V 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 is
Cov(X~)=n1X~⊤X~, and eigenvalue decomposition of this covariance matrix gives
Cov(X~)=VΛV⊤ (Λ=diag(λ1,⋯,λp) : eigenvalues (variance size, descending order), V∈Rp×p : eigenvectors corresponding to each λ).
Now substituting SVD decomposition of X~, X~=UΣV⊤, since U=[u1u2⋯un] is an orthogonal matrix ({u1,⋯,un} is an orthonormal set)
X~⊤X~=(UΣV⊤)⊤(UΣV⊤)=VΣ⊤U⊤UΣV⊤=VΣ2V⊤
∴ Eigenvalues of X~⊤X~: Diagonal elements of Σ2 (i.e., variance)
Eigenvectors of X~⊤X~: Column vectors of V
[3] Select Principal Components
V=[v1v2⋯vn]∈Rp×p
Select top k principal components:
W=[v1v2⋯vk]∈Rp×k
[4] Dimensionality Reduction
Z=X~W∈Rn×k
→ This is the result of projecting original data X onto the k-dimensional principal component space.
[5] Reconstruction to Original Dimensions (Optional)
X^=ZW⊤+XˉwhereXˉ=1nμ⊤∈Rn×p (column mean vector of data, i.e., mean value before centering)
→ Reconstructed data X^∈Rn×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~=σjXij−μj
Vector expression: Xstd=(X−μ)⊘σμ∈R1×p: mean vector
σ∈R1×p: standard deviation vector
⊘: 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=[v1,…,vk]∈Rp×k,Z∈Rn×k
⇒Therefore, PCA is a linear transformation that passes through the origin and rotates and reduces the basis.
Let the transpose of the i-th row vector (sample) of X~ be x~i. (x~i∈Rp is a p-dimensional column vector)
Also, let zi be the transpose of the i-th row vector (sample) of Z,
For each sample x~i, zi=W⊤x~i∈Rk (k-dimensional column vector),
This means PCA is a transformation that sends x~i to low-dimensional vector zi by multiplying matrix W⊤.
5. Truncated SVD
Rewriting the original SVD:
SVD:
A=UΣVT
A∈Rm×n
U∈Rn×n
Σ∈Rn×p
V∈Rp×p
Meanwhile, in PCA, we select only the top k principal components from V=[v1v2⋯vn]∈Rp×p. Correspondingly, we can select the top k singular values (=principal components with large information content) from Σ, and also select only the corresponding first k column vectors from U to rewrite SVD as follows. This is called Truncated SVD.
Truncated SVD:
A≈UkΣkVkT
A∈Rm×n
Uk∈Rm×k : Matrix with only k corresponding column vectors from the front
Σk∈Rk×k : Diagonal matrix with only top k singular values
Vk∈Rn×k : Matrix with only k 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ΣkVk⊤Vk)=UkΣK
Source: Lecture Notes from undergraduate and graduate courses - Linear Algebra, Linear Regression, Macroeconometrics, Advanced Machine Learning