\documentclass[jou]{apa6}

\usepackage[american]{babel}

\usepackage{csquotes}
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\addbibresource{bibliography.bib}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Discrete Structures
%% The start of RBS stuff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Working internal and external links in PDF
\usepackage{hyperref}
% Extra math symbols in LaTeX
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{amssymb}
% Enumerations with (a), (b), etc.
\usepackage{enumerate}

\let\OLDitemize\itemize
\renewcommand\itemize{\OLDitemize\addtolength{\itemsep}{-6pt}}

\usepackage{etoolbox}
\makeatletter
\preto{\@verbatim}{\topsep=3pt \partopsep=3pt }
\makeatother

% These sizes redefine APA for A4 paper size
\oddsidemargin 0.0in
\evensidemargin 0.0in
\textwidth 6.27in
\headheight 1.0in
\topmargin -24pt
\headheight 12pt
\headsep 12pt
\textheight 9.19in

\title{Sample Quiz 8}
\author{Discrete Structures, Spring 2020}
\affiliation{RBS}

\leftheader{Discrete Sample Quiz 8}

\abstract{%
}

%\keywords{}

\setlength\parindent{0pt}

\begin{document}

%\thispagestyle{empty}

\twocolumn
\section{Worksheet 12: Trees}

{\bf Question 1.} Count the objects:\\
{\bf (A)} If $T$ is a tree with $999$ vertices, then $T$ has $\ldots$ edges.\\
{\bf (B)} There are $\ldots$ non-isomorphic trees with four vertices.\\
{\bf (C)} There are $\ldots$ non-isomorphic rooted trees with four vertices (isomorphism
for rooted trees can change map any node to any other; but it should map root to root).\\
{\bf (D)} There are $\ldots$ full binary trees with six vertices.\\
{\bf (E)} The cycle graph $C_7$ has $\ldots$ spanning trees.\\
{\bf (F)} If $T$ is a binary tree with 100 vertices, its minimum height is $\ldots$.\\
{\bf (G)} If $T$ is a full binary tree with $101$ vertices, its minimum height is $\ldots$.\\
{\bf (H)} If $T$ is a full binary tree with $101$ vertices, its maximum height is $\ldots$.\\
{\bf (I)} If $T$ is a full binary tree with $50$ leaves, its minimum height is $\ldots$.\\
{\bf (J)} Every full binary tree with $61$ vertices has $\ldots$ leaves.\\
{\bf (K)} Every full binary tree with $50$ leaves has $\ldots$ vertices.\\
{\bf (L)} Every 3-ary tree with 13 vertices has $\ldots$ leaves.

\vspace{10pt}
{\bf Question 2.} Find, if a statement is true or false:\\
{\bf (A)} If T is a tree with 17 vertices, then there is a simple path in T of length 17.\\
{\bf (B)} Every tree is bipartite.\\
{\bf (C)} There is a tree with degrees $3, 2, 2, 2, 1, 1, 1, 1, 1$.\\
{\bf (D)} There is a tree with degrees $3, 3, 2, 2, 1, 1, 1, 1$.\\
{\bf (E)} If two trees have the same number of vertices and the same degrees, then the two trees are isomorphic.\\
{\bf (F)} If $T$ is a tree with $50$ vertices, the largest degree that any vertex can have is $49$.\\
{\bf (G)} In a binary tree with $16$ vertices, there must be a path of length $4$.\\
{\bf (H)} If $T$ is a rooted binary tree of height $5$, then $T$ has at most $25$ leaves.

\vspace{10pt}
{\bf Question 3.}\\
Suppose you have $50$ coins, one of which is counterfeit
(either heavier or lighter than the others). You use a
balance scale to find the bad coin. Prove that $4$ weighings
are not enough to guarantee that you find the
bad coin and determine whether
it is heavier or lighter than the other coins.

\vspace{10pt}
{\bf Question 4.}\\
Suppose you have $5$ coins, one of which is counterfeit
(either heavier or lighter than the other four). You use
a pan balance scale to find the bad coin and determine
whether it is heavier or lighter.\\
{\bf (A)} Prove that $2$ weighings are not enough to guarantee
that you find the bad coin and determine whether it
is heavier or lighter.\\
{\bf (B)}  Draw a decision tree for weighing the coins to determine
the bad coin (and whether it is heavier or lighter)
in the minimum number of weighings.

\vspace{10pt}
{\bf Question 5.}\\
Suppose you have $5$ coins, one of which is heavier than the other four.
Draw the decision tree for using a
balance scale to find the heavy coin. How many weighings would you need?

\vspace{10pt}
{\bf Question 6.}
\begin{figure}[!htb]
\center{\includegraphics[width=2.5in]{quiz-sample-12/quiz12-graph.png}}
\caption{\label{fig:quiz12-graph} Graph for DFS and BFS traversal.}
\end{figure}

{\bf (A)} Using alphabetical ordering, find a spanning tree for the graph on Figure~\ref{fig:quiz12-graph} by using a depth-first search.\\
{\bf (B)} Using alphabetical ordering, find a spanning tree for this graph by using a breadth-first search.\\
{\bf (C)} Using the ordering $C, D, E, F, G, H, I, J, A, B$, find a spanning tree for this graph by using a depth-first search.\\
{\bf (D)} Using the ordering $C, D, E, F, G, H, I, J, A, B$, find a spanning tree for this graph by using a breadth-first search.\\
{\bf (E)} Using reverse alphabetical ordering, find a spanning tree for the graph by using a depth-first search.\\
{\bf (F)} Using reverse alphabetical ordering, find a spanning tree for the graph by using a breadth-first search.

\vspace{10pt}
{\bf Question 7.}\\
Write the compound proposition $(\neg p) \rightarrow (q \vee (r \wedge \neg s))$
as the abstract syntax tree ($\neg$, $\rightarrow$, $\vee$ and $\wedge$ operators
are inner nodes; but $p,q,r,s$ are leaves).\\
List the graph nodes in pre-order, in-order and post-order traversal of this syntax tree.

\vspace{10pt}
{\bf Question 8.}\\
Draw the abstract syntax tree, the preorder and postorder traversal
of $(8x - y)^5 - 7\sqrt{4z - 3}$.

\vspace{10pt}
{\bf Question 9.}
The string\\
$p\;r\;q\;\rightarrow\;\neg\;q\;\triangle\;p\;\rightarrow\;\wedge$\\
is postfix notation for a logic expression; however, there is a misprint. The
triangle should be one of these three: $r$, $\vee$, or $\neg$.
Determine which of these three it must be and explain your
reasoning.

\mbox{}
\newpage
\subsection{Answers}

\vspace{10pt}
{\bf Question 1.} Answer:\\
{\bf (A)} If $T$ is a tree with $999$ vertices, then $T$ has $998$ edges.\\
{\bf (B)} There are $2$ non-isomorphic trees with four vertices.\\
{\bf (C)} There are $4$ non-isomorphic rooted trees with four vertices.\\
{\bf (D)} There are $0$ full binary trees with six vertices.\\
{\bf (E)} The cycle graph $C_7$ has $7$ spanning trees.\\
{\bf (F)} If $T$ is a binary tree with 100 vertices, its minimum height is $6$.\\
{\bf (G)} If $T$ is a full binary tree with $101$ vertices, its minimum height is $6$.\\
{\bf (H)} If $T$ is a full binary tree with $101$ vertices, its maximum height is $50$.\\
{\bf (I)} If $T$ is a full binary tree with $50$ leaves, its minimum height is $6$.\\
{\bf (J)} Every full binary tree with $61$ vertices has $31$ leaves.\\
{\bf (K)} Every full binary tree with $50$ leaves has $99$ vertices.\\
{\bf (L)} Every 3-ary tree with 13 vertices has $9$ leaves.

\vspace{10pt}
{\bf Question 2.} Answer: TBD \\

\vspace{10pt}
{\bf Question 3.} Answer:\\

Four weighings could give at most $3^4 = 81$ outcomes (each time we use scales there are
three possible results). But the problem has $2 \cdot 50$ different situations
(any of the $50$ coins can be different; and it can be either heavier or lighter).

\vspace{10pt}
{\bf Question 4.} Answer: TBD \\

\vspace{10pt}
{\bf Question 5.} Answer: TBD \\

\vspace{10pt}
{\bf Question 6.} Answer: TBD \\

\vspace{10pt}
{\bf Question 7.} Answer: TBD \\

\vspace{10pt}
{\bf Question 8.} Answer: TBD \\

\vspace{10pt}
{\bf Question 9.} Answer: TBD \\

\end{document}


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\section*{NYU Physics I---Problem Set 3}

Due Thursday 2018 September 27 at the beginning of lecture.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Re-do the ``block on a plane'' problem we did in class, but now using
vector components. Make the $x$ direction point down the plane, and
make the $y$ direction point perpendicular to the plane, and solve for
the $x$ and $y$ components of gravity, the normal force, and the
block's acceleration (that is, three vectors, and two components per
vector).

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
In a 200-m race, the winner crosses the halfway mark (ie, 100~m) at
$t_{1/2}=10.12$~s and the finish line at $t_{\rm f}=19.32$~s.  If you
make a kinematic model of the runner's behavior as (i)~constant
acceleration $a$ from rest for the period $0<t<t_a$ followed by
(ii)~constant speed $v=a\,t_a$ during the period $t_a<t<t_{\rm f}$,
what are $a$ and $t_a$?

\emph{Hint: Draw a graph of $v(t)$ before you start writing equations.}

\emph{Hint: Once you have a graph, consider the question: is $t_a$
going to be before or after $t_{1/2}$?  Make a quantitative argument.}

\emph{Hint: You can solve this problem with geometry and the graph; no
  need to do calculus!}

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%

In the system shown below, the strings are massless and inextensible
and the pulley is massless and frictionless.  There is a small
frictional force $F_\mathrm{f}=\mu\,N$ between block $m_1$ and the
table, but when released from rest, block $m_2$ falls. Ignore air
resistance!

\noindent~\hfill\includegraphics{../mp/pulley_table.pdf}\hfill~

\textsl{(a)} Draw complete free-body diagrams for both masses, and for
the pulley.

\textsl{(b)} What is the acceleration $\vec{a}$ (magnitude and
direction) of mass $m_1$?  Give your answer in terms of quantities
shown in the diagram.

\textsl{(c)} Why did we treat the strings as massless? How did that
help us?

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Imagine a package of mass $M$ sitting on the floor of an elevator that
is accelerating upwards at acceleration $a$. The acceleration due to
gravity is $g$.

\textsl{(a)} Draw the free-body diagram for the package.

\textsl{(b)} What is the magnitude $N$ of the normal force on the
package?

\textsl{(c)} Answer those same two questions again, but with the
elevator accelerating \emph{downwards} at acceleration $a$.

\textsl{(d)} Answer those same two questions again, but with the
elevator accelerating downwards at acceleration $g$ (that is, at
the gravitational acceleration).

\textsl{(e)} In lecture Prof Hogg did a stunt with a coffee cup and a
quarter. Draw the free-body diagram for the quarter when it was at the
top of the arc (that is, when it was directly overhead).

\paragraph{Extra Problem (will not be graded for credit):}%
In what sense were the astronauts in the Space Station weightless? Is
there no gravity acting? Look up the altitude at which the Space
Station orbited and ask yourself: How much weaker is the gravitational
force at that altitude? (The relevant distance is the distance from
the Space Station to the center of the Earth.)

Also, why didn't the quarter fall out of the cup?

\end{document}


%%%%%%%% ICML 2021 EXAMPLE LATEX SUBMISSION FILE %%%%%%%%%%%%%%%%%

\documentclass{article}

% Recommended, but optional, packages for figures and better typesetting:
% \usepackage[english]{babel}
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}
\usepackage{amsmath,amssymb,physics}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{booktabs} % for professional tables

% hyperref makes hyperlinks in the resulting PDF.
% If your build breaks (sometimes temporarily if a hyperlink spans a page)
% please comment out the following usepackage line and replace
% \usepackage{icml2021} with \usepackage[nohyperref]{icml2021} above.
\usepackage{hyperref}

% Attempt to make hyperref and algorithmic work together better:
\newcommand{\theHalgorithm}{\arabic{algorithm}}

% Use the following line for the initial blind version submitted for review:
% \usepackage{icml2021}

% If accepted, instead use the following line for the camera-ready submission:
\usepackage[accepted]{icml2021}

% The \icmltitle you define below is probably too long as a header.
% Therefore, a short form for the running title is supplied here:
\icmltitlerunning{Review on \textsc{Efficient Bandit Algorithms for Online Multiclass Prediction}}

\begin{document}

\twocolumn[
\icmltitle{Review on \textsc{Efficient Bandit Algorithms\\for Online Multiclass Prediction}}

% It is OKAY to include author information, even for blind
% submissions: the style file will automatically remove it for you
% unless you've provided the [accepted] option to the icml2021
% package.

% List of affiliations: The first argument should be a (short)
% identifier you will use later to specify author affiliations
% Academic affiliations should list Department, University, City, Region, Country
% Industry affiliations should list Company, City, Region, Country

% You can specify symbols, otherwise they are numbered in order.
% Ideally, you should not use this facility. Affiliations will be numbered
% in order of appearance and this is the preferred way.
% \icmlsetsymbol{equal}{*}

\begin{icmlauthorlist}
\icmlauthor{Xiaochen Zhu}{soc,math}     %{nus}%
% \icmlauthor{Author 2}{math}  %{nus}%
\end{icmlauthorlist}

\icmlaffiliation{math}{Department of Mathematics, National University of Singapore}
\icmlaffiliation{soc}{Department of Computer Science, National University of Singapore}
% \icmlaffiliation{nus}{National University of Singapore}
\icmlcorrespondingauthor{Xiaochen Zhu, A0194512H}{\texttt{xzhu@u.nus.edu}}
% \icmlcorrespondingauthor{Author 2}{email2@u.nus.edu}

% You may provide any keywords that you
% find helpful for describing your paper; these are used to populate
% the "keywords" metadata in the PDF but will not be shown in the document
\icmlkeywords{Machine Learning, ICML}

\vskip 0.3in
]

% this must go after the closing bracket ] following \twocolumn[ ...

% This command actually creates the footnote in the first column
% listing the affiliations and the copyright notice.
% The command takes one argument, which is text to display at the start of the footnote.
% The \icmlEqualContribution command is standard text for equal contribution.
% Remove it (just {}) if you do not need this facility.

%\printAffiliationsAndNotice{}  % leave blank if no need to mention equal contribution
\printAffiliationsAndNotice{} % otherwise use the standard text.

\begin{abstract}
    This report provides a critical review of the paper ``Efficient bandit algorithms for online multiclass prediction''\cite{kakade2008efficient}, which proposes an efficient algorithm, namely \textit{Banditron} for multiclass online learning with linear hypotheses in a bandit setting where the learner can only receive partial feedback about whether its prediction is correct or not, instead of the full information feedback which also contains the correct label. We review the Banditron algorithm and related proofs and discuss the positive points and contributions from an advocate perspective. Then, we identify some limitations with the algorithm, namely: (i) the mistake bound is polynomial to the number of examples; (ii) it is hard to optimally tune the hyperparameter $\gamma$. Then, we propose an improvement of Banditron to tackle the latter issue and theoretically show the mistake bound of the improved Banditron algorithm. At last, we address the incompleteness of our work (due to limited time) and further research work required to complement the current result.
\end{abstract}

\section{Overview}
\vspace{-.05in}

In convential multiclass machine learning (ML) settings, a learner aims to learn a model from a dataset $\mathcal{D}=\{(x_t,y_t):t\in\{1,2,\ldots,T\},x_t\in\mathbb{R}^d,y_t\in[k]=\{1,2,\ldots,k\}\}$ where $d$ is the dimension of examples and $k$ is the number of label classes. First, the learner initializes its model and make prediction $\hat{y_t}$ on example $x_t$. Then, it compares its own prediction $\hat{y_t}$ and the ground truth label $y_t$ to update its own model. However, in real world scenarios, one may not always have the privilege to know the actual labels but is only aware of the correctness of its predictions. We refer to this scenario as bandit setting, where the learner only has access to indicator $\mathbf{1}[\hat{y_t}=y_t]$ instead of $y_t$. Naturally, ML in bandit setting is an online (the learner cannot test a batch of examples at a time) multiclass (knowing $\mathbf{1}[\hat{y_t}=y_t]$ is equivalent to knowing $y_t$ for binary classification) classification problem, which has been extensively studied. The work of our interest, \citet{kakade2008efficient}, studies the learning of linear predicators in the bandit setting and proposes a variant of \textsc{Multiclass Perceptron} \cite{crammer2003ultraconservative}, namely \textsc{Banditron}. This section reviews the algorithm and gives a proof sketch on its mistake bound.

\subsection{Multiclass Perceptron}
Before introducing Banditron, we first discuss Multiclass Perceptron, the foundation of Banditron in the full information context (i.e. the learner receives ground truth labels $y_t$ instead of bandit feedback). In Multiclass Perceptron, the learner learns a model $W\in\mathbb{R}^{k\times d}$, where each row vector $W_j$ can be interpreted as a linear predictor $\theta_j\in\mathbb{R}^d$ as in the original binary Perceptron algorithm \cite{rosenblatt1958perceptron}. On example $\mathbf{x}_t,y_t$, the learner predicts $\text{argmax}_j (W\mathbf{x}_t)_j$, the index of the maximum prediction among all $\theta_j$ predictions. Similar to the binary Perceptron, Multicalss Perceptron updates $W$ on prediction mistakes, penalizing the row vector of $W$ making the wrong prediction and reinforcing the row vector of $W$ that should have given the greatest output. That is, given that $\hat{y_t}=\text{argmax}_j (W\mathbf{x}_t)_j$, then we have $\forall j\in[k]$,
\begin{equation}\label{eqn:perceptron_update}
    W^{(t+1)}_j=
    \begin{cases}
        W^{(t)}_j,&\text{if } \hat{y_t}=y_t\\
        \begin{cases}
            W^{(t)}_j - \mathbf{x}_t, &\text{if } j=\hat{y_t}\\
            W^{(t)}_j + \mathbf{x}_t, &\text{if } j=y_t
        \end{cases},&\text{if } \hat{y_t}\neq y_t
    \end{cases}
\end{equation}
Rearranging Equation (\ref{eqn:perceptron_update}), the update rule of Multiclass Perceptron can be expressed as $W^{(t+1)}=W^{(t)}+U^{(t)}$, where for all $j\in[k]$, \begin{equation}\label{eqn:perceptron_u}U^{(t)}_r=\mathbf{x}_t(\mathbf{1}[y_t=r]-\mathbf{1}[\hat{y_t}=r]).\end{equation}

Despite its simplicity, Multiclass Perceptron enjoys favorable mistake bounds. \citet{fink2006online} prove that if $\norm{\mathbf{x}_t}\leq1$ for all $t$, the number of mistakes (i.e. updates) Multiclass Perceptron makes to reach any fixed model $W^*\in\mathbb{R}^{(k\times d)}$ is upper bounded by $L+D+\sqrt{LD}$, where $L$ is the sum of hinge loss of $W^*$ on all examples \footnote{$L=\sum_{t=1}^T\max_{r\in[k]\setminus\{y_t\}}\max\{0,1-W^*_{y_t}\mathbf{x}_t+W^*_r\mathbf{x}_t\}$.} and $D=2\sum_{i=1}^{k}\sum_{j=1}^d (W^*_{ij})^2$, the \textit{complexity}\footnote{$D=2\norm{W^*}_F^2$, twice the square of Frobenius norm of $W^*$.} of $W^*$. Note that this bound is not assumed with any linear separability of $\mathcal{D}$. On contrast, \citet{crammer2003ultraconservative} shows that if $\norm{\mathbf{x}_t}\leq R$ for all $t$ and there exists a $W^*$ whose complexity $D\leq1$ that separate all examples correctly with a margin $\gamma$ (i.e. for all $t$, $W^*_{y_t}\mathbf{x}_t\geq\gamma/2$ and $W^*_i\mathbf{x}_t\leq\gamma/2$ for all $i\neq y_t$), the number of updates performed by Multiclass Perceptron is bounded by $2R/\gamma^2$. Since the focus of this review is Banditron, we will not prove these mistake bounds here.

\begin{algorithm}[bt]
    \caption{Banditron}\label{alg:band}
 \begin{algorithmic}
    \STATE \textbf{Given:} $\gamma\in(0,1)$
    \STATE Initialize $W^{(1)}\leftarrow\mathbf{0}\in\mathbb{R}^{(k\times d)}$
    \FOR{$t=1$ {\bfseries to} $T$}
    \STATE $\hat{y_t}\leftarrow\text{argmax}_j(W^{(t)}\mathbf{x}_t)_j$
    \STATE Choose from $\{\text{exploitation},\text{exploration}\}$ with probability $(1-\gamma,\gamma)$
    \IF{\text{exploitation}}
    \STATE $\tilde{y_t}=\hat{y_t}$
    \ELSE
    \STATE Randomly choose $\tilde{y_t}$ from $[k]$ uniformly
    \ENDIF
    \STATE $W^{(t+1)}\leftarrow W^{(t)}$
    \IF{$\tilde{y_t}\neq y_t$}
        \STATE Update $W^{(t+1)}_{\tilde{y_t}}\leftarrow W^{(t)}_{\tilde{y_t}}+\mathbf{x}_t/\text{P}(\tilde{y_t})$
        \STATE Update $W^{(t+1)}_{\hat{y_t}} \leftarrow W^{(t)}_{\hat{y_t}} - \mathbf{x}_t$
    \ELSE
    \STATE Update $W^{(t+1)}_{\hat{y_t}} \leftarrow W^{(t)}_{\hat{y_t}} - \mathbf{x}_t$
    \ENDIF
    \ENDFOR
 \end{algorithmic}
\end{algorithm}

\subsection{The Banditron algorithm}
Banditron, the main result of \citet{kakade2008efficient}, adopts the idea of Multiclass Perceptron. However, it cannot reinforce the row vector $W_{y_t}$ on mistakes because it does not receive ground truth labels $y_t$. Banditron addresses this issue by performing exploration rounds (predict based on a probability distribution) as well as exploitation rounds (predict based on its model $W$), which is a common idea in reinforcement learning. This is natural and intuitive because rather than being a supervised ML problem where the learner has access to a dataset with labels, the setting of ML with bandit feedback is more like reinforcement learning, where the learner has no information about the correct prediction, but only provided with a reward feedback on each of its actions, i.e. $\mathbf{1}[y_t=\hat{y_t}]$. The general idea of Banditron is that, on each example, the learner either explores with probability $\gamma$, where it randomly pick one label (i.e. each one with probability $\gamma/k$) to test, or explores with probability $1-\gamma$, where it predits $\hat{y}=\text{argmax}_j(W\mathbf{x}_t)_j$. Hence, on example $(\mathbf{x}_t,y_t)$, Banditron predicts $\hat{y_t}$ with probability $\gamma/k+1-\gamma$ and any other $i\neq\hat{y_t}$ with probability $\gamma/k$. Denote the probability of choosing $\tilde{y_t}=i$ as $\text{P}(i)$, the complete algorithm follows as Algorithm \ref{alg:band}. If one wants a closed-form update policy $W^{(t+1)}=W^{(t)}+\tilde{U}^{(t)}$ using the style of (\ref{eqn:perceptron_u}), we have for all $r\in[k]$ \begin{equation}\label{eqn:banditron_u}
    \tilde{U}^{(t)}_r=\mathbf{x}_t\left(\frac{\mathbf{1}[y_t=\tilde{y_t}]\mathbf{1}[r=\tilde{y_t}]}{\text{P}(r)}-\mathbf{1}[r=\hat{y_t}]\right).
\end{equation}

On correct predictions, if Banditron predicts by exploration, it reinforces the $\tilde{y_t}$-th row vector and penalize the $\hat{y_t}$-th row vector. If Banditron predicts correctly by exploitation, it adds $\mathbf{x}_t/\text{P}(\hat{y_t})-\mathbf{x}_t$ to the $\hat{y_t}$-th row vector which is an reinforcement since $1/\text{P}(\hat{y_t})>1$. On wrong predictions, Banditron subtracts $\mathbf{x}_t$ from the $\hat{y_t}$-th row vector, to make the algorithm \textit{unbiased} compared with Multiclass Perceptron, which is fomally defined in Lemma \ref{lem:unbias}.

\subsection{Mistake bound of Banditron}\label{sec:bound}
\citet{kakade2008efficient} proves a mistake bound similar to the $L+D+\sqrt{LD}$ bound for Multiclass Perceptron \cite{fink2006online}, stated in the following Theorem \ref{thm:bound}, whose concise sketch of proof will be discussed in this section.

\begin{theorem}[Mistake bound of Banditron]\label{thm:bound}
    If $\norm{\mathbf{x}_t}\leq1$ for all $t\in[T]$, then for any fixed model $W^*$, the number of mistakes $M$ made by Banditron satisifes \begin{equation}
        \mathbb{E}(M)\leq L+\gamma T+3\max\left\{\frac{kD}{\gamma},\sqrt{D\gamma T}\right\} + \sqrt{\frac{kDL}{\gamma}},
    \end{equation} where $L$ is the sum of hinge loss of $W^*$ on all examples and $D$ is the complexity of $W^*$ as defined earlier.
\end{theorem}

To bound the expectation of $M$, the number of mistakes Banditron makes when approaching $W^*$, naturally one investigates the term $\mathbb{E}[\langle W^*,W^{(t)}\rangle]$ \footnote{This is an extension of the conventionly inner product between vectors in the domain of matrices, i.e. $\langle A,B\rangle=\sum_i\sum_j A_{ij}B_{ij}$.}, which adopts the same idea used to prove the convergence bound of binary and multiclass Perceptron. The key ideas is to construct both an upper and a lower bound of $\langle W^*,W^{(t)}\rangle$. To do so, one needs the following lemmas, which can be proved by calculating the expectation w.r.t. $\tilde{y_t}$ using Equation (\ref{eqn:banditron_u}).

\begin{lemma}\label{lem:unbias}
    Banditron is unbiased compared with Multiclass Perceptron, in the sense for each update, that the expectation of Banditron's update matrix $\tilde{U}^{(t)}$ is the same as Multiclass Perceptron's update matrix $\tilde{U}$, w.r.t. the random variable $\tilde{y_t}$, that is, $\mathbb{E}_t[\tilde{U}^{(t)}]=U^{(t)}$.
\end{lemma}

\begin{lemma}\label{lem:frobenius}
    The expectation (w.r.t. $\tilde{y_t}$) of the squared Frobenius norm of $\tilde{U}^{(t)}$ is bounded as $\mathbb{E}_t[\Vert\tilde{U}^{(t)}\Vert^2_F]\leq2\norm{\mathbf{x}_t}^2\left(k/\gamma\mathbf{1}[y_t\neq \hat{y_t}]+\gamma\mathbf{1}[y_t=\hat{y_t}]\right)$.
\end{lemma}

First to lower bound $\mathbb{E}[\langle W^*,W^{(T+1)}\rangle]$, we have
\begin{equation}\label{eqn:5}
    \begin{aligned}
        &\mathbb{E}[\langle W^*,W^{(T+1)}\rangle]
        =\sum_{t=1}^T\mathbb{E}[\langle W^*,W^{(t+1)}\rangle]-\mathbb{E}[\langle W^*,W^{(t)}\rangle]\\
        &=\sum_{t=1}^T\mathbb{E}[\langle W^*,W^{(t+1)}-W^{(t)}\rangle]
        =\sum_{t=1}^T\mathbb{E}[\langle W^*,\tilde{U}^{(t)}\rangle]\\
        &=\sum_{t=1}^T\mathbb{E}[\langle W^*,U^{(t)}\rangle]\qquad\text{(by Lemma 1)}\\
        &\geq\sum_{t=1}^T\mathbb{E}[\mathbf{1}[\hat{y_t}\neq y_t]]-\ell_\text{hinge}(W^*,(\textbf{x}_t,y_t))
        =\mathbb{E}[\hat{M}]-L,
    \end{aligned}
\end{equation}
where $\hat{M}=\sum_{t=1}^T\mathbf{1}[\hat{y_t}\neq y_t]$. The last inequality is true because $\ell_{\text{hinge}}(W^*,(\mathbf{x}_t,y_t))\geq\mathbf{1}[\hat{y_t}\neq y_t]-\langle W^*,U^{(t)}\rangle$, derived from the definition of multiclass hinge loss.

Then, one wants to upper bound $\mathbb{E}[\langle W^*,W^{(T+1)}\rangle]$, using Cauchy-Schwartz and Jensen's inequalities, we have
\begin{equation}\label{eqn:6}
    \begin{aligned}
        &\mathbb{E}[\langle W^*,W^{(T+1)}\rangle]\leq\mathbb{E}[\Vert W^*\Vert_F\Vert W^{(T+1)}\Vert_F]\\
        &\leq\sqrt{\frac{D\mathbb{E}[\Vert W^{(T+1)}\Vert_F^2]}{2}}\qquad\text{(since }\sqrt{\cdotp}\text{ is concave)}.
    \end{aligned}
\end{equation}
Since $\Vert W^{(t+1)}\Vert_F^2=\Vert W^{(t )}\Vert_F^2+\langle W^{(t)},\tilde{U}^{(t)}\rangle+\Vert\tilde{U}^{(t)}\Vert^2_F$ for all $t\in [T]$, we then have
\begin{equation}\label{eqn:7}
    \begin{aligned}
        &\mathbb{E}[\Vert W^{(T+1)}\Vert_F^2]=\sum_{t=1}^T(\mathbb{E}[\langle W^{(t)},\tilde{U}^{(t)}\rangle]+\mathbb{E}[\Vert\tilde{U}^{(t)}\Vert^2_F])\\
        &=\sum_{t=1}^T(\mathbb{E}[\langle W^{(t)},{U}^{(t)}\rangle]+\mathbb{E}[\Vert\tilde{U}^{(t)}\Vert^2_F])\quad\text{(by Lemma 1)}\\
        &\leq\sum_{t=1}^T\mathbb{E}[\Vert\tilde{U}^{(t)}\Vert^2_F]\\
        &\leq\sum_{t=1}^T\mathbb{E}[\frac{2k}{\gamma}\mathbf{1}[y_t\neq \hat{y_t}]+2\gamma\mathbf{1}[y_t=\hat{y_t}]]\quad\text{(by Lemma 2)}\\
        &=\frac{2k}{\gamma}\mathbb{E}[\hat{M}] + 2\gamma T.
    \end{aligned}
\end{equation}

Substituting (\ref{eqn:7}) into (\ref{eqn:6}), we have
\begin{equation}\label{eqn:8}
    \begin{aligned}
    \mathbb{E}[\hat{M}]-L&\leq\mathbb{E}[\langle W^*,W^{(T+1)}\rangle]\\
    &\leq\sqrt{\frac{Dk\mathbb{E}[\hat{M}]}{\gamma}}+\sqrt{D\gamma T}.
    \end{aligned}
\end{equation}
Therefore, one can give an upper bound of $\mathbb{E}[\hat{M}]$ from (\ref{eqn:8}) and because Banditron explores no more than $\gamma T$ rounds, we have
\begin{align}
    &\mathbb{E}[M]\leq\mathbb{E}[\hat{M}]+\gamma T\label{eqn:9}\\
    &\leq L+\gamma T+3\max\left\{\frac{kD}{\gamma},\sqrt{D\gamma T}\right\} + \sqrt{\frac{kDL}{\gamma}}.\label{eqn:10}
\end{align}

\section{Contributions}\label{sec:positive}
\vspace{-.05in}
From the perspective of an advocate, this section discusses some of the contributions and positive points about \citet{kakade2008efficient}.
% \subsection{Mistake bound only dependent on $W^*$}

\subsection{As an unbiased variant of Multiclass Perceptron}
First of all, like its foundation Multiclass Perceptron, Banditron is an intuitive and simple algorithm that naturally makes sense. While Lemma \ref{lem:unbias} guarantees that the expected update matrix in Banditron is the same as Multiclass Perceptron, Banditron enjoys some of the advantages of Multiclass Perceptron such as the favorable performance (demonstrated in \citet{kakade2008efficient} empirically) and mistake bound (as proved in Section \ref{sec:bound}). As one of the earliest paper studying multiclass linear classification with bandit feedback, \citet{kakade2008efficient} enables further research to study this area more thoroughly. In short, the importance of the Banditron algorithm w.r.t. the bandit setting should be similar to that of the Perceptron \cite{rosenblatt1958perceptron} w.r.t. the full information setting.

\subsection{Mistake bound w.r.t. arbitrary $W^*$}\label{sec:2.2}
The approach \citet{kakade2008efficient} uses to provide a mistake bound for Banditron is similar to \citet{fink2006online}, which is given w.r.t. any fixed model matrix $W^*$ without any further assumptions on either the separability of $\mathcal{D}$ or the loss of $W^*$. In contrast, the mistake bounds for Perceptron and Multiclass Perceptron derived in \citet{rosenblatt1958perceptron,crammer2003ultraconservative} are made under the assumption of linear separability with a known margin and the existence of a zero-loss solution $W^*$. However, when running the algorithms, one cannot guarantee neither the existence of a solution nor the margin for linear separability, while the bounds in \citet{kakade2008efficient} and \citet{fink2006online} enables anyone to know the upper bound of mistakes when approaching any arbitrary goal $W^*$. Hence, the bound given by \citet{kakade2008efficient} is more generalized.

While it is not possible to derive the general case mistake boundary from the linear separable case, we can easily derive some mistake bound on the separable case from the general bound given by \citet{kakade2008efficient}. Assume that $\mathcal{D}$ is linearly separable and $W^*$ is a zero-loss solution, one can easily derive that $\mathbb{E}[M]$ is bounded by $O(\sqrt{T})$ by substituting $L=0$ in Equation (\ref{eqn:10}).

\section{Limitations}\label{sec:negative}
\vspace{-.05in}
From the perspective of a critic, this section discusses some of the limitations and negative points about the \citet{kakade2008efficient}.

\begin{figure}[t]
    \centering
    \includegraphics[width=0.7\linewidth]{./images/gammas.png}
    \label{fig:gammas}
    \caption{Two runs of Banditron with various $\gamma$}
\end{figure}

\subsection{Dependency of mistake bound on $T$}
Note that the mistake bound given by \citet{kakade2008efficient} (Theorem \ref{thm:bound}) is polynomial large w.r.t. the number of examples/updates $T$. Such dependency on $T$ does not exist on the mistake bounds in Multiclass Perceptron and has made Banditron's mistake bounds undesirable with a long time horizon. \citet{beygelzimer2019bandit} addresses this issue in the $m$-linearly separable case by proprosing an algorithm that achieve near-optimal mistake bound of $O(k/\sqrt{m})$.

\subsection{Tuning of hyperparameter $\gamma$}\label{sec:3.2}
Another limitation of Banditron is the difficulty in tuning of hyperparameter, namely the exploration-exploitation trade-off parameter $\gamma$. First, because of the randomness of the algorithm, the performance (i.e. error rate) of Banditron with different $\gamma$ values have high variation and can be dramastically different in each run. This has been demonstrated in Figure \ref{fig:gammas}, where the same algorithm with the same set of $\gamma$ values is executed on the dataset of Wine quality \cite{wine1999}, which is a non-linearly separable dataset with $k=7,d=11,T=4898$. We can see that different runs of the same parameter may result in dramastically different performance (i.e. in the first run, the best $\gamma$ seems to be $0.002$ while in the second run, the best $\gamma$ seems to be much larger at either $0.02$ or $0.01$). Even one can run the algorithm for multiple times and compare the average performance to choose $\gamma$, the high variantion of the performance will make such hyperparameter tuning less effective.

Another issue regarding tuning of $\gamma$ is that, the optimal $\gamma$ that can minimize error rate varies a lot on different datasets, the $\gamma$ chosen from the known dataset may not be applicable for predicting actual user behavior, while the learner cannot directly trains Banditron with user to with several $\gamma$ to choose the best one (because in bandit setting, the learner cannot choose the examples it sees or sees the same example over and over again, otherwise the learner can just trial and error every label until receiving a positive feedback). Hence, the choice of $\gamma$ seems to be difficult in real world applications.

\section{Extension}\label{sec:extension}
\vspace{-.05in}

\begin{algorithm}[bt]
    \caption{Banditron with variable $\gamma$}\label{alg:vari}
 \begin{algorithmic}
    \STATE \textbf{Given:} $\gamma_1,\gamma_2,\ldots,\gamma_T\in(0,1)$
    \STATE Initialize $W^{(1)}\leftarrow\mathbf{0}\in\mathbb{R}^{(k\times d)}$
    \FOR{$t=1$ {\bfseries to} $T$}
    \STATE $\hat{y_t}\leftarrow\text{argmax}_j(W^{(t)}\mathbf{x}_t)_j$
    \STATE $\gamma\leftarrow \gamma_t$
    \STATE Choose from $\{\text{exploitation},\text{exploration}\}$ with probability $(1-\gamma,\gamma)$
    \IF{\text{exploitation}}
    \STATE $\tilde{y_t}=\hat{y_t}$
    \ELSE
    \STATE Randomly choose $\tilde{y_t}$ from $[k]$ uniformly
    \ENDIF
    \STATE $W^{(t+1)}\leftarrow W^{(t)}$
    \IF{$\tilde{y_t}\neq y_t$}
        \STATE Update $W^{(t+1)}_{\tilde{y_t}}\leftarrow W^{(t)}_{\tilde{y_t}}+\mathbf{x}_t/\text{P}(\tilde{y_t})$
        \STATE Update $W^{(t+1)}_{\hat{y_t}} \leftarrow W^{(t)}_{\hat{y_t}} - \mathbf{x}_t$
    \ELSE
    \STATE Update $W^{(t+1)}_{\hat{y_t}} \leftarrow W^{(t)}_{\hat{y_t}} - \mathbf{x}_t$
    \ENDIF
    \ENDFOR
 \end{algorithmic}
\end{algorithm}

In this section, we introduce some extensions of Banditron theoretically and empirically, focusing on the use of variable $\gamma$ in Banditron. First, there are several issues with the constant $\gamma$ value in Banditron:
\begin{enumerate}
    \item As discussed in Section \ref{sec:3.2} constant $\gamma$ will have big impact on the performance and make it harder to tune;
    \item With constant $\gamma$, Banditron uses the same exploitation-exploration stategy even after a long time horizon, when the matrix $W$ should be able to reach a very small loss and Banditron should value exploitation more than exploration. Instead, Banditron still explores with probability $\gamma$. This is especially undesirable under separability.
\end{enumerate}

Motivated by these issues, we study the use of variable $\gamma$ instead of constant $\gamma$ in Banditron. If Banditron can still work under variable $\gamma$, then we can design better and more flexible update policies, such as exploration more in earlier iterations while exploitation more in later ones. Moreover, the sequence of $\gamma$ is potentially \textit{learnable} to minimize the error rate and therefore there's no need to tune the parameter.

The Banditron with variable $\gamma$ is given as Algorithm \ref{alg:vari}, and we can prove the following mistake bound for this algorithm.

\begin{theorem}[Banditron with variable $\gamma$]\label{thm:2}
    If $\Vert \mathbf{x}_t\Vert\leq1$ for all $t\in[T]$, then for any fixed model $W^*$, the number of mistakes $M$ made by Algorithm \ref{alg:vari} satisifes
    \begin{equation}
        \mathbb{E}[M]\leq L+\gamma_{\textup{sum}}+3\max\{\frac{kD}{\gamma_{\min}},\sqrt{D\gamma_{\textup{sum}}}\}+\sqrt{\frac{kDL}{\gamma_{\min}}}
    \end{equation} where $\gamma_{\min}=\min\{\gamma_1,\ldots,\gamma_T\},\gamma_{\textup{sum}}=\sum_{t=1}^T\gamma_t$ and $k,L,D$ have been defined previously.
\end{theorem}

We hereby provide a proof sketch of the stated theorem by modifying the original proof in Section \ref{sec:bound}.

First, note that although the $\gamma$ values in different rounds are different, the update policy in each round is still the same with the original Banditron of fixed $\gamma$. Therefore, Lemma \ref{lem:unbias} and \ref{lem:frobenius} are still true (other than replacing $\gamma$ with $\gamma_t$ in Lemma \ref{lem:frobenius}) given that the expectation is taken w.r.t. the choice of $\tilde{y_t}$ in a single round with one $\gamma$. Therefore Equation (\ref{eqn:5}) should still be true while Equation (\ref{eqn:7}) now becomes
\begin{equation}
    \begin{aligned}
        &\mathbb{E}[\Vert W^{(T+1)}\Vert_F^2]\\
        &\leq\sum_{t=1}^T\mathbb{E}[\frac{2k}{\gamma_t}\mathbf{1}[y_t\neq \hat{y_t}]+2\gamma_t\mathbf{1}[y_t=\hat{y_t}]]\quad\text{(by Lemma 2)}\\
        % &=\frac{2k}{\gamma}\mathbb{E}[\hat{M}] + 2\gamma T.
        &=\sum_{t=1}^T\mathbb{E}\left[\left(\frac{2k}{\gamma_t}-2\gamma_t\right)\mathbf{1}[y_t\neq\hat{y_t}]+2\gamma_t\right]\\
        &=2\gamma_{\text{sum}}+\sum_{t=1}^T\mathbb{E}\left[\left(\frac{2k}{\gamma_t}-2\gamma_t\right)\mathbf{1}[y_t\neq\hat{y_t}]\right]\\
        &\leq2\gamma_{\text{sum}}+\sum_{t=1}^T\mathbb{E}\left[\left(\frac{2k}{\gamma_{\min}}-2\gamma_{\min}\right)\mathbf{1}[y_t\neq\hat{y_t}]\right]\\
        % &=2\gamma_{\text{sum}}+\left(\frac{2k}{\gamma_{\min}}-2\gamma_{\min}\right)\mathbb{E}[\hat{M}]\\
        &\leq2\gamma_{\text{sum}}+\frac{2k}{\gamma_{\min}}\mathbb{E}[\hat{M}].
    \end{aligned}
\end{equation}

Therefore, similar to Equation (\ref{eqn:8}), we now have
\begin{equation}\label{eqn:13}
    \begin{aligned}
    \mathbb{E}[\hat{M}]-L&\leq\mathbb{E}[\langle W^*,W^{(T+1)}\rangle]\\
    &\leq\sqrt{\frac{Dk\mathbb{E}[\hat{M}]}{\gamma_{\min}}}+\sqrt{D\gamma_{\text{sum}}}.
    \end{aligned}
\end{equation}
Hence, one can derive an upper bound of $\mathbb{E}[\hat{M}]$ from Equation (\ref{eqn:13}). Since our algorithm in expectation runs $\gamma_{\text{sum}}$ exploration rounds, we have
\begin{equation}
    \begin{aligned}
    &\mathbb{E}[M]\leq \mathbb{E}[\hat{M}]+\gamma_{\text{sum}}\\
    &\leq L+\gamma_{\textup{sum}}+3\max\{\frac{kD}{\gamma_{\min}},\sqrt{D\gamma_{\textup{sum}}}\}+\sqrt{\frac{kDL}{\gamma_{\min}}}.
    \end{aligned}
\end{equation}

\section{Further research}
Therorem \ref{thm:2} enables Banditron to run with variable $\gamma$ values, which can be applied to design better update policies for Banditron. I have experimented several (intuitive) update policies on the datasets of wine quality and Iris \cite{wine1999,iris2019}, including:
\begin{itemize}
    \item a decreasing sequence of $\gamma$, preferring exploration first and then preferring exploitation in later rounds;
    \item adaptively modify $\gamma$ using the history accuracy of exploitation rounds and exploration rounds;
    \item set an initial $\gamma$ and a learning rate $\eta$, adaptively update $\gamma$ at each round by either $\gamma=\gamma+\eta$ or $\gamma=\gamma-\eta$, depending on the history performance of exploitation and exploration.
\end{itemize}

Unfortunately, none of these hypotheses consistently outperform the constant-$\gamma$ Banditron. However, we believe that Banditron with various $\gamma$ is still promising because it allows more flexibility than vanilla Banditron and introduces the possibility of automation (the algorithm adaptively updates its $\gamma$). Further research can be done to better study this area and propose working solutions to learn the variable $\gamma$ sequence.

% \section*{Acknowledgements}

% \newpage
% \vphantom{a}
% \newpage
\bibliography{ref}
\bibliographystyle{icml2021}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DELETE THIS PART. DO NOT PLACE CONTENT AFTER THE REFERENCES!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

% This document was modified from the file originally made available by
% Pat Langley and Andrea Danyluk for ICML-2K. This version was created
% by Iain Murray in 2018, and modified by Alexandre Bouchard in
% 2019 and 2021. Previous contributors include Dan Roy, Lise Getoor and Tobias
% Scheffer, which was slightly modified from the 2010 version by
% Thorsten Joachims & Johannes Fuernkranz, slightly modified from the
% 2009 version by Kiri Wagstaff and Sam Roweis's 2008 version, which is
% slightly modified from Prasad Tadepalli's 2007 version which is a
% lightly changed version of the previous year's version by Andrew
% Moore, which was in turn edited from those of Kristian Kersting and
% Codrina Lauth. Alex Smola contributed to the algorithmic style files.


\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{center}
\large{\textbf{Sample Question Paper\\for\\Mathematics using Python}}
\end{center}

\begin{tabular}{p{8cm}r}
\textbf{Duration:3 Hrs} & \textbf{30 weightage}
\end{tabular}\\

\section{Answer all Questions. $4\times 1\frac{1}{2}$}

\begin{enumerate}
\item What are the main document classes supported by LaTeX.
\item Typeset $\sin^{2}x+\cos^{2}x=1$ using LaTeX.
\item Plot a circle using the polar() function.
\item Write code to print all perfect cubes upto 2000.
\end{enumerate}

\section{Answer any two Questions. $3\times 5$}

\begin{enumerate}
\item Set a sample question paper using LaTeX.
\item Write a Python function to calculate the GCD of two numbers
\item Write a program with a Canvas and a circle drawn on it.
\end{enumerate}

\begin{center}\text{End}\end{center}

\end{document}


\renewcommand{\lsql}[1]{\lstinline[language=SQL,prebreak=]!#1!}

\lab{SQL 2 (The SQL Sequel)}{Advanced SQL}
\objective{Learn more of the advanced and specialized features of SQL.}
\label{lab:advancedsql}

\section*{Database Normalization}
Normalizing a database is the process of organizing tables and columns to minimize the amount of redundant information in the database.
For example, a non-normalized database might have a table that stores customer contact information and a table that contains all of the products a company has sold.
However, they might want to track who buys what products in case they need to contact them later. To do so, they store all the contact information of a particular buyer along with every item they purchased.
Now, two tables store the customer contact information.
If we needed to update a customer's phone number, we have to update two tables.
While that may not be bad for small databases, larger databases would be near impossible to update correctly.
The idea of normalizing a database allows us to store all customer contact information in one place in the database.
All other tables that might need a customer's name, phone number, or address would reference the contact information table.
When an update needs to be performed, we only need to update the contact information table.
Then any table that references this information is also automatically up to date.

To properly normalize a database, we need to discuss the types of relations tables might have.
\subsection*{One to One}
This is the simplest relation to model.
A single table can be used to express this relation.
The relation is between one record and at most one other record.
An example of this relationship is an employee and their organization.
One employee works at one organization.
Another example would be that a driver's license belongs to only one person.

\subsection*{One to Many}
This relationship and its inverse must be modeled with at least two tables.
The general approach is to use a unique ID.
Note that a relationship that appears one to one may actually be a one to many relationship.
Many people will, therefore, use the same unique ID approach on one to one relationships too in the case it turns out to be a one to many relationship.
An example of a one to many relationship would be between an department and its employees.
The department would receive a unique ID and then each employee in that department would be tagged with that ID.

\subsection*{Many to Many}
This relationship requires at least three tables.
A many to many relationship can be visualized as two, separate one to many relationships.
The records in each of the two tables receive a unique ID.
A third table then serves as a map between IDs of table to IDs of the other table.
An example of a many to many relationship is doctors and patients.
One doctor can have several patients and one patient can have several doctors.

For the rest of the lab, we will be using the following tables: \ref{table:students}, \ref{table:majors}, \ref{table:grades}, and \ref{table:classes}.

\begin{table}
\begin{tabular}{|l|l|l|l|}
\hline
StudentID & Name & MajorCode & MinorCode \\
\hline
401767594 & Michelle Fernandez & 1 & NULL \\
678665086 & Gilbert Chapman & NULL & NULL\\
553725811 & Roberta Cook & 2 & 1\\
886308195 & Rene Cross & 3 & 1\\
103066521 & Cameron Kim & 4 & 2\\
821568627 & Mercedes Hall & NULL & 3 \\
206208438 & Kristopher Tran & 2 & 4\\
341324754 & Cassandra Holland & 1 & NULL\\
262019426 & Alfonso Phelps & NULL & NULL\\
622665098 & Sammy Burke & 2 & 3 \\
\hline
\end{tabular}
\caption{students}
\label{table:students}
\end{table}

\begin{table}
\begin{tabular}{|l|l|}
\hline
ID & Name \\
\hline
1 & Math \\
2 & Science \\
3 & Writing \\
4 & Art \\
\hline
\end{tabular}
\caption{fields}
\label{table:majors}
\end{table}

\begin{table}
\begin{tabular}{|l|l|l|}
\hline
StudentID & ClassID & Grade \\
\hline
401767594 & 4 & C \\
401767594 & 3 & B- \\
678665086 & 4 & NULL \\
678665086 & 3 & A+ \\
553725811 & 2 & C \\
678665086 & 1 & NULL \\
886308195 & 1 & A \\
103066521 & 2 & C \\
103066521 & 3 & C- \\
821568627 & 4 & D \\
821568627 & 2 & NULL \\
821568627 & 1 & B \\
206208438 & 2 & A \\
206208438 & 1 & C+ \\
341324754 & 2 & D- \\
341324754 & 1 & NULL \\
103066521 & 4 & A \\
262019426 & 2 & B \\
262019426 & 3 & NULL \\
622665098 & 1 & A \\
622665098 & 2 & A- \\
\hline
\end{tabular}
\caption{grades}
\label{table:grades}
\end{table}

\begin{table}
\begin{tabular}{|l|l|}
\hline
ClassID & Name \\
\hline
1 & Calculus \\
2 & English \\
3 & Pottery \\
4 & History \\
\hline
\end{tabular}
\caption{classes}
\label{table:classes}
\end{table}

\begin{problem}
Classify the relations between the various records in these tables: \ref{table:students}, \ref{table:majors}, \ref{table:grades}, and \ref{table:classes}.

Classify each relation as either one to one, one to many, or many to many.
Identify the tables used in each relationship.
\label{prob:tablerelations}
\end{problem}

\begin{info}
There are instances where you would not want a completely normalized database.
Whether to normalize your database depends on your specific needs.
Usually, though, the decision to denormalize a database is a last-resort attempt to improve performance.
\end{info}

\section*{Joining Tables}
We can use SQL to join two or more tables together for a query.
This is a very powerful tool.
SQLite supports three types of standard table joins.

Joining tables is a common practice to collect data from different parts of the database into a single table.
Joins are absolutely essential in a normalized database since data is split between multiple tables.

\subsection*{Inner Join}
This is often the default join operation in SQL.
An inner join can be depicted as an intersection of two or more tables.
\begin{figure}
\centering
\includegraphics[width=.5\textwidth]{inner_join.pdf}
\caption{An inner joining of tables A, B, and C.}
\label{fig:inner_join}
\end{figure}
When performing an inner join on tables, the result will only be those records that match across all tables.
For example, this join will select all the students' names along with their major as long as the students.majorcode matches the majors.id.
If the students.majorcode is missing or null, then they won't be selected.
\begin{lstlisting}[language=SQL]
SELECT students.name, majors.name FROM students JOIN majors ON students.majorcode=majors.id;
\end{lstlisting}
An inner join is equivalent to the following pseudo-loop in Python
\begin{lstlisting}
for row_s in students:
    for row_m in majors:
        if predicates(row_s, row_m):
            yield columns(row_s, row_m)
\end{lstlisting}

\begin{table}
\begin{tabular}{|l|l|}
\hline
students.name & majors.name \\
\hline
Michelle Fernandez & Math \\
Roberta Cook & Science \\
Rene Cross & Writing \\
Cameron Kim & Art \\
Kristopher Tran & Science \\
Cassandra Holland & Math \\
Sammy Burke & Science \\
\hline
\end{tabular}
\caption{An inner join of students and majors}
\label{table:ij_studentsmajors}
\end{table}

\subsection*{Left Outer Join}
A left outer join will return all relations from the left table even if they don't match any relation on the joined tables.
An illustration of a left outer join is given in figure \ref{fig:left_outer}.
\begin{figure}
\centering
\includegraphics[width=.5\textwidth]{left_outer.pdf}
\caption{A left outer table join of A with tables B and C.}
\label{fig:left_outer}
\end{figure}

A Pythonesque loop that illustrates how to perform a left outer join is
\begin{lstlisting}
for row_s in students:
    for row_m in majors:
        if predicates(row_s, row_m):
            yield columns(row_s, row_m)
        else:
            yield columns(row_s)
\end{lstlisting}

The following left outer join will result in the table shown in table \ref{table:lo_studentsmajors}.
\begin{lstlisting}[language=SQL]
SELECT students.name, majors.name FROM students LEFT OUTER JOIN majors ON students.majorcode=majors.id;
\end{lstlisting}
\begin{table}
\begin{tabular}{|l|l|}
\hline
students.name & majors.name \\
\hline
Michelle Fernandez & Math \\
Gilbert Chapman & None \\
Roberta Cook & Science \\
Rene Cross & Writing \\
Cameron Kim & Art \\
Mercedes Hall & None \\
Kristopher Tran & Science \\
Cassandra Holland & Math \\
Alfonso Phelps & None \\
Sammy Burke & Science \\
\hline
\end{tabular}
\caption{A left outer join of students and majors}
\label{table:lo_studentsmajors}
\end{table}

\subsection*{Cross Join}
Essentially a Cartesian product of tables.
Care must be taken when using cross join because of the size of the joined table.
A cross join should only be used on small tables.
It matches each relation in one table with every other possible combination of relations in the joined tables.
For example, if you were to run a cross join on the above join.  You would get every student matched with every major.
This doesn't really make much sense but can be useful for other applications.
Use with caution.

\section*{Advanced Selections}
Aggregate functions are useful for summarizing the data in a column.
The functions can be found in \ref{table:aggregations}.
\begin{table}
\begin{tabular}{|l|l|}
\hline
Function & Description \\
\hline
MIN() & Retrieve the smallest numeric value of a column \\
MAX()& Retrieve the largest numeric value of a column \\
SUM() & Sum the numeric values of a column \\
AVG() & Retrieve the average numeric value of the column \\
COUNT() & Retrieve the total number of matching records in a column \\
\hline
\end{tabular}
\caption{SQL aggregation functions}
\label{table:aggregations}
\end{table}

We can count the number of students by executing the following SQL statement.
\begin{lstlisting}[language=SQL]
SELECT COUNT(*) FROM students;
\end{lstlisting}

\subsection*{Ordering and Grouping Relations}
The \lsql{ORDER BY} keyword can be used to sort the result set by columns.
We can sort in ascending order or descending order.
\begin{lstlisting}[language=SQL]
SELECT name FROM students ORDER BY name ASC;
SELECT name FROM students ORDER BY name DESC;
\end{lstlisting}

Another useful SQL keyword is the \lsql{GROUP BY} keyword.
It is used along with an aggregating function to group the result set by columns.
\begin{lstlisting}[language=SQL]
SELECT grade, COUNT(studentid) FROM grades GROUP BY grade;
\end{lstlisting}
The result set is given in table \ref{table:group_by_grade}.
\begin{table}
\begin{tabular}{|l|l|}
\hline
grade & COUNT(studentid) \\
\hline
None & 5 \\
A & 4 \\
A+ & 1 \\
A- & 1 \\
B & 2 \\
B- & 1 \\
C & 3 \\
C+ & 1 \\
C- & 1 \\
D & 1 \\
D- & 1 \\
\hline
\end{tabular}
\caption{Grouping of students by grade.}
\label{table:group_by_grade}
\end{table}

\begin{problem}
Create a database containing tables \ref{table:students}, \ref{table:majors}, \ref{table:grades}, and \ref{table:classes}.
Write a SQL query to count how many students belong to each major, including students that don't have a major.
Sort your results in ascending order by name.
Your result set should be table \ref{table:grouporder}
\begin{table}[H]
\begin{tabular}{|l|l|}
\hline
None & 3 \\
Art & 1 \\
Math & 2 \\
Science & 3 \\
Writing & 1 \\
\hline
\end{tabular}
\caption{Result set}
\label{table:grouporder}
\end{table}
\label{prob:studentmajors}
\end{problem}

Another important keyword is the \lsql{HAVING} keyword.
This is necessary because the \lsql{WHERE} clause does not support aggregate functions.
A \lsql{HAVING} clause requires a \lsql{GROUP BY} clause.
The following will not work.
\begin{lstlisting}[language=SQL]
SELECT grade FROM grades GROUP BY grade WHERE COUNT(*)=1;
\end{lstlisting}
Since \lsql{COUNT} is an aggregating function, the following is required.
\begin{lstlisting}[language=SQL]
SELECT grade FROM grades GROUP BY grade HAVING COUNT(*)=1;
\end{lstlisting}
This SQL query returns all the grades that occur only once in the table.
A simple way to remember the difference is \emph{\lsql{WHERE} operates on individual records and \lsql{HAVING} operates on groups of records}.

\begin{problem}
Select all the students who have received grades (non-null grades) in more than two classes.  How many grades did he receive?
\label{prob:manygrades}
\end{problem}

\subsection*{Case Expression}
A case expression allows you to temporarily modify records from a select operation.
There are two forms of the case expression; simple and searched.
The simple form of the expression is a match and replace on a specified column.
A simple case expression is demonstrated below.
This code will return the name of the student along with their majorcode.
But instead of integers, the names of the majors will be returned.
\begin{lstlisting}[language=SQL]
SELECT name,
CASE majorcode
    WHEN 1 THEN 'Math'
    WHEN 2 THEN 'Science'
    WHEN 3 THEN 'Writing'
    WHEN 4 THEN 'Art'
    ELSE 'Undeclared'
    END AS major
FROM students;
\end{lstlisting}

A searched case expression using a boolean expression for the \lsql{WHEN} clauses.
\begin{lstlisting}[language=SQL]
SELECT name,
CASE
    WHEN majorcode IS NULL THEN 'Undeclared'
    ELSE majorcode
    END AS major,
CASE
    WHEN minorcode IS NULL THEN 'Undeclared'
    ELSE minorcode
    END AS minor
FROM students;
\end{lstlisting}

\begin{problem}
Find the overall GPA of all the students in the school.
Use a regular 4.0 scale (A=4.0, B=3.0, C=2.0, D=1.0).
Any pluses or minuses are dropped so an A- becomes an A.

Your result set should be one column and one row with average of all GPAs of all the students taking classes.
Your solution should return a single floating point number.

Use the \lsql{ROUND()} function in SQL to round your result to the nearest hundredth.
\label{prob:studentGPA}
\end{problem}

\subsection*{Like Command}
The SQL keyword, \lsql{LIKE}, allows us to match patterns in a column.
For example,
\begin{lstlisting}[language=SQL]
SELECT name, studentid FROM students WHERE studentid LIKE '\%4';
\end{lstlisting}
will return all the students that have a student ID that ends with the digit 4.
Use `\textbackslash\%' before the `4' to signify that there can be any number of characters before the `4.'
If you only want one character, you can use an underscore.
For example, if you were to search a database of words in the english dictionary and you entered the following command:
\begin{lstlisting}[language=SQL]
SELECT word FROM englishDictionary WHERE word LIKE 'i_';
\end{lstlisting}
You would get words like `is,' `it,' or `in.'

\begin{problem}
Write a SQL statement that will find all students with a last name that begins with the letter `C' and return their names and majors.  Your returned records should be
\begin{table}[H]
\begin{tabular}{|l|l|}
\hline
Gilbert Chapman & None \\
Roberta Cook & Science \\
Rene Cross & Writing \\
\hline
\end{tabular}
\label{table:likec_solution}
\end{table}
\label{prob:likec}
\end{problem}

\let\undefined\lsql


%% modified for BE3M33UI at FEL CVUT
%% bare_jrnl.tex
%% V1.2
%% 2002/11/18
%% by Michael Shell
%% mshell@ece.gatech.edu
\documentclass[journal]{IEEEtran}
\usepackage{graphicx}

\begin{document}
%
% paper title
\title{B(E)3M33UI\\ Semestral project 1:\\Spam filter}
\author{Sinchiguano Cesar}

\markboth{SEMESTRAL WORK, COURSE BE3M33UI, CZECH TECHNICAL UNIVERSITY IN PRAGUE, 20018/19}{Shell \MakeLowercase{\textit{et al.}}: Bare Demo of IEEEtran.cls for Journals}
\maketitle

%done
\begin{abstract}
This paper explores and identifies the use of four different learning algorithms (Logistic Regression classifier, AdaBoost classifier, Random Forest classifier and Naive Bayesian Classifier) for classifying spam messages(spam filtering) from a data set. A comparative analysis of the algorithms has also been presented and it will showcase that simple AdaBoost classifier taking from the ensemble models, could
be efficient for the dataset which could be classified as binary tree.
\end{abstract}

%done
\section{Assignment}
The goal of this semestral task is to employ the knowledge of the ML lectures and previous exercises, and apply it to a text classification task, namely called spam filtering. A dataset with text
messages and their classification as spam or ham is provided, in addition to a skeleton code where it shows the use of a dummy classifier as the starting point.

\section{Introduction}

The classification algorithms such as Logistic Regression classifier, AdaBoost classifier, Random Forest classifier and Naive Bayesian Classifier are currently used in various datasets and
showing a good classification result.

In this paper, the four algorithms already mentioned above are proposed as anti-spam filtering methods to compare their performances. For each algorithm, we develop it by adjusting some parameters better-called hyper-parameters to achieve its best possible predicted result with the use of Grid-search method.
Grid-search is a way to select the best of a family of models, parametrized by a grid of parameters.

As to the data set. It was already divided into training and testing
sets. The way as it was dividing our data set is called cross-validation. And it is a good one approach in order to avoid the overfitting state. We then trained each one of the algorithms using the training set, and as for the last step, we proceeded to evaluate their performances on the testing set.
For the sake of the working algorithm, the training and testing sets had to be expressed as a vector. The dimensions in the vector are corresponding
to the word frequency existing in the document. To achieve that, we used the CountVectorizer method as the previous step to the training one. The CountVectorizer method converts from a text document to a matrix of token counts. The resulting matrix is composed of a number of each word appears in the text document. Therefore, we transformed our given inputs of a text domain into a numerical domain which can be treated as task classification using each on of the classification methods.

%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
\begin{enumerate}
\item \textbf{Logistic Regression classifier}

Given a set of inputs X, we want to assign them to one of two possible categories (spam or ham). Logistic regression models the probability that each input belongs to a particular category. A function takes inputs and returns outputs. To generate probabilities, logistic regression uses a function that gives outputs between 0 and 1 for all values of X. There are many functions that meet this description, but the used in this case is the logistic function (sigmoid).

\begin{figure}[!h]
\begin{center}
\includegraphics[width=2in]{fig2.png}
%\includegraphics[width=2in]{figure.eps} %to texify use eps
\caption{An example of logistic regression. \cite{temp1}}
\end{center}\label{fig:mypicture}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
\item \textbf{AdaBoost classifier}

AdaBoost can be used to boost the performance of any machine learning algorithm. It is best used with weak learners. These are models that achieve accuracy just above random chance on a classification problem.

The most suited and therefore most common algorithm used with AdaBoost are decision trees with one level. Because these trees are so short and only contain one decision for classification, they are often called decision stumps.

Each instance in the training dataset is weighted. The initial weight is set to:

$$weight(x_i) = \frac{1}{n}$$

Where $x_{i}$ is the i’th training instance and n is the number of training instances.

%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
\item \textbf{Random Forest classifier}

The random forest is another ensemble approach we used in this paper. The random-forest algorithm brings extra randomness into the model, when it is growing the trees. Instead of searching for the best feature while splitting a node, it searches for the best feature among a random subset of features. This process creates a wide diversity, which generally results in a better model.

\begin{figure}[!h]
\begin{center}
\includegraphics[width=2in]{fig3.png}
%\includegraphics[width=2in]{figure.eps} %to texify use eps
\caption{An example of random forest with two trees. \cite{temp2}}
\end{center}\label{fig:mypicture}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
\item \textbf{Naive Bayesian (NB) Classifier}

Naive Bayesian algorithm is one of the frequently used
machine learning methods for text categorization. The original idea of identifying whether an email is spam or ham looking at which words are found in the message and
which words are absent from it. This approach begins by
studying the content of a large collection of emails which
have already been classified as spam or ham email.
Then when a new email comes into some user's mailbox,
the information obtained from the training set is used to
compute the probability that the email is spam or ham from
the words in the email.
Given a feature vector $ x =\{ x_{1},..., x_{n}\} $ where are the values of attributes $X_1 , . . ., X_n$ , and n is the number of attributes in the corpus.
Let C denote the category to be predicted, i.e., $C \in \{spam,ham\}$. It uses a
discriminate function to compute the conditional probabilities of $P(C_i|X)$. Here, given the inputs, $P(C_i|X)$ denotes the probability that, example X belongs to class $C_i$ :
$$P(C_i|X)=\frac{P(C_i)*P(X|C_i)}{P(X)}$$
$P(C_i )$ is the probability of observing class i. $P(X|C_i )$ denotes
the probability of observing the example, given class $C_{i}$.
$P(X)$ is the probability of the input, which is independent
of the classes.
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Methodology}
%done
\begin{enumerate}
%\item Automatic tuning via grid search\\
\item \textbf{Automatic tuning via grid search}\\
All algorithms implemented have hyper-parameters. A hyperparameter is a parameter whose value is set before the learning process begins. By contrast, the values of other parameters are derived via training. When using any type of the classifier described above, default parameters are taking into account. However, these default parameters often times are not the right choice for optimal prediction of the algorithm. So that, we were obliged to change most of them, or at least the most important, those who can be suitable for the spam filtering task.
There are two ways to do so, one of them can be done by hand, which can be a time-consuming task, the other alternative is to do it through an optimizer better known in Machine learning world as grid search where the algorithm is optimized by cross-validation based on a scoring function. The performance of the selected hyper-parameters and trained model is then measured on a dedicated evaluation set that was not used during the model selection step.
%not
%\item Model diagnostics
\item \textbf{Model diagnostics}

The modified accuracy macc is used to measure the quality of the several algorithms for the spam filtering task on a certain dataset. In addition to additional model evaluations such as Receiver operating characteristic (ROC) and AUC (which stands for Area under the curve) are discussed in order to better understand which spam filtering is performing well or not.

\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
%working on
\section{Experiments}

In this section, the four classification algorithms are evaluated the effects based on different hyper-parameters and also different feature sizes in order to find the optimal model for spam filtering. Afterward, the  performance of the spam filtering is measured in terms of accuracy. It means that each one of the filters is evaluated using a modified accuracy score which is already implemented in the supplied filter.py module as the function called $modified_{\_}accuracy$ which uses the confusion matrix feature to compute TP, FP, TN, FN.

$$macc=\frac{n_{TP}+n_{TN}}{n_{TP}+n_{TN}+10*n_{FP}+n_{FN}}$$

The algorithms described in the instroduction part, were carefully selected, not before a thorough research in many related jobs those who were done many years ago. Even so, in order to get a better and wide insight into the performance of each one of the models, we proceeded to run them with their default values, the results are shown in the Table \ref{modifiedaccuracy}.

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|}
\hline
Classifier & Accuracy score\\
\hline
Logistic regression & 70.75 \%\\
\hline
Adaboost & 70.75 \%\\
\hline
Random Forest & 64.39 \%\\
\hline
Naive Bayesian & 78.78 \% \\
\hline
\end{tabular}

\caption{Test accuracy of different classifiers with standard parameter-settings}
\label{modifiedaccuracy}
\end{table}

Table \ref{modifiedaccuracy} shows good performances for a Logistic regression, Adaboost and Naive Bayesian. On the contrary, Random forest performed badly as spam filtering, with that we confirmed the criterion of many researchers that Random Forest is not suitable for filtering spam messages and also that Naive Bayesian is more acute for the task. From now on, Random Forest classifier is irrelevant for a deeply study. Therefore, it is not dicussed anymore.

Considering as a first experiment the one we did above, running our model with default parameter, then we proceeded as a second experiment to run each model with the use an optimizer called grid search in order to find the best hyper-parameters for itself.

%in process
\begin{enumerate}

\item Logistic Regression classifier
\begin{enumerate}
\item Grid Search\\
We came out with four parameters: penalty, c, and class weight as parameters for the logistic regression classifier and $ngram_{\_}range$ as the only one parameter for the count vectorizer method. The reason to work with these exclusive parameters is that they are relevant in order to get a good result. We could use as many parameters as we wanted but the more we use them, the more time-consuming would be for the optimizer to find the best match. But it can be done if we could have worked with GPU which is suitable due to its high speed in processing data.

\item Filter Evaluation\\
As we already mentioned in the methodology part, the filter is evaluated using the modified accuracy score. The results are shown in the Table \ref{temp0}

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|c|}
\hline
$ Data$ & Default values & Tuned values\\
\hline
Training & 1.0 & 0.99167\\
\hline
Testing & 0.7076 & 0.8571\\
\hline
\end{tabular}
\caption{Accuracy score}
\label{temp0}
\end{table}
Table \ref{temp0} shows clearly that there is a significant improvement in the performance of the model. The table shows both scores, the one with default parameters and the other with the parameters found by the optimizer.

\item Best parameters

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|}
\hline
$class_{\_}weight$ &  balanced\\
\hline
penalty & l2\\
\hline
$c$ & 0.1 \\
\hline
$ngram_{\_}range$ & (1, 3) \\
\hline
\end{tabular}
\caption{Hyper-parameters}
\label{temp2}
\end{table}
Table \ref{temp2} shows the final value of the hyper-parameters, those who were encounter by the grid search method.

\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item AdaBoost classifier

\begin{enumerate}
\item Grid Search\\
We came out with two parameters: $n_{\_}estimator$ for the AdaBoost classifier and $ngram_{\_}range$ as a parameter for the count vectorizer method.

\item Filter Evaluation\\
As we already mentioned in the methodology part, the filter is evaluated using the modified accuracy score. The results are shown in the Table \ref{temp0}

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|c|}
\hline
$ Data$ & Default values & Tuned values\\
\hline
Training & 1.0 & 0.99167\\
\hline
Testing & 0.7075 & 0.83333\\
\hline
\end{tabular}
\caption{Accuracy score}
\label{temp0}
\end{table}
Table \ref{temp0} shows significant improvement in the perfomance of the model. The table also shows both scores, the one with default parameters and the other with the parameter found by the optimizer.

\item Best parameters

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|}
\hline
$n_{\_}estimator$ & 30\\
\hline
$ngram_{\_}range$ & (1, 2) \\
\hline
\end{tabular}
\caption{Hyper-parameters}
\label{temp3}
\end{table}
Table \ref{temp3} shows the final value of the hyper-parameters, those who were encounter by the grid search method.
\end{enumerate}

%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
\item Naive Bayesian Classifier\\
We select the MultinomialNB, which is one of the two classic naive Bayes variants used in text classification.

\begin{enumerate}
\item Grid Search\\
We came out with two parameters: alpha for Naive Bayesian classifier and $ngram_{\_}range$ as a parameter for the count vectorizer method.
The alpha determines how much the data should be smoothed and the $ngram_{\_}range$ decides between the following options: unigrams and $bi-grams$ in the model, in order to capture important information involving multiple tokens.

\item Filter Evaluation\\
As we already mentioned in the methodology part, the filter is evaluated using the modified accuracy score. The results are shown in the Table \ref{temp0}

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|c|}
\hline
$ Data$ & Default values & Tuned values\\
\hline
Training & 1.0 & 0.99167\\
\hline
Testing & 0.7878 & 0.7988\\
\hline
\end{tabular}
\caption{Accuracy score}
\label{temp0}
\end{table}
Table \ref{temp0} shows slightly improvement. It was expected to work well enough for this kind of task due to its usage in many task related to spam filtering.

\item Best parameters

\begin{table}[ht]
\renewcommand{\arraystretch}{1.3}
\centering
\begin{tabular}{|c|c|}
\hline
$n_{\_}estimator$ & 30\\
\hline
$ngram_{\_}range$ & (1, 2) \\
\hline
\end{tabular}
\caption{Hyper-parameters}
\label{temp5}
\end{table}
Table \ref{temp5} shows the final values of the hyper-parameters, those who were encounter by the grid search method.
\end{enumerate}
\end{enumerate}

%%%%%%%%%%%%%
%%%%%%%%%%%%%

\section{Discussion}

After the two experiments we did try on each one of the models. We are not able to tell which one should be selected, but it is clearly so far that logistic regression classifier performed well compare to the Adaboost classifier and the Naive Bayesian classifier. In order to take the final decision, we plot a Receiver operating characteristic curve better called ROC curve and we show the Area under the curve better known as AUC for each one of them.

\begin{enumerate}
\item Receiver Operating Characteristic curve\\
In order to choose the optimal model, we have to look carefully which curve is closer to the upper left corner of the fig. 3 and simultaneously we have to see which one is with the less false positive rate. And finally, we came out with the solution that the logistic regression is the one who meets the requirements. In Figure \ref{fig:mypicture}, we can also see the values of the area under the curve for each model in order to better confirm the selected model(logistic regression) as final spam filtering.

\begin{figure}[!h]
\begin{center}
\includegraphics[width=2in]{roc.png}
%\includegraphics[width=2in]{figure.eps} %to texify use eps
\caption{Receiver Operating Characteristic curve (ROC curve)}
\end{center}
\label{fig:mypic}
\end{figure}
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Conclusion}

In this paper, we propose four machine learning methods for spam filtering and present an empirical evaluation for them on data corpus given to us. These approaches include Logistic Regression classifier, AdaBoost classifier, Random Forest classifier and Naive Bayesian Classifier. The only one experiment, is carried out to test the performances of these algorithms by changing the values of the hyper-parameters with the use of an optimizer (grid search). Experimental results show that Random Forest classifier is more sensitive to the training set size and unsuitable for using as a spam filtering. Generally, the performances of the Logistic regression classifier and Naive Bayesian classifier are less influenced by data sets, and slightly superior to the AdaBoost classifier. Hence, we selected the logistic regression classifier as the final spam filtering. We also choose this one because it shows higher AUC which is also realted to the accuracy.

\begin{thebibliography}{1}
\bibitem{temp1}
https://gab41.lab41.org/the-10-algorithms-machine-learning-engineers-need-to-know-f4bb63f5b2fa
\bibitem{temp2}
https://towardsdatascience.com/the-random-forest-algorithm-d457d499ffcd
\end{thebibliography}

\end{document}


\section{Recursion}

% \begin{frame}
%   \frametitle{Housekeeping}
%   \begin{itemize}[<+->]
%   \item Explain: ``if $\tyjudge{}{e}{\tau}$ and $\jtrans{e}{e'}$, then $\tyjudge{}{e'}{\tau}$''.
%     \begin{itemize}
%     \item If $e$ is well-typed and $e$ reduces to $e'$, then $e'$ is
%       also well-typed (and both $e$ and $e'$ have the same type).
%     \item This statement is also called \emph{type preservation} (cf.\ type safety,  slide~\ref{fr:ty-safety}).
%     \end{itemize}
%   \item Whiteboard pictures on Moodle $\implies$ ask on Piazza.
%   \item \LaTeX\ in the lectures $\implies$ too risky!
%   \end{itemize}
% \end{frame}

\begin{frame}
  \frametitle{Introduction}

  \begin{center}
    {\large
      What is the \emph{expressive power} of the languages we have studied so far?
    }
  \end{center}

  \pause

  \bigskip

  \begin{itemize}[<+->]
  \item We can specify the expressivity of a programming language by
    considering the set of computable functions it can represent.
    %
  \item Most programming languages are \emph{universal}, i.e., Turing
    complete (meaning that they can be used to simulate a Turing
    machine).
    %
  \item Hence, expressivity of programming languages is generally
    concerned with questions such as: can construct $C$ in language
    $L$ be simulated in language $L'$?
    %
  \item For more on expressivity of programming languages beyond
    computational power, see, e.g.,
    \emph{``\href{https://www.sciencedirect.com/science/article/pii/016764239190036W}{On
        the expressive power of programming languages}''}, by Matthias
    Felleisen.
  \end{itemize}

\end{frame}

% \note{In particular, what sort of recursive programs (or programs that
%   ``loop'' infinitely) can we write in the languages we have seen thus far?}

\begin{frame}
  \frametitle{Language \lggeT}
  %
  \[
  \begin{array}{llclll}
    \TYPES & \tau & \Coloneqq & \tynat  & \tynat & \text{natural}
    \\
           &&& \tyarr{\tau_1}{\tau_2}  & \tau_1 \rightarrow \tau_2 & \text{function}
    \\
    \\ \pause
    \EXPS & e & \Coloneqq & \var{x} & \var{x} & \text{variable}
    \\
           &&& \ez &  \ez & \text{zero}
    \\
           &&& \esucc{e} &  \esucc{e} & \text{successor}
    \\
           &&& \elam{\tau}{x}{e} & \clam{\tau}{x}{e} & \text{abstraction}
    \\
           &&& \eapp{e_1}{e_2} & \capp{e_1}{e_2} & \text{application}
    \\
           &&& \eiter{e_0}{x}{e_1}{e} & \multicolumn{2}{c}{\citer{e_0}{x}{e_1}{e}}
  \end{array}
  \]

  \pause

  We write $\bnum{3}$ for $\esucc{\esucc{\esucc{\ez}}}$.
\end{frame}

\begin{frame}
  \frametitle{Statics}
  % (same as $\lggeEF$)
  \[
  \tyrule
  {\ttyrulename{var}}
  {\,}
  {\tyjudge{\Gamma_1, \var{x}: \tau, \Gamma_2}{\var{x}}{\tau} }
  \]

  \pause
  \bigskip

  \[
  \tyrule
  {\ttyrulename{nat}}
  {\,}
  {\tyjudge{\Gamma}{\ez}{\tynat}}
  \qquad\qquad\qquad
  \tyrule
  {\ttyrulename{num}}
  {\tyjudge{\Gamma}{{e}}{\tynat{}}}
  {\tyjudge{\Gamma}{\esucc{e}}{\tynat{}}}
  \]
\end{frame}

\begin{frame}
  \frametitle{Statics}

  \[
  \tyrule
  {\ttyrulename{lam}}
  {\tyjudge{\Gamma, \var{x} : \tau_1}{e}{\tau_2}}
  {\tyjudge{\Gamma}{\elam{\tau_1}{x}{e}}{\tyarr{\tau_1}{\tau_2}}}
  \]

  \pause

  \[
  \tyrule
  {\ttyrulename{ap}}
  {
    \tyjudge{\Gamma}{e_1}{\tyarr{\tau_1}{\tau}}
    \and
    \tyjudge{\Gamma}{e_2}{\tau_1}
  }
  {
    \tyjudge{\Gamma}{\eapp{e_1}{e_2}}{\tau}
  }
  \]

  \pause

  \bigskip

  \bigskip

  NB: this rules are the same as for Language $\lggeEF$.
\end{frame}

\begin{frame}
  \frametitle{Statics}
  \[
  \tyrule
  {\ttyrulename{ite}}
  {
    \tyjudge{\Gamma}{e}{\tynat}
    \and
    \tyjudge{\Gamma}{e_0}{\tau}
    \and
    \tyjudge{\Gamma, \var{x} : \tau}{e_1}{\tau}
  }
  {
    \tyjudge{\Gamma}{\eiter{e_0}{x}{e_1}{e}}{\tau}
  }
  \]

  \bigskip

  \pause

  Why do $e_0$ and $e_1$ need to have the same type?

\end{frame}

\begin{frame}
  \frametitle{Dynamics}
  \emph{Eager} semantics:
  \[
  \semrule{\tsemrulename{z}}
  {\,}
  {\valjudge{\ez}}
  \qquad \qquad  \qquad
  \semrule{\tsemrulename{s}}
  {\valjudge{e}}
  {\valjudge{\esucc{e}}}
  \]

  \[
  \semrule
  {\tsemrulename{lam}}
  {\,}
  {\valjudge{\elam{\tau}{x}{e}}}
  \]

\end{frame}

\begin{frame}
  \frametitle{Dynamics}

  % (same as $\lggeEF$)

  \[
  \semrule
  {\tsemrulename{ss}}
  {\jtrans{e}{e'}}
  {
    \jtrans{\esucc{e}}{\esucc{e'}}
  }
  \]

  \[
  \semrule
  {\tsemrulename{ap}}
  {\jtrans{e_1}{e'_1}}
  {
    \jtrans{\eapp{e_1}{e_2}}{\eapp{e'_1}{e_2}}
  }
  \]
\end{frame}

\begin{frame}
  \frametitle{Dynamics}
  %  (same as $\lggeEF$)

  \[
  \semrule
  {\tsemrulename{lan}}
  {\valjudge{e_1}
    \and \jtrans{e_2}{e'_2}
  }
  {\jtrans{\eapp{e_1}{e_2}}{\eapp{e_1}{e'_2}}}
  \]

  \[
  \semrule
  {\tsemrulename{lav}}
  {\valjudge{e_2}}
  {\jtrans{\eapp{\elam{\tau}{x}{e_1}}{e_2}}{\subs{e_1}{e_2}{x}}}
  \]
\end{frame}

\begin{frame}
  \frametitle{Dynamics (iterator)}

  \begin{itemize}[<+->]
  \item Evaluate the parameter
    \[
    \semrule
    {\tsemrulename{rin}}
    {\jtrans{e}{e'}}
    {
      \jtrans{\eiter{e_0}{x}{e_1}{e}}{\eiter{e_0}{x}{e_1}{e'}}
    }
    \]
    %
  \item Case if zero
    \[
    \semrule
    {\tsemrulename{r0}}
    {\,}
    {
      \jtrans{\eiter{e_0}{x}{e_1}{\ez}}{e_0}
    }
    \]
  \item Case if strictly positive
    \[
    \semrule
    {\tsemrulename{rs}}
    {\valjudge{{e}}}
    {
      \jtrans{\eiter{e_0}{x}{e_1}{\esucc{e}}}{\subs{e_1}{{\eiter{e_0}{x}{e_1}{{e}}}}{x}}
    }
    \]
  \end{itemize}

  NB: $\eiter{e_0}{x}{e_1}{e}$ stands for ${\citer{e_0}{x}{e_1}{e}}$
\end{frame}

\begin{frame}
  \frametitle{Alpha equivalence ($\aeq$)}
  \begin{itemize}[<+->]
  \item Two programs are \emph{$\alpha$-equivalent} if they are
    identical up to the choice of \emph{bound} variables.
    %
    \pause
    \[
    \elam{\tynat}{x}{\esucc{\var{x}}} \aeq   \elam{\tynat}{y}{\esucc{\var{y}}}
    \]

    \pause

    \[
    \esucc{\var{x}} \naeq \esucc{\var{y}}
    \]

  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Alpha equivalence ($\aeq$)}
  \begin{itemize}
  \item \emph{Bound} variables can be renamed \emph{consistently}
    without changing the meaning of a program.
    \[
    \begin{array}{c}
      \elam{\tyarr{\tynat}{\tynat}}{x_1}{
      \elam{\tynat}{x_2}{
      \eapp
      {\var{x_1}}
      {\var{x_2}}
      }
      }
      \\
      \pause
      \qquad
      \aeq
      \elam{\tyarr{\tynat}{\tynat}}{y_1}{
      \elam{\tynat}{y_2}{
      \eapp
      {\var{y_1}}
      {\var{y_2}}
      }
      }
      \\
      \pause
      \qquad
      \naeq
      \elam{\tyarr{\tynat}{\tynat}}{y_1}{
      \elam{\tynat}{y_2}{
      \eapp
      {\underline{\var{y_2}}}
      {\underline{\var{y_1}}}
      }
      }
    \end{array}
    \]
    \pause
  \item It's helpful to rename bound variables so that they are all
    \emph{distinct}, e.g.,
    \[
    \begin{array}{c}
      \eapp
      {\elam{\tau}{x}{{\var{x}}}}
      {\elam{\tau'}{x}{\esucc{\var{x}}}}
      \\ \qquad
      \pause
      \aeq
      \eapp
      {\elam{\tau}{x}{{\var{x}}}}
      {\elam{\tau'}{y}{\esucc{\var{y}}}}
    \end{array}
    \]

  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Substitution}
  {\Large
    \[
    \subs{e_1}{e_2}{x}
    \]
  }
  \pause
  \begin{itemize}[<+->]
  \item Substitution is the process of ``plugging in'' an object
    ($e_2$) for the variable ($\var{x}$) in a program ($e_1$).
    %
  \item Only the \emph{free} occurrences of variable $\var{x}$ should
    be replaced!
  \item Example: if
    \[
    e_1 = \eapp{\elam{\tynat}{x}{\esucc{\var{x}}}}{\underline{\var{x}}}
    \]
    \pause
    then
    \[
    \subs{e_1}{\ez}{x} =
    \pause
    \eapp{\elam{\tynat}{x}{\esucc{\var{x}}}}{\ez}
    \]
  \end{itemize}
  %
  \pause
  NB: $ \eapp{\elam{\tynat}{x}{\esucc{\var{x}}}}{\underline{\var{x}}}
  \aeq  \eapp{\elam{\tynat}{y}{\esucc{\var{y}}}}{\underline{\var{x}}} $
\end{frame}

\begin{frame}{Exercises}
  \label{fr:define-t}
  %
  In $\lggeT$, implement the following functions:
  \begin{itemize}[<+->]
  \item Successor ($\tynat{} \rightarrow \tynat$): $\text{succ} \defi \clam{\tynat{}}{x}{{\color{red} ??}}$
  \item Doubling ($\tynat{} \rightarrow \tynat$): {\color{red} ??}
  \item Addition ($\tynat{} \rightarrow \tynat \rightarrow \tynat$):
    $\text{add} \defi \clam{\tynat{}}{x}{\clam{\tynat{}}{y}{ {\color{red} ??} }}$
  \item Multiplication ($\tynat{} \rightarrow \tynat \rightarrow \tynat$): {\color{red} ??}
    %
    %
  \end{itemize}

  % \pause
  % \bigskip

  % Using complex data types (see further chapters):
  % \begin{itemize}
  % \item Predecessor ($\tynat{} \rightarrow \tynat$): {\color{red} ??} (add product types to $\lggeT$)
  % \item Subtraction ($\tynat{} \rightarrow \tynat \rightarrow \tynat$): {\color{red} ??}
  % \end{itemize}
\end{frame}

% Add: \x \y . iter x { z -> y | v -> s(v)}
% Doubling: \x . iter x {z -> z | v -> s(s(v))}
% Multiply: \x \y . iter x {z -> z | v -> add(y,v)}
% Predecessor: \x . pl(iter x {z -> <z,z> | v -> <pr . v, s(pr . v)>})
% Subtraction: \x \y . iter x {z -> y | v -> pred(v)}

% \begin{frame}
%   \frametitle{Housekeeping}
%   \begin{itemize}[<+->]
%   \item What does the following term evaluate to
%     \[
%     \eapp{\elam{\tynat}{x}{\var{x}}}{\esucc{{\var{x}}}}
%     \]
%   \item Is language $\lggeT$ using Peano numbers? Yes, $\lggeT$ is
%     based on Godel's system T (1958), which includes Peano
%     axioms/numbers.
%   \end{itemize}
% \end{frame}
\begin{frame}
  \frametitle{Expressivity of $\lggeT$}
  \begin{itemize}
  \item Language $\lggeT$ provides a mechanism called \emph{primitive
      recursion} (which we used to define arithmetic operations).
    %
  \item Primitive recursion can characterise the \emph{inductive}
    nature of the natural numbers.
    %
  \item In $\lggeT$, we can only define \emph{total recursive
      functions} on the natural numbers (functions that \emph{always} return
    something).
    %
  \item This inductive natures implies that every program comes with a
    proof of its \emph{termination} (we always ``bottom out'' using the
    induction principle).
    %
  \item To obtain Turing completeness, we need a \emph{partial
      recursive} language (where some programs may not terminate).
  \end{itemize}
\end{frame}

% \separator{Examinable material for 2018 \emph{ends} here.}

\begin{frame}
  \frametitle{Y-Combinator}
  An option to express \emph{general recursion}\footnote{i.e.,
    allowing for partial functions.} is to introduce the $Y$
  combinator.

  \bigskip
  Its type is
  \[
  Y : (\tau \rightarrow \tau) \rightarrow \tau
  \]

  \pause

  Additional semantic rule:
  \[
  \semrule
  {\tsemrulename{y}}
  {\,}
  {
    \jtrans{Y f}{ f(Y f)}
  }
  \]

  \pause
  \bigskip

  NB: in the \emph{untyped} lambda-calculus, it can be expressed as
  \[
  Y \defi \lambda f  .\ (\lambda x . f (x \ x))  \ (\lambda x . f (x \ x))
  \]

  Exercise: try to find a type for that term!
\end{frame}

\separator{Examinable material for 2020 ends here.}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:

%  LocalWords:  computable expressivity Examinable