\documentclass[a4paper]{article}
\oddsidemargin 2.1mm
\textwidth     155mm
\topmargin     -12mm
\textheight    230mm

\def\tabstrut{\rule{0pt}{2.4ex}}
\def\eq{\!\!\!=\!\!\!}

\begin{document}

\subsection*{The Normalized $\chi^2$ Measure
             for Association Rule Evaluation}

Let $C$ and $A$ be two attributes with domains
$\mbox{dom}(A) = \{ a_1, \ldots a_{n_A} \}$ and
$\mbox{dom}(C) = \{ c_1, \ldots c_{n_C} \}$, respectively,
and let $\cal X$ be a dataset over $C$ and $A$.
Let $N_{ij}$, $1 \le i \le n_C$, $1 \le j \le n_A$, be the number of
sample cases in $\cal X$, which contain both the attribute values~$c_i$
and $a_j$. Furthermore, let
\[ N_{i.} = \sum_{j=1}^{n_A} N_{ij}, \qquad
   N_{.j} = \sum_{i=1}^{n_C} N_{ij}, \qquad\mbox{and}\qquad
   N_{..} = \sum_{i=1}^{n_C} \sum_{j=1}^{n_A} N_{ij} = |{\cal X}|. \]
Finally, let
\[ p_{i.} = \frac{N_{i.}}{N_{..}}, \qquad
   p_{.j} = \frac{N_{.j}}{N_{..}}, \qquad\mbox{and}\qquad
   p_{ij} = \frac{N_{ij}}{N_{..}} \]
be the probabilities of the attribute values and their combinations,
as they can be estimated from these numbers. Then the well-known
$\chi^2$ measure is usually defined as
\begin{eqnarray*}
\chi^2(C,A)
& = & \sum_{i=1}^{n_C} \sum_{j=1}^{n_A}
      \frac{(E_{ij} -N_{ij})^2}{E_{ij}}
      \qquad\mbox{where}\quad E_{ij} = \frac{N_{i.}N_{.j}}{N_{..}} \\
& = & \sum_{i=1}^{n_C} \sum_{j=1}^{n_A}
      \frac{\left(\frac{N_{i.}N_{.j}}{N_{..}} -N_{ij}\right)^2}
           {\frac{N_{i.}N_{.j}}{N_{..}}}
~~=~~ \sum_{i=1}^{n_C} \sum_{j=1}^{n_A}
      \frac{N_{..}^2 \left(\frac{N_{i.\phantom{j}}}{N_{..}}
                           \frac{N_{.j}}{N_{..}}
                         - \frac{N_{ij}}{N_{..}}\right)^2}
           {N_{..}\;       \frac{N_{i.\phantom{j}}}{N_{..}}
                           \frac{N_{.j}}{N_{..}}} \\
& = & N_{..} \sum_{i=1}^{n_C} \sum_{j=1}^{n_A}
      \frac{(p_{i.}\;p_{.j} - p_{ij})^2}{p_{i.}\;p_{.j}}
~~=~~ N_{..} \sum_{i=1}^{n_C} \sum_{j=1}^{n_A}
      \frac{(N_{i.}\;N_{.j} - N_{..}N_{ij})^2}{N_{i.}\;N_{.j}}.
\end{eqnarray*}
This measure is often normalized by dividing it by the
size~$N_{..} = |{\cal X}|$ of the dataset to remove the
dependence on the number of sample cases.

For association rule evaluation, $C$ refers the consequent and $A$ to
the antecedent of the rule. Both have two values, which we denote by
$c_0$, $c_1$ and $a_0$, $a_1$, respectively. $c_0$ means that the
consequent of the rule is not satisfied, $c_1$ that it is satisfied;
likewise for $A$. Then we have to compute the $\chi^2$ measure from
the $2 \times 2$ contingency table
\begin{center}
\begin{tabular}{|l|c|c|l|} \cline{2-3}
\multicolumn{1}{l|}{}
      & $a_0$    & $a_1$    \\ \hline
$c_0$ & $N_{00}$ & $N_{01}$ & $N_{0.}$\tabstrut \\ \hline
$c_1$ & $N_{10}$ & $N_{11}$ & $N_{1.}$\tabstrut \\ \hline
\multicolumn{1}{l|}{}
      & $N_{.0}$ & $N_{.1}$ & $N_{..}$\tabstrut \\ \cline{2-4}
\end{tabular}
\end{center}
or the estimated probability table
\begin{center}
\begin{tabular}{|l|c|c|l|} \cline{2-3}
\multicolumn{1}{l|}{}
      & $a_0$    & $a_1$    \\ \hline
$c_0$ & $p_{00}$ & $p_{01}$ & $p_{0.}$\tabstrut \\ \hline
$c_1$ & $p_{10}$ & $p_{11}$ & $p_{1.}$\tabstrut \\ \hline
\multicolumn{1}{l|}{}
      & $p_{.0}$ & $p_{.1}$ & $1$\tabstrut \\ \cline{2-4}
\end{tabular}
\end{center}
That is, we have
\begin{eqnarray*}
\frac{\chi^2(C,A)}{N_{..}}
& = & \sum_{i=0}^1 \sum_{j=0}^1
      \frac{(p_{i.}\;p_{.j} - p_{ij})^2}{p_{i.}\;p_{.j}}. \\
& = & \frac{(p_{0.}\;p_{.0} -p_{00})^2}{p_{0.}\;p_{.0}}
  +   \frac{(p_{0.}\;p_{.1} -p_{01})^2}{p_{0.}\;p_{.1}}
  +   \frac{(p_{1.}\;p_{.0} -p_{10})^2}{p_{1.}\;p_{.0}}
  +   \frac{(p_{1.}\;p_{.1} -p_{11})^2}{p_{1.}\;p_{.1}}
\end{eqnarray*}
Now we can exploit
\[ p_{00} + p_{01} = p_{0.}, \quad
   p_{10} + p_{10} = p_{1.}, \quad
   p_{00} + p_{10} = p_{.0}, \quad
   p_{01} + p_{11} = p_{.1}, \quad
   p_{0.} + p_{1.} = 1, \quad
   p_{.0} + p_{.1} = 1, \]
which leads to
\begin{eqnarray*}
p_{0.}\;p_{.0} -p_{00}
& = & (1 -p_{1.})(1 -p_{.1}) -(1 -p_{1.} -p_{.1} +p_{11})
~~=~~ p_{1.}\;p_{.1} -p_{11}, \\
p_{0.}\;p_{.1} -p_{01}
& = & (1 -p_{1.})p_{.1} -(p_{.1} -p_{11})
~~=~~ p_{11} -p_{1.}\;p_{.1}, \\
p_{1.}\;p_{.0} -p_{10}
& = & p_{1.}(1 -p_{.1}) -(p_{1.} -p_{11})
~~=~~ p_{11} -p_{1.}\;p_{.1}. \\
\end{eqnarray*}
Therefore it is
\begin{eqnarray*}
\frac{\chi^2(C,A)}{N_{..}}
& = & \frac{(p_{1.}\;p_{.1} -p_{11})^2}{(1 -p_{1.})(1 -p_{.1})}
  +   \frac{(p_{1.}\;p_{.1} -p_{11})^2}{(1 -p_{1.})\;p_{.1}}
  +   \frac{(p_{1.}\;p_{.1} -p_{11})^2}{p_{1.}(1 -p_{.1})}
  +   \frac{(p_{1.}\;p_{.1} -p_{11})^2}{p_{1.}\;p_{.1}} \\
& = & \frac{(p_{1.}\;p_{.1} -p_{11})^2
            (p_{1.}\;p_{.1}
            +p_{1.}(1 -p_{.1})
            +(1 -p_{1.})p_{.1}
            +(1 -p_{1.})(1 -p_{.1}))}
           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})} \\
& = & \frac{(p_{1.}\;p_{.1} -p_{11})^2
            (p_{1.}\;p_{.1}
            +p_{1.} -p_{1.}\;p_{.1}
            +p_{.1} -p_{1.}\;p_{.1}
            +1 -p_{1.} -p_{.1} +p_{1.}\;p_{.1})}
           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})} \\
& = & \frac{(p_{1.}\;p_{.1} -p_{11})^2}
           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})}.
\end{eqnarray*}
In the program, $p_{1.}$ (argument {\tt head}), $p_{.1}$
(argument {\tt body}) and $p_{1|1} = \frac{p_{11}}{p_{.1}}$
(argument {\tt post}, rule confidence) are passed to the routine
that computes the measure, so the actual computation is
\begin{eqnarray*}
\frac{\chi^2(C,A)}{N_{..}}
& = & \frac{(p_{1.}\;p_{.1} -p_{1|1}\;p_{.1})^2}
           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})}.
~~=~~ \frac{((p_{1.} -p_{1|1})p_{.1})^2}
           {p_{1.}(1 -p_{1.})p_{.1}(1 -p_{.1})}.
\end{eqnarray*}
In an analogous way the measure can also be computed from the absolute
frequencies $N_{ij}$, $N_{i.}$, $N_{.j}$ and $N_{..}$, namely as
\begin{eqnarray*}
\frac{\chi^2(C,A)}{N_{..}}
& = & \frac{(N_{1.}N_{.1} -N_{..}N_{11})^2}
           {N_{1.}(N_{..} -N_{1.})N_{.1}(N_{..} -N_{.1})}.
\end{eqnarray*}
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\title{Soil Carbon Models}
\date{11/21/2016}
\begin{document}
\maketitle
\section*{Century Model}
The flow diagram for the century model proposed by Parton et al. (1988) is shown in Figure 1. In this document, we re-write the model in terms of a set of differential equations. In this model, we have 5 pools, each with a different turnover times:
\begin{itemize}
\item[pool 1:] \makebox[2.5cm]{Structural C,\hfill}  $\kappa_1 \approx 1/3$,
\item[pool 2:] \makebox[2.5cm]{Metabolic C,\hfill} $\kappa_2 \approx 1/0.5$,
\item[pool 3:] \makebox[2.5cm]{Active Soil C,\hfill}  $\kappa_3 \approx 1/1.5$,
\item[pool 4:] \makebox[2.5cm]{Slow Soil C,\hfill} $\kappa_4 \approx 1/25$,
\item[pool 5:] \makebox[2.5cm]{Passive Soil C,\hfill}  $\kappa_5 \approx 1/1000$,
\end{itemize}
where $\kappa$ denotes the decay rate which is defined as 1 over the turnover.

We denote the transfer rate from pool $j$ to pool $i$ by $r_{ij}$. The transfer rates are parameterized as a ratio of the decay rate: $r_{ij} = \alpha_{ij} \kappa_j$. From Figure 1, we have:
\begin{align*}
\alpha_{31} & =  (1-\text{A})(1-0.45 \times \text{SL} - 0.55 \times \text{BL}), \\
\alpha_{41} & =  0.7 \times \text{A}, \\
\alpha_{32} & = 0.45, \\
\alpha_{43} & = 1 - F(\text{T}) - 0.004, \\
\alpha_{53} & = 0.004, \\
\alpha_{34} & = 0.42, \\
\alpha_{54} & = 0.03, \\
\alpha_{35} & = 0.45,
\end{align*}
where `SL' is the surface litter, `BL' is the soil litter, `A' is the Lignin fraction, `T' is the soil silt + clay content, and $F(\text{T}) = 0.85 - 0.68 \times \text{T}$. The rest of the transfer coefficients are zero.

For each pool, we can write the following differential equation:
\begin{equation*}
\frac{d C_i(t)}{dt} = I_i(t) -\kappa_i C_i(t) + \sum_{j\neq i} \alpha_{ij} \kappa_j,
\end{equation*}
where $I_i(t)$ is the external input flow to pool $i$. As far as I understand, in the century model, the input flows are due to the plant residues and only enter the first two pools. Denoting the total flow due to plant residue by $I$, we have:
\begin{align*}
I_1(t) & = (1-\text{L/N})\times I, \\
I_2(t) & = \text{L/N}\times I,
\end{align*}
where L/N denotes the Lignin to Nitrogen ratio. Combining all these differential equations into a single formula, we get:
\begin{equation*}
\frac{dC(t)}{dt} = \left( {\begin{array}{c}
   (1-\text{L/N})\times I \\ \text{L/N}\times I \\ 0   \\ 0 \\ 0  \end{array} } \right) +
   \left( {\begin{array}{ccccc}
   -\kappa_1 & 0 & 0 & 0 & 0 \\
   0 & -\kappa_2 & 0 & 0 & 0 \\
   \alpha_{31}\kappa_1 & \alpha_{32}\kappa_2 & -\kappa_3 & \alpha_{34}\kappa_4 & \alpha_{35}\kappa_5 \\
   \alpha_{41}\kappa_1 & 0 & \alpha_{43}\kappa_3 & -\kappa_4& 0  \\
   0 & 0 & \alpha_{53}\kappa_3 & \alpha_{54}\kappa_4 & -\kappa_5
   \end{array} } \right) C(t).
\end{equation*}
\begin{figure}[!h]
\centering
\includegraphics[scale=0.85]{century}
\caption{Flow diagram of century model}
\end{figure}

\section*{CN Model}
The flow diagram of the CN model, developed by Thronton et al., is shown in Figure 2. There are six pools:
\begin{itemize}
\item[pool 1:] \makebox[1.5cm]{Lit1,\hfill}  $\kappa_1 \approx 0.7$,
\item[pool 2:] \makebox[1.5cm]{Lit2,\hfill} $\kappa_2 \approx 0.07$,
\item[pool 3:] \makebox[1.5cm]{Lit3,\hfill}  $\kappa_3 \approx 0.014$,
\item[pool 4:] \makebox[1.5cm]{SOM1,\hfill} $\kappa_4 \approx 0.07$,
\item[pool 5:] \makebox[1.5cm]{SOM2,\hfill}  $\kappa_5 \approx 0.014$,
\item[pool 6:] \makebox[1.5cm]{SOM3,\hfill}  $\kappa_6 \approx 0.0005$.
\end{itemize}
The transfer rate coefficients are:
\begin{equation*}
\alpha_{41}  = 0.61, \quad \alpha_{52}  = 0.45, \quad \alpha_{63}  = 0.71, \quad \alpha_{54} = 0.72, \quad \alpha_{65} = 0.56.
\end{equation*}
So,
\begin{equation*}
\frac{dC(t)}{dt} = \left( {\begin{array}{c}
    I_1 \\ I_2 \\ I_3   \\ 0 \\ 0  \\ 0 \end{array} } \right) +
   \left( {\begin{array}{cccccc}
   -\kappa_1 & 0 & 0 & 0 & 0 & 0\\
   0 & -\kappa_2 & 0 & 0 & 0 & 0\\
   0 & 0 & -\kappa_3 & 0 & 0 & 0 \\
   \alpha_{41}\kappa_1 & 0 & 0 & -\kappa_4 & 0 & 0 \\
   0 &  \alpha_{52}\kappa_2 & 0 & \alpha_{54}\kappa_4 & -\kappa_5 & 0 \\
   0 & 0 & \alpha_{63}\kappa_3 & 0 & \alpha_{65}\kappa_5 & -\kappa_6
   \end{array} } \right) C(t).
\end{equation*}
\begin{figure}[!h]
\centering
\includegraphics[scale=0.9]{cn}
\caption{Flow diagram of CN model}
\end{figure}
\end{document}


\documentclass[twocolumn]{article}

\usepackage{booktabs}	% For formal tables
\usepackage{listings}
\usepackage{amsmath}	% AMS Math Package
\usepackage{amsthm} 	% Theorem Formatting
\usepackage{amssymb}	% Math symbols such as \mathbb
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{siunitx} % deg
\usepackage[margin=2cm]{geometry}

\let\Bbbk\relax

\begin{document}

\title{Implementation of a Freeform Modelling Tool }

\author{Robert Jendersie, Johannes Hauffe}

\maketitle

\section{Introduction}
This report aims to explain implementation details of our multi-resolution freeform modelling tool.
Both in terms of control metaphor and mathematical foundation, we follow the approach described in  \cite{botsch2004intuitive}. Thus, we focus on aspects which are either different in our implementation or only mentioned briefly in the original paper.\\
In addition, we give technical background for the occurring \textit{parameters}, many of which are exposed to the user to allow for experimentation and handling of vastly different meshes.
\section{Smooth Deformation}
Same as in \cite{botsch2004intuitive}, we perform the smooth deformation by minimizing a certain energy functional of the surface with respect to some boundary conditions. For the practical implementation on a triangle mesh we use discretization of the Laplace-Beltrami operator from \cite{meyer2003discrete}. For the vertices $P = \begin{bmatrix}p_1,\dots, p_n\end{bmatrix}^T$ of the mesh, it can be written in matrix form as
\begin{equation}\label{laplace}
\triangle = M^{-1} L,
\end{equation}
where $M$ is the diagonal matrix of vertex areas
\begin{equation*}
m_{ii} = 2 A_{\text{mixed}}(p_i),
\end{equation*} and $L$ is the sparse symmetric operator of edge weights $e_{ij}$
\begin{equation*}
l_{ij} = l_{ji} = \begin{cases} e_{ij} & i \neq j, \text{edge i-j exists} \\ -\sum_{p_k \in N_1(p_i)} e_{ik} & i=j \\ 0 & \text{else}  \end{cases},
\end{equation*}
where $N_1(p)$ is the one-ring of $p$. To improve numerical robustness for poor triangulations, the edge weights are computed by clamping extreme $\cot$ angles to the range $[0+c,\ang{180}-c]$
\begin{align*}
e_{ij} &= \max(0, f(\cot \alpha_{ij}) + f(\cot \beta_{ij})) \\
f(x) &= \max(\cot c, \min(x, \cot (\ang{180}-c))).
\end{align*}
We use $c = \ang{3}$.\\
With \eqref{laplace} we can introduce the higher \textit{order} operators $\triangle^k$ where $k=1$ deforms the surface like a membrane by minimizing the area, $k=2$ characterizes thin plate surfaces which minimize
surface bending and $k=3$ minimizes curvature variation. At the boundary, this behaviour can be smoothly interpolated pointwise by introducing diagonal matrices $D_l$
\begin{equation}\label{laplace2}
\hat{\triangle}^2 = M^{-1} L D_1 M^{-1} L
\end{equation} ,
\begin{equation}\label{laplace3}
\hat{\triangle}^3 = M^{-1}LD_2 M^{-1} L D_1 M^{-1} L,
\end{equation}
with $d_{k_{ii}} = \lambda_k(p_i)$ from \cite{botsch2004intuitive}.
This value can be adjusted by the user as \textit{smoothness} for boundary and handle points.
Finally, we can look at solving $\hat{\triangle}^k = 0$. Taking only the rows $\hat{\triangle}^k_{sup} = \begin{bmatrix}L_1 L_2\end{bmatrix}$ acting on the support vertices $s$ and the fixed boundary vertices $b$ we get
\begin{equation*}
\begin{bmatrix}L_1 & L_2 \\ 0 & I\end{bmatrix} \begin{bmatrix}s \\ b\end{bmatrix} = \begin{bmatrix} 0 \\ b \end{bmatrix},
\end{equation*}
which leads to the sparse system with non-trivial solution
\begin{equation}\label{lsg}
L_1 s = -L_2 b.
\end{equation}
In all cases $L_1$ is positive definite and in the context of solving the system \eqref{lsg}, both \eqref{laplace} and \eqref{laplace2} can be easily made symmetric, since multiplication by $M$ from the left effectively removes the leftmost $M^{-1}$. For \eqref{laplace3} this only works if $D_1 = D_2$, that is, when no interpolation is done. Thus, if applicable, we employ a sparse $LDL^T$ decomposition and fall back to a sparse $LU$ decomposition for the latter case. \\
Although either decomposition needs to be done just once and solving the system afterwards is relatively fast, introducing precomputed basis functions as described in \cite{botsch2004intuitive} further improves performance.
Instead of picking affinely independent points from the handle $h$, we always use the orthogonal frame
\[
Q\begin{bmatrix}0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 1 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 1\end{bmatrix} = \begin{bmatrix} h & 1 \end{bmatrix},
\]
to find the matrix $Q \in \mathbb{R}^{H \times 4}$ of affine combinations.
\section{Detail Preservation}
We implement a multi-resolution editing approach based on point wise displacement vectors, as described in \cite{kobbelt1998interactive}.
To preserve high frequency components in the support area, the details need to be first extracted and then reapplied to the modified mesh. We either use the displacement resulting from the initial solution of \eqref{lsg} without changes to the handle, or perform \textit{implicit smoothing} of the form
\begin{equation}
(I - dt \triangle^k) s = s_0,
\end{equation}
to the support region with initial points $s_0$. The choice of a reasonable time-step $dt$ varies per mesh and can be adjusted by the user as \textit{strength}.
To maintain the full details, the \textit{smoothing order} $k$ should be the same as for the deformation, but in some cases a different order is more robust.
Similar to \eqref{lsg}, we can integrate the fixed boundary and make the system symmetric to then solve
\begin{equation}
(M_1 - dt L_1) s = M_1 s_0 + dt L_2 b,
\end{equation}
with the sparse $LDL^T$ decomposition, where $M_1$ are the area weights of vertices associated with $s$.
Since the Laplace-Beltrami operator \eqref{laplace} is used, the points should only move in normal direction.
Thus, the resulting displacement is encoded per vertex in a local frame, defined by the vertex normal and one edge to fix the rotation. Optionally, other vertices in the \textit{n-ring} can be considered to find the local frame where the displacement vector has the smallest length. Also proposed in \cite{kobbelt1998interactive}, this leads to fewer anomalies in the reconstructed surface, as seen in Figure~\ref{fig:searchRing}.
\begin{figure}
	\includegraphics[width=0.5\textwidth]{searchframe.png}
	\caption{Detail reconstruction using the local frame of each vertex (left) and the frame with the shortest displacement vector in the 4-ring neighbourhood (right). }
	\label{fig:searchRing}
\end{figure}

\section{Results}
To evaluate the usability of our tool, we measure the performance for both modifications to the mesh and parameter changes of the operator.
Times are measured on a i5-6600k ($4 \times 3.50$GHz) with 16GB DDR4 running Win10 Pro 64bit.
The test scenario consists of a mesh with 125k vertices, with a handle region containing 15k and the support region 35k vertices. \\
First we consider modifications to the mesh. Updating the support vertices takes $1.6\si{ms}$, adding the details another $21.6\si{ms}$, resulting overall in a smooth framerate for editing.
\begin{table}
	\centering
	\caption{Measurements for updates to the operator.}
	\begin{tabular}{lc}
		parameter & time [ms] \\
		\hline
		order 1 & 276.77 \\
		order 2 & 922.87 \\
		order 3 & 2262.19 \\
		smoothness & 5692.42 \\
		\hline
	\end{tabular}
	\label{tab:order}
\end{table}\\
Parameter changes require recomputing the higher order operator and precomputing \eqref{lsg}. Times for this are recorded in Table~\ref{tab:order}. A higher order significantly increases computation times and so does the switch to the $LU$ solver for smoothness. Still, a wait time of up to 6s makes it possible to just try out different configurations during editing.
\begin{table}
	\centering
	\caption{Measurements for changes to the smoothing.}
	\begin{tabular}{lc}
		parameter & time [ms] \\
		\hline
		details order 1 & 212.81 \\
		details order 2 & 830.77 \\
		details order 3 & 2168.81 \\
		search ring 1 & 89.59 \\
		search ring 5 & 239.42 \\
		search ring 10 & 725.02 \\
		\hline
	\end{tabular}
	\label{tab:smoothing}
\end{table}\\
Similar values are observed for the smoothing-step in Table~\ref{tab:smoothing}.
Considering that the editing already requires a fixed boundary, the extra implicit smoothing is only useful in edge cases where full reconstruction is not feasible due to strongly stretched or compressed areas. Thus, this time can mostly be saved. A larger seach ring however, can be beneficial in both cases. Above a value of $10$, few differences where observed and considering the extra cost of around $\frac{1}{3}$ of a third order operator computation in this case, this option can always be used.

\bibliographystyle{ieeetr}
\bibliography{references}

\end{document}


\newcommand{\sign}{\text{sign}}
\newcommand{\matr}[1]{\mathbf{#1}}

MODFLOW gives us flows across cell-cell interfaces, which we can divide by interface areas to get specific discharge components normal to the interfaces. We refer to specific discharge here as ``velocity'' as a shortened form of Darcy velocity, with dimensions of $L/T$. So MODFLOW is essentially giving us normal-component velocity information at each interface. The idea behind the weighted-averaging scheme described here is to combine the normal-component information from the interfaces into estimates of the  $x$, $y$, and $z$ components of velocity at the cell center (node). The weights take into account both distance from the cell center and alignment with the desired velocity component.  The greatest weight is given to interfaces that are closest to the cell center and whose normals are most closely aligned with the desired velocity component. For example, when we are estimating the $x$ component of velocity at the cell center, an interface whose normal is in the $y$ direction is given a weight of zero because it provides a value for the $y$ component of velocity; it tells us nothing about the $x$ component.

\subsection{Estimating the $z$ Component of Velocity}

At each horizontal interface $k$ (along the top or bottom of the cell), MODFLOW gives us the interfacial flow, which we can divide by the area to get the $z$ component of velocity at the interface, $v_k^z$. Taking a weighted average of the estimates from all of the cell's horizontal interfaces, we get the following cell-center estimate of the $z$ component of velocity:

\begin{equation}
\label{vz}
v^z = \sum_{k=1}^K \phi_k^z v_k^z,
\end{equation}

\noindent where the summations are over the cell's horizontal interfaces (locally numbered 1 through $K$), and $\phi_k^z$ is the weight assigned to the estimate from interface  $k$, $v_k^z$, for the purpose of computing the cell-center value, $v^z$. We'll discuss the weights in more detail later.

\subsection{Estimating the $x$ and $y$ Components of Velocity}

At each vertical interface $i$ (along a ``side'' of the cell), MODFLOW gives us the interfacial flow, which we can divide by the area to get the component of velocity normal to the interface, $v_i^n$. This normal component is, of course, related to the full velocity vector at interface $i$, $v_i$, by

\begin{equation}
\label{nivi}
\matr{n_i} \cdot \matr{v_i} = v_i^n,
\end{equation}

\noindent or

\begin{equation}
\label{nivi2}
n_i^x v_i^x + n_i^y v_i^y + n_i^z v_i^z = v_i^n.
\end{equation}

For concreteness, suppose we're currently interested in estimating the $x$ component of velocity at interface $i$ (so we can ultimately use it, together with similar estimates at the other interfaces, to inform our estimate of the $x$ component of velocity at the cell center).  Recognizing that $n_i^z = 0$  for vertical interfaces, and solving \ref{nivi2} for the $x$ component, we get

\begin{equation}
\label{vix}
v_i^x = \left ( v_i^n - n_i^y v^y \right ) / n_i^x.
\end{equation}

Equation \ref{vix} is an estimate of the $x$ component of velocity based on information from interface $i$ . Taking a weighted average of the estimates from all of the cell's vertical interfaces, we get the following cell-center estimate of the $x$ component of velocity:

\begin{equation}
\label{vx}
v^x = \sum_{i=1}^N \phi_i^x v_i^x = \sum_{i=1}^N \frac{\phi_i^x v_i^n}{n_i^x} - \left( \sum_{i=1}^N \frac{\phi_i^x n_i^y}{n_i^x}  \right ) v^y,
\end{equation}

We now have two equations, \ref{vix} and \ref{vx}, in two unknowns, $v^x$ and $v^y$. Solving this 2x2 system, we get

\begin{equation}
\label{vxAB}
v^x = \frac{1}{1 - A^{xy} A^{yx}} \sum_{i=1}^N  \left( B_i^x - A^{xy} B_i^y \right ) v_i^n
\end{equation}

\begin{equation}
\label{vxAB}
v^y = \frac{1}{1 - A^{xy} A^{yx}} \sum_{i=1}^N  \left( B_i^y - A^{yx} B_i^x \right ) v_i^n,
\end{equation}

\noindent where

\begin{equation}
\label{Axy}
A^{xy} = \sum_{i=1}^N B_i^x n_i^y
\end{equation}

\begin{equation}
\label{Ayx}
A^{yx} = \sum_{i=1}^N B_i^y n_i^x,
\end{equation}

\noindent and

\begin{equation}
\label{Bix}
B_i^x = \frac{\phi_i^x}{n_i^x}
\end{equation}

\begin{equation}
\label{Biy}
B_i^y = \frac{\phi_i^y}{n_i^y}.
\end{equation}

Both equations \ref{Bix} and \ref{Biy} have the potential to blow up when $n_i^x$ and $n_i^y$ go to zero, but this will be taken care of in the formulation of the weights.

\subsection{Weights}

For estimation of the $z$ component of velocity, we can define a set of weights based on the distance (however we care to measure that---any reasonable measure will do) from each interface $k$ to the cell center, $D_k$, as follows:

\begin{equation}
\label{omegaz}
\omega_k^z = 1 - \frac{D_k}{\sum_{m=1}^K D_m}.
\end{equation}

Interfaces that are closest to the cell center receive the greatest weights. However, as written above, the weights don't add up to 1, so we?ll normalize them such that they do:

\begin{equation}
\label{phiz}
\phi_k^z = \frac{\omega_k^z}{K - 1} = \frac{1}{K - 1} \left (1 - \frac{D_k}{\sum_{m=1}^K D_m} \right ).
\end{equation}

As noted earlier, for estimating the $x$ and $y$ components of velocity, we also want to take into account how closely the normal-component information at each vertical interface aligns with the velocity component ($x$ or $y$) we're trying to estimate.  For that purpose, we can define the following set of weights:

\begin{equation}
\label{omegax}
\omega_i^x = \left [ 1 - \frac{D_i \left | n_i^x \right | }{\sum_{l=1}^N{} D_l  \left | n_l^x \right | } \right ] \left | n_i^x \right |,
\end{equation}

and,

\begin{equation}
\label{omegay}
\omega_i^y = \left [ 1 - \frac{D_i \left | n_i^y \right | }{\sum_{l=1}^N{} D_l  \left | n_l^y \right | } \right ] \left | n_i^y \right |.
\end{equation}

These weight equations can also be written as

\begin{equation}
\label{omegax2}
\omega_i^x = \left [ \frac{\sum_{l=1}^N D_l  \left | n_l^x \right |  - D_i \left | n_i^x \right | }{\sum_{l=1}^N D_l  \left | n_l^x \right | } \right ] \left | n_i^x \right |,
\end{equation}

and,

\begin{equation}
\label{omegay2}
\omega_i^y = \left [ \frac{\sum_{l=1}^N{} D_l  \left | n_l^y \right | - D_i \left | n_i^y \right | }{\sum_{l=1}^N{} D_l  \left | n_l^y \right | } \right ] \left | n_i^y \right |.
\end{equation}

These don't add up to 1, so they are normalized so that they do:

\begin{equation}
\label{phix}
\phi_i^x =  \frac{\omega_i^x \left | n_i^x \right | }{\sum_{l=1}^N \omega_l^x  \left | n_l^x \right | } ,
\end{equation}

and,

\begin{equation}
\label{phiy}
\phi_i^y =  \frac{\omega_i^y \left | n_i^y \right | }{\sum_{l=1}^N \omega_l^y  \left | n_l^y \right | } .
\end{equation}

These weights are substituted into the following equations for $B$, which are needed to solve for $v^x$ and $v^y$.

\begin{equation}
\label{bx}
B_i^x =  \frac{\phi_i^x }{ n_i^x } ,
\end{equation}

and,

\begin{equation}
\label{by}
B_i^y =  \frac{\phi_i^y }{ n_i^y }.
\end{equation}

Development of an efficient solution scheme is obtained by substituting equations ~\ref{omegax2} and ~\ref{omegay2} into equations ~\ref{phix} and ~\ref{phiy}.  This results in the following expressions for $\phi_i^x$ and $\phi_i^y$:

\begin{equation}
\label{phix2}
\phi_i^x =  \frac{\left [ \frac{\sum_{l=1}^N D_l  \left | n_l^x \right |  - D_i \left | n_i^x \right | }{\sum_{l=1}^N D_l  \left | n_l^x \right | } \right ] \left | n_i^x \right | \left | n_i^x \right | }{\sum_{j=1}^N \left [ \frac{\sum_{l=1}^N D_l  \left | n_l^x \right |  - D_j \left | n_j^x \right | }{\sum_{l=1}^N D_l  \left | n_l^x \right | }  \right ] \left | n_j^x \right |  \left | n_j^x \right |  } ,
\end{equation}

and,

\begin{equation}
\label{phiy2}
\phi_i^y =  \frac{\left [ \frac{\sum_{l=1}^N D_l  \left | n_l^y \right |  - D_i \left | n_i^y \right | }{\sum_{l=1}^N D_l  \left | n_l^y \right | } \right ] \left | n_i^y \right | \left | n_i^y \right | }{\sum_{j=1}^N \left [ \frac{\sum_{l=1}^N D_l  \left | n_l^y \right |  - D_j \left | n_j^y \right | }{\sum_{l=1}^N D_l  \left | n_l^y \right | } \right ] \left | n_j^y \right |  \left | n_j^y \right |  } .
\end{equation}

Equations ~\ref{phix2} and ~\ref{phiy2} can be simplified as:

\begin{equation}
\label{phix3}
\phi_i^x =  \frac{\left [ \sum_{l=1}^N D_l  \left | n_l^x \right |  - D_i \left | n_i^x \right |  \right ] \left | n_i^x \right | \left | n_i^x \right | }{\sum_{j=1}^N \left [ \sum_{l=1}^N D_l  \left | n_l^x \right |  - D_j \left | n_j^x \right | \right ] \left | n_j^x \right |  \left | n_j^x \right |  } ,
\end{equation}

and

\begin{equation}
\label{phiy3}
\phi_i^y =  \frac{\left [ \sum_{l=1}^N D_l  \left | n_l^y \right |  - D_i \left | n_i^y \right |  \right ] \left | n_i^y \right | \left | n_i^y \right | }{\sum_{j=1}^N \left [ \sum_{l=1}^N D_l  \left | n_l^y \right |  - D_j \left | n_j^y \right | \right ] \left | n_j^y \right |  \left | n_j^y \right |  } .
\end{equation}

Final combined equations for the $B$ terms are derived by substituting ~\ref{phix3} and ~\ref{phiy3} into ~\ref{bx} and ~\ref{by} to give:

\begin{equation}
\label{bx2}
B_i^x =  \frac{\left [ \sum_{l=1}^N D_l  \left | n_l^x \right |  - D_i \left | n_i^x \right |  \right ] \left | n_i^x \right | \sign (n_i^x)  }{\sum_{j=1}^N \left [ \sum_{l=1}^N D_l  \left | n_l^x \right |  - D_j \left | n_j^x \right | \right ] \left | n_j^x \right |  \left | n_j^x \right | } ,
\end{equation}

and

\begin{equation}
\label{bx2}
B_i^y =  \frac{\left [ \sum_{l=1}^N D_l  \left | n_l^y \right |  - D_i \left | n_i^y \right |  \right ] \left | n_i^y \right | \sign (n_i^y)  }{\sum_{j=1}^N \left [ \sum_{l=1}^N D_l  \left | n_l^y \right |  - D_j \left | n_j^y \right | \right ] \left | n_j^y \right |  \left | n_j^y \right | } .
\end{equation}


\lab{Applications}{Riemann Sphere and Mobius Transformations}{Riemann Sphere and Mobius Transformations}

\objective{Understand the Riemann Sphere in graphics applications.}

We have now examined several applications of complex numbers and functions.  In this lab we extend several of these ideas and develop some intuition about the Riemann sphere using visualization techniques in Python.

Recall that the complex numbers are an extension of the real numbers that include the imaginary numbers.  We extend them even further in this section and examine the extended complex numbers.  Similar to the extended real numbers, the extended complex numbers are our regular set of complex numbers with the addition of positive and negative infinity.  This allows us to examine, for example, certain quotients that are undefined on the standard complex numbers.

The Riemann sphere construction allows a compact and intuitive construction of the extended complex numbers.  Consider the standard complex plane, only now in 3-space instead of a 2 dimensional plane.  Let the plane pass threw the z-axis at $0$.

{\bf PICTURE HERE}

Now consider a the unit sphere combined with the complex numbers in 3-space:

{\bf PICTURE HERE}

We say that the point at the top of the sphere is positive infinity, while the point at the bottom of the sphere is negative infinity.  We are able to construct any point on the complex plane as the point where a line going from either positive or negative infinity and intersecting the sphere at one point.  Such a line can be constructed to intersect the complex plane at any point of our choosing.  Here are some examples:

{\bf PICTURE AND GOOD CAPTION HERE}.

How do we construct such a line?  Using our understanding of lines in 3 space the construction is rather straightforward.

\begin{problem}  Find the point on the Riemann sphere that along with the point at infinity, creates the line that intersects the complex plane at $1 + 5i$, $10 + 15i$, and $1000 + 1500i$.  Why do we say that the top and bottom of the sphere are infinities?  Draw these lines and the Riemann sphere in Python.  Write a function that, given a point on the complex plane, finds the corresponding point on the Riemann sphere and visualizes it.
\end{problem}

\section*{Mobius Transformations}

Recall from chapter {\bf ???} that a conformal mapping is a complex function that preserves angles between lines.  We now examine a special kind of conformal mapping called a Mobius transformation.  We first give the definition of the Mobius transform, and then examine what sorts of transformations we can do with them.

\begin{definition}  A Mobius transformation is a any complex function of the form
\[
f(z) = \frac{az + b}{cz + d}
\]
With the restriction that $ad \neq bc$
\end{definition}

The Mobius transformation is versatile enough to include translations, rotations, magnifications, or any combination of the same, of shapes in the complex plane.  For example, if we wish to translate the unit disk on the complex plane and then magnify it two times, we would use the following transformation:
\[
PUT IT HERE
\]

{\bf PICTURE GOES HERE}

\begin{problem} Write a Python function that accepts arguments $a,b,c,$ and $d$.  Perform the corresponding Mobius transformation on a grid inside the box $[-1,1]\times[-i,i]$, and then visualize the box before and after the transformation on the same plot, but using different colors.
\end{problem}

What do these special transformations have to do with the Riemann sphere?  Recall from the conformal maps chapter that we can construct any point on the complex plane by drawing a line from infinity through a point on the Riemann sphere.  Consider the points on the sphere that can be used to construct the grid in the previous problem.

{\bf PICTURE GOES HERE}

It turns out that we can express any Mobius transformation as a translation or rotation of the Riemann sphere.  For example:

{\bf SEVERAL PICTURES WITH GOOD CAPTIONS GO HERE}

EXAMPLE OF HOW TO FIND THE TRANSFORMATION OF THE SPHERE HERE

\begin{problem}  Write a Python program that extends the previous problem to 3-dimensions.  Visualize the Mobius translation as a rotation/translation of the Riemann sphere.
\end{problem}


\chapter{Markov Chains}

\section{Important/Useful Theorems}

\subsection{}
For a Markox transition matrix, the limiting probabilities of being in a certain state as $n \rightarrow \infty$ are given by the solution to the following set of linear equations.
\begin{equation}
	p_j^* = \sum_{i=1}^{\infty} p_i^* p_{ij}
\end{equation}

\section{Answers to Problems}
\subsection{}
%problem 7.1
Since state $i$ signifies that the highest number chosen so far is $i$, what is the probability the next number is lower than $i$ and you stay in state $i$?  Well, there are $m$ possible numbers that could get picked and $i$ of them are less than or equal to $i$ giving:

\begin{equation}
	p_{ii} = \frac{i}{m}
\end{equation}

What now if we're in $i$ and we want to know what the probability of being in state $j$ is next.  Well, if $j<i$ then it's zero because you can't go to a lower number in this game.  If, however, $j$ is not lower then there are $m$ possible numbers that could get called and only one of them is $j$, giving:
\begin{equation}
	p_{ij} = \frac{1}{m}, j>i
\end{equation}
\begin{equation}
	p_{ij} = 0, j<i
\end{equation}

\textbf{Answer verified}

\subsection{}
%problem 7.2
Since the chain has an inevitable endpoint that you cannot get out of, there is a persistent state at $i=m$ while all other states are transient.  Transient, in that you will only see them a few times but $m$ is bound to show up sooner or later and once you're in $m$ you can't get out no matter what.

\textbf{Answer not verified}

\subsection{}
%problem 7.3
To do this properly we need to first construct the matrix $P$.
\begin{equation}
P = \left(
\begin{array}{ccccc}
 0 & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} \\
 0 & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} & \frac{1}{4} \\
 0 & 0 & \frac{1}{2} & \frac{1}{4} & \frac{1}{4} \\
 0 & 0 & 0 & \frac{3}{4} & \frac{1}{4} \\
 0 & 0 & 0 & 0 & 1
\end{array}
\right)
\end{equation}
Then we square it:
\begin{equation}
P^2 =
\left(
\begin{array}{ccccc}
 0 & \frac{1}{16} & \frac{3}{16} & \frac{5}{16} & \frac{7}{16} \\
 0 & \frac{1}{16} & \frac{3}{16} & \frac{5}{16} & \frac{7}{16} \\
 0 & 0 & \frac{1}{4} & \frac{5}{16} & \frac{7}{16} \\
 0 & 0 & 0 & \frac{9}{16} & \frac{7}{16} \\
 0 & 0 & 0 & 0 & 1
\end{array}
\right)\end{equation}
\textbf{Answer not verified}

\subsection{}
%problem 7.4
So, if we start with $i$ balls in the urn, what is the probability that we have $j$ after drawing $m$ and discarding all the white balls.  The obvious first simplification we can make is that you can't end up with fewer that the $N-m$ white balls after drawing:
\begin{equation}
	p_{ij} = 0, j > N - m
\end{equation}
You also can't gain white balls
\begin{equation}
	p_{ij} = 0, j > i
\end{equation}
OK! now for the interesting one.  There are $\binom{N}{m}$ ways to draw $m$ balls from the urn.  In any given step, you are going to draw $i-j$ white balls from a total of $i$ and $m - i +j$ black balls from a total of $N-i$.  Thus there are $\binom{i}{i-j}\binom{N-i}{m - i +j}$ ways to make that draw.
\begin{equation}
	p_{ij} = \frac{\binom{i}{i-j}\binom{N-i}{m - i +j}}{\binom{N}{m}}, \text{otherwise}
\end{equation}
\textbf{Answer verified}

\subsection{}
%problem 7.5
Once again, we start building the transition matrix.
\begin{equation}
	P = \left(
\begin{array}{ccccccccc}
 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 \frac{1}{2} & \frac{1}{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 \frac{3}{14} & \frac{4}{7} & \frac{3}{14} & 0 & 0 & 0 & 0 & 0 & 0 \\
 \frac{1}{14} & \frac{3}{7} & \frac{3}{7} & \frac{1}{14} & 0 & 0 & 0 & 0 & 0 \\
 \frac{1}{70} & \frac{8}{35} & \frac{18}{35} & \frac{8}{35} & \frac{1}{70} & 0 & 0 & 0 & 0 \\
 0 & \frac{1}{14} & \frac{3}{7} & \frac{3}{7} & \frac{1}{14} & 0 & 0 & 0 & 0 \\
 0 & 0 & \frac{3}{14} & \frac{4}{7} & \frac{3}{14} & 0 & 0 & 0 & 0 \\
 0 & 0 & 0 & \frac{1}{2} & \frac{1}{2} & 0 & 0 & 0 & 0 \\
 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0
\end{array}
\right)

\end{equation}
And then just square it!
\begin{equation}
	P^2 = \left(
\begin{array}{ccccccccc}
 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 \frac{3}{4} & \frac{1}{4} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
 \frac{107}{196} & \frac{20}{49} & \frac{9}{196} & 0 & 0 & 0 & 0 & 0 & 0 \\
 \frac{75}{196} & \frac{24}{49} & \frac{6}{49} & \frac{1}{196} & 0 & 0 & 0 & 0 & 0 \\
 \frac{1251}{4900} & \frac{624}{1225} & \frac{264}{1225} & \frac{24}{1225} & \frac{1}{4900} & 0 & 0 & 0 & 0 \\
 \frac{39}{245} & \frac{471}{980} & \frac{153}{490} & \frac{23}{490} & \frac{1}{980} & 0 & 0 & 0 & 0 \\
 \frac{22}{245} & \frac{102}{245} & \frac{393}{980} & \frac{22}{245} & \frac{3}{980} & 0 & 0 & 0 & 0 \\
 \frac{3}{70} & \frac{23}{70} & \frac{33}{70} & \frac{3}{20} & \frac{1}{140} & 0 & 0 & 0 & 0 \\
 \frac{1}{70} & \frac{8}{35} & \frac{18}{35} & \frac{8}{35} & \frac{1}{70} & 0 & 0 & 0 & 0
\end{array}
\right)
\end{equation}
Telling us there is a 39 in 245 chance that if we start with 5 balls that we'll be at zero after two steps.
\textbf{Answer verified}

\subsection{}
%problem 7.6
Since our chain is finite-dimensional and each state is accessible from every other state, all states are persistent by the corollary to theorem 7.3.

\textbf{Answer not verified}

\subsection{}
%problem 7.7
As the problem alludes to, if you start off on at any given point, there is zero probability of being at that point during the next step.  Hence, the elements of the transfer matrix oscillate between being 0 and non-zero so the limit of 7.20 is always zero and not greater than zero as implied.

\textbf{Answer not verified}

\subsection{}
%problem 7.8

Because you can now conceivably stay at the edge point, that means that every point is now accessible from every other point at every time step after a certain period of time has elapsed.  Since we're also finite dimensional and now accessible, 7.20 is now satisfied and we have proven the existence of the stationary probabilities.

\textbf{Answer not verified}

\subsection{}
%problem 7.9

We now want to solve:

\begin{equation}
	p_j^* = \sum_{i=1}^{m} p_i^* p_{ij}
\end{equation}
So let's get to it!

\begin{eqnarray}
	p_1^* = \sum_{i=1}^{m} p_i^* p_{i1} = q p_1^* + q p_2^* \\
	p_2^* = \sum_{i=1}^{m} p_i^* p_{i2} = p p_1^* + q p_3^* \\
	p_j^* = p p_{j-1}^* + q p_{j+1}^* \\
	p_m^* = \sum_{i=1}^{m} p_i^* p_{im} = p p_{m-1}^* + p p_{m}^*
\end{eqnarray}
You can easily solve the first equation to get:
\begin{equation}
	p_2^* =\frac{p}{q} p_1^*
\end{equation}
Then if we look to solve the second equation for $p_2^*$,
\begin{eqnarray}
	p_2^*  = p p_1^* + q p_3^* \\
	\frac{p}{q} p_1^* = p p_1^* + q p_3^* \\
	\left( \frac{p}{q^2} - \frac{p}{q} \right) p_1^* = p_3^* \\
	p_3^* = \left( \frac{p}{q} \right)^2 p_1^*
\end{eqnarray}
So clearly if we were to put that back into the third equation, we'd get another factor of $p/q$, ergo:
\begin{eqnarray}
	p_j^* = \left( \frac{p}{q} \right)^{j-1}p_1^*
\end{eqnarray}
This needs to be normalized, however:
\begin{eqnarray}
	1 = \sum_{j = 1}^m p_j^* = \sum_{j = 1}^m \left( \frac{p}{q} \right)^{j-1}p_1^* \\
	1 = \frac{q \left(\left(\frac{p}{q}\right)^m-1\right)}{p-q} p_1^* \\
	p_1^* = \frac{p-q}{q \left(\left(\frac{p}{q}\right)^m-1\right)}
\end{eqnarray}
But that's only if $q \neq p$.  Clearly, if they are equal, each term of the sum will just be equal to 1. giving:
\begin{eqnarray}
	1 = \sum_{j = 1}^m p_j^* = \sum_{j = 1}^m \left( \frac{p}{q} \right)^{j-1}p_1^* \\
	1 = m p_1^* \\
	p_1^* = \frac{1}{m}
\end{eqnarray}
\textbf{Answer verified}

\subsection{}
%problem 7.10
Let's turn $A$ into 1 and $B$ into 2.  So, if 1 is shooting, there is a $\alpha$ probability that 1 will go next whereas there is a $1 - \alpha$ probability that 2 goes next.  Similarly, if 2 is shooting, there is a $1 - \beta$ chance he shoots again and a $\beta$ chance that 1 goes next.  That gives us a transfer matrix of:
\begin{equation}
P = \left(
\begin{array}{cc}
 \alpha  & 1-\alpha  \\
 \beta  & 1 - \beta  \\
\end{array}
\right)
\end{equation}
We want to solve the equation:
\begin{eqnarray}
	\pi^T P = \pi^T \\
	\pi^T (P - I) = 0 \\
	\pi_1 +\pi_2 = 0
\end{eqnarray}
I got lazy so I plugged the last two equations into my choice of symbolic manipulation program and got:
\begin{eqnarray}
	p_1^* = \frac{\beta }{1 - \alpha +\beta} \\
	p_2^* = \frac{1 - \alpha }{1 - \alpha +\beta}
\end{eqnarray}
Since we want to know the probability the target eventually gets hit, the first limiting probability is our choice since it  represents the limit that $A$ is firing as the number of shots goes towards infinity.

\textbf{Answer not verified}
NOTE: this answer is different from the book's answer... I tried like a dozen times and kept getting this so I think it may be wrong although I'd also believe that I am wrong so let me know!

\subsection{}
%problem 7.11

\begin{equation}
	p_j^* = \sum_{i=1}^{m} p_i^* p_{ij}
\end{equation}
But we're also told:
\begin{equation}
	1 = \sum_{i=1}^{m} p_{ij} = \sum_{j=1}^{m} p_{ij}
\end{equation}
Let's expand things a bit:
\begin{eqnarray}
	p^*_1 = p_{11}p^*_1 + p_{21}p^*_2 + p_{31}p^*_3 + \cdots	p_{m1}p^*_m \\
	p^*_2 = p_{12}p^*_1 + p_{22}p^*_2 + p_{32}p^*_3 + \cdots	p_{m2}p^*_m \\
	\cdots \\
	p^*_m = p_{1m}p^*_1 + p_{2m}p^*_2 + p_{3m}p^*_3 + \cdots	p_{mm}p^*_m
\end{eqnarray}
You will notice that a clear solution is every $p^*$ being unity and since it is a solution, that's all we care for.  Then, since the solution must be normalized, they all turn out to actually be $p^*_i = \frac{1}{m}$.
\textbf{Answer not verified}

\subsection{}
%problem 7.12

\textbf{Solution practically in book}

\subsection{}
%problem 7.13
\begin{equation}
	p_j^* = \sum_{i=1}^{\infty} p_i^* p_{ij}
\end{equation}
So let's solve...
\begin{eqnarray}
	p_1^* = \sum_{i=1}^{\infty} p_i^* p_{i1} = \sum_{i=1}^{m} p_i^* \frac{i}{i+1} \\
	p_j^* = \sum_{i=1}^{\infty} p_i^* p_{ij} = \frac{1}{j} p^*_{j-1} \\
	p_j^* = \frac{1}{j!} p_1^* \\
\end{eqnarray}
Normalize this
\begin{eqnarray}
	\sum_{j=1}^{\infty} p_j^* = 1 = \sum_{j=1}^{\infty} \frac{1}{j!} p_1^* \\
	1 = (1-e)p_1^* \\
	p_1^* = \frac{1}{1-e} \\
	p_j^* = \frac{1}{j!(1-e)}
\end{eqnarray}

\textbf{Answer verified}

\subsection{}
%problem 7.14

\textbf{Solution practically in book}
\subsection{}
%problem 7.15
If the stakes are doubled, it's like playing the game without doubled stakes but half the capital on both sides in which case it is clear that $\hat{p_j}$ gets bigger.
\textbf{Answer verified}

\subsection{}
%problem 7.16
Play with the two possible limits in equation 7.34.
\textbf{Sorry... maybe some other day}
%%answer template
%\subsection{}
%%problem n.n
%
%
%\begin{equation}
%
%\label{answern.n}
%\end{equation}
%\textbf{Answer [not] verified}


\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{cancel}
\usepackage[nodayofweek]{datetime}

% Set size of text area with total parameter
\usepackage[a4paper, total={155mm, 255mm}]{geometry}

\title{Computing the Mean of Consecutive Integers}
\author{Dyson}
\date{\today}

\begin{document}

\maketitle

% Set paragraph spacing here to avoid messing with title
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

While looking through the source code of Julia's Statistics library to try out the \texttt{@edit} macro like the massive nerd I am, I noticed something interesting. If the user calls \texttt{mean()} with a \texttt{UnitRange} object, which is just a range between two integers, then the \texttt{mean()} function doesn't sum the range and divide by its length. Instead, it simply returns the start of the range, plus the end, divided by 2. This makes sense intuitively. The mean of a range of consecutive integers is just the middle of the range, but I wanted to prove it rigorously.

\section{The Conjecture}

We want to show that $\displaystyle \frac{\sum\limits_{n = a}^b n}{b - a + 1} \equiv \frac{a + b}{2}$, for $a, b \in \mathbb{Z}$ and $b > a$.

We have to use $b - a + 1$ for the length of the range, per se. $b - a$ is just the difference, but we need to count both $a$ and $b$, so we have to add one.

\section{The Proof}

We should start by getting rid of the sum.
\begin{gather*}
\sum_{n = a}^b n = \sum_{n = 1}^b n - \sum_{n = 1}^{a - 1} n\\[0.5em]
= \frac{b(b + 1)}{2} - \frac{(a - 1)(a - 1 + 1)}{2}\\[0.5em]
= \frac{b(b + 1)}{2} - \frac{a(a - 1)}{2}\\[0.5em]
= \frac{b^2 + b - a^2 + a}{2}
\end{gather*}

This means that now we only need to show that $\displaystyle \frac{b^2 + b - a^2 + a}{2} \div (b - a + 1) \equiv \frac{a + b}{2}$.
\begin{gather*}
\frac{b^2 + b - a^2 + a}{2} \div (b - a + 1) = \frac{b^2 + b - a^2 + a}{2(b - a + 1)}
\end{gather*}

\newpage

We want this to become $\dfrac{a + b}{2}$, so if we could show that the numerator could be written as $(a + b)(b - a + 1)$, then we could just cancel the fraction down and get what we want. Factoring $b - a + 1$ out of the numerator is tricky, but expanding the brackets to show that we get the numerator is easy.

\begin{gather*}
(a + b)(b - a + 1) = ab - a^2 + a + b^2 - ab + b\\[0.5em]
= -a^2 + a + b^2 + b\\[0.5em]
= b^2 + b - a^2 + a\\[1em]
\therefore \frac{b^2 + b - a^2 + a}{2(b - a + 1)} = \frac{(a + b)\cancel{(b - a + 1)}}{2\cancel{(b - a + 1)}} = \frac{a + b}{2}
\end{gather*}
\hspace*{\fill}$\square$

\end{document}


\section{Progress Summary}

Six work packages span the timeline of this project. Since this project is primarily theoretical, we planned the first package to be a comprehensive review of the underlying concepts. Since graph states lie at the heart of measurement-based quantum computing, it is necessary to the terminology and some fundamental results. The second work package involves a literature review on measurement-based quantum computing. We discovered that since this subject is a major application area of stabilizer formalism and graph states in general, most of the available introductory materials on stabilizer formalism or graph states contain a review of measurement-based quantum at the very least. Furthermore, almost every resource on measurement-based quantum computing introduces the preliminary material, though with slightly different notations. Therefore we decided on overlapping the timelines of the first two work packages.

Graphs are mathematical objects commonly used in computer science that are composed of vertices and edges connecting them\cite{clrs}. A graph is defined by the set \(V\) of \(N\) vertices and \(E\) of \(M\) edges.
\begin{equation}
  V = \Set{1, 2, \dots, N} \quad\text{and}\quad E \subseteq [V]^2 \text{ where } \abs{E\,} = M
\end{equation}
Since we do not define an order among the vertices that are connected by an edge, an edge is used only to denote \emph{connectivity}. Two vertices \(a, b \in V\) are called adjacent if there is an edge connecting them. A \emph{neighborhood} of a vertex \(a \in V\) is the set of all other vertices that are connected to it.
\begin{equation}
  N_a = \Set{\,b\in V \given \Set{a, b}\in E\,}
\end{equation}

A subtype of graphs is \emph{simple graphs} that contain no loops---edges connecting a vertex to itself---or multiple edges between any two vertices\cite{hein2006}. We mainly deal with simple graphs in this paper.

Simple graphs can represent the interactions of some qubit-based quantum systems. These systems, which we use to describe the structure of measurement-based quantum computers, are called \emph{graphs states}. One of the two ways of defining a graph state is by its interaction patterns. A graph state describing the graph \(G=\p{V, E}\) is made up of qubits that are labelled by the vertices of \(G\). The interaction pattern of the qubits \(a\) and \(b\) connected by an edge in \(E\) is an Ising interaction. We also impose the following conditions.

\begin{enumerate}
  \item Since an edge only denotes connectivity, all two-particle unitaries that involve an edge must commute
  \begin{equation}
    [U_{ab}, U_{bc}] = 0 \quad \forall a, b, c \in V
  \end{equation}
  \item Since edges do not denote a direction, unitaries must be symmetric
  \begin{equation}
    [U_{ab}, U_{ba}] = 0 \quad \forall a, b \in V
  \end{equation}
  \item All the particles must interract through the same unitary.
\end{enumerate}

The general form of such an interaction pattern is given by the following unitary, parameterized by the \emph{interraction strength}.
\begin{equation}
  U_{ab}^I(\psi_{ab}) = e^{-i \psi_{ab} \, \sigma_z^a \, \sigma_z^b}
\end{equation}
This interraction pattern is useful to us because of the entanglement patterns it produces. Note that such a unitary with parameter \(\psi_{ab}\) is equivalent to a controlled \(\sigma_z\) gate---denoted by \(\cz\)---up to some additional \(\pi/4\)-rotations around the \(z\) axis for each qubit.
\begin{equation}
  \begin{aligned}
  e^{-i\frac{\pi}{4}} e^{i\sigma_z^a\frac{\pi}{4}} e^{i\sigma_z^b\frac{\pi}{4}} U^I_{ab}\p*{\frac{\pi}{4}} &= e^{-i\frac{\pi}{4}} e^{i\sigma_z^a\frac{\pi}{4}} e^{i\sigma_z^b\frac{\pi}{4}} e^{-i \frac{\pi}{4} \, \sigma_z^a \, \sigma_z^b}\\
  &= e^{-i\frac{\pi}{4}}\\
  &= \begin{bmatrix}
    1 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 \\
    0 & 0 & 1 & 0 \\
    0 & 0 & 0 & -1
  \end{bmatrix}
\end{aligned}
\end{equation}
Using \(\cz\) to construct edges makes sure that the resulting edege
\begin{equation}
  U_{ab}\ket+^a\ket+^b = \frac{1}{\sqrt2}(\ket0^a\ket+^b + \ket1^a\ket-^b)
\end{equation}
is maximally entangled. Furhtermore \(U_{ab}\)\/ is Hermitian so it can be used to delete an edge as well.

A graph state \(\ket{G}\) which correspond to the simple graph \(G=\p{V, E}\) is defined to be
\begin{equation}
  \ket{G} = \prod_{\p{a,b} \, \in E} U_{ab}\,\ket+^V,
\end{equation}
and is prepared via the following procedure.
\begin{enumerate}
  \item For each vertex in \(V\), prepare the corresponding qubit with the positive \(\sigma_x\) eigenstate \(\ket+\).
  \item For each edge \(\p{a,b}\in E\), apply \(U_{ab}\) to the system.
\end{enumerate}

\begin{figure}[bt]
  \centering
  \subcaptionbox{The diagram of \(G\)}[0.85\linewidth]{\input{{fig/graph.tikz}}}
  \vspace{1em}

  \subcaptionbox{Interraction pattern representation of \(\ket{G}\)}[0.43\linewidth]{%
    \begin{align*}
      \ket{G}
      &= U_{24}U_{23}U_{12}\ket{+}^{\otimes 4} \\
      &= \begin{aligned}[t]
        &\ket0\ket0\ket0\ket+ -\ket0\ket0\ket1\ket-\\
        &+\ket0\ket1\ket0\ket+ -\ket0\ket1\ket1\ket-\\
        &+\ket1\ket0\ket0\ket+ +\ket1\ket0\ket1\ket-\\
        &-\ket1\ket1\ket0\ket+ +\ket1\ket1\ket1\ket-
      \end{aligned}
  \end{align*}}
  \hfill
  \subcaptionbox{Stabilizer representation of \(\ket{G}\)}[0.43\linewidth]{%
  \begin{gather*}
    \sigma_x^1\sigma_z^2\\
    \sigma_x^2\sigma_z^1\sigma_z^3\sigma_z^4\\
    \sigma_x^3\sigma_z^2\\
    \sigma_x^4\sigma_z^2
  \end{gather*}}

  \caption{Representations of the graph state \(\ket{G}\) which correspons to the graph \(G = \Set{V, E}\) where \(V = \Set{1,2,3}\) and \(E = \Set{\Set{1,2}, \Set{2,3}, \Set{2,4}}\)}\label{fig:graph_state}
\end{figure}

An alternative definition of graph states with a more compact representation uses stabilizer formalism\cite{caves2014}. A stabilizer is defined to be a commutative subgroup of the \(N\)-qubit Pauli group \(\symcal{P}^V\) over the qubits in \(V\) that does not contain \(-\id_V\) or \(\pm i\id_V\)\cite{Briegel_2001,pusey2011}. For a given simple graph \(G=\p{G, E}\), the corresponding graph state \(\ket{G}\) is defined as the unique and common eigenvector to the
set of independent commuting observables
\begin{equation}
  K_a = \paulix^a \pauliz^{N_a} = \paulix^a \prod_{b\in N_a} \pauliz^{b}
\end{equation}
with eigenvalues \(+1\). The commutative subgroup of \(\symcal{P}^B\) generated by the set \(\Set{K_a \given a \in V}\) is called \emph{the stabilizer of}\/ \(\ket{G}\). Due to the common eigenvalues of its generator, a stabilizer provides the following measurement outcome correlations.
\begin{equation}
  m_x^a\prod_{b\in N_a}m_z^b = 1
\end{equation}

A simple graph state, along with its interaction pattern and stabilizer definitions, is given in Figure\ref{fig:graph_state}.

At the heart of the measurement-based computing paradigm lies the notion of a \emph{cluster}\cite{russendorf2001,russendorf2003}. A cluster is a \(d\)-dimensional array of qubits where every qubit interacts with its neighbours through Ising interactions. The state of a cluster \(\ket{C}\) is a graph state. The cluster provides a general substrate that can perform universal computation. Then, Pauli measurements are applied on the cluster to encode and process the data as needed. In the next phase of this project, we are going to introduce the specific procedures which are necessary to achive universal computation by simulating CNOT, H, \(z\)-rotation, general rotation and \(\pi/2\) phase gates.

The third work package involves the preparation of introduction and method parts of the written report. It is yet to be completed and we are actively working on it. Due to the deadline extension of the interim report, we decided to shift the deadline of this work package as well. Lastly, there are no changes on the remaining work packages. The new timeline is given in Table \ref{tab:wp}.

\begin{table}[hbt]
  \centering
  \newcommand\cc{\blacksquare}
  \begin{tabular}{r @{\hspace{2em}}c c c c c c c c c c c c c c}
    \toprule
      & \multicolumn{13}{c}{Week} \\\cmidrule{2-14}
    WP &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 & 10 & 11 & 12 & 13 & 14 \\
    \midrule
    1 & \cc & \cc & \cc & \cc & \cc & \cc                                           \\
    2 &     &     &     & \cc & \cc & \cc & \cc & \cc                               \\
    3 &     &     &     &     & \cc & \cc & \cc & \cc & \cc                          \\
    4 &     &     &     &     &     &     &     & \cc & \cc & \cc & \cc & \cc       \\
    5 &     &     &     &     &     &     &     &     &     &     &     & \cc & \cc \\
    6 &     &     &     &     &     &     &     &     &     &     & \cc & \cc & \cc \\
    \bottomrule
  \end{tabular}

    \caption{Revised timeline of the project\label{tab:wp}}
\end{table}


\chapter{Classification: Alternative}

\section{Underfitting and Overfitting}
Re-substitution Errors, $e$: error on training
\marginnote{I do not focus on Support Vector Machines and Artificial Neural Network} \\
Generalization Errors, $e^{'}$: error on testing \\
\\
Optimistic approach to estimate $e^{'}$:
$$e^{'}=e$$
Pessimistic approach to estimate $e^{'}$:
$$e^{'}=e + \frac{\# leaf \times 0.5}{Total\ \# \ Instances}$$
\textbf{Occam's Razor} Given two models of similar generalization errors, one should prefer the simpler model over the more complex model.

\section{k-Nearest Neighbour}
Instance based classifier: Use training records directly to predict the class label of unseen cases \\ \\
K-nearest neighbors of a record $x$ are data points that have the $k$ smallest distance to $x$. \\

\section{Na$\ddot{i}$ve Bayes Classifiers}

Bayes Theorem:
$$P(C\mid A) = \frac{P(A\mid C)P(C)}{P(A)}$$
\\
Na$\ddot{i}$ve Bayes Classifiers: Compute the posterior probability for all values of C using the Bayes theorem
$$P(C\mid A_1 A_2 \ldots A_n) = \frac{P(A_1 A_2 \ldots A_n\mid C)P(C)}{P(A_1 A_2 \ldots A_n)}$$
Assume independence among attributes $A_i$
$$P(C\mid A_1 A_2 \ldots A_n) = \frac{P(A_1\mid C_j)P(A_2\mid C_j)\ldots P(A_n\mid C_n) P(C)}{P(A_1 A_2 \ldots A_n)}$$
For discrete attribute:
$$P(A_i\mid C_j)=\frac{\mid A_{ik} \mid}{N_c}$$
For continuous attribute, can use probability density estimation:
$$P(A_i\mid C_j)=\frac{1}{\sqrt{2\pi \sigma_j^{2}}}\exp^{-\frac{A_i-\mu_j^{2}}{2\sigma_j^{2}}}$$
\section{Support Vector Machines}
Find a linear hyperplane (decision boundary) that will separate the data

$$f(\vec{x})=
\begin{cases}
    1 & if\ \vec{w}\bullet \vec{x}+b \ge 1 \\
    0 & if\ \vec{w}\bullet \vec{x}+b \le -1
\end{cases}
$$

\section{Ensemble Classification}
Predict class label of previously unseen records by aggregating predictions made by multiple classifiers \\ \\
Assumption: Individual classifiers could be lousy, but the aggregate can usually classify correctly.

\subsection{Bagging}
Simplified steps:
\begin{enumerate}
\item Sampling with replacement to get $k$ set of data
\item Train multiple $k$ models on $k$ different samples
\item For each test example, predict by using simple majority voting
\end{enumerate}

\subsection{Boosting}
An iterative procedure to adaptively change distribution of training data by focusing more on previously misclassified records. \\ \\
Records that are wrongly classified will have their weights increased. Records that are correctly classified will have their weights decreased