Repository navigation
Markov Chains
The game of Monopoly is the worst board game ever. After you go around the board a couple times, everyone knows who's going to win. Then you have a 2.5 hour slow bleed to get to the inevitable finish, punctuated with various fights between family members.
Here's another thing about Monopoly...the probabilities for any individual turn (where your little top hat will end up) depend only on your current location. It doesn't matter where I was last turn; it only matters where I am now. This is the defining characteristic of a technique in probability called Markov Chains.
Applications of Markov Chains go well beyond board games. This is one of the engines that allow us to search the internet! Let's look into it.
We will start with a few definitions:
Definition: A probability vector is a vector of nonnegative entries that all add up to 1.
Definition: A stochastic matrix is a square matrix whose columns are all probability vectors.
Note
Stochastic just means "random".
Definition: A Markov Chain is a sequence of probability vectors generated by a stochastic matrix
$\large P$ :
Note
We see that we are computing
Note
It is a fact that if
Markov chains are used to model probabilities in dynamic situations where the probability of an event depends only on the current state. Here are two small examples:
We will make a simple model. If today is sunny, there's a 90% chance that tomorrow will be sunny (leaving a 10% chance that tomorrow will be rainy). If today is rainy, there's a 50% chance that tomorrow will be rainy too. We can visualize this chain with the following graph:
Our stochastic matrix is:
Note that each column is a probability vector (it adds up to 1).
Markov himself chose 20,000 letters from a Russian novel (Alexander Pushkin's Yevgeniy Onegin). He counted how many vowels were followed by a consonant and how many consonants were followed by vowels. He arrived at the following stochastic matrix:
The first column includes the probability that a vowel is followed by another vowel (0.128) or a consonant (0.872). The second gives the probability that a consonant is followed by another consonant (0.663) or by a vowel (0.337).
Let's use the weather example above and actually build a Markov Chain. Let's start with a 50/50 split:
If we iterate, we'll get the following chain:
We see that the process is converging to something. There appears to be a limit involved in these iterations. Just to make sure, let's really ramp it up:
Definition: This process will often (not always!) have a limit:
$\large \displaystyle \lim_{k\to\infty}\vec{x}_k=\vec{q}$ . When the limit does exist, we call it a steady state vector or equilibrium vector. The equilibrium vector is characterized by the equation$\large P\vec{q}=\vec{q}$ .
Note
The equation for the equilibrium vector is an eigenvector equation with eigenvalue 1. It is a fact that any stochastic matrix has
Note
What does it mean for
Now that we know the steady state probability vector is an eigenvector with
Warning
In the video, we are reminded that our process of finding an eigenvector doesn't naturally generate probability vectors. We normalize the vector to make sure the terms add up to 1.
We've seen that we can find the steady state as the eigenvector of
We see that if we raise
Perhaps the most impactful application of Markov Chains in the Google PageRank algorithm. This is the algorithm that decides how to rank the millions of pages that turn up when we put "Linear Algebra" in the search bar. We really wouldn't have a useful internet without it, and we'll see a very simplified version here.
Consider a small internet consisting of 7 pages as shown:
The 7 pages are labeled, and the arrows indicate links between pages. We see, for example, that Page 2 contains links to Page 1 and to Page 5. Page 4 is linked to only by Page 3, and it doesn't have any outgoing links. We can turn this into a stochastic matrix, where
Two problems arise if we try to just use
- The "dead end" pages (Pages 4 and 7 have no outgoing links) are a problem mathematically - these columns are not probability vectors! We replace them with even odds to all pages: a column of all
$\large 1/7$ (or$\large 1/n$ if there are$\large n$ web pages). - It's possible to have little disconnected islands of pages. To fix this, Google defines the "Google Matrix"
$\large G$ :
where
Note
The Google Matrix is huge, where each column has over a billion entries.
If we choose
If we raise this to a large power, we get the following, which contains the steady state probability vector in each column:
We see that every column is the same, as expected. The steady state vector gives us our ranking. The pages, in order, are: 3, 2 and 6 (tied), 5, 1, 4, 7.
Note
As mentioned, we've outlined the basic idea of PageRank. Google has added much to this since it was invented in 1996. Some of the additions include a way to weigh links differently if they get clicked more often, anti-spam efforts, and the addition of both AI outputs and advertised pages among the displayed results.
I can:
- Identify probability vectors and stochastic matrices.
- Generate a Markov chain from a stochastic matrix.
- Find the steady state probability vector for a stochastic matrix (either by finding eigenvectors or by raising
$\large P$ to a large power). - Interpret steady state vectors probabilistically.