Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/notebooks/Chapter 16 - Gram-Schmidt Process and QR Decomposition.ipynb
Views: 449
The Gram-Schmidt Process
The Gram-Schmidt Process is an algorithm of producing an orthogonal or orthonormal basis.
An Example in
Let , where . They are not orthogonal, but we can construct an orthogonal basis for based on . We will visualize the process.
First we plot the .
If we choose , then the orthogonal component of projection of onto is .
Define , then , rearange for
According to definition above
The orthogonal component, is
Next step, we find , define
Again, the codes are superfluous, yet exceedingly intuitive.
Now we have orthogonal basis , and futher we can normalize them.The column of is a set of orthonormal basis.
We can also use SymPy built-in algorithm orthogonalize
or GramSchmidt
, for Gram-Schmidt process.
SymPy Functions for Gram-Schimidt Process
We need to prepare all the vectors in a form
where is a column vector.
The QR Decomposition
QR decomposition is commonly used for solving linear systems and is also very popular for least squares solutions. QR decomposition is based on the Gram-Schmidt process we just discussed.
Consider two matrices:
where is the orthonormalized version of . We define as :
Since is an orthonormal matrix, we have:
Try not to use decomposition in SymPy directly, here we convert fraction into float with sy.N()
and round it with round_expr
.
The Least-Squares Problem
We are not delving deeply into this topic at the moment, as we will revisit it multiple times. For those who have not studied linear regression or econometrics, it suffices to know that least-squares solutions involve finding a coordinate for the basis of , which forms a linear combination of .
is the orthogonal projection of onto , denoted as .
The distance between and is the shortest among all possible in the vector space, meaning that
The is orthogonal to the component of the orthogonal projection of , thus