SafeZone AI Learn
Learn/ Mathematical Foundations/ Linear Algebra for ML · lesson 2 of 6

Eigenvectors and eigenvalues

The directions a transformation only stretches: the eigendecomposition, power iteration (the algorithm that ranked the web), and the spectral theorem — the single result the rest of this curriculum leans on hardest.

Watch any linear map act on the plane and most vectors get knocked off their direction. A few do not: they come out scaled, pointing exactly where they pointed before. Those stubborn directions — eigenvectors — are the transformation’s skeleton, and finding them turns an incomprehensible map into a diagonal one. This lesson earns three things: the decomposition itself, the humble iteration that computes it at web scale, and the spectral theorem — which, count them, already underwrites the condition number κ, the Hessian classification of critical points, ridge’s shrinkage picture, and the covariance geometry of PCA.

The definition, and how to find them by hand

A nonzero vv is an eigenvector of AA with eigenvalue λ\lambda when

Av=λvA v = \lambda v

— the map’s entire action on that direction is a stretch by λ\lambda (negative: flip; magnitude below one: contraction). Rearranged, (AλI)v=0(A - \lambda I)v = 0 demands a nonzero vector in the kernel of AλIA - \lambda I, which exists exactly when that matrix is singular:

det(AλI)=0— the characteristic equation.\det(A - \lambda I) = 0 \qquad\text{— the characteristic equation.}

For a 2×2 this is a quadratic with a form worth memorizing, λ2tr(A)λ+det(A)=0\lambda^2 - \operatorname{tr}(A)\,\lambda + \det(A) = 0, so trA=λ1+λ2\operatorname{tr} A = \lambda_1 + \lambda_2 and detA=λ1λ2\det A = \lambda_1 \lambda_2 — the area factor from last lesson is the product of the stretches, as it must be. Beyond 3×3 nobody solves characteristic polynomials (they are numerically treacherous); iteration wins, as you are about to see.

If AA has nn independent eigenvectors, stack them as columns of VV:

A=VΛV1Ak=VΛkV1.A = V \Lambda V^{-1} \qquad\Longrightarrow\qquad A^k = V \Lambda^k V^{-1}.

Read the decomposition as instructions: change into eigen-coordinates, stretch each axis independently, change back. The payoff line Ak=VΛkV1A^k = V\Lambda^k V^{-1} turns repeated application — the expensive thing — into powering scalars, and it is the exact tool you used in Optimization to solve gradient descent’s dynamics (xt+1=(IηH)xtx_{t+1} = (I - \eta H)x_t decoupling per eigendirection into factors (1ηλi)t(1-\eta\lambda_i)^t: that was this lesson, smuggled in early).

Power iteration: the web-ranking algorithm in four lines

Apply AA repeatedly to almost any starting vector and expand in the eigenbasis:

Akx=c1λ1kv1+c2λ2kv2+=λ1k(c1v1+c2(λ2λ1)kv2+).A^k x = c_1 \lambda_1^k v_1 + c_2 \lambda_2^k v_2 + \cdots = \lambda_1^k \Big( c_1 v_1 + c_2 (\tfrac{\lambda_2}{\lambda_1})^k v_2 + \cdots \Big).

Every component decays relative to the dominant one at rate λ2/λ1k\lvert \lambda_2/\lambda_1 \rvert^k — the direction of AkxA^k x converges to the top eigenvector, no polynomial-solving required. Normalize each step and you have power iteration, and you have also just derived PageRank: Google’s founding algorithm builds the web’s link matrix (column-stochastic, damped) and power-iterates it; the stationary importance of every page on the internet is the top eigenvector, and the damping factor 0.85 exists precisely to control the λ2/λ1\lambda_2/\lambda_1 gap that sets convergence speed. The same iteration scores nodes in every network (eigenvector centrality), finds the top principal component when the data is too big to decompose, and — as the Deep RL chapter’s power method for values hints — is the quiet engine inside many “iterate to a fixed point” algorithms.

The dashed lines never move when the grid shears around them — drag the columns and watch the skeleton reorient. Press Apply A repeatedly: the gold vector swings toward the dominant eigendirection and locks on; the closer λ₂/λ₁ is to 1 (drag the columns to make the eigenvalues similar — read them in the panel), the more steps it takes — the spectral gap is the convergence rate, exactly as derived above. Try the rotate preset: the readout reports complex eigenvalues and the dashed lines vanish — a pure rotation stretches no real direction, and the power vector just circles forever. That failure case is as instructive as the success.

The spectral theorem: symmetry buys everything

For general matrices, eigenvectors may be non-orthogonal, complex, or missing. For the matrices ML actually optimizes over, nature is kind:

Spectral theorem. Every symmetric A=AA = A^\top has real eigenvalues and an orthonormal basis of eigenvectors: A=QΛQA = Q \Lambda Q^\top with QQ orthogonal.

Symmetric maps are exactly rotate, stretch along perpendicular axes, rotate back — no shear, no complex behaviour, nothing hidden. And the matrices this curriculum lives on are symmetric by construction: XXX^\top X (Supervised Learning’s normal equations), covariance matrices (PCA, next lessons), Hessians 2f\nabla^2 f (Optimization), kernel matrices (SVMs). For all of them the spectral theorem is why:

  • κ was well-defined: the condition number is λmax/λmin\lambda_{\max}/\lambda_{\min} of a symmetric Hessian — perpendicular stretch factors of the loss’s local bowl.
  • Saddles were classifiable: mixed Hessian eigenvalue signs = up in some perpendicular directions, down in others (the Non-convex landscapes lesson’s taxonomy is the spectral theorem plus adjectives).
  • Ridge’s shrinkage was diagonal: (XX+λI)1(X^\top X + \lambda I)^{-1} shares eigenvectors with XXX^\top X, shrinking each direction by dj2/(dj2+λ)d_j^2/(d_j^2 + \lambda) — the Regularization lesson’s formula, now with its provenance attached.

The quadratic-form view makes the geometry tactile: f(x)=xAxf(x) = x^\top A x has the eigenvectors as its principal axes and the eigenvalues as curvatures along them — which is precisely the surface classification you will drive by slider in lesson 5’s widget, and precisely what “positive definite” (λi>0\lambda_i > 0: a bowl) means.

import numpy as np

A = np.array([[1.5, 0.45], [0.35, 0.9]])
lam, V = np.linalg.eig(A)                 # general case

def power_iteration(A, k=50):
    v = np.random.randn(A.shape[0])
    for _ in range(k):
        v = A @ v
        v /= np.linalg.norm(v)            # the whole algorithm
    return v, v @ A @ v                   # direction, Rayleigh-quotient eigenvalue

S = A + A.T                               # symmetrize → spectral theorem applies
lam_s, Q = np.linalg.eigh(S)              # eigh: real λ, orthonormal Q, sorted
np.testing.assert_allclose(Q @ np.diag(lam_s) @ Q.T, S, atol=1e-12)

Exercises

Work these before the next lesson

  1. Derive λ2tr(A)λ+det(A)=0\lambda^2 - \operatorname{tr}(A)\lambda + \det(A) = 0 for 2×2, and compute the eigen-pairs of the widget’s default AA (columns (1.5,0.35)(1.5, 0.35) and (0.45,0.9)(0.45, 0.9)). Check against the panel’s readout.
    Solution

    Worked solutions are part of Premiumunlock all of them for £5/month →

  2. 5 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →

References

  • G. Strang, Introduction to Linear Algebra, ch. 6 — eigenvalues with the geometry kept on.
  • S. Brin & L. Page, “The Anatomy of a Large-Scale Hypertextual Web Search Engine”, 1998 — PageRank; read §2.1 and recognize this lesson.
  • L. Trefethen & D. Bau, Numerical Linear Algebra — why nobody solves characteristic polynomials, and what production eigensolvers actually do.