\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage[pdftex]{graphicx}
\usepackage{url}
\usepackage{mathrsfs}
\usepackage{multicol}
\usepackage{mathdots}
 \usepackage{colortbl}
\usepackage{color}
 \definecolor{teal}{rgb}{0.5,0.8,0.8}
\usepackage{hhline}
\usepackage{hyperref}
\hypersetup{colorlinks=true}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{.25in}
\setlength{\textwidth}{6in}
\setlength{\topmargin}{-0.4in}
\setlength{\textheight}{8.5in}



\input{preamble.tex}

\begin{document}

\lecture{3: Discrete Dynamical Systems and the Internet}{Week 3}

\section{Discrete Dynamical Systems}

In many branches of mathematics, we typically consider individual objects --- the set of all prime numbers, the functions $\sin(x)$ and $\cos(x)$, a trefoil knot, the unit sphere in $\mathbb{R}^3$ --- as if they are \textbf{fixed}, i.e.\ static or unchanging.  This is often a useful abstraction to make, in that these objects are often difficult enough on their own; there is lots of interesting mathematics that we can do with a fixed knot in space without having to worry about it moving around!  So we usually assume that these objects are unchanging, and study them with this assumption.

This assumption, however, is not a great way to model the world around us.  Pretty much every object we encounter is constantly changing; materials degrade and reinforce themselves, sea levels rise and shrink, populations wax and wane.  Accordingly, you would want to model this idea of ``change'' mathematically!  The field of dynamical systems, roughly speaking, is the branch of mathematics that studies such changing objects.

Formally, we can define a \textbf{dynamical system}\footnote{Formally speaking, we think of this as a discrete dynamical system, because we have ``discretized'' time here: i.e. we have a sense in which we are advancing from a time $t$ to a time $t+1$ all at once, as opposed to smoothly increasing $t$.} as follows:
\begin{itemize}
\item An object $X$; typically something that can have a number of different states.
\item An update map $f$, that when applied to $X$ outputs a ``new'' set of states for $X$.  We think of applying $f$ to $X$ as a way to advance one time-step, for whatever notion of time-step that we're simulating; that is, in some senses we would think of $f(X)$ as denoting what $X$ will be after one second, or (for different maps $f,X$) one hour, or one year.
\end{itemize}

As with many objects in mathematics, this is best understood with an example.  
\begin{quest}
Consider the problem of modeling a population of rabbits and wolves on an island.  Suppose that we start with 4000 rabbits and 1000 wolves.  Moreover, suppose that if we have $R$ rabbits and $W$ wolves at month $t$, the number of rabbits and wolves at month $t+1$ can be written as
\begin{align*}
R_{\textrm{new}} = 2R_{\textrm{old}}  - 1W_{\textrm{old}}, \qquad W_{\textrm{new}} = R_{\textrm{old}}  + \frac12 W_{\textrm{old}}.
\end{align*}

What is the long-term behavior for our populations of rabbits and wolves?
\end{quest}
\begin{answer}
To answer this problem quickly, we use matrix\footnote{\begin{defn}
A $n \times n$ \textbf{matrix} $A$, for the purposes of this lecture, is a particular kind of function from $\mathbb{R}^n \to \mathbb{R}^n$.  A matrix is specified by giving a $n \times n$ array of elements from $\mathbb{R}$, drawn as follows:
\begin{align*}
A := \begin{bmatrix}
a_{11} & a_{12} & a_{13} & \ldots & a_{1n}\\
a_{21} & a_{22} & a_{23} & \ldots & a_{2n}\\
a_{31} & a_{32} & a_{33} & \ldots & a_{3n}\\
\vdots & \vdots & \vdots & \ddots & \vdots\\
a_{n1} & a_{n2} & a_{n3} & \ldots & a_{nn}\\
\end{bmatrix}
\end{align*}
With this array of elements specified, we can define the function $A: \mathbb{R}^n \to \mathbb{R}^n$ as follows: for any vector $\vec{v} = (v_1, v_2, \ldots v_n) \in \mathbb{R}^n$, write
\begin{align*}
A(\vec{v}) = \left( \sum_{i=1}^n a_{1i}v_i, ~\sum_{i=1}^n a_{2i}v_i,~ \sum_{i=1}^n a_{3}v_i, ~\ldots~, \sum_{i=1}^n a_{ni}v_i\right).
\end{align*}
\end{defn}
For example, the following object 
\begin{align*}
A = \begin{bmatrix} \pi & \pi & 0 \\ 0 &2 &1 \\ 1 & 3 & -21\end{bmatrix}
\end{align*}
can be thought of as a $3 \times 3$ matrix over $\mathbb{R}$, and thus is a function from $\mathbb{R}^3 \to \mathbb{R}^3$.  If we wanted to know where $A$ sends the vector $(1,2,1)$, we could just use the definition above to calculate
\begin{align*}
A((1,2,1)) &= \left( \sum_{i=1}^3 a_{1i}v_i, ~\sum_{i=1}^3 a_{2i}v_i,~ \sum_{i=1}^3 a_{3}v_i\right)\\
&=\left( \pi \cdot 1 + \pi \cdot 2 + 0 \cdot 1, 0 \cdot 1 + 2\cdot 2 + 1 \cdot 1, 1 \cdot 1 + 3 \cdot 2 + (-21) \cdot 1\right)\\
&= (3\pi, 5, -14).
\end{align*}
} notation!  Specifically, notice that we can describe our update rules as the following:

\begin{align*}
\begin{bmatrix} 2 & -1 \\ 1 & 1/2 \end{bmatrix} \cdot \begin{bmatrix}R_{\textrm{old}}  \\ W_{\textrm{old}}\end{bmatrix} = \begin{bmatrix} 2R_{\textrm{old}}  - 1W_{\textrm{old}}\\R_{\textrm{old}}  + \frac12 W_{\textrm{old}}\end{bmatrix} =  \begin{bmatrix}R_{\textrm{new}}  \\ W_{\textrm{new}}\end{bmatrix} .
\end{align*}

So, if we want to simulate our rabbit/wolf population, we can simply use this matrix to repeatedly update our population states!  We do this here:
\begin{align*}
\begin{bmatrix} 2 & -1 \\ 1 & 1/2 \end{bmatrix} \cdot \begin{bmatrix} 4000 \\ 1000 \end{bmatrix} &= \begin{bmatrix} 7000, 4500\end{bmatrix}\\
\begin{bmatrix} 2 & -1 \\ 1 & 1/2 \end{bmatrix} \cdot \begin{bmatrix} 7000, 4500\end{bmatrix} &= \begin{bmatrix} 9500, 9250\end{bmatrix}\\
\begin{bmatrix} 2 & -1 \\ 1 & 1/2 \end{bmatrix} \cdot \begin{bmatrix} 9500, 9250\end{bmatrix}&=\begin{bmatrix} 9750, 14125\end{bmatrix}\\
\begin{bmatrix} 2 & -1 \\ 1 & 1/2 \end{bmatrix} \cdot \begin{bmatrix} 9750, 14125\end{bmatrix}&=\begin{bmatrix} 5375, 16812.5\end{bmatrix}\\
\begin{bmatrix} 2 & -1 \\ 1 & 1/2 \end{bmatrix} \cdot \begin{bmatrix} 5375, 16812.5\end{bmatrix}&=\begin{bmatrix} -6062.5, 13781.3\end{bmatrix}.
\end{align*}
In other words, sometime between months 4 and 5 our rabbit population cratered to 0 (after which, presumably, our model is no longer accurate\footnote{Or there are antimatter rabbits.}.)  
\end{answer}

This is a simple example of a dynamical system.  Additionally, we've illustrated one of the key questions that we like to study for any given dynamical system:\ given a starting state along with an update rule, what does our dynamical system eventually go towards?  In this case, the rabbit population cratered (with presumably the wolf population cratering shortly thereafter;) in general, you can see how you would simulate out such a system with starting state equal to some vector $\vec{v}$ and update rule given by a matrix $A$ by just calculating $A^n\cdot \vec{v}$ for increasingly large values of $n$.

This is not the only kind of problem we like to study with dynamical systems, though!  Consider the second sort of problem:\
\begin{quest}
On a second island, we want to study the \href{http://en.wikipedia.org/wiki/Wolves_and_moose_on_Isle_Royale}{long-term behavior of wolves and moose} over time.  As before, we have a set update rule: if we have $M$ moose and $W$ wolves at month $t$, the number of moose and wolves at month $t+1$ can be written as
\begin{align*}
M_{\textrm{new}} = 4M_{\textrm{old}}  - 1W_{\textrm{old}}, \qquad W_{\textrm{new}} = 6M_{\textrm{old}}  -  W_{\textrm{old}},
\end{align*}
and we can denote this update map with a matrix $A = \begin{bmatrix} 4 & -1 \\ 6 & -1 \end{bmatrix}$.   This time, however, we're not trying to measure the long-term trajectory of some predetermined population.  Instead, we want to solve a different problem:\ suppose that we get to seed the island with our own preselected population $(M, W)$ of moose and wolves.  Can we pick $M, W$ so that our population is \textbf{stable}:\ in other words, such that $A(M,W) = (M,W)$?
\end{quest}
\begin{answer}
We can do this!  This is not too hard to do.  We simply want a solution to the equation
\begin{align*}
\begin{bmatrix} 4 & -1 \\ 6 & -1 \end{bmatrix} \cdot \begin{bmatrix} M \\ W \end{bmatrix} = \begin{bmatrix} M \\ W \end{bmatrix};
\end{align*}
in other words, by expanding the LHS, we can see that we want $M, W$ such that 
\begin{align*}
 \begin{bmatrix} 4M - W\\ 6M - W \end{bmatrix} = \begin{bmatrix} M \\ W \end{bmatrix}.
\end{align*}
In other words, we want $4M - W = M$ and $6M - W = W$; i.e.\ in both cases we want the relation $3M = W$.  So any population that has this proportion (three wolves for each moose) is a stable population!
\end{answer}

The above sort of problem --- where we have a matrix $A$ and want to find a vector $\vec{v}$ such that $A\vec{v} = \vec{v}$ --- is one of the (many) reason we care about \textbf{eigenvectors} and \textbf{eigenvalues}!  If you haven't seen them before, here's a definition:
\begin{defn}
Let $A$ be a $n \times n$ matrix over $\mathbb{R}$.  We say that $\vec{v} \in F^n$ is an \textbf{eigenvector} and $\lambda \in F$ is an \textbf{eigenvalue} if
\begin{align*}
A \vec{v} = \lambda \vec{v}.
\end{align*}
We usually ask that $\vec{v} \neq \vec{0}$, to avoid silly trivial cases.
\end{defn}

So, in the example above, a \textbf{stable state} was precisely an eigenvector with eigenvalue 1!  Studying eigenvectors and eigenvalues is something you'll do a lot more of in Math 4a/108a-b; instead, I want to talk about one more problem that relates the dynamical systems concepts we've talked about to an area of modern research!


\section{The Googles}

Basically, before Google came along, web search engines were \textbf{atrocious}; many search results were not very-sophisticated massive keyword-bashes plus some well-meaning but dumb attempts to improve these results by hand.  In the 90's, Brin and Page (the two founders of Google) came onto the scene, with the following simple idea:
\begin{center}
\textit{Important websites are the websites other important websites link to}.
\end{center}

This seems kinda circular, so let's try framing this in more of a graph-theoretic framework: Take the internet.  Think of it as a collection of webpages, which we'll think of as ``vertices,'' along with a collection of hyperlinks, which we'll think of as directed lines\footnote{A  ``series of tubes,'' if you will.} going between webpages.  Call these webpages $\{v_1,\ldots v_n\}$ for shorthand, and denote the collection of webpages linking to some $v_i$ as the set $\textrm{LinksTo}(v_i)$.

In this sense, if we have some quantity of ``importance'' $rank(v_i)$ that we're associating to each webpage $i$, we still want it to obey the entire ``important websites are the websites other important websites link to'' idea.  However, we can refine what we mean by this a little bit.  For example, suppose that we know a website is linked to by Google.  On one hand, this might seem important --- Google is an important website, after all! --- but on the other hand, this isn't actually that relevant, because Google basically links to \textbf{everything.} So we don't want to simply say something is important if it's linked to by something important --- we want to \textbf{weight} that importance by how many \textbf{other} things that important website links to!  In other words, if you're somehow important and also only link to a few things, we want to take those links very seriously --- i.e. if something is linked to by the front page of the New York Times or the Guardian, that's probably pretty important!

If we write this down with symbols and formulae, we get the following equation:
\begin{align*}
\textrm{rank}(v_i) = \sum_{v_j \in \textrm{LinksTo}(v_i)} \frac{\textrm{rank}(v_j)}{\textrm{number of links leaving}(v_j)}.
\end{align*}
In other words, to find your rank, we add up all of the ranks of the webpages that link to you, scaling each of those links by the number of other links leaving those webpages.
This is \ldots still circular.  But it looks mathier!  Also, it's more promising from a linear-algebra point of view.  Suppose that we don't think of each ranking individually, but rather take them all together as some large rank vector $\vec{r} = (\textrm{rank}(v_1) , \ldots\textrm{rank}(v_n) )$.  

As well, instead of thinking of the links one-by-one, consider the following $n \times n$ ``link-matrix'' $A$, formed by doing the following:
\begin{itemize}
\item If there is a link to $v_i$ from $v_j$, put a $\frac{1}{\textrm{number of links leaving}(v_j)}$ in the entry $(i,j)$.
\item Otherwise, put a 0.
\end{itemize}
This contains all of the information about the internet's links, in one handy $n \times n$ matrix!

Now, notice that if we multiply this matrix $A$ by our rank vector $\vec{r}$, we get
\begin{align*}
A \cdot \vec{r} = \begin{bmatrix}   \sum_{v_j \in \textrm{LinksTo}(v_1)} \frac{\textrm{rank}(v_j)}{\textrm{number of links leaving}(v_j)} \\ 
\sum_{v_j \in \textrm{LinksTo}(v_2)} \frac{\textrm{rank}(v_j)}{\textrm{number of links leaving}(v_j)} \\
\vdots \\
\sum_{v_j \in \textrm{LinksTo}(v_n)} \frac{\textrm{rank}(v_j)}{\textrm{number of links leaving}(v_j)} \\\end{bmatrix}.
\end{align*}
In other words, if we the ``mathy'' version of the importance rule we derived earlier, we have
\begin{align*}
A \cdot \vec{r} = \vec{r}.
\end{align*}
In other words, the vector $\vec{r}$ that we're looking for is an \textbf{eigenvector} for $A$, corresponding to the eigenvalue 1! The entries in this eigenvector then correspond to the ``importance'' ranks we were looking for.  In particular, the coordinate in the vector $\vec{r}$ with the highest value corresponds to the ``most important'' website, and should be the first page suggested by the search engine.

Up to tweaks and small modifications, this is precisely how search works nowadays; people come up with quick and efficient ways to find eigenvectors for subgraphs of the internet that correspond to the eigenvalue 1.  (Actually finding this eigenvector in an efficient manner is a problem people are still working on; much of modern search is a study for ``better/faster'' ways to find this eigenvector!)
\end{document}






























