%% -*- coding:utf-8 -*-
\section{Monoidal object}

Monoid plays very important role in category theory

\section{Monoid in \textbf{Set}}
Lets consider \mynameref{def:monoid} in the terms of Set theory and
will try to give the definition that is based rather on morphisms then
on internal set structure. Consider a set $M$ and by the definition
$\forall m_1, m_2 \in M$ we can define a new element of the set
$\mu(m_1, m_2) \in M$. Later we will use the following notation for
the $\mu$:
\[
\mu(m_1, m_2) \equiv m_1 \cdot m_2.
\]
If the $(M, \cdot)$ is monoid then the following 2 conditions have to
be satisfied. The first one (associativity) declares that $\forall
m_1, m_2, m_3 \in M$
\[
m_1 \cdot ( m_2 \cdot m_3) = ( m_1 \cdot
m_2 ) \cdot m_3.
\]
The second one (identity presence) says that
\(
\exists e \in M
\) such that $\forall m \in M$:
\begin{equation}
m \cdot e = e \cdot m = m.
\label{eq:monoid2}
\end{equation}

Lets start with the first one we can define $\mu$ as
\mynameref{def:morphism} in the following way $\mu: M\times M \to M$
where $M \times M$ is \mynameref{ex:set_product} in
\mynameref{def:setcategory}. I.e. $M, M \times M \in \catob{Set}$ and
$\mu \in \cathom{Set}$.  Consider another objects of $\cat{Set}$: $A =
M \times \left( M \times M \right)$ and $A' = \left( M \times M \right)
\times M$. They are not the same but there is a trivial
\mynameref{def:isomorphism} between them $A \cong_\alpha A'$, where
\[
\alpha(x,(y,z)) = ((x,y),z).
\]
Consider the action of \mynameref{def:product_of_morphisms}
$\idm{M} \times \mu$ on $A$:
\[
\idm{M} \times \mu \left(x,\left(y,z\right)\right) =
\left(\idm{M}(x),\mu\left(y,z\right)\right) =
\left(x, y \cdot z\right) \in M \times M
\]
i.e. $\idm{M} \times \mu: M \times \left( M \times M \right) \to M
\times M$. If we act $\mu$ on the result we will get:
\begin{eqnarray}
\mu \left(\idm{M} \times \mu \left(x,\left(y,z\right)\right)\right) =
\left(\idm{M}(x),\mu\left(y,z\right)\right) =
\nonumber \\
=
\mu\left(x, y \cdot z\right) = x \cdot (y\cdot z) \in M,
\nonumber
\end{eqnarray}
i.e.
$\mu \circ \left(\idm{M} \times \mu\right): M \times \left( M \times M
\right) \to M$.

For $A'$ we have the following one:
\begin{eqnarray}
\mu\circ\left(\mu \times \idm{M}\right)\left(\left(x,y\right),z\right)
= \mu\left(x \cdot y, z\right) = (x \cdot y) \cdot z.
\nonumber
\end{eqnarray}
Monoid associativity requires
\[
x \cdot (y\cdot z) =
(x \cdot y) \cdot z
\]
i.e. the morphisms the corresponding morphisms commute:
\[
\mu\circ\left(\mu \times \idm{M}\right) =
\mu \circ \left(\idm{M} \times \mu\right) \circ \alpha.
\]
This corresponds the diagram is at \cref{fig:monoid_mu_alpha}.

\begin{figure}
  \centering
  \begin{tikzpicture}[ele/.style={fill=black,circle,minimum
        width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
        sep=-2pt}]

    % the texts

    \node[ele,label=above:$M\times\left(M \times M\right)$] (M31) at (0,3) {};
    \node[ele,label=above:$\left(M \times M\right)\times M$] (M32) at (6,3) {};
    \node[ele,label=below:$M \times M$] (M21) at (0,0) {};
    \node[ele,label=below:$M \times M$] (M22) at (6,0) {};
    \node[ele,label=below:$M$] (M) at (3,0) {};

    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M31) to
    node[sloped,above]{$\alpha$} (M32);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M31) to
    node[sloped,below]{$\idm{M} \times \mu$} (M21);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M32) to
    node[sloped,below]{$\mu \times \idm{M}$} (M22);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M22) to
    node[sloped,above]{$\mu$} (M);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M21) to
    node[sloped,above]{$\mu$} (M);
  \end{tikzpicture}
  \caption{Commutative diagram for $\mu\circ\left(\mu \times
    \idm{M}\right) = \mu \circ \left(\idm{M} \times \mu\right) \circ
    \alpha$.}
  \label{fig:monoid_mu_alpha}
\end{figure}
Very often the isomorphism $\alpha$ is omitted i.e.
\[
M\times\left(M \times M\right)
= \left(M \times M\right)\times M = M^3
\]
and the morphism
equality is written as follow
\[
\mu\circ\left(\mu \times \idm{M}\right) =
\mu \circ \left(\idm{M} \times \mu\right)
\]
The corresponding commutative diagram is shown in
\cref{fig:monoid_mu}.
\begin{figure}
  \centering
  \begin{tikzpicture}[ele/.style={fill=black,circle,minimum
        width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
        sep=-2pt}]

    % the texts

    \node[ele,label=above:$M^3$] (M3) at (0,3) {};
    \node[ele,label=above:$M \times M$] (M21) at (3,3) {};
    \node[ele,label=below:$M \times M$] (M22) at (0,0) {};
    \node[ele,label=below:$M$] (M) at (3,0) {};

    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M3) to
    node[sloped,below]{$\idm{M} \times \mu$} (M21);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M3) to
    node[sloped,above]{$\mu \times \idm{M}$} (M22);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M22) to
    node[sloped,above]{$\mu$} (M);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M21) to
    node[sloped,above]{$\mu$} (M);
  \end{tikzpicture}
  \caption{Commutative diagram for $\mu\circ\left(\mu \times
    \idm{M}\right) = \mu \circ \left(\idm{M} \times \mu\right)$.}
  \label{fig:monoid_mu}
\end{figure}

For \eqref{eq:monoid2} consider a morphism $\eta$ from
a one point set $I = \{0\}$ to a special element $e \in M$ such that
$\forall m \in M: e \cdot m = m \cdot e = m$. I.e. $\eta: I \to M$ and
$e = \eta(0)$. Consider 2 sets $B = I \times M$ and $B' = M \times I$.
We have 2 \mynameref{def:isomorphism}s: $B \cong_\lambda M$ and $B'
\cong_\rho M$ where the isomorphisms are defined as follow
\[
\lambda(0, m) = m
\]
and
\[
\rho(m, 0) = m.
\]

If we apply \mynameref{def:product_of_morphisms} $\eta \times \mu$ and
$\mu \times \eta$ on $B$ and $B'$ respectively then we get
\begin{eqnarray}
\eta \times \idm{M} \left(0 \times m\right) = e \times m,
\nonumber \\
\idm{M} \times \eta \left(m \times 0\right) = m \times e.
\nonumber
\end{eqnarray}
If we apply $\mu$ on the result then we get
\begin{eqnarray}
\mu \left(\eta \times \idm{M} \left(0 \times m\right) \right) = e \cdot m,
\nonumber \\
\idm{M} \times \eta \left(m \times 0\right) = m \times e.
\nonumber
\end{eqnarray}
\begin{figure}
  \centering
  \begin{tikzpicture}[ele/.style={fill=black,circle,minimum
        width=.8pt,inner sep=1pt},every fit/.style={ellipse,draw,inner
        sep=-2pt}]

    % the texts

    \node[ele,label=above:$M$] (M') at (0,3) {};
    \node[ele,label=above:$M \times M$] (M21) at (3,3) {};
    \node[ele,label=below:$M \times M$] (M22) at (0,0) {};
    \node[ele,label=below:$M$] (M) at (3,0) {};

    \draw [double equal sign distance] (M') to (M);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M') to
    node[sloped,below]{$\lambda$} (M21);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M') to
    node[sloped,above]{$\rho$} (M22);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M22) to
    node[sloped,above]{$\mu$} (M);
    \draw[->,thick,shorten <=2pt,shorten >=2pt] (M21) to
    node[sloped,above]{$\mu$} (M);
  \end{tikzpicture}
  \caption{Commutative diagram for $\mu \circ (\eta \times \idm{M})
    \circ \lambda = \mu \circ (\idm{M} \times \mu) \circ \rho =
    \idm{M}$ .}
  \label{fig:monoid_eta_lambda_rho}
\end{figure}
The \eqref{eq:monoid2} leads to the following equation for morphisms
\[
\mu \circ (\eta \times \idm{M}) \circ \rho =
\mu \circ (\idm{M} \times \mu) \circ \lambda =
\idm{M}
\]
or the commutative diagram show on \cref{fig:monoid_eta_lambda_rho}.

\section{Monoidal object}
If we take into consideration that one-point set is
\mynameref{ex:set_terminal_object} then we can conclude that the
monoid can be defined for instance in a \mynameref{def:cartesian_closed_category}
as follow
\begin{definition}[Monoidal object]
\label{def:monoidal_object}
Consider a \mynameref{def:category} $\cat{C}$ with a
\mynameref{def:terminal_object} $t \in \catob{C}$. The object $m \in
\catob{C}$ is called \textit{monoidal object} if the following
conditions satisfied:
\begin{enumerate}
\item the \mynameref{def:product}s $m \times m, m \times t, t \times
  m$ exist
\item there is a \mynameref{def:morphism} $\mu: m \times m \to m$ in
  the category
\item there is another morphism $\eta: t \to m$
\item the morphisms satisfy the following conditions:
\begin{eqnarray}
\mu\circ\left(\mu \times
    \idm{M}\right) = \mu \circ \left(\idm{M} \times \mu\right) \circ
    \alpha,
\nonumber \\
\mu \circ (\eta \times \idm{M})
\circ \lambda = \mu \circ (\idm{M} \times \mu) \circ \rho =
\idm{M}
\nonumber
\end{eqnarray}
where $\alpha$ (associator) is an isomorphism between $m \times (m
\times m)$ and $(m \times m) \times m$, $\lambda, \rho$ - 2 another
isomorphisms:
\[
t \times m \cong_\lambda m
\]
and
\[
m \times t \cong_\rho m
\]
\end{enumerate}
\end{definition}


%---------------------------Shear and Size---------------------------
\section{Shear and Size\label{s:hex-shear-and-size}}

Let $R$ be the relative size squared as defined in \S\ref{s:hex-relative-size-squared}
and $H$ be the shear as defined in \S\ref{s:hex-shear}.
The ``shear and size'' metric is the the product of these two numbers:
\[
  q = RH
\]

\hexmetrictable{shear and size}%
{$1$}%                                        Dimension
{$[0.2,1]$}%                                  Acceptable range
{$[0,1]$}%                                    Normal range
{$[0,1]$}%                                    Full range
{Dependent on $\overline{V}$}%                Cube
{\cite{knu:03}}%                              Citation
{v\_hex\_shear\_and\_size}%                   Verdict function name


% !TEX encoding = UTF-8 Unicode
% !TEX spellcheck = en_US
% !TEX root = ../../../ICMA2020.tex

\subsection{Model Reduction Algorithm}
A parameter identification in a process not optimized for this purpose leads to a significantly worse identifiability compared to an optimized excitation trajectory due to the sub-optimal excitation of the individual parameters.
In order to still perform a parameter estimation directly on a process the robot model has to be reduced.
According to \cite{Brun2001} two factors can be distinguished that lead to poor identifiability and a high condition number: sensitivity problems and collinearity problems.
Sensitivity can differ between parameters so that some parameters affect the output only negligibly while others dominate. Collinearity means that the effect of one parameter is compensated by the interplay of other parameters.

Many model order reduction techniques strive to establish a new basis without multi-collinearities, which is possibly even orthogonal.
Here these approaches are prohibited by the fact that the interpretability of the base parameters should be preserved in the sense of the linear combination of physical parameters in (\ref{eq:Parametersatz}).
A different approach is to delete parameters that are involved in collinearity problems \cite{Akinniyi2017}, but this could change the prediction of the model considerably if the respective parameter is important.
Therefore, only the sensitivity problem is addressed here. As the model can be written linear in the parameters, see \eqref{eq:model_regressor}, it is possible to remove those parameters with a low sensitivity on a per-parameter basis. The parameter sensitivities depend on the excitation but not on the parameter values. For a particular excitation the sensitivity matrix is given by the design matrix $\boldsymbol{C}$.
To characterize the sensitivity of a parameter $i$ with a single value the mean of the respective column $\overline{c}_i$ of $\boldsymbol{C}$ over all joints is used:
%\begin{equation}\label{eq:mean_Sensitivity}
%	\overline{c}_i = \frac{1}{6N} \sum_{i = 1}^{6N} \left| \boldsymbol{c}_i \right| \text{ with } \boldsymbol{C} = (\boldsymbol{c}_1, \boldsymbol{c}_2, %\hdots, \boldsymbol{c}_i).
%\end{equation}
\begin{equation}\label{eq:mean_Sensitivity}
	\overline{c}_i = \frac{1}{6N} \| \boldsymbol{c}_i \|_1 \text{ with } \boldsymbol{C} = (\boldsymbol{c}_1, \boldsymbol{c}_2, \hdots, \boldsymbol{c}_i).
\end{equation}

The model error that is introduced by removing a particular parameter is evaluated using the error between the measured data $\boldsymbol{\tau}$ and the model prediction $\hat{\boldsymbol{\tau}}$. The mean absolute error
\begin{equation}\label{eq:absError}
	e_{k,j} = \frac{1}{N}  \sum\limits_{p=1}^{N} \left| \tau_j(t_p) - \hat{\tau}_{k,j}(t_p) \right|,
\end{equation}
and the relative error
\begin{equation}\label{eq:relError}
	e^*_{k,j} = \frac{e_{k,j}}{\frac{1}{N} \sum\limits_{p=1}^{N} \left| \tau_j(t_p) \right|}
\end{equation}
are calculated in every step $k$ for all joints $j$. If removing a parameter would lead to a large model error, this parameter is retained.

The following is a detailed description of the proposed approach, explained along the pseudo code in algorithm\,\ref{alg:ModelReductionAlgorithm}. It can be characterized as a \textit{backward stepwise selection} \cite{Volinsky1997} because starting from the full model parameters are removed successively.

The algorithm begins with calculating the initial design matrix $\boldsymbol{C}_0$ for the full model (line 1). It is checked if the design matrix is of full rank, so that all parameters are identifiable. Given that the parameter estimation is to be performed directly on a process and not with an optimized trajectory, some parameters may not be identifiable. In such a case the parameters in question must be removed prior to the model reduction.

If the design matrix is of full rank, a first parameter estimation with the full model needs to be carried out (line 2). Based on that the absolute and relative model errors $e_{0,j}$ and $e^*_{0,j}$ are calculated (line 3). These values will be the reference to determine if a parameter is negligible for the model.

\begin{algorithm}[ht]
\caption{Pseudo code of the model reduction algorithm.}\label{alg:ModelReductionAlgorithm}
	\begin{algorithmic}[1]
	%\State Load data
	%\State Calculate design matrix $\boldsymbol{C}$
	\State Examine rank of design matrix $\boldsymbol{C}_k$ (initially $\boldsymbol{C}_0$)
	\State Calculate $\hat{\boldsymbol{\theta}}_{0}$ using WLS
	\State Calculate $e_{0,j}$, $e^*_{0,j}$
	\State Initialize $I$ and $E$
	\For {$k =1,2,\ldots,n_i$}
		%\State Construct design matrix with parameters $i \in I$
		%\State Calculate $\overline{c}_i$ for $i \in I$
		\State Calculate $\arg \min_{i} (\overline{c}_i)$ with $i \in I \wedge i \notin E$
		\State Remove parameter $i$
		\State Calculate $\hat{\boldsymbol{\theta}}_{k}$ using WLS
		\State Calculate $e_{k,j}$, $e^*_{k,j}$
		\If {$\frac{e^*_{k,j}}{e^*_{0,j}} \geq e_{\text{tol}} \text{ } \forall j$}
			\State Add parameter $i$ to $E$
		\Else
			\State Remove parameter $i$ from $I$
		\EndIf
	\EndFor
	\end{algorithmic}
\end{algorithm}

Sets $I$ (included) and $E$ (essential) are initialized  (line 4): Set $I$ represents the parameters which are still included in the model in a given iteration and is initialized to contain all parameters. Set $E$ contains all parameters which are indispensable for the model. The friction may be indispensable for the model if all joints perform a sufficient motion during the observed process. In this case  $E$ will include the friction parameters, otherwise set $E$ is initialized empty.

The model reduction is then performed in a loop which iterates over all $n_i=35$ parameters in the model. First the design matrix needs to be constructed with the parameters defined by $I$ and $E$ (line 6). Then the parameter with the lowest sensitivity is determined using $\overline{c}_i$ from \eqref{eq:mean_Sensitivity} and removed from the model (line 7). With the resulting reduced model a parameter estimation is carried out using the WLS method and the absolute and relative model errors $e_{k,j}$ and $e^*_{k,j}$ are calculated (line 8 and 9).

In a final step it needs to be determined if the removed parameter is negligible for the model (line 10). The parameter can be considered negligible if the relative model error $e^*_{k,j}$ in step $k$ is within a pre-defined tolerance margin $e_{\mathrm{tol}}$ with respect to the reference value $e^*_{0,j}$ for all joints $j$.% Removing the friction parameters may result in a reduced model which is within the error tolerance, but the robustness of the parameter estimation is negatively impacted. This can be seen in a high condition number of the reduced model which means the parameters are not equally excited and therefore poorly identified.

The advantage of the algorithm is that it removes unimportant parameters so that the model error keeps low, but since the condition number is not optimized directly its improvement may be small. Nevertheless, it has been found in several experiments that the condition number is also improved.


\section{Converge to Equilibrium}
Theorem \ref{power_inv} tells us that we might be able to obtain an invariant measure of a Markov chain by looking at the limit $p_{ij}^{(n)}$ as $n\to\infty$.
Of course, this does not always work.
\begin{example}[Non-example]
    Take
    $$P=\begin{pmatrix}
        0&1\\
        1&0
    \end{pmatrix}$$
    then $P^n$ does not converge as $n\to\infty$ but it has an invariant distribution $(1/2,1/2)$.
    This is an example of what is called a periodic Markov chain.
\end{example}
But we want to find cases where it does work.
The previous example motivates the following definition.
\begin{definition}
    A state $i\in I$ is aperiodic if $p_{ii}^{(n)}>0$ for sufficiently large $n$.
    $P$ is periodic if all $i\in I$ are periodic.
\end{definition}
\begin{lemma}
    Let $P$ be irreducible and some $i\in I$ is aperiodic, then for all $j,k\in I$, $p_{jk}^{(n)}>0$ for sufficiently large $n$.
\end{lemma}
In particular, in an irreducible Markov chain, one state being aperiodic implies all states being aperiodic.
\begin{proof}
    Choose $r,s$ such that $p_{ji}^{(r)}>0$ and $p_{ik}^{(s)}>0$.
    Then
    $$p_{jk}^{(r+n+s)}\ge p_{ji}^{(r)}p_{ii}^{(n)}p_{ik}^{(s)}>0$$
    for sufficiently large $n$.
\end{proof}
Here we are ready to state our main theorem.
\begin{theorem}\label{aperiodic_conv}
    Let $P$ be irreducible and aperiodic and suppose $\pi$ is an invariant distribution for $P$.
    Let $\lambda$ be any distribution and suppose $(X_n)\sim\operatorname{Markov}(\lambda,P)$, then for all $j\in I$ we have $\mathbb P[X_n=j]\to\pi_j$ as $n\to\infty$.
\end{theorem}
In particular, $p_{ij}^{(n)}\to\pi_j$ as $n\to\infty$ for any $i,j\in I$.
The proof uses a very interesting trick called coupling.
Behold.
\begin{proof}
    Let $(Y_n)\sim\operatorname{Markov}(\pi,P)$ and independent of $(X_n)$.
    Fix a reference state $b\in I$ and set $T=\inf\{n\ge 1:X_n=Y_n=b\}$.
    We claim that $\mathbb P[T<\infty]=1$.
    Now $W_n=(X_n,Y_n)$ is a Markov chain $\tilde{P}$ on the state space $I\times I$ and the transition probability is obviously
    $$\tilde{p}_{(i,k)(j,l)}=p_{ij}p_{kl}$$
    with initial distribution $\tilde{\lambda}_{(i,k)}=\lambda_i\pi_k$.
    As $P$ is irreducible and aperiodic, the preceding lemma implies that $\tilde{p}_{(i,k)(j,l)}^{(n)}>0$ for sufficiently large $n$.
    In particular, $\tilde{P}$ is irreducible.
    Also, it has invariant distribution $\tilde{\pi}_{(i,k)}=\pi_i\pi_k$, which implies that $\tilde{P}$ is positive recurrent.
    In addition $T$ is the first passage time of $(W_n)$ to $(b,b)$.
    Since $P$ is irreducible and recurrent, $\mathbb P[T<\infty]=1$ as desired.
    It follows that, by Theorem \ref{strong_markov},
    \begin{align*}
        \mathbb P[X_n=i]&=\mathbb P[X_n=i,n<T]+\mathbb P[X_n=i,n\ge T]\\
        &=\mathbb P[X_n=i,n<T]+\mathbb P[Y_n=i,n\ge T]\\
        &=\mathbb P[X_n=i,n<T]+\pi_i-\mathbb P[Y_n=i,n< T]
    \end{align*}
    Therefore by rearranging,
    \begin{align*}
        |\mathbb P[X_n=i]-\pi_i|&=|\mathbb P[X_n=i,n<T]-\mathbb P[Y_n=i,n< T]|\\
        &\le\mathbb P[n<T]\to 0
    \end{align*}
    as $n\to\infty$ since $\mathbb P[T<\infty]=1$.
\end{proof}
What would go wrong if the Markov chain is not aperiodic?
\begin{example}
    Take as usual
    $$P=\begin{pmatrix}
        0&1\\
        1&0
    \end{pmatrix}$$
    We know that $\pi=(1/2,1/2)$ is an invariant distribution.
    If $X\sim\operatorname{Markov}(\delta_0,P)$ and $Y\sim\operatorname{Markov}(\pi,P)$, then $X_n,Y_n$ will never meet.
\end{example}
We want to get a grip of what happens when $X_n$ is periodic (i.e. not aperiodic).
We will not include proofs as they are not in the scope of this course, but we will state some results and the ones who are interested can find out further in J. R. Norris's book.
\begin{lemma}
    Let $P$ be irreducible.
    There exists an integer $d\ge 1$ and a partition $I=C_0\cup\cdots\cup C_{d-1}$ such that:\\
    1. $p_{ij}^{(n)}>0$ only if $i\in C_r$ and $j\in C_{r+n}$ for some $r$ where the indices of $C_k$ are taken modulo $d$.\\
    2. For any $r$ and $i,j\in C_r$ we have $p_{ij}^{(nd)}>0$ for sufficiently large $n$.
\end{lemma}
Such a $d$ is called the period of a periodic markov chain.
The $d=1$ case corresponds to the aperiodic case.
\begin{theorem}
    Let $P$ be irreducible of period $d$ with $C_0,\ldots, C_{d-1}$ as in the preceding lemma.
    Let $\lambda$ be a distribution with $\sum_{i\in C_0}\lambda_i=1$.
    Suppose $(X_n)\sim\operatorname{Markov}(\lambda,P)$, then for $r=0,\ldots,d-1$ and $j\in C_r$,
    $$\mathbb P[X_{nd+r}=j]\to\frac{d}{m_j}$$
    as $n\to\infty$ where $m_j$ is the expected return time to $j$.
\end{theorem}
This is a pretty intuitive generalisation of Theorem \ref{aperiodic_conv} by setting $d=1$.


\subsection{Helper methods}
There are 4 helper methods to handle our abstract map:\\

$\begin{array}{rl}
\wsf{contains} & \in \AMap \times \AKey \rightarrow \wbf{Boolean} \\
\wsf{lookup} & \in \AMap \times \AKey \rightarrow \AVal \times \wbf{Boolean} \\
\wsf{update} & \in \AMap \times \AKey \times \AVal \rightarrow \AMap \\
\wsf{delete} & \in \AMap \times \AKey \rightarrow \AMap \\
\end{array}$\\\\

\textbf{Monotonicity } ??\\

\textbf{Soundness }
We proved the soundness of those methods at section \ref{sec:soundness}.\\

\textbf{Termination }
We call a abstract map \emph{infinite} if $\Dom$ of the abstract map is infinite,
and \emph{finite} otherwise.
Even though the definition of $\AMap$ does not guarantee a abstract map to be finite,
the inputs of the helper methods will never be infinite during the analysis.
Because every abstract map created by alpha function during the analysis is finite
as the program code is finite, and if the input abstract map is finite,
the resulted abstract map of helper methods is also finite by the definition of the methods.
So we assume that every abstract map used as inputs of helper method are finite.
Thus the helper methods always terminates.\\

\subsubsection{contains}
$\wsf{contains}$ is used to check whether the given abstract key
has a mapping in given abstract map.\\

$\begin{array}{l}
\wsf{contains} \in \AMap \times \AKey \rightarrow \wbf{Boolean} \\\\
\wsf{contains}(\bot_m,\ \hat{k}) = \bot_b \\
\wsf{contains}(\hat{m},\ \bot_k) = \bot_b \\
\wsf{contains}(\hat{m},\ \hat{k}) = \hat{b} \\
\quad \begin{array}{ll} \textrm{where }
& \hat{b} = \left \{ \begin{array}{ll}
\top_b & \textrm{if } \emph{domIn?} \land \gamma_k(\hat{k}) \not\subseteq \Defset(\hat{m}) \\
\hat{\texttt{true}} & \textrm{if } \emph{domIn?} \land \gamma_k(\hat{k}) \subseteq \Defset(\hat{m}) \\
\hat{\texttt{false}} & \textrm{if } \neg \emph{domIn?} \\
\end{array} \right.\\
& \emph{domIn?} = \exists \hat{k}' \in \Dom(\hat{m}) \cdot
\wsf{isRelated}(\hat{k},\ \hat{k}')\\
\end{array}\\
\end{array}$

\subsubsection{lookup}
$\wsf{lookup}$ gets the abstract map and abstract key,
and returns the abstract value mapped to the keys related to given abstract key.
The abstract boolean value returned with the abstract value indicates
whether the returned value is definite or not.\\

$\begin{array}{l}
\wsf{lookup} \in \AMap \times \AKey \rightarrow \AVal \times \wbf{Boolean} \\\\

\wsf{lookup}(\bot_m,\ \hat{k}) = (\bot_v,\ \bot_b) \\
\wsf{lookup}(\hat{m},\ \bot_{k}) = (\bot_v,\ \bot_b) \\

\wsf{lookup}(\hat{m},\ \hat{k}) = (\emph{local},\ \hat{b}) \\
\quad \begin{array}{rl} \textrm{where}
& \emph{local} = \bigsqcup_v \left \{
\Map(\hat{m})(\hat{k}') \mid \hat{k}' \in \emph{S} \right \} \vspace{1mm}\\
& \hat{b} = \left \{ \begin{array}{ll}
\top_b & \textrm{if } \emph{S} \neq \varnothing \land
\gamma_k(\hat{k}) \not\subseteq \Defset(\hat{m}) \\
\hat{\texttt{true}} & \textrm{if } \emph{S} \neq \varnothing \land
\gamma_k(\hat{k}) \subseteq \Defset(\hat{m}) \\
\hat{\texttt{false}} & \textrm{if } \emph{S} = \varnothing \\
\end{array} \right. \vspace{1mm} \\
& \emph{S} = \{ \hat{k}' \mid \hat{k}' \in \Dom(\hat{m})
\land \wsf{isRelated}(\hat{k},\ \hat{k}') \}\\
\end{array} \\
\end{array}$

\subsubsection{update}
$\wsf{update}$ calculate updated abstract map of given map with given key and value.
If the given abstract key is \emph{exact}, ignore existing mapped value to the key.
Otherwise, join the existing mapped value with the new value.
It is important to determine whether the given key is \emph{exact} or not,
in order to the result of the $\wsf{update}$ methods be precise.\\

$\begin{array}{l}
\wsf{update} \in \AMap \times \AKey \times \AVal \rightarrow \AMap \\\\

\wsf{update}(\bot_m,\ \hat{k},\ \hat{v}) = \bot_m \\
\wsf{update}(\hat{m},\ \bot_k,\ \hat{v}) = \bot_m \\
\wsf{update}(\hat{m},\ \hat{k},\ \bot_{v}) = \hat{m} \\

\wsf{update}(\hat{m},\ \hat{k},\ \hat{v}) = \langle \emph{map},\ \emph{defset} \rangle \vspace{1mm}\\
\quad \begin{array}{rl} \textrm{where}
& \emph{map} = \left \{ \begin{array}{ll}
\Map(\hat{m}) \ast [ \hat{k} \mapsto \hat{v} ]
& \textrm{if } \hat{k} \not\in \Dom(\hat{m}) \\

(\Map(\hat{m}) - \hat{k}) \ast [ \hat{k} \mapsto \hat{v}]
& \textrm{if } \emph{exact?} \land \hat{k}\in \Dom(\hat{m}) \\

(\Map(\hat{m}) - \hat{k})
\ast [ \hat{k} \mapsto \hat{v} \sqcup_v \Map(\hat{m})(\hat{k}) ]
& \textrm{if } \neg \emph{exact?} \land \hat{k}\in \Dom(\hat{m}) \\
\end{array} \right. \vspace{1mm}\\

& \emph{defset} = \left \{ \begin{array}{ll}
\Defset(\hat{m}) \cup \gamma_k(\hat{k}) & \textrm{if} ~ \emph{exact?} \\
\Defset(\hat{m}) & \textrm{otherwise}\\
\end{array} \right. \vspace{1mm}\\

& \emph{exact?} = \mid \gamma_k(\hat{k}) \mid = 1 \\
\end{array} \\
\end{array} $

\subsubsection{delete}
For given abstract map and abstract key,
$\wsf{delete}$ returns the new abstract map
which have no value mapped to the given key.
Similar to $\wsf{update}$ method,
if the given key is not \emph{exact},
$\wsf{delete}$ cannot change the input map.
Thus it is important to determine \emph{exact}ness of the given key.\\

$\begin{array}{l}
\wsf{delete} \in \AMap \times \AKey \rightarrow \AMap \\\\

\wsf{delete}(\bot_m,\ \hat{k}) = \bot_m \\
\wsf{delete}(\hat{m},\ \bot_k) = \bot_m \\

\wsf{delete}(\hat{m},\ \hat{k}) =
\langle \emph{map},\ \Defset(\hat{m}) \setminus \gamma_k(\hat{k}) \rangle \vspace{1mm}\\
\quad \begin{array}{rl} \textrm{where}
& \emph{map} = \left \{ \begin{array}{ll}
(\Map(\hat{m}) - \hat{k})
& \textrm{if } \emph{exact?} \land \hat{k} \in \Dom(\hat{m}) \\
\Map(\hat{m})
& \textrm{otherwise} \\
\end{array} \right. \vspace{1mm}\\

& \emph{exact?} = \mid \gamma_k(\hat{k}) \mid = 1 \\
\end{array} \\
\end{array}$

\subsection{Soundness} \label{sec:soundness}
\newtheorem{thm}{Theorem}
\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{contains}$)
$\forall m_1 \in \CMap, k_1 \in \CKey :$\\
If $\exists \hat{m}_2 \in \AMap \cdot m_1 \in \gamma_m(\hat{m}_2)$
and $\exists \hat{k}_2 \in \AKey \cdot k_1 \in \gamma_k(\hat{k}_2)$,
then $\textsf{contains}(m_1,\ k_1) \in \gamma_b(\wsf{contains}(\hat{m}_2,\ \hat{k}_2))$.
\end{thm}
\textbf{Proof } $\forall m_1 \in \CMap, k_1 \in \CKey$,
let $\hat{m}_2 \in \AMap \cdot m_1 \in \gamma_m(\hat{m}_2)$
and $\hat{k}_2 \in \AKey \cdot k_1 \in \gamma_k(\hat{k}_2)$.\\
Let $\hat{m}_1 = \alpha_m(\{ m_1 \})$ and $\hat{k}_1 = \alpha_k(\{ k_1 \})$,
then $\hat{m}_1 \po_m \hat{m}_2$ and $\hat{k}_1 \po_k \hat{k}_2$.
\begin{itemize}
\item If $\textsf{contains}(m_1, k_1) = \texttt{true}$, then $k_1 \in \Dom(m_1)$.\\
$\Dom(\hat{m}_1)  = \{ \alpha_k(\{k\}) \mid k \in \Dom(m_1) \}$
by definition of $\alpha_m$, thus $\hat{k}_1 \in \Dom(\hat{m}_1)$.\\
Also, $\exists \hat{k} \in \Dom(\hat{m}_2)
\cdot \hat{k}_1 \po_k \hat{k} \land \Map(\hat{m}_1)(\hat{k}_1) \po_v \Map(\hat{m}_2)(\hat{k})$,
by definition of $\po_m$.\\
$k_1 \in \gamma_k(\hat{k}_1) \subseteq \gamma_k(\hat{k})$ by monotonicity of $\gamma_k$.\\
$\wsf{isRelated}(\hat{k}_2, \hat{k})$ must be \texttt{true},
since $k_1 \in \gamma_k(\hat{k}) \land k_1 \in \gamma_k(\hat{k}_2)$. \\
Therefore $\wsf{contains}(\hat{m}_2, \hat{k}_2)$ should be either $\top_b$ or $\hat{\texttt{true}}$.\\
Thus $\textsf{contains}(m_1, k_1) \in \gamma_b(\wsf{contains}(\hat{m}_2, \hat{k}_2))$.
\item If $\textsf{contains}(m_1, k_1) = \texttt{false}$, then $k_1 \not\in \Dom(m_1)$.\\
$\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ by definition of $\po_m$,
and $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
$k_1 \not\in \Defset(\hat{m}_2)$ because $k_1 \not\in \Dom(m_1) = \Defset(\hat{m}_1)$. \\
$\gamma_k(\hat{k}_2) \not\subseteq \Defset(\hat{m}_2)$, since
$k_1 \not\in \Defset(\hat{m}_2)$ but $k_1 \in \gamma_k(\hat{k}_2)$.\\
Therefore $\wsf{contains}(\hat{m}_2, \hat{k}_2)$ should be either $\top_b$ or $\hat{\texttt{false}}$.\\
Thus $\textsf{contains}(m_1, k_1) \in \gamma_b(\wsf{contains}(\hat{m}_2, \hat{k}_2))$.
\end{itemize}

\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{lookup}$)
$\forall m_1 \in \CMap, k_1 \in \CKey :$\\
If $\exists \hat{m}_2 \in \AMap \cdot m_1 \in \gamma_m(\hat{m}_2)$,
$\exists \hat{k}_2 \in \AKey \cdot k_1 \in \gamma_k(\hat{k}_2)$,
and $(\hat{v}, \hat{b}) = \wsf{lookup}(\hat{m}_2,\ \hat{k}_2)$
for $\hat{v} \in \AVal, \hat{b} \in \wbf{Boolean}$,
then $\textsf{lookup}(m_1,\ k_1) \in \gamma_v(\hat{v}) \cup \gamma_b(\hat{b})$.
\end{thm}
\textbf{Proof } $\forall m_1 \in \CMap, k_1 \in \CKey$,
let $\hat{m}_2 \in \AMap \cdot m_1 \in \gamma_m(\hat{m}_2)$,
$\hat{k}_2 \in \AKey \cdot k_1 \in \gamma_k(\hat{k}_2)$,
and $(\hat{v},\ \hat{b}) = \wsf{lookup}(\hat{m}_2,\ \hat{k}_2)$.\\
Let $\hat{m}_1 = \alpha_m(\{ m_1 \})$ and $\hat{k}_1 = \alpha_k(\{ k_1 \})$,
then $\hat{m}_1 \po_m \hat{m}_2$ and $\hat{k}_1 \po_k \hat{k}_2$.
\begin{itemize}
\item If $\textsf{lookup}(m_1, k_1) = m_1(k_1) \in \CVal$, then $k_1 \in \Dom(m_1)$.\\
$\hat{v} = \bigsqcup_v \emph{V}$
where $\emph{V} = \{ \Map(\hat{m}_2)(\hat{k}) \mid \hat{k} \in \emph{S} \}$
and $\emph{S} = \{ \hat{k} \mid \hat{k} \in \Dom(\hat{m}_2) \land \wsf{isRelated}(\hat{k}, \hat{k}_2) \}$
by definition of $\wsf{lookup}$. \vspace{1mm} \\
$\Dom(\hat{m}_1)  = \{ \alpha_k(\{k\}) \mid k \in \Dom(m_1) \}$
by definition of $\alpha_m$, thus $\hat{k}_1 \in \Dom(\hat{m}_1)$.\\
Also, $\exists \hat{k} \in \Dom(\hat{m}_2)
\cdot \hat{k}_1 \po_k \hat{k} \land \Map(\hat{m}_1)(\hat{k}_1) \po_v \Map(\hat{m}_2)(\hat{k})$,
by definition of $\po_m$.\\
$k_1 \in \gamma_k(\hat{k}_1) \subseteq \gamma_k(\hat{k})$ by monotonicity of $\gamma_k$.\\
$\wsf{isRelated}(\hat{k}_2, \hat{k})$ must be \texttt{true},
since $k_1 \in \gamma_k(\hat{k}) \land k_1 \in \gamma_k(\hat{k}_2)$,
thus $\hat{k} \in \emph{S} $.\\
It means $\Map(\hat{m}_2)(\hat{k}) \in \emph{V}$,
so that $\Map(\hat{m}_2)(\hat{k}) \po_v \hat{v}$. \vspace{1mm} \\
$m_1(k_1) \in \gamma_v (\Map(\hat{m}_1)(\hat{k}_1))$ by definition of $\alpha_m$.\\
$m_1(k_1) \in \gamma_v (\Map(\hat{m}_1)(\hat{k}_1))
\subseteq \gamma_v (\Map(\hat{m}_2)(\hat{k})) \subseteq \gamma_v (\hat{v})$,
by monotonicity of $\gamma_v$.\\
Therefore, $\textsf{lookup}(m_1, k_1) \in \gamma_v(\hat{v}) \cup \gamma_b(\hat{b})$.
\item If $\textsf{lookup}(m_1, k_1) = \texttt{false}$, then $k_1 \not\in \Dom(m_1)$.\\
$\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ by definition of $\po_m$,
and $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
$k_1 \not\in \Defset(\hat{m}_2)$ because $k_1 \not\in \Dom(m_1) = \Defset(\hat{m}_1)$. \\
$\gamma_k(\hat{k}_2) \not\subseteq \Defset(\hat{m}_2)$, since
$k_1 \not\in \Defset(\hat{m}_2)$ but $k_1 \in \gamma_k(\hat{k}_2)$.\\
Then $\hat{b}$ should be either $\top_b$ or $\hat{\texttt{false}}$,
so that $\texttt{false} \in \gamma_b(\hat{b})$. \\
Thus $\textsf{lookup}(m_1, k_1) \in \gamma_v(\hat{v}) \cup \gamma_b(\hat{b})$.
\end{itemize}

\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{update}$)
$\forall m_1 \in \CMap, k_1 \in \CKey, v_1 \in \CVal :$\\
If $\exists \hat{m}_2 \in \AMap \cdot m_1 \in \gamma_m(\hat{m}_2)$,
$\exists \hat{k}_2 \in \AKey \cdot k_1 \in \gamma_k(\hat{k}_2)$,
and $\exists \hat{v}_2 \in \AVal \cdot v_1 \in \gamma_v(\hat{v}_2)$,
then $\textsf{update}(m_1,\ k_1,\ v_1) \in \gamma_m(\wsf{update}(\hat{m}_2,\ \hat{k}_2,\ \hat{v}_2))$.
\end{thm}
\textbf{Proof } $\forall m_1 \in \CMap, k_1 \in \CKey$,
let $\hat{m}_2 \in \AMap \cdot m_1 \in \gamma_m(\hat{m}_2)$,
$\hat{k}_2 \in \AKey \cdot k_1 \in \gamma_k(\hat{k}_2)$,
and $\hat{v}_2 \in \AVal \cdot v_1 \in \gamma_v(\hat{v}_2)$.\\
Let $\hat{m}_1 = \alpha_m(\{ m_1 \})$,
$\hat{k}_1 = \alpha_k(\{ k_1 \})$,
$\hat{v}_1 = \alpha_v(\{ v_1 \})$,
then $\hat{m}_1 \po_m \hat{m}_2$,
$\hat{k}_1 \po_k \hat{k}_2$,
and $\hat{v}_1 \po_v \hat{v}_2$.\\
For $\hat{m}_2' = \wsf{update}(\hat{m}_2, \hat{k}_2, \hat{v}_2)$,
and $\emph{mset} = \{ \textsf{update}(m_1, k_1, v_1) \}$, \\
if $\alpha_m(\emph{mset}) \po_m \hat{m}_2'$
then $\textsf{update}(m_1, k_1, v_1) \in \gamma_m(\hat{m}_2')$
by definition of $\gamma_m$.\\
To show $\alpha_m(\emph{mset}) \po_m \hat{m}_2'$, we need to prove 2 things:
\begin{enumerate}[label=({\arabic*})]
\item $\forall \hat{k} \in \Map(\alpha_m(\emph{mset})) \cdot
\exists \hat{k}' \in \Dom(\hat{m}_2'):
\hat{k} \po_k \hat{k}' \land \Map(\alpha_m(\emph{mset}))(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k}')$
\item $\Defset(\hat{m}_2') \subseteq \Defset(\alpha_m(\emph{mset}))$
\end{enumerate}
\begin{itemize}
\item If $k_1 \not\in \Dom(m_1)$,
then $\emph{mset} = \{ m_1 \cup \{[k_1 \mapsto v_1]\} \}$.\\
$\alpha_m(\emph{mset}) =
\langle \{ [\alpha_k(\{ k \}) \mapsto \alpha_v(\{ m_1(k) \} )] \mid k \in \Dom(m_1) \}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\
\Dom(m_1) \cup \{ k_1 \} \rangle$\\
$= \langle \{ [ \hat{k} \mapsto \Map(\hat{m}_1)(\hat{k}) ] \mid \hat{k} \in \Dom(\hat{m}_1) \}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\
\Dom(m_1) \cup \{ k_1 \} \rangle$
by definition of $\alpha_m$.

Prove (1). \\
$\forall \hat{k} \in \Dom(\hat{m}_1) \cdot \exists \hat{k}' \in \Dom(\hat{m}_2):
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2)(\hat{k}')$
since $\hat{m}_1 \po_m \hat{m}_2$.

$\Dom(\alpha_m(\emph{mset})) = \Dom(\hat{m}_1) \cup \{ \hat{k}_1 \} $
by definition of $\alpha_m$. For same reason, \\
$\forall \hat{k} \in \Dom(\hat{m}_1) \cdot
\Map(\alpha_m(\emph{mset}))(\hat{k}) = \Map(\hat{m}_1)(\hat{k})$,
and $\Map(\alpha_m(\emph{mset}))(\hat{k}_1) = \hat{v}_1$.

Also, $\Dom(\hat{m}_2') = \Dom(\hat{m}_2) \cup \{ \hat{k}_2 \}$
by definition of $\wsf{update}$. For same reason, \\
$\forall \hat{k} \in (\Dom(\hat{m}_2) \setminus \{ \hat{k}_2 \}) \cdot
\Map(\hat{m}_2)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k})$,
and $\hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.

For $\hat{k}_1$, $\exists \hat{k}_2 \in \Dom(\hat{m}_2')$
such that $\hat{k}_1 \po_k \hat{k}_2 \land
\Map(\alpha_m(\emph{mset}))(\hat{k}_1) \po_v \hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.\\
For $\hat{k} \in \Dom(\hat{m}_1)$,
there exists $\hat{k}' \in \Dom(\hat{m}_2') \cdot
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k}')$.

Prove (2).\\
\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid = 1$, then $\gamma_k(\hat{k}_2) = \{ k_1 \}$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2) \cup \gamma_k(\hat{k}_2)
= \Defset(\hat{m}_2) \cup \{ k_1 \}$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ as $\hat{m}_1 \po_m \hat{m}_2$.\\
Also, $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
Therefore, $\Defset(\hat{m}_2') =
\Defset(\hat{m}_2) \cup \gamma_k(\hat{k}_2) \subseteq \Dom(m_1) \cup \{ k_1 \}
= \Defset(\alpha_m(\emph{mset}))$.

\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid > 1$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2)$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Dom(m_1)$,
thus $\Defset(\hat{m}_2) \subseteq \Dom(m_1) \cup \{ k_1 \}
= \Defset(\alpha_m(\emph{mset}))$.
Therefore $\Defset(\hat{m}_2') \subseteq \Defset(\alpha_m(\emph{mset}))$.

\item If $k_1 \in \Dom(m_1)$,
then $\emph{mset} = \{ (m_1 \setminus \{ [ k_1 \mapsto m_1(k_1)] \}) \cup \{ [k_1 \mapsto v_1]\} \}$.\\
$\alpha_m(\emph{mset}) =
\langle \{ [\alpha_k(\{ k \}) \mapsto \alpha_v(\{ m_1(k) \} )] \mid
k \in (\Dom(m_1) \setminus \{ k_1 \})\}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\ \Dom(m_1) \rangle$\\
$= \langle \{ [ \hat{k} \mapsto \Map(\hat{m}_1)(\hat{k}) ] \mid
\hat{k} \in (\Dom(\hat{m}_1) \setminus \{ \hat{k}_1 \}) \}
\cup \{ [ \hat{k}_1 \mapsto \hat{v}_1 ] \},\ \Dom(m_1) \rangle$
by definition of $\alpha_m$.

Prove (1). \\
$\forall \hat{k} \in \Dom(\hat{m}_1) \cdot \exists \hat{k}' \in \Dom(\hat{m}_2):
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2)(\hat{k}')$
since $\hat{m}_1 \po_m \hat{m}_2$.

$\Dom(\alpha_m(\emph{mset})) = \Dom(\hat{m}_1)$
by definition of $\alpha_m$. For same reason, \\
$\forall \hat{k} \in (\Dom(\hat{m}_1) \setminus \{ \hat{k}_1 \}) \cdot
\Map(\alpha_m(\emph{mset}))(\hat{k}) = \Map(\hat{m}_1)(\hat{k})$,
and $\Map(\alpha_m(\emph{mset}))(\hat{k}_1) = \hat{v}_1$.

Also, $\Dom(\hat{m}_2') = \Dom(\hat{m}_2) \cup \{ \hat{k}_2 \}$
by definition of $\wsf{update}$. For same reason, \\
$\forall \hat{k} \in (\Dom(\hat{m}_2) \setminus \{ \hat{k}_2 \}) \cdot
\Map(\hat{m}_2)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k})$,
and $\hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.

For $\hat{k}_1$, $\exists \hat{k}_2 \in \Dom(\hat{m}_2')$
such that $\hat{k}_1 \po_k \hat{k}_2 \land
\Map(\alpha_m(\emph{mset}))(\hat{k}_1) \po_v \hat{v}_2 \po_v \Map(\hat{m}_2')(\hat{k}_2)$.\\
For $\hat{k} \in \Dom(\hat{m}_1)$,
there exists $\hat{k}' \in \Dom(\hat{m}_2') \cdot
\hat{k} \po_k \hat{k}' \land \Map(\hat{m}_1)(\hat{k}) \po_v \Map(\hat{m}_2')(\hat{k}')$.

Prove (2).\\
\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid = 1$, then $\gamma_k(\hat{k}_2) = \{ k_1 \}$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2) \cup \gamma_k(\hat{k}_2)
= \Defset(\hat{m}_2) \cup \{ k_1 \}$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Defset(\hat{m}_1)$ as $\hat{m}_1 \po_m \hat{m}_2$.\\
Also, $\Defset(\hat{m}_1) = \Dom(m_1)$ by definition of $\alpha_m$.\\
Moreover, $\Dom(m_1) \cup \{ k_1 \} = \Dom(m_1)$ as $k_1 \in \Dom(m_1)$ \\
Therefore $\Defset(\hat{m}_2') \subseteq \Dom(m_1) = \Defset(\alpha_m(\emph{mset}))$.

\textbf{Case} if $\mid \gamma_k(\hat{k}_2) \mid > 1$.\\
$\Defset(\hat{m}_2') = \Defset(\hat{m}_2)$ by definition of $\wsf{update}$.\\
However, $\Defset(\hat{m}_2) \subseteq \Dom(m_1) = \Defset(\alpha_m(\emph{mset}))$.
Therefore $\Defset(\hat{m}_2') \subseteq \Defset(\alpha_m(\emph{mset}))$.
\end{itemize}

\begin{thm} \normalfont
(\textit{Soundness of} $\wsf{delete}$)
$\forall m \in \CMap, k \in \CKey :$\\
If $\exists \hat{m} \in \AMap \cdot m \in \gamma_m(\hat{m})$
and $\exists \hat{k} \in \AKey \cdot k \in \gamma_k(\hat{k})$,
then $\textsf{delete}(m,\ k) \in \gamma_m(\wsf{delete}(\hat{m},\ \hat{k}))$.
\end{thm}


\documentclass{ximera}
\input{../preamble}
\title{Exercises: Cumulative}
%%%%%\author{Philip T. Gressman}

\begin{document}
\begin{abstract}
Exercises relating to various topics we have studied.
\end{abstract}
\maketitle

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{(-1)^n}{n - e^{-n}} \]
\begin{multipleChoice}
\choice{Absolute}
\choice[correct]{Conditional}
\choice{Diverge}
\end{multipleChoice}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{(-1)^n e^{-n}}{n - e^{-n}} \]
\begin{multipleChoice}
\choice[correct]{Absolute}
\choice{Conditional}
\choice{Diverge}
\end{multipleChoice}
\begin{hint}
Take absolute values and try direct comparison test.
\end{hint}
\begin{hint}
Try direct comparison to $e^{-n}$.
\end{hint}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{(-1)^n n}{n - e^{-n}} \]
\begin{multipleChoice}
\choice{Absolute}
\choice{Conditional}
\choice[correct]{Diverge}
\end{multipleChoice}
\begin{hint}
What is the dominant term in the denominator as $n \rightarrow \infty$?
\end{hint}
\begin{hint}
The dominant term in the denominator is $n$.
\end{hint}
\begin{hint}
This means that the terms do not go to zero.
\end{hint}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{1}{n^2 + (-1)^n n} \]
\begin{multipleChoice}
\choice[correct]{Absolute}
\choice{Conditional}
\choice{Diverge}
\end{multipleChoice}
\begin{hint}
What is the dominant term in the denominator as $n \rightarrow \infty$?
\end{hint}
\begin{hint}
The dominant term in the denominator is $n^2$.
\end{hint}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{(-1)^n}{n - e^{-n}} \]
\begin{multipleChoice}
\choice{Absolute}
\choice[correct]{Conditional}
\choice{Diverge}
\end{multipleChoice}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{(-1)^n \sqrt{n}}{\ln (n+1)} \]
\begin{multipleChoice}
\choice{Absolute}
\choice{Conditional}
\choice[correct]{Diverge}
\end{multipleChoice}
\begin{hint}
Which term dominates as $n \rightarrow \infty$: $\sqrt{n}$ or $\ln (n+1)$?
\end{hint}
\begin{hint}
Answer: $\sqrt{n}$ dominates $\ln (n+1)$ as $n \rightarrow \infty$.
\end{hint}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{(-1)^n}{\sqrt{n} + \ln (n+1)} \]
\begin{multipleChoice}
\choice{Absolute}
\choice[correct]{Conditional}
\choice{Diverge}
\end{multipleChoice}
\begin{hint}
To show that convergence is not absolute, try limit comparison.
\end{hint}
\begin{hint}
The comparison series can be taken to be $1/\sqrt{n}$ in this case.
\end{hint}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{1}{n} \ln \left(2 + \frac{1}{n} \right) \]
\begin{multipleChoice}
\choice{Absolute}
\choice{Conditional}
\choice[correct]{Diverge}
\end{multipleChoice}
\begin{hint}
Try limit comparison with the harmonic series.
\end{hint}
\end{exercise}

\begin{exercise}
Determine whether the series below converges absolutely, conditionally, or diverges.
\[ \sum_{n=1}^\infty \frac{n \cos n \pi}{n^2 - 1} \]
\begin{multipleChoice}
\choice{Absolute}
\choice[correct]{Conditional}
\choice{Diverge}
\end{multipleChoice}
\begin{hint}
With absolute values, compare to a harmonic series.
\end{hint}
\begin{hint}
How do we know that the alternating series test applies?
\end{hint}
\end{exercise}

\section*{Sample Exam Questions}

\begin{question}%%%%%[2015C.04.alt]

Determine whether the following series converge or diverge.
\[ \text{I: } \sum_{n=1}^\infty \frac{n^3}{n^4+4} \ \ \
\text{II: } \sum_{n=1}^\infty \frac{3^n}{n!} \ \ \
\text{III: } \sum_{n=2}^\infty \frac{ \ln \ln n}{\ln n} \ \ \
\text{IV: } \sum_{n=1}^\infty \frac{3n^2}{(n!)^2} \]
\begin{multiplechoice}
\choice{I \& II converge; III \& IV diverge}
\choice{I \& III converge; II \& IV diverge}
\choice{I \& IV converge; II \& III diverge}
\choice{II \& III converge; I \& IV diverge}
\choice[correct]{II \& IV converge; I \& III diverge}
\choice{III \& IV converge; I \& II diverge}
\end{multiplechoice}

\end{question}

\begin{question}%%%%%[2016C.09]

Determine whether the following series are convergent or divergent. Justify your answers.
\[ \text{I: } \sum_{n=1}^\infty \frac{n^2-3n}{\sqrt[3]{n^{10}-4n^2}} \ \ \ \ \text{II: } \sum_{n=1}^\infty \frac{(-n)^n}{5^{2n+3}} \]
\begin{multiplechoice}
\choice{I \& II divergent}
\choice[correct]{I convergent, II divergent}
\choice{I divergent, II convergent}
\choice{I \& II convergent}
\end{multiplechoice}

\end{question}

\begin{question}%%%%%[2016C.10]

Determine whether the following series are convergent or divergent. Justify your answers.
\[ \text{I: } \sum_{n=1}^\infty \frac{\arctan n}{n^4} \ \ \ \ \text{II: } \sum_{n=1}^\infty \frac{\sin \frac{1}{n}}{n^2} \]
\begin{multiplechoice}
\choice{I \& II divergent}
\choice{I convergent, II divergent}
\choice{I divergent, II convergent}
\choice[correct]{I \& II convergent}
\end{multiplechoice}

\end{question}

\begin{question}%%%%%[2017C.11]

Determine which of the following series are convergent. \offline{For full credit, be sure to explain your reasoning and specify which tests were used.}
\[ \text{I: } \sum_{n=2}^\infty 2ne^{-n^2} \ \ \ \ \text{II: } \sum_{n=2}^\infty \frac{n + 2 \ln n}{2 n^4} \ \ \ \ \text{III: } \sum_{n=2}^\infty \frac{n^n}{n!} \]
\begin{multiplechoice}
\choice{only I}
\choice[correct]{only I and II}
\choice{only I and III}
\choice{only II}
\choice{only II and III}
\choice{only III}
\end{multiplechoice}

\end{question}

\end{document}


\section{Discriminant Analysis II}

\subsection{Rank Reduced Linear Discriminant Analysis}

\begin{frame}
	\frametitle{Rank Reduced Linear Discriminant Analysis}

	\begin{center}
		\begin{minipage}{0.8\textwidth}
			\begin{itemize}
				\item[{\bf Problem}:] How to choose an $L$-dimensional subspace with $L=K-1$ that is good for  LDA? \\[.5cm]
				\item[{\bf Idea}:] Maximize the spread of the $L$-dimensional projection of centroids. \\[.5cm]
				\item[{\bf Solution}:] Principal component analysis, i.\,e.\ \\
				      we compute the principal components of the \\
				      covariance matrix of the mean vectors
				      $$\vec{\mu}'_y = \phi(\vec{\mu}_y) \in \real^{K-1},$$
				      where $y=1,2,\dots, K$.
			\end{itemize}
		\end{minipage}
	\end{center}
\end{frame}

\begin{frame}
	\frametitle{Rank Reduced Linear Discriminant Analysis \cont}

	In \structure{Principle Component Analysis (PCA)} we compute a linear mapping $\mat\Phi \in \real^{L \times (K-1)}$ that
	results in the highest spread of projected features:
	\pause

	\begin{displaymath}
		\mat{\Phi}^* = \argmax_{\mat{\Phi}} \left(
		\frac{1}{K}
		\sum_{y=1}^K (\mat{\Phi}\vec {\mu}'_y - \mat {\Phi}\bar{\mat \mu}' )^T
		(\mat{\Phi}\vec {\mu}'_y - \mat {\Phi}\bar{\mat \mu}' ) +
		\sum_{i=1}^{L} \lambda_i (\| \mat{\Phi}_i \|_2^2 - 1)
		\right)
	\end{displaymath}
	%
	where we applied the \structure{Lagrange multiplier} method to allow for the maximization of the spread subject to
	%
	\begin{displaymath}
		\| \mat {\Phi}_i \|_2^2 = 1 ~, \quad i = 1, \ldots, K-1 ~.
	\end{displaymath}
	%
	Here $\| \mat{\Phi}_i \|_2^2$ denotes the $L_2$ norm of the $i$-th row vector of $\mat{\Phi}$.
\end{frame}

\begin{frame}
	\frametitle{Excursus: Optimization with Constraints}

	\structure{Lagrange Multipliers:} simple example

	\begin{columns}
		\column{.5\linewidth}

		\begin{itemize}
			\item Find the maximum of \\
			      $f(x,y) = x +y$ \\[.25cm]
			      \onslide<2->{
			\item constraint: $x^2 + y^2 = 1$ \\[.25cm]
			      }
			      \onslide<4->{
			\item Lagrange function: \\
			      $L(x,y,\lambda) = x + y + \lambda(x^2 + y^2 - 1)$ \\[0.25cm]
			      }
			      \onslide<5->{
			\item Set the partial derivatives to zero: \\
			      $\frac{\partial L}{\partial x} =
				      \frac{\partial L}{\partial y} =
				      \frac{\partial L}{\partial \lambda}
				      \stackrel{!}{=} 0$
			      }
		\end{itemize}

		\column{.5\linewidth}

		\begin{center}
			\resizebox{\linewidth}{!}{
				\alt<3->{
					\input{\texfigdir/lagrange_multiplier3.pstex_t}
				}{\alt<2>{
						\input{\texfigdir/lagrange_multiplier2.pstex_t}
					}{
						\input{\texfigdir/lagrange_multiplier1.pstex_t}
					}}
			}
		\end{center}
	\end{columns}
\end{frame}

\begin{frame}
	\frametitle{Rank Reduced Linear Discriminant Analysis \cont}

	We need some facts from matrix calculus: \\
	\point \structure{\url{www.matrixcookbook.com}}%
	\footnote{website currently off-line -- you can still download it \point\href{http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=3274}{\structure{here}}} \\
	%
	\spread

	\begin{enumerate}
		\item Let $\vec\mu$ denote the mean and $\mat \Sigma$ the covariance matrix of a \\
		      random vector $\vec x$, then we get:
		      \begin{displaymath}
			      E[(\mat A \vec x)^T(\mat A \vec x)] =
			      {\mbox{tr}}(\mat A \mat \Sigma \mat A^T) + (\mat A \vec \mu)^T(\mat A\vec \mu)
		      \end{displaymath}
		      \pause
		\item The matrix derivative is:
		      \begin{displaymath}
			      \frac{\partial \mbox{tr}( \mat X \mat B \mat X^T)}{\partial \mat X} = \mat X\mat B^T +\mat X\mat B
		      \end{displaymath}
	\end{enumerate}
\end{frame}

\begin{frame}
	\frametitle{Rank Reduced Linear Discriminant Analysis \cont}

	For our \structure{optimization problem} this implies:

	\begin{eqnarray*}
		& & \frac{\partial}{\partial{\mat{\Phi}}}
		\left\{
		\frac{1}{K} \sum_{y=1}^K (\mat{\Phi} \vec{\mu}'_y - \mat{\Phi} \bar{\vec{\mu}}' )^T
		(\mat{\Phi} \vec{\mu}'_y - \mat{\Phi} \bar{\vec{\mu}}' )  +
		\sum_{i=1}^{L} \lambda_i (\| \mat{\Phi}_i \|^2_2 - 1)
		\right\} \\[.5cm] \pause
		& & = \quad \frac{\partial}{\partial{\mat{\Phi}}}
		\left\{
		\frac{1}{K} \sum_{y=1}^K \left( \mat\Phi (\vec{\mu}'_y - \bar{\vec{\mu}}') \right)^T
		\left( \mat\Phi (\vec{\mu}'_y - \bar{\vec{\mu}}') \right) +
		\sum_{i=1}^{L} \lambda_i (\| \mat {\Phi}_i \|^2_2 - 1)
		\right\} \\[.5cm] \pause
		& & = \quad \frac{\partial}{\partial{\mat{\Phi}}}
		\left\{
		\mbox{tr} (\mat\Phi \ \mat \Sigma_{\mbox{inter}} \ \mat\Phi^T) +
		\sum_{i=1}^{L} \lambda_i (\| \mat {\Phi}_i \|_2^2 - 1)
		\right\}
		\stackrel{!}{=} \mat 0.
	\end{eqnarray*}
\end{frame}

\begin{frame}
	\frametitle{Rank Reduced Linear Discriminant Analysis \cont}

	Now we compute the \structure{partial derivatives}:

	\begin{displaymath}
		\frac{\partial}{\partial{\mat{\Phi}}}
		\left\{
		\mbox{tr} (\mat \Phi \ \mat \Sigma_{\mbox{inter}}  \ \mat \Phi^T) + \sum_{i=1}^{L} \lambda_i (\| \mat {\Phi}_i \|^2_2 - 1)  \right\} =
		2 \mat \Phi\mat  \Sigma_{\mbox{inter}} +2 \mat{\lambda} \mat \Phi = \mat 0
	\end{displaymath}
	\pspread

	This results in the eigenvalue and eigenvector problem:
	\begin{displaymath}
		\mat{\Sigma}_{\mbox{inter}} \mat \Phi^T = \mat{\lambda}' \mat \Phi^T
	\end{displaymath}
	\pspread

	\structure{Note:} \\
	In original PCA, the transform $\mat \Phi$ maximizes the overall spread using the covariance matrix of all features:

	\begin{displaymath}
		\mat{\Sigma} \mat{\Phi}^T = \mat{\lambda}' \mat \Phi^T
	\end{displaymath}
\end{frame}

\begin{frame}
	\frametitle{Rank Reduced Linear Discriminant Analysis \cont}

	\begin{algorithmic}
		\STATE  \structure{Input:} training data:  $S = \{ (\vec x_1, y_1), (\vec x_2, y_2), (\vec x_3, y_3), \dots, (\vec x_m, y_m) \}$ \\[.3cm]
		\STATE 1. Compute the covariance matrix of transformed mean vectors
		$$\widehat{\mat{\Sigma}}_{\mbox{inter}} =
			\frac{1}{K} \sum_{y=1}^K (\vec \mu'_y - \bar{\vec \mu}')(\vec \mu'_y - \bar{\vec \mu}')^T,$$
		\quad\,where $\bar{\vec \mu}' = \frac{1}{K} \cdot \sum_{y=1}^{K}\vec\mu'_y$. \\[.3cm]
		\pause
		\STATE 2. Compute the $L$ eigenvectors of the covariance matrix belonging \\
		\quad\,to the largest eigenvalues. \\[.3cm]
		\pause
		\STATE 3. The eigenvectors are the rows of the mapping $\mat\Phi$ from the \\
		\quad\,$(K-1)$- to the $L$-dimensional feature space. \\[.3cm]
		\STATE  \structure{Output:} matrix $\mat\Phi$
	\end{algorithmic}
\end{frame}

\input{nextTime.tex}

\subsection{Fisher Transform}

\begin{frame}
	\frametitle{Fisher Transform}

	The described method to compute the LDA mapping is not the original derivation.\\[.5cm]

	\structure{Original method}

	\begin{center}
		\resizebox{0.6\linewidth}{!}{
			\input{\texfigdir/lda.pstex_t}
		}
	\end{center}
\end{frame}

\begin{frame}
	\frametitle{Fisher Transform}

	The described method to compute the LDA mapping is not the original derivation.\\[.5cm]

	\structure{Original method}

	\begin{columns}
		\column{.65\linewidth}

		\small \vspace{-.5cm}
		\begin{itemize}
			\item Project samples $\vec{x}_i$ onto a straight line with direction $\vec{r}$, $\lVert \vec{r} \rVert_2 = 1$:
			      \begin{displaymath}
				      \tilde{x}_i = \vec{x}_i^T \vec{r}
			      \end{displaymath}
			      \onslide<2->{
			      \vspace{-.5cm}
			\item Maximize the ratio of the between-class scatter and the within-class scatter:
			      \begin{displaymath}
				      \vec{r}^* =
				      \argmax_{\vec{r}} J(\vec{r}) =
				      \argmax_{\vec{r}} \frac{|\tilde{\mu}_1 - \tilde{\mu}_2|^2}{\tilde{s}_1^2 + \tilde{s}_2^2}
			      \end{displaymath}
			      }
			      \onslide<3->{
			      \vspace{-.5cm}
			\item Classify by applying a threshold to $\tilde{x}_i$
			      }
		\end{itemize}

		\column{.35\linewidth}

		\onslide<1->{
			\resizebox{\linewidth}{!}{
				\input{\texfigdir/lda.pstex_t}
			}
		}
	\end{columns}
\end{frame}

\begin{frame}
	\frametitle{Fisher Transform \cont}

	\structure{Finding $\vec{r}^*$}

	\begin{enumerate}
		\item Mean and scatter matrix for each class:
		      {\small
		      \begin{eqnarray*}
			      \vec{\mu}_k &=& \frac{1}{m_k} \sum_{\substack{~i = 1\\ y_i = k}}^{m_k} \vec{x}_i \\
			      \mat{S}_k   &=& \sum_{\substack{~i = 1\\ y_i = k}}^{m_k} (\vec{x}_i - \vec{\mu}_k) (\vec{x}_i - \vec{\mu}_k)^T
		      \end{eqnarray*}
		      }
		\item \structure{Within-class scatter} matrix:
		      {\small
		      \begin{displaymath}
			      \structure{\mat{S}_\mathsf{W}} = \mat{S}_1 + \mat{S}_2
		      \end{displaymath}
		      }
		\item \structure{Between-class scatter} matrix:
		      {\small
		      \begin{displaymath}
			      \structure{\mat{S}_\mathsf{B}} = (\vec{\mu}_1 - \vec{\mu}_2) (\vec{\mu}_1 - \vec{\mu}_2)^T
		      \end{displaymath}
		      }
	\end{enumerate}
\end{frame}

\begin{frame}
	\frametitle{Fisher Transform \cont}

	\structure{Finding $\vec{r}^*$}

	\begin{enumerate}
		\setcounter{enumi}{3}
		\item Expressing $\tilde{\mu}_k$ and $\tilde{s}_k^2$ of the projected samples in terms of $\vec{\mu}_k$ and $\mat{S}_k$:
		      {\small
		      \begin{eqnarray*}
			      \onslide<1->{
				      \tilde{\mu}_k &=&
				      \onslide<1->{ \frac{1}{m_k} \sum_{\substack{~i = 1\\ y_i = k}}^{m_k} \tilde{x}_i }
				      \onslide<2->{ = \frac{1}{m_k} \sum_{\substack{~i = 1\\ y_i = k}}^{m_k} \vec{r}^T  \vec{x}_i }
				      \onslide<3->{ = \vec{r}^T \vec{\mu}_k } \\
			      }
			      \onslide<1->{
				      \tilde{s}_k^2 &=&
				      \onslide<1->{ \sum_{\substack{~i = 1\\ y_i = k}}^{m_k} (\tilde{x}_i - \tilde{\mu}_k)^2 }
				      \onslide<4->{ = \sum_{\substack{~i = 1\\ y_i = k}}^{m_k} (\vec{r}^T \vec{x}_i - \vec{r}^T \vec{\mu}_k)^2 }
				      \onslide<5->{ = \vec{r}^T \mat{S}_k \vec{r} }
			      }
		      \end{eqnarray*}
		      }
		      \onslide<6->{
		\item Plug it into $J(\vec{r})$:
		      {\small
		      \begin{displaymath}
			      J(\vec{r})
			      = \frac{|\tilde{\mu}_1 - \tilde{\mu}_2|^2}{\tilde{s}_1^2 + \tilde{s}_2^2}
			      \onslide<7->{ = \frac{\vec{r}^T \mat{S}_B \vec{r}}{\vec{r}^T \mat{S}_W \vec{r}}}
		      \end{displaymath}
		      }
		      }
		      \onslide<7->{
		\item[] This is known as the \structure{Generalized Rayleigh Quotient}.
		      }
	\end{enumerate}
\end{frame}

\begin{frame}
	\frametitle{Fisher Transform \cont}

	\structure{Finding $\vec{r}^*$}

	\begin{enumerate}
		\setcounter{enumi}{5}
		\item Maximizing the Generalized Rayleigh Quotient is equivalent to solving the following \structure{generalized eigenvalue problem}:
		      {\small
		      \begin{eqnarray*}
			      \mat{S}_\mathsf{B} \vec{r}^* &=& \lambda \mat{S}_\mathsf{W} \vec{r}^* \\
			      \mat{S}_\mathsf{W}^{-1} \mat{S}_\mathsf{B} \vec{r}^* &=& \lambda \vec{r}^* \\
		      \end{eqnarray*}
		      }
		\item \structure{Note}: $\mat{S}_\mathsf{B} \vec{r}^*$ is always in the direction of $\vec{\mu}_1 - \vec{\mu}_2$; \\
		      no need to compute the eigenvalues and eigenvectors of $\mat{S}_\mathsf{W}^{-1} \mat{S}_\mathsf{B}$! \\[.25cm]
		      The direction of $\vec{r}^*$ is:
		      {\small
		      \begin{displaymath}
			      \vec{r}^* = \mat{S}_\mathsf{W}^{-1} (\vec{\mu}_1 - \vec{\mu}_2)
		      \end{displaymath}
		      }
	\end{enumerate}
\end{frame}

\begin{frame}
	\frametitle{Fisher Transform \cont}

	\begin{itemize}
		\item Usually the total linear mapping for LDA is computed dimension by dimension through the maximization of the
		      Rayleigh ratio for each projection axis $\vec a^*$:
		      \begin{eqnarray*}
			      \vec a^* &=& \argmax_{\vec a}\ \frac{\vec a^T \mat \Sigma_{\mbox{inter}} \vec a}{\vec a^T \mat \Sigma_{\mbox{intra}} \vec a}
		      \end{eqnarray*}
		      \pause
		\item The solution is a generalized eigenvalue problem: $\vec a$ is the eigenvector of
		      $$\mat \Sigma_{\mbox{intra}} ^{-1} \mat \Sigma_{\mbox{inter}}$$
		      that belongs to the largest eigenvalue.
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Fisher Transform \cont}

	In literature the optimization problem is mostly rewritten:
	\spread

	\begin{itemize}
		\item Equivalent constrained optimization problem
		      \begin{eqnarray*}
			      \mbox{maximize:}   & & \vec r^T \mat \Sigma_{\mbox{inter}}\vec r\\
			      \mbox{subject to:} & & \vec r^T \mat \Sigma_{\mbox{intra}} \vec r =1
		      \end{eqnarray*}
		      \spread
		\item Lagrange multiplier method ($\lambda>0$):
		      \begin{displaymath}
			      \vec{r}^* = \argmax_{\vec r}
			      \left\{
			      \vec r^T \mat \Sigma_{\mbox{inter}} \vec r
			      - \lambda{\vec r^T \mat \Sigma_{\mbox{intra}} \vec r}
			      \right\}
		      \end{displaymath}
	\end{itemize}
\end{frame}

\subsection{Dimensionality Reduction}

\begin{frame}

	\frametitle{Dimensionality Reduction}

	A few comments on dimensionality reduction:

	\begin{itemize}
		\item PCA does not require a classified set of feature vectors \\
		      (in contrast to LDA). \\[.15cm]
		\item PCA transformed features are approximately normally distributed (central limit theorem). \\[.15cm]
		\item Components of PCA transformed features are mutually independent. \\[.15cm]
		\item There exist many other methods for dimensionality reduction, e.\,g.,
		      Sammon transform, independent component analysis. \\[.15cm]
		\item Usually the estimation of transforms is computationally prohibited. \\[.15cm]
		\item \structure{Johnson-Lindenstrauss lemma}: If vectors are projected onto a randomly selected subspace of suitably high dimension, then the distances between the vectors are approximately preserved.
	\end{itemize}
\end{frame}

\input{nextTime.tex}

\subsection{LDA application: adidas\_1 }

\begin{frame}
	\frametitle{The adidas\_1: A Digital Revolution in Sports}

	\vspace{.5cm}
	\begin{columns}[c,onlytextwidth]
		\begin{column}{0.4\textwidth}
			\includegraphics[width=1.25\linewidth]{\jpgdir/adidas_1_components.\jpg}
		\end{column}\begin{column}{0.6\textwidth}
			\begin{itemize}
				\item For the first time ever, sport specific information can be processed with a running shoe
				\item A built-in microprocessor permits an adaptation of the shoe to the prevailing run situation
				      \begin{itemize}
					      \item Running speed
					      \item Runner fatigue
					      \item Running surface
					      \item \ldots
				      \end{itemize}
				\item Pattern Recognition at the LME provides the algorithms used for recognition
			\end{itemize}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	\frametitle{The adidas\_1: System Overview}

	\vspace{.5cm}

	\begin{columns}[c, onlytextwidth]
		\begin{column}{0.5\textwidth}
			\structure{Important parts of the adidas\_1:}
			\begin{itemize}
				\item A cushioning element (01) with a magnetic system for compression measurement \\
				      \begin{itemize}
					      \item $f_\mathsf{sample} = 1\mbox{kHz}$
					      \item resolution $\Delta d = 0.1\,\mbox{mm}$
				      \end{itemize}
				\item A microcontroller and user interface (02)
				      \begin{itemize}
					      \item $f_\mathsf{clock} = 24\,\mbox{MHz}$
					      \item 8 kB program memory
				      \end{itemize}
				\item A motor for cushioning adaptation \\
				      using a cable system (03)
			\end{itemize}
		\end{column}\begin{column}{0.3\textwidth}
			\includegraphics[width=\linewidth]{\jpgdir/adidas_shoe_exploded.\jpg}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}
	\frametitle{The adidas\_1: Classification Framework Requirements}

	\begin{itemize}
		\item Only a few, simple features can be calculated in real time \\[.3cm]
		\item The classification system has to be efficient, \\
		      but computationally undemanding \\[.3cm]
		\item LDA classifier yields a linear decision boundary and can be implemented using a polynomial of order one with weights $\alpha_i$ and features $x_i$ \\[.3cm]
		\item In the two class case:
		      \begin{displaymath}
			      \mbox{sgn}(\vec\alpha^T\vec x+\alpha_0) =
			      \mbox{sgn} \left ( \alpha_1 x_1 + \alpha_2 x_2 + \ldots + \alpha_d x_d + \alpha_0 \right )
		      \end{displaymath}
		      yields decision for either class.
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Classification System: Computed Features}

	\begin{itemize}
		\item 19 features initially computed for classification experiments
		\item Feature selection: 3 features selected for implementation
	\end{itemize}

	\begin{center}
		\includegraphics[width=.7\linewidth]{\jpgdir/adidas_features.\jpg}
	\end{center}
\end{frame}

\begin{frame}
	\frametitle{Classification System: LDA Classifier Visualization}

	\begin{itemize}
		\item Visualization of the decision region for hard/soft surface classification \\
		      in 3D feature space
	\end{itemize}

	\begin{center}
		\includegraphics[width=.45\linewidth]{\jpgdir/adidas_decision_region.\jpg}
	\end{center}
\end{frame}

\iftrue

	\subsection{PCA application: Shape Modeling}

	\begin{frame}
		\frametitle{Shape Modeling}

		\begin{itemize}
			\item Each shape is represented by $n$ sampled surface points.
			\item Surface points are denoted by $\vec p_k\in \real^3$, $k=1,2, \dots, n$.
			\item The set of surface points is encoded in a single vector (shape vector):
			      \begin{displaymath}
				      \vec x = \left(
				      \begin{array}{c}
						      \vec p_{1} \\
						      \vec p_{2} \\
						      \vdots     \\
						      \vec p_{n}
					      \end{array}
				      \right)
				      = \left(
				      \begin{array}{c}
						      p_{1,1} \\ p_{1,2} \\ p_{1,3} \\ p_{2,1}\\ \vdots \\ p_{n,3}
					      \end{array}
				      \right)
				      \in \real^{3n}
			      \end{displaymath}
			      with $\vec p_k=(p_{k,1}, p_{k,2},  p_{k,3})^T$.
		\end{itemize}
	\end{frame}

	\begin{frame}
		\frametitle{Shape Modeling \cont}

		We have $m$ shapes, thus $m$ shape vectors, and can generate the landmark configuration matrix:

		\begin{displaymath}
			\mat L =  [\vec x_1, \vec x_2, \dots, \vec x_m]
		\end{displaymath}
		\pause

		Now we can compute the PCA of the columns of $\mat L$ and get the spectral decomposition of the associated covariance matrix

		\begin{displaymath}
			\mat \Sigma_L = \sum_i \lambda_i \vec e_i \vec e_i^T
		\end{displaymath}

		where $\lambda_i$ denote the eigenvalues and $\vec e_i$ the eigenvectors.
	\end{frame}

	\begin{frame}
		\frametitle{Shape Modeling \cont}

		Shape vectors $\vec x^*$ within the eigenvector space can be computed using linear combinations of $l$ eigenvectors:

		\begin{displaymath}
			\vec x^* = \bar{\vec x} + \sum_{i=1}^l a_i \vec e_i
		\end{displaymath}

		where $\bar{\vec x}$ denotes just the mean of the column vectors of $\mat L$ and $a_i\in \real$ are the shape parameters.
	\end{frame}

	\begin{frame}
		\frametitle{Application of PCA: Segmentation}

		\begin{itemize}
			\item Lung, liver or kidneys
			\item Generate and train an Active Shape Model (ASM) for such organs; \\
			      requires training data and ``gold standard'' segmentation
			\item Once \structure{point correspondences} are found, the different variations within the training data can be easily approximated by its Eigenvectors
		\end{itemize}

\begin{figure}
  \copyrightbox[b]{
      \makebox[.3\linewidth]{
        \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006}{
          \includegraphics[height=.2\textwidth]{\psdir/ASMFirstEigenMode.\ps}\hspace{2cm}
        }
      }
      \makebox[.3\linewidth]{
        \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006}{
          \includegraphics[height=.2\textwidth]{\psdir/ASMSecondEigenMode.\ps}
        }
      }
  }{M. Spiegel, D. Hahn, V. Daum, J. Wasza, J. Hornegger. \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006} {``Segmentation of kidneys using a new active shape model generation technique based on non-rigid image registration'', Computerized Medical Imaging and Graphics 2009}}
\caption{Variation of the mean kidney shape along the first and second Eigenvector.}
  \end{figure}

	\end{frame}

	\begin{frame}
		\frametitle{Application of PCA: Segmentation \cont}

\begin{figure}
  \copyrightbox[b]{
      \makebox[.5\linewidth]{
        \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006}{
          \includegraphics[height=.45\textwidth]{\psdir/ASMSegmentationExample.\ps}
        }
      }
  }{M. Spiegel, D. Hahn, V. Daum, J. Wasza, J. Hornegger. \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006} {``Segmentation of kidneys using a new active shape model generation technique based on non-rigid image registration'', Computerized Medical Imaging and Graphics 2009}}
\caption{Iterative segmentation progress of a right kidney using an ASM.}
  \end{figure}

	\end{frame}

	\begin{frame}
		\frametitle{Application of PCA: Segmentation \cont}

\begin{figure}
  \copyrightbox[b]{
      \makebox[.5\linewidth]{
        \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006}{
          \includegraphics[height=.45\textwidth]{\jpgdir/ASM3DResults.\jpg}
        }
      }
  }{M. Spiegel, D. Hahn, V. Daum, J. Wasza, J. Hornegger. \href{https://www.sciencedirect.com/science/article/abs/pii/S0895611108001006} {``Segmentation of kidneys using a new active shape model generation technique based on non-rigid image registration'', Computerized Medical Imaging and Graphics 2009}}
\caption{3-D view of the segmentation result.}
  \end{figure}
	\end{frame}

\fi

\input{nextTime.tex}

\subsection{Notes on Regression}

\subsubsection{Linear Regression}

\begin{frame}
	\frametitle{Notes on Regression}

	In the two class situation, we set $y\in \{-1,+1\}$ and use the decision rule:

	\begin{displaymath}
		y^* = \mbox{sgn}(\vec \alpha^T\vec x + \alpha_0).
	\end{displaymath}

	We can compute the linear decision boundary simply by least-square estimation.
\end{frame}

\begin{frame}
	\frametitle{Linear Regression \cont}

	For a given set of learning data we use matrix notation:

	\begin{displaymath}
		\mat{X} = \left(
		\begin{array}{cc}
				\vec x_1^T & 1      \\
				\vec x_2^T & 1      \\
				\vdots     & \vdots \\
				\vec x_m^T & 1
			\end{array}
		\right) \in \real^{m\times (d+1)} \qquad \vec y \quad = \quad
		\left(
		\begin{array}{c}
				y_1    \\
				y_2    \\
				\vdots \\
				y_m    \\
			\end{array}
		\right) \in \real^m
	\end{displaymath}

	and define

	\begin{displaymath}
		\vec \theta = { \vec \alpha\choose \alpha_0}
	\end{displaymath}
\end{frame}

\begin{frame}
	\frametitle{Linear Regression \cont}

	One option to estimate $\vec \theta$ is to solve the linear regression problem:

	\begin{displaymath}
		\hat{\vec \theta} = \argmin_{\vec \theta}\| \mat X \vec \theta - \vec y\|_{2}^2
	\end{displaymath}
\end{frame}

\begin{frame}
	\frametitle{Linear Regression \cont}

	The \structure{least-square estimator} for the $L_2$-norm:

	\begin{eqnarray*}
		\widehat{\vec \theta} &=& \argmin_{\vec\theta} \ \sum_{i=1}^m (\vec \theta^T\vec x_i-y_i)^2\\
		&=& \argmin_{\vec\theta} \ (\mat{X}\vec \theta-\vec y)^T(\mat{X}\vec \theta-\vec y)
	\end{eqnarray*}
	\pause

	and thus we get

	\begin{displaymath}
		\widehat{\vec \theta} = (\mat{X}^T\mat{X})^{-1}\mat{X}^T\vec y
	\end{displaymath}

	if the column vectors of $\mat X$ are mutually independent.
\end{frame}

\begin{frame}
	\frametitle{Linear Regression \cont}

	\structure{A few obvious questions:} \\[.5cm]

	\begin{itemize}
		\item Why should we prefer the Euclidean norm ($L_2$-norm)? \\[.5cm]
		\item Will different norms lead to different results? \\[.5cm]
		\item Which norm and decision boundary is the best one? \\[.5cm]
		\item Can we incorporate prior knowledge in linear regression?
	\end{itemize}
\end{frame}

\subsubsection{Ridge Regression}

\begin{frame}
	\frametitle{Ridge Regression}

	In \structure{\emph{ridge regression}} (also called \emph{regularized regression}) we extend the \\
	objective function by an additional term constraining the Euclidean length \\
	of the parameter vector $\vec{\theta}$:

	\begin{itemize}
		\item It is linear regression with the log-likelihood penalized by $-\lambda\vec \theta^T \vec \theta$ \\
		      where $\lambda > 0$, or alternatively \\[.5cm]
		\item It is extended by a prior distribution on the parameter vector $\vec\theta$
		      \begin{displaymath}
			      \vec \theta = {\cal N}(\vec 0,\mbox{diag}( \tau^2) )
		      \end{displaymath}
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Ridge Regression \cont}

	\structure{Regularized regression:}

	\begin{eqnarray*}
		\widehat{\vec\theta}
		&=& \argmin_{\vec\theta} \| \mat{X} \vec\theta - \vec y \|^2_2 + \lambda \|\vec\theta\|^2_2 \\ \pause
		&=& \argmin_{\vec\theta} \ (\mat{X} \vec\theta - \vec y)^T (\mat{X} \vec\theta-\vec y) +
		\lambda \cdot \vec\theta^T\vec \theta
	\end{eqnarray*}
	\pause

	and thus we get the estimator:

	\begin{displaymath}
		\widehat{\vec\theta} = (\mat{X}^T\mat{X}+\lambda \mat{I})^{-1}\mat{X}^T\vec y
	\end{displaymath}
\end{frame}

\begin{frame}
	\frametitle{Ridge Regression \cont}

	\structure{Notes:}

	\begin{itemize}
		\item The term $\lambda \mat{I}$ adds a positive constant $\lambda$ to the diagonal elements.
		\item The problem is non-singular even if $\mat{X}^T \mat{X}$ is not of full rank. \\
		\item This was the main motivation of ridge regression when it was first introduced in statistics in 1970. \\[.25cm] \pause
		\item The ridge solutions are not equivariant under scaling of the inputs: \\
		      \structure{standardize} the input before solving the regression problem! \\[.25cm] \pause
		\item The intercept $\alpha_0$ should not be penalized:
		      \begin{itemize}
			      \item \structure{Center} the input $\vec{x}_i$.
			      \item Estimate $\alpha_0$ by $\bar{y} = \frac{1}{m} \sum_{i=1}^m y_i$.
			      \item Estimate the remaining coefficients by a ridge regression without  intercept. \\
			            Matrix $\vec{X}$ has $d$ columns (instead of $d+1$).
		      \end{itemize}
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Ridge Regression \cont}

	\structure{Statistical approach:} parameters $\alpha_j$ are random variables \\[.5cm]

	\begin{itemize}
		\item Suppose
		      \begin{displaymath}
			      \forall 1 \le i \le m: \quad y_i
			      \sim \mathcal{N}(\underbrace{\vec{\alpha}^T \vec{x}_i + \alpha_0}_\text{mean}, \underbrace{\sigma^2}_\text{variance})
			      \onslide<2->{
				      = \frac{1}{\sqrt{2 \pi} \cdot \sigma} e^{-\frac{1}{2} \cdot \frac{(y_i - \vec{\alpha}^T \vec{x}_i - \alpha_0)^2}{\sigma^2}}
			      }
		      \end{displaymath}
		\item Parameters $\alpha_j$ are assumed to be independent of each other.
		\item Prior distribution of $\alpha_j$:
		      \begin{displaymath}
			      \forall 1 \le j \le d: \quad \alpha_j
			      \sim \mathcal{N}(0, \tau^2)
			      \onslide<3->{
				      = \frac{1}{\sqrt{2 \pi} \cdot \tau} e^{-\frac{1}{2} \cdot \frac{(\alpha_j - 0)^2}{\tau^2}}
			      }
		      \end{displaymath}
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Ridge Regression \cont}

	\begin{itemize}
		\item \structure{Maximizing the posterior probability of $\vec{\alpha}$ for given $\sigma^2$ and $\tau^2$:}
		      \footnotesize
		      \begin{eqnarray*}
			      \argmax_{\vec{\alpha}} \prod_{i=1}^m p(\vec{\alpha}|y_i) \pause
			      &=& \argmax_{\vec{\alpha}} \Bigg\{ \prod_{i=1}^m p(\vec{\alpha}) \cdot p(y_i | \vec{\alpha}) \Bigg\} \\ \pause
			      &=& \argmax_{\vec{\alpha}} \Bigg\{ \prod_{j=1}^d p(\alpha_j) \cdot \prod_{i=1}^m p(y_i | \vec{\alpha}) \Bigg\} \\ \pause
			      &=& \argmax_{\vec{\alpha}} \Bigg\{ \sum_{j=1}^d \log p(\alpha_j) + \sum_{i=1}^m \log p(y_i | \vec{\alpha}) \Bigg\} \\ \pause
			      &=& \argmax_{\vec{\alpha}} \Bigg\{ - \frac{1}{2 \tau^2} \sum_{j=1}^d \alpha_j^2 - \frac{1}{2 \sigma^2} \sum_{i=1}^m (y_i - \vec{\alpha}^T \vec{x} - \alpha_0)^2 \Bigg\} \\ \pause
			      &=& \argmin_{\vec{\alpha}} \Bigg\{ \frac{\sigma^2}{\tau^2} \sum_{j=1}^d \alpha_j^2 + \sum_{i=1}^m (y_i - \vec{\alpha}^T \vec{x} - \alpha_0)^2 \Bigg\}
		      \end{eqnarray*}
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Ridge Regression \cont}

	\begin{itemize}
		\item \structure{Maximizing the posterior probability of $\vec{\alpha}$ for given $\sigma^2$ and $\tau^2$:} \\[.25cm]
		      {\footnotesize
		      \begin{displaymath}
			      \argmax_{\vec{\alpha}} \prod_{i=1}^m p(\vec{\alpha}|y_i)
			      = \argmin_{\vec{\alpha}} \Bigg\{ \lambda \vec{\alpha}^T \vec{\alpha} + (\mat{X}\vec{\alpha} - \vec{y})^T (\mat{X}\vec{\alpha} - \vec{y}) \Bigg\}
			      \quad \text{with} \quad
			      \lambda = \frac{\sigma^2}{\tau^2}
		      \end{displaymath}
		      }
		      \vspace{.25cm} \pause
		\item \structure{The ridge estimate is the mode of the posterior pdf!}
	\end{itemize}
\end{frame}

\subsubsection{Lasso}

\begin{frame}
	\frametitle{Lasso}
	Regularized regression using a mixture of $L_2$- and $L_1$-norm, \\
	where the residual is penalized using the $L_2$-norm and \\
	the regularizer uses the $L_1$-norm:

	\begin{displaymath}
		\widehat{\vec \theta} = \argmin_{\vec\theta} \|\mat{X}\vec \theta-\vec y\|^2_2 + \lambda \cdot \|\vec \theta\|_1
	\end{displaymath}
	\pause

	The lasso is used to compute a sparse solution of the system of \\
	linear equations, i.\,e.\ the number of non-zero elements in $\vec \theta$ shall be small.
\end{frame}

\subsection{Lessons Learned}

\begin{frame}
	\frametitle{Lessons Learned}

	\begin{itemize}
		\item Principal component analysis \\[.5cm]
		\item Linear discriminant analysis with and without dimension reduction \\[.5cm]
		\item Both PCA and LDA relate to an eigenvalue eigenvector problem \\[.5cm]
		\item Alternative formulation of LDA using the Fisher transform \\[.5cm]
		\item Linear and ridge regression for classification
	\end{itemize}
\end{frame}

\input{nextTime.tex}

\subsection{Further Readings}

\begin{frame}
	\frametitle{Further Readings}

	You are required to be familiar with \structure{linear algebra} and \structure{matrix calculus}:

	\begin{itemize}
		\item SIAMS best selling book in the last decade:\\[.15cm]
		      Lloyd N. Trefethen, David Bau III: \\
		      \structure{Numerical Linear Algebra}, \\
		      SIAM, Philadelphia, 1997. \\[0.15cm]
		\item All about matrix derivatives and related problems is described in the Matrix Cookbook:
		      \structure{\url{http://www.matrixcookbook.com}} \\[.3cm]
	\end{itemize}

	Basics on \structure{discriminant analysis} can be found in

	\begin{itemize}
		\item T. Hastie, R. Tibshirani, and J. Friedman: \\
		      \structure{The Elements of Statistical Learning --}\\
		      \structure{ Data Mining, Inference, and Prediction},\\
		      2nd edition, Springer, New York, 2009.
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Further Readings \cont}

	\structure{Details on the adidas\_1 shoe and the implemented classifier:}

	\begin{itemize}
		\item B.~Eskofier, F.~H\"onig, P.~K\"uhner: \\
		      \structure{Classification of Perceived Running Fatigue in Digital Sports}, \\
		      Proceedings of the 19th International Conference on Pattern Recognition (ICPR 2008), Tampa, Florida, U.\,S.\,A., 2008
	\end{itemize}
	\spread

	\structure{Details on the shape modeling of kidneys and its application to segmentation:}

	\begin{itemize}
		\item M.~Spiegel, D.~Hahn, V.~Daum, J.~Wasza, J.~Hornegger: \\
		      \structure{Segmentation of kidneys using a new active shape model generation technique based on non-rigid image registration}, \\
		      Computerized Medical Imaging and Graphics 2009 33(1):29-39
	\end{itemize}
\end{frame}

\subsection{Comprehensive Questions}

\begin{frame}
	\frametitle{Comprehensive Questions}

	\begin{itemize}
		\item What is the difference between PCA and LDA? \\[1cm]
		\item How can PCA and LDA be combined to achieve a high rank reduction? \\[1cm]
		\item Write down a straight forward objective function for linear regression! \\[1cm]
		\item What happens if we replace the $L_2$-norm by another norm?
	\end{itemize}
\end{frame}


\documentclass[aps,pra,notitlepage,amsmath,amssymb,letterpaper,12pt]{revtex4-1}
\usepackage{amsthm}
\usepackage{graphicx}
%  Above uses the Americal Physical Society template for Physical Review A
%  as a reasonable and fully-featured default template

%  Below define helpful commands to set up problem environments easily
\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{solution}{\begin{proof}[Solution]}{\end{proof}}

% --------------------------------------------------------------
%                   Document Begins Here
% --------------------------------------------------------------

% In what follows, you can easily change text to see what happens to the document
% For example, replacing the text "Document X" inside the "\title{}" command will
% change the document title

\begin{document}

\title{Double Well Potential}
\author{Gabriella Nutt}
\affiliation{PHYS 220, Schmid College of Science and Technology, Chapman University}
\date{\today}

\maketitle

\section{Double Well Potential} % Specify main sections this way

% x.yz is the problem number
\begin{problem}{1}
Consider a ball of mass $m$ with horizontal coordinate $x$ rolling in a double-well potential $V(x) = x^4/4 - x^2/2$. (This is sometimes called the "sombrero" potential. Plot it to see why, for $x\in[-1.5,1.5]$.) This potential produces a force $f_{\text{hat}}(x) = -V'(x) = -x^3 + x$ on the rolling ball. Suppose the ball also has slight friction, so experiences a drag force $f_{\text{drag}}(\dot{x}) = -\nu \dot{x}$. With these forces we thus expect the ball to roll down the sides of the sombrero potential and settle in one of the two stable wells. However, this is boring, so instead we are going to shake the hat back and force periodically with a driving force $f_{\text{drive}}(t) = F\cos(\omega t)$. For small driving forces $F$, this should simply jiggle the ball back and forth at the bottom of one of the stable wells. Our task will be to explore what happens for larger driving forces $F$.
Note that according to Newton's second law, the ball must satisfy the equation of motion: $$m\ddot{x} = f_{\text{hat}}(x) + f_{\text{drag}}(\dot{x}) + f_{\text{drive}}(t) = x - x^3 - \nu \dot{x} + F\cos(\omega t)$$ This system is known as a periodically driven nonlinear "Duffing oscillator," and can be split into a set of two coupled first-order ODEs: $$\dot{x}(t) = y(t)$$ $$m\dot{y}(t) = -\nu y(t) + x(t) - x^3(t) + F\cos(\omega t)$$ Your task will be to solve these equations numerically, for $m=1$, $\nu = 0.25$, and $\omega = 1$. Use a time-step size of $\Delta t = 0.001$ with the 4th-order Runge-Kutta integration method to keep sufficient numerical precision. Implement your code in a python file sombrero.py with suitable test functions in testsombrero.py.
\end{problem}

\begin{solution} %You can also use proof in place of solution
In this we solved the differential equations above and observed their behavior on different graphs as their we change the values of F, x(0), and y(0).
From look at all of these graphs it can be found that changing the initial conditions drastically change the behavior. At first it seems like when you change the conditions that the oscillating motion becomes more inconsistent. To further explore the behavior we can strobe the graph at different instances and turn it into a gif. This gives us better insight into the motion of a point. It's very fun. When doing this you actually find the oscillating motion isn't as inconsistent as as it seems when you only observe one moment.
% Use align environments for equations. The \\ is a newline character. The & is the alignment character.
% Using align* or \nonumber on each line removes equation numbers
\end{solution}

\subsection{Here is a scatter plot!} % Specify subsections and subsubsections this way

Figures can be included easily.

\begin{figure}[h!] % h forces the figure to be placed here, in the text
  \includegraphics[width=0.4\textwidth]{frame99.png}  % if pdflatex is used, jpg, pdf, and png are permitted
  \caption{Strobe of duffing oscillator.}
  \label{fig:figlabel}
\end{figure}

This text should be below the figure unless \LaTeX  decides that a different layout works better.

% Repeat as needed

\end{document}


In this appendix some \gls{ir} background is presented, as core data storage and querying of our prototype\index{prototype} is based on.

\subsubsection{TF-IDF \& Apache Lucene}

The equations~\ref{eq:ir-tf-1} to~\ref{eq:ir-tf-idf} lay out some of the most fundamental concepts behind \gls{ir}.

\begin{equation}
\text{tf}(t, d) = f_{t,d}
\label{eq:ir-tf-1}
\end{equation}

\begin{equation}
f_{t,d} =
\begin{cases}
  1 \quad \text{if } t \text{ occurs in } d \\
  0 \quad \text{otherwise} \\
\end{cases}
\label{eq:ir-tf-2}
\end{equation}

\begin{equation}
\text{idf}(t, D) = \log\frac{N}{|\{d \in D : t \in d\}|}
\label{eq:ir-idf}
\end{equation}

\begin{equation}
\text{tf-idf}(t, d, D) = \text{tf}(t, d) \times \text{idf}(t, D)
\label{eq:ir-tf-idf}
\end{equation}

It is \emph{\gls{tf-idf}}\footnote{\textcolor{blue}{\href{https://en.wikipedia.org/wiki/Tf-idf}{en.wikipedia.org/wiki/Tf-idf}}}.
Basically, this is an effective as well as efficient way to score term query search hits based on term occurrences in a corpus of documents.
The illustrated formula set uses a simple boolean frequency.

A popular and high-quality search engine implementation in Java is \emph{Apache Lucene\footnote{\textcolor{blue}{\href{https://lucene.apache.org/}{lucene.apache.org}}}}.
It is also the foundation on which Elasticsearch is built upon~\cite{Gormley2015}.