inversion_ideas.utils.get_largest_eigenvalue#
- inversion_ideas.utils.get_largest_eigenvalue(matrix, *, n_iters=4, seed=None, atol=1e-16)[source]#
Estimate largest absolute eigenvalue for a diagonalizable matrix.
Use the power iteration method to estimate the eigenvector associated with the largest absolute eigenvalue for the given matrix.
- Parameters:
- matrix(n,n)
arrayor (n,n)sparrayor (n,n)LinearOperator Square matrix or
LinearOperatorwhich eigenvalue will be estimated.- n_iters
int, optional Number of iterations used in the power iteration method.
- seed
intornumpy.random.GeneratororNone, optional Random seed used to define a random initial guess for the eigenvector.
- atol
float, optional Absolute tolerance that will be passed to
numpy.isclose()when checking if the norm of the eigenvector is small enought that it can be considered equal to zero. If a null eigenvector is found during the iterations, aConvergenceErrorwill be raised.
- matrix(n,n)
- Returns:
floatEstimated largest absolute eigenvalue of the
matrixargument.
- Raises:
inversion_ideas.errors.ConvergenceErrorIf the norm of the eigenvector falls below the
atolargument, and therefore is considered to be the null vector.
Notes
Given a diagonalizable matrix \(\mathbf{A}\), we can estimate the eigenvector related to its largest absolute eigenvalue \(|\lambda|\) through the power iteration method. In a nutshell, we start with a random unit vector \(\mathbf{b}_0\), and estimate that eigenvector through a recursive relation:
\[\mathbf{b}_{k+1} = \frac{ \mathbf{A}\mathbf{b}_k }{ \lVert \mathbf{A}\mathbf{b}_k \rVert }\]Once we obtained the \(\mathbf{b}_k\) eigenvector, we can get the absolute value of its corresponding eigenvalue through:
\[|\lambda| = \frac{ \lVert \mathbf{A} \mathbf{b}_k \rVert }{ \lVert \mathbf{b}_k \rVert }\]If the eigenvector \(\mathbf{b}_k\) is a unit vector (normalized by its magnitude), then we can simplify the last expression to:
\[|\lambda| = \lVert \mathbf{A} \mathbf{b}_k \rVert\]References
https://en.wikipedia.org/wiki/Power_iteration
Examples
>>> import numpy as np >>> matrix = np.array( ... [ ... [1., 0., 0.], ... [0., 2., 0.], ... [0., 0., 3.], ... ] ... ) >>> get_largest_eigenvalue(matrix, seed=42) 3.0