Inverse Iteration
Power iteration finds only the largest eigenvalue, and slowly if the next one is close. Applying power iteration to instead finds the eigenvalue closest to a shift , and can converge very fast. Updating the shift at every step gives Rayleigh quotient iteration, which converges cubically for symmetric matrices.
Shift and invert
implies . The eigenvalue of nearest becomes the largest eigenvalue of , so power iteration on it converges to that eigenvector with rate
which is small when is a good guess. We never form the inverse: factor once and solve one system per step.
import numpy as np
import scipy.linalg as sla
rng = np.random.default_rng(61)
Q, _ = np.linalg.qr(rng.normal(size=(40, 40)))
lams = np.r_[3.0, 3.2, np.linspace(-10, 2, 19), np.linspace(5, 10, 19)]
A = Q @ np.diag(lams) @ Q.T # symmetric, eigenvalues include 3 and 3.2
s = 2.9 # shift near 3
lu = sla.lu_factor(A - s * np.eye(40))
x = rng.normal(size=40)
for k in range(1, 9):
x = sla.lu_solve(lu, x)
x /= np.linalg.norm(x)
print(f"k = {k}: Rayleigh quotient {x @ A @ x:.14f}")
print("predicted rate:", round(abs(3.0 - s) / min(abs(l - s) for l in lams if l != 3.0), 4), "per step for the vector; squared for the Rayleigh quotient")k = 1: Rayleigh quotient 2.99907073268261
k = 2: Rayleigh quotient 3.00006638643713
k = 3: Rayleigh quotient 3.00000829589685
k = 4: Rayleigh quotient 3.00000092708005
k = 5: Rayleigh quotient 3.00000010304934
k = 6: Rayleigh quotient 3.00000001145033
k = 7: Rayleigh quotient 3.00000000127226
k = 8: Rayleigh quotient 3.00000000014137
predicted rate: 0.3333 per step for the vector; squared for the Rayleigh quotient
Rayleigh quotient iteration
If we use the current Rayleigh quotient as the shift at every step, the shift gets better as the vector does. For symmetric matrices the convergence is cubic: the number of correct digits roughly triples per step. The price: a new factorization each step, since the shift changes.
import numpy as np
rng = np.random.default_rng(61)
Q, _ = np.linalg.qr(rng.normal(size=(40, 40)))
lams = np.r_[3.0, 3.2, np.linspace(-10, 2, 19), np.linspace(5, 10, 19)]
A = Q @ np.diag(lams) @ Q.T
x = Q[:, 0] + 0.02 * rng.normal(size=40) # rough approximation of the eigenvector
x /= np.linalg.norm(x)
for k in range(1, 5):
rho = x @ A @ x
print(f"k = {k}: shift {rho:.16f}, error {abs(rho - 3.0):.1e}")
x = np.linalg.solve(A - rho * np.eye(40), x)
x /= np.linalg.norm(x)k = 1: shift 2.9848539169591461, error 1.5e-02
k = 2: shift 3.0000000244592337, error 2.4e-08
k = 3: shift 3.0000000000000027, error 2.7e-15
k = 4: shift 3.0000000000000009, error 8.9e-16
Notice that becomes nearly singular as approaches the eigenvalue. That is harmless: the solve's error points mostly along the eigenvector we want, and normalization removes the huge scale.
Uses
- Computing an eigenvector once an eigenvalue estimate is known (the standard way LAPACK gets selected eigenvectors).
- Interior eigenvalues of large sparse matrices with shift-invert Krylov methods:
eigsh(A, k, sigma=s). - Finding the vibration mode of a structure nearest a forcing frequency.
In software
scipy.sparse.linalg.eigsh(A, k=3, sigma=2.9)uses shift-invert mode with a sparse LU of and returns the 3 eigenvalues nearest 2.9.scipy.linalg.eigh(A, subset_by_value=(a, b))returns only the eigenvalues in an interval.
Exercises
Exercise 1: Which eigenvalue?
has eigenvalues . Inverse iteration with shift converges to which, and at what rate?
Answer
, rate .
Solution
Distances to : . The nearest is (), the next is ().
Exercise 2: The smallest eigenvalue
How do you find the eigenvalue of smallest magnitude with inverse iteration?
Answer
Use shift : power iteration on .
Solution
The largest eigenvalue of is where is the eigenvalue of of smallest magnitude.
Exercise 3: Shift-invert in SciPy (code)
Find the 3 eigenvalues of the lesson's matrix nearest with scipy.sparse.linalg.eigsh in shift-invert mode.
Answer
, and .
Solution
import numpy as np
from scipy.sparse.linalg import eigsh
rng = np.random.default_rng(61)
Q, _ = np.linalg.qr(rng.normal(size=(40, 40)))
A = Q @ np.diag(np.r_[3.0, 3.2, np.linspace(-10, 2, 19), np.linspace(5, 10, 19)]) @ Q.T
vals = eigsh(A, k=3, sigma=2.9, return_eigenvectors=False)
print(np.round(np.sort(vals), 4))[2. 3. 3.2]
Test yourself
Inverse iteration with shift converges to the eigenvalue…
- largest in magnitude
- closest to
- smallest in magnitude
- farthest from
For symmetric matrices, Rayleigh quotient iteration converges…
- linearly
- quadratically
- cubically
- not at all
Inverse iteration should be implemented by…
- computing explicitly
- factoring once and solving each step
- using the determinant
- power iteration on