Repository navigation
Singular Value Decomposition
We have a variety of recent ideas that are limited in scope (to square and/or symmetric matrices):
- Eigenstuff for square matrices.
- Diagonalization for square matrices.
- Orthogonal diagonalization for symmetric matrices.
We can do quite a lot with these things, but the matrices we encounter in data are typically not square (let alone symmetric). That makes diagonalization limited in scope. We will see today the antidote: an analogue of eigenvalues and diagonalization that applies to any matrix!
In Lab 6, we learned about the Spectral Theorem for Symmetrix Matrices:
If
-
$\large A$ has only real eigenvalues. - The eigenvectors for different eigenvalues are orthogonal.
-
$\large A$ is orthogonally diagonalizable, meaning$\large A=PDP^T$ for an orthogonal matrix$\large P$ . Remember that for an orthogonal matrix$\large P$ , we have$\large PP^T=I$ and that the columns of an orthogonal matrix form an orthonormal set.
The orthogonal diagonalization of
With this factorization, we can break up A in a way called a spectral decomposition:
Note
Since
Let's see an example of this. The video shows the spectral decomposition of the matrix:
This decomposition breaks up
Note
This decomposition is almost useful. If we could just do this for all matrices instead of only square, symmetric matrices, we'd make data science very happy.
We have a problem: our decomposition (and eigenvalues/vectors in general) is not possible for general matrices. Data in particular rarely comes in square, symmetric matrices. What do we do? There is a matrix factorization called the Singular Value Decomposition (or SVD) which comes to the rescue.
Let
But look at
The columns of
Fact: The eigenvalues
$\large \lambda_i$ are all nonnegative.
We can prove this, and it's clever and cool, so let's prove it in the video:
Definition: The singular values
$\large \sigma_i$ of$\large A$ are the square roots of the eigenvalues of$\large A^TA$ :
Let's see an example. Find the singular values of
The solution is in the video:
Note
We're just going to emphasize again that, unlike eigenvalues for square matrices, any matrix of any size has singular values!
With this background, we can state today's main result:
Theorem: If
$\large A$ has$\large r$ singular values, then$\large \text{rank}(A)=r$ , and$\large A = U\Sigma V^T$ , where$\large U$ is an$\large m\times m$ orthogonal matrix,$\large \Sigma$ is a matrix that is mostly diagonal (padded with some rows and columns of zeros), and$\large V$ is an$\large n\times n$ orthogonal matrix. This factorization of$\large A$ is called the Singular Value Decomposition (SVD).
The matrix
This is a diagonal matrix in the upper left (with the singular values in the diagonal) with rows and columns of zeros padded on the bottom and right. There are
Note
Definition: The columns of
$\large U$ are called the left singular vectors of$\large A$ . The columns of$\large V$ are called the right singular vectors of$\large A$ . Since$\large U$ and$\large V$ are orthogonal matrices, the left/right singular vectors form orthonormal sets.
Important
The singular values and singular vectors of
We will not outline the steps for computing the SVD by hand. They get messy, they are hard to remember, and they often involve Gram-Schmidt orthogonalization. Furthermore, we can only do it by hand for small matrices, but the real uses of the SVD are almost always for large matrices.
No one should be computing these by hand! Instead, we will use Python to compute SVDs. But we will show a completed example here. For the matrix we were working with earlier, the SVD is:
- Take a quick look at
$\large U$ and$\large V$ in the example (remember, what we see above is not$\large V$ , it's$\large V^T$ ). Verify that the columns are orthogonal to each other. Verify that they are unit vectors. - Take a quick look at
$\large \Sigma$ . We see the singular values we computed earlier. We see the extra column of 0's that is necessary to make$\large \Sigma$ the same size as$\large A$ . - Note that
$\large \text{rank}(A)=2$ since$\large A$ has two nonzero singular values.
Note
We learned to find the rank of a matrix at the very beginning of class, using Gaussian elimination. Turns out, when we use the built-in rank command in Python, it uses the SVD rather than Gaussian elimination!
Recall from the beginning of this lesson that we can break a symmetric matrix down into its spectral decomposition. We now have something similar for rectangular and other non-symmetric matrices. The singular value decomposition of
Here we break
Find the singular value decomposition for:
The solution is in the video:
Again, today we are just introducing this big new thing. Tomorrow, we will take a look at why this is so useful when dealing with data.
I can:
- Find the spectral decomposition of a symmetric matrix.
- Find the singular values of any matrix by finding the eigenvalues of
$\large A^TA$ . - Find the rank of a matrix using the singular values or the SVD.
- Find the singular values of a matrix from the SVD.
- From the SVD of
$\large A$ , write$\large A$ as a sum of rank 1 matrices.