Hello! Welcome to your next lesson in our linear algebra course.
In our last lesson, we saw how the Singular Value Decomposition (SVD) gives us a profound insight into a matrix's structure by revealing its rank, kernel (null space), and image (column space). We learned that a matrix fails to be invertible if it's non-square or if its rank is less than its number of columns (i.e., it has zero singular values). This means we can't use the standard matrix inverse to solve the system .
This raises a critical question: what do we do in these cases? In real-world applications, especially in data science, we constantly face systems that are "unsolvable" in the classical sense. Today's lesson provides the answer.
Our goal is to compute the pseudoinverse of a non-square or singular matrix using SVD. The pseudoinverse, often denoted , is a powerful generalization of the matrix inverse. It allows us to find the "best possible" solution to any system of linear equations, even when a unique, exact solution doesn't exist.
1. When the Inverse Fails: The Need for an Alternative
Before we define the pseudoinverse, let's build our intuition about why we need it. Most systems of equations you'll encounter in machine learning are not simple, square, invertible systems. They usually fall into one of two categories.
The following video provides an excellent overview of these cases and motivates the need for a generalized inverse.
Linear Systems of Equations, Least Squares Regression, Pseudoinverse
This video from Steve Brunton introduces the challenges of solving A\mathbf{x} = \mathbf{b} when A is not a square, invertible matrix. It sets the stage for why the pseudoinverse is such a crucial tool.
Please watch the first two segments of the video, from the beginning until 6:00. Focus on understanding the two main scenarios for non-square matrices and why they don't have a simple, unique solution.
To summarize the key ideas from the video:
- Overdetermined Systems (Tall, skinny matrix, ): We have more equations (data points) than unknowns (features). Think of trying to fit a single straight line perfectly through 100 scattered points. In general, there is no exact solution because the vector is unlikely to lie in the column space of .
- Underdetermined Systems (Short, fat matrix, ): We have fewer equations than unknowns. Think of having two variables but only one equation, like . There are infinitely many solutions.
In both scenarios, the standard inverse is undefined. We need a new tool that can give us a meaningful, "best" answer in both cases. This tool is the Moore-Penrose pseudoinverse.
2. Constructing the Pseudoinverse from SVD
The beauty of the SVD is that it provides a direct way to construct the pseudoinverse. The logic is wonderfully straightforward.
If we have and want to "invert" it to solve for in , our first instinct might be to invert each component:
Since and are unitary matrices, their inverses are simply their transposes ( and ). So, the expression becomes:
This looks promising! The only problem is . The matrix is generally rectangular and contains zeros on its diagonal, making it non-invertible in the standard sense.
The solution is to define a pseudoinverse of , denoted . Here is how you construct it:
- Start with the matrix .
- Create a new matrix, , filled with zeros.
- For every non-zero singular value at position in , place its reciprocal at position in .
For example, if we have a matrix of rank 2, its matrix and its pseudoinverse would be:
Notice that has the shape of .
With this final piece, we can formally define the pseudoinverse of .
Definition: The Pseudoinverse
For a matrix with SVD , its pseudoinverse is defined as:
The "best" solution to the system is then given by:
We use (read "x-hat") to signify that this is an estimated or approximate solution, not necessarily an exact one.
The following video walks through this derivation and shows how to calculate the components in practice.
The Moore-Penrose Pseudoinverse — Topic 37 of Machine Learning Foundations
In this video, Jon Krohn provides a clear, hands-on explanation of how the pseudoinverse is computed from SVD components. Pay close attention to how he constructs the pseudoinverse of the diagonal matrix of singular values.
Please watch the segment from 3:15 to 10:42. He uses 'D' where we use '\Sigma', but the concept is identical. Focus on the steps to create 'D+' (our '\Sigma^\dagger') and how the final pseudoinverse is assembled from V, D+, and U transpose.
For a supplementary text-based derivation, the following article is also very helpful.
Geometric Meaning of Pseudo Inverse
This article, 'Geometric Meaning of Pseudo Inverse', provides a clear mathematical derivation of the pseudoinverse formula using SVD.
Please read the section titled 'Representation of Pseudo-Inverse using SVD'. This will reinforce the formula and show you the derivation in mathematical steps, which may complement the video's explanation.
Test your understanding!
You are given a matrix with rank 2. Its SVD components include:
- What are the dimensions of ?
- What is the matrix ?
- Write the full formula for using the SVD components.
Show answer
-
Dimensions: Since is , must be .
-
Matrix : We take the reciprocals of the non-zero singular values (10 and 5) and place them in a matrix.
-
Formula for : Using the definition, we have:
3. The Optimal Nature of the Pseudoinverse Solution
We've repeatedly called the "best" solution. But what does "best" actually mean? The answer depends on which of the two problem cases we are in. The properties of the pseudoinverse solution are precisely what make it so useful in machine learning and optimization.
Let's return to the video by Steve Brunton to see what makes this solution optimal.
Linear Systems of Equations, Least Squares Regression, Pseudoinverse
This final segment of the video explains the remarkable properties of the solution obtained using the pseudoinverse.
Please watch from 8:52 to the end (11:54). The video explains what the pseudoinverse solution represents for both underdetermined and overdetermined systems.
Here is a summary of these two crucial properties:
-
For overdetermined systems (more equations than unknowns, usually no solution), the pseudoinverse provides the least squares solution. This means that is the vector that minimizes the error between the desired output and the actual output . Specifically, it minimizes the Euclidean norm of the error vector: . This is the foundation of linear regression.
Geometrically, is the orthogonal projection of the vector onto the column space of . It's the closest possible vector to that can actually be produced by the transformation .

This image from theangeloyeo.github.ioarticle illustrates the concept. When is outside the column space of A (Col(A)), no exact solution exists. The pseudoinverse finds the solution that produces the projection of onto Col(A), which is the closest vector in the column space to . -
For underdetermined systems (fewer equations than unknowns, infinite solutions), the pseudoinverse provides the minimum norm solution. Of the infinitely many vectors that exactly solve , the vector is the one with the smallest length (smallest Euclidean norm, ). In many physical or computational systems, this corresponds to the most "efficient" or "simplest" solution.
Conclusion
Today, we've added a powerful and practical tool to our linear algebra toolkit. By leveraging the SVD, we can now find a meaningful solution to any system of linear equations , regardless of the shape or rank of .
Key Takeaways:
- The pseudoinverse () generalizes the matrix inverse to all matrices, including non-square and singular ones.
- It is computed directly from the SVD components via the formula .
- The matrix is constructed by taking the transpose of and replacing the non-zero singular values with their reciprocals .
- The solution is "optimal" in two distinct ways:
- It's the least squares solution for overdetermined systems (minimizing error).
- It's the minimum norm solution for underdetermined systems (shortest solution vector).
Preview of the Next Lesson:
The concept of a "least squares solution" is not just a mathematical curiosity; it's the engine behind one of the most fundamental algorithms in data science: linear regression. In our next lesson, we will formally define the least squares problem and see how the pseudoinverse provides an elegant and direct method for finding the "best-fit" line through a set of data points.