\def\err{{\mathop{\overline{\mathsf{err}}}}}

\section{AdaBoost}

%\subsection{Boosting}

\begin{frame}
  \frametitle{Boosting Methods}

  \begin{itemize}
    \item Boosting is one of the most powerful learning techniques introduced in the last twenty years.
    \item Combines output of many \structure{\textit{weak} classifiers} to produce a powerful committee.
    \item The most popular boosting algorithm is called \structure{\textit{AdaBoost}} \\
      (Freund and Schapire, 1997).
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Boosting Methods \cont}

  \begin{citeblock}{Definition}

    A \structure{weak classifier} is one whose error rate is only slightly better than random guessing.
  \end{citeblock}
  \pspread

  \structure{Idea of boosting:}

  \begin{itemize}
    \item Sequentially apply the \emph{weak} classifier to repeatedly modified versions of the data.
    \item This produces a sequence of classifiers.
    \item Weighted majority vote yields the final prediction.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Boosting Methods \cont}

  \begin{itemize}
    \item Consider a two-class problem with $y \in \{ -1, +1\}$. \\[.25cm] %\pause
    \item Given a set of observations $\mathcal{D} = \{(\vec{x}_i, y_i); \quad i=1,\ldots,N\}$ and a classifier $G(\vec x)$, the \structure{error rate} on the training sample is:
      \begin{displaymath}
        \err = \frac{1}{N} \sum_{i=1}^N I(y_i \neq G(\vec{x}_i))
      \end{displaymath}
      where $I$ is the \structure{indicator function}.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Boosting Methods \cont}

  \begin{itemize}
    \item Sequentially applied weak classifiers produce a sequence $G_m(\vec x)$ with $m=1,2,\ldots,M$ %\pause
    \item The \structure{combined prediction} is then:
      \begin{displaymath}
        G(\vec x) = \sign \left( \sum_{m=1}^M \alpha_m G_m(\vec x) \right)
      \end{displaymath}
      %\pause
    \item The weighting factors $\alpha_1, \ldots, \alpha_M$ are computed by the boosting algorithm. %\pause
    \item Each $\alpha_m$ weights the output of the corresponding classifier $G_m(\vec x)$.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Boosting Methods}

  \structure{Schematic of boosting procedure:}

  \begin{center}
    \resizebox{.35\linewidth}{!}{
      \input{\texfigdir/boosting_schematic.pstex_t}
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Boosting Methods \cont}

  \structure{Modifications on the data:}

  \begin{itemize}
    \item Each boosting step consists of applying weights $w_1, w_2, \ldots, w_N$ to the training samples. %\pause
    \item Initially, the weights are set to $w_i = 1/N$. %\pause
    \item Thus the first classifier in the sequence is trained the usual way. %\pause
    \item For $m \geq 2$ the weights are individually modified. %\pause
    \item The classifiers $G_m$, with $m \geq 2$ are trained on differently-weighted samples.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Boosting Methods}

  \structure{Weighting scheme:}

  \begin{itemize}
    \item At step $m$ the misclassified observations from $G_{m-1}$ have increased weights.
    \item The weights for correctly classified samples from $G_{m-1}$ have decreased weights.
  \end{itemize}
  \pspread

  \structure{Effects of the weighting scheme:}

  \begin{itemize}
    \item Observations that are difficult to classify correctly get ever-increasing influence.
    \item Each successive classifier is forced to concentrate more on those observations that were misclassified by the previous one.
  \end{itemize}
\end{frame}

\subsection{AdaBoost}

\begin{frame}
  \frametitle{AdaBoost}

  \structure{AdaBoost algorithm:}
%
  \begin{centernss}
    \small
    \resizebox{.85\linewidth}{!}{
      \begin{struktogramm}(100,50)
        \assign{Initialize weights: $w_i =\gets 1/N ~,~i=1, \ldots, N$}
        \assign{$m \gets 1$}
        \until{$ m = M$}
          \assign{\structure{Fit classifier $G_m(\vec x)$ to training data using $\vec w$}}
          \assign{\structure{Compute classification error:}\\
            $ \mathsf{err}_m = \frac{\sum_{i=1}^N w_i I(y_i \neq G_m(x_i))}{\sum_{i=1}^N w_i}$
          }
          \assign{\structure{Compute classifier weights:}\\
            $ \alpha_m = \log \left( \frac{1- \mathsf{err}_m}{\mathsf{err}_m} \right) $
          }
          \assign{\structure{Compute new sample weights:}\\
            $ w_i \leftarrow w_i \exp \left[ \alpha_m I(y_i \neq G_m(x_i)) \right] ~,~ i = 1, \ldots, N $
          }
          \assign{$m \gets m + 1$}
        \untilend
        \assign{\structure{Output:} $G(\vec x) = \sign \left( \sum_{m=1}^M \alpha_m G_m(\vec x) \right) $}
      \end{struktogramm}
    }
  \end{centernss}

%   \begin{center}
%     \small
%     \begin{struktogramm}{10cm}{0.7cm}
%       \BLOCK {Initialize weights: $w_i = 1/N ~,~i=1, \ldots, N$}
%       \BLOCK {Set $m:=1$}
%       \REPEAT {
%         \BLOCK {\structure{Fit classifier $G_m(\vec x)$ to training data using $\vec w$}}
%         \BLOCK {\structure{Compute classification error:}\\
%           $ \mathsf{err}_m = \frac{\sum_{i=1}^N w_i I(y_i \neq G_m(x_i))}{\sum_{i=1}^N w_i}$
%         }
%         \BLOCK {\structure{Compute classifier weights:}\\
%           $ \alpha_m = \log \left( \frac{1- \mathsf{err}_m}{\mathsf{err}_m} \right) $
%         }
%         \BLOCK {\structure{Compute new sample weights:}\\
%           $ w_i \leftarrow w_i \exp \left[ \alpha_m I(y_i \neq G_m(x_i)) \right] ~,~ i = 1, \ldots, N $
%         }
%         \BLOCK {Set $m:= m + 1$}
%       }
%       UNTIL {$ m = M$}
%       \BLOCK {\structure{Output:} $G(\vec x) = \sign \left( \sum_{m=1}^M \alpha_m G_m(\vec x) \right) $}
%     \end{struktogramm}
%   \end{center}
\end{frame}

\begin{frame}
  \frametitle{AdaBoost \cont}

  \structure{Notes:}

  \begin{itemize}
    \item This version of AdaBoost is called \structure{discrete}, because each $G_m(\vec x)$ returns a discrete class label. %\pause
    \item AdaBoost can be modified to return also a real-valued prediction in the interval $[-1,+1]$.  %\pause
    \item Instead of taking just any classifier for $G_m(\vec x)$, that classifier may be used that results in the smallest error at step $m$.
  \end{itemize}
  \pspread

  AdaBoost dramatically increases the performance of even a very weak classifier.
\end{frame}

\begin{frame}
  \frametitle{AdaBoost \cont}

  \structure{Example from J.\ Matas and J.\ \v{S}ochman \\(Centre for Machine Perception, Technical University, Prague):}
%
  \begin{center}
    \resizebox{!}{6.5cm}{
      \input{\texfigdir/adaboost1.pstex_t}
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{AdaBoost \cont}

  \structure{Example from J.\ Matas and J.\ \v{S}ochman \\(Centre for Machine Perception, Technical University, Prague):}

  \begin{center}
    \resizebox{!}{6.5cm}{
      \alt<2->{
        \input{\texfigdir/adaboost3.pstex_t}
      }{
        \input{\texfigdir/adaboost2.pstex_t}
      }
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{AdaBoost \cont}

  \structure{Example from J.\ Matas and J.\ \v{S}ochman \\(Centre for Machine Perception, Technical University, Prague):}
%
  \begin{center}
    \resizebox{!}{6.5cm}{
      \input{\texfigdir/adaboost4.pstex_t}
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{AdaBoost \cont}

  \structure{Example from J.\ Matas and J.\ \v{S}ochman \\(Centre for Machine Perception, Technical University, Prague):}

  \begin{columns}[c, onlytextwidth]
    \begin{column}{0.5\textwidth}
      \begin{figure}
        \centering
        \resizebox{.7\linewidth}{!}{
          \alt<8->{
            \input{\texfigdir/adaboost-classifier.pstex_t}
          }{\alt<7>{
            \input{\texfigdir/adaboost-classifier7.pstex_t}
          }{\alt<6>{
            \input{\texfigdir/adaboost-classifier6.pstex_t}
          }{\alt<5>{
            \input{\texfigdir/adaboost-classifier5.pstex_t}
          }{\alt<4>{
            \input{\texfigdir/adaboost-classifier4.pstex_t}
          }{\alt<3>{
            \input{\texfigdir/adaboost-classifier3.pstex_t}
          }{\alt<2>{
            \input{\texfigdir/adaboost-classifier2.pstex_t}
          }{
            \input{\texfigdir/adaboost-classifier1.pstex_t}
          }}}}}}}
        }
        \caption{\footnotesize Final classifier (based on a perceptron).}
      \end{figure}
    \end{column}\begin{column}{0.5\textwidth}
      \begin{figure}
        \centering
        \resizebox{\linewidth}{!}{
          \alt<8->{
            \input{\texfigdir/adaboost-error.pstex_t}
          }{\alt<7>{
            \input{\texfigdir/adaboost-error7.pstex_t}
          }{\alt<6>{
            \input{\texfigdir/adaboost-error6.pstex_t}
          }{\alt<5>{
            \input{\texfigdir/adaboost-error5.pstex_t}
          }{\alt<4>{
            \input{\texfigdir/adaboost-error4.pstex_t}
          }{\alt<3>{
            \input{\texfigdir/adaboost-error3.pstex_t}
          }{\alt<2>{
            \input{\texfigdir/adaboost-error2.pstex_t}
          }{
            \input{\texfigdir/adaboost-error1.pstex_t}
          }}}}}}}
        }
        \caption{\footnotesize Reduction of the classification error w.\,r.\,t.\ the sequence length.}
      \end{figure}
  \end{column}
  \end{columns}
\end{frame}

\input{nextTime.tex}

\subsection{Exponential Loss}

\begin{frame}
  \frametitle{Exponential Loss}

  \begin{itemize}
    \item Boosting fits an \structure{additive model} in a \structure{set of elementary basis functions}: \\[.1cm]
      \begin{center}
        \tikz[baseline]{
          \node[fill=bl1!100, anchor=base, rounded corners=3pt, inner sep=1mm] (d1) {
            \color{bl3}
            $
              \displaystyle
              f_M(\vec x) =
              \sum_{m=1}^M \beta_m \, b(\vec x ; \vec \gamma_m)
            $
          };
        }
      \end{center}
      \vspace{.1cm}
      where $\beta_m$ are expansion coefficients and $b(\vec x ; \vec \gamma_m)$ is a basis function given a set of parameters $\vec \gamma_m$. \\[.3cm] \pause
    \item Additive expansions are very popular in learning techniques:
      \begin{itemize}
        \item single-hidden-layer neural networks (perceptron)
        \item wavelets
        \item classification trees
        \item etc.
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \begin{itemize}
    \item Expansion models are typically fit by \structure{minimizing a loss function $L$} averaged over the training data:
      \begin{equation}
        \label{eq:loss}
        \min_{\{ \beta_m, \vec \gamma_m \}_1^M } ~
        \left\{
          \sum_{i=1}^N L \big( y_i, f_M(\vec{x}_i) \big) =
          \sum_{i=1}^N L \left( y_i, \sum_{m=1}^M \beta_m \, b(\vec{x}_i ; \vec \gamma_m) \right)
        \right\}
      \end{equation}
      \\[.3cm] \pause
    \item \structure{Forward stagewise modeling} approximates the solution to \eqref{eq:loss}: \\[.1cm]
      \begin{itemize}
        \item New basis functions are sequentially added. \\[.1cm] %\pause
        \item Parameters and coefficients of already added functions are not changed. \\[.1cm] %\pause
        \item At each iteration, the subproblem of fitting just a single basis function is solved.
      \end{itemize}
%       \begin{displaymath}
%         \min_{\beta, \vec \gamma} ~\sum_{i=1}^N L(y_i, \beta b(\vec{x}_i ; \vec{\gamma}))
%        \end{displaymath}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \begin{itemize}
    \item The \structure{$m$-th subproblem} may be rewritten as: \\[.3cm]
      \begin{center}
        \tikz[baseline]{
          \node[fill=bl1!100, anchor=base, rounded corners=3pt, inner sep=1mm] (d1) {
            \color{bl3}
            $
              \displaystyle
              (\beta_m, \vec \gamma_m) = \argmin_{\beta, \vec \gamma} ~\sum_{i=1}^N L\big(y_i, f_{m-1}(\vec{x}_i) + \beta \, b(\vec{x}_i ; \vec{\gamma})\big)
            $
          };
        }
      \end{center}
      \vspace{.3cm} \pause
    \item AdaBoost is equivalent to a forward stagewise additive modeling using an \structure{exponential loss function}:
      \begin{displaymath}
        L(y, f(\vec x)) = \exp (-y \, f(\vec x))
      \end{displaymath}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \structure{Proof:}

  \begin{itemize}
    \item For AdaBoost, the basis functions are the classifiers $G_m(\vec x) \in \{-1,+1\}$. %\pause
    \item Using the \structure{exponential loss function}, one must solve at each step:
      \begin{eqnarray*}
        (\beta_m, G_m) = \argmin_{\beta, G} ~\sum_{i=1}^N \exp \left[ -y_i \big(f_{m-1}(\vec{x}_i) + \beta G(\vec{x}_i)\big) \right]
      \end{eqnarray*}
      %\pause
    \item Using the weight $w_i^{(m)} = \exp(-y_i \, f_{m-1}(\vec{x}_i))$ this can be rewritten as:
      \begin{eqnarray*}
        (\beta_m, G_m) = \argmin_{\beta, G} ~\sum_{i=1}^N w_i^{(m)} \exp (-\beta y_i G(\vec{x}_i))
      \end{eqnarray*}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \structure{Observations:}

  \begin{itemize}
    \item Since $w_i^{(m)}$ is independent of $\beta$ and $G(\vec x)$, it can be seen as a weight applied to each observation. %\pause
    \item However, this weight depends on $f_{m-1}$, so the weights change with \\
      each iteration $m$.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \vspace{-.5cm}
  \begin{eqnarray*}
    (\beta_m, G_m)
      &=& \argmin_{\beta, G} ~\sum_{i=1}^N w_i^{(m)} \exp (-\beta y_i G(\vec{x}_i)) \\ %\pause
      &=& \argmin_{\beta, G} ~ e^{-\beta} \sum_{y_i = G(\vec{x}_i)} w_i^{(m)} + e^{\beta} \sum_{y_i \neq G(\vec{x}_i)} w_i^{(m)} \\ %\pause
      &=& \argmin_{\beta, G} ~ \left( e^{\beta} - e^{-\beta} \right) \sum_{i=1}^N w_i^{(m)} I(y_i \neq G(\vec{x}_i)) + e^{-\beta} \sum_{i=1}^N w_i^{(m)}
  \end{eqnarray*}
  \pause

  \begin{itemize}
    \item Thus, for any value $\beta > 0$ the solution for $G_m(\vec x)$ is: \\[.25cm]
      \begin{center}
        \tikz[baseline]{
          \node[fill=bl1!100, anchor=base, rounded corners=3pt, inner sep=1mm] (d1) {
            \color{bl3}
            $
              \displaystyle
              G_m = \argmin_G \sum_{i=1}^N w_i^{(m)} \, I(y_i \neq G(\vec{x}_i))
            $
          };
        }
      \end{center}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \begin{itemize}
    \item Plugging the reformulated $G_m(\vec x)$ into the objective function and solving for $\beta_m$ yields: \\[.15cm]
      \begin{center}
        \tikz[baseline]{
          \node[fill=bl1!100, anchor=base, rounded corners=3pt, inner sep=1mm] (d1) {
            \color{bl3}
            $
              \displaystyle
              \beta_m = \frac{1}{2} \log \frac{1 - \mathsf{err}_m}{\mathsf{err}_m}
            $
          };
        }
      \end{center}
      \vspace{.25cm}

      with $\mathsf{err}_m$ being the \structure{minimized weighted error rate}: \\[.15cm]

      \begin{displaymath}
        \mathsf{err}_m = \frac{\sum_{i=1}^N w_i^{(m)} I(y_i \neq G_m(\vec{x}_i))}{\sum_{i=1}^N w_i^{(m)}}
      \end{displaymath}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \begin{itemize}
    \item From the update formula of the approximation:
      \begin{eqnarray*}
        f_m(\vec x) = f_{m-1}(\vec x) + \beta_m \, G_m(\vec x)
      \end{eqnarray*}
      we can calculate the \structure{weights for the next iteration}:
      \begin{eqnarray*}
        w_i^{(m+1)}
          &=& w_i^{(m)} ~ e^{-\beta_m y_i G_m(\vec{x}_i)} \\ \vspace{1cm} %\pause
          & & \mbox{\small(using: $-y_i G_m(\vec{x}_i) = 2 I (y_i \neq G_m(\vec{x}_i)) - 1$)} \\[.5cm] %\pause
          &=& w_i^{(m)} e^{\alpha_m I(y_i \neq G_m(\vec{x}_i))} e^{-\beta_m}
      \end{eqnarray*}
      with $\alpha_m = 2 \beta_m$.
  \end{itemize}

  \hfill \qed
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \structure{Compare result to initial AdaBoost algorithm:}

  \begin{itemize}
    \item \structure{Exponential loss:}
      \begin{eqnarray*}
        \beta_m     &=& \frac{1}{2} \log \frac{1 - \mathsf{err}_m}{\mathsf{err}_m} \\
        \alpha_m    &=& 2 \beta_m \\
        w_i^{(m+1)} &=& w_i^{(m)} ~ e^{\alpha_m I(y_i \neq G_m(\vec{x}_i))} ~ e^{-\beta_m}
      \end{eqnarray*}
      \pspread
    \item \structure{AdaBoost:}
      \begin{eqnarray*}
        \alpha_m &=&          \log \frac{1- \mathsf{err}_m}{\mathsf{err}_m} \\
        w_i      &\leftarrow& w_i \, e^{\alpha_m I(y_i \neq G_m(\vec{x}_i))}
      \end{eqnarray*}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \begin{center}
    \resizebox{.85\linewidth}{!}{
      \alt<4->{
        \input{\texfigdir/exploss4.pstex_t}
      }{\alt<3>{
        \input{\texfigdir/exploss3.pstex_t}
      }{\alt<2>{
        \input{\texfigdir/exploss2.pstex_t}
      }{
        \input{\texfigdir/exploss1.pstex_t}
      }}}
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \structure{Discussion:}

  \begin{itemize}
    \item The equivalence of AdaBoost to forward stagewise additive modeling was discovered five years after its invention. %\pause
    \item The AdaBoost criterion yields a monotone decreasing function of the \structure{margin}: $y\,f(\vec x)$. \\[.5cm] %\pause
    \item In $\{-1, 1\}$ classification, the margin plays a role similar to the \\
      residuals $y - f(\vec x)$ in regression:
      \begin{itemize}
        \item Observations with $y_i \, f(\vec{x}_i) > 0$ are classified correctly
        \item Observations with $y_i \, f(\vec{x}_i) < 0$ are misclassified
        \item The decision boundary is at $f(\vec x) = 0$
     \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Exponential Loss \cont}

  \structure{Discussion (cont.):}

  \begin{itemize}
    \item The goal of the classification algorithm is to produce positive margins as frequently as possible. %\pause
    \item Thus, any loss criterion should penalize negative margins more heavily than positive ones! %\pause
    \item The exponential criterion concentrates much more influence on observations with large negative margins.
  \end{itemize}
  \pspread

  Due to the exponential loss, AdaBoost performance is known to degrade rapidly:
  \begin{itemize}
    \item in situations of noisy data
    \item when there are wrong class labels in the training data
  \end{itemize}
\end{frame}

\input{nextTime.tex}

%\subsection{Face Detection}

\begin{frame}
  \frametitle{Face Detection}

  Famous algorithm developed by \structure{Viola and Jones} in 2001.
  \spread

  \structure{Contributions:}

  \begin{itemize}
    \item Integral images for feature computation.
    \item Usage of AdaBoost for boosting.
    \item Classifier cascade for fast rejection of non-face regions.
  \end{itemize}
  \spread

  Various implementations available: for example look into \textit{OpenCV FaceDetector} sample code.
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Features:}

  \begin{itemize}
    \item Features are adapted from Haar basis functions. %\pause
    \item They are calculated by subtracting the sum of the pixels in the white from the sum of the pixels in the gray rectangles: \\[.3cm] %\pause
  \end{itemize}

  \structure{4 types of features used:}

  \begin{center}
    \resizebox{.4\linewidth}{!}{
      \input{\texfigdir/haar_features.pstex_t}
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \begin{itemize}
    \item The exhaustive set of features is very large: $> 45\,000$ for a 380x280 image. %\pause
    \item Rectangle features can be efficiently computed using an \\
     \structure{Integral Image $II$}:
      \begin{displaymath}
        II(x,y) = \sum_{x' \leq x, y' \leq y} I(x', y')
      \end{displaymath}
  \end{itemize}
  \spread

  \begin{center}
    \resizebox{.4\linewidth}{!}{
      \input{\texfigdir/integral_image.pstex_t}
    }
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Computation of the sum of intensities for any rectangle D  with just \\ 3 basis operations based on the integral image:} \\[.5cm]

  \begin{center}
    \resizebox{.4\linewidth}{!}{
      \input{\texfigdir/integral_image2.pstex_t}
    }
  \end{center}

  \begin{itemize}
    \item Value at 1: A %\pause
    \item Value at 2: A + B %\pause
    \item Value at 3: A + C %\pause
    \item Value at 4: A + B + C + D %\pause
    \item Sum within D: $4 + 1 - (2 + 3)$
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Boosting:}

  \begin{itemize}
    \item The classification functions are restricted to each depend on a single feature only. %\pause
    \item This way, AdaBoost can be interpreted as an effective feature selecting algorithm:
      \begin{itemize}
        \item The single rectangle feature is selected which best separates the observations. %\pause
        \item For each feature, the weak learner determines the optimal threshold classification function.
      \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \begin{itemize}
    \item A weak classifier $G_j(\vec x)$ consists of a \structure{feature $x_j$}, an \structure{optimal threshold $\theta_j$}, and a \structure{parity $s_j$} to indicate the direction of the inequality:
      \begin{displaymath}
        G_j(\vec x) = \begin{cases}
                        1 \quad \mbox{if} ~s_j f_j(\vec x) < s_j \theta_j \\
                        0 \quad \mbox{otherwise}
                      \end{cases}
      \end{displaymath}
      with $\vec x$ being a sub-window of an image.
      \pspread
    \item Very aggressive process to discard the vast majority of features.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \begin{itemize}
    \item Best feature selected by AdaBoost:
  \end{itemize}

  \begin{center}
    \begin{figure}
            \copyrightbox[b]{
      \makebox[.6\linewidth]{
          \includegraphics[width=0.4\linewidth]{\pngdir/bestfeature.\png}
      }
    }{Christian Hacker, Anton Batliner, and Elmar Noeth. \href{https://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2006/Hacker06-AYL.pdf}{Are You Looking at Me, Are You Talking with Me: Multimodal Classification of the Focus of Attention.}}
  \end{figure}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Classifier Cascade:}

  \begin{itemize}
    \item Despite the efficiency of the feature computation, the complexity of the problem is still huge. %\pause
    \item Evaluating the full AdaBoost sequence on all sub-windows of the image takes too much time.
    \pspread
    \item Idea of cascaded classifiers:
    \begin{itemize}
      \item Simpler classifiers used to reject the majority of sub-windows. %\pause
      \item Each stage is again created by AdaBoost. %\pause
      \item Stage 1 uses the two features shown before; detects 100\,\% faces with \\ false positive rate (FPR) of around 40\,\%.
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \begin{itemize}
    \item The cascade has the overall shape of a degenerated decision tree: \\[.5cm]
      \begin{center}
        \resizebox{.7\linewidth}{!}{
          \input{\texfigdir/cascade.pstex_t}
        }
      \end{center}
      \pspread
    \item A negative classification at any stage yields an immediate rejection of the sub-window.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \begin{itemize}
    \item Structure of cascade reflects the (usually) overwhelming majority of negative sub-windows in an image. %\pause
    \item Goal is to reject as many negatives as possible at the earliest stage of the processing.
  \end{itemize}
  \spread

  \structure{Training of the cascade:}

  \begin{itemize}
    \item Subsequent classifiers are trained using only those examples which pass through all the previous stages. %\pause
    \item The next classifier faces a more difficult task than the previous one. %\pause
    \item Trade-off between more features achieving higher detection rates and lower false positive rates while requiring more computation time.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Final classifier:}

  \begin{itemize}
    \setlength\itemsep{0.5cm}
    \item 32 layer cascade of increasingly strong boosted classifiers

    \begin{center}
      \begin{tabular}{r@{}l r c c}
        \multicolumn{2}{c}{\structure{Layer}} &
        \structure{\# Features} &
        \structure{TPR} &
        \structure{FPR}\\
        \hline
           &1  &   2~~~~~ & 100\,\% & 40\,\% \\
           &2  &   5~~~~~ & 100\,\% & 20\,\% \\
         3-&5  &  20~~~~~ & \\
         6-&7  &  50~~~~~ & \\
         8-&12 & 100~~~~~ & \\
        13-&32 & 200~~~~~ & \\ %\pause
      \end{tabular}
    \end{center}

    \item Number of stages and features adapted until false positive rate on validation was nearly zero while maintaining high correct rate.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Example images from the training set:}

  \begin{center}
  \begin{figure}
            \copyrightbox[b]{
      \makebox[.6\linewidth]{
          \includegraphics[width=0.45\linewidth]{\pngdir/FaceTraining.\png}
      }
    }{Paul Viola and Michael Jones. \href{https://www.researchgate.net/publication/3940582_Rapid_Object_Detection_using_a_Boosted_Cascade_of_Simple_Features}{Rapid Object Detection using a Boosted Cascade of Simple Features. IEEE Conf Comput Vis Pattern Recognit.}}
  \end{figure}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Face Detection \cont}

  \structure{Results on test set:}
  \begin{center}
  \begin{figure}
            \copyrightbox[b]{
      \makebox[.6\linewidth]{
          \includegraphics[width=0.5\linewidth]{\pngdir/facedetection.\png}
      }
    }{Christian Hacker, Anton Batliner, and Elmar Noeth. \href{https://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2006/Hacker06-AYL.pdf}{Are You Looking at Me, Are You Talking with Me: Multimodal Classification of the Focus of Attention.}}
  \end{figure}
  \end{center}
\end{frame}

%\subsection{Lessons Learned}

\begin{frame}
  \frametitle{Lessons Learned}

  \begin{itemize}
    \item Boosting of weak classifiers can yield a powerful combined classifier \\[.3cm]
    \item AdaBoost algorithm \\[.3cm]
    \item Weights of the classifiers and on the data are adjusted \\[.3cm]
    \item AdaBoost minimizes an exponential loss function \\[.3cm]
    \item Viola \& Jones face detection algorithm
  \end{itemize}
\end{frame}

\subsection{Further Reading}

\begin{frame}
  \frametitle{Further Reading}

  Most of the content of this lecture has been taken from: \\[.25cm]

  \small
  \begin{itemize}
    \item T.\ Hastie, R.\ Tibshirani, J.\ Friedman: \\
      \structure{The Elements of Statistical Learning}, \\
      2nd Edition, Springer, 2009.\\%[.15cm]
    \item Y.\ Freund, R.\,E.\ Schapire: \\
      \structure{A decision-theoretic generalization of on-line learning and \\
	    an application to boosting},\\
      Journal of Computer and System Sciences, 55(1):119-139, 1997.\\%[.15cm]
    \item P.\,A.\ Viola, M.\,J.\ Jones:
      \structure{Robust Real-Time Face Detection}, \\
      International Journal of Computer Vision 57(2): 137-154, 2004.\\%[.15cm]
    \item J.\ Matas and J.\ \v{S}ochman:
      \structure{AdaBoost}, \\
      Centre for Machine Perception, Technical University, Prague. \\%[.15cm]
      \structure{\point\url{http://cmp.felk.cvut.cz/~sochmj1/adaboost_talk.pdf}}
  \end{itemize}
\end{frame}


% Document Head
\documentclass[11pt, oneside]{book}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage[parfill]{parskip}
\usepackage{graphicx}

% Essential Packages
\usepackage{ragged2e}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[hyperref]{ntheorem}

% Theorem Style Customization
\setlength\theorempreskipamount{2ex}
\setlength\theorempostskipamount{3ex}

% hyperref Package Settings
\usepackage{hyperref}
\hypersetup{
	colorlinks = true,
	linkcolor = magenta
}

% ntheorem Declarations
\theoremstyle{break}
\newtheorem{thm}{Theorem}[section]
\newtheorem*{proof}{Proof}
\newtheorem{crly}{Corollary}[thm]
\newtheorem{lemma}[thm]{Lemma}
\newtheorem{propo}{Proposition}[section]
\newtheorem*{remark}{Remark}
\newtheorem*{note}{Note}
\newtheorem{defn}{Definition}[section]
\newtheorem{eg}{Example}[section]
\newtheorem{axiom}{Axiom}[chapter]
\newtheorem{principle}{Principle}[chapter]

% ntheorem listtheorem style
\makeatletter
\def\thm@@thmline@name#1#2#3#4{%
        \@dottedtocline{-2}{0em}{2.3em}%
                   {\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
                   {#4}}
\@ifpackageloaded{hyperref}{
\def\thm@@thmline@name#1#2#3#4#5{%
    \ifx\#5\%
        \@dottedtocline{-2}{0em}{2.3em}%
            {\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
            {#4}
    \else
        \ifHy@linktocpage\relax\relax
            \@dottedtocline{-2}{0em}{2.3em}%
                {\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
                {\hyper@linkstart{link}{#5}{#4}\hyper@linkend}%
        \else
            \@dottedtocline{-2}{0em}{2.3em}%
                {\hyper@linkstart{link}{#5}%
                  {\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}\hyper@linkend}%
                    {#4}%
        \fi
    \fi}
}
\makeatother
\newlength\widesttheorem
\AtBeginDocument{
  \settowidth{\widesttheorem}{Proposition A.1.1.1\quad}
}

\theoremlisttype{allname}

% Shortcuts
\newcommand{\bb}[1]{\mathbb{#1}}			% using bb instead of mathbb
\newcommand{\floor}[1]{\lfloor #1 \rfloor}	% simplifying the writing of a floor function
\newcommand{\ceiling}[1]{\lceil #1 \rceil}	% simplifying the writing of a ceiling function
\newcommand{\dotp}{\, \cdotp}				% dot product to distinguish from \cdot

% Main Body
\title{MATH145 Readings}
\author{Johnson Ng}

\begin{document}
\maketitle

\chapter*{Introduction}
\textit{Below is an introduction written by the author of the referred notes, Kenneth R. Davidson.}

As a student entering university to study mathematics, you probably have encountered prime bumbers. Chances are great that you believe that every integer factors uniquely into a product of primes but have not seen a proof. This important fact, known as the Fundamental Theorem of Algebra, is of crucial importance in the theory of numbers. It is not easy to prove. More importantly, it is not \textit{intuitively obvious}. Indeed, its significance is only realized with very large numbers beyond our real experience. The crucial fact that enables us to prove this with relative ease is the Euclidean Algorithm for finding greatest common divisors. The first two chapters deal with these basic properties of the integers and modular arithmetic.

It is worth noting that there are number systems not very much different from the intergers in which this unique factorization into primes fails. Far from being a disaster, this is an opportunity to investigate why this phenomena occurs. It shows us which properties of the integers themsevles are crucial to make the theory work. That is why we make a foray into quadratic number domains in chapter 3. Naturally, we merely touch the surface here as this theory lies in a rather deep connection between algebra and number theory.

A nice application of modular arithmetic is the Rivest-Shamir-Adelman (RSA) public key cryptography scheme. This code allows the author to publish the method of \textit{encoding} a message in a public place, while keeping the method of \textit{decoding} the message secret. This is a rather different idea of coding, as for all previously known codes, the method of decoding merely reversed the endoing method. The secret here is that it is very easy (with a computer) to find large primes (say 100-200 digits) but very difficult to factor the product of two large primes. If you believe that checking whether a number is prime involes trial division by all numbers up to the square root, it might be hard to imagine why determining if a number if prime should be any easier than finding factors. So we delve more deeply into methods used to determine whether a number is prime or composite. It quickly becomes clear that simple tests can determine beyond any doubt that a number is composite without giving any information at all about the factors.

In chapter 5, we introduce the complex numbers. There is a tacit assumption that the student is already reasionably familiar with the real numbers from studying calculus. However, a section is devoted to a brief discussion of how the real numbers are developed. No attempt is made to separate algebra from analysis. Indeed, all of mathematics is integrated and it is foolish to pretend that there are natural walls. In particular, we prove the Fundamental Theorem of Algebra that every complex polynomial factors into a product of linear terms. In spite of its name, this is a theorem of analysis because it relies on the (topological) completeness of the complex numbers. The proof we give is one of the simplest, and relies on the Extreme Value Theorem. We also develop the complex exponential function. This again is really a theorem of analysis. But it is included because it plays such an important role in other applications of the compelx numbers.

In chapter 6, we show that the same theory applies to the algebra of polynomials. In particular, there is a Euclidean Algorithm and unique factorization into irreducible polynomials. We exanime various tests for irreducibility, and study connections with irrationality of the roots. Then we do a few special topics about real and complex polynomials such as Sturm's Theorem for counting real roots, and the formula for solving cubics. Then in chapter 7, we study finite fields in some detail. This is just doing modular arithmetic modulo an irreducible polynomial instead of modulo a prime integer. Many of the results for $\bb{Z}_p$ carry over to finite fields with the same ideas. A rather beautiful application of these ideas is an algorithm for factoring polynomials over the rationals. This algorithm is based on a method for factoring polynomial of degree \textit{d} mod \textit{p} is much easeier than factoring a \textit{d} digit base \textit{p} number.

\tableofcontents

\chapter*{List of Definitions}
\theoremlisttype{all}
\listtheorems{defn}

\chapter*{List of Theorems}
\theoremlisttype{all}
\listtheorems{lemma,thm,crly,propo}

\chapter*{Axioms and Principles}
\listtheorems{axiom,principle}

% =================================
% 		The Integers
% =================================
\chapter{The Integers}

\section{Basic Properties}

The following list of properties is what a student taught in the `modern' style would come up with when talking about properties of integers. We give the name Commutative Rings for sets of numbers that satisfy these properties.

\begin{defn}[Commutative Rings]\label{defn-commutative-rings}
	A commutative ring is a set of numbers that satisfy these properties.
	\begin{enumerate}
		\item The \textbf{integers} consist of a set $\bb{Z}$ together with two binary operations \textbf{addition} (+) and \textbf{multiplication} ($\cdot$)
		\item (\textbf{commutativity of addition}) $\forall a, b \in \bb{Z} \quad a + b = b + a$
		\item (\textbf{associativity of addition}) $\forall a, b, c \in \bb{Z} \quad (a + b) + c = a + (b + c)$
		\item (\textbf{additive identity}) $\exists 0 \in \bb{Z} \enspace \forall a \in \bb{Z} \quad a + 0 = a = 0 + a$
		\item (\textbf{additive inverse}) $\forall a \in \bb{Z} \enspace \exists (-a) \in \bb{Z} \quad a + (-a) = 0$
		\item (\textbf{commutativity of multiplication}) $\forall a, b \in \bb{Z} \quad a \cdot b = b \cdot a$
		\item (\textbf{associativity of multiplication}) $\forall a, b, c \in \bb{Z} \quad (a \cdot b) \cdot c = a \cdot (b \cdot c)$
		\item (\textbf{multiplicative identity}) $\exists 1 \in \bb{Z} \enspace \forall a \in \bb{Z} \quad a \cdot 1 = a = 1 \cdot a$
		\item (\textbf{distributive law}) $\forall a, b, c \in \bb{Z} \enspace (a + b) \cdot c = a \cdot c + b \cdot c$
	\end{enumerate}
\end{defn}

But this does not fully distinguish integers from many other sets, for example:
\begin{enumerate}
	\item The real numbers $\bb{R}$.
	\item The set $\bb{Z}[\sqrt{3}] = \{a + b\sqrt{3} \; | \; a, b \in \bb{Z}\}$ \\
		See Exercise 1.1 for proof.
	\item The set $\bb{Z} \oplus \bb{Z} := \{(a, b) \, | \, a, b \in \bb{Z}\}$ with coordinate-wise addition and multiplication.
\end{enumerate}

\begin{defn}[Ring]
	A ring is a set of numbers that satisfy all properies of a commutative ring except for property 6, \textbf{commutativity of multiplication}, and added with an additional distributive law
	\begin{equation*}
		\forall a, b, c \in \bb{Z} \quad a \cdot (b + c) = a \cdot b + a \cdot c
	\end{equation*}
\end{defn}

\begin{eg}
	An example of a non-commutative ring is the set of $2 \times 2$ matrices with integer entries. While addition is coordinate-wise, multiplication is defined by the rule: $\forall a, b, c, d, w, x, y, z \in \bb{Z}$
	\begin{equation*}
		\begin{bmatrix}
			a & b \\
			c & d
		\end{bmatrix}
		\begin{bmatrix}
			w & x \\
			y & z
		\end{bmatrix}
		=
		\begin{bmatrix}
			aw + by & ax + bz \\
			cw + dy & cx + dz
		\end{bmatrix}
	\end{equation*}
	which is clearly non-commutative since
	\begin{equation*}
		\begin{bmatrix}
			w & x \\
			y & z
		\end{bmatrix}
		\begin{bmatrix}
			a & b \\
			c & d
		\end{bmatrix}
		=
		\begin{bmatrix}
			aw + cx & bw + dx \\
			ay + cz & by + dz
		\end{bmatrix}
	\end{equation*}
\end{eg}

\begin{eg}
	Another important example is the set of integers \textbf{modulo} n. Consider the ring $\bb{Z}_2$ consisting of two elements $\{0, 1\}$ with operations given by the tables: \\
	\begin{center}
		\begin{tabular}{c|c c}
			$+$	&	0	&	1 \\
			\hline
			0	&	0	&	1 \\
			1	&	1	&	0
		\end{tabular}
		$\quad$
		\begin{tabular}{c|c c}
			$\times$	&	0	&	1 \\
			\hline
			0			&	0	&	0 \\
			1			&	0	&	1
		\end{tabular}
	\end{center}
\end{eg}

The above example gives us a clue about how to add further properties to our list in Definition \ref{defn-commutative-rings} to ensure that the integers become our only example.

For instance, we declare the following property so as to distinguish many other commutative rings from the integers.

\begin{enumerate}
	\setcounter{enumi}{9}
	\item $\bb{Z}$ is generated by $\{0, 1\}$
\end{enumerate}

With this, we have laid the foundations of starting our set starting with 0 and 1, then form the rest of the elements of $\bb{Z}$ so as to provide the \textit{minimal} collection satisfying all our properties. In particular, since a ring is \textit{closed} under addition and multiplication, we need all the numbers of the form $1, 1 + 1, 1 + 1 + 1, 1 + 1 + 1 + 1, ...$.

Note that such a construction ensures that the set is indeed closed under addition and multiplication. The set is closed under addition since
\begin{gather*}
	\forall a, b \in \bb{Z} \\
	a + b = \underbrace{\underbrace{1 + 1 + \hdots + 1}_\text{a many 1's} + \underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}}_\text{(a + b) many 1's}
\end{gather*}
which thus implies that $a + b \in \bb{Z}$ since a ring is closed under addition. The set is closed under multiplication since
\begin{align*}
	a \cdot b &= (\underbrace{1 + 1 + \hdots + 1}_\text{a many 1's}) \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}) \\
			  &= \underbrace{1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}) + 1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}) + \hdots + 1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's})}_\text{a times}
\end{align*}
by the distributive law, and since each $1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}) \in \bb{Z}$, we have, once again, that
\begin{equation*}
	a \cdot b = \underbrace{1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}) + 1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's}) + \hdots + 1 \cdot (\underbrace{1 + 1 + \hdots + 1}_\text{b many 1's})}_\text{a times} \quad \in \bb{Z}
\end{equation*}
and thus our construction is closed under multiplication.

Next, in order to satisfy the \textbf{additive inverse property}, we \textit{may} have to add in $-1, -(1 + 1), -(1 + 1 + 1), ...$ The proof that such a collection is enough to satisfy all the properties of a commutative ring is similar to our exercise above.

Our legwork is not done yet, since we still have, for example, $\bb{Z}_2$ also being generated by its 0 and 1. We can, fortunately, eliminate this group of sets by stating that $1, 1 + 1, 1 + 1 + 1, ...$ are all unique. If such a property holds in any ring, then the collection $S = \{1, 1 + 1, 1 + 1 + 1, ...\}$ will be indistinguishable from the \textbf{natural numbers $\bb{N}$} (without the 0) by any mathematical property. In fact, to ensure that all the elements are distinct, it is important that none of them are 0, since for example:
\begin{equation*}
	0 = 1 + 1 + 1 + 1 \implies (1 + 1 + 1 + 1) + 1 = 1 \; \text{but} \; (1 + 1) + (1 + 1 + 1) = 5
\end{equation*}
by the distributive law.

With that said, then $-S \cap S = \emptyset$, and thus $R = S \cup \{0\} \cup -S$ is a ring that has indistinguishable properties from $\bb{Z}$. To clarify the explanation above, we state the following as a property:

\begin{enumerate}
	\setcounter{enumi}{10}
	\item No nontrivial sum of 1's is equal to 0.
\end{enumerate}

Some questions come into attention here (and will be hinted in Exercise 1.4 below):
\begin{enumerate}
	\item What does it mean to say that two mathematical objects are the same?
	\item What does it mean to say that two mathematical objects have the same properties?
\end{enumerate}

\begin{defn}[Order]
	We define order as follows:
	\begin{gather*}
		a < b \qquad \text{if} \qquad b - a \in \bb{N} \\
		a = b \qquad \text{if} \qquad b - a = 0 \\
		a > b \qquad \text{if} \qquad b - a \in \bb{N}
	\end{gather*}
	This order satisfies some simple properties:
	\begin{enumerate}
		\item[O1] $\forall a, b, c \in \bb{Z} \land a < b, \; a + c < b + c$
		\item[O2] $\forall a, b, c \in \bb{Z} \land a < b \land c > 0, \; ac < bc$
	\end{enumerate}
\end{defn}

\textbf{Exercises}
\begin{enumerate}
	\item[1.1] Show that $\bb{Z}[\sqrt{3}]$ is a commutative ring.
	\item[1.2] Describe explicitly the ring $\bb{Z}[\sqrt[3]{5}]$.
	\item[1.3] What are the additive and multiplicative identities for $\bb{Z} \oplus \bb{Z}$? Show that there are non-zero elements which multiply to 0.
	\item[1.4] Consider the ring $R = \{2^n \; | \; n \in \bb{Z}\}$ with addition $\oplus$ given by $2^n \oplus 2^m = 2^{n + m}$, and multiplication $\odot$ given by $2^n \odot 2^m = 2^{nm}$. Show that this is a ring. Then show that the map taking $2^n$ to its logarithm base 2 (namely n) maps R one-to-one and onto $\bb{Z}$ and preverse addition and multiplication. We say that R is isomorphic to $\bb{Z}$.
	\item[1.5] What other properties of the integers can you think of? Can these properties be deduced from the ones given above?
	\item[1.6] Can an order be put on $\bb{Z}_2$ satisfying O1?
\end{enumerate}

\section{Well Ordering Principle}

\begin{principle}[Well Ordering Principle]
	Every non-empty subset of $\bb{N}$ has a least element.
\end{principle}

\begin{thm}[Generalized Principle of Induction]
	For all integers n, let P(n) be the statement about n propositions. Suppose that proposition P(1) is true. Furthermore, suppose that if P(k) is true for $1 \leq k < n$, then P(n) is true. Then P(n) is true for all $n \geq 1$.
\end{thm}

\begin{proof}
	Let S be the set of all n such that P(n) is false. If S is empty, then we have our desired conclusion, i.e. P(n) is true for all $n \geq 1$. Otherwise, S is non-empty. Then by the Principle of Induction, there exists an n in S such that n is the least element in S. By the hypothesis, $n \neq 1$. Since n is the smallest integer in S, we know that P(k) is true for all $1 \leq k < n$ (otherwise if there is an $1 \leq l < n$ such that P(l) is false, then $l \in S \land l < n$ will contradict the fact that n is the least element). But by the induction hypothesis, P(n) must be true. This contradicts that P(n) is false. Thus our assumption that S is non-empty is false. Therefore, S must be empty, and therefore P(n) is true for all $n \geq 1$.
\end{proof}

\begin{eg}[False Proof of Induction]
	Let P(n) be the statement that every set of n people have all the same hair colour. This is evident for n = 1. Now look at larger n. Suppose that P(n - 1) is true. Given a group of n people, apply the induction hypothesis to all but the last person in the group. This group will have all the same hair colour. Now repeat this argument with all but the first person. We find that all the people have the same hair colour by combining these two facts. By induction, all people have the same hair colour.
\end{eg}

\textbf{Exercises}
\begin{enumerate}
	\item[2.1] Find the error in the False Proof of Induction example above.
\end{enumerate}

I believe the problem lies in the execution of ``Now repeat this argument with all but the first person''. The problem is that if the last person has a different hair colour, then the base case would have been false from the beginning, thus rendering the entire induction to be false.

\begin{enumerate}
	\item[2.2] Prove by induction that
	\begin{equation*}
		\sum_{i=1}^{n} i^3 = \left(\sum_{i=1}^{n} i\right)^2.
	\end{equation*}
\end{enumerate}

The base case is true and easily verifiable, since $1^3 = (1)^2 = 1$. Now suppose that for all k where $1 \leq k < n$ such that
\begin{equation*}
	\sum_{i=1}^{k} i^3 = \left(\sum_{i=1}^{k} i \right)^2
\end{equation*}
is true. Now consider the case n = k + 1. Then
\begin{align*}
	\sum_{i = 1}^{k + 1} i^3
		&= \sum_{i=1}^{k} i^3 + (k + 1)^3 \\
		&= \left( \sum_{i=1}^{k} i \right)^2 + (k + 1)^3 \\
		&= \left( \sum_{i=1}^{k} i \right)^2 + k^3 + 3k^2 + 3k + 1
\end{align*}

\begin{align*}
	\left( \sum_{i=1}^{k + 1} i \right)^2
		&= \left( \sum_{i = 1}^{k} i + k + 1 \right)^2 \\
		&= \left( \sum_{i = 1}^{k} i \right)^2 + 2(k+1)\left( \sum_{i = 1}^{k} i \right) + (k + 1)^2 \\
		&= \sum_{i=1}^{k} i^3 + (k+1)\left(\sum_{i=1}^{k} 2i + k + 1 \right)
\end{align*}
So
\begin{align*}
	\sum_{i = 1}^{k + 1} i^3 - \left( \sum_{i=1}^{k + 1} i \right)^2
		&= (k + 1)^3 - 2(k+1)\left( \sum_{i = 1}^{k} i \right) - (k + 1)^2 \\
		&= (k + 1)\Bigg( k^2 + 2k + 1 - \sum_{i=1}^{k} 2i - k - 1 \Bigg)
\end{align*}

\begin{enumerate}
	\item[2.3] Consider the Fibonnaci sequence, given by F(0) = F(1) = 1, and for $n \geq 0$, F(n + 2) = F(n) + F(n + 1). Let $r = (\sqrt{5} + 1)/2$. Prove by induction that
	\begin{equation*}
		F(n) = \frac{r^{n + 1} - (\frac{-1}{r})^{n + 1}}{\sqrt{5}}.
	\end{equation*}
	\item[2.4] Define a sequence of real numbers by the rules
	\begin{equation*}
		s_0 = 0 \quad \text{and} \quad s_{n + 1} = \sqrt{3 + s_n} \enspace \text{for } n \geq 0
	\end{equation*}
	\begin{enumerate}
		\item Show by induction that $s_n < s_{n + 1} < 3$ for all $n \geq 0$.
		\item The least upper bound principle (chapter 5) shows that the sequence has a limit. Show that the limit should be $\sigma = \frac{1 + \sqrt{13}}{2}.$
		\item Obtain a formula for $\sigma - s_{n + 1}$ in terms of $\sigma - s_n$. Hence prove by induction that $0 < \sigma - s_n < \frac{3}{4^n}$ for all $n \geq 0$.
	\end{enumerate}
\end{enumerate}

\end{document}
% Document End


\documentclass{beamer}
\usetheme{Madrid}

\def\Re#1{\operatorname{Re}\left(#1\right)}

\title[No Largest Prime]{There Is No Largest Prime Number}
\subtitle{With an introduction to a new proof technique}

\author[Euclid, DDU]{
    Euclid of Alexandria\inst{1}
    \and
    DDU\inst{2}
}
\institute[Alexandria, ST]{
    \inst{1}
    \texttt{euclid@alexandria.edu}\\
    Department of Mathematics\\
    University of Alexandria
    \and
    \inst{2}
    \texttt{ddu6@protonmail.com}\\
    Simple Text Orgnazition
}
\date[ISPN '80]{27th International Symposium of Prime Numbers, --280}

\begin{document}

\frame{\titlepage}

\begin{frame}
    \frametitle{Outline}
    \tableofcontents[pausesections]
\end{frame}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Outline}
    \tableofcontents[currentsection]
  \end{frame}
}

\section{Motivation}

\subsection{What Are Prime Numbers?}

\begin{frame}
    \frametitle{What Are Prime Numbers?}

    \begin{definition}
        A \alert{prime number} is a number that has exactly two divisors.
    \end{definition}

    \begin{example}
        \begin{itemize}
            \item 2 is prime (two divisors: 1 and 2).
            \pause
            \item 3 is prime (two divisors: 1 and 3).
            \pause
            \item 4 is not prime (\alert{three} divisors: 1, 2, and 4).
        \end{itemize}
    \end{example}
\end{frame}

\section{Results}

\subsection{Proof of the Main Theorem}

\begin{frame}
    \frametitle{Proof of the Main Theorem}
    \framesubtitle{The proof uses \textit{reductio ad absurdum}}

    \begin{theorem}
        There is no largest prime number.
    \end{theorem}

    \begin{proof}
        \begin{enumerate}
            \item<1-| alert@1> Suppose $p$ were the largest prime number.
            \item<2-> Let $q$ be the product of the first $p$ numbers.
            \item<3-> Then $q + 1$ is not divisible by any of them.
            \item<1-> But $q + 1$ is \only<4->{greater than $1$, thus }divisible by some prime number not in the first $p$ numbers.\qedhere
        \end{enumerate}
    \end{proof}

    \uncover<5->{The proof used \textit{reductio ad absurdum}.}
\end{frame}

\section{What's More}

\subsection{An Open Question}

\begin{frame}
    \frametitle{An Open Question}

    \begin{columns}
        \column{.45\textwidth}
        \begin{block}{Answered Questions}
            How many primes are there?
        \end{block}

        \column{.45\textwidth}
        \begin{block}{Open Questions}
            Is every even number the sum of two primes?
            \cite{Goldbach1742}
        \end{block}
    \end{columns}

    \begin{thebibliography}{10}
        \bibitem{Goldbach1742}[Goldbach, 1742]
        Christian Goldbach.
        \newblock A problem we should try to solve before the ISPN '43 deadline,
        \newblock \emph{Letter to Leonhard Euler}, 1742.
    \end{thebibliography}
\end{frame}

\subsection{Another Open Question}

\begin{frame}
    \frametitle{Another Open Question}

    In complex plane, define $\zeta(s)=\sum\limits_{n=1}^\infty\frac1{n^s}$. Then, are all zeros of $\zeta$ in the strip $0\leq\Re{s}\leq1$ lie on the line $\Re{s}=\frac12$?
    \pause

    \begin{block}{Some Observation}
        If $\Re{s}>1$\pause, then
        \begin{align*}
            \zeta(s)&=\sum_{n=1}^\infty\frac1{n^s}\\
            &=\prod_p\frac1{1-p^{-s}}.
        \end{align*}
        \pause
       Thus $\zeta$ does not vanish when $\Re{s}>1$.
    \end{block}
\end{frame}

\subsection{An Algorithm For Finding Primes Numbers}

\begin{frame}[fragile]
    \frametitle{An Algorithm For Finding Primes Numbers}

    \begin{semiverbatim}
        \uncover<1->{\alert<0>{int main (void)}}
        \uncover<1->{\alert<0>{\{}}
        \uncover<1->{\alert<1>{ \alert<4>{std::}vector<bool> is_prime (100, true);}}
        \uncover<1->{\alert<1>{ for (int i = 2; i < 100; i++)}}
        \uncover<2->{\alert<2>{ if (is_prime[i])}}
        \uncover<2->{\alert<0>{ \{}}
        \uncover<3->{\alert<3>{ \alert<4>{std::}cout << i << " ";}}
        \uncover<3->{\alert<3>{ for (int j = i; j < 100;}}
        \uncover<3->{\alert<3>{ is_prime [j] = false, j+=i);}}
        \uncover<2->{\alert<0>{ \}}}
        \uncover<1->{\alert<0>{ return 0;}}
        \uncover<1->{\alert<0>{\}}}
    \end{semiverbatim}

    \visible<4->{Note the use of \alert{\texttt{std::}}.}
\end{frame}

\end{document}


\documentclass[hidelinks]{article}
\usepackage{tikz}
\usepackage{physics}
\usepackage{bbm}
\usepackage{pstricks}
\usepackage{bm}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{hyperref}
\usepackage{bbm}
\usepackage{seqsplit}

%opening
\title{Frog on a Garden Path}
% See https://arxiv.org/pdf/1108.0337.pdf
\author{Harry Mallinson}

\begin{document}

\maketitle

\begin{abstract}
I used this problem in one of an ongoing series of  data science internal training sessions, summer 2021. It highlights nicely how large performance benefits can come from simply rolling up one's mathematical sleeves a little.
\end{abstract}

\section{Problem Statement}
\subsection{Frog 1}

\textbf{Difficulty:} 2/5 \\

A frog sits at the start of a garden path of length 10m.  Each hop it can jump either 1, 2 or 3 metres exactly.  How many different ways can it reach the end of the garden path without overshooting?
\\

\textit{Note}: The frog must end exactly at the end of the path. For example, a hop sequence of 3,3,3,3 is  invalid, as the frog ends up hopping 12m, not 10m.

\textit{Note}: Hopping e.g. 3, 3, 3, 1 is counted as different to hopping 3, 3, 1, 3 and so on.

\textit{Note}: The frog starts at the 0m mark.

\subsection{Frog 2}

\textbf{Difficulty:} 3/5\\

Solve the general case of \textbf{Frog 1}, where the length of the garden path is $N$, and the frog can jump $1, 2, 3, \dots, k$ metres per jump (i.e. the frog can jump any integer distance between 1 and $k$ metres).

If you have coded your solution, check its efficiency by making sure it can calculate $N=100, k=25$ in under a second. The correct result is 633824582314588604117041545216. \\

Push the boat out: see if you can calculate $N=900, k=300$ in under a second. The correct result is: \\

\seqsplit{4226356249085321970818718279332132852150778608288972177023685672213391220453798875795337423636543278788203143456775509834095840855975089871860087480189730594682178682543044117377244106228260440730347272120364229185899239035975403380259737710579931032227208688810246275072}.

\newpage

\section{Solution}

I'll present three ways you might approach this.

First note that the question is equivalent to asking you to enumerate the possible \textbf{compositions} of integer $N$ with largest part of size $k$ - in the non-general case above we have $N=10$ and $k=3$.  To understand compositions we must first understand \textbf{partitions}.

A \textbf{partition} of an integer is a way of writing that integer as a sum of positive integers. Two partitions of an integer are considered identical if they differ only in the order of their parts (their summands). For example, one partition of 6 could be $3+2+1$ which is identical to the partition $2+3+1$.

A \textbf{composition} of an integer is simply an ordered partition of that integer - that is, a composition is identical to a partition except that the order of the parts matters. For example, $3+2+1$ and $2+3+1$ are distinct compositions of 6.

\textbf{Frog 1} is equivalent to asking for the total possible compositions of 10 with no part greater than 3, and \textbf{Frog 2} is equivalent to asking for the total possible compositions of any integer $N$ with no part greater than integer $k$.

\subsection{Fibonacci}

We wish to find the number of compositions of some integer $N$ with possible parts $\{1,\dots,k\}$. Write this as $C_N^k$.

If $k=1$ the only possible composition of N is $1+1+\dots+1$, which is just the composition of $C_{N-1}^1$ (so $N-1$ $1$s) with a $1$ appended.  If $k=2$ we can do similarly: we can append a 1 to the compositions of $C_{N-1}^2$ and a 2 to the compositions of $C_{N-2}^2$. From this observation we have our solution.  Consider the compositions of increasing $N$ for $k=2$, where for ease I've written some general composition $a+b+c+d$ as $(a,b,c,d)$:

\begin{center}
	\begin{tabular}{| r | l |}
		\hline
		Element & Compositions \\ [0.5ex]
		\hline
		$C_0^2$ & ()\\
		$C_1^2$ & (1) \\
		$C_2^2$ & (1,1), (2)\\
		$C_3^2$ & (1,1,1), (2,1), (1,2) \\
		$C_4^2$ & (1,1,1,1), (2,1,1), (1,2,1), (1,1,2), (2,2) \\
		\hline
	\end{tabular}
\end{center}

Notice that the compositions of $C_1^2$ are just all the compositions of $C_0^2$ with a $1$ appended. Notice then that the compositions of $C_2^2$ are just all the compositions of $C_1^2$ with a $1$ appended, and then all the compositions of $C_0^2$ with a $2$ appended.  Finally, the compositions of $C_3^2$ are just all the compositions of $C_2^2$ with a $1$ appended, and all those of $C_1^2$ with a $2$ appended. We can't go back and append a $3$ to the compositions of $C_0^2$ as the max part size is in the above table is $k=2$.

For general $C_N^k$ we can then just append 1s to the $C_{N-1}^k$ compositions, 2s to the $C_{N-2}^k$ compositions and so on to appending $k$s to the $C_{N-k}^k$ compositions.  As appending does not change the total number of compositions for each $C_{N-i}^k$, we can just write $C_N^k$ (the number of compositions of $N$ with max part size $k$) as

\begin{equation}
C_N^k = C_{N-1}^k + C_{N-2}^k + \dots + C_{N-k}^k
\end{equation}
and as we know the boundary condition $C^k_0=1$  (there is only one composition of 0, the empty sequence) and $C^k_{N<0}=0$ (there are no compositions of the negatives) this just defines a (certain generalisation of) the Fibonacci sequence.

We have then that the number of compositions of integer $N$ of max part size $k$ is given by the general Fibonacci number
\begin{equation}
F_n^k =
\begin{cases}
0 & \text{if }n<0; \\
1 & \text{if }n=0; \\
\sum_{i=1}^kF^k_{n-i} & \text{if }n>0.
\end{cases}
\end{equation}

This suffices to solve \textbf{Frog 2}. To solve \textbf{Frog 1} we just want $F_{10}^3=274$.

Continuing along this path you can get all sorts of interesting results - the number of times some part of size $j$ appears, or the total number of parts present in the set of compositions, or (relatedly) the average number of parts per composition.

~\\[8pt]
\subsection{Adjacency Matrices}

We can represent the frog scenario as an ordered graph, with node 0 (the starting point) connected to nodes 1, 2 and 3 representing the possible jumps of 1, 2 and 3 metres (up to $k$ metres in the generalised question).  Node 1 connects to nodes 2, 3 and 4 and so on up to $k$.

We can represent connected graphs in matrix form.  Consider the directed graph $G_1$ in \ref{G_1}.

\begin{figure}[h]
	\centering
	\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=3cm,main node/.style={circle,draw}]

	\node[main node] (A) {A};
	\node[main node] (B) [above right of=A] {B};
	\node[main node] (C) [below right of=B] {C};
	\node[main node] (D) [above right of=C] {D};

	\path[every node/.style={font=\sffamily\small}]
	(A) edge node [left] {} (B)

	(C) edge node [right] {} (D)
	edge [bend right] node[right] {} (B)
	(B) edge [bend right] node [left] {} (C)
	;
	\end{tikzpicture}
	\caption{\textit{Directed Graph $G_1$}} \label{G_1}
\end{figure}
We can represent this as an \textbf{adjacency matrix }
\begin{equation}
\textbf{M} =
\begin{pmatrix}
0  & 1 & 0 & 0 \\
0  & 0 & 1 & 0 \\
0  & 1 & 0 & 1 \\
0  & 0 & 0 & 0
\end{pmatrix}
\end{equation}
where $\textbf{M}_{ij}$ represents the number of connections from $i$ to $j$, for $A=0, B=1, \dots$.  If one starts at $A$ and stores one's position in a $1\cross4$ vector $\textbf{P}$, and takes all available paths at any time, then $\textbf{P}$ acting on $\textbf{M}$ $n$ times will determine your (possibly multiple) potential position(s) after $l$ moves.  For example
\begin{equation}
\begin{split}
\begin{pmatrix}
1 & 0 & 0 & 0
\end{pmatrix}
\textbf{M} & = \textbf{PM} \\
& =
\begin{pmatrix}
0 & 1 & 0 & 0
\end{pmatrix}
\end{split}
\end{equation}
which just codifies your position(s) after 1 move from $A$ (so here just ending up at $B$), and
\begin{equation}
(\textbf{PM})\textbf{M}=\textbf{PM}^2=
\begin{pmatrix}
0 & 0 & 1 & 0
\end{pmatrix}
\end{equation}
which just codifies your position(s) after 2 moves from $A$ (so here just ending up at $C$), and
\begin{equation}
\textbf{P}\textbf{M}^3=
\begin{pmatrix}
0 & 1 & 0 & 1
\end{pmatrix}
\end{equation}
which just codifies your position(s) after 3 move from $A$ (so here ending up at both $C$ and $D$).

Continuing this reasoning, we can see that $(\textbf{PM}^n)_i$ tells you the number of possible paths that end up at node $i$ after $n$ moves from node $A$ (as we started at node $A$).  Then we see that we can do away with $P$ altogether, as $(\textbf{M}^n)_{ij}$ represents the number of possible paths of length $n$ from node $i$ to node $j$.\footnote{For any starting position $M_{ij}$ - which, referring back to \textbf{P}, just has non-0 $j$ telling us the starting node - when multiplying its row $i$ by $M$, you can see that $M_{ij}$ will be ``caught''  by exactly those elements of $M$ in row $j$ that represent the connections from node $j$ onwards to some other (or same) node $l$.}  If you don't see this just play around with $\textbf{P}$ and $\textbf{M}$, referring back to the graph.

So, we have that an adjacency matrix \textbf{M} is a way of representing a graph $G$, with $M_{ij}$ telling you the number of direct connections from node $i$ to node $j$ of $G$, and that $(M^n)_{ij}$ gives the number of $n$-step connection from node $i$ to node $j$.

In order to ``catch'' the frogs once they reach the final step of node 10 we connect node 10 to itself (otherwise every time a frog arrives at node 10 it would disappear on the next step, in our notation).  The adjacency matrix is then an $11\cross11$ matrix

\begin{equation}
\text{\textbf{M}} =
\begin{pmatrix}
0 & 1 & 1 & 1 & 0 & 0 & \dots &\\
0 & 0 & 1 & 1 & 1 & 0 & \dots &\\
0 & 0 & 0 & 1 & 1 & 1 & \dots &\\
&  &  &  & \ddots & \ddots & \ddots & \\
&   &   &   & \dots  & 0  & 0  &  1
\end{pmatrix}.
\end{equation}

$(M^{10})_{1,10}=274$ then gives us our answer as the total number of possible paths from node 0 to node 10. This suffices to solve \textbf{Frog 1}. Generalising this to finding the number of compositions of some integer $N$ with largest size $k$ is straightforward - we simply want $(M^N)_{1,N}$ for an appropriately constructed $\textbf{M}$.\footnote{Instead of each row containing a max of 3 $1$s, the rows will have a max of $k$ 1s.} This suffices to solve \textbf{Frog 2}.

\subsection{Generating functions}
For our purposes, it suffices to note that if we use the following ``generating'' function
\begin{equation}
f(x)=x^1+x^2+\dots+x^k
\end{equation}
then the total coefficient of $f(x)^r[x^N]$ (all terms of order $[x^N]$ in $f(x)^r$) will equal the number of compositions of $N$ with $r$ parts and max part size $k$.\footnote{Play a little with this if it's not clear - it all rests on the fact that $x^ax^b = x^{a+b}=x^bx^a$. Squaring $g(x)=x^1+x^2$ gives $g(x)^2 = x^{1+1}+x^{1+2}+x^{2+1}+x^{2+2} = x^2+2x^3+x^4$. This tells us that there is 1 composition of 2 with two parts, max part size 2 (just the $1+1$) as the coefficient of the $x^2$ term is 1. Similarly there are two compositions of 3 with two parts, max part size 2 (compositions $2+1$ and $1+2$) as the coefficient of the $x^3$ term is 2, and only 1 for 4 (composition $2+2$).}

That is, for $f(x)^r=(x^1+\dots+x^k)^r$, if we take only the $x^N$ terms from the expanded product, the coefficient will equal the number of compositions of $N$ of $r$ parts, with max part size $k$.\footnote{Another way to see this is to note that the expanded product will have every possible length $r$ product permutation (with repetition) of the $x^1, \dots, x^k$, which means that the powers of $x$ in the expanded product will be equal to every possible length $r$ \textit{summation} of just those powers $1, \dots, k$. Hence the coefficient in front of each $x^n$ must represent all the different ways to make up $n$ from exactly $r$ permutations (with repetition) of $1, \dots, k$.}

It is easy to show that
\begin{equation}
(1-x)\sum_{n=0}^kx^n=(1-x)(x^0+x^1+\dots+x^{k})=(1-x^{k+1})
\end{equation}
hence
\begin{equation}
\sum_{n=0}^kx^n=\frac{1-x^{k+1}}{1-x}
\end{equation}
for $x\neq1$.  We have then that
\begin{equation}
\begin{split}
f(x)^r & =(x^1+\dots+x^k)^r \\
& = \left[(x^0+x^1+\dots+x^k)-x^0\right]^r \\
& = \left[\frac{1-x^{k+1}}{1-x}-1 \right]^r  \\
& = \left[x \frac{1-x^k}{1-x} \right]^r .
\end{split}
\end{equation}
From the binomial theorem, by separating out the numerator and denominator we can write this as
\begin{equation}
f(x)^r=x^r\sum_{i=0}^r(-1)^{i}x^{ki}\binom{r}{i}\sum_{j=0}^{\infty}(-1)^jx^j\binom{-r}{j}
\end{equation}
where in the second sum we're using the generalised binomial coefficient
\begin{equation}
\binom{\alpha}{\beta}\equiv \frac{\alpha(\alpha-1)(\alpha-2)\dots(\alpha-\beta+1)}{\beta!}.
\end{equation}
Rearranging our second sum\footnote{Write out the binomial coefficient on the LHS, extract $(-1)^j$, and massage.} we have
\begin{equation}
\sum_{j=0}^{\infty}(-1)^jx^j\binom{-r}{j} = \sum_{j=0}^{\infty}x^j\binom{j+r-1}{r-1}.
\end{equation}
We now have that
\begin{equation}
f(x)^r=x^r\sum_{n=0}^r(-1)^{n}x^{kn}\binom{r}{n}\sum_{j=0}^{\infty}x^j\binom{j+r-1}{r-1}.
\end{equation}
As we want $f(x)^r[x^N]$ we know that all the factors of $x$ must multiply to $x^N$, so
\begin{equation}
	r+kn+j=N
\end{equation}
so, rearranging for $j$
\begin{equation}
j = N-kn-r.
\end{equation}
We can now write $f(x)^r[x^N]$ as
\begin{equation}
f(x)^r[x^S]=x^N\sum_{n=0}^r(-1)^{n}\binom{r}{n}\binom{N-nk-1}{r-1}.
\end{equation}
The terms of the sum are clearly $0$  when $N-kn<r$, hence we only need sum to $k=\left \lfloor{\frac{N-r}{k}}\right \rfloor$.  So
\begin{equation}
f(x)^r[x^N]=x^N\sum_{n=0}^{\left \lfloor{\frac{N-r}{k}}\right \rfloor}(-1)^{n}\binom{r}{n}\binom{N-nk-1}{r-1}.
\end{equation}
Recall that the coefficient above will give us the number of compositions of $N$ in exactly $r$ parts, of max part size $k$. We need to know this number for all possible part sizes - as the minimum hop is always going to be a distance of $1$, there can only ever be at most $N$ parts in a composition of $N$, here, so we want
\begin{equation}
\sum_{r=0}^Nf(x)^r[x^N]=x^N\sum_{r=0}^N\sum_{n=0}^{\left \lfloor{\frac{N-r}{k}}\right \rfloor}(-1)^{n}\binom{r}{n}\binom{N-nk-1}{r-1}.
\end{equation}

Using the notation introduced in \textbf{Fibonacci}, we therefore have that

\begin{equation}
C^k_N = \sum_{r=0}^N\sum_{n=0}^{\left \lfloor{\frac{N-r}{k}}\right \rfloor}(-1)^{n}\binom{r}{n}\binom{N-nk-1}{r-1}.
\end{equation}

This suffices to solve \textbf{Frog 2}. To solve \textbf{Frog 1} we can plug in $N=10, k=3$:
\begin{equation}
C^3_{10}=274.
\end{equation}

\end{document}