- Introduction
- Generalized minimal residual method
- Implementation
- Installation Guide
- Execution Guide
- References
In mathematics, the generalized minimal residual method (GMRES) is an iterative method for the numerical solution of an indefinite non-symmetric system of linear equations.
The method approximates the solution by the vector in a Krylov subspace with minimal residual. The Arnoldi iteration is used to find this vector.
In linear algebra, the order-r
Krylov subspace generated by an n-by-n matrix A and a vector b of dimension n
is the linear subspace spanned by the images of b under the first r powers of A (starting from
Modern iterative methods such as Arnoldi iteration can be used for finding one (or a few) eigenvalues of large sparse matrices or solving large systems of linear equations. They try to avoid matrix-matrix operations, but rather multiply vectors by the matrix and work with the resulting vectors. Starting with a vector
In numerical linear algebra, the Arnoldi iteration is an eigenvalue algorithm and an important example of an iterative method. Arnoldi finds an approximation to the eigenvalues and eigenvectors of general (possibly non-Hermitian) matrices by constructing an orthonormal basis of the Krylov subspace, which makes it particularly useful when dealing with large sparse matrices.
The Arnoldi method belongs to a class of linear algebra algorithms that give a partial result after a small number of iterations, in contrast to so-called direct methods which must complete to give any useful results (see for example, Householder transformation). The partial result in this case being the first few vectors of the basis the algorithm is building.
The GMRES method was developed by Yousef Saad and Martin H. Schultz in 1986. It is a generalization and improvement of the MINRES method due to Paige and Saunders in 1975. The MINRES method requires that the matrix is symmetric, but has the advantage that it only requires handling of three vectors. GMRES is a special case of the DIIS method developed by Peter Pulay in 1980 (DIIS is applicable to non-linear system).
Denote the Euclidean norm of any vector
The matrix A is assumed to be invertible of size m-by-m. Furthermore, it is assumed that b is normalized, i.e., that
The n-th Krylov subspace for this problem is
where
GMRES approximates the exact solution of
The vectors
Therefore, the vector
The Arnoldi process also produces an
For symmetric matrices, a symmetric tri-diagonal matrix is actually achieved, resulting in the minres method.
Because columns of
where
is the first vector in the standard basis of
This is a linear least squares problem of size n.
This yields the GMRES method. On the
1. calculate q_n with the Arnoldi method;
2. find the y_n which minimizes ||r_n||;
3. compute x_n = x_0 + Q_n y_n;
4. repeat if the residual is not yet small enough
At every iteration, a matrix-vector product
One part of the GMRES method is to find the vector
In some practical implementation this part is solved using Givens rotation but in this vanilla one we do without it in order to make it easier to understand.
One of the most important characteristics of GMRES is that it will always arrive at an exact solution (if one exists). At the
Sometimes, the exact solution
This does not happen in general. Indeed, a theorem of Greenbaum, Pták and Strakoš states that for every nonincreasing sequence
In practice, though, GMRES often performs well. This can be proven in specific situations. If the symmetric part of A, that is
where
If A is symmetric and positive definite, then we even have
where
In the general case, where A is not positive definite, we have
where
All these inequalities bound only the residuals instead of the actual error, that is, the distance between the current iterate
The frst few iterations of GMRES have low spatial and temporal complexity. However, as
This issue is addressed by using GMRES(k)
, or GMRES with restarts. When GMRES(k)
will always have manageable spatial and temporal complexity, but it is less reliable than GMRES. If the true solution GMRES(k)
could converge very slowly or not at all.
The project is composed by two part:
- Arnoldi Iteration implementation and testing: in the
Arnoldi_Iteration/
folder 📂 there is a .ipynb notebook where has been implemented the Arnoldi Iteration algorithm.
The main scope of this notebook is to demonstrate that with the Arnoldi Iteration is possible to approximate some eigenvalue in a matrix. This application is usefull, above all, for large and sparse matrix, where other method (like Power Method) can't be applied. We show that the eigenvalue found by Arnoldi Iteration and Power method for small matrices is the same. But, with very huge matrices the Power Method is inapplicable while the Arnoldi Iteration can find a good approximation for the bigger eigevalue of the matrix (with a sufficient iteration number). In the notebook are reported the results and the implementations. - GMRES algorithm implementation and testing: in the
GMRES/
folder 📂 there is a .ipynb notebook where has been implemented the GMRES algorithm. This time the code is written inOctave
so, in order to execute the code in your machine, you can follow the Installation and Testing Guide in the section below. The notebook is also formattend in an Ocatve file so, you can execute only that without install any docker container.
The main scope of this notebook is to show the possible application, the operation, the advantages and the drawbacks of this algorithm. The notebook start with a brief part in which we explained the possible way to load very huge sparse matrix: you can use some examples matrix from https://sparse.tamu.edu/, or you can generate it randomly in different ways (with or without conditioning).
The file proceed with theGMRES
standard implementation and theGMRES with Restarting
implementation. The remaining part of the notebook contains a lot of tests that we have done in order to show, in easy way, when the algoritmh converges and when not. You can see all the results in the notebook but, to summarise, we report a brief explanation here:
We show that the GMRES algorithm does't converge with any matrix (for clarity, usually it never converge in is standard form). Of course it has been demonstrate that the algorithm always converge with a number of iteration equal to the dimension of the matrix. But in a real application is inapplicable when the matrix is huge. The particular cases, when the algorithm converge, are when the eigenvalues of the matrices are clustered near the center of the plane, in the other cases it never converges. To achieve this problem, some tecniques has been proposed and implemented in the years, i.e. is possible to applicate a conditioning on the matrices that leads the eigenvalue to be cluestered near the center of the plan.
To prepare the system to run the project, it is necessary something that is able to execute a Jupyter Notebook with all dependacies and requirements.
You can install it by yourself but, to make this work easier, we propose a docker container with everything you need. To install it you have to move in docker_container/
📂 folder and run the following command:
docker compose up
Now you have a system able to execute all the code 🦧.
To start the docker you have to run
docker start -a docker_container-octave-1
To run the notebook you have to open the jupyter web page following the link that terminal return to you after starting the specific docker container, for example:
http://127.0.0.1:8888/lab?token=c8c09f0b3ce7078426536c1152713b850a24363715eca933
Now move to the notebook that you want to execute and open it (from web page). You also have to choose the correct jupyter kernel:
- for the GMRES algorithm you have to choose the
Octave Kernel
, - for the Arnoldi Iteration the
python kernel
Now everything is done.
To stop the docker container you have to run:
docker stop docker_container-octave-1
- Wikipedia
- GMRES first paper: Yousef Saad and Martin H. Schultz
- GMRES labs
Cristian Cosci 🐔 | Nicolò Vescera 🦧 | Fabrizio Fagiolo 🐛 |