Discover: a definition that chases its own tail
In 1998 two Stanford PhD students, Sergey Brin and Lawrence Page, described a prototype search engine called Google. One of its key ideas was a way to score every page on the web by importance, and it fits on one line:
Spotted in the wild
Read it aloud: “the PageRank of page is one minus , plus times the sum, over the pages to that link to , of each one's PageRank divided by its number of outgoing links.” Here counts the links going out of page , and is a “damping factor” the paper usually sets to . Each page splits its own importance equally among the pages it links to, and a page is important if important pages link to it.
Now look again. To compute you need . But is defined by the same formula, using the pages that link to it, and one of those might well be . The definition chases its own tail. How can a number be defined in terms of itself, and how would you ever compute it?
The answer is one of the most useful ideas in linear algebra. Collect all the PageRanks into a single vector: the formula says that a certain matrix leaves that vector exactly where it is. A vector that a matrix doesn't turn is called an eigenvector, and by the end of this chamber you'll compute PageRank yourself.
Learn: the directions a matrix only stretches
Chamber 4 taught you to see a matrix as a machine that moves space. Feed it a vector and, almost always, the output points somewhere new. But for most matrices a few special directions are merely stretched: the output lies on the same line through the origin as the input.
Read it as “A v equals lambda v”. A non-zero vector with this property is an eigenvector of , and the number (lambda) is its eigenvalue: the factor by which stretches that direction. The zero vector is excluded because for every , which tells you nothing.
The size and sign of tell the story. With the eigenvector triples in length. With it halves. With it flips to point the other way, still on its line. With it is flattened to , so it lies in the null space.
You have met eigenvectors already without the name:
- A diagonal matrix such as stretches the -axis by 2 and squashes the -axis by half. Its eigenvectors are (with ) and (with ).
- A projection onto a line (Chamber 7) leaves vectors on the line alone () and sends the perpendicular direction to zero ().
- A reflection across a line keeps the line () and flips the perpendicular direction ().
- A rotation by turns every direction. It has no real eigenvectors at all.
One more fact before you go hunting. If is an eigenvector, so is any non-zero multiple , because . Eigenvectors come in whole lines through the origin, so we really look for eigen-directions.
- “A v equals lambda v”The eigenvalue equation: only stretches , by the factor , and never turns it off its line. A non-zero that satisfies it is an eigenvector, and is its eigenvalue.
- “lambda”An eigenvalue: the stretch factor. stretches, shrinks, a negative flips, and flattens the vector to .
- “det of A minus lambda I equals zero”The characteristic equation. Its solutions are exactly the eigenvalues of .
- “p of lambda”The characteristic polynomial , of degree for an matrix. For matrices it is .
- “trace of A”The trace: the sum of the diagonal entries. It always equals the sum of the eigenvalues.
- “the Rayleigh quotient of x”Exactly when is an eigenvector, and a good estimate of it when is close to one. Power iteration uses it to read off the eigenvalue.
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “A v equals lambda v” | The eigenvalue equation: only stretches , by the factor , and never turns it off its line. A non-zero that satisfies it is an eigenvector, and is its eigenvalue. | ||
| “lambda” | An eigenvalue: the stretch factor. stretches, shrinks, a negative flips, and flattens the vector to . | ||
| “det of A minus lambda I equals zero” | The characteristic equation. Its solutions are exactly the eigenvalues of . | ||
| “p of lambda” | The characteristic polynomial , of degree for an matrix. For matrices it is . | ||
| “trace of A” | The trace: the sum of the diagonal entries. It always equals the sum of the eigenvalues. | ||
| “the Rayleigh quotient of x” | Exactly when is an eigenvector, and a good estimate of it when is close to one. Power iteration uses it to read off the eigenvalue. |
Suppose . What is ?
Now find some by eye. Turn the unit vector around the circle and watch where sends it.
Interactive lab
Eigenvector hunt
Turn x around the circle. Watch for the moments when Ax lines up with x.
x
(0.94, 0.34)
Ax
(1.88, 0.17)
Angle between the lines of x and Ax
14.8°
Under 1° counts as parallel.
A few things to notice. The stretch matrix's eigenvectors are the axes, as expected. The symmetric matrix has eigen-directions at and , which meet at a right angle. The triangular matrix's two directions don't: they meet at about . And one of its eigenvalues is negative, so there points straight back the way came. With Show A(circle) on, you can see each eigen-direction pointing to where the ellipse crosses it, at distance from the origin.
Learn: finding eigenvalues with the determinant
Hunting by eye works in two dimensions. For anything bigger we need algebra, and the derivation takes four steps, each resting on an earlier chamber.
- 1
Move everything to one side
is the same as , that is, . We slip in the identity because we can't subtract a number from a matrix, but is a matrix.
- 2
Read it as a null space
We need a non-zero with : the matrix must have a non-trivial null space (Chamber 6).
- 3
Translate to singular
A square matrix has a non-trivial null space exactly when it is singular, not invertible (Chamber 5).
- 4
Translate to a determinant
A square matrix is singular exactly when its determinant is zero (Chamber 5). So is an eigenvalue of if and only if .
This is the characteristic equation, and (read “p of lambda”) is the characteristic polynomial. For a matrix it is worth expanding once and for all:
The coefficient is the trace (read “trace of A”), the sum of the diagonal entries, and is the determinant. So . If the roots are and , then , and matching coefficients gives two free checks:
A worked example with the lab's symmetric matrix . The trace is 4 and the determinant is 3, so and the eigenvalues are 3 and 1. For each one, find the null space of :
Those are the and lines you found in the lab. For the triangular matrix it's even quicker. is triangular, and a triangular determinant is the product of its diagonal (Chamber 5), so and the eigenvalues are simply the diagonal entries, 2 and . For , gives .
And the rotation ? Its trace is 0 and its determinant is 1, so , which has no real roots. The algebra agrees with the picture: a quarter turn leaves no direction on its own line.
The matrix has two real eigenvalues. What is the larger one?
Learn: diagonalisation and matrix powers
Put the eigen-equations for all eigenvectors side by side. Stack the eigenvectors as the columns of a matrix and the eigenvalues on the diagonal of (capital lambda). Column of is , which is also column of . So , and when is invertible:
Read it right to left, as a journey. translates a vector into eigen-coordinates. stretches each coordinate by its own eigenvalue, independently. translates back. In the right coordinates, every diagonalisable matrix is just a stretch.
The payoff is powers. Multiply two copies and the middle cancels:
Powering a diagonal matrix just powers its diagonal entries. Applying a hundred times costs no more than raising numbers to the hundredth power.
When is invertible? When the eigenvectors are independent, and there's a clean guarantee. Here is the proof for two eigenvectors; the same idea extends to any number.
Claim. If and , with and , then and are linearly independent.
Proof. Suppose . We must show . Apply to both sides. By linearity and the eigen-equations,
Multiply the original equation by instead, giving , and subtract it from the line above. The terms cancel:
Here and , so . Then the original equation reads with , so too.
The trick is worth remembering: apply to create a second equation, then combine the two to eliminate one eigenvector. So an matrix with distinct eigenvalues is always diagonalisable. With repeated eigenvalues it may not be: the shear has only one eigen-direction, and no exists.
- “capital lambda”The diagonal matrix of eigenvalues, .
- “A equals V capital lambda V inverse”Diagonalisation. The columns of are eigenvectors of . Reading right to left: change to eigen-coordinates (), stretch each coordinate (), change back ().
- “A to the k equals V capital lambda to the k V inverse”Powers of a diagonalisable matrix: the eigenvectors stay put and only the eigenvalues are raised to the -th power.
- “x k plus one equals A x k over the norm of A x k”Power iteration: multiply by and rescale, over and over. The direction converges to the eigenvector whose eigenvalue is largest in absolute value.
- “lambda one”Usually the dominant eigenvalue, the one largest in absolute value, when eigenvalues are listed by size. It controls the long-run growth of .
- “phi”The golden ratio : the dominant eigenvalue of the Fibonacci matrix.
- “P pi equals pi”(bold pi) is a stationary distribution of a Markov chain with transition matrix : an eigenvector with eigenvalue 1 whose entries are probabilities.
| Symbol | Say it | Meaning | LaTeX |
|---|---|---|---|
| “capital lambda” | The diagonal matrix of eigenvalues, . | ||
| “A equals V capital lambda V inverse” | Diagonalisation. The columns of are eigenvectors of . Reading right to left: change to eigen-coordinates (), stretch each coordinate (), change back (). | ||
| “A to the k equals V capital lambda to the k V inverse” | Powers of a diagonalisable matrix: the eigenvectors stay put and only the eigenvalues are raised to the -th power. | ||
| “x k plus one equals A x k over the norm of A x k” | Power iteration: multiply by and rescale, over and over. The direction converges to the eigenvector whose eigenvalue is largest in absolute value. | ||
| “lambda one” | Usually the dominant eigenvalue, the one largest in absolute value, when eigenvalues are listed by size. It controls the long-run growth of . | ||
| “phi” | The golden ratio : the dominant eigenvalue of the Fibonacci matrix. | ||
| “P pi equals pi” | (bold pi) is a stationary distribution of a Markov chain with transition matrix : an eigenvector with eigenvalue 1 whose entries are probabilities. |
Fibonacci from eigenvalues
Here is diagonalisation doing something that looks like magic. The Fibonacci numbers obey . Write one step as a matrix acting on a pair:
(starting from , ). The trace is 1 and the determinant is , so , with roots
That's (phi), the golden ratio, and its partner (psi). Since for both roots, you can check that is an eigenvector: . Now write the starting vector in eigen-coordinates. The difference of the two eigenvectors is , so
Applying multiplies each eigenvector by its eigenvalue times. Reading off the second entry:
This is Binet's formula: irrational numbers on the right, whole numbers on the left, for every . Because , the term dies away, so is simply the nearest integer to , and each Fibonacci number is about times the one before. The golden ratio is the growth rate, because it is the dominant eigenvalue.
Learn: power iteration
The characteristic polynomial is fine for a matrix. For the web, with billions of pages, it is hopeless: nobody can expand a determinant that size. But multiplying a vector by a matrix, even a huge sparse one, is cheap. Power iteration finds the dominant eigenvector with nothing else:
Multiply, rescale so the numbers don't blow up, repeat. Why does it work? Suppose has eigenvectors with , and the start is with . Each multiplication by multiplies each eigen-component by its eigenvalue, so
The ratio is less than 1, so the second term fades geometrically and the direction swings onto . The rescaling only changes the length, never the direction. The speed is set by the ratio: the error shrinks by a factor of about per step.
By hand, with and , skipping the rescaling:
The vectors line up with fast, because . To read off the eigenvalue, use the Rayleigh quotient , which equals exactly when is an eigenvector. At it is already , and at it is , closing in on .
import numpy as np
def power_iteration(A, x, steps=50):
for _ in range(steps):
x = A @ x
x = x / np.linalg.norm(x) # rescale: direction is all that matters
return x, (x @ A @ x) / (x @ x) # eigenvector and Rayleigh quotient
S = np.array([[2.0, 1.0], [1.0, 2.0]])
x, lam = power_iteration(S, np.array([1.0, 0.0]))
print(x.round(4), round(lam, 4)) # [0.7071 0.7071] 3.0
The Fibonacci recurrence is power iteration too. Starting from and applying over and over, the direction settles on , which is why .
Two caveats. The start must have some component along (); a random start almost surely does. And there must be a single eigenvalue of largest size: if , the vector flips back and forth for ever.
Learn: Markov chains and PageRank
A Markov chain is a system that hops between states at random, where the next hop depends only on where you are now. Its transition matrix has equal to the probability of moving to state from state , so each column is a probability distribution and sums to 1. If is the vector of probabilities of being in each state at time , one step is a matrix multiplication: . Running the chain is power iteration.
A worked example. Tomorrow is sunny with probability after a sunny day, and with probability after a rainy one:
Start on a sunny day, . Then , , , and the numbers settle down. The limit is a stationary distribution: a with (read “P pi equals pi”). That is an eigenvector with eigenvalue 1. Solving : the first row says , so , and with we get . Five days in six are sunny in the long run. The other eigenvalue is , so the chain forgets its starting day like .
Why must 1 always be an eigenvalue? Because each column of sums to 1, the row vector of ones passes through unchanged: . Transposing, , so 1 is an eigenvalue of . And and always share eigenvalues, because .
In a two-state weather model, a sunny day is followed by a sunny day with probability , and a rainy day is followed by a sunny day with probability . In the long run, what fraction of days are sunny?
PageRank is a Markov chain
Back to the formula you couldn't compute. Brin and Page describe a “random surfer” who clicks links at random and, every so often, gets bored and jumps to a random page. As the formula is written, at each step the surfer follows a random outgoing link with probability and jumps to a random page with probability . A page's PageRank measures how often the surfer is there in the long run: the stationary distribution of this chain.
Take a web of four pages: links to and , links to , links to , and links to . Build the link matrix , with when page links to page :
Column says where page 's rank goes. All four of the paper's equations at once read , and the Decoder below shows how that becomes an eigenvector equation . To compute it, just iterate: start with every rank equal to 1 and apply the formula again and again. It's power iteration, and the error shrinks by at least a factor each round.
import numpy as np
d = 0.85
M = np.array([[0, 0, 1, 0],
[0.5, 0, 0, 0],
[0.5, 1, 0, 1],
[0, 0, 0, 0]])
r = np.ones(4)
for _ in range(100):
r = (1 - d) + d * M @ r # the paper's formula, for every page at once
print(r.round(3), r.sum().round(6)) # [1.49 0.783 1.577 0.15 ] 4.0
Page wins: three pages link to it. But comes a close second with a single incoming link, because that link comes from the important page and is 's only outgoing link. Page , which nobody links to, gets only the baseline . This is exactly the intuition the paper gives: a page ranks highly if many pages point to it, or if a few highly ranked pages do.
Read beyond the course
Interactive · free online · ~15 min
Eigenvectors and Eigenvalues Explained VisuallyVictor Powell & Lewis Lehe (Setosa)
Drag a vector until it lines up with its image, then watch eigen-directions attract the sequence . It revisits this chamber's examples, Fibonacci and a two-state migration chain, as interactive pictures. The perfect ten minutes right after the lab.
Book · free online · ~60 min
Mathematics for Machine LearningMarc Peter Deisenroth, A. Aldo Faisal & Cheng Soon Ong · Sections 4.1, 4.2 and 4.4
Determinant and trace, eigenvalues and eigenvectors, then eigendecomposition and diagonalisation, with the same notation you'll meet in ML papers. Section 4.2 also proves the facts about symmetric matrices that the Chamber 9 spectral theorem builds on.
Article · free online · ~45 min
The $25,000,000,000 Eigenvector: The Linear Algebra behind GoogleKurt Bryan & Tanya Leise (SIAM Review, 2006) · Sections 1–4
Written for students who have just met eigenvectors. It builds the PageRank matrix from small example webs, shows why the damping term guarantees a unique ranking, and explains why power iteration converges. Many of the exercises can be done by hand.
Book · free online · ~40 min
Mining of Massive DatasetsJure Leskovec, Anand Rajaraman & Jeffrey D. Ullman · Chapter 5, Section 5.1 (PageRank)
The Stanford data-mining textbook's account of PageRank as an engineer sees it: dead ends, spider traps, “taxation” (their name for damping), and how the iteration is run on a graph far too big for memory.
Papers and lectures
Brin and Page's paper is long and mostly about engineering a search engine: crawling, indexing, storage. You only need a page and a half of it now. Read the abstract, then jump to Section 2.1, “PageRank: Bringing Order to the Web”, and read Sections 2.1.1 and 2.1.2 slowly. That is the formula, the sentence connecting it to “the principal eigenvector of the normalized link matrix of the web”, and the random-surfer story. Skip Sections 3 to 5 unless you're curious how a search engine was built in 1998. Appendix A is short and worth a look: the founders argue that search engines funded by advertising will be “inherently biased towards the advertisers”.
The Anatomy of a Large-Scale Hypertextual Web Search EngineSergey Brin, Lawrence Page · Computer Networks and ISDN Systems 30 (WWW7), 1998The paper that introduced Google to the research world. Its PageRank section turns the link structure of the web into an eigenvector problem.
Decode the paper · Section 2.1.1, “Description of PageRank Calculation”
The Anatomy of a Large-Scale Hypertextual Web Search EngineSergey Brin, Lawrence Page · Computer Networks and ISDN Systems 30 (WWW7), 1998
Brin and Page's definition of PageRank. It looks circular: is defined through the PageRanks of the pages linking to it, whose own definitions may involve . Match each symbol to its meaning, then see how an eigenvector breaks the circle.
Options
Watch
The first video animates exactly what you did in the lab: most vectors are knocked off their span, a few stay on it. Watch for the moment the eigenbasis turns a matrix into a diagonal one. The second derives the mean-and-product trick for eigenvalues; try each of its examples before it reveals the answer.
Your turn
Match symbols to words and to code, prove two facts, then compute: Fibonacci's growth, a frog's favourite lily pad, and the PageRank of a small web, using the paper's formula exactly as printed.
Match · Maths ↔ In words
Say what it means
Match each statement in symbols to the same statement in words.
Options
Match · Maths ↔ NumPy
From symbols to NumPy
Match each piece of mathematics to the NumPy that computes it.
Options
Proofs
Proof puzzle
Inverting a matrix inverts its eigenvalues
Claim
If is invertible and with , then and is an eigenvector of with eigenvalue .
Tap lines in the order they should appear. Not every line belongs. Tap a line in your proof to send it back.
Your proof
- Pick the first line below.
Available lines
Prove it yourself
Symmetric matrices have perpendicular eigenvectors
Claim
Let be symmetric (), with and , where . Prove that . (This is half of the spectral theorem you'll meet in Chamber 9: a symmetric matrix has an orthonormal basis of eigenvectors, so .)
Your typeset proof appears here.
Code it up
Problem 22·Warm-up
A thousand rabbits deep
The Fibonacci numbers are and . One step of the recurrence is a matrix multiplication,
and diagonalising that matrix gives Binet's formula
How many decimal digits does have?
Problem 23·Standard
Where does the frog spend its time?
A frog hops among ten lily pads numbered . Each minute, if it is on pad , it hops to pad with probability , leaps to pad with probability , and stays on pad with probability . If two of these moves land on the same pad, their probabilities add. This is a Markov chain with a transition matrix , where is the probability of moving from pad to pad , so each column sums to 1. In the long run, the fraction of minutes the frog spends on each pad is given by the stationary distribution , with and .
What fraction of the time does the frog spend on pad ? Give to 4 decimal places.
Problem 24·Challenge
Rank a tiny web
Apply Brin and Page's formula to a web of ten pages numbered . Page links to every distinct page in the set
other than itself. So page 0 links only to page 1, page 1 only to page 2, and page 2 to pages 3 and 4. Every page ends up with at least one outgoing link.
Use the formula exactly as the paper prints it, with :
where are the pages that link to and is the number of links going out of . Start with every equal to 1 and update all ten at once, repeatedly, until nothing changes.
What is the largest PageRank of the ten pages? Give it to 4 decimal places.
Key takeaways
- An eigenvector is a direction a matrix only stretches: with . The eigenvalue is the stretch factor; negative flips, zero flattens.
- Eigenvalues solve , because must be singular. For matrices, ; the eigenvalues add to the trace and multiply to the determinant.
- Diagonalisation makes a matrix a pure stretch in eigen-coordinates, so . Distinct eigenvalues guarantee it; Fibonacci's growth rate is the eigenvalue .
- Power iteration multiplies and rescales; every direction but the dominant one fades like .
- Markov chains settle into an eigenvector with eigenvalue 1, and PageRank is exactly that: the stationary distribution of a random surfer, computed by power iteration.
Checkpoint
Prove it to the labyrinth
Answer every question to clear this chamber. First-try answers earn the most XP.
Which of these is an eigenvector of ?
Why does the rotation have no real eigenvectors?
What is the product of the eigenvalues of ?
with . What is the largest eigenvalue of ?
is an eigenvalue of a square matrix exactly when…
Why can't the shear be diagonalised?
Power iteration is run on four matrices, each with the two eigenvalues listed. On which does it converge fastest?
Use Brin and Page's formula exactly as printed, , on a web of pages in which every page has at least one outgoing link. What do all the PageRanks add up to?
End of the chamber
Clear this chamber
- Questions in this chamber (0/12 solved)Next unsolved
- Bonus: Eigen hunter (+50 XP)
- Bonus: Problem 22: A thousand rabbits deep (+20 XP)
- Bonus: Problem 23: Where does the frog spend its time? (+35 XP)
- Bonus: Problem 24: Rank a tiny web (+50 XP)
- Bonus: Proof: Inverting a matrix inverts its eigenvalues (+25 XP)
- Bonus: Proof: Symmetric matrices have perpendicular eigenvectors (+40 XP)
- Bonus: Decode the paper (+30 XP)
- Bonus: Match: Say what it means (+25 XP)
- Bonus: Match: From symbols to NumPy (+25 XP)