Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 42

Pseudoinverse for Least Squares

Recommended resources

Hello! Welcome back to our final lesson in the "Applications in Data Analysis" module.

In our last session, we explored two methods for finding the least squares solution to an overdetermined system . We derived the normal equations (), a direct but potentially numerically unstable method. We then looked at the more robust QR decomposition approach, which transforms the problem into solving a simple triangular system.

Today, we'll uncover a third, and perhaps the most elegant, method that leverages the Singular Value Decomposition. Our goal is to find the least squares solution using the pseudoinverse derived from SVD. This powerful concept not only provides a solution to the least squares problem but also generalizes the idea of a matrix inverse to any matrix, regardless of its shape or rank. This will be a fitting capstone to our work on SVD.

1. What is a Pseudoinverse?

We know that to solve a simple equation like , we multiply by the inverse: . Similarly, for a square and invertible matrix , the solution to is .

But what happens when is not square or not invertible, as in our typical least squares problems? The standard inverse doesn't exist. This is where the Moore-Penrose pseudoinverse (often just called the pseudoinverse), denoted or , comes in. It's a generalization of the inverse that exists for any matrix.

The pseudoinverse always finds the "best possible" solution. What "best" means depends on the system:

  • For an overdetermined system (more equations than unknowns, like in data fitting), it gives the least squares solution that minimizes .
  • For an underdetermined system (fewer equations than unknowns), there are infinite solutions. The pseudoinverse gives the unique solution that has the minimum Euclidean norm .

The following video provides an excellent introduction to why we need to generalize the concept of an inverse to handle the non-square matrices that arise in data analysis.

Linear Systems of Equations, Least Squares Regression, Pseudoinverse

Watch this segment from 'Linear Systems of Equations, Least Squares Regression, Pseudoinverse' by Steve Brunton to understand the challenges posed by non-square matrices in linear systems.

Watch from 1:35 to 5:48. The first part (until 2:22) motivates why SVD is key. The second part (until 5:48) clearly explains the underdetermined and overdetermined cases, which is the context for using a pseudoinverse.

The key idea is that the pseudoinverse provides a unified way to handle all these cases. If a matrix is invertible, its pseudoinverse is simply its regular inverse: .


2. Constructing the Pseudoinverse with SVD

The Singular Value Decomposition provides a direct and numerically stable way to compute the pseudoinverse of any matrix.

Let's start with the SVD of an matrix :

If were square and invertible, we know its inverse would be . The formula for the pseudoinverse looks remarkably similar:

The only new element is , the pseudoinverse of the singular value matrix .

So, how do we find ? The process is simple:

  1. Take the transpose of . If is , then is . This ensures the dimensions in the final multiplication for are correct.
  2. On the diagonal of this transposed matrix, take the reciprocal of all the non-zero singular values. Leave any zeros as they are.

For example, if for a matrix , the matrix is:

Then is found by transposing and taking reciprocals of non-zero elements:

This procedure is the heart of computing the pseudoinverse. The fact that we only invert non-zero singular values is what makes the method so robust. In practice, this means we can set a small threshold and treat any singular values below it as zero, effectively filtering out numerical noise—a crucial feature for any real-world computation.

The following article gives a very clear, step-by-step guide to this construction.

Least Squares with the Moore-Penrose Inverse

The article 'Least Squares with the Moore-Penrose Inverse' provides an excellent explanation of how to construct the pseudoinverse from SVD.

Read the section titled 'Constructing MP-Inverses with the SVD'. It gives a clear 3-step procedure and works through a concrete example with a singular matrix. Pay close attention to how \Sigma^+ is formed.

Test your understanding!

Suppose a matrix has an SVD where the matrix of singular values is:

What is ?

Show answer

First, we transpose to get a matrix:

Next, we take the reciprocal of the non-zero diagonal entries:


3. Finding the Least Squares Solution

Once we have the pseudoinverse , finding the least squares solution vector is astonishingly simple. We just multiply it by :

This single line replaces the two-step processes of the normal equations and QR decomposition.

Singular Value Decomposition and the Pseudoinverse in Linear Systems
This image connects the abstract concepts of SVD and the pseudoinverse to the practical problem of linear regression. The equation for the solution \(\mathbf{x}\) is exactly what we are discussing.

The Geometric Intuition: Why It Works

This is elegant, but why does it give the least squares solution? The answer lies in the geometry of projection, which we've revisited several times. Remember, the least squares solution is the vector such that is the orthogonal projection of onto the column space of .

Let's see what happens when we compute using our new formula for :

Since is an orthogonal matrix, . The expression simplifies to:

Let's look at the product . Using our example from before, where was :

This resulting matrix is a special kind of identity matrix. It has 1s corresponding to the non-zero singular values and 0s elsewhere. If we let be the rank of (the number of non-zero singular values), then multiplying by is equivalent to multiplying by , where is the matrix containing the first columns of .

And what is ? It's the projection matrix onto the column space of A! (Since the first columns of form an orthonormal basis for the column space of A).

So, the equation tells us that our solution is precisely the vector that makes equal to the projection of onto the column space of . This is the definition of the least squares solution.

The following video walks through this exact derivation, providing a clear explanation of how the term acts as a projection.

Least Squares Regression and the SVD

To solidify the geometric intuition, watch this explanation from 'Least Squares Regression and the SVD' by Steve Brunton.

Watch from 1:05 to 5:30. The video clearly shows how plugging the pseudoinverse solution back into A\mathbf{x} results in the term UU^T\mathbf{b} and explains why this represents the projection of \mathbf{b} onto the column space of A.

This SVD-based method is the preferred approach in many modern numerical libraries because it's not only general but also the most numerically stable and robust of the methods we've seen.


Conclusion

In this lesson, we've brought together several key ideas from the course—SVD, orthogonality, and projections—to develop a powerful and elegant method for solving least squares problems.

Key Takeaways:

  • The Moore-Penrose pseudoinverse generalizes the concept of a matrix inverse to any matrix.
  • It provides the least squares solution for overdetermined systems and the minimum norm solution for underdetermined systems.
  • The pseudoinverse is computed robustly from the SVD via the formula , where is formed by transposing and inverting its non-zero diagonal entries.
  • The solution works because it finds the vector that causes to be the orthogonal projection of onto the column space of .
  • Compared to the normal equations, this method is far more numerically stable and is preferred in practice.

Preview of the Next Lesson:
We have now completed our module on applications in data analysis and seen how central linear algebra is to machine learning. Our next module, "Tensor Products for Composite Systems," will pivot towards your goal of understanding quantum mechanics. We will learn about a new way to combine vector spaces called the tensor product, which is fundamental for describing systems composed of multiple parts, like the multi-qubit systems in a quantum computer.