手把手教你SVD分解

Intro

SVD分解是 singular value decomposition的缩写,也就是奇异值分解,它是spectral decomposition谱分解的推广(谱分解适用于方阵)。在机器学习中,这是一种非常有用的降维手段,另外它还可以构建主题词模型,可谓是功能丰富啊。本文通过一个简单的例子,来手把手演示SVD分解的数学步骤。

数学表示,分解矩阵 \(A = \Gamma\Lambda\Delta^T\)

其中A是nxp的,\(\Gamma\)是nxr的,\(\Delta\)是pxr的,而\(\Lambda = diag(\lambda^{1/2}, ... , \lambda^{1/2})\)

另外,\(\Gamma^T\Gamma = \Delta^T\Delta=I_r\),这表示他们俩都是关于列垂直。

实例

给定一个2X3的矩阵 A = \(\begin{bmatrix}1 & 1 & 0 \\ 0 & 1 &1\end{bmatrix}\),rank(A)=2

Step1

计算,\(AA^T = \begin{bmatrix}1 & 1 & 0 \\ 0 & 1 & 1\end{bmatrix}\begin{bmatrix}1&0 \\ 1&1 \\ 0&1\end{bmatrix} = \begin{bmatrix}2&1 \\ 1&2\end{bmatrix}\) 的特征值和特征向量

\(det(AA^T - \lambda I) = \begin{vmatrix}2-\lambda & 1 \\ 1 & 2-\lambda\end{vmatrix} \overset{set}{=} 0\)

得到,\(\lambda_1 = 1, \lambda_2 = 3\), \(v_1 = a\begin{pmatrix}1\\-1\end{pmatrix}, v_2 = b\begin{pmatrix}1\\1\end{pmatrix}\)

Step2

计算,\(A^TA = \begin{bmatrix}1&0 \\ 1&1 \\ 0&1\end{bmatrix}\begin{bmatrix}1&1&0 \\ 0 & 1 & 1\end{bmatrix} = \begin{bmatrix}1&1&0 \\ 1&2&1 \\ 0&1&1\end{bmatrix}\) 的特征值和特征向量

得到,\(\lambda_1 = 3, \lambda_2 = 1, \lambda_3 = 0\), \(v_1 = a\begin{pmatrix}1\\2\\1\end{pmatrix}, v_2 = b\begin{pmatrix}1\\0\\1\end{pmatrix}, v_3=c\begin{pmatrix}1\\-1\\1\end{pmatrix}\)

Step3

根据前面得到的非零特征及其对应的特征向量(取norm1),就可以分别得到\(\Gamma, \Lambda, \Delta\)

\(AA^T: \lambda_1 = 1, \lambda_2 = 3, v_1 = \begin{pmatrix}1/\sqrt{2} \\ -1/\sqrt{2}\end{pmatrix}, v_2 = \begin{pmatrix}1/\sqrt{2} \\ 1/\sqrt{2}\end{pmatrix}\)

因此,\(\Gamma = \begin{bmatrix}1/\sqrt{2} & 1/\sqrt{2} \\ -1/\sqrt{2} & 1/\sqrt{2} \end{bmatrix}\)

\(\Lambda = \begin{bmatrix} 1 & 0 \\ 0 & \sqrt{3}\end{bmatrix}\)

\(A^TA: \lambda_1 = 3, \lambda_2 = 1, v_1 = \begin{pmatrix}1/\sqrt{6} \\ 2/\sqrt{6} \\ 1/\sqrt{6}\end{pmatrix}, v_2 = \begin{pmatrix}1/\sqrt{2} \\ 0 \\ -1/\sqrt{2}\end{pmatrix}\)

因此,\(\Delta = \begin{bmatrix}1/\sqrt{6} & 1/\sqrt{2} \\ 2/\sqrt{6} & 0 \\ 1/\sqrt{6} & -1/\sqrt{2}\end{bmatrix}\)

Overall,\(A = \Gamma\Lambda\Delta^T = \begin{bmatrix}1/\sqrt{2} & 1/\sqrt{2} \\ -1/\sqrt{2} & 1/\sqrt{2} \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & \sqrt{3}\end{bmatrix} \begin{bmatrix}1/\sqrt{6} & 1/\sqrt{2} \\ 2/\sqrt{6} & 0 \\ 1/\sqrt{6} & -1/\sqrt{2}\end{bmatrix}^T\)

posted @ 2020-09-16 00:39  MrDoghead  阅读(4231)  评论(0编辑  收藏  举报