% !TEX root = ../thesis.tex
%
\chapter{Related Work}
\label{sec:related}
In this chapter we quickly want to revise other works touching the tasks of this thesis. In \treft{sec:related:detection} we discuss multiple successful object detection methods using \glspl{cnn} and in \treft{sec:related:retrieval} we list previous image retrieval systems also focusing on those employing \glspl{cnn}.

\section{Object detection}
\label{sec:related:detection}
The first work to approach object detection with a \gls{cnn} were \citet{girshick_rich_2014}, with their \textbf{\gls{rcnn}}. For each image they use Selective Search to generate a set of region proposals. Selective Search is a technique to identify object-like, but type independent, regions probing texture and color of the image at multiple scales. All these boxes are reshaped to a uniform size and forwarded through a normal classification network (in their case AlexNet \citep{krizhevsky_imagenet_2012}) to yield feature vectors from the \gls{fc} layers. Lastly a multi-class \gls{svm} classifies these proposals. Additionally the \gls{rcnn} is trailed by a linear regression model which uses the classified boxes to produce tighter box coordinates. Although the results proved that \glspl{cnn} can greatly improve detection results, the method is hard to train because the classifier network, the \gls{svm} and the regressor have to be trained independently. Also at test time classifying each region box independently is extremely slow.

A year later again \citet{girshick_fast_2015} released \textbf{Fast \gls{rcnn}} which improves computation performance and training complexity. Instead of computing features for each proposed region, Fast \gls{rcnn} computes the features for the whole image at once. Then the regions in the image are projected onto the feature map of the network, thus yielding the patch-wise features. Those patch-wise feature maps are pooled, forwarded through \gls{fc} layers and finally into a classifier and the box regressor. The \gls{svm} is replaced with a SoftMax and the linear regression model with a additional \gls{fc} layer. As such the three models from \gls{rcnn} become one unified network which is faster and easier to train.
\clearpage
In the same year \citet{ren_faster_2015} tackled the big bottleneck of this approach, which is the region proposal system, with their \textbf{Faster \gls{rcnn}}. The previously used Selective Search is slow and still independent of the model. Using also the features generated by the \gls{conv} layers, they add a new network branch, a \gls{rpn}, to generate box proposals. These are used for the same \gls{roi} pooling as in the Fast \gls{rcnn}. The \gls{rpn} is a \gls{fcn} that takes the feature map and at each positions tests for a predefined set of $k$ anchor boxes whether those could be objects. So for each window the \gls{rpn} outputs a score of \textit{objectness} and coordinates of the bounding box. Those are then the inputs for the Fast \gls{rcnn} method.

This year \citet{he_mask_2017} extended this approach with \textbf{Mask \gls{rcnn}} to pixel-wise segmentation of images. In the previous versions the regions from the original image were projected onto the feature maps by just down-scaling their shapes with the respective factor and discretizing them on the feature grid. This rounding introduces errors in the proposed bounding boxes and leads to misalignment. Instead they use bilinear interpolation inside each region to find more precise feature representations. This process is done by a new branch inside the Faster \gls{rcnn} and outputs binary pixel-wise masks for each \gls{roi}. The regions are classified as in the Faster \gls{rcnn} and as such they are able to return semantic image segmentations.

\citet{dai_r-fcn:_2016} incorporates the \gls{roi}-wise processing into the main network branch of their \textbf{R-FCN} through a series of \gls{conv} layers. The \gls{conv} layers encode scores at relative positions like top-left or bottom-center. Next the regions from the \gls{rpn} are divided into the same relative sub-regions and each sub-region is used to pool from the corresponding layer and then to vote for the whole \gls{roi}.

As our work also has to focus on time performance, it is related to other fast object detectors. \citet{redmon_you_2016} use a freshly designed network architecture \textbf{YOLO} to achieve object detection at real-time. The input image is divided into a regular grid. The last \gls{fc} layer from their network predicts for each cell of the grid the class probabilities and the coordinates and objectness confidence of two bounding boxes. Detections get selected by the multiplication of their conventional class probabilities and their individual confidence predictions. While the method is extremely fast it is limited by the shape of bounding boxes it will predict.
\clearpage
\section{Image retrieval}
\label{sec:related:retrieval}
Retrieving relevant images from large databases by searching for similarities to an exemplar image, is a long used idea. The first methods employed hand-crafted features like histograms, SIFT or \gls{hog} to compare different images in a low dimensional space. Problems in such approaches arise with semantically close groups of objects with wide visual differences.\\
One of the more classical but successful approaches is \textbf{OASIS} \citep{chechik_large_2010}. Here the authors solve a bilinear similarity function for whole images using sparse local pattern descriptors. While the approach is successful under its training settings it is heavily restricted in that it has to be trained on all needed image classes.

\citet{wu_online_2013} learns image similarity using stacked neural networks. The inputs for those are low image features and they learn representations of modalities of these features giving a optimized multi-model combination. With a bag of five features they achieve better results, retrieving similar images, than OASIS but also lack wider applicability through the complexity of training.

The step forward to just learning similarity on top of raw pixels is done by \citet{babenko_neural_2014}, as they show that using just the distance between  the outputs of \gls{fc} layers, it is possible to retrieve visually similar images. More sophisticated is \textbf{DeepRanking} \citep{wang_learning_2014} use the deep feature of an AlexNet, together with visual features extracted by convolutions, in a linear embedding as a image descriptor. With the distance between the embeddings as measure, they rank the similarity of images to a query image. The visual features and the linear embedding are learned by feeding the network triplets of query, positive, and negative images. They show that the learned features outperform hand-crafted ones.

Neural networks shown success in being used in reverse image search systems. In \citep{khosla_building_2015} they train different network architectures on images of shoes and use a distance measure between the descriptors from the trailing \gls{fc} layer to retrieve alike shoes to a query shoe. Similarly the image descriptions from a task-specifically fine-tuned network are used in \citep{chen_visual-based_2015} to select similar styles inside clothing catalogs. Using the idea of \citep{wang_learning_2014} \citet{bell_learning_2015} learn a embedding of image descriptors. They use a siamese network architecture to learn from tuples of similar or dissimilar pairs. With the learned embedding space they retrieve similar interior designs given a query product by picking close training samples in the embedding space.


\documentclass[12pt]{article}
\usepackage{graphics}
\begin{document}

\section*{NYU Physics 1---Final Exam}

\vfill

\paragraph{Name:} ~

\paragraph{email:} ~

\vfill

This exam consists of six problems.  Write only in this booklet.  Be
sure to show your work.

\vfill

\emph{You must ensure that the proctor checks off your name on the
attendance sheet when you hand in your exam.  Your exam will
\textbf{not} be graded if your name is not checked off.}

\clearpage

\section*{Problem 1}

(a) A block of mass $M$ slides down a plane inclined at an angle
$\theta$ to the horizontal.  There is a coefficient of sliding
friction $\mu$ between block and plane.  What is the magnitude of the
acceleration $a$ of the block down the plane?  Be sure to draw a
free-body diagram.

\vfill

(b) A \emph{different} block of mass $M$ sits on the same plane.  In
this case, the frictional force is so great that the block does not
slide down the plane.  What is the magnitude $f$ and direction of the
frictional force?  Try to give your answer in terms of $M$, $g$ and
$\theta$ only.

\vfill ~

\clearpage

\section*{Problem 2}

A major-league baseball pitcher can throw a baseball at about
$100~\mathrm{mi\,hr^{-1}}$.  Estimate the impulse $\Delta p$ given to
the ball by the pitcher.  Make an estimate of the work done $\Delta W$
by the pitcher on the ball during the throw.  Now figure out some way
to compute the average force $F$ applied by the pitcher to the ball.
Does your answer seem reasonable?  \emph{Clearly state your
assumptions, and justify any that are non-trivial.}

\clearpage

\section*{Problem 3}

Draw free-body diagrams for all the masses and pulleys in this
mechanism.  Find the tensions in all three strings and the
accelerations of the two blocks.
\\ \rule{0.35\textwidth}{0pt}
\resizebox{0.3\textwidth}{!}{\includegraphics{../mp/tackle_blocks.eps}}
\\
Be careful with your kinematic constraints, and assume that all the
strings and pulleys are massless and frictionless.

\clearpage

\section*{Problem 4}

A figure skater spins in place on frictionless ice at angular speed
$\omega_i$ with her hands outstretched.  She has a total moment of
inertia $I_i$.  As the skater draws her hands into her body, her
moment of inertia decreases to $I_f=I_i/2$.  Does her kinetic energy
$K$ increase, decrease, or stay the same?  \emph{Explain your answer
concisely but clearly with either one sentence or a short
calculation.}

\clearpage

\section*{Problem 5}

A ``seconds'' pendulum has a period of exactly $2.000~\mathrm{s}$.

\textsl{(a)}~If $g=9.797~\mathrm{m\,s^{-2}}$ in Austin Texas, how long
should a Texan make her or his seconds pendulum?

\vfill

\textsl{(b)}~If $g$ is 0.1~percent (a factor of 1.001) larger in
Paris, France, than in Austin, how different, in percent, should the
length of a Parisian's seconds pendulum be than a Texan's?  Should it
be longer or shorter?  \emph{Note:} You can answer this question
without getting part (a) correct.

\vfill ~

\clearpage

\section*{Problem 6}

Consider the following attractive radial force law, which is
\emph{very different} from Newton's law of gravity:
\begin{equation}
F = \frac{k\,M\,m}{r^4}
\end{equation}
Where $k$ is a constant.

Consider a body of mass $m$ orbiting in a circular orbit of radius $R$
around another body of mass $M$, with $m\ll M$, according to the above
force law.

\textsl{(a)}~One of Kepler's laws is that for gravity, orbital period
$T$ is related to orbital radius $r$ by $T\propto r^{3/2}$.  Use
either a dimensional argument or a direct calculation to get the
equivalent relation for this \emph{very different} radial force law.

\vfill

\textsl{(b)}~What is the potential energy of the mass $m$ at radius
$r=R$, relative to its potential energy at infinite $r$?  \emph{Note:}
You can answer this question without getting part (a) correct.

\vfill ~

\clearpage

[This page intentionally left blank for calculations or other work.]

\end{document}


%\documentclass[12pt]{article}
\documentclass[12pt,landscape]{article}

\include{preamble}

\newcommand{\instr}{\small Your answer will consist of a lowercase string (e.g. \texttt{aebgd}) where the order of the letters does not matter. \normalsize}

\title{Math 342W / 650 Fall \the\year{} \\ Midterm Examination Two}
\author{Professor Adam Kapelner}

\date{Thursday, May 13, \the\year{}}

\begin{document}
\maketitle

%\noindent Full Name \line(1,0){410}

\thispagestyle{empty}

\section*{Code of Academic Integrity}

\footnotesize
Since the college is an academic community, its fundamental purpose is the pursuit of knowledge. Essential to the success of this educational mission is a commitment to the principles of academic integrity. Every member of the college community is responsible for upholding the highest standards of honesty at all times. Students, as members of the community, are also responsible for adhering to the principles and spirit of the following Code of Academic Integrity.

Activities that have the effect or intention of interfering with education, pursuit of knowledge, or fair evaluation of a student's performance are prohibited. Examples of such activities include but are not limited to the following definitions:

\paragraph{Cheating} Using or attempting to use unauthorized assistance, material, or study aids in examinations or other academic work or preventing, or attempting to prevent, another from using authorized assistance, material, or study aids. Example: using an unauthorized cheat sheet in a quiz or exam, altering a graded exam and resubmitting it for a better grade, etc.
\\

\noindent By taking this exam, you acknowledge and agree to uphold this Code of Academic Integrity. \\

%\begin{center}
%\line(1,0){250} ~~~ \line(1,0){100}\\
%~~~~~~~~~~~~~~~~~~~~~signature~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date
%\end{center}

\normalsize

\section*{Instructions}
This exam is 100 minutes (variable time per question) and closed-book. You are allowed \textbf{two} 8.5 $\times$ 11'' pages (front and back) of a \qu{cheat sheet}, blank scrap paper and a graphing calculator. Please read the questions carefully. No food is allowed, only drinks. %If the question reads \qu{compute,} this means the solution will be a number otherwise you can leave the answer in \textit{any} widely accepted mathematical notation which could be resolved to an exact or approximate number with the use of a computer. I advise you to skip problems marked \qu{[Extra Credit]} until you have finished the other questions on the exam, then loop back and plug in all the holes. I also advise you to use pencil. The exam is 100 points total plus extra credit. Partial credit will be granted for incomplete answers on most of the questions. \fbox{Box} in your final answers. Good luck!

\pagebreak

\problem\timedsection{11} Consider the following causal diagrams where all events have other causes that are not displayed. It is assumed that the timing of events is known and to scale. Assume you have a training set $\mathbb{D}$ with a large sample size $n$ with columns x, y, z (and w if included).

\vspace{-.3cm}
\begin{figure}[htp]
\centering
\includegraphics[width=7in]{basic_causal_diagrams}
\end{figure}

\vspace{-.4cm}

\vspace{-0.3cm}\benum\truefalsesubquestionwithpoints{11}

\begin{enumerate}[(a)]
%\item In diagram A, x and z could be spuriously correlated.
%\item In diagram D, w and y could be spuriously correlated.
%\item In diagram E, w and y could be spuriously correlated.
%\item Assume the data generating process that $\mathbb{D}$ is sampled from is diagram A. When running the OLS model y $\sim$ x you find a strong correlation. This correlation is spurious.
\item Assume  diagram A is the data generating process that $\mathbb{D}$ is sampled from. When running the OLS model y $\sim$ x you find a strong correlation. In out-of-sample data there would likely be a near-zero correlation betweeen y and x.
\item In diagram A, z is a lurking variable when analyzing the causal effect of x on y.
\item In diagram B, z is a lurking variable when analyzing the causal effect of x on y.
\item In diagram D, w is a lurking variable when analyzing the causal effect of x on y.
\item In diagram E, w is a lurking variable when analyzing the causal effect of x on y.
\item In diagram C, x causes y (according to our in-class definition of causality).
\item In diagram B, an OLS model of y $\sim$ x demonstrates that x and y are correlated but this correlation disappears if you run an OLS model of y $\sim$ x + z
\item In diagram D, an OLS model of y $\sim$ x demonstrates that x and y are correlated but this correlation disappears if you run an OLS model of y $\sim$ x + w
\item In diagram D, x can be used to predict y better than $g_0$ (out of sample)
\item In diagram D, w can be used to predict y better than $g_0$ (out of sample)
\item In diagram E, an OLS model of y $\sim$ x demonstrates that x and y are correlated but this correlation disappears if you run an OLS model of y $\sim$ x + w

\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\problem\timedsection{7} \ingray{Consider the following causal diagrams where all events have other causes that are not displayed. It is assumed that the timing of events is known and to scale.} Assume now you have a training set $\mathbb{D}$ with a large sample size $n$ with columns x, y, z (and w if included).
%
%
%\begin{figure}[htp]
%\centering
%\includegraphics[width=7in]{basic_causal_diagrams}
%\end{figure}
%
%\vspace{-.5cm}
%
%\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{14}
%
%\begin{enumerate}[(a)]
%\item Assume the data generating process that $\mathbb{D}$ is sampled from is diagram A. When running the OLS model y $\sim$ x you find a strong correlation. This correlation is spurious.
%\item Assume the data generating process that $\mathbb{D}$ is sampled from is diagram A. When running the OLS model y $\sim$ x you find a strong correlation. In out-of-sample data there would likely be a near-zero correlation betweeen y and x.
%\item Assume the data generating process that $\mathbb{D}$ is sampled from is diagram E. When running the OLS model y $\sim$ x you find a strong correlation. This correlation is spurious.
%\item Assume the data generating process that $\mathbb{D}$ is sampled from is diagram E. When running the OLS model y $\sim$ x you find a strong correlation. In out-of-sample data there would likely be a near-zero correlation betweeen y and x.
%\end{enumerate}
%\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{7} Consider the \texttt{iris} data frame, a famous dataset of four measurements on $n = 150$ iris flowers where the response is \texttt{Species}, a categorical variable with three levels: versicolor, viriginica and setosa (where each species has 50 observations). Below is a sample:

\lstset{
  basicstyle=\footnotesize,
  xleftmargin=.2\textwidth, xrightmargin=.2\textwidth
}
\begin{lstlisting}
   Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
          5.5         4.2          1.4         0.2     setosa
          7.6         3.0          6.6         2.1     virginica
          7.2         3.2          6.0         1.8     virginica
          5.6         3.0          4.1         1.3     versicolor
          5.2         4.1          1.5         0.1     setosa
...
\end{lstlisting}

\vspace{-0.7cm}

\noindent And also consider the \texttt{common\_name} data frame which provides the common names:

\lstset{
  basicstyle=\footnotesize,
  xleftmargin=.3\textwidth, xrightmargin=.3\textwidth
}
\begin{lstlisting}
Species         English_Name
aphylla	        table iris
setosa 		      bristle-pointed iris
reichenbachii   rock iris
versicolor      blue flag iris
flavescens      lemonyellow iris
\end{lstlisting}
\vspace{-1cm}

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{8}

%\begin{changemargin}{-0.8cm}{0cm}
Joining the two data frames on the \texttt{Species} column via a ...
\begin{enumerate}[(a)]
%\item These two data frames can be joined by either a left join, a right join, an inner join and a full join.\\
\item ... left join (where \texttt{iris} was on the left) would yield a new data frame with 150 rows.
\item ... right join (where \texttt{iris} was on the right) would yield a new data frame with 150 rows.
\item ... left join (where \texttt{common\_name} was on the left) would yield a new data frame with 150 rows.
\item ... right join (where \texttt{common\_name} was on the right) would yield a new data frame with 150 rows.
\item ... inner join would yield a new data frame with 150 rows.
\item ... full join would yield a new data frame with 150 rows.
\item ... inner join would yield a new data frame with 100 rows.
\item ... full join would yield a new data frame with 100 rows.
\end{enumerate}
%\end{changemargin}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{6} \ingray{Consider the \texttt{iris} data frame, a famous dataset of four measurements on $n = 150$ iris flowers where the response is \texttt{Species}, a categorical variable with three levels: versicolor, viriginica and setosa (where each species has 50 observations).} Consider the subset of the observations for only y = setosa. Below is a sample:

\lstset{
  basicstyle=\footnotesize,
  xleftmargin=.25\textwidth, xrightmargin=.25\textwidth
}
\begin{lstlisting}
  Sepal.Length Sepal.Width Petal.Length Petal.Width
          5.2         4.1          1.5         0.1
          5.4         3.4          1.7         0.2
          5.3         3.7          1.5         0.2
          4.5         2.3          1.3         0.3
          4.8         3.0          1.4         0.3
...
\end{lstlisting}
\vspace{-1cm}
\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{7}

If you were to convert this dataset from wide format to long format ...

\begin{enumerate}[(a)]
\item ... there would be two columns
\item ... there would be four columns
\item ... all columns would have continuous features
\item ... all columns would have categorical features
\item ... there would be 50 rows
\item ... there would be 200 rows
\item ... the resulting data frame would be easier to manipulate using a visualization library such as \texttt{ggplot2}
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{9} \ingray{Consider the \texttt{iris} data frame, a famous dataset of four measurements on $n = 150$ iris flowers where the response is \texttt{Species}, a categorical variable with three levels: versicolor, viriginica and setosa (where each species has 50 observations).} We fit a CART model with \texttt{Nodesize} = 1 to this dataset. The result is a model with 17 internal nodes and 9 leaf nodes with $\hat{y}$ values of 1 (= setosa), 2 (= virginica) and 3 (= versicolor). Below is an abridged illustration of the tree. Ignore the ``M$\rightarrow$'' and \qu{$\leftarrow$M} notation. Numbers in parentheses indicate number of observation in a node. The left direction means the split condition is true.

\vspace{-0.2cm}
\begin{figure}[htp]
\centering
\includegraphics[width=5.3in]{classification_tree.png}
\end{figure}
\vspace{-0.3cm}
\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{14}
\vspace{-0.2cm}
\begin{enumerate}[(a)]
\item This is a regression tree model
\item This model can be written as a linear model of the form $g(\x) = b_0 + b_1 x_1 + b_2 x_2 + b_3 x_3 + b_4 x_4$ where $x_1, x_2, x_3, x_4$ are the four measurements \texttt{Sepal.Length}, \texttt{Sepal.Width}, \texttt{Petal.Length} and \texttt{Petal.Width}
\item This model is overfit
\item If the stump is considered depth zero, then this tree has a depth of 3
\item For all $\mathbb{D}$, a binary split on \texttt{Petal.Length} is the best overall split to reduce heterogeneity in the response
\item For future data, this model will likely predict setosa correctly with high probability
\item If \texttt{Petal.Length} $> 2.45$, there exists a second binary split that is able to isolate all virginica observations in one leaf and all versicolor observations in the other leaf
\item If \texttt{Petal.Length} $> 4.95$, $\hat{y}$ will always be the same
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{6} Consider the following data frame displayed in random order, where missingess is visualized in red. The last column is the response $y$ and there is no missingness in the response. The feature that has the most missingness is $x_{34}$ and the observation with the most missingness is row \#10.

\begin{figure}[htp]
\centering
\includegraphics[width=7in]{missingness.png}
\end{figure}

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{7}

\begin{enumerate}[(a)]
\item Dropping all observations with missingness (listwise deletion) will seriously impact future performance of any model fit with the data
\item The dataset exhibits one MCAR missingness mechanism and this mechanism is the same for all entries
\item The dataset may exhibit a different independent NMAR missingness mechanism for each feature
\item When building a predictive model, the most prudent thing to do is to drop the feature $x_{34}$ and to drop observation \#10
\item Imputing missing values using the columns' sample averages will result in a data frame with no missingness
\item The recommended procedure is to impute with the \texttt{missForest} and then use only the imputed matrix $\X$ to construct your model ignoring the original $\X$ matrix
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{6} \ingray{Consider the following data frame, where missigness is visualized in red. The last column is the response $y$ and there is no missingness in the response. The feature that has the most missingness is $x_{34}$ and the observation with the most missingness is row \#10.}

\begin{figure}[htp]
\centering
\includegraphics[width=7in]{missingness.png}
\end{figure}

\noindent Now assume that $x_{34}$ and observation \#10 were dropped and the remaining missing values were imputed via the \texttt{missForest} algorithm.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{6}

\begin{enumerate}[(a)]
\item An OLS model cannot be fit on the imputed data frame
\item A ridge model with $\lambda = 10^{-6}$ cannot be fit on the imputed data frame
\item A lasso model with $\lambda = 10^{-6}$ cannot be fit on the imputed data frame
\item An elastic net model with $\lambda = 10^{-6}$ and $\alpha = 0.1$ cannot be fit on the imputed data frame
\item After using the model selection procedure to select $\lambda$ for the lasso based on oos $s_e$, the number of nonzero linear coefficients in the resulting model will likely be small relative to $p$
\item After using the model selection procedure to select $\lambda$ for the ridge based on oos $s_e$, the number of nonzero linear coefficients in the resulting model will likely be small relative to $p$
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\problem\timedsection{7} Consider the \texttt{diamonds} data frame, which has $n = 53940$ diamonds with 9 measurements each and the response variable \texttt{price} measured in USD. Below is a sample of five observations:
%
%\lstset{
%  basicstyle=\footnotesize,
%  xleftmargin=.2\textwidth, xrightmargin=.2\textwidth
%}
%\begin{lstlisting}
%  carat       cut color clarity depth table price    x    y    z
%  0.41 Very Good     D     SI2  62.3    61   638 4.72 4.75 2.95
%  0.50 Very Good     F     VS2  62.8    57  1402 5.05 5.08 3.18
%  1.03      Fair     I     SI2  65.2    56  3530 6.42 6.35 4.16
%  1.10     Ideal     I     SI1  62.1    57  5037 6.60 6.64 4.11
%  1.51 Very Good     E     VS2  63.3    61 13757 7.24 7.17 4.56
%...
%\end{lstlisting}
%\vspace{-.5cm}
%
%\noindent We wish to fit many models to this dataset: (1) OLS with the formula $y \sim .$ (2) OLS with the formula $y \sim . * .$ (3) OLS with the formula $y \sim . * . * .$ (4) a regression tree with \texttt{nodesize} = 10 (5) a Random Forest (RF) with 500 trees. The dataset is sampled into a distinct training set of size $n=3,000$, a distinct select set of $n=3,000$ and a distinct test set of $n=3,000$ and these three subsets are used in accordance with the modeling selection procedure we learned about in class.
%
%\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{14}
%
%\begin{enumerate}[(a)]
%\item The training set is fit to each of the five models above
%\item The select set is fit to each of the five models above
%\item Predicting on the training set is \qu{out of sample}
%\item Predicting on the select set is \qu{out of sample}
%\item Each of the five models above predict on the select set
%\item Each of the five models above predict on the test set
%\item The model that predicts on the test set was fit on $n=6000$ observations
%\item The final model was fit on $n=6000$ observations
%\item For the RF model, there is no need to use a separate out-of-sample set as you can assess the oos performance using the oob error estimate
%\end{enumerate}
%\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{14} Consider the \texttt{diamonds} data frame, which has $n = 53940$ diamonds with 9 measurements each and the response variable \texttt{price} measured in USD. We wish to fit many models to this dataset: (1) OLS with the formula $y \sim .$ (2) OLS with the formula $y \sim . * .$ (3) OLS with the formula $y \sim . * . * .$ (4) a regression tree with \texttt{nodesize} = 10 (5) a Random Forest (RF) with 500 trees. Consider two model selection procedures:
\vspace{-0.1cm}
\begin{enumerate}[A.]
\item The three-split dataset model selection procedure where the original dataset is sampled into a distinct training set of size $n=3,000$, a distinct select set of $n=3,000$ and a distinct test set of $n=3,000$.
\item The \textit{nested resampling procedure} for model selection where $K_{select} = 3$ and $K_{test} = 5$ on a subset of $n=9,000$ observations from the original data frame.
\end{enumerate}

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{16}

\begin{enumerate}[(a)]
\item In procedure [A], the training set is fit to each of the five models above
\item In procedure [A], the the select set is fit to each of the five models above
\item In procedure [A], predicting on the training set is \qu{out of sample}
\item In procedure [A], predicting on the select set is \qu{out of sample}
\item In procedure [A], each of the five models above predict on the test set
\item In procedure [A], the model that predicts on the test set was fit on $n=6000$ observations
\item In procedure [A], the final model was fit on $n=6000$ observations
%\item For the RF model, there is no need to use a separate out-of-sample set as you can assess the oos performance using the oob error estimate
\item Procedure [B] is more computationally costly than procedure [A]
\item Procedure [B] has lower variance in its estimate of future performance
\item Procedure [B] is likely to select a model with better future performance than procedure [A]
\item There are a total of 16 models fit during procedure [B] including the final model
\item There are a total of 26 models fit during procedure [B] including the final model
\item There are a total of 65 models fit during procedure [B] including the final model
\item There are a total of 76 models fit during procedure [B] including the final model
\item During procedure [B], for each of the $K_{test}$ outer resamplings, there could be a different model that predicts on the test set
\item In procedure [B], the final model will be the modal model out of the $K_{test}$ models selected
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{8} \ingray{Consider the \texttt{diamonds} data frame, which has $n = 53940$ diamonds with 9 measurements each and the response variable \texttt{price} measured in USD.} Beginning with the design matrix $\tilde{\X}$ created by the OLS model of $y \sim . * . * .$ we consider the \emph{greedy forward stepwise} linear model algorithm. The dataset is sampled into a distinct training set of size $n=3,000$, a distinct select set of $n=3,000$ and a distinct test set of $n=3,000$ and these three subsets are used in accordance with the modeling selection procedure we learned about in class.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{7}

\begin{enumerate}[(a)]
\item This algorithm at most has $p+1$ iterations where $p+1$ is the number of columns in $\tilde{\X}$ and in each iteration, it fits a different linear model
\item This algorithm likely has less than $p+1$ iterations
\item The prediction error in the training set is monotonically decreasing
\item The prediction error in the select set is monotonically decreasing
\item The prediction error in the test set is monotonically decreasing
\item When predicting on the test set, the model will definitely have the same number of degrees of freedom as the final model
\item The future performance of the model selected by the \emph{greedy forward stepwise} linear model algorithm will be better than the future performance of the OLS model of  $y \sim .$ based on your knowledge of this dataset from class
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{7} \ingray{Consider the \texttt{diamonds} data frame, which has $n = 53,940$ diamonds with 9 measurements each and the response variable \texttt{price} measured in USD. Beginning with the design matrix $\tilde{\X}$ created by the OLS model of $y \sim . * . * .$ we consider the \emph{greedy forward stepwise} linear model algorithm. The dataset is sampled into a distinct training set of size $n=3,000$, a distinct select set of $n=3,000$ and a distinct test set of $n=3,000$ and these three subsets are used in accordance with the modeling selection procedure we learned about in class.} The design matrix $\tilde{\X}$ has $p+1 = 1477$ number of columns. Consider the case where we run through all of the $t = 1, 2, \ldots, 1477$ iterations of this stepwise algorithm.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{7}

Let $g_t$ denote the model fit at every iteration $t$.

\begin{enumerate}[(a)]
\item As $t$ increases the bias of $g_t$ increases monotonically
\item As $t$ increases the variance of $g_t$ increases monotonically
\item As $t$ increases the MSE of $g_t$ increases monotonically
\item $g_1, g_2, \ldots, g_{1477}$ are independent models\\

Consider the model $g_{avg}$ that averages models $g_1, g_2, \ldots, g_{1477}$.

\item $g_{avg}$ is called a \qu{bagged} model
\item $g_{avg}$ has lower bias than $g_{1477}$
\item $g_{avg}$ always has lower MSE than the model that was selected by the greedy forward stepwise linear model algorithm
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{12} Consider the \texttt{adult} data frame, which has data on $n = 32,560$ people with 14 measurements each and the response variable \texttt{income} which is binary (1 = the person has an income $>$50K and 0 = the person has an income  $\leq$50K). Consider the following model fit to \texttt{adult\_train}, a training set of $n=10,000$ leaving the remainder of the data as a holdout set. The $\b$ vector for the fitted model is displayed below on the last line.

\lstset{
  basicstyle=\footnotesize,
  xleftmargin=.0\textwidth, xrightmargin=.0\textwidth
}
\begin{lstlisting}
> lmod = glm(income ~ age + hours_per_week + capital_gain + education_num, adult_train, family = "binomial")
Warning message:
glm.fit: fitted probabilities numerically 0 or 1 occurred
> coef(lmod)
   (Intercept)            age hours_per_week   capital_gain  education_num
       -8.1582         0.0454         0.0380         0.0003         0.3200
\end{lstlisting}

\vspace{-0.8cm}\benum\truefalsesubquestionwithpoints{12}

\begin{enumerate}[(a)]
\item The vector $\b$ was computed solely using linear algebra calculations
\item For a future person $\x_*$, the quantity $\x_*\b$ can be used to produce probability predictions in the set (0, 1)
\item For a future person $\x_*$, if $\x_*\b < 0$, this model is predicting that it is impossible for this person's income to be $>$50K
\item The Brier score for this model's predictions in-sample will likely be closer to zero than the Brier score for predictions out-of-sample.
\item The probability predictions of this model will be the same predictions as a probit model fit to the same data
\item \qu{For a future person $\x_*$, the probability that this person's income $>$50K will increase by 0.044 if the person becomes one year older}.
\item \qu{For a future person $\x_*$, the probability that this person's income $>$50K will increase by 0.044 if the person becomes one year older as long as the three other measurements for this person do not change}.
\item If \texttt{age} increases and the three other variables remain the same, the predicted probability will increase for any $\x$
\item The warning message means there was numerical underflow and/or overflow during the computation of $\b$
\item For a 20yr-old with no job, capital gains or education, the probability he has an income of $>$50K is 0.9993 to the nearest four significant digits
\item For a 20yr-old with no job, capital gains or education, the probability he has an income of $>$50K is 0.0007095 to the nearest four significant digits
\item You have all the information necessary in this problem statement to trace out a DET curve
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{14} \ingray{Consider the \texttt{adult} data frame, which has data on $n = 32,560$ people with 14 measurements each and the response variable \texttt{income} which is binary (1 = the person has an income $>$50K and 0 = the person has an income  $\leq$50K).} Considering the model from the previous quesiton fit to \texttt{adult\_train}, a training set of $n=10,000$ leaving the remainder of the data as a holdout set, we now predict on \texttt{adult\_test} and perform binary classification:

\lstset{
  basicstyle=\footnotesize,
  xleftmargin=.15\textwidth, xrightmargin=.15\textwidth
}
\begin{lstlisting}
> yhat = as.numeric(predict(lmod, adult_test, type = "response") > 0.9)
> table(y_test, yhat)
             yhat
y_test     0     1
     0 15107    30
     1  4439   585
\end{lstlisting}

\vspace{-0.8cm}\benum\truefalsesubquestionwithpoints{9}

\begin{enumerate}[(a)]
\item This is likely an asymmetric cost classification model
\item The FDR, FOR, FPR calculated using the above table are honest estimates of future performance
\item This model makes mistakes 22.2\% of the time to the nearest three significant digits
\item This classification model is absolutely the best classification model you could build from \texttt{lmod} to minimize costs when the cost of a FP is \$9 and the cost of a FN is \$9
\item This model implies the point (0.00198, 0.116) on an ROC curve to the nearest three significant digits
\item When predicting in the future using this classification model, if $\hat{y} = 1$, then the probability of making an error is 4.88\% to the nearest three signification digits
\item If the cost of a false positive is \$100 and the cost of false negatives was negligible and there is no reward for classifying correctly, then you expect to lose \$0.15 per prediction to the nearest two signification digits
\item If the probability threshold was increased within the binary classification model, then the number of FP's would decrease
\item You have all the information necessary in this problem statement to compute the AUC for \texttt{lmod}
\end{enumerate}
\eenum\instr\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%!TEX root = forallxyyc-solutions.tex
%\part{Interpretations}
%\label{ch.semantics}
%\addtocontents{toc}{\protect\mbox{}\protect\hrulefill\par}

\stepcounter{chapter} % Extensionality

\chapter{Truth in FOL}\setcounter{ProbPart}{0}
\problempart
\label{pr.TorF1}
Consider the following interpretation:
	\begin{ebullet}
		\item The domain comprises only Corwin and Benedict
		\item `$\atom{A}{x}$' is to be true of both Corwin and Benedict
		\item `$\atom{B}{x}$' is to be true of Benedict only
		\item `$\atom{N}{x}$' is to be true of no one
		\item `$c$' is to refer to Corwin
	\end{ebullet}
Determine whether each of the following sentences is true or false in that interpretation:
\begin{earg}
\item $\atom{B}{c}$ \hfill \myanswer{False}
\item $\atom{A}{c} \eiff \enot \atom{N}{c}$ \hfill \myanswer{True}
\item $\atom{N}{c} \eif (\atom{A}{c} \eor \atom{B}{c})$ \hfill \myanswer{True}
\item $\forall x\,\atom{A}{x}$ \hfill \myanswer{True}
\item $\forall x \enot \atom{B}{x}$ \hfill \myanswer{False}
\item $\exists x(\atom{A}{x} \eand \atom{B}{x})$ \hfill \myanswer{True}
\item $\exists x(\atom{A}{x} \eif \atom{N}{x})$ \hfill \myanswer{False}
\item $\forall x(\atom{N}{x} \eor \enot \atom{N}{x})$ \hfill \myanswer{True}
\item $\exists x\,\atom{B}{x} \eif \forall x\,\atom{A}{x}$ \hfill \myanswer{True}
\end{earg}

\problempart
\label{pr.TorF2}
Consider the following interpretation:
	\begin{ebullet}
		\item The domain comprises only Lemmy, Courtney and Eddy
		\item `$\atom{G}{x}$' is to be true of Lemmy, Courtney and Eddy.
		\item `$\atom{H}{x}$' is to be true of and only of Courtney
		\item `$\atom{M}{x}$' is to be true of and only of Lemmy and Eddy
		\item `$c$' is to refer to Courtney
		\item `$e$' is to refer to Eddy
	\end{ebullet}
Determine whether each of the following sentences is true or false in that interpretation:
\begin{earg}
\item $\atom{H}{c}$ \hfill \myanswer{True}
\item $\atom{H}{e}$\hfill \myanswer{False}
\item $\atom{M}{c} \eor \atom{M}{e}$ \hfill \myanswer{True}
\item $\atom{G}{c} \eor \enot \atom{G}{c}$ \hfill \myanswer{True}
\item $\atom{M}{c} \eif \atom{G}{c}$ \hfill \myanswer{True}
\item $\exists x\,\atom{H}{x}$ \hfill \myanswer{True}
\item $\forall x\,\atom{H}{x}$ \hfill \myanswer{False}
\item $\exists x \enot \atom{M}{x}$ \hfill \myanswer{True}
\item $\exists x(\atom{H}{x} \eand \atom{G}{x})$ \hfill \myanswer{True}
\item $\exists x(\atom{M}{x} \eand \atom{G}{x})$ \hfill \myanswer{True}
\item $\forall x(\atom{H}{x} \eor \atom{M}{x})$ \hfill \myanswer{True}
\item $\exists x\,\atom{H}{x} \eand \exists x\,\atom{M}{x}$ \hfill \myanswer{True}
\item $\forall x(\atom{H}{x} \eiff \enot \atom{M}{x})$ \hfill \myanswer{True}
\item $\exists x\,\atom{G}{x} \eand \exists x \enot \atom{G}{x}$ \hfill \myanswer{False}
\item $\forall x\exists y(\atom{G}{x} \eand \atom{H}{y})$ \hfill \myanswer{True}
\end{earg}

\problempart
\label{pr.TorF3}
Following the diagram conventions introduced at the end of \S23, consider the following interpretation:
\begin{center}
\begin{tikzpicture}
\node (atom1) at (0,2) {1};
\node (atom2) at (2,2) {2};
\node (atom4) at (0,0) {3};
\node (atom5) at (2,0) {4};
\node (atom6) at (4,0) {5};
\draw[->, thick] (atom1)+(-0.15,0.15) arc (-330:-30:.3);
\draw[->, thick] (atom6)+(0.15,-0.15) arc (-150:150:.3);
\draw[->, thick] (atom1) -- (atom2);
\draw[->, thick] (atom1) -- (atom4);
\draw[<->, thick] (atom1) -- (atom5);
\draw[->, thick] (atom1) -- (atom6);
\draw[->, thick] (atom2) -- (atom6);
\end{tikzpicture}
\end{center}
Determine whether each of the following sentences is true or false in that interpretation:
\begin{earg}
\item $\exists x\,\atom{R}{x,x}$ \hfill \myanswer{True}
\item $\forall x\,\atom{R}{x,x}$ \hfill \myanswer{False}
\item $\exists x \forall y\,\atom{R}{x,y}$ \hfill \myanswer{True}
\item $\exists x \forall y\,\atom{R}{y,x}$ \hfill \myanswer{False}
\item $\forall x \forall y \forall z ((\atom{R}{x,y} \eand \atom{R}{y,z}) \eif \atom{R}{x,z})$ \hfill \myanswer{False}
\item $\forall x \forall y \forall z ((\atom{R}{x,y} \eand \atom{R}{x,z}) \eif \atom{R}{y,z})$ \hfill \myanswer{False}
\item $\exists x \forall y \enot \atom{R}{x,y}$ \hfill \myanswer{True}
\item $\forall x(\exists y\,\atom{R}{x,y} \eif \exists y\,\atom{R}{y,x})$ \hfill \myanswer{True}
\item $\exists x \exists y (\enot x = y \eand \atom{R}{x,y} \eand \atom{R}{y,x})$ \hfill \myanswer{True}
\item $\exists x \forall y(\atom{R}{x,y} \eiff x = y)$ \hfill \myanswer{True}
\item $\exists x \forall y(\atom{R}{y,x} \eiff x = y)$ \hfill \myanswer{False}
\item $\exists x \exists y(\enot x = y \eand \atom{R}{x,y} \eand \forall z(\atom{R}{z,x} \eiff y = z))$ \hfill \myanswer{True}
\end{earg}

\stepcounter{chapter} % Semantic concepts

\chapter{Using Interpretations}\setcounter{ProbPart}{0}

\solutions
\problempart
\label{pr.Contingent}
Show that each of the following is neither a validity nor a contradiction:
\begin{earg}
\item $\atom{D}{a} \eand \atom{D}{b}$

\myanswer{The sentence is true in this model:
\begin{ekey}
	\item[\text{domain}] Stan
	\item[D(x)] Stan
	\item[a] Stan
	\item[b] Stan
\end{ekey}
And it is false in this model:
\begin{ekey}
	\item[\text{domain}] Stan
	\item[D(x)] % $\emptyset$
	\item[a] Stan
	\item[b] Stan
\end{ekey}}
\item \leftsolutions\ $\exists x\,\atom{T}{x,h}$

\myanswer{The sentence is true in this model:
\begin{ekey}
	\item[\text{domain}] Stan
	\item[T(x,y)] \ntuple{Stan, Stan}
	\item[h] Stan
\end{ekey}
And it is false in this model:
\begin{ekey}
	\item[\text{domain}] Stan
	\item[T(x,y)] % $\emptyset$
	\item[h] Stan
\end{ekey}}

\item $\atom{P}{m} \eand \enot\forall x\,\atom{P}{x}$

\myanswer{	The sentence is true in this model:
\begin{ekey}
	\item[\text{domain}] Stan, Ollie
	\item[P(x)] Stan
	\item[m] Stan
\end{ekey}
And it is false in this model:
\begin{ekey}
	\item[\text{domain}] Stan
	\item[P(x)] % $\emptyset$
	\item[m] Stan
\end{ekey}}
\item $\forall z\, \atom{J}{z} \eiff \exists y\,\atom{J}{y}$
\item $\forall x (\atom{W}{x,m,n} \eor \exists y\atom{L}{x,y})$
\item $\exists x (\atom{G}{x} \eif \forall y\,\atom{M}{y})$
\item $\exists x (x = h \eand x = i)$
\end{earg}

\solutions
\problempart
\label{pr.NotEquiv}
Show that the following pairs of sentences are not logically equivalent.
\begin{earg}
\item $\atom{J}{a}$, $\atom{K}{a}$

\myanswer{Making the first sentence true and the second false:
\begin{ekey}
	\item[\text{domain}] $0$
	\item[J(x)] $0$
	\item[K(x)] % $\emptyset$
	\item[a] $0$
\end{ekey}}
\item $\exists x\,\atom{J}{x}$, $\atom{J}{m}$

\myanswer{Making the first sentence true and the second false:
\begin{ekey}
	\item[\text{domain}] $0$, $1$
	\item[J(x)] $0$
	\item[m] $1$
\end{ekey}}
\item $\forall x\,\atom{R}{x,x}$, $\exists x\,\atom{R}{x,x}$

\myanswer{Making the first sentence false and the second true:
\begin{ekey}
	\item[\text{domain}] $0$, $1$
	\item[R(x,y)] \ntuple{$0$,$0$}
\end{ekey}}
\item $\exists x\,\atom{P}{x} \eif \atom{Q}{c}$, $\exists x (\atom{P}{x} \eif \atom{Q}{c})$

\myanswer{Making the first sentence false and the second true:
\begin{ekey}
	\item[\text{domain}] $0$, $1$
	\item[P(x)] $0$
	\item[Q(x)] % $\emptyset$
	\item[c] $0$
\end{ekey}}
\item $\forall x(\atom{P}{x} \eif \enot \atom{Q}{x})$, $\exists x(\atom{P}{x} \eand \enot \atom{Q}{x})$

\myanswer{Making the first sentence true and the second false:
\begin{ekey}
	\item[\text{domain}] $0$
	\item[P(x)] % $\emptyset$
	\item[Q(x)] % $\emptyset$
\end{ekey}}
\item $\exists x(\atom{P}{x} \eand \atom{Q}{x})$, $\exists x(\atom{P}{x} \eif \atom{Q}{x})$

\myanswer{Making the first sentence false and the second true:
\begin{ekey}
	\item[\text{domain}] $0$
	\item[P(x)] % $\emptyset$
	\item[Q(x)] $0$
\end{ekey}}
\item $\forall x(\atom{P}{x}\eif \atom{Q}{x})$, $\forall x(\atom{P}{x} \eand \atom{Q}{x})$

\myanswer{Making the first sentence true and the second false:
\begin{ekey}
	\item[\text{domain}] $0$
	\item[P(x)] % $\emptyset$
	\item[Q(x)] $0$
\end{ekey}}
\item $\forall x\exists y\,\atom{R}{x,y}$, $\exists x\forall y\,\atom{R}{x,y}$

\myanswer{Making the first sentence true and the second false:
\begin{ekey}
	\item[\text{domain}] $0$, $1$
	\item[R(x,y)] \ntuple{$0$, $1$}, \ntuple{$1$, $0$}
\end{ekey}}
\item $\forall x\exists y\,\atom{R}{x,y}$, $\forall x\exists y\,\atom{R}{y,x}$

\myanswer{Making the first sentence false and the second true:
\begin{ekey}
	\item[\text{domain}] $0$, $1$
	\item[R(x,y)] \ntuple{$0$, $0$}, \ntuple{$0$, $1$}
\end{ekey}}
\end{earg}

\problempart
Show that the following sentences are jointly satisfiable:
\begin{earg}
\item $\atom{M}{a}, \enot \atom{N}{a}, Pa, \enot \atom{Q}{a}$
\item $\atom{L}{e,e}, \atom{L}{e,g}, \enot \atom{L}{g,e}, \enot \atom{L}{g,g}$
\item $\enot (\atom{M}{a} \eand \exists x\,\atom{A}{x}), Ma \eor \atom{F}{a}, \forall x(\atom{F}{x} \eif \atom{A}{x})$
\item $\atom{M}{a} \eor \atom{M}{b}, \atom{M}{a} \eif \forall x \enot \atom{M}{x}$
\item $\forall y\,\atom{G}{y}, \forall x (\atom{G}{x} \eif \atom{H}{x}), \exists y \enot \atom{I}{y}$
\item $\exists x(\atom{B}{x} \eor \atom{A}{x}), \forall x \enot \atom{C}{x}, \forall x\bigl[(\atom{A}{x} \eand \atom{B}{x}) \eif Cx\bigr]$
\item $\exists x\,\atom{X}{x}, \exists x\,\atom{Y}{x}, \forall x(\atom{X}{x} \eiff \enot \atom{Y}{x})$
\item $\forall x(\atom{P}{x} \eor \atom{Q}{x}), \exists x\enot(\atom{Q}{x} \eand \atom{P}{x})$
\item $\exists z(\atom{N}{z} \eand \atom{O}{z,z}), \forall x\forall y(\atom{O}{x,y} \eif \atom{O}{y,x})$
\item $\enot \exists x \forall y\,\atom{R}{x,y}, \forall x \exists y\,\atom{R}{x,y}$
\item $\enot \atom{R}{a,a}$, $\forall x (x=a \eor \atom{R}{x,a})$

\myanswer{The sentences are both true in this interpretation:
\begin{ekey}
	\item[\text{domain}] Harry, Sally
	\item[R(x,y)]\ntuple{Sally, Harry}
	\item[a] Harry
	\end{ekey}}
\item $\forall x\forall y\forall z[(x=y \eor y=z )\eor x=z]$, $\exists x\exists y\ \enot x= y$

\myanswer{There are no predicates or constants, so we only need to give a domain.
Any domain with 2 elements will do.}
\item $\exists x\exists y((\atom{Z}{x} \eand \atom{Z}{y} )\eand x=y)$, $\enot \atom{Z}{d}$, $d=e$
\end{earg}

\problempart
Show that the following arguments are invalid:
\begin{earg}
\item $\forall x(\atom{A}{x} \eif \atom{B}{x}) \therefore \exists x\,\atom{B}{x}$
\item $\forall x(\atom{R}{x} \eif \atom{D}{x}), \forall x(\atom{R}{x} \eif \atom{F}{x}) \therefore \exists x(\atom{D}{x} \eand \atom{F}{x})$
\item $\exists x(\atom{P}{x}\eif \atom{Q}{x}) \therefore \exists x\,\atom{P}{x}$
\item $\atom{N}{a} \eand \atom{N}{b} \eand \atom{N}{c} \therefore \forall x\,\atom{N}{x}$
\item $\atom{R}{d,e}, \exists x\,\atom{R}{xd} \therefore \atom{R}{e,d}$
\item $\exists x(\atom{E}{x} \eand \atom{F}{x}), \exists x\,\atom{F}{x} \eif \exists x\,\atom{G}{x} \therefore \exists x(\atom{E}{x} \eand \atom{G}{x})$
\item $\forall x\,\atom{O}{x,c}, \forall x\,\atom{O}{c,x} \therefore \forall x\,\atom{O}{x,x}$
\item $\exists x(\atom{J}{x} \eand \atom{K}{x}), \exists x \enot \atom{K}{x}, \exists x \enot \atom{J}{x} \therefore \exists x(\enot \atom{J}{x} \eand \enot \atom{K}{x})$
\item $\atom{L}{a,b} \eif \forall x\,\atom{L}{x,b}, \exists x\,\atom{L}{x,b} \therefore \atom{L}{b,b}$
\item $\forall x(\atom{D}{x} \eif \exists y\,\atom{T}{y,x}) \therefore \exists y \exists z\ \enot y= z$
\end{earg}

\stepcounter{chapter} % Reasoning about interpretations


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%

%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE

\newcommand{\exercisesection}[1]{\subsection*{#1}}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
Project 4, deadline  April 30
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf Stock Market model${}^{}$} \\ [0mm]
\end{center}

\begin{center}
% List of all institutions:
\end{center}

% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Spring semester 2017
\end{center}
% --- end date ---

\vspace{1cm}

\subsection*{Theoretical background and description of the system}

The aim of this project is to simulate financial transactions among financial agents
using Monte Carlo methods. The final goal is to extract a distribution of income  as function
of the income $m$.   From Pareto's work (\href{{http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto}}{V.~Pareto, 1897}) it is known from empirical studies
that the higher end of the distribution of money follows a distribution
\[
w_m\propto m^{-1-\alpha},
\]
with $\alpha\in [1,2]$. We will here follow the analysis made by \href{{http://www.sciencedirect.com/science/article/pii/S0378437104004327}}{Patriarca and collaborators}.

Here we will study numerically the relation between the micro-dynamic relations among financial
agents and the  resulting macroscopic money distribution.

We assume we have $N$ agents that exchange money in pairs $(i,j)$. We assume also that all agents
start with the same amount of money $m_0 > 0$. At a given 'time step', we choose randomly a pair
of agents $(i,j)$ and let a transaction take place. This means that agent $i$'s money $m_i$ changes
to $m_i'$ and similarly we have $m_j\rightarrow m_j'$.
Money is conserved during a transaction, meaning that
\begin{equation}
  m_i+m_j=m_i'+m_j'.
  \label{eq:conserve}
\end{equation}
The change is done via a random reassignement (a random number) $\epsilon$, meaning that

\begin{equation*}
m_i' = \epsilon(m_i+m_j),
\end{equation*}
leading to

\begin{equation*}
m_j'= (1-\epsilon)(m_i+m_j).
\end{equation*}
The number $\epsilon$ is extracted from a uniform distribution.
In this simple model, no agents are left with a debt, that is $m\ge 0$.
Due to the conservation law above, one can show that the system relaxes toward an equilibrium
state given by a Gibbs distribution

\begin{equation*}
w_m=\beta \exp{(-\beta m)},
\end{equation*}
with

\begin{equation*}
\beta = \frac{1}{\langle m\rangle},
\end{equation*}
and $\langle m\rangle=\sum_i m_i/N=m_0$, the average money.
It means that after equilibrium has been reached that the majority of agents is left with a small
number of money, while the number of richest agents, those with $m$ larger than a specific value $m'$,
exponentially decreases with $m'$.

We assume that we have $N=500$ agents.   In each simulation, we need a sufficiently large number of transactions, say $10^7$. Our aim is find the final equilibrium distribution $w_m$. In order to do that we would need
several runs of the above simulations, at least $10^3-10^4$ runs (experiments).

\paragraph{Project 4a): Simulation of Transactions.}
Your task is to first set up an algorithm which simulates the above transactions with an initial
  amount $m_0$.
  The challenge here is to figure out a Monte Carlo  simulation  based on the
  above equations.
  You will in particular need to make an algorithm which sets up a histogram as function of $m$.
  This histogram contains the number of times a value $m$ is registered and represents
  $w_m\Delta m$. You will need to set up a value for the interval $\Delta m$  (typically $0.01-0.05$).
  That means you need to account for the number of times you register an income in the interval
  $m,m+\Delta m$. The number of times you register this income, represents the value that enters the histogram.
  You will also need to find a criterion for when the equilibrium situation has been reached.

\paragraph{Project 4b): Recognizing the distribution.}
Make thereafter a plot of  $\log{(w_m)}$ as function of $m$
  and see if you get a straight line.
  Comment the result.

\paragraph{Project 4c): Transactions and savings.}
We can then change our model to allow for a saving criterion, meaning that the agents save
  a fraction $\lambda$ of the money they have before the transaction is made. The final distribution will then no longer be given by Gibbs distribution. It could also include a taxation on financial transactions.

  The conservation law of Eq. (\ref{eq:conserve}) holds, but the money to be shared in a transaction between
  agent $i$ and agent $j$ is now $(1-\lambda)(m_i+m_j)$. This means that we have

\begin{equation*}
  m_i' = \lambda m_i+\epsilon(1-\lambda)(m_i+m_j),
  \end{equation*}
  and

\begin{equation*}
  m_j' = \lambda m_j+(1-\epsilon)(1-\lambda)(m_i+m_j),
  \end{equation*}
  which can be written as

\begin{equation*}
  m_i'=m_i+\delta m
  \end{equation*}
  and

\begin{equation*}
  m_j'=m_j-\delta m,
  \end{equation*}
  with

\begin{equation*}
  \delta m=(1-\lambda)(\epsilon m_j-(1-\epsilon)m_i),
  \end{equation*}
  showing how money is conserved during a transaction.
  Select values of $\lambda =0.25,0.5$ and $\lambda=0.9$ and try to extract the corresponding
  equilibrium distributions and compare these with the Gibbs distribution. Comment your results.
Extract a parametrization of the above curves, see for example \href{{http://www.sciencedirect.com/science/article/pii/S0378437104004327}}{Patriarca and collaborators} and see if you can parametrize the high-end tails of the distributions in terms of power laws. Comment your results.

\paragraph{Project 4d): Nearest neighbor interactions.}
In the rest of this project we will follow the work of \href{{http://www.sciencedirect.com/science/article/pii/S0378437114006967}}{Goswami and Sen}.
In the studies above the agents were selected randomly, irrespective of whether we allowed for
saving or not during a transaction. What is often observed is that various agents tend to make preferences for for whom to interact with. We will now study the evolution of the distribution of wealth $w_m$ by assuming that there is a likelihood
\[
p_{ij} \propto \vert m_i-m_j\vert^{-\alpha},
\]
for an interaction between agents $i$ and $j$ with respective wealths $m_i$ and $m_j$. The parameter  $\alpha >  0$. For $\alpha=0$ we recover our model from part 5a).
Perform the same analysis as previously with $N=500$ as well as with $N=1000$ agents and study the distribution of wealth for $\alpha =0.5$, $\alpha =1.0$, $\alpha =1.5$ and $\alpha =2.0$.
You should try to reproduce Figure 1 of \href{{http://www.sciencedirect.com/science/article/pii/S0378437114006967}}{Goswami and Sen}.
Extract the tail of the distribution and see if it follows a Pareto distribution
\[
w_m\propto m^{-1-\alpha}.
\]
What happens if $\alpha \gg 1$?

Perform the analysis with and without a saving $\lambda$ on each transaction and comment your results.
\paragraph{Project 4e): Nearest neighbors and former  transactions.}
We add to the previous probability the possibility that two agents who interact have performed similar transactions earlier. That is, in addition to being financially close, we assume that the likelihood for interacting increases if two agents have interacted earlier.
We add this feature by modifying the previous likelihood to
\[
p_{ij} \propto \vert m_i-m_j\vert^{-\alpha}\left(c_{ij}+1\right)^{\gamma},
\]
where $c_{ij}$ represents the number of  previous interactions that have taken place between $i$ and $j$. The factor $1$ is added in order to ensure that if they have not interacted earlier they can still interact.  Perform similar studies as above with $N=1000$, $\alpha=1.0$ and $\alpha=2.0$ using $\gamma = 0.0, 1.0, 2.0, 3.0$ and $4.0$. Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving $\lambda$ in each transaction. Comment your results and compare them with figures 5 and 6 of \href{{http://www.sciencedirect.com/science/article/pii/S0378437114006967}}{Goswami and Sen}.

Finally, (this part is optional) if you have time, which features would you add to these models in order to make them even more realistic?

\subsection*{Background literature}

\begin{itemize}
  \item \href{{http://www.institutcoppet.org/2012/05/08/cours-deconomie-politique-1896-de-vilfredo-pareto}}{V. Pareto, Cours d'economie politique, Lausanne, 1897}.

  \item \href{{http://www.sciencedirect.com/science/article/pii/S0378437104004327}}{M. Patriarca, A. Chakraborti, K. Kaski, Physica A \textbf{340}, 334 (2004)}.

  \item \href{{http://www.sciencedirect.com/science/article/pii/S0378437114006967}}{S. Goswami and P. Sen, Physica A \textbf{415}, 514 (2014)}.
\end{itemize}

\noindent
\subsection*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.

\begin{itemize}
  \item Give a short description of the nature of the problem and the eventual  numerical methods you have used.

  \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.

  \item Include the source code of your program. Comment your program properly.

  \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.

  \item Include your results either in figure form or in a table. Remember to        label your results. All tables and figures should have relevant captions        and labels on the axes.

  \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.

  \item Try to give an interpretation of you results in your answers to  the problems.

  \item Critique: if possible include your comments and reflections about the  exercise, whether you felt you learnt something, ideas for improvements and  other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.

  \item Try to establish a practice where you log your work at the  computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember  what a previous test version  of your program did. Here you could also record  the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
\end{itemize}

\noindent
\subsection*{Format for electronic delivery of report and programs}

The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file.  As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:

\begin{itemize}
  \item Use your github repository to upload your report. Indicate where the report is by creating for example a \textbf{Report} folder. Please send us as soon as possible your github username.

  \item Place your programs in a folder called for example \textbf{Programs} or \textbf{src}, in order to indicate where your programs are. You can use a README file to tell us how your github folders are organized.

  \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.

  \item In this and all later projects, you should include tests (for example unit tests) of your code(s).

  \item Comments  from us on your projects, with score and detailed feedback will be emailed to you.
\end{itemize}

\noindent
Finally,
we encourage you to work two and two together. Optimal working groups consist of
2-3 students. You can then hand in a common report.

% ------------------- end of main content ---------------

\end{document}


\documentclass{beamer}
\usetheme{Copenhagen}

\title{Introduction to Python}
\usepackage{listings}
\subtitle{Iterables, Iterators and Generators}
\date{13 November 2015}

\begin{document}
\definecolor{keywords}{RGB}{255,0,90}
\definecolor{comments}{RGB}{0,0,113}
\definecolor{red}{RGB}{160,0,0}
\definecolor{green}{RGB}{0,150,0}
\lstset{language=Python,
        basicstyle=\ttfamily\small,
        keywordstyle=\color{keywords},
        commentstyle=\color{comments},
        stringstyle=\color{red},
        showstringspaces=false,
        identifierstyle=\color{green},
        procnamekeys={def,class}}
\begin{frame}
  \titlepage
\end{frame}

\section{Iterables}
\begin{frame}[fragile]{Examples 1}
  \begin{itemize}
	\item {We have already seen that loops in Python are pretty flexible:
	\pause
  \begin{block}{}
\begin{lstlisting}{frame=single}
for i in [1,2,3]:
    print i # prints elements
for	i in "123":
    print i # prints characterwise
\end{lstlisting}
\end{block}
	}
  \end{itemize}
\end{frame}
\begin{frame}[fragile]{Examples 2}
  \begin{itemize}
	\item {We have already seen that loops in Python are pretty flexible (excuse lack of indentation):
  \begin{block}{}
\begin{lstlisting}{frame=single}
for i in xrange(4):
    print i #prints the range without storing
for i in enumerate([1,2,3]):
    print i # gives me indices as well as elements
\end{lstlisting}
\end{block}
	}
	\pause
	\item{ Hopefully you see this and think how do I do that in my code!}
  \end{itemize}
\end{frame}
\begin{frame}[fragile]{Definition}
  \begin{itemize}
	\item { An \textbf{iterable} is any object that responds to the function iter(obj)
	}
	\pause
	\item{ Python likes to hide this!
  \begin{block}{}
  \begin{lstlisting}{frame=single}
	for i in x:
	    # Do loop stuff
  \end{lstlisting}
\end{block}
}
\item Call iter(x) and assign to some name that is never used in the code.
\pause
\item iter(x) returns an object that can do one thing and one thing alone - respond to \_\_next\_\_()
\pause
\item Assign i to the response to \_\_next\_\_() each time round until it throws StopIteration exception (sort of an error) and then move on.
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Definition}
  \begin{itemize}
  \begin{block}{}
  \begin{lstlisting}{frame=single}
	for i in x:
	    # Do loop stuff
  \end{lstlisting}
\end{block}
	\item{ This is equivalent to:
  \begin{block}{}
  \begin{lstlisting}{frame=single}
  randomName = iter(x)
  while(True):
      try:
          i = randomName.__next__()
          # Do loop stuff
      except StopIteration:
           break
  \end{lstlisting}
\end{block}
}
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Uses for Iterables}
  \begin{itemize}
	\item{ Iterables can be used all over the place!
  \begin{block}{}
  \begin{lstlisting}{frame=single}
  new_list = list(iterable)
  total = sum(iterable)
  smallest = min(iterable)
  largest = max(iterable)
  combined = ''.join(iterable)
  result = [f(x) for x in iterable]
 \end{lstlisting}
\end{block}
}

\end{itemize}
\end{frame}
\section{Generators}
\begin{frame}[fragile]{Make your own iterables}
  \begin{itemize}
  \item{ To make an object and iterable you only need to define the \_\_iter\_\_() hook.}
  \item{\textbf{Generators} are a great way to create your own iterables that are extremely flexible}
  \pause
  \item{You define generators in a similar way to function but using the keyword \textbf{yield}
  \begin{block}{}
\begin{lstlisting}{frame=single}
def myXRange(n):
    i = 0
    while( i < n):
        yield i
        i += 1
\end{lstlisting}
\end{block}
}
\pause
\item This responds to the \emph{next} call by running until it hits yield and then stopping and waiting.
\pause
\item Demo Time!
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Make your own iterables 2}
  \begin{itemize}
\item No reason to make our iterable only finite!
\item{ Lets have all of the positive even numbers
\begin{block}{}
\begin{lstlisting}{frame=single}
def evens():
    i = 2
    while True:
        yield i
        i += 2
\end{lstlisting}
\end{block}
}
\pause
\item Be careful when using these! Don't try to make a list out of this one...
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Make your own iterables 3}
\begin{itemize}
\item{ Perhaps most importantly, we can make iterables that depend on other iterables.
\pause
\begin{block}{}
\begin{lstlisting}{frame=single}
def myEnumerate(iterable):
    index = 0
    for i in iterable:
        yield (index,i)
        index += 1
\end{lstlisting}
\end{block}
}
\item Demo Time!
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Fin}
\begin{itemize}
\item Suggested watching: Loop Like A Native, Ned Batchelder
\item Suggested Library: itertools (This probably has what you need!)
\end{itemize}
\end{frame}

\end{document}


%-------------------------------------------------------------------------------
\section{Pre-fit and post-fit event yields in the $\Htautau$ search}
\label{sec:prepostfit_yields_Htautau_appendix}
%-------------------------------------------------------------------------------

Table~\ref{tab:Htautau_Prefit_Yields_Unblind} presents the observed and predicted yields in each of the analysis regions
for the search before the fit to data.
Tables~\ref{tab:Htautau_Postfit_Yields_Unblind_Hc} and~\ref{tab:Htautau_Postfit_Yields_Unblind_Hu} present the observed and predicted yields
in each of the analysis regions after the fit to the data under the signal-plus-background hypothesis, assuming
$tHc$ and $tHu$ as signal, respectively.

%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[htbp]
\caption{
Predicted and observed yields in each of the analysis regions considered.
The prediction is shown before the fit to data. Also shown are the signal expectations for
$\Hc$ and $\Hu$ assuming $\BR(t\to Hc)=0.1\%$ and $\BR(t\to Hu)=0.1\%$ respectively.
The contributions with real $\had$ candidates from $\ttbar$ and  $Z\to \ell^+\ell^-$ ($\ell = e, \mu$), diboson, $\ttbar V$, $\ttbar H$, single-top-quark, and other small backgrounds are combined into
a single background source referred to as ``Other MC'' in the leptonic channels , whereas single-top-quark and the small contributions are combined into ``Rare'' in the hadronic channels.
The quoted uncertainties are the sum in quadrature of statistical and systematic uncertainties of the yields.}
\small
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
 & $t_{l}\tau_{had}-1j$ & $t_{l}\tau_{had}-2j$ & $t_{h}\tau_{lep}\tau_{had}-3j$ & $t_{h}\tau_{lep}\tau_{had}-2j$ & $t_{l}\tau_{had}\tau_{had}$\\\hline
  QCD Fake lep  & $916.84 \pm 469.22$ & $434.65 \pm 218.77$ & $233.82 \pm 155.13$ & $416.75 \pm 232.61$ & $0 \pm 0$ \\
  W-jet fake $\tau$   & $839.60 \pm 257.79$ & $963.47 \pm 297.97$ & $2934.6 \pm 2722.5$ & $3434.22 \pm 3525.35$ & $4.96 \pm 2.80$ \\
  Other Fake $\tau$   & $2918.71 \pm 315.44$ & $2625.87 \pm 196.24$ & $1767.93 \pm 721.15$ & $1635.44 \pm 910.48$ & $138.86 \pm 23.10$ \\
  b Fake $\tau$   & $811.72 \pm 149.76$ & $1015.84 \pm 244.27$ & $522.39 \pm 236.07$ & $573.09 \pm 171.86$ & $68.10 \pm 14.20$ \\
  %tuH   & 71.0825 \pm 8.98689 & 62.9807 \pm 4.44175 & 123.517 \pm 14.72 & 87.6489 \pm 6.581 & 93.0677 \pm 3.83729 \\
  Lep fake $\tau$    & $221.68 \pm 31.75$ & $87.81 \pm 10.74$ & $307.45 \pm 102.87$ & $563.25 \pm 84.76$ & $0.88 \pm 0.36$ \\
  Double Fake $\tau$    & $0 \pm 0$ & $0 \pm 0$ & $0 \pm 0$ & $0 \pm 0$ & $89.74 \pm 37.20$ \\
  $\bar{t}t$   & $280.14 \pm 20.08$ & $178.8 \pm 42.01$ & $7081.53 \pm 2237.99$ & $11610.1 \pm 1263.95$ & $5.10 \pm 4.28$ \\
  Other MC   & $84.62 \pm 8.00$ & $83.30 \pm 3.31$ & $880.00 \pm 233.62$ & $1591.41 \pm 254.97$ & $40.79 \pm 2.02$ \\\hline
  Total B & $6073 \pm 488$ & $5390 \pm 291$ & $13728 \pm 1192$ & $19824 \pm 2091$ & $348 \pm 42$ \\ \hline
  Data & $6353\pm80$ & $5390 \pm 291$ & $35942\pm190$ & $50412\pm225$ & $351\pm19$\\\hline
  $\bar{t}t\to bWcH$ & $57.59\pm0.61$ &$52.80\pm0.58$ & $133.14\pm1.19$ &$102.58\pm0.97$ & $66.43\pm0.65$\\
$cg\to tH$ & $2.23\pm0.04$ & $1.38\pm0.03$  & $4.47\pm0.08$ & $5.66\pm0.08$ & $5.10\pm0.06$\\
tcH~merged & $59.82\pm0.61$ & $54.19\pm0.58$ & $137.61\pm1.19$ & $108.24\pm0.98$ & $71.53\pm0.65$\\\hline
$\bar{t}t\to bWuH$ & $59.72\pm7.52$ & $55.47\pm3.91$ & $139.67\pm16.65$ & $105.62\pm7.93$ & $69.10\pm2.85$\\
$ug\to tH$ & $11.36\pm1.43$ &$7.51\pm0.53$ & $24.78\pm3.00$ &$28.60\pm2.15$ & $24.00\pm1.00$\\
tuH~merged & $71.08\pm9.00$ & $62.98\pm4.44$ & $164.45\pm19.60$ & $134.22\pm10.10$ & $93.10\pm3.84$\\\hline
 % Total  & 6144.39 \pm 487.946 & 5452.72 \pm 291.302 & 13851.2 \pm 1191.74 & 19911.9 \pm 2091.1 & 441.49 \pm 41.7833 \\
\hline
\end{tabular}
\begin{tabular}{|c|c|c|}
\hline
 & $t_{h}\tau_{had}\tau_{had}-2j$ & $t_{h}\tau_{had}\tau_{had}-3j$\\
\hline
  only $\tau_{sub}$ real   & $64.23 \pm 70.07$ & $84.46 \pm 100.98$ \\
  %tcH   & 31.4803 \pm 6.36964 & 84.4383 \pm 10.5275 \\
  %tuH   & 45.6609 \pm 6.76374 & 105.38 \pm 10.798 \\
  Diboson   & $8.40 \pm 1.65$ & $10.75 \pm 1.25$ \\
  Fake $\tau$ MC   & $277.11 \pm 148.41$ & $332.76 \pm 153.96$ \\
  $\bar{t}t$   & $225.85 \pm 34.02$ & $209.75 \pm 50.43$ \\
  $Z\rightarrow\tau\tau$   & $485.70 \pm 53.51$ & $406.02 \pm 64.48$ \\
  $\bar{t}tV$   & $0.75 \pm 0.44$ & $5.46 \pm 1.13$ \\
  Rare   & $17.84 \pm 2.96$ & $10.05 \pm 2.72$ \\
  SM Higgs   & $17.29 \pm 2.18$ & $25.88 \pm 2.55$ \\
\hline
Total B  & $1097 \pm 197$ & $1085 \pm 230$ \\ \hline
data                  & $1033\pm32$                   & $1052\pm32$  \\\hline
$\bar{t}t\to bWcH$    & $28.13\pm5.70$        & $80.14\pm9.94$     \\
$cg\to tH$            & $3.35\pm0.67$                 & $4.30\pm0.53$      \\
tcH~merged            & $31.48\pm6.37$                & $84.44\pm10.53$     \\\hline
$\bar{t}t\to bWuH$    & $28.37\pm4.26$        & $83.75\pm8.40$     \\
$ug\to tH$            & $17.29\pm2.59$                & $21.63\pm2.40$     \\
tuH~merged            & $45.66\pm6.76$                & $105.38\pm10.80$    \\\hline
\end{tabular}
%\input{\FCNCTables/tthML/showFake/faketau/postfit/NOMINAL_SROnly/yield_chart}
%\input{\FCNCTables/xTFW/showFake/NOMINAL/yield_chart}
%\begin{center}
%\begin{tabular}{l*{4}{c}}
%\hline\hline
% & $\lephad$, 3j & $\lephad$, $\geq$4j & $\hadhad$, 3j &  $\hadhad$, $\geq$4j \\
%\hline
%$\Hc$  &   $ 89 \pm 14 $ &   $ 226 \pm 43 $ &   $ 46 \pm 14 $ &   $ 122 \pm 32 $ \\
%$\Hu$  &   $ 100 \pm 17 $ &   $ 237 \pm 47 $ &   $ 32 \pm 10 $ &   $ 114 \pm 28 $ \\
%\hline
%Fake $\had$  &   $ 2828 \pm 78 $ &   $ 3200 \pm 100 $ &   $ 710 \pm 110 $ &   $ 500 \pm 62 $ \\
%Top (real $\had$)  &   $ 3840 \pm 720 $ &   $ 3160 \pm 890 $ &   $ 113 \pm 72 $ &   $ 117 \pm 35 $ \\
%$Z \to \tau\tau$  &   $ 420 \pm 140 $ &   $ 320 \pm 120 $ &   $ 283 \pm 99 $ &   $ 267 \pm 96 $ \\
%Other  &   $ 168 \pm 56 $ &   $ 103 \pm 33 $ &   $ 8.9 \pm 2.5 $ &   $ 11.2 \pm 2.5 $ \\
%\hline
%Total background  &   $ 7260 \pm 730 $ &   $ 6770 \pm 880 $ &   $ 1120 \pm 120 $ &   $ 900 \pm 120 $ \\
%\hline
%Data  & 7259  & 6768  & 1119  & 894  \\
%\hline\hline
%\end{tabular}
%%\\
%\vspace{0.2cm}
%
%\end{center}
%\vspace{-0.5cm}
\label{tab:Htautau_Prefit_Yields_Unblind}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[htbp]
\caption{
Predicted and observed yields in each of the analysis regions considered.
The background prediction is shown after the fit to asimov data under the signal-plus-background hypothesis
(assuming $\Hc$ as signal).
The contributions with real $\had$ candidates from $\ttbar$ and  $Z\to \ell^+\ell^-$ ($\ell = e, \mu$), diboson, $\ttbar V$, $\ttbar H$, single-top-quark, and other small backgrounds are combined into
a single background source referred to as ``Other MC'' in the leptonic channels , whereas single-top-quark and the small contributions are combined into ``Rare'' in the hadronic channels.
The quoted uncertainties are the sum in quadrature of statistical and systematic uncertainties of the yields,
computed taking into account correlations among nuisance parameters and among processes.}
\small
\centering
\begin{tabular}{|c|c|c|c|c|c|}\hline
  & $t_{l}\tau_{had}-1j$ & $t_{l}\tau_{had}2j$ & $t_{h}\tau_{lep}\tau_{had}-3j$ & $t_{h}\tau_{lep}\tau_{had}-2j$ & $t_{l}\tau_{had}\tau_{had}$\\\hline
  QCD Fake lep   & $916.84 \pm 213.23$ & $434.65 \pm 98.21$ & $233.82 \pm 77.52$ & $416.75 \pm 107.82$ & $0 \pm 0$ \\
  W-jet fake $\tau$  & $839.60 \pm 176.84$ & $963.47 \pm 211.11$ & $2934.6 \pm 602.46$ & $3434.22 \pm 820.85$ & $4.96 \pm 1.58$ \\
  Other Fake $\tau$  & $2918.71 \pm 217.11$ & $2625.87 \pm 161.15$ & $1767.93 \pm 455.10$ & $1635.44 \pm 784.74$ & $138.86 \pm 14.05$ \\
  b Fake $\tau$  & $811.72 \pm 109.86$ & $1015.84 \pm 158.82$ & $522.39 \pm 69.31$ & $573.09 \pm 75.11$ & $68.10 \pm 8.32$ \\
    tcH   & $59.82 \pm xxx$ & $54.19 \pm xxx$ & $137.61 \pm xxx$ & $108.24 \pm xxx$ & $71.53 \pm xxx$ \\
  Lep fake $\tau$  & $221.68 \pm 29.45$ & $87.81 \pm 9.62$ & $307.45 \pm 33.81$ & $563.25 \pm 60.64$ & $0.88 \pm 0.34$ \\
  Double Fake $\tau$  & $0 \pm 0$ & $0 \pm 0$ & $0 \pm 0$ & $0 \pm 0$ & $89.74 \pm 23.31$ \\
  $\bar{t}t$   & $280.14 \pm 15.02$ & $178.8 \pm 26.84$ & $7081.53 \pm 363.91$ & $11610.1 \pm 475.80$ & $5.10 \pm 2.69$ \\
  Other MC   & $84.62 \pm 7.34$ & $83.30 \pm 3.10$ & $880.00 \pm 67.57$ & $1591.41 \pm 84.97$ & $40.79 \pm 1.75$ \\
\hline
  Total  & $6144 \pm 170$ & $5453 \pm 94$ & $13851 \pm 138$ & $19912 \pm 164$ & $441 \pm 29$ \\ \hline
\end{tabular}
\begin{tabular}{|c|c|c|}
\hline
 & $t_{h}\tau_{had}\tau_{had}-2j$ & $t_{h}\tau_{had}\tau_{had}-3j$\\
\hline
  only $\tau_{sub}$ real   & $64.23 \pm 49.64$ & $84.46 \pm 66.13$ \\
  tcH   & $31.48 \pm 9.43$ & $84.44 \pm 22.34$ \\
%  tuH   & $45.66 \pm 13.02$ & $105.38 \pm 27.65$ \\
  Diboson   & $8.40 \pm 1.59$ & $10.75 \pm 1.10$ \\
  Fake $\tau$ MC   & $277.11 \pm 87.45$ & $332.77 \pm 93.32$ \\
  $\bar{t}t$   & $225.85 \pm 26.18$ & $209.75 \pm 31.01$ \\
  $Z\rightarrow\tau\tau$   & $485.70 \pm 43.14$ & $406.02 \pm 51.63$ \\
  $\bar{t}tV$   & $0.76 \pm 0.43$ & $5.46 \pm 1.03$ \\
  Rare   & $17.84 \pm 2.76$ & $10.05 \pm 2.53$ \\
  SM Higgs   & $17.30 \pm 1.90$ & $25.88 \pm 2.05$ \\ \hline
  Total background  & $1097 \pm 38$ & $1085 \pm 45$ \\
\hline
\end{tabular}
%\begin{center}
%\begin{tabular}{l*{4}{c}}
%\hline\hline
% & $\lephad$, 3j & $\lephad$, $\geq$4j & $\hadhad$, 3j &  $\hadhad$, $\geq$4j \\
%\hline
%$\Hc$  &   $ -4.2 \pm 8.2 $ &   $ -11 \pm 21 $ &   $ -2.4 \pm 4.3 $ &   $ -10 \pm 11 $ \\
%\hline
%Fake $\had$  &   $ 2290 \pm 680 $ &   $ 2640 \pm 880 $ &   $ 640 \pm 110 $ &   $ 440 \pm 100 $ \\
%Top (real $\had$)  &   $ 4300 \pm 670 $ &   $ 3660 \pm 860 $ &   $ 147 \pm 84 $ &   $ 139 \pm 35 $ \\
%$Z \to \tau\tau$  &   $ 500 \pm 100 $ &   $ 359 \pm 90 $ &   $ 320 \pm 79 $ &   $ 306 \pm 76 $ \\
%Other  &   $ 178 \pm 45 $ &   $ 112 \pm 28 $ &   $ 9.6 \pm 2.6 $ &   $ 12.5 \pm 2.6 $ \\
%\hline
%Total  &   $ 7230 \pm 160 $ &   $ 6760 \pm 170 $ &   $ 1117 \pm 65 $ &   $ 893 \pm 45 $ \\
%\hline
%Data & 7259  & 6768  & 1119  & 894 \\
%\hline\hline
%\end{tabular}
%%\\
%\vspace{0.2cm}
%
%\end{center}
%\vspace{-0.5cm}
\label{tab:Htautau_Postfit_Yields_Unblind_Hc}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[htbp]
\caption{
Predicted and observed yields in each of the analysis regions considered.
The background prediction is shown after the fit to the asimov data under the signal-plus-background hypothesis
(assuming $\Hu$ as signal).
The contributions with real $\had$ candidates from $\ttbar$ and  $Z\to \ell^+\ell^-$ ($\ell = e, \mu$), diboson, $\ttbar V$, $\ttbar H$, single-top-quark, and other small backgrounds are combined into
a single background source referred to as ``Other MC'' in the leptonic channels , whereas single-top-quark and the small contributions are combined into ``Rare'' in the hadronic channels.
The quoted uncertainties are the sum in quadrature of statistical and systematic uncertainties of the yields,
computed taking into account correlations among nuisance parameters and among processes.
}
\small
\centering
\begin{tabular}{|c|c|c|c|c|c|}
  \hline
 & $t_{l}\tau_{had}-1j$ & $t_{l}\tau_{had}2j$ & $t_{h}\tau_{lep}\tau_{had}-3j$ & $t_{h}\tau_{lep}\tau_{had}-2j$ & $t_{l}\tau_{had}\tau_{had}$\\
\hline
  QCD Fake lep   & $916.84 \pm 213.23$ & $434.65 \pm 98.21$ & $233.82 \pm 77.52$ & $416.75 \pm 107.82$ & $0 \pm 0$ \\
  W-jet fake $\tau$  & $839.60 \pm 176.84$ & $963.47 \pm 211.11$ & $2934.6 \pm 602.46$ & $3434.22 \pm 820.85$ & $4.96 \pm 1.58$ \\
  Other Fake $\tau$  & $2918.71 \pm 217.11$ & $2625.87 \pm 161.15$ & $1767.93 \pm 455.10$ & $1635.44 \pm 784.74$ & $138.86 \pm 14.05$ \\
  b Fake $\tau$  & $811.72 \pm 109.86$ & $1015.84 \pm 158.82$ & $522.39 \pm 69.31$ & $573.09 \pm 75.11$ & $68.10 \pm 8.32$ \\
  tuH   & $71.08 \pm 14.95$ & $62.98 \pm 11.26$ & $123.52 \pm 20.39$ & $87.65 \pm 13.75$ & $93.07 \pm 14.64$ \\
  Lep fake $\tau$  & $221.68 \pm 29.45$ & $87.81 \pm 9.62$ & $307.45 \pm 33.81$ & $563.25 \pm 60.64$ & $0.88 \pm 0.34$ \\
  Double Fake $\tau$  & $0 \pm 0$ & $0 \pm 0$ & $0 \pm 0$ & $0 \pm 0$ & $89.74 \pm 23.31$ \\
  $\bar{t}t$   & $280.14 \pm 15.02$ & $178.8 \pm 26.84$ & $7081.53 \pm 363.91$ & $11610.1 \pm 475.80$ & $5.10 \pm 2.69$ \\
  Other MC   & $84.62 \pm 7.34$ & $83.30 \pm 3.10$ & $880.00 \pm 67.57$ & $1591.41 \pm 84.97$ & $40.79 \pm 1.75$ \\
\hline
  Total  & $6144 \pm 170$ & $5453 \pm 94$ & $13851 \pm 138$ & $19912 \pm 164$ & $441 \pm 29$ \\ \hline
\end{tabular}
\begin{tabular}{|c|c|c|}
\hline
 & $t_{h}\tau_{had}\tau_{had}-2j$ & $t_{h}\tau_{had}\tau_{had}-3j$\\
\hline
  only $\tau_{sub}$ real   & $64.23 \pm 49.64$ & $84.46 \pm 66.13$ \\
  %  tcH   & $31.48 \pm 9.43$ & $84.44 \pm 22.34$ \\
  tuH   & $45.66 \pm 13.02$ & $105.38 \pm 27.65$ \\
  Diboson   & $8.40 \pm 1.59$ & $10.75 \pm 1.10$ \\
  Fake $\tau$ MC   & $277.11 \pm 87.45$ & $332.77 \pm 93.32$ \\
  $\bar{t}t$   & $225.85 \pm 26.18$ & $209.75 \pm 31.01$ \\
  $Z\rightarrow\tau\tau$   & $485.70 \pm 43.14$ & $406.02 \pm 51.63$ \\
  $\bar{t}tV$   & $0.76 \pm 0.43$ & $5.46 \pm 1.03$ \\
  Rare   & $17.84 \pm 2.76$ & $10.05 \pm 2.53$ \\
  SM Higgs   & $17.30 \pm 1.90$ & $25.88 \pm 2.05$ \\ \hline
  Total background  & $1097 \pm 38$ & $1085 \pm 45$ \\
\hline
\end{tabular}
%\begin{center}
%\begin{tabular}{l*{4}{c}}
%\hline\hline
% & $\lephad$, 3j & $\lephad$, $\geq$4j & $\hadhad$, 3j &  $\hadhad$, $\geq$4j \\
%\hline
%$\Hu$  &   $ -5.7 \pm 8.6 $ &   $ -14 \pm 21 $ &   $ -2,0 \pm 2.8 $ &   $ -7.1 \pm 9.8 $ \\
%\hline
%Fake $\had$  &   $ 2270 \pm 680 $ &   $ 2620 \pm 880 $ &   $ 640 \pm 110 $ &   $ 440 \pm 100 $ \\
%Top (real $\had$)  &   $ 4320 \pm 660 $ &   $ 3680 \pm 860 $ &   $ 148 \pm 84 $ &   $ 140 \pm 35 $ \\
%$Z \to \tau\tau$  &   $ 470 \pm 100 $ &   $ 359 \pm 89 $ &   $ 321 \pm 79 $ &   $ 308 \pm 77 $ \\
%Other  &   $ 177 \pm 44 $ &   $ 111 \pm 27 $ &   $ 9.7 \pm 2.6 $ &   $ 12.5 \pm 2.6 $ \\
%\hline
%Total  &   $ 7230 \pm 160 $ &   $ 6760 \pm 160 $ &   $ 1118 \pm 66 $ &   $ 892 \pm 45 $ \\
%\hline
%Data  & 7259  & 6768  & 1119  & 894  \\
%\hline\hline
%\end{tabular}
%%\\
%\vspace{0.2cm}
%
%\end{center}
%\vspace{-0.5cm}
\label{tab:Htautau_Postfit_Yields_Unblind_Hu}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CS624: Analysis of Algorithms
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/beacon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Question 5}

Show how depth-first search works on the graph of Figure \ref{fig51}.
Assume that the \textbf{for} loop of lines 5-7 of the \textsc{DFS} procedure considers the vertices in alphabetical order, and assume that each adjacency list is ordered alphabetically.
Show the discovery and finishing times for each vertex, and show the classification of each edge.

\begin{figure}[H]\centering
\tikzstyle{every path}=[draw,->]
\tikzstyle{vertex}=[circle,draw,minimum size=0.7cm]
\tikzstyle{not visited}=[]
\tikzstyle{visited}=[fill=gray!50]
\tikzstyle{in queue}=[fill=gray!20]
\tikzstyle{label}=[]
\tikzstyle{ultra thick}=[line width=0.6mm]
  \begin{tikzpicture}
    \node[vertex] (1) {q};
    \node[vertex] (3) [left = 1cm of 1] {s};
    \node[vertex] (9) [right = 1cm of 1] {y};
    \node[vertex] (6) [left = 1cm of 3] {v};
    \node[vertex] (7) [below = 1cm of 6] {w};
    \node[vertex] (4) [below = 1cm of 9] {t};
    \node[vertex] (2) [right = 1cm of 9] {r};
    \node[vertex] (5) [below = 1cm of 2] {u};
    \node[vertex] (8) [below = 1cm of 1] {x};
    \node[vertex] (10)[left = 1cm of 8] {z};
%    \node[label]  (9) [above = 0.1cm of 1] {r};
%    \node[label]  (10) [above = 0.1cm of 2] {s};
%    \node[label]  (11) [above = 0.1cm of 3] {t};
%    \node[label]  (12) [above = 0.1cm of 4] {u};
%    \node[label]  (13) [below = 0.1cm of 5] {v};
%    \node[label]  (14) [below = 0.1cm of 6] {w};
%    \node[label]  (15) [below = 0.1cm of 7] {x};
%    \node[label]  (16) [below = 0.1cm of 8] {y};

    \path[thick]
      (1) edge (4)
      (1) edge (3)
      (1) edge (7)
      (3) edge (6)
      (6) edge (7)
      (7) edge (3)
      (4) edge (8)
      (8) edge (10)
      (10) edge [bend left = 30] (8)
      (4) edge (9)
      (9) edge (1)
      (2) edge (9)
      (5) edge (9)
      (2) edge (5)
      ;
    \path[ultra thick]
      ;
  \end{tikzpicture}
\caption{Directed graph $G$}\label{fig51}
\end{figure}

\subsection*{Solution}

Final tree constructed by applying the depth-first search algorithm to graph $G$ starting from source vertex $q$ and continuing alphabetically, is shown in Figure \ref{fig52}.
As can be seen, starting and finishing time of each node is written next to it.

\begin{figure}[H]\centering
\tikzstyle{every path}=[draw,->]
\tikzstyle{vertex}=[circle,draw,minimum size=0.7cm]
\tikzstyle{not visited}=[]
\tikzstyle{visited}=[fill=gray!50]
\tikzstyle{in queue}=[fill=gray!20]
\tikzstyle{label}=[]
\tikzstyle{ultra thick}=[line width=0.6mm]
  \begin{tikzpicture}
    \node[vertex,visited] (1) {q};
    \node[vertex,visited] (3) [left = 1cm of 1] {s};
    \node[vertex,visited] (9) [right = 1cm of 1] {y};
    \node[vertex,visited] (6) [left = 1cm of 3] {v};
    \node[vertex,visited] (7) [below = 1cm of 6] {w};
    \node[vertex,visited] (4) [below = 1cm of 9] {t};
    \node[vertex,visited] (2) [right = 1cm of 9] {r};
    \node[vertex,visited] (5) [below = 1cm of 2] {u};
    \node[vertex,visited] (8) [below = 1cm of 1] {x};
    \node[vertex,visited] (10)[left = 1cm of 8] {z};
    \node[label]  (11) [above = 0.1cm of 6] {3/6};
    \node[label]  (12) [above = 0.1cm of 3] {2/7};
    \node[label]  (13) [above = 0.1cm of 1] {1/16};
    \node[label]  (14) [above = 0.1cm of 9] {13/14};
    \node[label]  (15) [above = 0.1cm of 2] {17/20};
    \node[label]  (16) [below = 0.1cm of 7] {4/5};
    \node[label]  (17) [below = 0.1cm of 10]{10/11};
    \node[label]  (18) [below = 0.1cm of 8] {9/12};
    \node[label]  (19) [below = 0.1cm of 4] {8/15};
    \node[label]  (20) [below = 0.1cm of 5] {18/19};

    \path[thick]
      (1) edge (7)
      (7) edge (3)
      (10) edge [bend left = 30] (8)
      (4) edge (9)
      (9) edge (1)
      (2) edge (9)
      (5) edge (9)
      ;
    \path[ultra thick]
      (1) edge (3)
      (3) edge (6)
      (6) edge (7)
      (1) edge (4)
      (4) edge (8)
      (8) edge (10)
      (2) edge (5)
      ;
  \end{tikzpicture}
\caption{Graph $G$ after implementation of DFS algorithm starting from node $q$}\label{fig52}
\end{figure}

A brief explanation of how the algorithm works is as follows.
First, node $q$ is visited.
Then, due to the alphabetical order, node $s$ will be discovered and visited as the child of $q$.
Since node $s$ is connected to $v$, the algorithm continues by visiting $v$ and $w$.
Once $w$ is visited, since nodes connected to $w$ are already visited, the algorithm will continue with the second child of $q$.
$t$ itself will be discovered and visited.
Since $x$ alphabetically proceeds $y$, the algorithm continues with discovering the subtree $t \rightarrow x \rightarrow z$.
After this step, as second child of $t$ will be visited.
Since $y$ is not connected to any unvisited node, the algorithm will mark it as visited and continues with discovering a new node $r$ and eventually visiting the last node $u$.

Using the DFS algorithm on graph $G$ will lead to a set of tree edges that is as follows.
$E = \{(q,s), (s,v), (v,w), (q,t), (t,x), (x,z), (r,u)\}$.
At the same time, set of forward edges will have only one element $(q,w)$ and set of back edges will include $\{(w,x), (z,x), (y,q)\}$.
Noteworthy that $(r,y)$ and $(u,y)$ are neither in set of forward nor back edges.


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Homework\ \#2}
\newcommand{\hmwkDueDate}{January 24th, 2017}
\newcommand{\hmwkClass}{Elements of Algebra I}
\newcommand{\hmwkClassTime}{Section 161}
\newcommand{\hmwkClassInstructor}{Professor Deepam Patel}
\newcommand{\hmwkAuthorName}{Yao Xiao}

%
% Title Page
%

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{Due\ on\ \hmwkDueDate\  }\\
    \vspace{0.1in}\large{\textit{\hmwkClassInstructor\ \hmwkClassTime}}
    \vspace{3in}
}

\author{\textbf{\hmwkAuthorName}}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\pagebreak

\begin{homeworkProblem}
Proof by induction \\
When n=1,
\[
\begin{split}
1=\frac{n(n+1)(2n+1)}{6}=\frac{1*2*3}{6}
\end{split}
\]
Suppose n=k
\[
\begin{split}
1+2^2+3^2+...+k^2=\frac{k(k+1)(2k+1)}{6}\\
1+2^2+3^2+...+k^2+(k+1)^2&=\frac{k(k+1)(2k+1)}{6}+(k+1)^2\\
&=\frac{6(k+1)^2+k(k+1)(2k+1)}{6}\\
&=\frac{(k+1)(6(k+1)+(2k+1)k)}{6}\\
&=\frac{(k+1)(6k+6+2k^2+k)}{6}\\
&=\frac{(k+1)(2k^2+7k+6)}{6}\\
&=\frac{(k+1)(2k+3)(k+2)}{6}\\
&=\frac{(k+1)(2(k+1)+1)((k+1)+1)}{6}\\
\end{split}
\]
So the equation holds for n=k+1. Therefore, the inequalities hold for all positive integers n > 1 by induction

\end{homeworkProblem}

\begin{homeworkProblem}
Proof by induction \\
When n=2 \\
We have \(1<8/3<5\), so the inequalities hold when n=2

When n is greater than 2, \[
\begin{split}
1+2^2+3^2+...+(n-1)^2+n^2&<\frac{n^3}{3}+n^2\\
&=\frac{n^3+3n^2}{3}\\
&<\frac{n^3+3n^2+3n+1}{3}\\
&=\frac{(n+1)^3}{3}
\end{split}
\]
So the left inequality holds
\[
\begin{split}
1+2^2+3^2+...n^2+(n+1)^2&>\frac{n^3}{3}+(n+1)^2\\
&=\frac{n^3+3(n+1)^2}{3}\\
&=\frac{n^3+3n^2+6n+3}{3}\\
&>\frac{n^3+3n^2+3n+1}{3}\\
&=\frac{(n+1)^3}{3}
\end{split}
\]
So the right inequality holds as well
\end{homeworkProblem}
\begin{homeworkProblem}
\begin{enumerate}
\item Let a be the integer, (a-a)=0. 0 mod anything is 0. So it holds
\item Let a and b be integers. Suppose that a $\equiv$ b (mod n), aka a-b = kn. b-a=-(a-b)=(-k)n. So it holds
\item Let a,b,c be integers. a-b=nk, b-c=nj, let the first one plus the second one a-b+b-c=nk+nj, a-c=n(k+j) so a-c=nk' as well
\end{enumerate}
\end{homeworkProblem}
\begin{homeworkProblem}
\( a \rightarrow b \) is true iff \( \neg b \rightarrow \neg a \) is true.
So we assume a is even, and the product of the two even number is \(2k*2k=2(2k)\) and it's even too.
\end{homeworkProblem}
\begin{homeworkProblem}
Let rotate be function R, so that \[R(1)=2\ R(2)=3\ R(3)=4\ R(4)=1 \]
Let flip be function F, so that \[F(1)=2\ F(2)=1\ F(3)=4\ F(4)=3 \]
When you rotate the square once, twice and three times. It will become (2,3,4,1),(3,4,1,2),(4,1,2,3), respectively. So when you do \(R^3*R\). it will become (1,2,3,4) which is I. So any rotation could be one of the I,\(R,R^2,R^3\)
\end{homeworkProblem}
\begin{homeworkProblem}
Assume we are starting from (1,2,3,4)
\[
\begin{split}
F=(2,1,4,3)\\
FR=R(2,1,4,3)=(3,2,1,4)\\
FR^2=R^2(2,1,4,3)=(4,3,2,1)\\
FR^3=R^3(2,1,4,3)=(1,4,3,2)
\end{split}
\]
\end{homeworkProblem}
\begin{homeworkProblem}
Since \(F^2=I\) and \(R^4=I\), there will be all the symmetric flips. Also it's obvious that you rotate first and flip later
\[RF=F(2,3,4,1)=(3,2,1,4)=FR\]
\end{homeworkProblem}
\begin{homeworkProblem}
The inverse of R is \(R^3\)\\
The inverse of \(R^2\) is \(R^2\)\\
The inverse of \(R^3\) is \(R\)
\end{homeworkProblem}

\end{document}