\documentclass[12pt]{article}
\usepackage[usenames]{color} %used for font color
\usepackage{amsmath, amssymb, amsthm}
\usepackage{wasysym}
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage{mathtools}
\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\graphicspath{ {./} }
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\prob}{\mathbb{P}}
\newcommand{\degrees}{^{\circ}}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\author{Tianshuang (Ethan) Qiu}
\begin{document}
\title{Math 74, Week 15}
\maketitle

\section{Mon Lec, 2b}
$g_2 = \sqrt{a_1a_2}$, so $(1+g_2)^2 = 1 + a_1a_2 + 2\sqrt{a_1a_2}$
\newline
Our left hand side should be $(1+a_1)(1+a_2) = 1 + a_1a_2 + a_1 + a_2$. By Am-GM, $LHS \geq RHS$
\newline
Now we consider 3 elements. $g_3 = \sqrt[3]{a_1a_2a_3}$, and $(1+g_3)^3 = 1 + a_1a_2a_3 + 3\sqrt[3]{a_1a_2a_3} + 3(a_1a_2a_3)^{2/3}$.
\newline
Now LHS has $(1+a_1)(1+a_2)(1+a_3) = 1 + a_1 + a_2 + a_3 + a_1a_2 + a_1a_3 + a_2a_3 + a_1a_2a_3 $
Here we can cancel the $1$ on both sides, and by AM-GM we have $a_1+a_2+a_3 \geq 3\sqrt[3]{a_1a_2a_3}$. Now let the three terms be $a_1a_2$, $ a_1a_3$, and $ a_2a_3$. By AM-GM we have $a_1a_2 + a_1a_3 + a_2a_3 \geq 3 \sqrt[3]{a_1^2a_2^2a_3^2}$.
\newline
Thus we have shown that $LHS \geq RHS$ term by term.

\section{Mon Lec, 3c}
Since our plane passes through the point $(5,9,12)$, we know that the equation of a plane can be given by $\frac{x}{r} +
\frac{y}{s} + \frac{z}{t} = 1$.
Furthermore we have $\frac{5}{r} + \frac{9}{s} + \frac{12}{t} = 1$. Now we apply the Hamonic Mean-GM inequality:
$$\frac{3}{\frac{5}{r} + \frac{9}{s} + \frac{12}{t}} \leq \sqrt[3]{\frac{rst}{540}}$$
Now from the equation of the plane we know that $LHS = 3$, so now $\sqrt[3]{\frac{rst}{540}} \geq 3$, $\frac{rst}{540} \geq 27$
Finally, since the volume of this terahedron is equal to $\frac{1}{2}rst$, we know that $V \geq 7290$.
\newline
When the terms $\frac{5}{r}, \frac{9}{s},\frac{12}{t}$ are equal, we have $V = 7290$. Furthermore their sum is equal to 1. Therefore they are eaech a third. $r = 15, s = 27, t = 36$.
\newpage

\section{Mon Dis, 5c}
If two functions are convex, then their second derivatives must be non-negative. Then the sum must have a second derivatie that i also non-negative. Therefore this sum must also be convex.

\newpage

\section{Wed Lec, 2}
\subsection{c}
$g(0)=1$, $g(1) = 1$. The second derivative of $\frac{1}{x+1}$ is $\frac{1}{(x+1)^3}$, which on the domain of $[0,1]$, is positive. The second half to the function is linear and therefore convex. The sum of two convex functions is also convex, thus $g$ is convex on $[0,1]$
\newline
By the convex function theorem the maximum of $g$ on $[0,1]$ is $1$, so $g(x)\leq 1$.

\subsection{e}
We can first fix $b, c$ in $[0,1]$, in this case our function consists of a constant, a linear function, and two convex functions (from $c$ we know that the second derivative of fractional functions is positive).
Thus by our theorem that the sum of convex functions is convex, the original function is also convex.
\newline
Now we find the values of these functions at the end points: $f(0) = 1, f(1) = 1$. The above is true also for fixed $a,b$ or $a,c$, thus the original is maximized when they are either $0$ or $1$. Finally we can use the convex theorem to state that the original function must be less than or equal to $1$ on the domain $[0,1]$.

\section{Wed Lec, 4}
\subsection{b}
$f(x) = \frac{1}{x}$. Its second derivative is positive for $x>0$. By JI,
$$\frac{f(x_1)+f(x_2)+...+f(x_n)}{n} \geq f(\frac{x_1+x_2+...+x_n}{n})$$
$$\frac{\frac{1}{x_1}+...+\frac{1}{x_n}}{n} \geq \frac{n}{x_1+x_2+...+x_n}$$
The above inequality is equivalent to
$$\frac{n}{\frac{1}{x_1}+...+\frac{1}{x_n}} \leq \frac{x_1+x_2+...+x_n}{n}$$
, which is true due to the Arithmetic-Harmonic mean inequality.

\subsection{c}
$f(x) = x^{7/3}$. Its second derivative is positive for $x>0$. By JI,
$$\frac{f(x_1)+f(x_2)+...+f(x_n)}{n} \geq f(\frac{x_1+x_2+...+x_n}{n})$$
$$\frac{x_1^{\frac{7}{3}} + ... x_n^{\frac{7}{3}}}{n} \geq (\frac{x_1+x_2+...+x_n}{n})^{\frac{7}{3}}$$
The above inequality is equivalent to
$$(\frac{x_1^{\frac{7}{3}} + ... x_n^{\frac{7}{3}}}{n})^{\frac{3}{7}}\geq \frac{x_1+x_2+...+x_n}{n}$$
, which is true due to the Arithmetic-Power mean inequality. This power mean is equal to $\frac{7}{3} > 1$, so it is greater than or equal to the arithmetic mean.

\section{Wed Lec, 5c}
Per the algebraic definition for convex functions: $(\lambda x_1+(1- \lambda)x_2) \geq \lambda f(x_1)+(1- \lambda)f(x_2)$
By our assumption $\frac{f(x_1)+f(x_2)+f(x_3)+f(x_4)}{4} \geq f(\frac{x_1+x_2+x_3+x_4}{4})$
\newline
$\frac{x_1+x_2+x_3+x_4+x_5}{5} = \frac{4}{5}\frac{x_1+x_2+x_3+x_4}{4} + \frac{x_5}{5}$. let $\lambda = \frac{4}{5}$, and since the function is convex we have
$$f(\frac{x_1+x_2+x_3+x_4+x_5}{5}) = \lambda f(y_1)+(1- \lambda)f(y_2) \leq (\lambda f(y_1)+(1- \lambda)f(y_2))$$
$$ = \frac{4}{5}f(x_1+x_2+x_3+x_4) + \frac{1}{5}f(x_5) $$
Now by our inductive hypothesis the last term is less than or equal to $\frac{4}{5}\frac{f(x_1)+f(x_2)+f(x_3)+f(x_4)}{4} + \frac{f(x_5)}{5} = \frac{f(x_1)+f(x_2)+f(x_3)+f(x_4)+f(x_5)}{5}$
Thus we have shown that
$$f(\frac{x_1+x_2+x_3+x_4+x_5}{5}) \leq \frac{f(x_1)+f(x_2)+f(x_3)+f(x_4)+f(x_5)}{5}$$
And our proof is complete.
\newpage

\section{Wed Dis, 3a}
We know that both sides of the equation is positive, so the inequality is equivalent to us taking the natural log of both sides
$$\ln{x^x} \geq \ln{(\frac{x+1}{2})^{x+1}}$$
$$x \ln{x} \geq (x+1)\ln{\frac{x+1}{2}}$$
Now consider the function $y\ln(y)$ and two values $1, x$. By Jensen's inequality we have $(\ln(1)+x\ln(x))/2 \geq \frac{x+1}{2}\ln\frac{x+1}{2}$, which is identical to our initial statement when we multiply both sides by 2.

\newpage

\section{Friday Lec, 2}
\subsection{a}
$x_1 = 10, x_2 = 36, x_3 = 74$.
$$AM = \frac{x_1+x_2+x_3}{3} = 40$$
$$HM = \frac{3}{\frac{1}{10} + \frac{1}{36} + \frac{1}{74}} = \frac{19980}{941} \approx 21.2 < AM$$
Property holds.

\subsection{b}
$$x_1 = 10, x_2 = 36, x_3 = 74, AM = 40, HM \approx 21.2$$
$$x_1 = 10, x_2 = 40, x_3 = 70, AM = 40, HM \approx 21.5$$
$$x_1 = 40, x_2 = 40, x_3 = 40, AM = 40, HM = 40$$
Performed this operation twice.

\subsection{c}
Given $x_1<a<x_2$, we compute $x_1+x_2-a+a = x_1+x_2$. Therefore the sum of these two before and after the operation is the same, and the arithmetic change remains constant.
\newline
Now consider $\frac{1}{x_1}+\frac{1}{x_2} = \frac{x_1+x_2}{x_1x_2}$. $\frac{1}{a}+\frac{1}{x_1+x_2-a} = \frac{x_1+x_1}{x_1a+x_2a-a^2}$. In order to compare the size of the denominators, we take their difference: $x_1x_2 -(x_1a+x_2a-a^2) = (x_1)(x_2-a) - a(x_2-a) = (x_2-a)(x_1-a) $. Since $x_1<a<x_2$, the difference is negative.
Thus the denominator of the latter is larger, so $\frac{1}{x_1}+\frac{1}{x_2}>\frac{1}{a}+\frac{1}{x_1+x_2-a}$

\subsection{d}
This smoothing proccess eventually stops when all terms are equal to the arithmetic mean, or when all the terms are the same. This process means that for any number, we have a process in which we can inrease its harmonic mean and eventually be equal to the arithmetic mean.
This process implies that the harmonic mean is less than or equal to the arithmetic mean, otherwise this process would have been erroneous. Therefore it proves the AM-HM inequality.
\end{document}


\documentclass[11pt]{article}
%\usepackage{fancyheadings}
\usepackage{wrapfig}
\usepackage{epsfig}
\usepackage{hyperref}
\setlength{\headheight}{0pt}
%\setlength{\footheight}{0pt}
\setlength{\topmargin}{-.5in}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\evensidemargin}{-0.25in}
\setlength{\textwidth}{7truein}
\setlength{\textheight}{9truein}
\setlength{\parskip}{6pt}

\begin{document}

\section*{Social Distancing}

%\subsection*{Description}

\begin{wrapfigure}{r}{3in}
\vspace{-10pt}
\epsfig{figure=restaurant,width=3in}
\vspace{-30pt}
\end{wrapfigure}

You own a restaurant, and you want your customers to be as happy as possible. You've learned over the years that customers really don't like sitting very close to each other. They prefer if others cannot hear their conversations. This however, is a pretty hard problem, so you've decided to construct an algorithm that can figure out where to seat your patrons to maximize the distance between them.

Your restaurant is in an old building, and thus has a peculiar shape. The restuarant is very long and not very wide (it was the cheapest space available for lease!). Because of this your tables are all in a horizontal line down your restaurant, but the distances between the tables vary. Given a list of the positions of the tables in your restaurant, and the number of patrons that wish to be seated, return the maximum distance between any two of the patrons after being seated in the optimal arrangement.

\subsection*{Input}
The input file will begin with one line containing $n \leq 10^6$ and $p \leq 10^6$, the number of tables in your restaurant and the number of patrons to sit respectively. The following $n$ lines will each contain a single integer $l_i \leq 10^8$ describing the integer position of table $i$. These positions will be sorted in increasing order. All positions will be unique.

\subsection*{Output}
Output the largest possible value of the minimum distance between patrons after being seated in the optimal seating arrangement.

\vspace{0.25in}\hspace{-0.3in}\begin{tabular}{ll}

%\subsection*{Sample Input}
\parbox{3in}{{\large\bf Sample Input}

\vspace{0.15in}

{\tt
5 3\linebreak
1\linebreak
2\linebreak
4\linebreak
8\linebreak
9
}
}

&

\parbox{3in}{{\large\bf Sample Output}

\vspace{0.15in}

{\tt
3
}
}

\\
\end{tabular}

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{MAT257 Notes}
\author{Jad Elkhaleq Ghalayini}
\date{October 2 2018}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{cancel}

\usepackage[margin=1in]{geometry}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}
\newtheorem*{corollary}{Corollary}
\newtheorem{exercise}{Exercise}

\newcommand{\reals}[0]{\mathbb{R}}
\newcommand{\nats}[0]{\mathbb{N}}
\newcommand{\ints}[0]{\mathbb{Z}}
\newcommand{\rationals}[0]{\mathbb{Q}}
\newcommand{\brac}[1]{\left(#1\right)}
\newcommand{\sbrac}[1]{\left[#1\right]}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\eval}[3]{\left.#3\right|_{#1}^{#2}}
\newcommand{\ip}[2]{\left\langle#1,#2\right\rangle}
\newcommand{\prt}[2]{\frac{\partial #1}{\partial #2}}

\begin{document}

\maketitle

Examples:
\begin{enumerate}
  \item Let \[f(x, y) = \int_a^{x + y}g\] where \(g: \reals \to \reals\) is continuous. We compute \(Df(c, d)\) as follows:
  We have that \(f = q \circ s\), where
  \[q(t) = \int_a^tg, s(x, y) = x + y\]
  We have
  \[Df(c, d) =  g'(s(c, d))s'(c, d) = g(c + d)(c + d)\]
  since \(q'(t) = g(t)\).

  \item Let \[f(x, y) = \int_a^{x^y}g\] We have
  \[f = g \circ \xi, \xi(x, y) = x^y = e^{y\log x}\]
  Hence,
  \[D\xi(x, y) = x^yD(y\log x) = x^y((0, 1)\log x + (1/x, 0)y) = x^y(y/x, \log x)\]
  \[\implies Df(c, d) = q'(\xi(c, d))\xi'(c, d) = g(c^d)c^d(d/c, \log c)\]
\end{enumerate}

\section*{Higher-order Derivatives}
Let \(f: U \to \reals\) be a function where \(U \subseteq \reals^m\) and suppose
\[D_if = \prt{f}{x_i}: U \to \reals\]
exists for all \(i\). So we could now consider
\[D_j(D_if) = \prt{}{x_j}\left(\prt{f}{x_i}\right)\]
We'll write \(D_{ij}f\) to denote the above. Notice \(i\) is applied \textit{first}. We may also write \(f_{x_ix_j}\) and \(\frac{\partial^2 f}{\partial x_j \partial x_i}\). We have that
\[\frac{\partial^2 f}{\partial x_j \partial x_i}(a) = \frac{\partial^2 f}{\partial x_i \partial x_j}(a)\]
if both mixed partials exist and are continuous in a neighborhood of \(a\) (proof uses \(\int\)).

In general, we can consider taking higher order partials as well, as in
\[\frac{\partial^{\alpha_1 + ... + \alpha_n}f}{\partial x_1^{\alpha_1} ... \partial x_n^{\alpha_n}}\]
Of course we have to worry about the order, but the order is irrelevant if \(f\) is \(\mc{C}^\infty\), i.e. that all partial derivatives of all orders exist (and are hence continuous).

\section*{Multi-index notation}
In multi-index notation, \(\alpha = (\alpha_1,...,\alpha_m)\) is a vector of non-negative integers. We define the \textit{total order of \(\alpha\)}
\[|\alpha| = \alpha_1 + ... + \alpha_m\]
Furthermore, we define
\[x = (x_1,...,x_m) \implies x^\alpha = x_1^{\alpha_1}...x_m^{\alpha_m}\]
Once we look at Taylor's theorem, the notation
\[x! = x_1!...x_m!\]
will also come in handy.

We can now perform another example:
\begin{itemize}

  \item [3.] Let
  \[f(x, y) = \left\{\begin{array}{cc}
    xy\frac{x^2 - y^2}{x^2 + y^2} & (x, y) \neq (0, 0) \\
    0 & (x, y) = (0, 0)
  \end{array}\right.\]
  Is this function differentiable at the origin? Yes: \(f'(0, 0) = (0, 0)\). Let's check: we need to show that
  \[\lim_{(x, y) \to (0, 0)}\frac{f(x, y) - f(0, 0) - \cancel{(0, 0)\begin{pmatrix} x \\ y \end{pmatrix}}}{\sqrt{x^2 + y^2}} = \lim_{(x, y) \to (0, 0)}xy\frac{x^2 - y^2}{x^2 + y^2}\frac{1}{\sqrt{x^2 + y^2}} = 0\]
  We have that
  \[\left|xy\frac{x^2 - y^2}{x^2 + y^2}\frac{1}{\sqrt{x^2 + y^2}}\right| \leq \frac{|xy|}{\sqrt{x^2 + y^2}} \to 0\]

\end{itemize}

\end{document}


\subsection{Random Forests}
\label{random_forests}

\noindent{\bf Description}
\smallskip

Random forest is one of the most successful machine learning methods for classification and regression.
It is an ensemble learning method that creates a model composed of a set of tree models.
This implementation is well-suited to handle large-scale data and builds a random forest model for classification in parallel.\\

\smallskip
\noindent{\bf Usage}
\smallskip

{\hangindent=\parindent\noindent\it%
	{\tt{}-f }path/\/{\tt{}random-forest.dml}
	{\tt{} -nvargs}
	{\tt{} X=}path/file
	{\tt{} Y=}path/file
	{\tt{} R=}path/file
	{\tt{} bins=}integer
	{\tt{} depth=}integer
	{\tt{} num\_leaf=}integer
	{\tt{} num\_samples=}integer
	{\tt{} num\_trees=}integer
	{\tt{} subsamp\_rate=}double
	{\tt{} feature\_subset=}double
	{\tt{} impurity=}Gini$\mid$entropy
	{\tt{} M=}path/file
	{\tt{} C=}path/file
	{\tt{} S\_map=}path/file
	{\tt{} C\_map=}path/file
	{\tt{} fmt=}format

}

 \smallskip
 \noindent{\bf Usage: Prediction}
 \smallskip

 {\hangindent=\parindent\noindent\it%
 	{\tt{}-f }path/\/{\tt{}random-forest-predict.dml}
 	{\tt{} -nvargs}
 	{\tt{} X=}path/file
 	{\tt{} Y=}path/file
 	{\tt{} R=}path/file
 	{\tt{} M=}path/file
 	{\tt{} C=}path/file
 	{\tt{} P=}path/file
 	{\tt{} A=}path/file
 	{\tt{} OOB=}path/file
 	{\tt{} CM=}path/file
 	{\tt{} fmt=}format

 }\smallskip

\noindent{\bf Arguments}
\begin{Description}
	\item[{\tt X}:]
	Location (on HDFS) to read the matrix of feature vectors;
	each row constitutes one feature vector. Note that categorical features in $X$ need to be both recoded and dummy coded.
	\item[{\tt Y}:]
	Location (on HDFS) to read the matrix of (categorical)
	labels that correspond to feature vectors in $X$. Note that classes are assumed to be both recoded and dummy coded.
	This argument is optional for prediction.
	\item[{\tt R}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to read matrix $R$ which for each feature in $X$ contains column-ids (first column), start indices (second column), and end indices (third column).
	If $R$ is not provided by default all features are assumed to be continuous-valued.
	\item[{\tt bins}:] (default:\mbox{ }{\tt 20})
	Number of thresholds to choose for each continuous-valued feature (determined by equi-height binning).
	\item[{\tt depth}:] (default:\mbox{ }{\tt 25})
	Maximum depth of the learned trees in the random forest model
	\item[{\tt num\_leaf}:] (default:\mbox{ }{\tt 10})
	Parameter that controls pruning. The tree
	is not expanded if a node receives less than {\tt num\_leaf} training examples.
	\item[{\tt num\_samples}:] (default:\mbox{ }{\tt 3000})
	Parameter that decides when to switch to in-memory building of the subtrees in each tree of the random forest model.
	If a node $v$ receives less than {\tt num\_samples}
	training examples then this implementation switches to an in-memory subtree
	building procedure to build the subtree under $v$ in its entirety.
	\item[{\tt num\_trees}:] (default:\mbox{ }{\tt 10})
	Number of trees to be learned in the random forest model
	\item[{\tt subsamp\_rate}:] (default:\mbox{ }{\tt 1.0})
	Parameter controlling the size of each tree in the random forest model; samples are selected from a Poisson distribution with parameter {\tt subsamp\_rate}.
	\item[{\tt feature\_subset}:] (default:\mbox{ }{\tt 0.5})
	Parameter that controls the number of feature used as candidates for splitting at each tree node as a power of the number of features in the data, i.e., assuming the training set has $D$ features $D^{\tt feature\_subset}$ are used at each tree node.
	\item[{\tt impurity}:] (default:\mbox{ }{\tt "Gini"})
	Impurity measure used at internal nodes of the trees in the random forest model for selecting which features to split on. Possible value are entropy or Gini.
	\item[{\tt M}:]
	Location (on HDFS) to write matrix $M$ containing the learned random forest (see Section~\ref{sec:decision_trees} and below for the schema)
	\item[{\tt C}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to store the number of counts (generated according to a Poisson distribution with parameter {\tt subsamp\_rate}) for each feature vector. Note that this argument is optional. If Out-Of-Bag (OOB) error estimate needs to be computed this parameter is passed as input to {\tt random-forest-predict.dml}.
	\item[{\tt A}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to store the testing accuracy (\%) from a
	held-out test set during prediction. Note that this argument is optional.
	\item[{\tt OOB}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to store the Out-Of-Bag (OOB) error estimate of the training set. Note that the matrix of sample counts (stored at {\tt C}) needs to be provided for computing OOB error estimate. Note that this argument is optional.
	\item[{\tt P}:]
	Location (on HDFS) to store predictions for a held-out test set
	\item[{\tt CM}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to store the confusion matrix computed using a held-out test set. Note that this argument is optional.
	\item[{\tt S\_map}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to write the mappings from the continuous-valued feature-ids to the global feature-ids in $X$ (see below for details). Note that this argument is optional.
	\item[{\tt C\_map}:] (default:\mbox{ }{\tt " "})
	Location (on HDFS) to write the mappings from the categorical feature-ids to the global feature-ids in $X$ (see below for details). Note that this argument is optional.
	\item[{\tt fmt}:] (default:\mbox{ }{\tt "text"})
	Matrix file output format, such as {\tt text}, {\tt mm}, or {\tt csv};
	see read/write functions in SystemML Language Reference for details.
\end{Description}

 \noindent{\bf Details}
 \smallskip

Random forests~\cite{Breiman01:rforest} are learning algorithms for ensembles of decision trees.
The main idea is to build a number of decision trees on bootstrapped training samples, i.e., by taking repeatedly samples from a (single) training set.
Moreover, instead of considering all the features when building the trees only a random subset of the features---typically $\approx \sqrt{D}$, where $D$ is the number of features---is chosen each time a split test at a tree node is performed.
This procedure {\it decorrelates} the trees and makes it less prone to overfitting.
To build decision trees we utilize the techniques discussed in Section~\ref{sec:decision_trees} proposed in~\cite{PandaHBB09:dtree};
the implementation details are similar to those of the decision trees script.
Below we review some features of our implementation which differ from {\tt decision-tree.dml}.

\textbf{Bootstrapped sampling.}
Each decision tree is fitted to a bootstrapped training set sampled with replacement (WR).
To improve efficiency, we generate $N$ sample counts according to a Poisson distribution with parameter {\tt subsamp\_rate},
where $N$ denotes the total number of training points.
These sample counts approximate WR sampling when $N$ is large enough and are generated upfront for each decision tree.

\textbf{Bagging.}
Decision trees suffer from {\it high variance} resulting in different models whenever trained on a random subsets of the data points.
{\it Bagging} is a general-purpose method to reduce the variance of a statistical learning method like decision trees.
In the context of decision trees (for classification), for a given test feature vector
the prediction is computed by taking a {\it majority vote}: the overall prediction is the most commonly occurring class among all the tree predictions.

\textbf{Out-Of-Bag error estimation.}
Note that each bagged tree in a random forest model is trained on a subset (around $\frac{2}{3}$) of the observations (i.e., feature vectors).
The remaining ($\frac{1}{3}$ of the) observations not used for training is called the {\it Out-Of-Bag} (OOB) observations.
This gives us a straightforward way to estimate the test error: to predict the class label of each test observation $i$ we use the trees in which $i$ was OOB.
Our {\tt random-forest-predict.dml} script provides the OOB error estimate for a given training set if requested.

\textbf{Description of the model.}
Similar to decision trees, the learned random forest model is presented in a matrix $M$  with at least 7 rows.
The information stored in the model is similar to that of decision trees with the difference that the tree-ids are stored
in the second row and rows $2,3,\ldots$ from the decision tree model are shifted by one. See Section~\ref{sec:decision_trees} for a description of the model.

\smallskip
\noindent{\bf Returns}
\smallskip

The matrix corresponding to the learned model is written to a file in the format specified. See Section~\ref{sec:decision_trees} where the details about the structure of the model matrix is described.
Similar to {\tt decision-tree.dml}, $X$ is split into $X_\text{cont}$ and $X_\text{cat}$.
If requested, the mappings of the continuous feature-ids in $X_\text{cont}$ (stored at {\tt S\_map}) as well as the categorical feature-ids in $X_\text{cat}$ (stored at {\tt C\_map}) to the global feature-ids in $X$ will be provided.
The {\tt random-forest-predict.dml} script may compute one or more of
predictions, accuracy, confusion matrix, and OOB error estimate in the requested output format depending on the input arguments used.

\smallskip
\noindent{\bf Examples}
\smallskip

{\hangindent=\parindent\noindent\tt
	\hml -f random-forest.dml -nvargs X=/user/biadmin/X.mtx Y=/user/biadmin/Y.mtx
	R=/user/biadmin/R.csv M=/user/biadmin/model.csv
	bins=20 depth=25 num\_leaf=10 num\_samples=3000 num\_trees=10 impurity=Gini fmt=csv

}\smallskip

\noindent To compute predictions:

{\hangindent=\parindent\noindent\tt
	\hml -f random-forest-predict.dml -nvargs X=/user/biadmin/X.mtx Y=/user/biadmin/Y.mtx R=/user/biadmin/R.csv
	M=/user/biadmin/model.csv P=/user/biadmin/predictions.csv
	A=/user/biadmin/accuracy.csv CM=/user/biadmin/confusion.csv fmt=csv

}\smallskip

%\noindent{\bf References}
%
%\begin{itemize}
%\item B. Panda, J. Herbach, S. Basu, and R. Bayardo. \newblock{PLANET: massively parallel learning of tree ensembles with MapReduce}. In Proceedings of the VLDB Endowment, 2009.
%\item L. Breiman. \newblock{Random Forests}. Machine Learning, 45(1), 5--32, 2001.
%\end{itemize}


\chapter{Cross Section Determination Method}
\label{crosssectionchapter}
\label{limits}

This chapter summarizes the technique used to measure the single top quark cross section as well as the systematic uncertainties on the expected signal and background yields. Section~\ref{CrossSectionDetermination} derives the Bayesian posterior density function and shows how it is used to determine the single top quark production cross section. The treatment of systematic uncertainties is also covered in this section. A description of each systematic uncertainty and its effect on the signal acceptance and background yield is presented in Section~\ref{systematics}. Section~\ref{ensembles} describes the method designed to measure the stability and linearity of the cross section measurement technique. Finally, the expected sensitivity and cross section resolution for a Standard Model single top signal in the full dataset is presented in Section~\ref{exp-performance}.

\section{Bayesian Posterior Density Function}
\label{CrossSectionDetermination}

The single top cross section is measured by creating a Bayesian posterior density function, which yields the probability density for all single top quark production cross sections\footnote{The Bayesian posterior density function is sometimes referred to as the posterior in this text.}. The posterior is defined as the conditional probability that a process $\mathcal{A}$ is true given that another process $\mathcal{B}$ is also true; it is equal to the conditional probability of process $\mathcal{B}$ given process $\mathcal{A}$ multiplied by the prior probability for process $\mathcal{A}$ ($\pi(\mathcal{A})$) divided by the prior probability for process $\mathcal{B}$ ($\pi(\mathcal{B})$), as shown in  Eq.~\ref{bayestheorem}.

\begin{equation}
\label{bayestheorem}
P(\mathcal{A}|\mathcal{B}) = \frac{P(\mathcal{B}|\mathcal{A})\pi(\mathcal{A})}{\pi(\mathcal{B})}
\end{equation}

In the single top quark analysis $\mathcal{A}$ is the number of signal and background events and $\mathcal{B}$ is the observed number of events. The conditional probability $P(\mathcal{B}|\mathcal{A})$ is then interpreted as the probability to observe $N$ events given $n$, where $n$ is the expected number of signal and background events. Numerically this is given as the value of the Poisson probability density function for observed number of events given the expectation as seen in Eq.~\ref{poisson}. This term is also referred to as the likelihood and its application in the single top quark analysis is given latter in this section.

\begin{equation}
\label{poisson}
P(\mathcal{B}|\mathcal{A}) \equiv \mathcal{L}(N|n) = \frac{n^{N}e^{-n}}{N!}
\end{equation}

The quantity of interest in this analysis is the signal cross section and not the number of expected signal and background events. To expose the cross section dependence the expected yield $n$ is re-written as

\begin{equation}
\label{expected}
n = n_{S} + n_{B} = \alpha_{S} L \sigma_{S} + \sum_{i} n_{B,i},
\end{equation}

\noindent where $\alpha_{S}$ is the signal acceptance, $L$~is the integrated luminosity, $\sigma_{S}$ is the signal cross section, and $\sum_{i} n_{B,i}$ is the sum of background yields.\footnote{For the rest of this section, the luminosity is absorbed by the acceptance term ($\alpha_{S} \times L \rightarrow \alpha_{S}$).} The likelihood is also re-written as $\mathcal{L}(N|n) = \mathcal{L}(N|\sigma_{S},\alpha_{S},\vec{n}_{B})$ and the prior $\pi(n)$ is re-written as $\pi(\sigma_{S},\alpha_{S}, \vec{n}_{B})$.

The prior can be factored into a term dependent on the cross section and a term dependent on the signal acceptance and the background yield as shown in Eq.~\ref{prior}.

\begin{equation}
\label{prior}
\pi(n) \equiv \pi(\sigma_{S},\alpha_{S}, \vec{n}_{B}) = \pi(\sigma_{S}) \times \pi(\alpha_{S}, \vec{n}_{B})
\end{equation}

The likelihood is modified to combined multiple independent channels by replacing the original likelihood by the product of the likelihoods for each channel, as shown in Eq.~\ref{combine}.

\begin{equation}
\label{combine}
\mathcal{L}(N|\sigma_{S},\alpha_{S}, \vec{n}_{B}) \rightarrow \prod_{i} \mathcal{L}(N_{i}|\sigma_{S},\alpha_{S,i}, \vec{n}_{B,i})
\end{equation}

For the matrix element analysis method the values of $N$,~$\alpha$, and~$\vec{n}_{B}$ are given in the form of two-dimensional histograms, where one axis corresponds to the $s$-channel discriminant and the other axis corresponds to the $t$-channel discriminant. The histograms are filled with matrix element discriminants for the data (N), the signal Monte Carlo ($\alpha_{S}=n_{S}/\sigma_{S}$), and background Monte Carlo ($\vec{n}_{B}$). To incorporate the shape information of these quantities, the likelihood is further modified for a given channel as the product of the likelihoods for each bin in the two-dimensional histogram, as shown in Eq.~\ref{bins}.

\begin{equation}
\label{bins}
\mathcal{L}(N|\sigma_{S},\alpha_{S}, \vec{n}_{B}) \rightarrow \prod_{\rm{Bins}\{j\}} \mathcal{L}(N_{j}|\sigma_{S},\alpha_{S,j}, \vec{n}_{B,j})
\end{equation}

The acceptance and background yield dependence on the posterior are removed by integrating the likelihood and prior with respect to the signal acceptance and each background yield, as shown in Eq.~\ref{remove}.

\begin{equation}
\label{remove}
P(\sigma|N) = \frac{1}{P(N)} \int \int \mathcal{L}(N|\sigma_{S},\alpha^{'}_{S}, \vec{n}^{'}_{B}) \times \pi(\sigma_{S}) \times \pi(\alpha^{'}_{S}, \vec{n}^{'}_{B}) ~ d\alpha^{'}_{S} d\vec{n}^{'}_{B}
\end{equation}

\noindent The term $P(N)$ is the posterior normalization such that the posterior retains a probability density function interpretation (i.e~$\int P(\sigma|N) \rm{d}\sigma = 1$~). To ensure that the normalization is finite the prior for the signal cross section $\pi(\sigma_{S})$ is cut off at a maximum value, $\sigma_{\rm{max}}$. The prior is flat in the region of $0<\sigma<\sigma_{\rm{max}}$ and zero beyond this region.\footnote{A flat prior represents a minimal bias towards any signal cross section.} The value of $\sigma_{\rm{max}}$ is chosen to be large enough such that beyond that limit the likelihood is negligibly small for all $\alpha_{S}$ and $\vec{n}_{B}$.

The prior $\pi(\alpha^{'}_{S}, \vec{n}^{'}_{B})$ is defined separately for the case of no systematics uncertainties and complete systematics. Both cases are described in the following section.

\subsection{Prior Definition With and Without Systematic Uncertainties}

\subsubsection{Prior Without Systematics}

In the case of no systematic uncertainties the signal acceptance and background yields are perfectly known. This requires the prior to be a product of two delta functions, as shown in Eq.~\ref{priornosys}, and leads to a posterior shown in Eq.~\ref{postnosys}.

\begin{equation}
\label{priornosys}
\pi(\alpha^{'}_{S}, \vec{n}^{'}_{B})=\delta(\alpha^{'}_{S}-\alpha_{S})\times\delta(\vec{n}^{'}_{B}-\vec{n}_{B})
\end{equation}

\begin{equation}
\label{postnosys}
P(\sigma|N) = \frac{\mathcal{L}(N|\sigma_{S},\alpha_{S}, \vec{n}_{B}) \times \pi(\sigma_{S})}{\int \mathcal{L}(N|\sigma^{'}_{S},\alpha_{S}, \vec{n}_{B}) \times \pi(\sigma^{'}_{S})~d\sigma^{'}_{S}}
\end{equation}

\subsubsection{Prior With Systematics}

In the case of systematic uncertainties the prior is modified to reflect the uncertainty in $\alpha_{S}$ and $\vec{n}_{B}$. For each systematic uncertainty the $\pm$1$\sigma$~uncertainty is propagated through the analysis resulting in a $\pm$1$\sigma$~uncertainties for the signal acceptance~($\delta\alpha_{S}$) and the background yield~($\delta\vec{n}_{B}$). From these values a covariance matrix is created, which accounts for all correlations between systematics (e.g. the uncertainty in the integrated luminosity affects both the signal acceptance and the $\ttbar$ normalization). The covariance matrix element \{i,j\} for background or signal $i$ and $j$ is defined as

\begin{equation}
\rm{cov}_{i,j} = p_{i}p_{j} \sum_{k=1}^{m} f_{i,k}f_{j,k},
\end{equation}

\noindent where $p_{i}$ is the signal or background yield for the $i^{th}$ source and $f_{i,k}$ is the fractional uncertainty from the $k^{th}$ systematic component for the $i^{th}$ signal or background. The prior is then calculated as a multivariate Gaussian, as shown in Eq.~\ref{priorsys}.

\begin{equation}
\label{priorsys}
\pi(\alpha^{'}_{S}, \vec{n}^{'}_{B})= \frac{1}{\sqrt{(2\pi)^{N}|\Sigma|}} \mathrm{exp} \left\{ -\frac{1}{2}(\vec{x} - \mu)^{T} \Sigma^{-1} (\vec{x}-\mu) \right\}
\end{equation}

\noindent where $\Sigma$ is the covariance matrix, $\vec{x}$ represents $\{ \alpha^{'}_{S}, \vec{n}^{'}_{B} \}$, and $\mu$ represents $\{ \alpha_{S}, \vec{n}_{B} \}$

The posterior, when systematics are included, is solved using Monte Carlo importance sampling. In this method a set of points in $\{ \alpha_{S}, \vec{n}_{B} \}$-space are generated according the prior density defined in Eq.~\ref{priorsys}. The solution to the posterior is given by

\begin{equation}
\label{mcint}
\int \int \mathcal{L}(N|\sigma_{S},\alpha_{S}, \vec{n}_{B}) \times \pi(\alpha_{S}, \vec{n}_{B}) ~ d\alpha_{S}d\vec{n}_{B} = \frac{1}{K} \sum_{i=1}^{K} \mathcal{L}(N|\sigma_{S},\alpha_{S}, \vec{n}_{B})
\end{equation}

A discussion of the systematic uncertainties and their magnitudes can be found in Section~\ref{systematics} of this chapter.

\subsection{Cross Section Extraction}

If there is an excess of data events over the expected background yield then it is possible to determine the production cross section for a given process. The cross section is defined as the value which maximizes the posterior, as seen in Fig.~\ref{CrossSection}. The solid blue line represents the cross section (3.9 pb) and the dashed-blue lines represent the $\pm1\sigma$ uncertainty on the cross section. The uncertainties are calculated by integrating the posterior curve until 33.15$\%$ of the area is contained on each side of the cross section. In the case of Fig.~\ref{CrossSection} the $+1\sigma$ error band covers 2.3~pb above the cross section and the $-1\sigma$ error band covers 2.2~pb below the cross section.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Limits/CrossSection.eps}
\end{center}
\vspace{-0.1in}
\caption{Example cross section measurement (solid blue line) with $\pm1\sigma$ error band (dashed blue lines).}
\label{CrossSection}
\end{figure}

If there is no excess of data above the background, then upper limits on the production cross section can be set. An upper cross section limit, $\sigma_{\rm{CL}}$, at a given confidence level is found by integrating the posterior until an area equal to the confidence level is obtained, as shown in Eq.~\ref{cl}. Fig.~\ref{CrossSectionLimit} shows the cross section limit for the same posterior shown in Fig.~\ref{CrossSection}. The limit is 8.4 pb at 95$\%$~CL.

\begin{equation}
\label{cl}
\int_{0}^{\sigma_{\rm{CL}}} P(\sigma|N)~d\sigma = CL
\end{equation}

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Limits/Limit.eps}
\end{center}
\vspace{-0.1in}
\caption{Example of the 95$\%$~CL upper cross section limit. The value of the upper limit is shown by the blue curve. For this posterior the cross section limit is 8.4 pb.}
\label{CrossSectionLimit}
\end{figure}

Finally, a quantity used to optimize the sensitivity of a particular analysis channel is the Bayes ratio. This quantity is an approximation to the Bayes factor which is the likelihood for the case of signal+background divided by the background only likelihood. The Bayes ratio is defined as the ratio of the posterior at its maximum over the posterior at zero cross section. The larger the Bayes ratio the more sensitive a channel is to measure a cross section different from zero. This is shown graphically in Fig.~\ref{BayesRatio} for the same posterior curve used in the previous two figures.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Limits/BayesRatio.eps}
\end{center}
\vspace{-0.1in}
\caption{Example of the Bayes ratio defined as the maximum of the posterior (top blue line) over the posterior at zero cross section (lower blue line). The Bayes ratio for this curve is 5.0.}
\label{BayesRatio}
\end{figure}

\subsection{$s+t$-channel Cross Section Definition}

All cross sections presented in this thesis are the combined $s$-channel plus $t$-channel cross section. In this case the ratio of $s/t$-channel cross sections ($0.88/1.98=0.44$) is assumed to be consistent with the Standard Model. With an increased dataset a measurement of the individual $s$-channel and $t$-channel cross sections will be a future addition to this analysis.

\clearpage
\section{Systematic Uncertainties}
\label{systematics}
\label{sysdescription}

This section describes all systematic uncertainties considered in the matrix element analysis. In most cases the uncertainty source applies both to the signal acceptance ($\alpha$) and the background expectation ($n_{B}$). The other systematics are only applied to certain backgrounds as explained in the following text. Two sources of systematic uncertainties (jet energy scale and tag-rate functions) are referred to as  ``shape changing'' systematics, while the rest solely affect the signal or background normalization and are referred to as ``flat'' systematics. Flat systematics have a uniform uncertainty across all bins of the matrix element discriminant, while shape changing systematics vary bin-to-bin. Table~\ref{tab:generalsys} summarizes the relative uncertainties due to each systematic source\footnote{Appendix~\ref{allsys}~shows the uncertainties for each background yield and signal acceptance for each analysis channel.}. The effect of each systematic uncertainty on the measured single top cross section can be found in Chapter~\ref{results}.

\vspace{-0.1in}
\begin{table}[h]
\begin{center}
\caption{A summary of the relative systematic uncertainties
for each of the applied corrections and efficiencies. The uncertainty
shown is the error on the correction or the efficiency, before it has
been applied to the MC or data samples.}
\label{tab:generalsys}
\begin{tabular}{c|c||c|c}
%\multicolumn{4}{c}{\underline{Relative Systematic Uncertainties}}\\
\hline
{\ttbar} cross section		& $18\%$		& Primary vertex                    			&  $3\%$  \\
Luminosity                      	&  $6\%$  		& Electron reco * ID                			&  $2\%$  \\
Electron trigger                   & $3\%$   		& Electron trackmatch \& likelihood 		&  $5\%$  \\
Muon trigger                       	& $6\%$   		& Muon reco * ID                    			&  $7\%$  \\
Jet energy scale               	&wide range	& Muon trackmatch \& isolation      		&  $2\%$  \\
Jet efficiency                     	& $2\%$  		& Electron~$\varepsilon_{\rm{W+jets}}$ 	&  $2\%$  \\
Jet fragmentation              	& 5--7$\%$	& Muon~$\varepsilon_{\rm{W+jets}}$    	&  $2\%$  \\
Heavy flavor ratio             	& $30\%$  	& Electron~$\varepsilon_{\rm{Multijet}}$ 	&3--40$\%$\\
Tag-rate functions             	&2--16$\%$	& Muon~$\varepsilon_{\rm{Multijet}}$    	&2--15$\%$
\end{tabular}
\end{center}
\end{table}

\begin{itemize}
\item {\bf Integrated luminosity} \\
The error on the integrated luminosity used in the analysis is $6.1\%$. This uncertainty comes from the error on the measured inelastic $\ppbar$~cross section. The error on the luminosity estimate affects the $\ttbar$ background since this background is normalized using the integrated luminosity.

\item {\bf Theoretical cross sections} \\
The $\ttbar$ background yield is normalized to the NLLO theoretical cross section. The uncertainty of this cross section for a top mass of 175~GeV is $18\%$. The uncertainty on the cross section is mainly due to the uncertainty from the top mass, but also from the choice of scale and parton distribution function uncertainties.

\item {\bf Trigger efficiency} \\
The uncertainty on the trigger efficiency is determined by varying the trigger term efficiencies at each trigger level by the $\pm1\sigma$ uncertainties. A total uncertainties of $3\%$ was assigned to the $e$+jets trigger and $6\%$ to the $\mu$+jets trigger. Fig.~\ref{triggeruncer} shows the affect of the $\pm1\sigma$~shift in the $e$+jets trigger efficiency on the electron $p_{T}$ in $\dilepton$ Monte Carlo events.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Systematics/trigger.eps}
\end{center}
\vspace{-0.1in}
\caption{Electron $p_{T}$ in weighted $\dilepton$ Monte Carlo events. The three curves represent the estimated yield in each $p_{T}$ bin for the case of $+1\sigma$ trigger weights (red), nominal trigger weights (black), and $-1\sigma$ trigger weights (blue).}
\label{triggeruncer}
\end{figure}

\item {\bf Primary vertex selection efficiency} \\
The longitudinal position of the primary interaction vertex is not well modeled in the Monte Carlo. The maximum deviation between the data and Monte Carlo is $3\%$ thus this number was taken as the systematic uncertainty. This uncertainty accounts for the beam profile along the longitudinal direction~\cite{beamshifts}.

\item {\bf Jet reconstruction and identification} \\
This systematic is due to the difference between the data and Monte Carlo for the $\eta$ and number of jets distributions. A $2\%$ uncertainty is assigned to this effect.

\item {\bf Jet energy scale (JES) and jet energy resolution} \\
The JES correction is raised and lowered by one standard deviation and
the whole analysis is repeated. In the data the JES uncertainty
contains the jet energy resolution uncertainty; however, in the Monte Carlo
the jet energy resolution uncertainty is not taken into account in the
JES uncertainty. To account for this the Monte Carlo energy smearing
is varied by the size of the jet energy resolution in MC. This
uncertainty affects the acceptance and the shapes of the
distributions. The $1\sigma$ error on the JES as a function of jet $p_{T}$ for central jets is shown in Fig.~\ref{jes2}. The JES uncertainty is larger for lower $p_{T}$ and more forward jets.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Systematics/jes.eps}
\end{center}
\vspace{-0.1in}
\caption{$1\sigma$~uncertainties from each of the jet energy scale components as a function of jet $p_{T}$ for jets with $\eta=0.0$. The total uncertainty is shown by the black line. }
\label{jes2}
\end{figure}

\item {\bf Jet fragmentation} \\
The uncertainty of the jet fragmentation model is determined by the difference in fragmentation models between the Pythia and Herwig Monte Carlo generators. This uncertainty also covers the uncertainties due to initial and final state radiation. The total uncertainty is $5\%$ for $\dilepton$ and single top quark events and $7\%$ for $\lepjets$~events.

\item {\bf Electron reconstruction and identification efficiency} \\
This uncertainty derives from the error on the electron reconstruction Monte Carlo correction factor. The uncertainty is determined by varying the correction factor by $1\sigma$ in the parameterized bins of $p_{T}$ and $\phi$. The total uncertainty is determined to be $2\%$.

\item {\bf Electron track matching and likelihood efficiency} \\
This uncertainty derives from the error on the electron track match and likelihood Monte Carlo correction factor. The uncertainty is determined by varying the correction factor by $1\sigma$ in the parameterized bins of $\eta$ and $\phi$. The total uncertainty is determined to be $5\%$.

\item {\bf Muon reconstruction and identification efficiency} \\
This uncertainty derives from the error on the muon reconstruction Monte Carlo correction factor. The uncertainty is determined by varying the correction factor by $1\sigma$ in the parameterized bins of $\eta$ and $\phi$. The total uncertainty is determined to be $7\%$.

\item {\bf Muon track matching and isolation} \\
This uncertainty derives from the error on the muon track match and isolation Monte Carlo correction factor. The uncertainty is determined by varying the correction factor by $1\sigma$ in the parameterized bins of $\eta$ and $\phi$ for the track match factor and $p_{T}$ and the number of jets for the isolation factor. The total uncertainty is determined to be $2\%$.

\item {\bf Matrix method normalization} \\
The normalization of the W+jets and multijet backgrounds is performed using the matrix method and its error is dominated by the error on the efficiency that a lepton not originating from a $W$ decay will pass the electron likelihood or muon isolation cut ($\delta\varepsilon_{\rm{Multijet}}$). The statistics of the normalized samples also contributes to the total uncertainty. The average values and errors for $\varepsilon_{\rm{Multijet}}$ for both electron and muon events is shown in Table~\ref{eps-qcd}.

\begin{table}[!h!tbp]
\begin{center}
\caption{$\varepsilon_{\rm{Multijet}}$ for electrons as a function of
the trigger period and jet multiplicity, and $\varepsilon_{\rm{Multijet}}$ for muons averaged over $\eta$. The definition of the trigger periods is found in Chapter~\ref{analysis}.}
\label{eps-qcd}
\begin{tabular}{c|ccccc|c}
%\multicolumn{7}{c}{\hspace{0.8in}\underline{Fake-Lepton Probabilities}}
%\vspace{0.05in}\\
& \multicolumn{5}{c|}{ Electron $\varepsilon_{\rm{Multijet}}$ For Five Trigger Periods ($\%$)} & \multicolumn{1}{c}{ Muon $\varepsilon_{\rm{Multijet}}$  ($\%$)} \\
Jets & I   &     II     &     III    &     IV    &     IV     &     I \\
\hline
 2 & $12.8 \pm 1.0$ & $19.2 \pm 1.0$ & $18.8 \pm 2.2$ & $19.4 \pm 1.1$ & $22.0 \pm 1.2$ & $35.8 \pm 3.2$ \\
 3 & $13.6 \pm 1.5$ & $19.5 \pm 1.6$ & $19.8 \pm 3.4$ & $19.2 \pm 1.6$ & $19.4 \pm 1.7$ & $34.2 \pm 4.5$ \\
\end{tabular}
\vspace{-0.1in}
\end{center}
\end{table}

\item {\bf Ratio of $Wb\bar{b}+Wc\bar{c}$ to $Wjj$ Events} \\
There is a $30\%$ systematic error due to the uncertainty on this ratio. The error is much larger than the fit to the events in the zero tag sample to account for theoretical shape-dependent errors that are not modeled in the Monte Carlo. The largest of these theoretical errors is the shape change to the $b$-quark $p_{T}$ between NLO and LO $Wbb$ events. The error on this ratio is folded into the overall matrix method normalization uncertainty when determining the acceptance and background yield uncertainties.

\item {\bf Monte Carlo tag-rate functions}\\
The uncertainty associated with the tag-rate functions is evaluated by shifting the TRFs by $\pm1\sigma$ and evalulating the change in the signal acceptance and background yield. The tag-rate function uncertainties are dominated by the assumed fraction of heavy flavor in the multijet samples used to determine the fake tagging rate in data and the decreased statistics in each bin due the parameterization in $p_{T}$ and $\eta$. The tag rate functions for $B$-jets and charm-jets and the $1\sigma$~error bands are shown in Fig.~\ref{trfserror2}. The total uncertainty depends heavily on the number of $B$-tagged jets in the event.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.48\textwidth]{eps/Systematics/trf_b_0.775_pt.eps}
\includegraphics[width=0.48\textwidth]{eps/Systematics/trf_b_0.775_eta.eps}
\includegraphics[width=0.48\textwidth]{eps/Systematics/trf_c_0.775_pt.eps}
\includegraphics[width=0.48\textwidth]{eps/Systematics/trf_c_0.775_eta.eps}
\end{center}
\vspace{-0.1in}
\caption{Neural network $B$-jet tagger efficiency (green line) and $1\sigma$~error bands (dashed lines) jet $p_{T}$ and $\eta$ for $B$-jets (upper row) and charm-jets (lower row). The red lines represent the efficiency of the $B$-tagging algorithm when applied directly to the Monte Carlo.}
\label{trfserror2}
\end{figure}

\end{itemize}

\clearpage
\section{Ensemble Testing}
\label{ensembles}

Ensemble tests are performed to ensure there is no bias in the measured cross section. An ensemble is a group of pseudo-datasets created with a known fraction of signal and background events. Since the fractions are known the linearity of the measured cross section can be tested against the known cross section.

The ensembles are generated from a large set of weighted signal and background events. For each analysis channel the total background yield, as shown in Chapter~\ref{background}, is used as the expected value of a Poisson distribution and a new background yield is generated from this distribution. The uncertainty in the yield due to systematics is included when generating a new background and signal yield as explained in Appendix~\ref{ensemblegeneration}. This procedure will on average produce the expected background compositeness (e.g. ratio of Wbb to Wjj events). The cross section is then determined for all psuedo-datasets in the ensemble.

Five ensembles were generated with the following $s+t$-channel input signal cross sections:

\begin{itemize}
\item $\sigma_{s+t} = 2$~pb.
\item $\sigma_{s+t} = 2.9$~pb. (Expected Standard Model cross section)
\item $\sigma_{s+t} = 4$~pb.
\item $\sigma_{s+t} = 6$~pb.
\item $\sigma_{s+t} = 8$~pb.
\end{itemize}

\noindent 2,000 datasets were generated in each ensemble. A histogram of the measured cross sections for each of these ensembles is shown in Fig.~\ref{blue}. A plot of the mean of these histograms versus the input cross section is shown in Fig.~\ref{linearity}. A linear fit to the data points yields a good $\chi^{2}$/dof of 0.13/3, a slope consistent with 1 of $1.03\pm0.03$, and an offset of $0.32\pm0.09$.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.48\textwidth]{eps/Limits/Blue2.0.eps}
\includegraphics[width=0.48\textwidth]{eps/Limits/Blue2.9.eps}
\includegraphics[width=0.48\textwidth]{eps/Limits/Blue4.0.eps}
\includegraphics[width=0.48\textwidth]{eps/Limits/Blue6.0.eps}
\includegraphics[width=0.48\textwidth]{eps/Limits/Blue8.0.eps}
\end{center}
\vspace{-0.1in}
\caption{Observed cross section for a set of 2,000 pseudo-datasets for the five ensembles: $\sigma_{s+t}=2.0$~pb (upper left), $\sigma_{s+t}=2.9$~pb (upper right), $\sigma_{s+t}=4.0$~pb (middle left), $\sigma_{s+t}=6.0$~pb (middle right), and $\sigma_{s+t}=8.0$~pb (bottom middle)}
\label{blue}
\end{figure}

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Limits/Linearity.eps}
\end{center}
\vspace{-0.1in}
\caption{Response of the five generated ensemble sets versus input cross section. The response is measured as the mean value of the histogram for each ensemble.}
\label{linearity}
\end{figure}

\clearpage
\section{Expected Results}
\label{exp-performance}

This section presents the expected performance of the analysis given a Standard Model single top signal. To test the expected sensitivity the number of data events is set equal to the number of signal and background events in each bin of the Likelihood (i.e. the excess of data over background in each bin is equal, by construction, to the number of events expected from a signal with $\sigma=2.9$ pb). This test is performed for each analysis channel and various combinations of the channels. Figs.~\ref{exp-post-1d-2j} and \ref{exp-post-1d-3j} show the
resulting $tb$+$tqb$\footnote{$tb+tqb$ is used to donate the combined $s$-channel plus $t$-channel cross section measurement} posterior for the combined $e$+$\mu$ $\geq$~1
$B$-tag channel in two-jet and three-jet events.
Figure~\ref{exp-post-1d-allj} shows the $tb$+$tqb$ posterior for the
combination of all channels. The figures on the left correspond to the case
of only statistical uncertainties, whereas the figures on the right include statistical and systematic uncertainties.

\vspace{0.1in}
\begin{figure}[!h!tbp]
\includegraphics[width=0.49\textwidth]
{eps/MatrixElement/posterior/nosys/expected_limit_TBTQ_LeptonsCombined_2Jet_TagsCombined}
\includegraphics[width=0.49\textwidth]
{eps/MatrixElement/posterior/sys/expected_limit_TBTQ_LeptonsCombined_2Jet_TagsCombined}
\vspace{-0.1in}
\caption{Expected 1D posterior plots for the combined
$e$+$\mu$ $\geq$~1 $B$-tag channel in two-jet events, with statistical
uncertainties only (left plot) and including also systematic
uncertainties (right plot).}
\label{exp-post-1d-2j}
\end{figure}

\vspace{0.1in}
\begin{figure}[!h!tbp]
\includegraphics[width=0.49\textwidth]
{eps/MatrixElement/posterior/nosys/expected_limit_TBTQ_LeptonsCombined_3Jet_TagsCombined}
\includegraphics[width=0.49\textwidth]
{eps/MatrixElement/posterior/sys/expected_limit_TBTQ_LeptonsCombined_3Jet_TagsCombined}
\vspace{-0.1in}
\caption{Expected 1D posterior plots for the combined
$e$+$\mu$ $\geq$~1 $b$-tag channel in three-jet events, with
statistical uncertainties only (left plot) and including also
systematic uncertainties (right plot).}
\label{exp-post-1d-3j}
\end{figure}

\vspace{0.1in}
\begin{figure}[!h!tbp]
\includegraphics[width=0.49\textwidth]
{eps/MatrixElement/posterior/nosys/expected_limit_TBTQ_LeptonsCombined_JetsCombined_TagsCombined}
\includegraphics[width=0.49\textwidth]
{eps/MatrixElement/posterior/sys/expected_limit_TBTQ_LeptonsCombined_JetsCombined_TagsCombined}
\vspace{-0.1in}
\caption{Expected 1D posterior plots for the
combination of all channels, with statistical uncertainties only (left
plot) and including also systematic uncertainties (right plot).}
\label{exp-post-1d-allj}
\end{figure}

Table~\ref{tab:expxsecs} shows the expected cross sections for various
combinations of analysis channels. The expected result for each
combination is consistent with the standard model cross
section. Table~\ref{exp-errors} summarizes the relative uncertainty on
the expected $tb$+$tqb$ cross section measurement, defined as half the
width of the $tb$+$tqb$ posterior, divided by the cross section value
at the posterior peak.

\begin{table}[!h!tbp]
\begin{center}
\caption{Expected $tb$+$tqb$ cross sections, without and
with systematic uncertainties, for many combinations of the analysis
channels. The final expected result of this analysis are shown in the
lower right hand corner in bold type.}
\label{tab:expxsecs}
\begin{tabular}{c|cc|cc|cc|c}
%  \multicolumn{8}{c}{\hspace{0.5in}\underline{Expected $tb$+$tqb$ Cross Section}}\vspace{0.1in}\\
& \multicolumn{2}{c|}{1,2tags + 2,3jets}& \multicolumn{2}{c|}{$e$,$\mu$ + 2,3jets}
& \multicolumn{2}{c|}{$e$,$\mu$ + 1,2tags}& All \\
                 &  $e$-chan & $\mu$-chan& 1 tag & 2 tags& 2 jets& 3 jets&channels\\
\hline
Statistics only  &  $2.8^{+1.5}_{-1.4}$  & $2.8^{+1.8}_{-1.7}$ & $2.9^{+1.3}_{-1.2}$ & $2.8^{+2.5}_{-2.2}$ & $2.9^{+1.4}_{-1.3}$ & $2.8^{+2.2}_{-2.1}$ & $2.9^{+1.2}_{-1.1}$ \\
With systematics &  $3.0^{+2.2}_{-1.8}$  & $3.1^{+2.5}_{-2.1}$ & $2.9^{+1.8}_{-1.6}$ & $2.7^{+3.4}_{-2.7}$ & $2.9^{+1.9}_{-1.6}$ & $2.5^{+3.5}_{-2.5}$ & $\mathbf{3.0^{+1.8}_{-1.5}}$ \\
\end{tabular}
\vspace{-0.1in}
\end{center}
\end{table}

\vspace{-0.1in}
\begin{table}[!h!tbp]
\begin{center}
\caption{Relative uncertainties on the expected
$tb$+$tqb$ cross section, without and with systematic uncertainties,
for many combinations of the analysis channels. The best value from
all channels combined, with systematics, is shown in bold type.}
\label{exp-errors}
\begin{tabular}{l|cc|cc|cc|c}
%  \multicolumn{8}{c}{\hspace{0.5in}\underline{Relative Uncertainties on the Expected $tb$+$tqb$ Cross Section}}\vspace{0.1in}\\
& \multicolumn{2}{c|}{1,2tags + 2,3jets}& \multicolumn{2}{c|}{$e$,$\mu$ + 2,3jets}
& \multicolumn{2}{c|}{$e$,$\mu$ + 1,2tags}& All \\
                 &  $e$-chan & $\mu$-chan& 1 tag & 2 tags& 2 jets& 3 jets&channels\\
\hline
Statistics only  &  $52\%$  & $60\%$ & $45\%$ & $83\%$  &  $46\%$  & $75\%$  & $41\%$     \\
With systematics &  $67\%$  & $75\%$ & $59\%$ & $115\%$ &  $60\%$  & $121\%$ & $\mathbf{55\%}$     \\
\end{tabular}
\vspace{-0.1in}
\end{center}
\end{table}


\chapter{Electronic transport calculations with the \bw\ module}\label{ch:boltzwann}

By setting $\verb#boltzwann#=\verb#TRUE#$, \postw\ will call the \bw\ routines to calculate some transport coefficients using the Boltzmann transport equation in the relaxation time approximation.

In particular, the transport coefficients that are calculated are: the electrical conductivity $\bvec \sigma$, the Seebeck coefficient $\bvec S$ and the coefficient $\bvec K$ (defined below; it is the main ingredient of the thermal conductivity).

The list of parameters of the \bw\ module are summarized in Table~\ref{parameter_keywords_bw}.
An example of a Boltzmann transport calculation can be found in the \wannier\ Tutorial.

\textbf{Note}: By default, the code assumes to be working with a 3D bulk material, with periodicity along all three spatial directions. If you are interested in studying 2D systems, set the correct value for the \texttt{boltz\_2d\_dir} variable (see Sec.~\ref{sec:boltz2ddir} for the documentation). This is important for the evaluation of the Seebeck coefficient.

Please cite the following paper~\cite{pizzi-cpc14} when publishing results obtained using the \bw\  module:
\begin{quote}
G. Pizzi, D. Volja, B. Kozinsky, M. Fornari, and N. Marzari, \\
\emph{BoltzWann: A code for the evaluation of thermoelectric and electronic transport properties with a maximally-localized Wannier functions basis},\\
Comp. Phys. Comm. 185, 422 (2014), DOI:10.1016/j.cpc.2013.09.015.
\end{quote}

%Reference: [BoltzWann paper]
\section{Theory}
\label{sec:boltzwann-theory}
The theory of the electronic transport using the Boltzmann transport equations can be found for instance in Refs.~\cite{ziman-book72,grosso-book00,mahan-itc06}. Here we briefly summarize only the main results.

The current density $\bvec J$ and the heat current (or energy flux density) $\bvec J_Q$ can be written, respectively, as
\begin{align}
  \bvec J   &= \bvec \sigma(\bvec E - \bvec S \bvec \nabla T) \\
  \bvec J_Q &= T \bvec \sigma \bvec S \bvec E - \bvec K \bvec \nabla T,
\end{align}
where the electrical conductivity $\bvec \sigma$, the Seebeck coefficient $\bvec S$ and $\bvec K$ are $3\times 3$ tensors, in general.

Note: the thermal conductivity $\bvec \kappa$ (actually, the electronic part of the thermal conductivity), which is defined as the heat current per unit of temperature gradient in open-circuit experiments (i.e., with $\bvec J=0$) is not precisely $\bvec K$, but  $\bvec\kappa = \bvec K-\bvec S \bvec \sigma \bvec S T$ (see for instance Eq.~(7.89) of Ref.~\cite{ziman-book72} or Eq.~(XI-57b) of Ref.~\cite{grosso-book00}).
The thermal conductivity $\bvec \kappa$ can be then calculated from the $\bvec \sigma$, $\bvec S$ and $\bvec K$ tensors output by the code.

These quantities depend on the value of the chemical potential $\mu$ and on the temperature $T$, and can be calculated as follows:
\begin{align}
  [\bvec \sigma]_{ij}(\mu,T)&=e^2 \int_{-\infty}^{+\infty} d\varepsilon \left(-\frac {\partial f(\varepsilon,\mu,T)}{\partial \varepsilon}\right)\Sigma_{ij}(\varepsilon), \\
  [\bvec \sigma \bvec S]_{ij}(\mu,T)&=\frac e T \int_{-\infty}^{+\infty} d\varepsilon \left(-\frac {\partial f(\varepsilon,\mu,T)}{\partial \varepsilon}\right)(\varepsilon-\mu)\Sigma_{ij}(\varepsilon), \label{eq:boltz-sigmas}\\
  [\bvec K]_{ij}(\mu,T)&=\frac 1 T \int_{-\infty}^{+\infty} d\varepsilon \left(-\frac {\partial f(\varepsilon,\mu,T)}{\partial \varepsilon}\right)(\varepsilon-\mu)^2 \Sigma_{ij}(\varepsilon),\label{eq:boltz-thermcond}
\end{align}
where $[\bvec \sigma \bvec S]$ denotes the product of the two tensors $\bvec \sigma$ and $\bvec S$, $f(\varepsilon,\mu,T)$ is the usual Fermi--Dirac distribution function
\begin{equation*}
  f(\varepsilon,\mu,T) = \frac{1}{e^{(\varepsilon-\mu)/K_B T}+1}
\end{equation*}
and $\Sigma_{ij}(\varepsilon)$ is the Transport Distribution Function (TDF) tensor, defined as
\begin{equation*}
  \Sigma_{ij}(\varepsilon) = \frac 1 V \sum_{n,\bvec k} v_i(n,\bvec k) v_j(n,\bvec k) \tau(n,\bvec k) \delta(\varepsilon - E_{n,k}).
\end{equation*}

In the above formula, the sum is over all bands $n$ and all states $\bvec k$ (including spin, even if the spin index is not explicitly written here). $E_{n,\bvec k}$ is the energy of the $n-$th band at $\bvec k$, $v_i(n,\bvec k)$ is the $i-$th component of the band velocity at $(n,\bvec k)$, $\delta$ is the Dirac's delta function, $V$ is the cell volume, and finally $\tau$ is the relaxation time. In the \emph{relaxation-time approximation} adopted here, $\tau$ is assumed as a constant, i.e., it is independent of $n$ and $\bvec k$ and its value (in fs) is read from the input variable \verb#boltz_relax_time#.

\section{Files}
\subsection{{\tt seedname\_boltzdos.dat}}
OUTPUT. Written by \postw\ if {\tt boltz\_calc\_also\_dos} is \verb#true#. Note that even if there are other general routines in \postw\ which specifically calculate the DOS, it may be convenient to use the routines in \bw\ setting {\tt boltz\_calc\_also\_dos = true} if one must also calculate the transport coefficients. In this way, the (time-demanding) band interpolation on the $k$ mesh is performed only once, resulting in a much shorter execution time.

The first lines are comments (starting with \# characters) which describe the content of the file.
Then, there is a line for each energy $\varepsilon$ on the grid, containing a number of columns. The first column is the energy $\varepsilon$. The following is the DOS at the given energy $\varepsilon$.
The DOS can either be calculated using the adaptive smearing scheme\footnote{%
Note that in \bw\ the adaptive (energy) smearing scheme also implements a simple adaptive $k-$mesh scheme:
if at any given $k$ point one of the band gradients is zero, then that $k$ point is replaced by 8 neighboring $k$ points. Thus, the final results for the DOS may be slightly different with respect to that given by the {\tt dos} module.} if {\tt boltz\_dos\_adpt\_smr} is \verb#true#, or using a ``standard'' fixed smearing, whose type and value are defined by {\tt boltz\_dos\_smr\_type} and {\tt boltz\_dos\_smr\_fixed\_en\_width}, respectively.
If spin decomposition is required (input flag {\tt spin\_decomp}), further columns are printed, with the spin-up projection of the DOS, followed by spin-down projection.

\subsection{{\tt seedname\_tdf.dat}}
OUTPUT. This file contains the Transport Distribution Function (TDF) tensor $\bvec \Sigma$ on a grid of energies.

The first lines are comments (starting with \# characters) which describe the content of the file.
Then, there is a line for each energy $\varepsilon$ on the grid, containing a number of columns. The first is the energy $\varepsilon$, the followings are the components if $\bvec \Sigma(\varepsilon)$ in the following order: $\Sigma_{xx}$, $\Sigma_{xy}$, $\Sigma_{yy}$, $\Sigma_{xz}$, $\Sigma_{yz}$, $\Sigma_{zz}$. If spin decomposition is required (input flag {\tt spin\_decomp}), 12 further columns are provided, with the 6 components of $\bvec \Sigma$ for the spin up, followed by those for the spin down.

The energy $\varepsilon$ is in eV, while $\bvec \Sigma$ is in
 $\displaystyle\frac{1}{\hbar^2}\cdot\frac{\mathrm{eV}\cdot\mathrm{fs}}{\text{\AA}}$.

\subsection{{\tt seedname\_elcond.dat}}
OUTPUT. This file contains the electrical conductivity tensor $\bvec \sigma$ on the grid of $T$ and $\mu$ points.

The first lines are comments (starting with \# characters) which describe the content of the file.
Then, there is a line for each $(\mu,T)$ pair, containing 8 columns, which are respectively: $\mu$, $T$, $\sigma_{xx}$, $\sigma_{xy}$, $\sigma_{yy}$, $\sigma_{xz}$, $\sigma_{yz}$, $\sigma_{zz}$. (The tensor is symmetric).

The chemical potential is in eV, the temperature is in K, and the components of the electrical conductivity tensor ar in SI units, i.e. in 1/$\Omega$/m.

\subsection{{\tt seedname\_sigmas.dat}}
OUTPUT. This file contains the tensor $\bvec\sigma\bvec S$, i.e. the product of the electrical conductivity tensor and of the Seebeck coefficient as defined by Eq.~\eqref{eq:boltz-sigmas}, on the grid of $T$ and $\mu$ points.

The first lines are comments (starting with \# characters) which describe the content of the file.
Then, there is a line for each $(\mu,T)$ pair, containing 8 columns, which are respectively: $\mu$, $T$, $(\sigma S)_{xx}$, $(\sigma S)_{xy}$, $(\sigma S)_{yy}$, $(\sigma S)_{xz}$, $(\sigma S)_{yz}$, $(\sigma S)_{zz}$. (The tensor is symmetric).

The chemical potential is in eV, the temperature is in K, and the components of the tensor ar in SI units, i.e. in A/m/K.

\subsection{{\tt seedname\_seebeck.dat}}
OUTPUT. This file contains the Seebeck tensor $\bvec S$ on the grid of $T$ and $\mu$ points.

Note that in the code the Seebeck coefficient is defined as zero when the determinant of the electrical conductivity $\bvec \sigma$ is zero. If there is at least one $(\mu, T)$ pair for which $\det \bvec \sigma=0$, a warning is issued on the output file.

The first lines are comments (starting with \# characters) which describe the content of the file.
Then, there is a line for each $(\mu,T)$ pair, containing 11 columns, which are respectively: $\mu$, $T$, $S_{xx}$, $S_{xy}$, $S_{xz}$, $S_{yx}$, $S_{yy}$, $S_{yz}$, $S_{zx}$, $S_{zy}$, $S_{zz}$.

NOTE: therefore, the format of the columns of this file is different from the other three files (elcond, sigmas and kappa)!

The chemical potential is in eV, the temperature is in K, and the components of the Seebeck tensor ar in SI units, i.e. in V/K.

\subsection{{\tt seedname\_kappa.dat}}
OUTPUT. This file contains the tensor $\bvec K$ defined in Sec.~\ref{sec:boltzwann-theory} on the grid of $T$ and $\mu$ points.

The first lines are comments (starting with \# characters) which describe the content of the file.
Then, there is a line for each $(\mu,T)$ pair, containing 8 columns, which are respectively: $\mu$, $T$, $K_{xx}$, $K_{xy}$, $K_{yy}$, $K_{xz}$, $K_{yz}$, $K_{zz}$. (The tensor is symmetric).

The chemical potential is in eV, the temperature is in K, and the components of the $\bvec K$ tensor are the SI units for the thermal conductivity, i.e. in W/m/K.


\subsection{CubeSpectrum}
\begin{description}
\item[Type:] CubeSpectrum
\item[Description:]

Produces per channel statistics on an input image cube. Output
format is a table with data described below.  In addition to
per channel output, (optional?) per cube values can also be
computed.

\item[ADMIT Task:] AT\_CubeStats \\

  Keywords: TBD

\item[Constituents:] BDP\_Table

\item[CASA Task(s):]  imstat

\item[Input BDP(s):]
Spectral cube (1 or more planes)

\item[Output BDP(s):]
\begin{verbatim}
- a table with channel dependent values:
    channel number
    freq in middle of channel
    mean
    sigma (not rms, sigma is around the mean)
    max value (i.e. peak)
    maxposx (optional)
    maxposy (optional)

- a global value for the cube
    mean
    sigma
    max
    maxposx
    maxposy
    maxposz

   This global value may be needed for CubeSpectrum

Note the difference between sigma and rms.  rms contains a bias, sigma
is N-1 normalized, rms is N normalized

######################################################################
OTHER NOTES:

# confirmed help(imstat) and this list are the same.
# ia.statistics() will by default give 17 (robust=F is default)
# is will not do median, medabsdevmed, quartile
# imstat produces a dictionary of 20 items
# (used to be 16; the minpos[f],maxpos[f] were added recently)
# !! Note that currently minpos[f],maxpos[f] are only available per cube,
#    not per slice

  CASA                      MIRIAD         NEMO
rms
medabsdevmed  "MADM"
minpos        (new)
min                         Minimum        min
max                         Maximum        max
sum                         Sum            sum
minposf       (new)
median                                     med
flux
sumsq
maxposf
trcf
quartile
npts                        Npoints        N
maxpos
mean                        Mean           mean
sigma                       rms            sigma
trc
blc
blcf

channel       -             plane          iz
velocity      -             Velocity       z
frequency     -             -              z
skewness      -             -              skew
kurtosis      -             -              kurt

imstat() and ia.statistics() will have new options to compute
statistics based on "robustly" removing signal, or finding
the normal part of the noise distribution, by using a new
filter= keyword.
Three methods ("hinges-fences", "fit-half", "chauvenet") will
initially be implemented.

Q: do we need to check the header for a beam, and do a proper
points-per-beam correction?
\end{verbatim}
\end{description}


\chapter{Human as a feedback system}

\section{Human behavior as a special case of the general feedback equation}

Let \(x ~ t\) be the input vector at time \(t\);
this vector has at least some billions of elements.
The function \(x\) represents the state of all sensors at a given time.

Let \(y ~ t\) be the control vector at time \(t\);
this vector is also big.

Let \(z~t\) be the output vector at time \(t\).

The environment feeds back a part of the output to the input.
Can the agent determine the response function?

The feedback forms memory, but see ``Memory without feedback in a neural network''.
https://www.ncbi.nlm.nih.gov/pubmed/19249281

\section{Hardwiring the concept of time}

We can transform a non-temporal behavior \(f~x = y\) into a temporal behavior \(f'~t = y'\)?

\section{Life of one neuron?}

% http://biology.stackexchange.com/questions/5306/how-do-neurons-form-new-connections-in-brain-plasticity

\section{A brain at a given time is an array function.}

A brain at a given time is an array function
having type \(\Real^\infty \to \Real^\infty\).
Each component of the input array is a signal from a sensor.
Each component of the output array goes to an actuator.

Since the brain is finite,
there must be infinitely many zeros in the input and output arrays.

\section{An array iself is also a function.}

An \(E\)-array is a function having type \(\Nat \to E\).
The input is an index.
The output is the value of the component at that index.
Subscripting denotes function application.

\section{Each brain has a maximand.}

Such maximand is a hidden function.
The brain always tries to maximize the maximand.

A differential change in brain tries to increase the maximand.
The brain follows gradient.

\section{Consider functions of length-one arrays.}

Let \(h\) be a differential change in brain.

\section{Draft}

The only way to know whether the system has learning something
is by testing it with samples the system has never seen.

Practically all machine learning cases deal with functions
that is continuous enough to form a Hilbert space.

Every classification problem in the real world can be written as \(f : I^n \to I\) for an \(n : \Nat\).
Usually \(I\) is discrete.

Consider the case where \(I = [0,1]\).
Continuous map from \(I^n\) to \(I\).
Continuous map from a hyperplane to a line.

\section{How do we relate vector functions and intelligence?}

\section{How does feedback happen in the brain?}

Feedback is due to environment and the physical laws.
When we move our hand, we see it, because the light
reflected by our hand now reaches our eyes.

The next input depends on the previous input.
\begin{align*}
    y_k &= b~x_k
    \\
    x_{k+1} &= f~x_k~y_k
\end{align*}

\section{The brain is a recurrence relation.}

This pictures the brain as a parallel dataflow computer
with clock period of a few microseconds.

% https://en.wikipedia.org/wiki/Dataflow_architecture

Let \(m\) be memory, \(x\) be senses, and \(y\) be actuators.
\begin{align*}
    m_{t+1} &= f~x_t~m_t
    \\
    y_{t+1} &= g~x_t~m_t
\end{align*}

There is also a version with implicit time.
\begin{align*}
    m' &= f~x~m
    \\
    y' &= g~x~m
\end{align*}

There is also a continuous version.
\begin{align*}
    m_{t+h} &= h \cdot f~x_t~m_t
    \\
    y_{t+h} &= h \cdot g~x_t~m_t
\end{align*}

\section{The brain evolved from simpler nervous systems.}

Nervous systems are control systems.

Nervous systems must have provided some evolutionary benefit;
otherwise natural selection would have phased them out.

Bacterial chemotaxis detects chemical concentration difference.

Nematode.
Caenorhabditis elegans.


\documentclass[a4paper,11pt]{article}
\usepackage{latexsym,amssymb}
\usepackage{array}
\usepackage{amsmath}
 \usepackage{graphicx}
\usepackage{setspace}
\usepackage{mathtools}
\usepackage{sectsty}
\usepackage{tocloft}
\usepackage{amsthm}
\usepackage{float}
\usepackage[hidelinks]{hyperref}
\usepackage{semantic}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{shadings}
\usepackage{fancyhdr}
\usepackage{physics}
\usepackage{pgfplots}

%Plot settings
\pgfplotsset{my style/.append style={axis x line=middle, axis y line=
           middle, xlabel={$x$}, ylabel={$y$}, axis equal }}

\setlength{\textwidth}{450pt}
\setlength{\textheight}{720pt}
\setlength{\topmargin}{-50pt}
\setlength{\oddsidemargin}{12pt}
\setlength{\parskip}{1pt plus 1pt}
\setlength{\mathsurround}{1pt}
\renewcommand{\baselinestretch}{1.05}

\setcounter{secnumdepth}{2}
\setcounter{secnumdepth}{0}
\sectionfont{\Large}
\subsectionfont{\fontsize{12}{8}\selectfont}

\renewenvironment{proof}{{\bfseries Proof.}}{\hfill $\square$}
\renewcommand*{\d}{\mathop{\kern5pt\mathrm{d}}\!{}}
\newcommand*\Eval[3]{\left.#1\right\rvert_{#2}^{#3}}
\newcommand{\floor}[1]{\lfloor #1 \rfloor}
\newcommand{\dotp}{\boldsymbol{\cdot}}
\newtheorem{theorem}{\indent\sc Theorem}[section]
\newtheorem{lemma}{\indent\sc Lemma}[section]
\newcommand{\Thmstop}{\hglue-6pt.\kern6pt}

\DeclareMathOperator{\R}{\mathbb{R}}
\DeclareMathOperator{\N}{\mathbb{N}}
\DeclareMathOperator{\Z}{\mathbb{Z}}
\DeclareMathOperator{\Q}{\mathbb{Q}}
\DeclareMathOperator{\C}{\mathbb{C}}

\onehalfspacing
\begin{document}
\begin{titlepage}
    \begin{center}
    \huge{\bfseries Course Name: HW \#}\\
         \vspace{0.5cm}
    \large{Name}\\
    \large{Student ID}\\
     \large{Date}\\
    \end{center}
    \begin{center}
    	\tableofcontents
    \end{center}
\end{titlepage}

\pagestyle{fancy}
\fancyhf{}
\rhead{Header}
\cfoot{Page \thepage}

\section{Question 1}
Let $a_n = \dfrac{18n^5+2n-5}{6n^5-n^3-3}$. We want to show that $(\forall \epsilon > 0)(\exists K \in \N)[n \geq K \Rightarrow |a_n-3| < \epsilon]$. \\\\
We have:
\begin{align*}
\left|\dfrac{18n^5+2n-5}{6n^5-n^3-3} - 3\right| &= \left|\dfrac{18n^5+2n-5 - 3(6n^5-n^3-3)}{6n^5-n^3-3}\right| \\
&= \left|\dfrac{3n^3+2n+4}{6n^5-n^3-3}\right| \\
&< \left|\dfrac{3n^3+3n^3+4n^3}{6n^5-n^3-3}\right| && \text{\small(as for $n \in \N$, $2n < 3n \leq 3n^3$ and $4 \leq 4n \leq 4n^3$)} \\
&\leq \left|\dfrac{10n^3}{6n^5-n^5-3n^5}\right| && \text{\small(as for $n \in \N$, $n^5 \geq n^3$ and $3n^5 \geq 3$)} \\
&=\left|\dfrac{10n^3}{2n^5}\right| \\
&=\left|\dfrac{5}{n^2}\right| \\
&=\dfrac{5}{n^2} && \text{$(*)$}
\end{align*}
Note that for $\epsilon > 0$ and $n > 0$, $\dfrac{5}{n^2} < \epsilon \iff n > \sqrt{\dfrac{5}{\epsilon}}$. \\
\begin{proof}
Let $\epsilon > 0$ be given. By the Archimedean property of $\R$, $\exists K \in \N$ such that $K >  \sqrt{\dfrac{5}{\epsilon}}$. Then for all $n \geq K$, we have:
\begin{align*}
\left|\dfrac{18n^5+2n-5}{6n^5-n^3-3} - 3\right| &< \dfrac{5}{n^2} && \text{(by $(*))$} \\
&\leq \dfrac{5}{K^2} && \text{(since $n \geq K$)} \\
&< \dfrac{5}{\left(\dfrac{5}{\epsilon}\right)} && \text{(since $K > \sqrt{\dfrac{5}{\epsilon}}$)} \\
&= \epsilon \\
\end{align*}
Hence, we have $\lim\limits_{n \to \infty}{\dfrac{18n^5+2n-5}{6n^5-n^3-3}} = 3$, as required.
\end{proof}

\section{Question 2}
Let $a$ be the common limit of the subsequences. We want to show that $(\forall \epsilon > 0)(\exists K \in \N)[n \geq K \Rightarrow |a_n-a| < \epsilon]$. \\\\
We know that:
$$(\forall \epsilon > 0)(\exists K_1 \in \N)[k \geq K_1 \Rightarrow |a_{2k}-a| < \epsilon]$$
$$(\forall \epsilon > 0)(\exists K_2 \in \N)[k \geq K_2 \Rightarrow |a_{4k-1}-a| < \epsilon]$$
$$(\forall \epsilon > 0)(\exists K_3 \in \N)[k \geq K_3 \Rightarrow |a_{4k-3}-a| < \epsilon]$$

We also note that these 3 subsequences partition $(a_n)$. This is because the integers can be partitioned into the equivalences classes of $\Z_4$. When $n$ is even, we have the union of equivalence classes $[0] \cup [2]$. In other words, if we only look at the positive, even values of $n$, we get the sequence $(a_{2k})$. If n is odd, we have the union of equivalence classes $[1] \cup [3]$. In other words, if we only look at the positive, odd values of $n$, we get either the sequence $(a_{4k-1})$ or $(a_{4k-3})$. \\

\begin{proof}
Let $\epsilon > 0$ be given. Let $K = \max\{2K_1, 4K_2-1, 4K_3-1\}$. Then for all $n \geq K$, we have:
\[ \begin{cases}
	|a_n-a| = |a_{2k}-a| < \epsilon & \text{if } n = 2k \text{	(since $k = \frac{n}{2} \geq \frac{K}{2} \geq K_1$)} \\
      	|a_n-a| = |a_{4k-1}-a| < \epsilon & \text{if } n = 4k-1 \text{	(since $k = \frac{n+1}{4} \geq \frac{K+1}{4} \geq K_2$)} \\
      	|a_n-a| = |a_{4k-3}-a| < \epsilon & \text{if } n = 4k-3 \text{	(since $k = \frac{n+3}{4} \geq \frac{K+3}{4} \geq K_3$)} \\
\end{cases}
\]
\end{proof}

\section{Question 3}
Note that $$x_1 = 6, x_2 = 5.33, x_3 = 5.12, x_4 = 5.05, x_5 = 5.02, x_6 = 5.01, ...$$
\begin{proof}
We first show that $x_n \geq 5$ for all $n \in \N$. Let $P(n)$ be the statement that $x_n \geq 5$. Clearly, $P(1)$ holds, as $x_{1} = 6 \geq 5$. Assume $P(k)$ holds, i.e. $x_k \geq 5$. Then $x_{k+1} = \dfrac{8x_k}{3+x_k} = 8 - \dfrac{24}{3+x_k} \geq 8 - \dfrac{24}{3+5}$, which gives $x_{k+1} \geq 5$. So, $P(k+1)$ holds. Thus, by the principle of mathematical induction,  $x_n \geq 5$ for all $n \in \N$, i.e., $(x_n)$ is bounded below by 5. \\\\
Now we show that $x_n$ is decreasing for all $n \in \N$. Let $D(n)$ be the statement $x_{n+1} \leq x_{n}$. Then, since $x_2 = \dfrac{48}{9} \leq 6$, $D(1)$ holds. Assume $D(k)$ holds, i.e. $x_{k+1} \leq x_{k}$. Then $x_{k+2} - x_{k+1} = \dfrac{8x_{k+1}}{3+x_{k+1}} - \dfrac{8x_{k}}{3+x_{k}} = \dfrac{24(x_{k+1}-x_{k})}{(3+x_{k+1})(3+x_{k})}$. Note that $(3+x_{k+1})(3+x_{k}) \geq 0$, since $x_k \geq 5$ for all $k \in \N$, and by our induction hypothesis, $x_{k+1}-x_{k} \leq 0$. Thus, $\dfrac{24(x_{k+1}-x_{k})}{(3+x_{k+1})(3+x_{k})} \leq 0$. So, $D(k+1)$ holds. Thus, by the principle of mathematical induction,  $x_{n+1} \leq x_{n}$ for all $n \in \N$, i.e., $x_n$ is decreasing. \\\\
Since $(x_n)$ is decreasing and bounded below, by Corollary 3.3.2(ii), it follows from the Monotone Convergence Theorem that $(x_n)$ converges. Let $\lim\limits_{n \to \infty}{x_{n}} = x \in \R$. By Theorem 3.4.1, as $(x_{n+1})$ is a subsequence of $(x_n)$, we know that  $\lim\limits_{n \to \infty}{x_{n+1}} = \lim\limits_{n \to \infty}{x_{n}} = x$. Hence,
\begin{align*}
x = \lim\limits_{n \to \infty}{x_{n+1}} &= \lim\limits_{n \to \infty}{\dfrac{8x_n}{3+x_n}} \\
&= \dfrac{\lim\limits_{n \to \infty}{8x_n}}{\lim\limits_{n \to \infty}{3+x_n}} && \text{(as $x_n$ is bounded below by 5, so $3+x_n \neq 0$ for any $n$)} \\
&= \dfrac{8\cdot\lim\limits_{n \to \infty}{x_n}}{3+\lim\limits_{n \to \infty}{x_n}} \\
&= \dfrac{8x}{3+x}
\end{align*}
Thus, $x = \dfrac{8x}{3+x}$, which gives $x^2-5x = 0$. So either $x = 5$ or $x = 0$. Let $y_n = 5$ be a constant sequence. So, by Theorem 3.2.9(b), as $x_n \geq 5$ (from above), $x = \lim\limits_{n \to \infty}{x_{n}} \geq \lim\limits_{n \to \infty}{y_{n}} = 5$. Hence, $x = 5$.
\end{proof}

\section{Question 4}
\begin{proof}
Let $m_1 = \liminf x_n$, $m_2 = \liminf y_n$ and $m = \min\{m_1, m_2\}$. Note that as $(x_n), (y_n)$ are bounded, $\exists a, b, c, d \in \R$ such that $a \leq x_n \leq b$ and $c \leq y_n \leq d$ for all $n \in \N$. As $z_n = \min\{x_n, y_n\}$, each term in $(z_n)$ is either in $(x_n)$ or $(y_n)$. So, $\min\{a, c\} \leq z_n \leq \max\{b, d\}$, i.e., $z_n$ is bounded. We know that $(\forall n \in \N)[(z_n \leq x_n) \land (z_n \leq y_n)]$, so by Theorem 3.5.4, $\liminf z_n \leq \liminf x_n  = m_1$ and $\liminf z_n \leq \liminf y_n = m_2$. Hence, $\liminf z_n \leq \min\{m_1, m_2\} = m$. \\\\\ (Note that since $x_n, y_n, z_n$ are bounded, by the Bolzano-Weierstrass Theorem, each of the sequences have at least one convergent subsequence, which means $S(x_n), S(y_n)$, and $S(z_n)$ are non-empty and thus $\liminf x_n$, $\liminf y_n$, and $\liminf z_n$ exist.) \\\\
Now let $z \in S(z_n)$. Then, there exists a subsequence $(z_{n_k})$ of $(z_n)$ (with each $n_k \geq k$) such that $\lim\limits_{n \to \infty}{z_n} = z$. Now as $(x_n), (y_n)$ are bounded sequences, by Theorem 3.5.2:
$$(\forall \epsilon > 0)(\exists K_1 \in \N)[n \geq K_1 \Rightarrow x_n > m_1-\epsilon]$$
\begin{center} and \end{center}
$$(\forall \epsilon > 0)(\exists K_2 \in \N)[n \geq K_2 \Rightarrow y_n > m_2-\epsilon]$$ \\
So, let $\epsilon > 0$ be given and $K = \max\{K_1, K_2\}$. Then $(\forall n \geq K)[(x_n > m_1-\epsilon) \land (y_n > m_2-\epsilon)]$. So, $(x_n > \min\{m_1-\epsilon, m_2-\epsilon\}) \land (y_n > \min\{m_1-\epsilon, m_2-\epsilon\})$. Hence, $z_n > \min\{m_1-\epsilon, m_2-\epsilon\}$. As $\epsilon$ is a constant, we get $z_n > \min\{m_1, m_2\} - \epsilon$, which is equivalent to $z_n > m - \epsilon$. Now, as $(z_{n_k})$ is a subsequence of $(z_n)$, $n_k \geq k$, so:
\begin{align*}
k \geq K &\Rightarrow n_k \geq k \geq K \\
&\Rightarrow z_{n_k} > m - \epsilon \\
&\Rightarrow z_{n_k} \geq m - \epsilon
\end{align*}
Thus, we have shown that $(\forall \epsilon > 0)(\exists K \in \N)[k \geq K \Rightarrow z_{n_k} \geq m-\epsilon]$. Now, if we let $k \to \infty$, by Theorem 3.2.9, $z = \lim\limits_{n \to \infty}{z_{n_k}} \geq m - \epsilon$. As $\epsilon > 0$ is arbitrary, $z \geq m$. \\\\
Hence, as $z$ is arbitrary, we have shown that $(\forall z \in S(z_n))[z \geq m]$. So, $m$ is a lower bound of $S(z_n)$. By definition, $\inf{S(z_n)}$ is greatest lower bound of $S(z_n)$, so $\liminf z_n \geq m$. \\\\
Consequently, as $(\liminf z_n \geq m) \land (\liminf z_n \leq m)$, $\liminf z_n = m = \min\{\liminf x_n,\liminf y_n\}$, as required.
\end{proof}

\section{Question 5}
\subsection{(a)}
False
\subsection{(b)}
False
\subsubsection{(i)}
False
\subsubsection{(ii)}
False

\end{document}


\documentclass[11pt, oneside]{article}   	% use "amsart" instead of "article" for AMSLaTex format

%\usepackage{draftwatermark}
% \SetWatermarkText{Confidential}
% \SetWatermarkScale{5}
% \SetWatermarkLightness {0.85}
% \SetWatermarkColor[rgb]{0.7,0,0}

\usepackage{geometry}                		% See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   		% ... or a4paper or a5paper or ...
%\geometry{landscape}                		% Activate for for rotated page geometryA. G. Barto, R. S. Sutton, and C. W. Anderson
%\usepackage[parfill]{parskip}    		% Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}				% Use pdf, png, jpg, or eps� with pdflatex; use eps in DVI mode
								% Tex will automatically convert eps --> pdf in pdflatex
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{url}
\usepackage{authblk}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{fixltx2e}
\usepackage{hyperref}
\usepackage{alltt}
\usepackage{color}

\newcommand{\argmax}{\operatornamewithlimits{argmax}}
\newcommand{\argmin}{\operatornamewithlimits{argmin}}

\DeclareMathOperator{\E}{\mathbb{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}

\title{The Law of Large Numbers and Policy Gradients}
\author{David Meyer \\ dmm@\{1-4-5.net,uoregon.edu,...\}}

\date{Last update: \today}							% Activate to display a given date or no date

\begin{document}
\maketitle

\section{Introduction}

The \emph{Strong Law of Large Numbers} (LLN) is usually stated as follows:

\bigskip
\noindent
Let $x_{1}, x_{2}, \hdots, x_{M}$ be a sequence of independent and identically distributed (i.i.d) random variables, each having a finite mean $\mu_i = E[x_{i}]$.

\bigskip
\noindent
Then with probability one
\begin{equation}
\frac{1}{M}\sum\limits_{i=1}^{M} x_i \rightarrow E[x]
\end{equation}
as  $M \rightarrow \infty$.

\bigskip
\noindent
A complementary theorem, Ergodic Theorem, is stated as follows:
\bigskip
\noindent
Let $\theta^{(1)}, \theta^{(2)}, \hdots, \theta^{(M)}$ be $M$ samples from a Markov chain that is \emph{aperiodic}, \emph{irreducible}, and \emph{positive recurrent}\footnote{In this case, the chain is said to be \emph{ergodic}.}, and $E[g(\theta)] < \infty$.

\bigskip
\noindent
Then with probability one
\begin{equation}
\frac{1}{M}\sum\limits_{i = 1}^{M} g(\theta_{i}) \rightarrow E[g(\theta)]  = \int_{\Theta}^{}g(\theta) \: \pi(\theta) \:d\theta
\end{equation}
as $M \rightarrow \infty$ and where $\pi$ is the stationary distribution of the Markov chain.

\section{The LLN and Likelihood Ratio Policy Gradients}
Suppose that $r(x)$ is a performance measure that depends on some random variable $X$, and
$q(x; \theta)$ is the is the probability that $X = x$,
parameterized by $\theta \in \mathbb{R}^K$. Under mild regularity conditions, the gradient with respect to $\theta$
of the expected performance $\eta(\theta)$ can be seen to be the following:

\begin{flalign}
\eta(\theta) &= \E_{x \sim q(xl \theta)} [r(x)]
 \: \quad \qquad \qquad \qquad \qquad \qquad \mathrel{\#} \text{definition of }  \eta(\theta) \\
&= \sum\limits_{x} r(x) \cdot q(x; \theta)
 \: \; \qquad \qquad \qquad \qquad \qquad \mathrel{\#} \text{definition of expectation}  \\
\nabla \eta(\theta)  &= \sum_{x} r(x) \nabla_{\theta} q(x; \theta)
\qquad \qquad \qquad \qquad \qquad \mathrel{\#} \text{take the derivative of both sides}  \\
&= \sum_{x} r(x) \frac{\nabla_{\theta} q(x; \theta)}{q(x; \theta)} q(x; \theta)
\quad \qquad \qquad \qquad \mathrel{\#} \text{multiply by } 1 = \frac{q(x; \theta)} {q(x; \theta)} \\
&= \E_{x \sim q(x;\theta)} r(x)  \frac{\nabla_{\theta} q(x; \theta)}{q(x; \theta)}
 \; \quad \qquad \qquad \qquad \mathrel{\#} \text{definition of expectation}
\end{flalign}

\bigskip
\noindent
So our gradient
$\nabla_{\theta} \eta(\theta) = \E_{x \sim q(x;\theta)} r(x)  \frac{\nabla_{\theta} q(x; \theta)}{q(x; \theta)}$, which
means we can estimate the expectation (gradient) with

\begin{equation*}
\hat{\eta}(\theta) = \frac{1}{N} \sum\limits_{i = 1}^N  r(x)  \frac{\nabla_{\theta} q(x; \theta)}{q(x; \theta)}
\end{equation*}

\bigskip
\noindent
Now, given the law of large numbers we know

\begin{flalign*}
\hat{\eta}(\theta) \rightarrow \eta(\theta) \text{ with probability one}
\end{flalign*}

\bigskip
\noindent
This means our gradient estimator ($\hat{\eta}(\theta)$) is \emph{unbiased} since its expected value
equals the true gradient. Specifically:

\begin{flalign}
\E[\hat{\eta}(\theta)] &= \nabla \eta(\theta)
\end{flalign}

\newpage
\bibliographystyle{ieeetr}
\bibliography{/Users/dmm/papers/bib/ml}

\end{document}


\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsmath,amsthm,amsfonts}
\usepackage{latexsym,graphicx}
\usepackage{fullpage,color}
\usepackage{url,hyperref}
\usepackage{natbib}
\usepackage{graphicx,subfigure}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{color}

\numberwithin{equation}{section}

\pagestyle{plain}

\setlength{\oddsidemargin}{0in}
\setlength{\topmargin}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{8.5in}

\newtheorem{lemma}{Lemma}[section]
\newtheorem{theorem}[lemma]{Theorem}

\def\A{{\bf A}}
\def\a{{\bf a}}
\def\B{{\bf B}}
\def\bb{{\bf b}}
\def\C{{\bf C}}
\def\c{{\bf c}}
\def\D{{\bf D}}
\def\d{{\bf d}}
\def\E{{\bf E}}
\def\e{{\bf e}}
\def\F{{\bf F}}
\def\f{{\bf f}}
\def\g{{\bf g}}
\def\h{{\bf h}}
\def\G{{\bf G}}
\def\H{{\bf H}}
\def\I{{\bf I}}
\def\K{{\bf K}}
\def\k{{\bf k}}
\def\LL{{\bf L}}
\def\M{{\bf M}}
\def\m{{\bf m}}
\def\N{{\bf N}}
\def\n{{\bf n}}
\def\PP{{\bf P}}
\def\Q{{\bf Q}}
\def\q{{\bf q}}
\def\R{{\bf R}}
\def\rr{{\bf r}}
\def\S{{\bf S}}
\def\s{{\bf s}}
\def\T{{\bf T}}
\def\tt{{\bf t}}
\def\U{{\bf U}}
\def\u{{\bf u}}
\def\V{{\bf V}}
\def\v{{\bf v}}
\def\W{{\bf W}}
\def\w{{\bf w}}
\def\X{{\bf X}}
\def\x{{\bf x}}
\def\Y{{\bf Y}}
\def\y{{\bf y}}
\def\Z{{\bf Z}}
\def\z{{\bf z}}
\def\0{{\bf 0}}
\def\1{{\bf 1}}

\def\AM{{\mathcal A}}
\def\CM{{\mathcal C}}
\def\DM{{\mathcal D}}
\def\EM{{\mathcal E}}
\def\GM{{\mathcal G}}
\def\FM{{\mathcal F}}
\def\IM{{\mathcal I}}
\def\JM{{\mathcal J}}
\def\KM{{\mathcal K}}
\def\LM{{\mathcal L}}
\def\NM{{\mathcal N}}
\def\OM{{\mathcal O}}
\def\PM{{\mathcal P}}
\def\SM{{\mathcal S}}
\def\TM{{\mathcal T}}
\def\UM{{\mathcal U}}
\def\VM{{\mathcal V}}
\def\WM{{\mathcal W}}
\def\XM{{\mathcal X}}
\def\YM{{\mathcal Y}}
\def\RB{{\mathbb R}}
\def\EB{{\mathbb E}}
\def\PB{{\mathbb P}}

\def\alp{\mbox{\boldmath$\alpha$\unboldmath}}
\def\bet{\mbox{\boldmath$\beta$\unboldmath}}
\def\epsi{\mbox{\boldmath$\epsilon$\unboldmath}}
\def\etab{\mbox{\boldmath$\eta$\unboldmath}}
\def\ph{\mbox{\boldmath$\phi$\unboldmath}}
\def\pii{\mbox{\boldmath$\pi$\unboldmath}}
\def\Ph{\mbox{\boldmath$\Phi$\unboldmath}}
\def\Ps{\mbox{\boldmath$\Psi$\unboldmath}}
\def\ps{\mbox{\boldmath$\psi$\unboldmath}}
\def\tha{\mbox{\boldmath$\theta$\unboldmath}}
\def\Tha{\mbox{\boldmath$\Theta$\unboldmath}}
\def\muu{\mbox{\boldmath$\mu$\unboldmath}}
\def\Si{\mbox{\boldmath$\Sigma$\unboldmath}}
\def\si{\mbox{\boldmath$\sigma$\unboldmath}}
\def\Gam{\mbox{\boldmath$\Gamma$\unboldmath}}
\def\Lam{\mbox{\boldmath$\Lambda$\unboldmath}}
\def\De{\mbox{\boldmath$\Delta$\unboldmath}}
\def\Ome{\mbox{\boldmath$\Omega$\unboldmath}}
\def\Pii{\mbox{\boldmath$\Pi$\unboldmath}}
\def\varepsi{\mbox{\boldmath$\varepsilon$\unboldmath}}

\def\argmax{\mathop{\rm argmax}}
\def\argmin{\mathop{\rm argmin}}
\def\bias{\mathsf{bias}}
\def\var{\mathsf{var}}
\def\sgn{\mathsf{sgn}}
\def\tr{\mathsf{tr}}
\def\rk{\mathrm{rank}}
\def\poly{\mathrm{poly}}
\def\diag{\mathsf{diag}}
\def\st{\mathsf{s.t.}}

\newcommand{\red}[1]{{\color{red}#1}}

\lstset{ %
extendedchars=false,            % Shutdown no-ASCII compatible
language=Python,                % choose the language of the code
xleftmargin=1em,
xrightmargin=1em,
basicstyle=\footnotesize,    % the size of the fonts that are used for the code
tabsize=3,                            % sets default tabsize to 3 spaces
numbers=left,                   % where to put the line-numbers
numberstyle=\tiny,              % the size of the fonts that are used for the line-numbers
stepnumber=1,                   % the step between two line-numbers. If it's 1 each line
                                % will be numbered
numbersep=5pt,                  % how far the line-numbers are from the code   %
keywordstyle=\color[rgb]{0,0,1},                % keywords
commentstyle=\color[rgb]{0.133,0.545,0.133},    % comments
stringstyle=\color[rgb]{0.627,0.126,0.941},      % strings
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
frame=single,                 % adds a frame around the code
%captionpos=b,                   % sets the caption-position to bottom
breaklines=true,                % sets automatic line breaking
breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
%title=\lstname,                 % show the filename of files included with \lstinputlisting;
%                                % also try caption instead of title
mathescape=true,escapechar=?    % escape to latex with ?..?
escapeinside={\%*}{*)},         % if you want to add a comment within your code
%columns=fixed,                  % nice spacing
%morestring=[m]',                % strings
%morekeywords={%,...},%          % if you want to add more keywords to the set
%    break,case,catch,continue,elseif,else,end,for,function,global,%
%    if,otherwise,persistent,return,switch,try,while,...},%
}

\begin{document}

\title{CS583A: Course Project}

\author{Name 1, Name 2, and Name 3}

%\date{ }

\maketitle

\section{Summary}

[Problem descriptions:] We pariticipe an active (or inactive with late submission) competition of classifying cats and dogs based on photos.
[Methodology:] The final model we choose is ResNet50, a deep convolutional neural network architecture, which takes $256\times 256$ images as input and outputs the class labels.
[Implementation:] We implement the convolutional neural network using Keras (or we directly use the ResNet50 provided by Keras) and run the code on a MacBook Pro with one Intel i7 CPU and 32 GB memory (or a workstation with 4 NVIDIA GeForce XXX GPUs.)
[Evaluation metric:] Performance is evaluated on the classification accuracy.
[Score and ranking:] In the public leaderboard, our score is $0.95123$; we rank 79 among the 215 teams. In the private leaderboard, our score is $0.95234$; we rank 82 among the 217 teams. (Or, the result on the public leaderboard is not available until Month Day Year.)

(Note: In your report, remove the words in brackets.)

\section{Problem Description}

\paragraph{Problem.}
The problem is to classify cats and dogs based on photos.
This is a binary classification and image recognition problem.
The competition is at \url{https://www.kaggle.com/c/dogs-vs-cats}.
[Use your own words to give a very short description. Do NOT copy the description on Kaggle.]

\paragraph{Data.}
The data are $256\times 256$ JPEG images.
The number of training samples is $n=25,000$.
The number of classes is $2$.
The training set is well-balanced: $n_{\textrm{dog}} = 12,500$ and $n_{\textrm{cat}} = 12,500$.

\paragraph{Challenges.}
[What makes the problem challenge? E.g., the training set is too small, the data is imbalanced, etc.]

[If your project is different from your proposal, add a section here to justify. Without a convincing justification, you may lose 2 points.]

\section{Solution}

\paragraph{Model.}
The model we finally choose is the ResNet50 \cite{he2016deep}, a standard deep convolutional neural network.
A description of ResNet is online: \url{https://en.wikipedia.org/wiki/Residential_network}.
[Describe your model only if it is non-standard.]

\paragraph{Implementation.}
We implement the ResNet50 model using Keras with TensorFlow as the backend. [Or, we directly use the ResNet model provided by Keras.]
Our code is available at \url{https://github.com/wangshusen/CS583A-2019Spring/}.
We run the code on a MacBook Pro with one Intel i7 CPU and 32 GB memory (or a workstation with 4 NVIDIA GeForce XXX GPUs.)
It takes $2.2$ hours to train the model.

\paragraph{Settings.}
The loss function is categorical cross-entropy.
The opitmizer is RMSprop.
[Specify the other hyperparameters such as learning rate, regularization, epochs, batch size, etc.]

\paragraph{Advanced tricks.}
[If you used advanced tricks, e.g., pretrain the model on ImageNet and fine-tune it on the Dog-VS-Cat dataset, then write down your tricks and discuss their contribution to the performance, e.g., improve the validation error by $5.6\%$.]

\paragraph{Cross-validation.}
We tune the parameters using a 5-fold cross-validation. [If you do not have GPU, you can simply partition the training data to 80\%-20\% or 90\%-10\% for hyperparameter tuning.]
[Just show the results of your final chosen model.]
Figure~\ref{fig:convergence} plots the the convergence curves on 80\% training data and 20\% validation data. [If you use 5-fold cross-validation, just plot one of the five folds.]
[Analyze the convergence curves. E.g., if the training accuracy is much better than the validation accuracy, then the model is likely to overfit the data, and that is why you pretrain your model on ImageNet.]

%---------------------------------Figure---------------------------------%
\begin{figure}
	\begin{center}
		\subfigure[The classification accuracy on the training set and validation set.]{\includegraphics[width=0.48\textwidth]{acc.png}}
		\subfigure[The loss on the training set and validation set.]{\includegraphics[width=0.48\textwidth]{loss.png}}
	\end{center}
	\caption{The convergence curves.}
	\label{fig:convergence}
\end{figure}
%---------------------------------Figure---------------------------------%

\section{Compared Methods}

[Hint: Try different methods (with brief descriptions) and report their performance.
You will lose up to 3 points if you do not compare with baselines.
Here are examples.]

\paragraph{ResNet.}
We use the ResNet50 model provided by Keras. Its parameters are pretrained on the ImageNet dataset. The training and validation accuracies are respective 80.0\% and 75.0\%.

\paragraph{Fully-connected neural network.}
We implemented a 3-layer fully-connected neural network.
The width of the layers (from bottom to top) are respectively 256, 512, and 10.
We apply dropout/batch normalization to the second layer.
The training and validation accuracies are respective 80.0\% and 75.0\%.

\paragraph{Random forest.}
We use the random forest model provided by SKlearn.
We set xxx to xxx.
The training and validation accuracies are respective 80.0\% and 75.0\%.

\paragraph{Advanced tricks.}
Our finally adopted method is a siamese network with 4 convolutional layers.
We applied the following tricks.
\begin{itemize}
	\item
	Data augmentation.
	Without data augmentation, the training and validation accuracies are respective 80.0\% and 75.0\%.
	With data augmentation, the training and validation accuracies are respective 82.0\% and 77.0\%.
	\item
	Over-sampling.
	Because the data is imbalanced (much more negative samples than positive samples),
	we tried over-sampling and under-sampling and found over-sampling works better.
	Using both data augmentation and over-sampling, the training and validation accuracies are improved to 85.0\% and 79.0\%.
	\item
	Ensemble.
	Using data augmentation, over-sampling, and ensemble, the training and validation accuracies are improved to 87.0\% and 83.0\%.
\end{itemize}

\section{Outcome}

[Top 30\% is considered good.
Top 30 to 60\% is considered medium, and you may lose 1 point.
Bottom 40\% is considered low, and you may lose 2 points.]

We participated in an active competition.
Our score is 0.89311 in the public leaderboard and 0.90112 in the private leaderboard.
We rank 100/312 in the public leaderboard and 101/312 in the private leaderboard.
The screenshots are in Figure~\ref{fig:leaderboard}.

%---------------------------------Figure---------------------------------%
\begin{figure}
	\begin{center}
		\subfigure[Private leaderboard.]{\includegraphics[width=0.48\textwidth]{private.png}}
		\subfigure[Public leaderboard.]{\includegraphics[width=0.48\textwidth]{public.png}}
	\end{center}
	\caption{Our rankings in the leaderboard.}
	\label{fig:leaderboard}
\end{figure}
%---------------------------------Figure---------------------------------%

%\vspace{3mm}
%\begin{lstlisting}
%import numpy
%
%def rfm(x, s, sigma):
%	n, d = x.shape
%	a = numpy.random.standard_normal((d, s)) / sigma
%	b = numpy.random.rand(1, s) * (2 * numpy.pi)
%	c = numpy.dot(x, a) + b
%	h = numpy.cos(c) * numpy.sqrt(2/s)
%	return h
%\end{lstlisting}
%\vspace{3mm}

%\newpage
\bibliographystyle{plain}
\bibliography{reference}

\end{document}


\subsection{Orientability of surfaces}