%s How the representative set is computed; pruning strategies and verification
%step goes here.

\section{Computing Representative Sets}
\label{sec:representative}
Representative vertex $v$ of a pattern
vertex $u$ implies that there exists an isomorphism $\phi$ for which $\phi(u) =
v$.  One way to interpret it is that the neighborhood of $u$ matches with that
of $v$.  By comparing the neighborhoods we can find vertices that are not valid
representatives of $u$ without trying to find an isomorphism exhaustively.
Therefore, to compute the representative sets we will start with a candidate
representative set denoted by \CR  and iteratively prune some of the vertices if
the neighborhoods cannot be matched.  The candidate set is a super set of the
representative set, $\CR \supseteq \RS$.  An example of candidate set, $ \CR =
\{v| v \in \vg, \labcost{C}{L(u)}{L(v)} \leq \alpha \}$ i.e., the isomorphisms of
the single vertex pattern with label $L(u)$.  In this section, we will describe
different notions of neighborhood and show how they help us in computing the
representative sets of vertices in a pattern.

The problem of checking whether a vertex $v \in R(u)$ involves solving
isomorphism is atleast as hard finding unlabeled subgraph isomorphism.
Therefore, checking if a vertex is a valid representative is an
NP Hard problem. The pruning methods typically do not
prune all the invalid vertices.  So, we use an exhaustive enumeration method to
prune these invalid vertices and reduce \CR to \RS.

 \subsection{\khop Label}
 \label{sec:khop}
 %Neighbors of a vertex in a graph denotes the set of vertices that are
 %reachable via a single edge.
 \khop label is defined as the set of vertices that are reachable via a simple
 path of length $k$.  In other words, k-hop label contains all vertices that are
 reachable in k-hops starting from $u$ and by visiting each vertex at most once.
 Note that, we use the word label even though we refer to a set of vertices.
 Formally, the \khop label of a vertex $u$ in graph $G$, $\khopl{k}{u,G} = \{v |
 v \in G, \kpath{u}{v}{k}\}$.  We simply write it as $\khopl{k}{u}$ when the
 graph is evident from the context.  For example, for pattern $P$ in
 Fig.~\ref{subfig:pattern}, the $0$-hop label of vertex $5$ is $h_0(5) = \{5\}$,
 its $1$-hop label is the multiset $h_1(5) = 2, 4, 6$ (we omit the set notation
 for convenience) and its $2$-hop label $h_2(5) = 1, 3$. The minimum cost of
 matching \khop labels $\khopl{k}{u}$ and $\khopl{k}{v}$ is

 \begin{equation} \label{eq:khop} \khopcost{k}{u}{v} =
     \text{min}\displaystyle\sum_{u' \in \khopl{k}{u}}
     \labcost{C}{L(u')}{L(f(u'))} \end{equation}

 where the minimization is over all injective functions $f\!\!:\khopl{k}{u}
 \rightarrow \khopl{k}{v}$ and $\labcost{C}{L(u')}{L(f(u'))}$ is the cost of
 matching the vertex labels.  In other words, it is the minimum total cost of
 matching the vertices present in the k-hop labels.  The following theorem
 places an upper bound on the minimum cost of matching the k-hop labels of
 a pattern vertex and any of its representative vertices.

\begin{thm}
\label{thm:khop}
Given any pattern vertex $u$, a representative vertex $v \in R(u)$
    and cost threshold $\alpha$, the minimum cost of matching the \khop labels,
    $\khopcost{k}{u}{v} \leq \alpha$ for all $k \geq 0$.

\begin{myproof} Consider any isomorphism $\phi$ such that $\phi(u) = v$. It is
    enough if we can show an injective function $f\!\!:\khopl{k}{u} \rightarrow
    \khopl{k}{v}$ with a cost ( as defined in equation \ref{eq:khop}) $\leq
    \alpha$. We will argue that the function $\phi$ on the restricted domain
    $\khopl{k}{u}$ is one such function $f$.  First, we know that
    $\sum\labcost{C}{L(u)}{\phi(L(u)} \leq \alpha$, $u \in \vp$, since $\phi$ is
    an isomorphism. Second, let $\kpath{u}{u'}{k}$ then $\phi(u') \in
    \khopl{k}{v}$ because for every edge $(u_1, u_2)$ on a path between $u$ and
    $u'$ in $\pat$, $(\phi(u_1),\phi(u_2)) \in \eg$.  Therefore the cost
    of matching the \khop labels using $\phi$ is  upper bounded by $\alpha$.  Hence,
    the minimum cost of matching $\khopcost{u}{v} \leq \alpha$.
    \end{myproof}
    \label{thm:khop} \end{thm}

Based on the above theorem, a vertex $v$ is not a representative vertex of $u$
if $\khopcost{k}{u}{v} > \alpha$ for any $k \geq 0$. However, in practice, it
enough to check the condition only for $k \leq |V_P|-1$ because $\khopl{k}{u}$
is the null set $\forall k \geq |V_P|$ and the condition is trivially satisfied.

Figure~\ref{fig:ncexample} shows an example for the \khop label based pruning of
the candidate representative set where the threshold $\alpha = 0.5$. Consider
vertex $2 \in \vp$ and vertex $20 \in \vg$, we have, $\khopcost{0}{2}{20} = 0$,
since the cost of matching vertex labels $\labcost{C}{L(2)}{L(20)} = 0$ , as per
the label matching matrix $C$ in Fig.~\ref{subfig:match}. The \khop labels for
$k=1,2,3$ and the minimum of cost matching them are as shown in the table
\ref{tab:khop220}, and it can be verified that the minimum cost is within the
threshold $\alpha$.

Thus far, we cannot prune node $20$ from $R(2)$.  However, $\khopl{4}{2} = 4, 6
$ and $\khopl{4}{20} = 30, 60$ and the minimum cost of matching them is $0.6 >
\alpha$.  Thus, from theorem \ref{thm:khop} we conclude that $20 \notin R(2)$. This example illustrates
that \khop labels can help prune the candidate representative sets.

% Example for showing the incremental updates of the labels
\begin{figure}[!ht]
\captionsetup[subfloat]{captionskip=15pt}
  \centering
  \subfloat[Pattern $P$]{
    \label{subfig:pattern}
	\scalebox{0.9}{
    % # 3 vertices and 2 edge pattern
    \begin{pspicture}(0,0)(4,3)
    \cnodeput[linecolor=black](0,2) {n1} {A}
    \cnodeput[linecolor=black](0,1) {n2} {C}
    \cnodeput[linecolor=black](1,0) {n3} {B}
    \cnodeput[linecolor=black](2,2) {n4} {C}
    \cnodeput[linecolor=black](2,1) {n5} {A}
    \cnodeput[linecolor=black](2,0) {n6} {D}
    %% Draw the edges of the pattern
  \ncline{-}{n1}{n2}
  \ncline{-}{n2}{n3}
  \ncline{-}{n3}{n4}
  \ncline{-}{n2}{n5}
  \ncline{-}{n4}{n5}
  \ncline{-}{n5}{n6}
  \ncline{-}{n3}{n6}
    \uput{.3cm}[90](n1){ {1} }
    \uput{.3cm}[180](n2){ {2} }
    \uput{.3cm}[270](n3){ {3} }
    \uput{.3cm}[90](n4){ {4} }
    \uput{.3cm}[0](n5){ {5} }
    \uput{.3cm}[270](n6){ {6} }
    \end{pspicture}
	} }
  \subfloat[Database Graph $G$]{
    \label{subfig:database}
	\scalebox{0.9}{
    \begin{pspicture}(0,0)(2.5,2.5)
    \cnodeput[linecolor=black](0,2) {N1} {A}
    \cnodeput[linecolor=black](0,1) {N2} {C}
    \cnodeput[linecolor=black](0,0) {N3} {D}
    \cnodeput[linecolor=black](1,2) {N4} {B}
    \cnodeput[linecolor=black](2.25,1) {N5} {B}
    \cnodeput[linecolor=black](2,0) {N6} {A}
    % vertex ids
    \uput{.3cm}[90](N1){ {10} }
    \uput{.3cm}[180](N2){ {20} }
    \uput{.3cm}[270](N3){ {30} }
    \uput{.3cm}[90](N4){ {40} }
    \uput{.3cm}[0](N5){ {50} }
    \uput{.3cm}[270](N6){ {60} }
    % edges in the database
  \ncline{-}{N1}{N2}
  \ncline{-}{N2}{N3}
  \ncline{-}{N4}{N5}
  \ncline{-}{N5}{N6}
  \ncline{-}{N3}{N4}
  \ncline{-}{N2}{N5}
  \ncline{-}{N2}{N6}
    \end{pspicture}
	} }
  \newline
\captionsetup[subfloat]{captionskip=5pt}
\subfloat[Cost Matrix]{
  \label{subfig:match}
  % Table for the search space pruning
  \begin{tabular}{|c|c|c|c|c|}
    \hline
    \costmat{C} & A &  B & C & D \\
    \hline
    A & 0 & 0.7 & 0.6 & 0.1\\
    \hline
    B & 0.7 & 0 & 0.3 & 1\\
    \hline
    C & 0.6 & 0.3 & 0 & 0.8\\
    \hline
    D & 0.1 & 1 & 0.8 & 0\\
    \hline
  \end{tabular}
  }
  \caption{Pattern \protect\subref{subfig:pattern},
  database graph \protect\subref{subfig:database}, and cost
  matrix \protect\subref{subfig:match}.
  }
  \label{fig:ncexample}
\end{figure}

\begin{table}[h]
    \centering
    \begin{tabular}{|c|c|c|c|}
        \hline
        k & $\khopl{k}{2}$ & $\khopl{k}{20}$ & $\khopcost{k}{2}{20}$\\
        \hline
        1 & 1, 3, 5 & 10, 30, 50, 60 & 0 \\
        2 & 4, 6 & 40, 50, 60 & 0.4 \\
        3 & 3, 5 & 40, 30, 50 & 0.1\\
        \hline
    \end{tabular}
    \caption{\khop label of vertices $2$ and $20$}
    \label{tab:khop220}
\end{table}

\begin{table}[h]
    \centering
    \begin{tabular}{|c|c|c|c|}
        \hline
        k & $h_k(3)$ & $h_k(50)$ & $\khopcost{k}{3}{50}$ \\
        \hline
        0 & 3 & 50 & $0$\\
        1 & 2, 4, 6 & 20, 40, 60 & $0.4$ \\
        2 & 1, 5 & 10, 20 , 30, 60 & 0\\
        3 & 2, 4, 6 & 10, 20, 30, 40 & $0.3$ \\
        4 & $1$ & $10, 40, 60$ & $0$ \\
        \hline
    \end{tabular}
    \caption{\khop labels of vertices $3$ and $50$.}
    \label{tab:khop350}
\end{table}

\subsection{Neighbor Concatenated Label} In Neighbor concatenated label (\ncl) ,
the information regarding the candidates of a neighbor that were pruned in the
previous iteration is used along with the current \khop label to prune
candidates in the current iteration. In contrast, the \khop label pruning
strategy for a vertex $u$ works independently of the result of \khop label
pruning of other vertices in the pattern. This leads us to the following
recursive formulation for \ncl.

The \ncl of a vertex in the ${k+1}^{th}$ iteration, $\nclab{k+1}{u}$, is defined
as the tuple $(\{\nclab{k}{u'} | u' \in N(u)\},\xspace \khopl{k+1}{u})$.  The
first element(A) of the tuple is the set of \ncl of the neighbors of the vertex $u$ in
the previous iteration($k$) and the second element(B) is exactly same as the (k+1)-hop
label defined in the section \ref{sec:khop}. We say that $\nclab{k+1}{u}$ dominated by
$\nclab{k+1}{v}$, denoted by $\nclab{k+1}{u} = (A, B) \preceq \nclab{k+1}{v} =
(A', B') $, i) iff $\khopcost{k+1}{B}{B'} \leq \alpha$ i.e., the minimum cost of
matching the (k+1)-hop labels is within $\alpha$ ii) there exits an injective
function $g\!\!:A\rightarrow A'$ such that $a \preceq g(a)$ for all $a \in A$
i.e., there is a one to one mapping between the \ncl labels (of the previous
iteration, $k$) of neighbors of $u$ and $v$.  The base case $\nclab{0}{u}
\preceq \nclab{0}{v}$ iff $\labcost{C}{L(u)}{L(v)} \leq \alpha$. For example, in
Fig~\ref{fig:ncexample} $\nclab{1}{2} \preceq \nclab{1}{20}$ because
$\khopcost{1}{2}{20} \leq \alpha$ and the \ncl labels of vertices $1, 3, 5$ are
dominated by the \ncl labels of vertices $10, 50, 30$ respectively.  The
following theorem states that the \ncl of a pattern vertex $u$ is dominated by
the \ncl of any of its representative vertex $v \in  R(u)$.

\begin{thm} Given any pattern vertex $u$, a representative vertex $v \in R(u)$
    and cost threshold $\alpha$, $\nclab{k}{u} \preceq \nclab{k}{v}$ for all $k
    \geq 0$.  \begin{myproof} Let $\phi$ be any isomorphism such that $\phi(u) =
        v$.  We prove the theorem by using induction on $k$.\\ \textbf{Base
        case:} $\nclab{0}{u} \preceq \nclab{0}{v} \iff \labcost{C}{L(u)}{L(v)}
        \leq \alpha$ is true because $v \in R(u)$. \\ \textbf{Inductive
        Hypothesis:} Assume that $\nclab{k}{u} \preceq \nclab{k}{v}$ holds true
        for all $u \in \pat$ and $v \in R(u)$. \\ Now consider $\nclab{k+1}{u} =
        (A, B)$  and $ \nclab{k+1}{v} = (A', B') $, from theorem \ref{thm:khop}
        we know that $\mathcal{C}[B][B'] \leq \alpha$, for all $k \geq 0$.
        Let $u' \in N(u)$ and $v' = \phi(u')$. From inductive hypothesis,
	$\nclab{k}{u'} \preceq \nclab{k}{v'}$. Also, $v' \in N(v)$ because
	$(u, u') \in \ep \implies (\phi(u)=v, \phi(u')=v') \in \eg$.
        Therefore,
        the injective function $\phi$ maps the elements $a \in A$ to $\phi(a)
        \in A'$.  The theorem follows from the definition of the NL label.
    \end{myproof} \label{thm:ncl} \end{thm}

Based on the above theorem, a vertex $v$ can be pruned from \CR if $\nclab{k}{u}
\not\preceq \nclab{k}{v}$ for some $k \geq 0$. In Fig~\ref{fig:ncexample} ,
consider the vertices $3 \in \pat$ , $50 \in \db$ and let $\alpha = 0.5$. The
\ncl labels, $\nclab{0}{3} \preceq \nclab{0}{50}$ as $\labcost{C}{B}{B} = 0 \leq
\alpha$.  Similarly it is also true for the pairs $(2, 20)$, $(4, 40)$ etc. It
follows that $\nclab{1}{3} \preceq \nclab{1}{50}$ as the neighbors $2, 4, 6$ can
be mapped to $20, 40, 60$ respectively and  the minimum cost of the matching the
$1$-hop label is $0.4$ which is less than the $\alpha$ threshold. But
$\nclab{2}{3} \not\preceq \nclab{2}{50}$ because the \ncl label $\nclab{1}{6}$
is not dominated by the \ncl label of $20, 40$ or  $60$ in the first
iteration . So, there is no mapping between the neighbors of vertices $3$ and
$50$ in the second iteration. Hence, $50 \notin R(3)$.
Note that using the \khop label in
the same example will not prune the vertex $50$ because the minimum cost of
matching the \khop labels is within $\alpha$ as shown in table
\ref{tab:khop350}. Therefore, \ncl label is more efficient compared to \khop
label as it subsumes the latter label.

\subsection{Candidate set verification} \label{sec:verification} The pruning
methods based on the \khop and the \ncl labels start with a \CR and prune some
of the candidate vertices based on the conditions described in theorems
\ref{thm:khop} and \ref{thm:ncl}.  The verification step reduces \CR to \RS by
retaining only those vertices $v$ for which there exists an isomorphism $\phi$ in
which $\phi(u) = v$.  Informally, it does this by checking if the pattern $P$ can be
embedded at $v$ such that total cost of label mismatch is at most $\alpha$.

A vertex $v \in R(u)$ iff for any walk $w_p = (u_0=u), u_1,\ldots,u_m$ that covers all
the edges in pattern $P$ there exists atleast one walk $w_d = (v_0=v), v_1,\ldots,
v_m$ in the database $G$ and satisfying the following three conditions: i)
$u_i = u_j \implies v_i = v_j$ ii) $(v_i, v_{i+1}) \in \eg$
iii) $\sum\labcost{C}{L(u_i)}{L(v_i)} \leq \alpha$.
Unlike the \ncl label condition, the above conditions are necessary and
sufficient and can be verified by following the definition of isomorphism.

Now, to check whether $v \in R(u)$, we first map $u$ to $v$ and subtract the cost of
$\labcost{C}{L(u)}{L(v)}$ from the threshold $\alpha$. We then try to map the
remaining vertices in $P$ by following $w_p$ one edge at a time. In any step
$(u_i, u_{i+1})$, if $u_i$ and $u_{i+1}$ are mapped to $x$ and $y$ respectively
then we ensure that $(x, y) \in \eg$
(condition ii). If on the other hand, $u_{i+1}$ is not mapped then we map it
to some vertex in $y \in R'(u_{i+1})$ and subtract the cost
$\labcost{C}{L(u_{i+1})}{L(y)}$ from the remaining $\alpha$ threshold. We back
track if the remaining threshold is less than $0$. The vertex $v \in R(u)$, if we
can complete the walk $w_p$ satisfying the above three conditions.

Consider checking whether the vertex $30 \in R(1)$
in the pattern in the figure~\ref{subfig:ex_sub} and let $\alpha = 0.5$. The
sequence $w_p = 1, 2, 4, 3, 1$ is a walk in the pattern that covers all the edges.
In general, finding a walk that covers all the edges in a graph is a special
case of Chinese postman problem \cite{chinesepostman}. We first map $1$ to $30$
an subtract the cost $\labcost{C}{L(1)}{L(30)} = 0.2$ from $0.5$. In the first
step $(1,2)$, since $2$ is not mapped we map it some vertex, say $20$. The cost
of the mapping is $0.2$ and the remaining threshold is $0.3 -0.2 = 0.1$. It can
be verified that these mappings cannot complete the walk $w_p$. So we backtrack
and map $2$ to another vertex say $10$. The walk can be completed with the
mappings as in $\phi_1$ in Table~\ref{subfig:ex_occur} and the remaining cost is
$0.1$. The mappings of the pattern vertices not only implies that $30 \in R(1)$,
it also tells us that $10, 60, 40$ represent vertices $2, 3, 4$ respectively.
The above procedure can be easily extended to enumerate all the isomorphims of the
pattern.

\subsection{Label costs and dominance checking} \label{sec:labelcheck}
Candidate representative vertices are pruned by checking for dominance
relation between the \ncl labels of pattern vertex and that of candidate
vertex in the database. Comparing the \ncl labels requires i) computing the
cost of matching the \khop labels ii) matching the neighbors of pattern vertex
with neighbors of the candidate vertex. First problem can be formulated
as a minimum cost maximum flow in a network and the second as maximum matching
in a bipartite graph.

\medskip{\textit{Computing \khop label cost}:} The minimum cost of matching the
\khop labels $\khopl{k}{u}$ and $\khopl{k}{v}$ is equal to
minimum cost for maximum cost in a flow network $F$ defined as follows.  Each
edge in $F$ is associated with a maximum capacity and a cost for sending one
unit of flow across it.  The network contains a vertex for each label $l_u =
L(u')$ where $u' \in h_k(u)$ and a vertex for each label $l_v = L(v')$ where $v'
\in h_k(v)$. There is a directed between between source vertex ($s$) and each
$l_u$ with zero cost and a capacity equal to the multiplicity of the $l_u$
i.e., the number of vertices in $h_k(u)$ that have the label $l_u$. Similarly
there is a directed edge between $l_v$ and the sink node ($t$). In addition,
there is a directed edge from $l_u$ to $l_v$ with a cost
equal to $\labcost{C}{l_u}{l_v}$ and a capacity equal to the
multiplicity of $l_u$. The cost between the \khop labels is equal to
the minimum cost for maximum flow if the maximum flow is equal to
$|\khopl{k}{u}|$ and $\infty$ otherwise.
\\ Figure~\ref{fig:Hflow} shows the
flow network required to compute the minimum cost of matching the \khop labels
$\khopl{2}{2} = 4,6 $ and $\khopl{2}{20} = 40, 50, 60$ as shown in Table
\ref{tab:khop220}. The labels of vertices in the \khop labels are $C,D$ and $B,
B, A$ respectively.
There is an edge from $s$ to each of $C, D$ with zero cost
and maximum capacity of one.  Similarly, there is an edge from each of $A, B$ to
the sink vertex $t$ with zero cost and maximum capacity of one and two
respectively. The capacity of the edge betweenn $B$ and $t$ is two because
both the vertices $40$ and $50$ have the same label $B$.
There is an edge from $C, D$ to each of $A, B$ with cost equal to
the corresponding entry in the cost matrix $C$. The maximum flow in the network
is two and the minimum cost of sending two units of flow $0.4$ is achieved by
pushing a unit flow along the paths $s, C, B, t$ and $a, D, A, t$.  Therefore,
the cost of matching the labels $\khopl{2}{2}$ and $\khopl{2}{20}$ is $0.4$. It
implies that the vertex $4$ with label $C$ can be matched to either $40$ or $50$
and the vertex $6$ to $60$.

\medskip{\textit{Dominance check}: } Consider the
\ncl labels $\nclab{k+1}{u} = (A, B)$ and  $\nclab{k+1}{v} = (A', B')$, the cost of
matching the \khop labels
$B$ and $B'$ can be computed using the above the network formulation.
Finding an injective function $f\!\!:A \rightarrow A'$ such that $a \preceq
f(a)$ , is equivalent to find a matching of size $|N(u)|$ in the bipartite graph
with edges $(a, a')$, for all $a \in A$ and $a \preceq a'$.
The \ncl label $\nclab{k}{u}$ is therefore dominated by $\nclab{k}{v}$ if the
cost between the \khop labels is within $\alpha$ and the size of maximum
bipartite matching is $|N(u)|$.

\medskip{\textit{Optimization}: } The candidate pattern may contain groups of
symmetric vertices that are indistinguishable with respect to the \khop label.
In such a scenario, the candidate representative sets of all these vertices are
exactly the same. Utilizing the symmetry, we can apply the pruning label strategy only on
one vertex per symmetry group and replicate the results for all other vertices
in the group. For example, the vertices $1$ and $4$ in
figure~\ref{subfig:ex_sub} are symmetric and the representative sets $R(1)$
and $R(4)$ are exactly the same.  In abstract algebra terms such  groups are
called orbits of the graph and can be computed using nauty algorithm
\cite{nauty}.
Even
though computing the orbits is expensive, we can avoid $ (|g|-1) \times |\CR|$
\ncl label cost computations where $g$ is the size of an orbit. Note that
we find the orbits only for the pattern which is usually very small compared
to the database graph.
%Note that the payoff is zero if all the vertex orbits are of size $1$.

\subsection{Precomputing database \khop labels} The \khop label of a database
vertex is independent of the candidate pattern.
Also, the flow network to compute the cost of matching the \khop labels requires
only the aggregate information about the multiplicity of the vertex label in the
\khop label.
Hence, we can precompute the \khop label of the database vertices and store them
in the memory. The following theorem proves that computing \khop label is
expensive.

\begin{thm} k-reachable (KR) : Given a graph $G$, $k$ and $u \in \vg$. Compute
    $\khopl{k}{u}$.  KR cannot be solved in polynomial time unless $P =
    NP$.

\begin{myproof} We prove this by reducing Hamiltonian path (HP) to KR.
    Hamiltonian Path : Given a graph $G$, is there a simple path of length
    $|\vg|-1$ i.e. is there a path that visits each and every vertex exactly
    once. The problem of finding a Hamiltonian path is
    NP-Complete \cite{npcomplete}.\\ Assume that algorithm $X(k)$ can
    compute KR in polynomial time. Let $|\vg| = n$ and $u$ be the starting
    vertex in HP if it exists.  Given an instance of HP, we first get a vertex
    $v$, $\kpath{u}{v}{n-1}$ using $X(n-1)$. The vertex $v$ is removed from the
    graph and we find a vertex $v'$ such that $\kpath{u}{v'}{n-2}$ and $(v', v)
    \in \eg$. We repeat this process $n-1$ times. If at any stage $X(j) = \{\}$
    then we restart from a different starting vertex. The vertices selected in
    each iteration lie on a path of length $n-1$ if it exists. If there is
    polynomial time algorithm for KR then HP could be solved in polynomial time
    by reducing it to KR. Therefore, $KR$ is atleast as hard as $HP$.
    So, KR cannot be solved in polynomial time unless
    P = NP.
\end{myproof}
\end{thm}

To compute \khop label of a vertex $u$, we check for each vertex $v$ whether $v
\in \kpath{u}{v}{k}$ by enumerating all possible $k$ length paths until a path
is found.  This procedure is exponential, we therefore fix a maximum value
$k_{max}$ and use the \ncl label based pruning only for values of $k \leq
k_{max}$.  It only takes a couple of minutes to compute the \khop label for $k
\leq 6$ for all the vertices in the database graph. This is significantly less
than the overall run time of the algorithm. Once $\khopl{k}{u}$ is computed we
store in memory only the tuples $(l, m)$ where $m$ is the multiplicity of the label
$l = L(u')$.
The total amount of main memory required to store
the precomputed \khop labels is O($|\vg| \times |\Sigma| \times k_{max}$).

\begin{figure}[!h]
    \centering
\scalebox{0.6}[0.6]{
  \psset{unit=0.85in}
  \newcommand\arc[4]{\ncline{#1}{#2}{#3}\ncput{\colorbox{gray!40}{#4}}}
      \begin{pspicture}(0,1)(5,3)
        \cnodeput[doubleline=true](1,2){src}{s}
        \cnodeput(2,1){n1}{C}
        \cnodeput(2,3){n2}{D}
        \cnodeput[doubleline=true](5,2){sink}{t}
        \cnodeput(4,1){n4}{B}
        \cnodeput(4,3){n5}{A}
        \arc{->}{src}{n1}{$1,0$}
        \arc{->}{src}{n2}{$1,0$}
        %\arc{->}{n1}{n4}{$1$}
        \ncline{->}{n1}{n4}\ncput[npos=0.5]{\colorbox{gray!40}{$1,0.1$}}
        \ncline{->}{n1}{n5}\ncput[npos=0.3]{\colorbox{gray!40}{$1,1$}}
        \ncline{->}{n2}{n4}\ncput[npos=0.3]{\colorbox{gray!40}{$1,0.6$}}
        \ncline{->}{n2}{n5}\ncput[npos=0.5]{\colorbox{gray!40}{$1,0.3$}}
        \arc{->}{n4}{sink}{$2,0$}
        \arc{->}{n5}{sink}{$1,0$}
        %\arc{->}{n6}{sink}{$1$}
      \end{pspicture}
    }
    \caption{Flow network for \khopl{2}{2} and \khopl{2}{20}}
	\label{fig:Hflow}
\end{figure}


\section{Conventional Feature Extraction Methods}
Researchers in this field of study often use a combination of features in the detection of informal settlements. Our research uses features that performed well in previous research;  the Histogram of Oriented Gradients (HoG) and Line Support Region (LSR) features. Both HoG and LSR are implemented in a Python library, called \textit{Spfeas}, which is based on the research of Graesser \textit{et al.} \cite{graesser2012image}. Alongside these features, we design a new feature that is based on the difference in the distribution of road intersections between formal and informal areas.

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{images/block_scale}
    \caption{An example of block size and scale}
    \label{fig:block_scale}
\end{figure}

\subsection{Terminology}
The paper of Graesser \textit{et al.} divides the image into small blocks instead of pixels when extracting features from the satellite images. The features are calculated for each block of pixels instead of each pixel individually, which significantly lowers the computational load as the extraction methods can be computationally quite expensive. The dimensions of the blocks are referred to as the \textit{block size},  which is 20 by 20 pixels in the paper of Graesser \textit{et al}. In our research, various block sizes will be evaluated for their effect on the classification performance. Besides \textit{block size}, another important parameter in the paper is the \textit{scale} of a feature. The \textit{scale} specifies an n by n block around the pixel block of which the features are calculated.

Figure \ref{fig:block_scale} is an example of how the size of the block and the scale are used in the calculation of the features from an image. In this example, the size of the image is 120 by 120 pixels and is divided into blocks of the 20 by 20 pixels each, which is the block size. In this example, the scale is the area around each of 80 by 80 pixels. For every block in the image, starting from the top left to the bottom right, the features are calculated over the area covered by the scale. To clarify, if we extract $n$ features from the image in the example, the dimensions of the feature vector would be (6 x 6 x $n$). The block size essentially controls the resolution of the calculated feature vector with an increased block size causing a decreased resolution and the same in reverse. In practice, the block size is almost never a multiple of the image size. In the border regions of the image using a scale larger than the block size, the outer blocks where the scale falls off the edge of the image are discarded. This results in a smaller feature vector than merely dividing the size of the image by the block size.

\begin{figure}[h]
    \centering
    $\mathlarger{\mathlarger{\mathlarger{   p_x = \ceil*{\frac{i_x}{b_x}} - \ceil*{\frac{i_x - s_x - b_x}{b_x}} }}}$
    \caption{Definition of the padding calculation in the $x$-direction}
    \label{padding}
\end{figure}

Figure \ref{padding} shows displays the equation to calculate how many blocks will be removed as padding $p$ for a particular image $i$ with the combination of scale $s$ and block size $b$. We displayed the function for the calculation of the padding in the $x$-direction, although this will be different for the $y$-direction if the image, scale or block size is not of equal width and length. In our case, only the images will have a different width and length; the scales and block sizes will always be $n$x$n$; thus we will be referring two these parameters with a single value $n$ instead of $n$x$n$

We used this equation to predict the dimensions of the features that the Python library would produce after we supplied the input image and the accompanying parameters. We need this prediction to reshape the ground truth into the same shape as the produced features. If the shape of the ground truth does not match the size of the feature, we cannot correctly label the values from the feature vector as either belonging to the formal or informal class and produce the dataset for training and testing for the classification algorithms.

\subsection{Histogram of Oriented Gradients}

Although the patent application describing the Histogram of Oriented Gradients was submitted in 1986, the approach only became widespread in 2005, after a paper used this method to detect humans on images \cite{dalal2005histograms}. The Histogram of Oriented gradients creates a histogram for every block in the image where the histogram contains the gradient orientation of the pixels in the block and surrounding area, as determined by the scale and block size parameter. In the case of the detection of humans, for example, the visual differences between humans and the background manifests itself in the gradient orientations of the image, which the Histogram of Oriented Gradients can capture. The difference in gradient orientation, therefore, enables objects with distinct visual characteristics, such as humans, to be detected from images.

Beyond the detection of humans, a paper from 2003 showed that this approach can also be used to detect man-made structures in photographs \cite{kumar2003man}, which used images of buildings surrounded by vegetation. The Histogram of Oriented Gradients method described in the paper of Graesser \textit{et al.} is based on this paper, although they used satellite images instead of regular photographs from nature. As in the method for the detection of humans with the Histogram of Oriented Gradients, the paper from Graesser \textit{et al.} captures characteristics of a particular class, which are, in this case, the characteristics of informal neighborhoods. In case of slums, these characteristics are the diverse orientations of gradients in a slum area due to diverse building orientations compared to formal structures. In contrast to slums, formal buildings are often placed in a regular pattern with consistent orientation.

The Python library we used extracts different features from the Histogram of Oriented Gradients than the ones described in the paper. The paper uses the first two central moments together with three orientation features, but they are ill-described; the library instead uses four central moments together with a maximum. Because we use the implementation from the library, we will only discuss the features that are used in the library instead of the paper.

The four central moments that are used form a set of values that characterize a probability distribution relative to the mean of the distribution. These characteristics of a distribution, better known as the mean, variance, skew and kurtosis, are defined using the formula displayed in \ref{central_moments} \cite{grimmett2001probability}. In this formula, $n$ is the order of the central moment, $\mu_{n}$ is the $n$th central moment and $\mu$ without a subscript is the mean of the distribution on which the central moments are based. The zeroth and first central moment are trivial because $n=0$ and $n=1$ will always result in 1 and 0 respectively. Instead of using the trivial first central moment, the library uses the regular mean instead. The other three central moments, variance, skew and kurtosis are calculated using the formula in \ref{central_moments} for $n=2$, $n=3$, and $n=4$, respectively. Besides the central moments, the fifth feature is a maximum although, due to lack of documentation, it is unclear what this maximum refers to exactly.

\begin{figure}[h]
    \centering
    $\mathlarger{\mathlarger{\mu_{n} = \int_{-\infty}^{+\infty} (x-\mu)^nf(x)dx }} $
    \caption{The definition of the central moments}
    \label{central_moments}
\end{figure}

Instead of using a single scale for feature calculation, the paper of Graesser \textit{et al.} uses octaves of three scales, meaning that the size of the scale doubles for every scale. To illustrate, the scale octaves used for both the Histogram of Gradients and the Line Support Regions, is 50, 100, and 200. To summarize: in the paper, a single HoG feature vector contains five values, since the feature is performed for three different scales, the total values in the feature vector results in 15. Although it is not mentioned in the paper, the library calculates the features for the different color bands as well, resulting in 45 values instead of 15, which implies that in the paper only a single color band was used.

According to the results presented in the paper, these 15 features could produce an accuracy of 65 to 75 percent. However, this feature was applied to specific image regions where the visual difference between formal and informal was substantial. It is therefore debatable whether this performance is to be attributed to the Histogram of Oriented Gradients or the specific contents of the image. Besides, the morphology of the slums in their area of study is different from the slums in Bangalore, making a comparison difficult.

\subsection{Line Support Region Features}

The Line Support Regions method was initially used for the detection of straight lines in photographs \cite{burns1986extracting}. As with the Histogram of Oriented Gradients, this method is a spatial feature and uses gradient orientation to characterize parts in the image, in this case, straight lines. This approach groups pixels together with similar gradient orientation based on the fact that straight lines are in essence regions of pixels with similar gradients.

This approach was shown to be suited for land use classification \cite{unsalan2004classifying} \cite{unsalan2006gradient}, and has been used in slum and informal region detection since \cite{graesser2012image} \cite{accra} \cite{colombo}. LSR characterizes neighborhoods using the lines that inhabit the area, which often corresponds to the contours of buildings. In formal neighborhoods, these lines are often relatively long since the formal structures tend to be bigger than informal structures. Furthermore, according to the paper \cite{unsalan2004classifying}, line contrast can be used as well to differentiate between land use, as developed areas tend to have high contrast as opposed to low contrast in underdeveloped areas. This difference in contrast can, for instance, be caused by the presence of asphalt, shining roof material and vegetation, which tends to lack in underdeveloped regions. In the paper, this approach was used to differentiate between urban areas and rural areas, although this is now used as well to differentiate between region types within an urban area.

LSR is implemented in Spfeas in accordance with the paper of Graesser \textit{et al.} \cite{graesser2012image}. The paper uses the line length entropy, mean, and entropy of line contrasts as statistical features from the Line Support Regions, although the paper does not describe this process detail. The paper to which Graesser \textit{et al.} refers to, describes the process of calculating these statistical features using three coefficients produced by a Fourier Transformation \cite{unsalan2004classifying}. These coefficients are $(\alpha_{-1}, \beta_{-1})$, $(\alpha_{0}, \beta_{0})$, and $(\alpha_{1}, \beta_{1})$ of which the derivation can be found in the paper.

\begin{figure}[h]
    \centering
    $$\mathlarger{\mathlarger{ \mu_{xy} = (\alpha_{0}, \beta_{0}) }}$$
    $$\mathlarger{\mathlarger{ l = 2\left[\sqrt{\alpha_{1}^2 + \beta_{1}^2} + \sqrt{\alpha_{-1}^2 + \beta_{-1}^2}\right] }}$$
    $$\mathlarger{\mathlarger{ \theta = \frac{\arctan(\frac{\beta_{1}}{\alpha_{1}}) + \arctan(\frac{\beta_{-1}}{\alpha_{-1}})}{2} }}$$
    \caption{Definition of the center of mass $\mu_{xy}$, the line length $l$ and orientation $\theta$}
    \label{line_def}
\end{figure}

Using these coefficients, we can characterize the lines detected within the scale of a block by using the center of mass $\mu_{xy}$, the line length $l$ and orientation $\theta$ with the formula displayed in Figure \ref{line_def}. The most straightforward statistical feature is the mean, which is calculated by taking the mean of all $l$ values of the detected line support regions. The other two features, the entropy of the line length and the line contrast,  are calculated using the entropy formula in Figure \ref{line_entropy_def}.

\begin{figure}[h]

    $$ \mathlarger{\mathlarger{ E = -\sum_{i=1}^{N} \left[ h(i) \log_2(h(i))\right] }}$$
    \caption{Definition of the entropy function}
    \label{line_entropy_def}
\end{figure}

In the creation of the line length entropy, the length of the lines in the area is collected in a histogram with bins representing the different length of the lines. The paper\cite{unsalan2004classifying} describes a total of 37 bins ranging from 5 to 150 pixels. Regarding the formula in Figure \ref{line_entropy_def}, using the histogram $h$ with $N$ bins, we can calculate the entropy of the line length $E_l$.

The line contrasts are calculated by finding the maximum gradient for every line support region. These maximum gradients are, as the line contrasts calculation, collected in a histogram of 31 bins, ranging from 5 to 3000. A more detailed description including the formula for the maximum feature selection can be found in the paper \cite{unsalan2004classifying}. The histogram is used by the entropy function defined in Figure \ref{line_entropy_def} and results in the line contrast entropy $E_c$.

The paper by Graesser \textit{et al.} uses the same octave scale and block size used for HoG, resulting in a total of 9 features. Again, since we use three color bands, the number of features used in our implementation is multiplied by three relative to the paper. Using the LSR features, the paper achieved an accuracy of 60 to 75 percent.


{\bf \Large
\begin{tabular}{ccc}
\hline
  Corresponding author & : & Seiya Nishizawa\\
\hline
\end{tabular}
}

\section{Temporal integration scheme}

\subsection{Runge-Kutta schemes}

For the time integration of Eqs.(\ref{eq:rhotot_d2})-(\ref{eq:etot_d2}),
we adopt the full explicit scheme with
the $p$ step Runge-Kutta scheme.
\begin{eqnarray}
&& \phi^{*}_{0} = \phi^{t}\\
&& k_1 = f(\phi^t) \\
&& k_2 = f(\phi^t + k_1 \Delta t \alpha_1) \\
&&  \cdot \cdot \cdot\nonumber\\
&& k_p = f(\phi^t + k_{p-1} \Delta t \alpha_{p-1}) \\
&& \phi^{t+\Delta t} = \phi^t + \Delta t\sum_p \beta_p k_p.
\end{eqnarray}
The 3 and 4 step Runge-Kutta scheme are implemented.

\subsubsection{The Heun's three step scheme}

\begin{align}
  k_1 &= f(\phi^n), \\
  k_2 &= f\left(\phi^n + \frac{1}{3}\Delta t k_1\right), \\
  k_3 &= f\left(\phi^n + \frac{2}{3}\Delta t k_2\right), \\
  \phi^{n+1} &= \phi^n + \frac{1}{4}\Delta t (k_1 + 3k_3).
\end{align}

\subsubsection{The Kutta's three step scheme}

\begin{align}
  k_1 &= f(\phi^n), \\
  k_2 &= f\left(\phi^n + \frac{1}{2}\Delta t k_1\right), \\
  k_3 &= f\left(\phi^n - \Delta t k_1  + 2 \Delta t k_2\right), \\
  \phi^{n+1} &= \phi^n + \frac{1}{6}\Delta t (k_1 + 4k_2 + k_3).
\end{align}

\subsubsection{The \citet{Wicker_2002}'s three step scheme}

\begin{align}
  k_1 &= f(\phi^n), \\
  k_2 &= f\left(\phi^n + \frac{1}{3}\Delta t k_1\right), \\
  k_3 &= f\left(\phi^n + \frac{1}{2}\Delta t k_2\right), \\
  \phi^{n+1} &= \phi^n + \Delta t k_3.
\end{align}

\subsubsection{The four step scheme}

\begin{align}
  k_1 &= f(\phi^n), \\
  k_2 &= f\left(\phi^n + \frac{1}{2}\Delta t k_1\right), \\
  k_3 &= f\left(\phi^n + \frac{1}{2}\Delta t k_2\right), \\
  k_4 &= f\left(\phi^n + \Delta t k_3\right), \\
  \phi^{n+1} &= \phi^n + \frac{1}{6}\Delta t (k_1 + 2k_2 + 2k_3 + k_4).
\end{align}

\subsubsection{The forward-backward scheme}
In the short time step, the momentums are updated first and then density is updated with the updated momentums.
\begin{align}
  \rho u^{n+1}_i &= \rho u^n_i + \Delta t f_{\rho u_i}(\rho^n), \\
  \rho^{n+1}     &= \rho^n + \Delta t f_{\rho}(\rho u^{n+1}_i).
\end{align}

\subsection{Numerical stability}

A fully compressive equations of a acoustic mode is considered.
The continuous and momentum equations is the followings:
\begin{align}
  \frac{\partial \rho}{\partial t} &=
  - \frac{\partial \rho u_i}{\partial x_i} \\
  \frac{\partial \rho u_i}{\partial t} &=
  - \frac{\partial p}{\partial x_i} \\
  p &= p_0 \left( \frac{R \rho \theta}{p_0} \right)^{c_p/c_v},
\end{align}
here the potential temperature $\theta$ is assumed to be constant.

In order to analize the numerical stability of equation, the equation of the state is linearized.
\begin{equation}
  p \approx \bar{p} + c^2 \rho',
\end{equation}
where $c$ is the sound speed: $c^2=\frac{c_p\bar{p}}{c_v\bar{\rho}}$.

We descritize the governing equation with the 2th order central difference.
\begin{align}
  \left. \frac{\partial \rho}{\partial t}\right|_{i,j,k} &=
  -\frac{U_{i+1/2}-U_{i-1/2}}{\Delta x}
  -\frac{V_{j+1/2}-V_{j-1/2}}{\Delta y}
  -\frac{W_{k+1/2}-W_{k-1/2}}{\Delta z} \\
  \left. \frac{\partial U}{\partial t}\right|_{i+1/2} &=
  -c^2\frac{\rho_{i+1}-\rho_i}{\Delta x} \\
  \left. \frac{\partial V}{\partial t}\right|_{j+1/2} &=
  -c^2\frac{\rho_{j+1}-\rho_j}{\Delta y} \\
  \left. \frac{\partial W}{\partial t}\right|_{i+1/2} &=
  -c^2\frac{\rho_{k+1}-\rho_k}{\Delta z},
\end{align}
where $U, V$, and $W$ is the momentum at the stagared grid point in $x, y$, and $z$ direction, respectively.

The error of the spatial differenece of a wavenumber $k$ component $\hat{\phi}_k$ is $\left\{\exp(ik\Delta x)-1\right\}\hat{\phi}$, and the error of 2-grid mode is the largest: $\exp(i\pi)-1 = -2$.

The temporal differential of the 2-grid mode is
\begin{align}
  \frac{\partial \rho}{\partial t} &=
  -\frac{1-\exp(-i\pi)}{\Delta x}U
  -\frac{1-\exp(-i\pi)}{\Delta y}V
  -\frac{1-\exp(-i\pi)}{\Delta z}W \\
  \frac{\partial U}{\partial t} &=
  -c^2\frac{\exp(i\pi)-1}{\Delta x}\rho \\
  \frac{\partial V}{\partial t} &=
  -c^2\frac{\exp(i\pi)-1}{\Delta y}\rho \\
  \frac{\partial W}{\partial t} &=
  -c^2\frac{\exp(i\pi)-1}{\Delta z}\rho.
\end{align}
The mode of which the $U, V$ and $W$ has the same phase is the most unstable:
\begin{align}
  \frac{\partial \rho}{\partial t} &=
  -3\frac{1-\exp(-i\pi)}{\Delta x}U \\
  \frac{\partial U}{\partial t} &=
  -c^2\frac{\exp(i\pi)-1}{\Delta x}\rho
\end{align}

Writing matrix form,
\begin{equation}
  \begin{pmatrix}
    \frac{\partial \rho}{\partial t} \\
    \frac{\partial U}{\partial t}
  \end{pmatrix}
  = D
  \begin{pmatrix}
    \rho \\
    U
  \end{pmatrix},
\end{equation}
where
\begin{equation}
  D =
  \begin{pmatrix}
    0 & -\frac{6}{\Delta x} \\
    \frac{2c^2}{\Delta x} & 0
  \end{pmatrix}.
\end{equation}

\subsubsection{The Euler scheme}
With the Euler scheme,
\begin{equation}
  \phi^{n+1} = \phi^n + \Delta t f(\phi^n)
\end{equation}
The $A$ is the matrix representing the time step, then
\begin{align}
  A &= I + dt D, \\
    &= \begin{pmatrix}
    1 & -6\frac{\Delta t}{\Delta x} \\
    \frac{2c^2\Delta t}{\Delta x} & 1
    \end{pmatrix}.
\end{align}
The eigen value of $A$ is larger than 1, and the Euler scheme is instable for any $\Delta t$.

\subsubsection{The second step Runge-Kutta scheme}
The Heun's second step Runge-Kutta scheme is
\begin{align}
  k_1 &= f(\phi^n), \\
  k_2 &= f(\phi^n + \Delta t k_1), \\
  \phi^{n+1} &= \phi^n + \frac{\Delta t}{2}(k_1 + k_2).
\end{align}

\begin{align}
  A &= I + \frac{\Delta t}{2}(K_1 + K_2), \\
  K_1 &= D, \\
  K_2 &= D (I + \Delta t K_1).
\end{align}
After all,
\begin{equation}
  A = \begin{pmatrix}
    1-6\nu^2 & -\frac{6\Delta t}{\Delta x} \\
    \frac{2c^2\Delta t}{\Delta x} & 1-6\nu^2
    \end{pmatrix},
\end{equation}
where $\nu$ is the Courant number for the sound speed: $\frac{c\Delta t}{\Delta x}$.
The eigen value of $A$ is larger than 1, and the Euler scheme is instable for any $\Delta t$.

\subsubsection{The third step Runge-Kutta scheme}
With the Heun's third step Runge-Kutta scheme, the matrix $A$ is written by
\begin{align}
  A &= I + \frac{\Delta t}{4}(K_1 + 4K_3), \\
  &= \begin{pmatrix}
    1-6\nu^2 & -\frac{6\Delta t}{\Delta x}(1-2\nu^2) \\
    \frac{2c^2\Delta t}{\Delta x}(1-2\nu^2) & 1-6\nu^2
  \end{pmatrix}, \label{eq: A two}
\end{align}
where
\begin{align}
  K_1 &= D, \\
  K_2 &= D (I + \frac{\Delta t}{3}K_1), \\
  K_3 &= D (I + \frac{2\Delta t}{3}K_2).
\end{align}

The condition that all the eigen values are less than or equal to 1 is
\begin{equation}
  \nu \leq \frac{1}{2}. \label{eq: cond nu two}
\end{equation}

In the Kutta's three step Runge-Kutta scheme, the matrix $A$ is
\begin{equation}
  A = I + \frac{\Delta t}{6}(K_1 + 4K_2 + K_3),
\end{equation}
where
\begin{align}
  K_1 &= D, \\
  K_2 &= D \left(I + \frac{\Delta t}{2}K_1\right), \\
  K_3 &= D \left(I - \Delta t K_1 + 2\Delta t K_2\right).
\end{align}
It is the idential as that in the Heun's scheme (eq. \ref{eq: A two}).
Thus, the stable condition is the same (eq. \ref{eq: cond nu two}).

The \citet{Wicker_2002}'s Runge-Kutta scheme is described as
\begin{align}
  A &= I + \Delta t K_3, \\
  K_1 &= D, \\
  K_2 &= D \left(I + \frac{\Delta t}{3}K_1\right), \\
  K_3 &= D \left(I + \frac{\Delta t}{2}K_2\right).
\end{align}
The $A$ and the consequent stable condition are the identical as the above two schemes.

\subsubsection{The four step Runge-Kutta scheme}
The matrix $A$ is
\begin{align}
  A &= I + \frac{\Delta t}{6}(K_1 + 2K_2 + 2K_3 + K_4), \\
  &= \begin{pmatrix}
    1-6\nu^2+6\nu^4 & -\frac{6\Delta t}{\Delta x}(1-2\nu^2) \\
    \frac{2c^2\Delta t}{\Delta x}(1-2\nu^2) & 1-6\nu^2+6^4
  \end{pmatrix},
\end{align}
where
\begin{align}
  K_1 &= D, \\
  K_2 &= D \left(I + \frac{\Delta t}{2}K_1\right), \\
  K_3 &= D \left(I + \frac{\Delta t}{2}K_2\right), \\
  K_4 &= D (I + \Delta t K_3).
\end{align}

The condition for stability is
\begin{equation}
  \nu \le \frac{\sqrt{6}}{3}.
\end{equation}

The number of floating opint operations with the four step Runge-Kutta scheme is about $4/3$ times larger than that with the three step scheme.
Howere, the time step can be $2\sqrt{6}/3$ larger than that in the three step scheme.
Since $2\sqrt{6}/3 > 4/3$, the four step Runge-Kutta scheme is more cost effective than the three step scheme in terms of numerical stability.

\subsubsection{The forward-backward scheme}
The stabitlity condition is
\begin{equation}
  \nu \le \frac{1}{\sqrt{3}}.
\end{equation}

The forward-backward scheme can be used in each step in the Runge-Kutta schemes.
The stability conditions are the followings:
\begin{description}
 \item[The second step RK scheme]
 \begin{equation}
   \nu \le \frac{1}{\sqrt{3}}.
 \end{equation}

 \item[The Heun's three step RK scheme]
 \begin{equation}
   \nu \le \frac{1}{2}.
 \end{equation}

 \item[The Kutta's three step RK scheme]
 \begin{equation}
   \nu \le \frac{1}{2}.
 \end{equation}

 \item[The\citet{Wicker_2002}'s three step RK scheme]
 \begin{equation}
   \nu \le \frac{\sqrt{6}}{4}.
 \end{equation}

 \item[The four step RK scheme]
 \begin{equation}
   \nu \le 0.66
 \end{equation}

\end{description}


\section{Conclusions}

The actual \emph{convergence rates} of the \emph{primal} $\protect \mathcal{L}_1$-SVM formulations, i.e., the figures~\ref{fig:l1_svc_loss_history} and~\ref{fig:l1_svr_loss_history}, shows as they do not meet the theoretical expectations at the first line of the table~\ref{primal_svm_objectives_rates}. Both the \emph{Polyak} and the \emph{Nesterov} momentums provide a significant accelleration wrt the \emph{vanilla SGD} and they are quite comparable.

Conversely, the actual \emph{convergence rates} of the \emph{primal} $\protect \mathcal{L}_2$-SVC formulations, i.e., the figure~\ref{fig:l2_svc_loss_history} and~\ref{fig:l2_svr_loss_history}, shows as they do in part meet the theoretical expectations at the second line of the table~\ref{primal_svm_objectives_rates}. Despite the \emph{Nesterov} momentum provide a significant accelleration wrt the \emph{vanilla SGD} as expected, also the \emph{Polyak} momentm provide a quite comparable accelleration only reserved for the quadratic case according to the theoretical analysis.

Meanwhile, the actual \emph{convergence rates} of the \emph{primal} $\protect \mathcal{L}_2$-SVR formulations, i.e., the figure~\ref{fig:l2_svr_loss_history}, shows as they do not meet the theoretical expectations at the second line of the table~\ref{primal_svm_objectives_rates} since in this specific case, both the \emph{Polyak} and \emph{Nesterov} momentums does not provide an accelleration wrt the \emph{vanilla SGD} as expected.

\bigskip

The actual \emph{convergence rates} of the \emph{Lagrangian dual} formulations shows as they do not meet the theoretical expectations in the table~\ref{dual_svm_objectives_props}. The different \emph{convergence rate} is more highlighted in the linear case for lower regularization parameters $C$ but the situation is reversed as the latter grows. In the nonlinear settings, it depends on the kernel function, e.g., in the \emph{polynomial} case the convergence can become pathologically slower, meanwhile in the \emph{gaussian} or \emph{laplacian} case often it is better.

Moreover, from all the actual \emph{convergence rates} of the \emph{Lagrangian dual} formulations, it is evident that fitting the bias in an explicit way, i.e., by adding Lagrange multipliers to control the equality constraint, always causes slower converge of the \emph{AdaGrad} algorithm wrt the \emph{Lagrangian dual} of the problem where the bias term embedded into the Hessian matrix.

\bigskip

All the \emph{custom} implementations underperforms the others, i.e., \emph{liblinear}~\cite{fan2008liblinear}, \emph{libsvm}~\cite{chang2011libsvm} and \emph{cvxopt}~\cite{vandenberghe2010cvxopt} implementations, in terms of \emph{time} obviously in part due to the different core implementation languages, i.e., Python vs C, in part due to the different algorithm uses to solve the  optimization problem, e.g., the \emph{liblinear}~\cite{fan2008liblinear} implementation uses the \emph{Coordinate Gradient Descent} to sove the \emph{primal formulation} which minimizes one coordinate at a time.

Meanwhile, for what about the \emph{Wolfe dual} formulations, despite \emph{cvxopt}~\cite{vandenberghe2010cvxopt} underperforms the \emph{libsvm}~\cite{chang2011libsvm} implementation in terms of \emph{time}, since it is a general-purpose QP solver and it does not exploit the structure of the problem, the number of \emph{iterations} of the \emph{custom} SMO algorithm is always lower wrt that in \emph{libsvm}~\cite{chang2011libsvm}, probably due to the improvements described in~\cite{keerthi2001improvements, shevade1999improvements} for classification and regression respectively.

\bigskip

Finally, all the \emph{primal formulations} are suitable for potentially large linear training since the complexity of the model grows with the number of features or, more in general, when the number of examples $n$ is much larger than the number of features $m$, i.e., $n \gg m$.

Meanwhile, the \emph{dual formulations} are suitable in case the number of examples $n$ is less than the number of features $m$, i.e., $n < m$, since the complexity of the model is dominated by the number of examples. The \emph{Lagrangian} formulation never overperforms the \emph{Wolfe} one in our experiments, neither in terms of \emph{time} nor in terms of \emph{iterations}, but it is useful to highlight the complexity introduced by the dual formulation. Its training time complexity is more than quadratic with the number of samples which makes it hard to scale to large datasets. In this case, it could be useful to use the \emph{primal formulation} possibly after a nonlinear transformation of the instance vectors (if this should not be in the given space) using a low-rank kernel matrix approximation, i.e., Nyström, before training.


\documentclass[main_montangero.tex]{subfiles}
\begin{document}

\section{Shor's algorithm}

It is a method to factor a product of large numbers.

\paragraph{Motivation}

Alice wants to communicate a message \(P\) to Bob.
Bob generates a public key \( K _{\text{Pu}} \) and a private key \( K _{\text{Pr}}  \), he sends the public key \( K _{\text{Pu}} \) to Alice, who encodes the message with an algorithm \(E\) which depends on the public key:

\begin{equation}
  C = E _{K _{\text{Pu}} } (P) = P ^e \mod N
\end{equation}

where \( N \) is chosen such that \( N = pq \), with \( p, q \in \Z_{\text{prime}} \), \(\Phi = (p-1) (q-1)\), \( 1<e<\Phi \),  and \( \text{GCD}(\Phi, e) = 1 \).

She then sends \( C \) to Bob, who uses \( K _{\text{Pr}} \) to decode it with an algorithm \(D\):

\begin{equation}
  P = D _{K _{\text{Pr}}} C^d \mod N % P (d, N)??
\end{equation}

where \( d \) is chosen such that \( de = 1 \mod \Phi \).

Factoring \( N \) is equivalent to finding the period of a function: the \emph{order} \( r \) is the number such that \( x ^{r} = 1 \mod N  \) , \( f(r) = x^r \mod N \).

If \( r \) is even, then \( y = x ^{r/2}  \), so \( y^2 = 1 \mod N \) therefore \( (y+1)(y-1) = 0 \mod N \).

Therefore \( (y+1)(y-1) = kN \) for some \( k \in \N \), so we have found the factors.

\paragraph{The algorithm}

Given \( N = pq \), we have the following steps:

\begin{enumerate}
  \item Choose \( x<N \). If it divides \( N \), we are done;
  \item Find the order \( r \) such that \( f(r) = x^r \mod N \); \label{item:qft}
  \item If \( r \) is even, we have the factors. If it is not, start over.
\end{enumerate}

The quantum step is in step \ref{item:qft}.

\paragraph{Step 1}

\subparagraph{Hypotheses} These are not actually needed but they make treating the problem much simpler, and there is not much to learn in generalizing: we assume \( N = 2^n \) and \( N/r = m \in \N \).

As always we cannot directly encode our function as a unitary transformation since it will be periodic, therefore not injective, therefore not unitary. So we encode it taking the input along, as

\begin{equation}
   U: \ket{x}\ket{0} \longmapsto \ket{x} \ket{f(x)}
\end{equation}

We start from \( \ket{0}^{\otimes n} \), apply \(N\) Hadamards and get \( \ket{\psi_0} \) = superposition of all possible states, and with this
we prepare

\begin{equation}
  \ket{\psi_1} = \frac{1}{\sqrt{2^n}} \sum _{x=0} ^{N}   \ket{x} \ket{f(x)}
\end{equation}

\paragraph{Step 2}

We measure the second registry, and obtain \( \ket{\overline{f}} \). Then the first registry must contain all the combinations which generate that state: so:

\begin{subequations}
\begin{align}
  \ket{\psi_2}
  &= \frac{1}{\sqrt{m}}\sum _{j=0} ^{m-1} \ket{x_0 + jr} \ket{\overline{f(x_0)}}  \\
  &= \qty[\frac{1}{\sqrt{m}}\sum _{j=0} ^{m-1} \ket{x_0 + jr} ] \otimes \ket{\overline{f(x_0)}}
\end{align}
\end{subequations}

\paragraph{Step 3}

We want to find \( r \), so we can do a quantum Fourier transform. It can be slow  to actually measure the full transform for generic functions but in our case the transform is applied to a function which is already periodic

\begin{equation}
  \ket{\psi _3} = \text{QFT}\qty{\ket{\psi_2}} = \frac{1}{\sqrt{mN}} \sum _{y=0} ^{N-1} \sum _{j=0} ^{m-1} \exp(2 \pi i (x_0 + jr) y/N) \ket{y}
\end{equation}

\paragraph{Step 4}

We compute the probability of obtaining a specific value \(\overline{y} \) from a measure of the registry:

\begin{subequations}
\begin{align}
  \P\qty(\overline{y})
  &= \frac{1}{Nm} \abs{\sum _{j=0} ^{m-1} \exp(2 \pi i (x_0 + jr) \overline{y}/N) }  \\
  &= \frac{1}{r} \abs{\frac{1}{m} \sum_j \exp(2 \pi i j \overline{y} /m)}
\end{align}
\end{subequations}

Claim: the states with nonzero probability to be found are those with \( \overline{y} = km \), where \( k \in 0, \dots,  r \).

\subparagraph{Example}

\( P(\overline{y} = 0) = 1/r \abs{1/m \sum_j 1} = 1/r \). Our function is periodic with period \(r\), and there are \(r-1\) other analogous states. So, the probability is saturated and there is no other possible outcome.

So all the states we get are in the form \( \overline{y}=km = kN/r \). We know $N$, we measured \( \overline{y} \), so:

\begin{itemize}
  \item if \( k=0 \), we failed;
  \item if \( k\neq 0 \), we set \( \overline{y}/N = \overline{k}/r \) and find the solution in polynomial time.
\end{itemize}

\( P(\text{success}) \sim 1 \) dopo \( O(\log(\log(r))) \).

Recall \( n = \log N \): the complexity of Shor's algorithm scales as \( O(n^2 \log n \log \log n) \), whereas the classical algorithm scales as \( \exp(O(\sqrt[3]{n\log n})) \).

It is important to emphasize that no classical algorithm has been found which runs in polynomial time, but it has \emph{not} been proven that it is impossible for one to be found.

\paragraph{Example of period search}

\begin{equation}
  f(x) = \frac{1}{2} \qty(\cos \pi x + 1)
\end{equation}

\[
 f:
\left|
  \begin{array}{rcl}
    \qty{0,1}^3 & \longrightarrow & \qty{0,1} \\
    0,2,4,6 & \longmapsto & 1 \\
    1,3,5,7 & \longmapsto & 0 \\
  \end{array}
\right.
\]

As always, we mix the notation for \(n\)-qubit states, \(n\)-bit numbers expressed in binary and in decimal.

So \( N = 2^3 = 8 \). \( r=2 \), \( m = N/r = 4 \).

\subparagraph{Step 1}

\begin{equation}
  \ket{\psi _1 }  =  \frac{1}{\sqrt{8}} \sum_{m=0} ^{7} \ket{x}_1 \ket{f(x)}_2
\end{equation}

\subparagraph{Step 2}

\begin{equation}
  \ket{\psi_2} = \frac{1}{2} \qty(\ket{1}+\ket{3}+\ket{5}+\ket{7})_1 \otimes \ket{0}_2
\end{equation}

\subparagraph{Step 3}

We map \( j \rightarrow \frac{1}{\sqrt{8}} \sum_k \exp(2 \pi i j k / 8) \ket{k} \)

\begin{subequations}
\begin{align}
  \ket{\psi_3}
  &= \frac{1}{2 \sqrt{8}} (\ket{0} + e^{i \pi/4} \ket{1} \\
  &+ \dots + \ket{0} + e^{3 i \pi /4}\ket{1})_1 \otimes \ket{0}_2 \\
  &= \frac{1}{\sqrt{2}} \qty(\ket{0}+\ket{4} )
\end{align}
\end{subequations}

We either measure 0 or 4. So, if it is 0 we have failed, if it is 4 we have \( \overline{y} = 4 \), therefore \( k=1 \)  works and \( r=2 \).

\end{document}


\documentclass[simplex.tex]{subfiles}
% NO NEED TO INPUT PREAMBLES HERE
% packages are inherited; you can compile this on its own

\onlyinsubfile{
\title{NeuroData SIMPLEX Report: Reduced Dimension Clustering}
}

\begin{document}
\onlyinsubfile{
\maketitle
\thispagestyle{empty}

The following report documents the progress made by the labs of Randal~Burns and Joshua~T.~Vogelstein at Johns Hopkins University towards goals set by the DARPA SIMPLEX grant.

%%%% Table of Contents
\tableofcontents

%%%% Publications
\bibliographystyle{IEEEtran}
\begin{spacing}{0.5}
\section*{Publications, Presentations, and Talks}
%\vspace{-20pt}
\nocite{*}
{\footnotesize	\bibliography{simplex}}
\end{spacing}
%%%% End Publications
}

\subsection{Batch effect removal in dimension reduction of multiway array data}

Batch effects are unwanted random variations caused by different data sources and experimental conditions. Generalized linear random effects model is effective to mitigate these confounders in traditional low dimensional data; however, there is a lack of such tool for high dimensional and multiway array data. While tensor factorization is routinely used for dimension reduction, due to the sharing of factors among all batches, the batch effects quickly populate the low dimensional core and confound the signal. In this research, we propose a different strategy by letting factor matrices vary over batches, while leaving the remaining variation in the core. This allows capturing sophisticated batch effects, while retaining the low rank structure for describing signal. To allow estimation with flexible factors, we utilize a hierarchical random effects model to borrow information among the batches. An efficient closed-form expectation conditional maxmization strategy is developed for rapid estimation. We focus the application on the joint diagonalization of brain connectivity data obtained from different sources.

The model we propose is:

\begin{equation}
\begin{aligned}
A_{ji, kl} & =  A_{ji, lk}\\
A_{ji, kl} & \stackrel{indep}{\sim} \text{Bern}(\text{logit}(\psi_{ji,kl}))\\
\psi_{ji,kl} & = \sum_{r=1}^{d} c_{ji, r} f_{j,kr} f_{j,lr}   \\
f_{j,kr} & \stackrel{indep}{\sim}  \text{N}(f_{0,kr}, \sigma^2)\\
f_{0,kr} & \stackrel{iid}{\sim} \text{N}(0, 1)
\end{aligned}
\end{equation}
with $k=1\ldots l$ and $l=2\ldots n$.

The batch effect adjusted connectome is then $A_{ji, kl} = \psi_{ji,kl} = \sum_{r=1}^{d} c_{ji, r} f_{0,kr} f_{0,lr} $
\begin{figure}[h!]
\begin{cframed}
\centering
\includegraphics[width=0.455\textwidth, clip = true,  trim = 0mm 15mm 0mm 10mm]{../../figs/avgA1}
\includegraphics[width=0.4635\textwidth, clip = true, trim = 0mm 15mm 0mm 10mm ]{../../figs/avgA3}
\includegraphics[width=0.455\textwidth, clip = true,  trim = 0mm 15mm 0mm 10mm]{../../figs/avgA1adjusted}
\includegraphics[width=0.4635\textwidth, clip = true, trim = 0mm 15mm 0mm 10mm]{../../figs/avgA3adjusted}
\caption{The first row shows the average connectome of two groups, that some difference can be obsevered. The second row shows the batch effect adjusted average connectome of the two groups, that they become similar.}
\end{cframed}
\end{figure}

\end{document}


\documentclass{article}
 \usepackage[utf8]{inputenc}
 \usepackage{graphicx}
 \graphicspath{ {images/} }
 \begin{document}

 \title{ARTIFICIAL INTELLIGENCE EXAM}
 \author{Course Code: 1DL340}
 \date{Ref.  This is a student generated exam. }
 \maketitle

 This exam has  18  questions for a total of  49  marks. Grade boundaries are:

 \begin{center}
 3 -  24.5

 4 -  32.5

 5 -  40.5

 \end{center}

 In exceptional circumstances these boundaries may be adjusted at the discretion of the examiner. This would be done on an exam-wide basis, NOT for individual students.

 You are permitted to make use of a calculator and language dictionary in this exam.
\clearpage
\section{A-Star}

Table~\ref{AStar_Edges} gives the edge values for a shortest path problem. Using these and the A* algorithm, find the shortest path from the start node to the goal node. Provide a valid heuristic and show all working. (4 marks)

\begin{table}[h!]
\caption{Edges}
\label{AStar_Edges}
\begin{center}
\begin{tabular}{ |c||c|c|c|c|c|c|c| }
\hline
 & Start & A & B & C & D & E & Goal\\
\hline
Start & 0 & 5 & 4 & 0 & 0 & 0 & 0\\
A & 0 & 0 & 6 & 0 & 6 & 0 & 0\\
B & 0 & 0 & 0 & 7 & 0 & 0 & 0\\
C & 0 & 0 & 0 & 0 & 2 & 0 & 0\\
D & 0 & 0 & 0 & 0 & 0 & 7 & 0\\
E & 0 & 0 & 0 & 0 & 0 & 0 & 3\\
Goal & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
\hline
\end{tabular}
\end{center}
\end{table}
\clearpage
\section{MCMC and Directed Graphical Models}

Tables~\ref{MCMC1} to~\ref{MCMC5} provide the conditional probability distributions for a directed graphical model.

A. Use this information to draw the graph of the associated directed graphical model. (1 mark)

B. Table~\ref{MCMC6} provides observed values for some of the nodes. Given these, the initial values provided in Table~\ref{MCMC7} and the random numbers provided below, use the Metropolis within Gibbs MCMC sampling algorithm to generate two complete samples of the variables. Assume that the candidate function gives the opposite of the current value. At each step, explain what value you are considering, what the current and candidate values are, and why you updated it or did not update it. (4 marks)

Random numbers: 0.839,0.753,0.534,0.923,0.72,0.739
\begin{table}[h!]
\caption{P(A)}
\label{MCMC1}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 - & A=F & A=T\\
\hline
 & 0.75 & 0.25\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{P(B$|$A)}
\label{MCMC2}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 A & B=F & B=T\\
\hline
 A=F & 0.15 & 0.85\\
 A=T & 0.05 & 0.95\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{P(C$|$A)}
\label{MCMC3}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 A & C=F & C=T\\
\hline
 A=F & 0.2 & 0.8\\
 A=T & 0.35 & 0.65\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{P(D$|$B,C)}
\label{MCMC4}
\begin{center}
\begin{tabular}{ |c|c||c|c| }
\hline
 B & C & D=F & D=T\\
\hline
 B=F & C=F & 0.8 & 0.2\\
 B=F & C=T & 0.55 & 0.45\\
 B=T & C=F & 0.3 & 0.7\\
 B=T & C=T & 0.1 & 0.9\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{P(E$|$C)}
\label{MCMC5}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 C & E=F & E=T\\
\hline
 C=F & 0.25 & 0.75\\
 C=T & 0.2 & 0.8\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Observed Values}
\label{MCMC6}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
 Node & Value \\
\hline
D & FALSE\\
E & FALSE\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Initial Values}
\label{MCMC7}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
 Node  & Value \\
\hline
A & TRUE\\
B & TRUE\\
C & TRUE\\
\hline
\end{tabular}
\end{center}
\end{table}
\clearpage
\section{Hidden Markov Models: Forward-Backward Algorithm}

Tables~\ref{hmmfb1} to~\ref{hmmfb4} provide the transition matrix, emission matrix, initial state and a sequence of observations for a hidden Markov model. Use the forward-backward algorithm to calculate the probability distributions for the state of the system at times 0, 1 and 2 given the observations. Show all working. (4 marks)

\begin{table}[h!]
\caption{Transition Matrix}
\label{hmmfb1}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 $S_{t-1}$ & $S_t$=0 & $S_t$=1\\
\hline
 0 & 0.3 & 0.7\\
 1 & 0.9 & 0.1\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Emission Matrix}
\label{hmmfb2}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 $S$ & $E=0$ & $E=1$\\
\hline
 0 & 0.1 & 0.9\\
 1 & 0.2 & 0.8\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Initial State}
\label{hmmfb3}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
 $S=0$ & $S=1$\\
\hline
0.5 & 0.5\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Observations}
\label{hmmfb4}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
 Time=1 & Time=2\\
\hline
FALSE & TRUE\\
\hline
\end{tabular}
\end{center}
\end{table}
\clearpage
\section{Hidden Markov Models: Viterbi Algorithm}

Tables~\ref{hmmvit1} to~\ref{hmmvit4} provide the transition matrix, emission matrix, initial state and a sequence of observations for a hidden Markov model. Use the Viterbi algorithm to calculate the most probable path and its probability. Show all working. (3 marks)

\begin{table}[h!]
\caption{Transition Matrix}
\label{hmmvit1}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 $S_{t-1}$ & $S_t$=0 & $S_t$=1\\
\hline
 0 & 0.4 & 0.6\\
 1 & 0.1 & 0.9\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Emission Matrix}
\label{hmmvit2}
\begin{center}
\begin{tabular}{ |c||c|c| }
\hline
 $S$ & $E=0$ & $E=1$\\
\hline
 0 & 0.7 & 0.3\\
 1 & 0.7 & 0.3\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Initial State}
\label{hmmvit3}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
 $S=0$ & $S=1$\\
\hline
0.5 & 0.5\\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Observations}
\label{hmmvit4}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
 Time=1 & Time=2\\
\hline
TRUE & TRUE\\
\hline
\end{tabular}
\end{center}
\end{table}
\clearpage
\section{Alpha-Beta Pruning}

Examine the game tree included in this exam. Note that the values in the nodes are node indices, not mini-max values. Perform alpha-beta pruning on this game tree.  You should show all working, where this means all alpha-beta values.  You can write these values on the diagram, or alternatively on a separate sheet of paper.  In both cases, provide a way of identifying the sequence of updates to alpha-beta values associated with nodes (we suggest you just cross out old values and write new values sequentially downwards).  If you write on a separate sheet of paper, use the node indices in the diagram as a way of identifying which node particular alpha-beta values are associated with.  Show where pruning occurs, by indicating which branches will not be evaluated.  Finally, provide the result (value at end state) of the game assuming optimal play. (3 marks)

\begin{figure}[h!]
\includegraphics[width=\textwidth]{ab.jpg}
\end{figure}
\clearpage
\section{Scheduling}

Provide a complete resource constrained schedule for the actions found in Table~\ref{schActions}. (4 marks)
\begin{table}[h!]
\caption{Actions}
\label{schActions}
\begin{center}
\begin{tabular}{ |c|c|c|c|c|c| }
\hline
 Index & Action & Duration & Uses & Consumes & After \\
\hline
1 & Start & 0 &   & 0 nails & NA\\
2 & Action 1 & 35 &  Saw & -1 nail & 1\\
3 & Action 2 & 45 &  Saw & 0 nails & 1\\
4 & Action 3 & 10 &   & -1 nail & 1\\
5 & Action 4 & 15 &   & 0 nails & 4\\
6 & Action 5 & 25 &   & 1 nail & 4,2,5\\
7 & Action 6 & 50 &  Saw & 0 nails & 3,5\\
8 & Action 7 & 40 &   & 1 nail & 3,2,4\\
9 & Finish & 0 &   & 0 nails & 6,7,8\\
\hline
\end{tabular}
\end{center}
\end{table}
\clearpage
\section{Multi-Armed Bandit Optimization}

Image we are testing click through rates on three different web layouts. At the current point, the Dirichlet (beta) distributions associated with each layout have the parameters in Table~\ref{MABO1}.\begin{table}[h!]
\caption{Dirichlet (Beta) Parameters for Layout}
\label{MABO1}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
 Layout & Parameter 1 & Parameter 2 \\
\hline
A &  11  &  4 \\
B &  8  &  3 \\
C &  10  &  6 \\
\hline
\end{tabular}
\end{center}
\end{table}

The first value is associated with not clicking through, the second clicking through.

A new person views the site. We generate samples from the distributions to determine which layout is used. These samples are given in Table~\ref{MABO2}.
\begin{table}[h!]
\caption{Samples from Layout Dirichlet (Beta) Distributions}
\label{MABO2}
\begin{center}
\begin{tabular}{ |c|c|c|c|c|c| }
\hline
 Layout & Sample 1 & Sample 2 & Sample 3 & Sample 4 & Sample 5 \\
\hline
A &  0.25  &  0.15  &  0.31  &  0.29  &  0.39 \\
A &  0.25  &  0.14  &  0.22  &  0.26  &  0.26 \\
A &  0.2  &  0.19  &  0.32  &  0.48  &  0.18 \\
\hline
\end{tabular}
\end{center}
\end{table}

When shown the website with the chosen layout, the person makes a purchase ('clicks through'). Give the new parameters of the three distributions after this event. (2 Marks)
\clearpage
\section{Basic Feed-Forward ANNs}

Examine the neural network given in the diagram labelled 'Basic Regression Feed-Forward Neural Network'. In this diagram, square nodes represent biases, blue nodes the input layer, green nodes a hidden layer, and red nodes the output layer. The first round blue input node is associated with feature X1, and the second with feature X2 (counting downwards). Assuming that all activation functions are rectifiers (i.e. the hidden nodes are ReLU units), and the output is a basic linear regression function, calculate the output of this network if it was given an input of X1 = 5 and X2 = -5. Show all working. (2 Marks)

\begin{figure}[h!]
\includegraphics[width=\textwidth]{ffnn.jpg}
\end{figure}
\clearpage
\section{Convolution layers in CNNs}

Tables~\ref{CNN1} to~\ref{CNN3} provide an input matrix and two filter matrices for a convolutional layer in a CNN. Assuming no padding, that stride is [1,1], and that all activation functions are rectifiers, calculate the output of this layer. (2 marks)
\begin{table}[h!]
\caption{Input Matrix}
\label{CNN1}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
-3  &  -2  &  1 \\
-3  &  4  &  -3 \\
-2  &  -4  &  0 \\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Filter 1}
\label{CNN2}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
4  &  -4 \\
1  &  2 \\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{table}[h!]
\caption{Filter 1}
\label{CNN3}
\begin{center}
\begin{tabular}{ |c|c| }
\hline
-2  &  -2 \\
3  &  -4 \\
\hline
\end{tabular}
\end{center}
\end{table}
\clearpage
\section{ Bias-Variance }

Give a basic explanation (as per what was discussed in the course) of the bias and variance components of expected error and their relationship to model complexity. (3 marks)
\clearpage
\section{ Reinforcement Learning }

What is the purpose of including randomness in the action-deciding process of a reinforcement learning system? (1 mark)\clearpage
\section{ LSTMs }

Explain the steps involving the memory vector in a pass through a LSTM layer at time t. Mention what is done to the memory vector (non-mathematically) and/or what the memory vector is used for in each of these steps. Make reference to the input at time t, and the outputs of time t-1 and t. (2 marks)\clearpage
\section{ Local Search }

Greedy Hill Climb suffers from the problem of local optima. Name and provide a brief explanation of three alternative local search strategies covered in this course that attempt to overcome or minimize this problem. (3 marks)
\clearpage
\section{ Planning Graphs }

Explain the two ways a planning graph can be used to provide a heuristic for A*. (2 marks)
\clearpage
\section{ Depth-First Search }

Under what conditions could a depth-first search FAIL to find a solution (in a finite search space with at most a single edge between any two nodes)? (1 mark)\clearpage
\section{ PDDL }

What is PDDL? Explain all components of a PDDL problem. Be as precise and concise as possible.  (4 marks)
\clearpage
\section{ Iterated Deepening }

Explain iterated deepening. (2 marks)
\clearpage
\section{ GANs }

Assume you have a GAN where the discriminator network is a simple binary (Genuine/Fake) classifier. Briefly explain how the generator network is trained. (2 marks)

\end{document}


\chapter{Algebraic integers}
Here's a first taste of algebraic number theory.

This is really close to the border between olympiads and higher math.
You've always known that $a+\sqrt2 b$ had a ``norm'' $a^2-2b^2$,
and that somehow this norm was multiplicative.
You've also always known that roots come in conjugate pairs.
You might have heard of minimal polynomials but not know much about them.

This chapter and the next one will make all these vague notions precise.
It's drawn largely from the first chapter of \cite{ref:oggier_NT}.

\section{Motivation from high school algebra}
This is adapted from my blog, \emph{Power Overwhelming}\footnote{URL: \url{https://usamo.wordpress.com/2014/10/19/why-do-roots-come-in-conjugate-pairs/}}.

In high school precalculus, you'll often be asked to find the roots of some polynomial with integer coefficients.
For instance,
\[ x^3 - x^2 - x - 15 = (x-3)(x^2+2x+5) \]
has roots $3$, $-1+2i$, $-1-2i$.
Or as another example,
\[ x^3 - 3x^2 - 2x + 2 = (x+1)(x^2-4x+2) \]
has roots $-1$, $2 + \sqrt 2$, $2 - \sqrt 2$.
You'll notice that the irrational roots, like $-1 \pm 2i$ and $2 \pm \sqrt 2$, are coming up in pairs. In fact, I think precalculus explicitly tells you that the imaginary roots come in conjugate pairs. More generally, it seems like all the roots of the form $a + b \sqrt c$ come in ``conjugate pairs''. And you can see why.

But a polynomial like
\[ x^3 - 8x + 4 \]
has no rational roots.
(The roots of this are approximately $-3.0514$, $0.51730$, $2.5341$.)
Or even simpler,
\[ x^3 - 2 \]
has only one real root, $\sqrt[3]{2}$.
These roots, even though they are irrational, have no ``conjugate'' pairs.
Or do they?

Let's try and figure out exactly what's happening.
Let $\alpha$ be any complex number.
We define the \vocab{minimal polynomial} of $\alpha$ over $\QQ$ to be the polynomial such that
\begin{itemize}
	\item $P(x)$ has rational coefficients, and leading coefficient $1$,
	\item $P(\alpha) = 0$.
	\item The degree of $P$ is as small as possible.
		We call $\deg P$ the \vocab{degree} of $\alpha$.
\end{itemize}
\begin{example}[Examples of minimal polynomials]
	\listhack
	\begin{enumerate}[(a)]
	\ii $\sqrt 2$ has minimal polynomial $x^2-2$.
	\ii The imaginary unit $i = \sqrt{-1}$ has minimal polynomial $x^2+1$.
	\ii A primitive $p$th root of unity, $\zeta_p = e^{\frac{2\pi i}{p}}$, has minimal polynomial $x^{p-1} + x^{p-2} + \dots + 1$, where $p$ is a prime.
	\end{enumerate}
\end{example}
Note that $100x^2 - 200$ is also a polynomial of the same degree which has $\sqrt 2$ as a root; that's why we want to require the polynomial to be monic. That's also why we choose to work in the rational numbers; that way, we can divide by leading coefficients without worrying if we get non-integers.

Why do we care? The point is as follows: suppose we have another polynomial $A(x)$ such that $A(\alpha) = 0$.
Then we claim that $P(x)$ actually divides $A(x)$!
That means that all the other roots of $P$ will also be roots of $A$.

The proof is by contradiction: if not, by polynomial long division we can find a quotient and remainder $Q(x)$, $R(x)$ such that
\[ A(x) = Q(x) P(x) + R(x) \]
and $R(x) \not\equiv 0$.
Notice that by plugging in $x = \alpha$, we find that $R(\alpha) = 0$.
But $\deg R < \deg P$, and $P(x)$ was supposed to be the minimal polynomial.
That's impossible!

Let's look at a more concrete example.
Consider $A(x) = x^3-3x^2-2x+2$ from the beginning.
The minimal polynomial of $2 + \sqrt 2$ is $P(x) = x^2 - 4x + 2$ (why?).
Now we know that if $2 + \sqrt 2$ is a root, then $A(x)$ is divisible by $P(x)$.
And that's how we know that if $2 + \sqrt 2$ is a root of $A$, then $2 - \sqrt 2$ must be a root too.

As another example, the minimal polynomial of $\sqrt[3]{2}$ is $x^3-2$. So $\sqrt[3]{2}$ actually has \textbf{two} conjugates, namely, $\alpha = \sqrt[3]{2} \left( \cos 120^\circ + i \sin 120^\circ \right)$ and $\beta = \sqrt[3]{2} \left( \cos 240^\circ + i \sin 240^\circ \right)$. Thus any polynomial which vanishes at $\sqrt[3]{2}$ also has $\alpha$ and $\beta$ as roots!

\begin{ques}
	[Important but tautological:
	irreducible $\iff$ minimal]
	Let $\alpha$ be a root of the polynomial $P(x)$.
	Show that $P(x)$ is the minimal polynomial
	if and only if it is irreducible.
	% (This is tautological: the point is just to realize that ``minimal polynomials'' and ``irreducible polynomials'' are the same beasts.)
\end{ques}

\section{Algebraic numbers and algebraic integers}
\prototype{$\sqrt2$ is an algebraic integer (root of $x^2-2$),
$\half$ is an algebraic number but not an algebraic integer (root of $x-\half$).}

Let's now work in much vaster generality.
First, let's give names to the new numbers we've discussed above.
\begin{definition}
	An \vocab{algebraic number} is any $\alpha \in \CC$
	which is the root of \emph{some} polynomial with coefficients in $\QQ$.
	The set of algebraic numbers is denoted $\ol\QQ$.
\end{definition}
\begin{remark}
	One can equally well say algebraic numbers are those of which
	are roots of some polynomial with coefficients in $\ZZ$ (rather than $\QQ$),
	since any polynomial in $\QQ[x]$ can be scaled to one in $\ZZ[x]$.
\end{remark}
\begin{definition}
	Consider an algebraic number $\alpha$ and
	its minimal polynomial $P$
	(which is monic and has rational coefficients).
	If it turns out the coefficients of $P$ are integers,
	then we say $\alpha$ is an \vocab{algebraic integer}.

	The set of algebraic integers is denoted $\ol\ZZ$.
\end{definition}
\begin{remark}
	One can show, using \emph{Gauss's Lemma}, that if $\alpha$ is the root
	of \emph{any} monic polynomial with integer coefficients,
	then $\alpha$ is an algebraic integer.
	So in practice, if I want to prove that $\sqrt 2 + \sqrt 3$ is an algebraic integer,
	then I only have to say ``the polynomial $(x^2-5)^2-24$ works''
	without checking that it's minimal.
\end{remark}
Sometimes for clarity, we refer to elements of $\ZZ$
as \vocab{rational integers}.
\begin{example}[Examples of algebraic integers]
	The numbers
	\[ 4, \; i = \sqrt{-1}, \; \sqrt[3]{2}, \; \sqrt2+\sqrt3 \]
	are all algebraic integers, since they are the roots of the monic polynomials
	$x-4$, $x^2+1$, $x^3-2$ and $(x^2-5)^2-24$.

	The number $\half$ has minimal polynomial $x - \half$,
	so it's an algebraic number but not an algebraic integer.
	(In fact, the rational root theorem also directly implies
	that any monic integer polynomial does not have $\half$ as a root!)
\end{example}

There are two properties I want to give
for these off the bat,
because they'll be used extensively in the tricky
(but nice) problems at the end of the section.
The first we prove now, since it's very easy:
\begin{proposition}[Rational algebraic integers are rational integers]
	An algebraic integer is rational
	if and only if it is a rational integer.
	In symbols, \[ \ol\ZZ \cap \QQ = \ZZ. \]
\end{proposition}
\begin{proof}
	Let $\alpha$ be a rational number.
	If $\alpha$ is an integer, it is the root of $x-\alpha$,
	hence an algebraic integer too.

	Conversely, if $P$ is a monic polynomial with integer
	coefficients such that $P(\alpha) = 0$ then
	(by the rational root theorem, say)
	it follows $\alpha$ must be an integer.
\end{proof}
The other is that:
\begin{proposition}
	[$\ol{\ZZ}$ is a ring and $\ol{\QQ}$ is a field]
	The algebraic integers $\ol{\ZZ}$ form a ring.
	The algebraic numbers $\ol{\QQ}$ form a field.
\end{proposition}
We could prove this now if we wanted to,
but the results in the next chapter will more or less
do it for us, and so we take this on faith temporarily.

\section{Number fields}
\prototype{$\QQ(\sqrt2)$ is a typical number field.}

Given any algebraic number $\alpha$,
we're able to consider fields of the form $\QQ(\alpha)$.
Let us write down the more full version.

\begin{definition}
	A \vocab{number field} $K$ is a field containing $\QQ$ as a subfield
	which is a \emph{finite-dimensional} $\QQ$-vector space.
	The \vocab{degree} of $K$ is its dimension.
\end{definition}
\begin{example}[Prototypical example]
	Consider the field
	\[ K = \QQ(\sqrt2) = \left\{ a+b\sqrt2 \mid a,b \in \QQ \right\}. \]
	This is a field extension of $\QQ$,
	and has degree $2$ (the basis being $1$ and $\sqrt2$).
\end{example}

You might be confused that I wrote $\QQ(\sqrt2)$
(which should permit denominators) instead of $\QQ[\sqrt2]$, say.
But if you read through \Cref{ex:gaussian_rationals},
you should see that the denominators don't really matter:
$\frac{1}{3-\sqrt2} = \frac17(3+\sqrt2)$ anyways, for example.
You can either check this now in general,
or just ignore the distinction and pretend I wrote square brackets everywhere.
\begin{exercise}
	[Unimportant]
	Show that if $\alpha$ is an algebraic number,
	then $\QQ(\alpha) \cong \QQ[\alpha]$.
\end{exercise}

\begin{example}[Adjoining an algebraic number]
	Let $\alpha$ be the root of some irreducible polynomial $P(x)$ in $\QQ$.
	The field $\QQ(\alpha)$ is a field extension as well, and the basis
	is $1, \alpha, \alpha^2, \dots, \alpha^{m-1}$,
	where $m$ is the degree of $\alpha$.
	In particular, the degree of $\QQ(\alpha)$ is just the degree of $\alpha$.
\end{example}
\begin{example}[Non-examples of number fields]
	$\RR$ and $\CC$ are not number fields since there is no \emph{finite}
	$\QQ$-basis of them.
\end{example}

\section{Primitive element theorem, and monogenic extensions}
\prototype{$\QQ(\sqrt3,\sqrt5) \cong \QQ(\sqrt3+\sqrt5)$. Can you see why?}

I'm only putting this theorem here because I was upset that no one
told me it was true (it's a very natural conjecture),
and I hope to not do the same to the reader.
However, I'm not going to use it in anything that follows.

\begin{theorem}
	[Artin's primitive element theorem]
	Every number field $K$ is isomorphic to $\QQ(\alpha)$
	for some algebraic number $\alpha$.
	\label{thm:artin_primitive_elm}
\end{theorem}
The proof is left as \Cref{prob:artin_primitive_elm}, since to prove it I need to talk
about field extensions first.

The prototypical example \[ \QQ(\sqrt3,\sqrt5) \cong \QQ(\sqrt3+\sqrt5) \]
makes it clear why this theorem should not be too surprising.
%To see why this is true, note that $K$ contains the element
%\[ \left( \sqrt3+\sqrt5 \right)^2-8 = 2\sqrt15 \]
%and hence also the element $2(\sqrt15)(\sqrt3+\sqrt5) = 6\sqrt5+10\sqrt3$.
%Thus from the fact that $6\sqrt5+10\sqrt3$ and $\sqrt3+\sqrt5$ are in $K$,
%we can extract both $\sqrt 3$ and $\sqrt 5$.
%Thus $\sqrt3, \sqrt5 \in K$, which is what we wanted.

\section{\problemhead}

\begin{problem}
	Find a polynomial with integer coefficients
	which has $\sqrt2+\sqrt[3]{3}$ as a root.
\end{problem}

\begin{problem}
	[Brazil 2006]
	\gim
	Let $p$ be an irreducible polynomial in $\QQ[x]$
	and degree larger than $1$.
	Prove that if $p$ has two roots $r$ and $s$ whose product is $1$
	then the degree of $p$ is even.
	\begin{hint}
		Note that $p(x)$ is a minimal polynomial for $r$,
		but so is $q(x) = x^{\deg p} p(1/x)$.
		So $q$ and $p$ must be multiples of each other.
	\end{hint}
\end{problem}

\begin{sproblem}
	\label{prob:rep_lemma}
	Consider $n$ roots of unity $\eps_1$, \dots, $\eps_n$.
	Assume the average $\frac1n(\eps_1 + \dots + \eps_n)$ is an algebraic integer.
	Prove that either the average is zero or $\eps_1 = \dots = \eps_n$.
	(Used in \Cref{lem:burnside_ant_lemma}.)
	\begin{hint}
		$\left\lvert \frac 1n(\eps_1 + \dots + \eps_n) \right\rvert \le 1$.
	\end{hint}
\end{sproblem}

\begin{dproblem}
	\gim
	Which rational numbers $q$ satisfy $\cos(q\pi) \in \QQ$?
	\begin{hint}
		Only the obvious ones.
		Assume $\cos(q\pi) \in \QQ$.
		Let $\zeta$ be a root of unity (algebraic integer
		as $\zeta^N-1 = 0$ for some $N$)
		and note that $2\cos(q\pi) = \zeta + \zeta^{N-1}$
		is both an algebraic integer and a rational number.
	\end{hint}
\end{dproblem}

\begin{problem}
	[MOP 2010]
	There are $n > 2$ lamps arranged in a circle;
	initially one is on and the others are off.
	We may select any regular polygon whose vertices are among the lamps
	and toggle the states of all the lamps simultaneously.
	Show it is impossible to turn all lamps off.
	\begin{hint}
		View as roots of unity. Note $\half$ isn't an algebraic integer.
	\end{hint}
\end{problem}

\begin{problem}[Kronecker's theorem]
	\yod
	Let $\alpha$ be an algebraic integer.
	Suppose all its Galois conjugates have absolute value one.
	Prove that $\alpha^N=1$ for some positive integer $N$.
	\begin{hint}
		Let $\alpha = \alpha_1$, $\alpha_2$, \dots, $\alpha_n$ be its conjugates.
		Look at the polynomial $(x-\alpha_1^e) \dots (x-\alpha_n^e)$ across $e \in \NN$.
		Pigeonhole principle on all possible polynomials.
	\end{hint}
\end{problem}

\begin{problem}
	\yod
	Is there an algebraic integer with absolute value one
	which is not a root of unity?
\end{problem}

\begin{problem}
	Is the ring of algebraic integers Noetherian?
\end{problem}


\subsection{Recap}

In the multinomial logit model we had:

\(P_{ij}=\dfrac{e^{\Theta z_j}}{1+\sum_{k=1} e^{\Theta z_k }}\)

\subsection{Adding customer characteristics}

If \(z_j\) just includes product characteristics then we have homogeneous preferences.

We can include customer level data in \(z_j\), for example individual income, location, age etc.

\subsection{Estimation}

As before, we want product characteristics and prices.

However rather than market share we instead use customer level  information.


\chapter{Lecture 13 May 30th 2018}%
\label{chp:lecture_13_may_30th_2018}
% chapter lecture_13_may_30th_2018

\section{Isomorphism Theorems (Continued)}%
\label{sec:isomorphism_theorems_continued}
% section isomorphism_theorems_continued

\subsection{Quotient Groups (Continued)}%
\label{sub:quotient_groups_continued}
% subsection quotient_groups_continued

\begin{propo}
\label{propo:propo_related_to_quotient_groups}
  Let $K \triangleleft G$ and write $\faktor{G}{K} = \{Ka \, : \, a \in G\}$ for the set of cosets of $K$.
  \begin{enumerate}
    \item $\faktor{G}{K}$ is a group under the operation $Ka Kb = Kab$.
    \item The mapping $\phi : G \to \faktor{G}{K}$ given by $\phi(a) = Ka$ is a surjective homomorphism.\sidenote{
    \begin{ex}
      Is $\phi$ injective?
    \end{ex}

    \begin{solution}
      We know that we cannot uniquely express a coset, since for $a, b \in Ka$ such that $a \neq b$, we have that $Ka = Kb$.
    \end{solution}
    }
    \item If $[G : K]$ is finite, then $\abs{\faktor{G}{K}} = [G : K]$. In particular, if $\abs{G}$ is finite, then $\abs{\faktor{G}{K}} = \frac{\abs{G}}{\abs{K}}$.
  \end{enumerate}
\end{propo}

\begin{proof}
  \begin{enumerate}
    \item By \cref{lemma:multiplication_of_cosets_of_normal_subgroups}, the operation is well-defined, and $\faktor{G}{K}$ is closed under the operation. The identity of $\faktor{G}{K}$ is $K = K(1)$ since $\forall Ka \in \faktor{G}{K}$,
      \begin{equation*}
        Ka K(1) = Ka = K(1) Ka.
      \end{equation*}
      Also, since
      \begin{equation*}
        Ka Ka^{-1} = K(1) = Ka^{-1} Ka,
      \end{equation*}
      the inverse of $Ka$ is $Ka^{-1}$. Finally, by associativity of $G$, we have that
      \begin{equation*}
        Ka(KbKc) = Kabc = (KaKb)Kc.
      \end{equation*}
      It follows that $\faktor{G}{K}$ is a group.

    \item Clearly, $\phi$ is surjective. For $a, b \in G$,
      \begin{equation*}
        \phi(ab) = Kab = Ka Kb = \phi(a) \phi(b).
      \end{equation*}
      Thus $\phi$ is a surjective homomorphism.

    \item If $[G : K]$ is finite, then by definition of the index $[G : K]$, we have that $[G : K] = \abs{\faktor{G}{K}}$. Also, if $\abs{G}$ is finite, then by \cref{thm:lagrange_s_theorem},
      \begin{equation*}
        \abs{\faktor{G}{K}} = [G : K] = \frac{\abs{G}}{\abs{K}}.
      \end{equation*}
  \end{enumerate}\qed
\end{proof}

\begin{defn}[Quotient Group]\index{Quotient Group}\index{Coset Map}\index{Quotient Map}
\label{defn:quotient_group}
  Let $K \triangleleft G$. The group $\faktor{G}{K}$ of all cosets of $K$ in $G$ is called the \hlnoteb{quotient group} of $G$ by $K$. Also, the mapping
  \begin{equation*}
    \phi: G \to \faktor{G}{K} \text{ defined by } a \mapsto Ka
  \end{equation*}
  is called the \hlnoteb{coset} (or \hlnoteb{quotient}) \hlnoteb{map}.
\end{defn}

% subsection quotient_groups_continued (end)

\subsection{Isomorphism Theorems}%
\label{sub:isomorphism_theorems}
% subsection isomorphism_theorems

\begin{defn}[Kernel and Image]\index{Kernel}\index{Image of a Homomorphism}
\label{defn:kernel_and_image}
  Let $\alpha: G \to H$ be a group homomorphism. The \hlnoteb{kernel} of $\alpha$ is defined by
  \begin{equation*}
    \ker \alpha := \{g \in G \, : \, \alpha(g) = 1_H \} \subseteq G
  \end{equation*}
  and the image of $\alpha$ is defined by
  \begin{equation*}
    \img \alpha := \alpha(G) = \{\alpha(g) \, : \, g \in G \} \subseteq H.
  \end{equation*}
\end{defn}

\begin{propo}
\label{propo:image_of_hm_is_a_subgroup_n_kernel_of_hm_is_a_normal_subgroup}
  Let $\alpha : G \to H$ be a group homomorphism.
  \begin{enumerate}
    \item $\img \alpha$ is a subgroup of $H$
    \item $\ker \alpha \triangleleft G$
  \end{enumerate}
\end{propo}

\begin{proof}
  \begin{enumerate}
    \item Note that $1_H = \alpha(1_G) \in \alpha(G)$ (i.e. the identity is in $\img \alpha$). Also, for $h_1 = \alpha(g_1)$ and $h_2 = \alpha(g_2)$ in $\alpha(G)$ and $h_1, h_2 \in H$, we have
      \begin{equation*}
        h_1 h_2 = \alpha(g_1) \alpha(g_2) = \alpha(g_1 g_2) \in \alpha(G).
      \end{equation*}
      (i.e. $\img \alpha$ i closed under its operation). By \cref{propo:properties_of_homomorphism}, $\alpha(g)^{-1} = \alpha(g^{-1}) \in \alpha(G)$ (i.e. the inverse of an element is also in $\img \alpha$). Thus by the \hlnotea{Subgroup Test}, we have that $\img \alpha$ is a subgroup of $H$.

    \item For $\ker \alpha$, $\alpha(1_G) = 1_H$. For $k_1, k_2 \in \ker \alpha$, we have
      \begin{equation*}
        \alpha(k_1 k_2) = \alpha(k_1) \alpha(k_2) = 1 \cdot 1 = 1.
      \end{equation*}
      Also,
      \begin{equation*}
        \alpha(k_1^{-1}) = \alpha(k_1)^{-1} = 1^{-1} = 1.
      \end{equation*}
      By the \hlnotea{Subgroup Test}, $\ker \alpha$ is a subgroup of $G$.

      If $g \in G$ and $k \in \ker \alpha$, then
      \begin{equation*}
        \alpha(gkg^{-1}) = \alpha(g) \alpha(k) \alpha(g^{-1}) = \alpha(g) \alpha(g^{-1}) = 1.
      \end{equation*}
      Thus by \cref{propo:normality_test}, $\ker \alpha \triangleleft G$.
  \end{enumerate}\qed
\end{proof}

\begin{eg}
  Consider the determinant map
  \begin{equation*}
    \det : GL_n(\mathbb{R}) \to \mathbb{R}^* \text{ defined by } A \mapsto \det A.
  \end{equation*}
  Then $\ker \det = SL_n(\mathbb{R})$. Then $SL_n(\mathbb{R}) \triangleleft GL_n(\mathbb{R})$, as proven before.
\end{eg}

\begin{eg}
  Define the \hldefn{sign of a permutation} $\sigma \in S_n$ by
  \begin{equation*}
    \sign(\sigma) = \begin{cases}
      1 & \text{if } \sigma \text{ is even;} \\
      -1 & \text{if } \sigma \text{ is odd.}
    \end{cases}
  \end{equation*}
  Then the sign mapping, $\sign : S_n \to \{\pm 1\}$ defined by $\sigma \mapsto \sign(\sigma)$ is a homomorphism.\sidenote{Think about why. It's quite straightforward using the defintion.} Also, $\ker \sign = A_n$. Thus, we have $A_n \triangleleft S_n$, as proven before.
\end{eg}

\begin{propo}[Normal Subgroup as the Kernel]
\label{propo:normal_subgroup_as_the_kernel}
  If $K \triangleleft G$, then $K = \ker \phi$ where $\phi : G \to \faktor{G}{K}$ is the coset map.
\end{propo}

\begin{proof}
  Recall that $\phi : G \to \faktor{G}{K}$ is defined by $g \mapsto Kg$, $\forall g \in G$, and is a group homomorphism. By \cref{propo:properties_of_cosets}, we have
  \begin{equation*}
    Kg = K = K1 \iff g \in K.
  \end{equation*}
  Thus $K = \ker \phi$.\qed
\end{proof}

\begin{thm}[First Isomorphism Theorem]
\index{First Isomorphism Theorem}
\label{thm:first_isomorphism_theorem}
  Let $\alpha: G \to H$ be a group homomorphism. We have
  \begin{equation*}
    \faktor{G}{\ker \alpha} \cong \img \alpha
  \end{equation*}
\end{thm}

\begin{proof}
  Let $K = \ker \alpha$. Since $K \triangleleft G$ (by \cref{propo:image_of_hm_is_a_subgroup_n_kernel_of_hm_is_a_normal_subgroup}), $\faktor{G}{K}$ is a group. Let\sidenote{We must check that the function is well-defined, since cosets are not uniquely represented and so it is likely that a constructed mapping is not well-defined.}
  \begin{equation*}
    \bar{\alpha} : \faktor{G}{K} \to \img \alpha \text{ be defined by } Kg \mapsto \alpha(g)
  \end{equation*}
  Note that
  \begin{equation*}
    Kg = Kg_1 \iff gg_1^{-1} \in K \iff \alpha(gg_1^{-1}) = 1 \iff \alpha(g) = \alpha(g_1).
  \end{equation*}
  Thus $\bar{ \alpha }$ is well-defined and injective. Clearly, $\bar{ \alpha }$ is surjective. It remains to show that $\bar{\alpha}$ is a group homomorphism. $\forall g, h \in G$, we have
  \begin{equation*}
    \bar{\alpha}(Kg Kh) = \bar{\alpha}(Kgh) = \alpha(gh) = \alpha(g) \alpha(h) = \bar{\alpha}(Kg) \bar{\alpha}(Kh).
  \end{equation*}
  Therefore, we have that $\bar{\alpha}$ is an isomorphism and hence $\faktor{G}{\ker \alpha} \cong \img \alpha$ as desired. \qed
\end{proof}

% subsection isomorphism_theorems (end)

% section isomorphism_theorems_continued (end)

% chapter lecture_13_may_30th_2018 (end)