No effect is observed when I try to use StartVector in eigs to improve numerical efficiency

2 ビュー (過去 30 日間)
Zhao-Yu
Zhao-Yu 2024 年 7 月 14 日
コメント済み: Umar 2024 年 7 月 18 日
I test the efficiency of using a good StartVector in eigs.
The code is quite simple.
First, I use eigs to figure out the eigenvector v1,
then I use this eigenvector v1 as the StartVector to run eigs again.
I expect that much less time might be needed now.
Nevertheless,
the time cost shows no improvement at all.
My code is as follows
----------------------------------------------------------------------
format long
n = 3000;
A = rand(n,n);
A = A + A';
tic
[v1,eta1]=eigs(@(vec)test_eigs(vec,A),n,1,'lm','Display',0,'IsFunctionSymmetric',0,'MaxIterations',300);
toc
StartVector = v1;
tic
[v2,eta2]=eigs(@(vec)test_eigs(vec,A),n,1,'lm','Display',0,'IsFunctionSymmetric',0,'MaxIterations',300,'StartVector',StartVector);
toc
eta1
eta2
function vec1 = test_eigs(vec0,A)
vec1 = A * vec0;
end
------------------------------------------------------------------------------------
The output is as follows
~~~~~~~~~~~~~~~~~~~~~~
Elapsed time is 0.069811 seconds.
Elapsed time is 0.066047 seconds.
eta1 =
3.000980119229400e+03
eta2 =
3.000980119229400e+03
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So my question is,
is there anything wrong in my understanding about StartVector in eigs?
Any suggestion or comment would be greatly appreciated.
  8 件のコメント
Zhao-Yu
Zhao-Yu 2024 年 7 月 18 日
Hi Dear Umar,
Thank you very much for your patience and kindness :)
Yes I am trying to improve the numerical efficiency of my code,
which carries out a numerical optimization by solving serials of eigenvalue problems.
In order to improve the efficiency of the code, I tried to use MATLAB coder, but I failed :(
Umar
Umar 2024 年 7 月 18 日
Hi Zhao,
Please don’t give up on your problem. After going through your insights and analysis of StartVector, it made me realize that you have potential to solve this problem. There are other functions and algorithms to help solve this problem and there is always various ways to solve a problem and get solution. So, I will encourage you to keep seeking solution to this problem. Again, if you still need our help, please let us know. We will be more happy to help you out.

サインインしてコメントする。

回答 (1 件)

Kaustab Pal
Kaustab Pal 2024 年 7 月 17 日
Your understanding of using StartVector is correct. The StartVector serves as the initial guess for the iterative algorithms used by eigs to find the eigenvalues and eigenvectors. A good initial guess can significantly speed up the convergence of the algorithm, while poor initial guesses might lead to slower convergence or convergence to unwanted eigenvalues.
However, please note that the benefit of using the StartVector is especially pronounced when dealing with large sparse matrices. In such cases, the speedup from using StartVectors is significant compared to not using them.
I tested this with a slight modification of the code you provided. You can find the code snippet along with the computation times below.
n = 10000;
A = rand(n,n);
A = A + A';
A_sparse = sparse(diag(1:n));
disp("Computation time without Start Vector for matrix A");
Computation time without Start Vector for matrix A
tic
[V, D] = eigs(@(vec)test_eigs(vec,A),n,1, 'lm','Display',0,'IsFunctionSymmetric',0,'MaxIterations',300);
toc
Elapsed time is 0.368794 seconds.
disp("Computation time with Start Vector for matrix A");
Computation time with Start Vector for matrix A
tic
[V, D] = eigs(@(vec)test_eigs(vec,A),n,1, 'lm','Display',0,'IsFunctionSymmetric',0,'MaxIterations',300, 'StartVector', V);
toc
Elapsed time is 0.319875 seconds.
disp("Computation time without Start Vector for matrix A_sparse");
Computation time without Start Vector for matrix A_sparse
tic
[V_sparse, D] = eigs(@(vec)test_eigs(vec,A_sparse),n,1, 'lm','Display',0,'IsFunctionSymmetric',0,'MaxIterations',300);
toc
Elapsed time is 0.591944 seconds.
disp("Computation time with Start Vector for matrix A_sparse");
Computation time with Start Vector for matrix A_sparse
tic
[V_sparse, D] = eigs(@(vec)test_eigs(vec,A_sparse),n,1, 'lm','Display',0,'IsFunctionSymmetric',0,'MaxIterations',300, 'StartVector', V_sparse);
toc
Elapsed time is 0.021382 seconds.
function vec1 = test_eigs(vec0,A)
vec1 = A * vec0;
end
As can be seen from the outputs, the computation time when using the StartVector to find the eigenvectors for a large sparse matrix is significantly faster than without using the StartVector.
I hope this clarifies your understanding.
  1 件のコメント
Zhao-Yu
Zhao-Yu 2024 年 7 月 17 日
編集済み: Zhao-Yu 2024 年 7 月 17 日
Hi Dear Kaustab Pal,
I have checked your script for many times,
and the time cost is indeed the same as you:
---------------------------------------------------------------------------
Computation time without Start Vector for matrix A
Elapsed time is 0.621284 seconds.
Computation time with Start Vector for matrix A
Elapsed time is 0.626303 seconds.
Computation time without Start Vector for matrix A_sparse
Elapsed time is 0.464736 seconds.
Computation time with Start Vector for matrix A_sparse
Elapsed time is 0.032755 seconds.
---------------------------------------------------------------------------
Thus, it is quite clear that
(1) When sparse large matrices are involved,
supplying a good guess vector can indeed speed up the convergence sigfinicantly.
(2) For dense matrices,
numerical simulations suggest that supplying a good guess vector to eigs may not speed up the convergence.
Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by