Definition
(Taken from Prof. Sun, Peng’s slides)


The geometric (orthonormal) properties of the columns of the Q matrix is useful, as we will see in the following example of least square problems.
Example: Least Square Problems
(Reference: S. Boyd and L. Vandenberghe, Introduction to Applied Linear Algebra – Vectors, Matrices, and Least Squares, Chapter 10 & 12. ->eBook<-.)
Problem definition
Suppose that we have a matrix A with the shape of , so the system of linear equations
(b is a
-vector) is over-determined. In other words, there are more equations (
) than variables (
).
Over-determined systems are very common in data-driven methods. The number of the entries in the dataset (columns, m) are usually a lot larger than the dimensions of the dataset (rows, n).
For most over-determined systems, there is no -vector x such that
. However, as a compromise, we can have an approximate solution
that minimize the residual
. In the linear least square problem, we minimize the squared norm of the residual
, that is:
In other words, any vector that satisfies
for all x is an solution for the least square problem.
Algebraic Interpretation

Geometric Interpretation
Consider the case for =3,
=2. Let A (Shape:
) be as follows:
Here, we can see that the column space of A lives in , while vector b lives in
. Therefore, it is not possible for us to find an exact solution for most of the cases. As for the approximate solution
, it gives the linear combination of the column vectors of A that minimize the norm of the residual vector Ax – b.

(Visualization: DE: Ax – b)
It is worth noting that the vector Ax – b is orthogonal to the column space of A. Below is the algebraic justification for this:

Solving Least Square Problems
Here, we need to make the assumption that the column vectors of matrix A are linearly independent.


The result can be written in the pseudo-inverse notation
.
Simplifying computation with QR factorization
Given that the column vectors of matrix A are linearly independent, we can implement QR factorization on A, which gives us a simpler way to calculate the pseudo-inverse. Moreover, empirical results suggests that using QR decomposition usually gives us condition numbers that are much smaller compared to directly calculating the pseudo-inverse.


For non-singular matrix A, we have
*Condition numbers

Smaller condition numbers, better numerical stability!
Gram-Schmidt Algorithm
Now we look at the Gram-Schmidt Algorithm that we use to actually implement the QR factorization.
Finding the Q matrix in essentially finding orthonormal basis of column space of A. The algorithm below utilizes this orthonormal property well. For , we just take the unit vector
that points into the same direction with
. For the following
, we compute them by subtracting
by it’s projections onto all the orthonormal basis we’ve already computed. In this case, we make sure that the residue is orthogonal to all the existing basis (i.e. the residue cannot be expressed by a linear combination of the existing basis). After this, we simply normalize
to get the orthogonal basis
.
For the R matrix, we note that for orthonormal basis and
The results can be easily validated by doing the matrix multiplication!


(A simple visualization)
Some thoughts
Borrowing the idea from my professor, the Gram-Schmidt algorithm can be seen as a form of incremental learning: instead of directly computing the whole Q & R matrices at the same time, we take the incremental way of subtracting the projections.
This actually reminds me of two machine learning algorithms that uses the same idea.
- The residual connections in ResNet
- Instead of learning the direct mapping H(x), residual blocks learn the residual F(x)=H(x) – x. This reformulation makes it easier to optimize identity mappings – the network can simply drive F(x) to zero rather than learning an identity function from scratch. (Generated by DeepSeek)
- The gradual denoising process in Diffusion Models
发表回复