TExcelTAD
Home › Numerical Methods › Power Iteration

Power Iteration

The simplest eigenvalue algorithm multiplies a vector by AA again and again. The component along the eigenvector with the largest eigenvalue grows fastest and soon dominates. Power iteration needs only matrix-vector products, so it works for huge sparse matrices; it is the idea behind PageRank and the starting point of all Krylov eigenvalue methods.

The algorithm

Start with a random x0\mathbf{x}_0 and repeat:

y=Axk,xk+1=y∥y∥,λ(k+1)=xk+1TAxk+1.\mathbf{y} = A\mathbf{x}_k, \qquad \mathbf{x}_{k+1} = \frac{\mathbf{y}}{\lVert\mathbf{y}\rVert}, \qquad \lambda^{(k+1)} = \mathbf{x}_{k+1}^TA\mathbf{x}_{k+1}.

The normalization prevents overflow; the Rayleigh quotient xTAx\mathbf{x}^TA\mathbf{x} estimates the eigenvalue.

Why it works

Write x0=∑jcjvj\mathbf{x}_0 = \sum_j c_j\mathbf{v}_j in the eigenvector basis with ∣λ1∣>∣λ2∣≥⋯\lvert\lambda_1\rvert > \lvert\lambda_2\rvert \ge \cdots. Then

Akx0=λ1k(c1v1+∑j≥2cj(λjλ1)kvj),A^k\mathbf{x}_0 = \lambda_1^k\left(c_1\mathbf{v}_1 + \sum_{j \ge 2}c_j\left(\frac{\lambda_j}{\lambda_1}\right)^k\mathbf{v}_j\right),

so the direction converges to v1\mathbf{v}_1 linearly with rate ∣λ2λ1∣\left\lvert\frac{\lambda_2}{\lambda_1}\right\rvert. For a symmetric matrix the Rayleigh quotient error goes like the square of that, ∣λ2λ1∣2k\left\lvert\frac{\lambda_2}{\lambda_1}\right\rvert^{2k}.

python · try it yourself
import numpy as np

rng = np.random.default_rng(51)
Q, _ = np.linalg.qr(rng.normal(size=(50, 50)))
lams = np.r_[10.0, 9.0, rng.uniform(-5, 5, 48)]
A = Q @ np.diag(lams) @ Q.T                     # symmetric, lambda1 = 10, lambda2 = 9

x = rng.normal(size=50)
prev = None
for k in range(1, 121):
    y = A @ x
    x = y / np.linalg.norm(y)
    if k % 20 == 0:
        err = abs(x @ A @ x - 10)
        rate = "" if prev is None else f", error factor per step {(err / prev) ** (1 / 20):.4f}"
        print(f"k = {k:3d}: error of Rayleigh quotient {err:.1e}{rate}")
        prev = err
k =  20: error of Rayleigh quotient 3.1e-05
k =  40: error of Rayleigh quotient 4.6e-07, error factor per step 0.8100
k =  60: error of Rayleigh quotient 6.8e-09, error factor per step 0.8100
k =  80: error of Rayleigh quotient 1.0e-10, error factor per step 0.8100
k = 100: error of Rayleigh quotient 1.5e-12, error factor per step 0.8103
k = 120: error of Rayleigh quotient 1.8e-14, error factor per step 0.8015

The measured factor per step matches the prediction (910)2=0.81\left(\frac{9}{10}\right)^2 = 0.81 until rounding error takes over. The ratio 910\frac{9}{10} makes convergence slow; a gap like 110\frac{1}{10} would converge in a handful of steps.

PageRank

The PageRank vector is the dominant eigenvector (eigenvalue 1) of the "Google matrix" G=αP+1−αn11TG = \alpha P + \frac{1 - \alpha}{n}\mathbf{1}\mathbf{1}^T, where PP is the column-stochastic link matrix. The damping α=0.85\alpha = 0.85 guarantees ∣λ2∣≤0.85\lvert\lambda_2\rvert \le 0.85, so power iteration converges at a known rate.

python · try it yourself
import numpy as np

links = {0: [1, 2], 1: [2], 2: [0], 3: [0, 2], 4: [3, 2]}     # page -> pages it links to
n = 5
P = np.zeros((n, n))
for j, outs in links.items():
    P[outs, j] = 1 / len(outs)
alpha = 0.85
x = np.ones(n) / n
for k in range(100):
    x_new = alpha * P @ x + (1 - alpha) / n
    if np.abs(x_new - x).sum() < 1e-12:
        break
    x = x_new
print("PageRank:", np.round(x_new, 4), "after", k + 1, "iterations")
print("ranking :", np.argsort(-x_new))
PageRank: [0.3667 0.1858 0.3747 0.0428 0.03  ] after 55 iterations
ranking : [2 0 1 3 4]

Limitations

  • Finds only the eigenvalue of largest magnitude, and converges slowly if ∣λ2∣≈∣λ1∣\lvert\lambda_2\rvert \approx \lvert\lambda_1\rvert.
  • Fails to settle if the two largest have equal magnitude (e.g. λ=±1\lambda = \pm 1 or a complex pair).
  • The fixes are shifts and inverse iteration (Inverse Iteration) and, for several eigenvalues at once, subspace or Krylov methods (Lanczos, Arnoldi).

In software

  • scipy.sparse.linalg.eigs / eigsh (ARPACK) use Krylov subspaces, a far better use of the same matrix-vector products; ask for k eigenvalues with which="LM" (largest magnitude), "SA", and so on.
  • Power iteration is used in deep learning to estimate spectral norms cheaply (spectral normalization of GAN discriminators).

Exercises

Exercise 1: Steps needed

∣λ2λ1∣=0.5\left\lvert\frac{\lambda_2}{\lambda_1}\right\rvert = 0.5. Roughly how many power-iteration steps reduce the eigenvector error by 10−1210^{-12}?

Answer

About 40.

Solution

0.5k=10−120.5^k = 10^{-12} gives k=12log⁡210≈39.9k = 12\log_2 10 \approx 39.9.

Exercise 2: By hand

Do two steps of power iteration on A=(2112)A = \begin{pmatrix} 2 & 1 \\ 1 & 2\end{pmatrix} from x0=(1,0)\mathbf{x}_0 = (1, 0), without normalizing.

Answer

(2,1)(2, 1), then (5,4)(5, 4).

Solution

The direction approaches (1,1)(1, 1), the eigenvector for λ=3\lambda = 3; the ratio λ2λ1=13\frac{\lambda_2}{\lambda_1} = \frac{1}{3}.

Exercise 3: Spectral norm by power iteration (code)

Estimate ∥B∥2\lVert B\rVert_2 for a random 200×100200 \times 100 matrix by power iteration on BTBB^TB (never form it: compute BT(Bx)B^T(B\mathbf{x})) and compare with np.linalg.norm(B, 2).

Answer

After 300 iterations they agree only to about 4 digits, because σ2\sigma_2 is close to σ1\sigma_1 (the printed ratio): convergence is slow.

Solution
python · try it yourself
import numpy as np
rng = np.random.default_rng(52)
B = rng.normal(size=(200, 100))
x = rng.normal(size=100)
for _ in range(300):
    x = B.T @ (B @ x); x /= np.linalg.norm(x)
s = np.linalg.svd(B, compute_uv=False)
print(f"{np.linalg.norm(B @ x):.10f} {s[0]:.10f}, (sigma2/sigma1)^2 = {(s[1] / s[0]) ** 2:.4f}")
23.0375003276 23.0392418338, (sigma2/sigma1)^2 = 0.9885

Test yourself

Power iteration converges to the eigenvector of…

  1. the smallest eigenvalue
  2. the eigenvalue of largest magnitude
  3. eigenvalue 0
  4. all eigenvalues at once

The convergence rate of power iteration is…

  1. quadratic
  2. linear with rate ∣λ2/λ1∣\lvert\lambda_2/\lambda_1\rvert
  3. linear with rate 1/21/2
  4. independent of the eigenvalues

Why is power iteration suitable for huge sparse matrices?

  1. It factorizes them
  2. It needs only matrix-vector products
  3. It uses the determinant
  4. It is exact