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) array or (n,n) sparray or (n,n) LinearOperator

Square matrix or LinearOperator which eigenvalue will be estimated.

n_itersint, optional

Number of iterations used in the power iteration method.

seedint or numpy.random.Generator or None, optional

Random seed used to define a random initial guess for the eigenvector.

atolfloat, 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, a ConvergenceError will be raised.

Returns:
float

Estimated largest absolute eigenvalue of the matrix argument.

Raises:
inversion_ideas.errors.ConvergenceError

If the norm of the eigenvector falls below the atol argument, 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