\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage{verbatim}
\usepackage[pdftex]{graphicx}
\usepackage{url}
\usepackage[table]{xcolor}
\usepackage{multicol}
\usepackage[all,arc]{xy}
\usepackage{color, colortbl}
\usepackage{mathrsfs}
\usepackage{hyperref}
\hypersetup{colorlinks=true}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{.25in}
\setlength{\textwidth}{6in}
\setlength{\topmargin}{-0.4in}
\setlength{\textheight}{8.5in}


\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}

\newcommand\Ground{%
\mathord{\text{\begin{tikzpicture}[circuit ee IEC,yscale=0.6,xscale=0.5]
\draw (0,0) to [ground={pos=1}] +(0,-2ex);
\end{tikzpicture}}}%
}

\input{preamble.tex}

\begin{document}

\lecture{5: Electrical Networks and Random Walks I}{Week 5}

Consider the following problem:

\begin{problem}
(The Lost Hedgehog's Walk.)  Oh nyo!  A hedgehog has gotten lost in the fog.  Will it ever come home?

Specifically: consider the following model for a lost hedgehog's very simplified map of the universe: 
\begin{center}
\includegraphics[width=3in]{math137b_s2014_randomwalk1.pdf}
\end{center}
There are in this world four possible locations: $H$, the hedgehog's camp, $B$, an all-devouring black hole that absorbs everything that accidentally wanders into it, and two intermediate locations $x$ and $y$.  Lost hedgehogs, left to its own devices, will randomly wander between these locations.  Specifically: if it is at some vertex that is neither $H$ nor $B$ at time $t$, at time $t+1$ it will choose via coinflip one of the neighboring vertices to its current location and wander there. If the hedgehog ever makes it home (i.e. wanders to $H$,) it is safe and is merrily reunited with its family.  If it wanders to $B$, it is sucked into the black hole and never will be seen again.

Suppose the lost hedgehog starts at $x$.  What are the hedgehog's chances of making it home?  How can we model these kinds of behaviors?
\end{problem}
\section{Random Walks}
For a model as simple as this one, it's remarkably simple to determine what happens!  Specifically, let's consider the hedgehog's chances of making it home starting from \textbf{any} vertex $v$, not just $x$: for notational convenience, denote this probability as $p(v)$.  What do we know about these values?
\begin{itemize}
\item $p(H) = 1$: if the hedgehog starts at home, it's happy and safe!
\item $p(B) = 0$: if we've accidentally left the hedgehog inside of the black hole, we're not going to see it anytime soon.
\item For $v \neq H,B,$ we have $p(x) = \frac{1}{2} p(H) + \frac{1}{2} p(y),$ and $p(y) = \frac12 p(x) + \frac12 p(B)$.  This is because a hedgehog at any vertex that's neither home or the black hole will choose between the two neighbors available to it with the same probability (1/2), and then travel to that respective vertex via that edge.  So, its chances of survival are $\frac{1}{2} \cdot$ its chances at the vertex to its left, plus $\frac{1}{2} \cdot$ its chances at the vertex to its right.
\end{itemize}
This gives us the following four linear equations in four unknowns:
\begin{multicols}{2}
\begin{itemize}
\item $p(B) = 0$,
\item $p(x) = \frac{p(H) + p(y)}{2}$,
\item $p(H) = 1$,
\item $p(y) = \frac{p(x) + p(B)}{2}$,
\end{itemize}
\end{multicols}
Solving this system tells you that $p(2) = \frac13, p(3) = \frac23$, and thus that our specific hedgehog at vertex $x$ has a $2/3$rds chance of making it home.  

Let's consider a trickier version of the above problem.  Suppose that instead of just a four-vertex path, we have some graph $G$ that we want to model a hedgehog's walk on, with selected vertices $H$ and $B$ that denote the hedgehog's home / a point of no return, respectively; this lets us model things like city blocks.  Also, let's attach weights $w_{xy}$ to every edge in our graph, that denote the likelihood that our hedgehog will pick that edge over the other edges available to it; this lets us distinguish between things like clean, well-light main streets and sketchy alleyways.

Under this model, if we still let $p(x)$ denote the probability that from $x$ we make it to $H$ before reaching $B$, we have the following system:
\begin{itemize}
\item $p(H) = 1$.
\item $p(B) = 0$.
\item For $x \neq H,B,$ we have 
\begin{align*}
p(x) = \sum_{y \in \textrm{(neighbors of }x)} p(y) \cdot \frac{w_{xy}}{w_x},
\end{align*}
where $w_x$ is the sum of all of the weights of edges leaving $x$:
\begin{align*}
w_x = \sum_{y \in \textrm{(neighbors of }x)} w_{xy}
\end{align*}
 This is because a hedgehog at any vertex that's neither home or the black hole will choose between the neighbors available to it with probabilities weighted by the values $w_{xy}$: i.e. the probability that we travel to a neighbor $y$ is just $w_{xy}/w_x$, the weight of the edge from $x$ to $y$ divided by the sum of the weights of all of the possible edges leaving $x$.  Therefore, our probability $p(x)$ of making it to home before the black hole is just the \textbf{weighted average} over all of $x$'s neighbors of the same event!  
\end{itemize}

To illustrate this idea, we calculate a second example:

\begin{problem}
(The Hedgehog's Walk.)  Consider the following second map for a hedgehog's walk:
\begin{center}
\includegraphics[width=3in]{math137b_s2014_randomwalk2.pdf}
\end{center}
There are in this world six possible locations: $H$, the hedgehog's home, $B$, a black hole, and four intermediate locations $a,b,c,d$, with weighted links between them as labeled.  Suppose that a hedgehog starts off at one of these four locations.  How likely are they to make it to the vertex $H$ before the vertex $B$?
\end{problem}

As noted above, we can turn this into a system of six linear equations in six unknowns:
\begin{multicols}{2}
\begin{itemize}
\item $p(B) = 0$,
\item $p(a) = \frac12p(H) + \frac12p(b)$,
\item $p(c) = \frac14p(H) + \frac14p(a) + \frac12p(d)$,
\item $p(H) = 1$,
\item $p(b) = \frac12p(a) + \frac14p(c) + \frac14p(B)$,
\item $p(d) = \frac12p(c) + \frac12p(B)$.
\end{itemize}
\end{multicols}

Again, we can just solve these equations by your favorite method of dealing with systems of linear equations, to get
\begin{align*}
p(a) = \frac{12}{19}, p(b) = \frac{5}{19}, p(c) = \frac{8}{19}, p(d) = \frac{4}{19}.
\end{align*}


Excellent!  We have a general method for solving a problem.  Let's put that aside for a second and consider a second problem that might seem unrelated at first:


\section{Electrical Networks}

We're going to talk about electrical circuits and networks here for a bit!  If you've never ran into the concepts of voltage, current, conductance, or resistance before, that's OK.  For our purposes, define these concepts as follows:
\begin{enumerate}
\item  Voltage is just some function $v: V(G) \to \mathbb{R}^+$ that assigns a positive number $v(x)$ to each vertex x.  In any circuit, we will have some vertex that is grounded; this vertex has $v(ground) = 0$.  Similarly, we will declare that some source vertex has a potential difference of $1v$  from ground assigned to it: this vertex has $v(source) = 1$.
\item Current is just another function $i: E(G)^+ \to \mathbb{R}$ that assigns a number to each ``oriented edge'' $(x,y) \in E(G)^+$.  We will usually denote the resistance of an edge as $i_{xy}$.  We ask that $i_{xy} = -i_{yx}$, which is why we have the current pay attention to the orientation of edges: we want the flow of current in one direction on an edge to be $-1 \cdot$ the flow of current in the opposite direction.
\item Resistance is a function $E(G) \to \mathbb{R}^+$ that assigns a positive number (measured in ohms, $\Omega$) to each unoriented edge $\{x,y\} \in E(G)$.  We usually denote the resistance of an edge as $R_{xy}$.
\end{enumerate}
We ask that these functions preserve the following two properties:
\begin{itemize}
\item (Ohm's law:)  The current  across an edge $\{x,y\}$ in the direction $(x,y)$, $i_{xy}$, satisfies
\begin{align*}
i_{xy} =  \frac{v(x) - v(y)}{R_{xy}},
\end{align*}
where $v(x), v(y)$ are the voltages at $x,y$ and $R_{xy}$ is the resistance of the edge $\{x,y\}$.
\item (Kirchoff's law:)  The sum of the currents into and out of any vertex other than the grounded vertex or the ``source'' vertex is zero: i.e. for any vertex neither grounded nor hooked up to power, we have
\begin{align*}
\sum_{y \in N(x)} i_{xy} = 0.
\end{align*}
\end{itemize}
For convenience's sake, we will also define the \textbf{conductance} of an edge $\{x,y\}$ as the reciprocal of its resistance: i.e. $C_{xy} = 1/R_{xy}$, and define the conductance of a vertex $x$ as the sum of the conductances of the edges leaving it: i.e. $C_x = \sum_{y \in N(x)} C_{xy}$.


With these definitions made, the following problem is a fairly natural one to consider.  
\begin{problem}
Suppose that we have an \textbf{electrical circuit}: i.e. a graph $G$ with the following structure:
\begin{itemize}
\item The values $R_{xy}$ have been defined for every edge.
\item Some vertex $G$ has been declared to be grounded, while another vertex $S$ has been declared to be a ``source'' with a potential difference of $1v$ from ground.
\end{itemize}
Can we find $v(x)$ for every vertex in our graph?
\end{problem}

We start by considering basically the first graph we studied in this lecture, $P_4$:
\begin{center}
\includegraphics[width=3in]{math137b_s2014_ee1.pdf}
\end{center}
Specifically: we have taken the graph $P_4$ we studied in our first example of random walks, and turned it into a circuit as follows:
\begin{enumerate}
\item We replaced all of $P_4$'s edges with resistors of unit resistance 1.
\item We grounded the vertex $G$, and created a potential difference of 1v across the vertices $G$ and $S$.
\end{enumerate}
The decorations on the graph above denote this transformation: i.e.\ attaching a vertex to $\Ground$ denotes that it is the ground vertex, \includegraphics[width=.3in]{math137b_s2014_potential.pdf} tells us that the vertex on the other side of this symbol from ground is a source vertex with a potential of some number of volts defined on it, \includegraphics[width=.3in]{math137b_s2014_resistor.pdf} tells us that an edge is a resistor with the labeled resistance, etc.

In this setup, what happens?  Well: we have that $v(G) = 0$, $v(S) = 1$, and for any vertex $v$ not $G$ or $S$, 
\begin{align*}
\sum_{y \in N(v)} i_{vy} = 0;
\end{align*}
i.e. for vertex $x$, we have
\begin{align*}
0 = \sum_{y \in N(x)} i_{x,y}  = i_{xS} + i_{xy} &= \frac{v(x) - v(S)}{R_{xS}} + \frac{v(x) - v(y)}{R_{xy}}\\
 & = v(x) - v(S) +v(x) - v(y),\\
\end{align*}
which implies that $v(x) = \frac{v(S) + v(y)}{2}$; similarly, we can derive that $v(y) = \frac{v(x) + v(G)}{2}$.  In other words, to find the voltages at the vertices $x,y$ we're solving the same equations we did for our hedgehog's walk earlier: i.e. $v(x)$ is $2/3$, the probability that a hedgehog walking on our graph starting from $x$ will make it to vertex $S$ before vertex $G$!

\section{Electrons Are Hedgehogs}
Surprisingly, this property above -- that our random walk and electrical network were, in some sense, the ``same'' -- holds for all graphs!  We state this formally in the following theorem:

\begin{thm}
Suppose that we have a connected graph $G$ with edges weighted by some labeling $w_{xy}$.  Define a \textbf{hedgehog's walk} starting at a vertex $x$ in our graph as the following process:
\begin{itemize}
\item Initially, the hedgehog starts at $x$.
\item Every minute, if a hedgehog is at some vertex $z$, it randomly chooses one of the elements $y \in N(z)$ with probability  given by the weights on its edges-- i.e. each neighbor has probability $w_{zy}/w_z$ of being picked -- and goes to that vertex.
\end{itemize}
Let $a, b$ be a pair of distinguished vertices in our graph, and $p(x)$ be the probability that a hedgehog starting at the vertex $x$ will make it to vertex $b$ before vertex $a$.  

Then $p(x) = v(x)$, if we turn our graph $G$ into a electrical network with $a$ connected to ground, a unit of electrical potential sent across $a$ and $b$, and replace every edge $\{x,y\}$ of $G$ with a resistor with conductance $w_{xy}$.
\end{thm}

In class, we skipped the proof of this theorem to just work with its consequences! 

In particular: this correspondence means that we've turned a problem in mathematics --- random walks --- into a problem in physics, electrical circuits!  This means that to solve our mathematical problem, we can use tools physicists have developed to solve their own problems; something that should make our work a lot easier!  We list some of those ideas in the next section:


\section{Circuits as Black Boxes}

Suppose that we have a circuit with two points $S, G$, where we've grounded $G$ and have a voltage of $1v$ established at $S$.  If you have done this, then there is some amount of current flowing out of $S$.  Denote this quantity as $i_S$, and note that $i_S$ is given by the sum $\sum_{x \in N(S)} i_{Sx}$.  Note that by Kirchoff's laws, the quantity of current that flows out of $S$ is the same as the quantity of current that flows into $G$, because the sum of the currents through every vertex not $S$, $B$ is equal to 0, and therefore whatever flows out of $S$ must eventually flow into $G$.

Now, imagine simply covering up all of the connections and other bits between $S$ and $G$ with some sort of big black box.  If we do this, then our circuit just looks like the following:
\begin{center}
\includegraphics[width=2in]{math137b_s2014_eeblackbox.pdf}
\end{center}

In this sense, we can simply ``abstract'' the rest of our circuit as some particularly large and bulky resistor, with effective resistance (which we denote $R_{\textrm{eff}}$) defined by Ohm's law:
\begin{align*}
\frac{V(S) - V(G)}{i_A} = R_{\textrm{eff}}
\end{align*}
Similarly, we can define $C_{\textrm{eff}} = 1/R_{\textrm{eff}}$.  

This is a useful concept!  In particular, this lets us ``simplify'' electrical networks (and their corresponding random walks) by replacing large chunks of complicated circuits with much simpler circuits.  

For example, look at the following structure:
\begin{center}
\includegraphics[width=2in]{resistors_parallel.pdf}
\end{center}
In this picture, the effective resistance of the circuit above is the reciprocal of the sum of the reciprocals of the resistors:
\begin{align*}
\frac{1}{R_{\textrm{eff}}} = \sum_{i=1}^n \frac{1}{R_i}.
\end{align*}
Alternately, you can think of this claim as the statement that the ``effective conductance'' of the circuit is the sum of the conductances of the circuit.

Similarly, suppose we have a circuit made of resistors linked in series, as depicted below:
\begin{center}
\includegraphics[width=2in]{resistors_series.pdf}
\end{center}
Then the effective resistance of the circuit above is the sum of the resistors:
\begin{align*}
R_{\textrm{eff}} = \sum_{i=1}^n R_i.
\end{align*}

So: if you have a circuit with a chain of resistors in series, you can replace that chain with one single resistor with resistance $R_{\textrm{eff}}$.  This process doesn't change the currents in our circuit, by construction, nor the resistances on anything we're not replacing with $R_{\textrm{eff}}$.  As a consequence, the voltages also don't change (as they're defined by Ohm's law in terms of resistance and current!)  

Consequently, the corresponding random walk can be simplified in the same way!  This is really useful, and makes our lives great.

\end{document}