\documentclass[usletter]{article}
\usepackage[margin=1.5in]{geometry}

\usepackage{graphicx}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{blkarray}

\usepackage[mathscr]{eucal}
\usepackage[dvipsnames]{color}
\usepackage[colorlinks=true,allcolors=blue,breaklinks,draft=false]{hyperref}

\usepackage{scribe}

\def\VR{\kern-\arraycolsep\strut\vrule &\kern-\arraycolsep}
\def\vr{\kern-\arraycolsep & \kern-\arraycolsep}

\newcommand*{\Scale}[2][4]{\scalebox{#1}{\ensuremath{#2}}}%

\newcommand {\mat}[1]  {\ensuremath{\mathbf{#1}}}

\newcommand {\setop}[1]  {\ensuremath{\mathcal{#1}}}
\newcommand {\powerset}  {\setop{P}}

\newcommand {\complexity}[1] {\ensuremath{\mathsf{#1}}}
\newcommand {\D}             {\complexity{D}}
\newcommand {\N}             {\complexity{N}}
\newcommand {\FS}            {\complexity{FS}}
\newcommand {\RS}[1]         {\ensuremath{\complexity{RS}_{#1}}}

\newcommand {\function}[2]  {\ensuremath{\textsc{#1}_{#2}}}
\newcommand {\efunction}[3] {\ensuremath{\textsc{#1}^{#2}_{#3}}}
\newcommand {\DISJ}[2]      {\function{DISJ}{#1,#2}}
\newcommand {\iDISJ}[2]     {\efunction{DISJ}{-1}{#1,#2}}

\newcommand {\bigO}     {\ensuremath{O}}
\newcommand {\bigT}     {\ensuremath{\Theta}}
\newcommand {\bigW}     {\ensuremath{\Omega}}

\newcommand {\vdim}     {\ensuremath{\mathbf{dim}}}
\newcommand {\rank}     {\ensuremath{\mathbf{rk}}\ }
\newcommand {\vspan}    {\ensuremath{\mathbf{span}}}

\newcommand {\operator}[1] {\ensuremath{\mathbb{#1}}}
\newcommand {\prob}        {\operator{P}}

\newcommand {\bit}       {\ensuremath{\{0,1\}}}
\newcommand {\range}[2]  {\ensuremath{\{#1{1},#1{2},\ldots,#1{#2}\}}}
\newcommand {\zrange}[2] {\ensuremath{\{#1{0},#1{1},\ldots,#1{#2}\}}}

\newcommand {\todo}   {\textbf{\color{blue} \large TODO: }}

\newenvironment {todoblock} {
  \begin{center}
  \begin{tabular}{|p{0.9\textwidth}|}
    \hline\\
    \textbf{\color{red} \large TODO:} \\
} {
    \\\\\hline
  \end{tabular}
  \end{center}
}

\begin{document}

\makeheader{Saswat Padhi}                             % your name
           {April 13, 2016}                           % lecture date
           {6}                                        % lecture number
           {$k$-disjointness \& \RS{}-Bound}  % lecture title

\noindent
In this lecture, we examine a function for which the relationship between the deterministic, nondeterministic, and co-nondeterministic communication complexities that we discussed in last section --- $D(f) \leqslant \bigO(\N(f)\ \N(\neg f))$, turns out to be tight. One such function is the $k$-disjointness function (\DISJ{n}{k}). We show that $D(f) \geqslant \bigW(\N(f)\ \N(\neg f))$ for $f = \DISJ{n}{k}$, thus proving that the bounds due to the earlier mentioned relationship is tight.

Finally we discuss a new technique for estimating lower-bounds on non-deterministic communication complexity of functions -- the \complexity{RectangleSize} bound (\RS{}-bound).

\section{The $k$-disjointness function (\textnormal{\DISJ{n}{k})}}

\begin{definition}
the $k$-disjointness function,
$$
\DISJ{n}{k} : \binom{\range{}{n}}{k} \times \binom{\range{}{n}}{k} \rightarrow \bit
$$
where,
$$
\binom{\range{}{n}}{k} = \{ S \subseteq \range{}{n} : |S| = k\}
$$
is defined as:
$$
\DISJ{n}{k}(A, B) =
  \begin{cases}
    \: 1 & \quad \text{if } A \cap B = \phi \\
    \: 0 & \quad \text{otherwise}\\
  \end{cases}
$$
\end{definition}

\noindent
This function is identical to the set disjointness (\function{DISJ}{n}) function, but note that the set of inputs is restricted to subsets of size \textit{exactly} $k$, rather than arbitrary subsets.

\noindent
We state the following lemmas, which are proved in subsequent subsections.
\begin{lemma}[Co-Nondeterministic Complexity]
\label{co-nondet-disj_nk}
$$
\N(\neg\DISJ{n}{k}) = \bigO(\log{n})
$$
\end{lemma}

\begin{lemma}[Nondeterministic Complexity]
\label{nondet-disj_nk}
$$
\N(\DISJ{n}{k}) = \bigO(k + \log{\log{n}})
$$
\end{lemma}

\begin{lemma}[Deterministic Complexity]
\label{det-disj_nk}
$$
\forall k \in \{1,2,\ldots,\lfloor n/2 \rfloor\} :
  \D(\DISJ{n}{k}) = \bigg\lceil \log{\binom{n}{k} + 1} \bigg\rceil
                  \geqslant k \log{\frac{n}{k}}
                  = \bigW(k \log{n})
$$
\end{lemma}

\noindent
It is easy to see that the bound obtained using ($\D(f) \leqslant \bigO(N(f) \ \N(\neg f))$), is tight.

\noindent
With $f = \DISJ{n}{k}$ and $k = \log{n}$, the relationship discussed in the last section gives us:
$$
\D(\DISJ{n}{\log{n}}) \leqslant \bigO(\N(\DISJ{n}{\log{n}}) \ \N(\neg \DISJ{n}{\log{n}}))
$$

\noindent
Using lemmas \ref{co-nondet-disj_nk}, \ref{nondet-disj_nk}, and \ref{det-disj_nk} we have:
$$
\D(\DISJ{n}{\log{n}}) \geqslant \bigW(\N(\DISJ{n}{\log{n}}) \ \N(\neg \DISJ{n}{\log{n}}))
$$

\noindent
Therefore the bound is actual tight, i.e.
$$
\D(\DISJ{n}{\log{n}}) = \bigT(\N(\DISJ{n}{\log{n}}) \ \N(\neg \DISJ{n}{\log{n}}))
$$

\subsection{Proof of Lemma~\ref{co-nondet-disj_nk}}
Proving this lemma is trivial. Note that:
$$
\neg\DISJ{n}{k}(A, B) = 1 \Rightarrow \exists i \in \range{}{n} : i \in A \wedge i \in B
$$
So $A$ can simply \textit{guess} an $i \in A$ and send it to $B$, using $O(\log{n})$ bits. \\$B$ can simply wait till it receives $i$ from $A$ and then output $1$ if $i \in B$.

\subsection{Proof of Lemma~\ref{nondet-disj_nk}}

Note that, if $A \cap B = \phi$, the following must hold:
$$
\exists S \subseteq \range{}{n} : A \subseteq S \wedge B \subseteq \overline{S}
$$
We call such a set $S$, the witness for the disjointness of $A$ and $B$. And we need an efficient protocol to compute such an $S$, to assert that $\DISJ{n}{k}(A, B) = 1$.

\subsubsection*{A Na\"{i}ve Nondeterministic Protocol}

A simple na\"{i}ve nondeterministic protocol could be:
\begin{enumerate}
  \item \textit{Guess} $S \subseteq \range{}{n}$ s.t. $|S| = k$. \hfill (communication cost = $k \log{n}$ bits)
  \item At $A$:
    \begin{enumerate}
        \item Check if $A \subseteq S$.
        \item If the check fails, output $0$ and terminate.
        \item Send a $1$ bit to $B$. \hfill (communication cost = $1$ bit)
    \end{enumerate}
  \item At $B$:
    \begin{enumerate}
        \item Wait till a $1$ bit is received from $A$.
        \item Output $1$ if $B \subseteq \overline{S}$ holds, else output $0$.
    \end{enumerate}
\end{enumerate}
This protocol has a huge communication cost of $\bigO(k \log{n})$! \\
Note that we transmit only the $k$ elements in $S$, with the assumption that $k \ll n$. For larger $k$, a more effective approach might be to transmit an $n$-bit vector, with a cost of $\bigO(n)$.

\subsubsection*{An Efficient Nondeterministic Protocol}

\begin{proof}[Idea]
Rather than \textit{guessing} $S$ from the large set $\powerset(\range{}{n})$, we would show that it is enough to choose $S$ from a much smaller family $\range{S_}{N}$ where $N \ll 2^n$, thus reducing the communication cost for guessing $S$ from $\log{2^{n}}$ to $\lceil \log{N} \rceil$.
\end{proof}

\noindent
Assuming the existence of such an $N$ (for which we provide a concrete value later), we can use the na\"{i}ve protocol with the restriction of \textit{guessing} $S$ from the family $\range{S_}{N}$. We pick sets $\range{S_}{N} \subseteq \range{}{n}$ uniformly at random. \\

\noindent
Then, for any pair of sets $\langle A, B\rangle \in \iDISJ{n}{k}(1)$,
\begin{align*}
&\underset{\range{S_}{N}}{\Scale[1.5]{\prob}}
   \Big[ \forall i : A \not\subseteq S_i \vee
                     B \not\subseteq \overline{S_i} \Big] \\
=\ &\bigg( \underset{S \subseteq \range{}{n}}{\Scale[1.5]{\prob}}
   \Big[ A \not\subseteq S \vee B \not\subseteq \overline{S} \Big] \bigg)^N \\
=\ &\bigg( 1 - \underset{S \subseteq \range{}{n}}{\Scale[1.5]{\prob}}
   \Big[ A \subseteq S \wedge B \subseteq \overline{S} \Big] \bigg)^N \\
=\ &\bigg( 1 - \frac{1}{2^{2k}} \bigg)^N  < e^{-\frac{N}{2^{2k}}}
\end{align*}

\noindent
Therefore,
\begin{align*}
&\underset{\range{S_}{N}}{\Scale[1.5]{\prob}}
   \Big[ \exists \langle A, B \rangle \subseteq \iDISJ{n}{k}(1) :
                 \forall i : A \not\subseteq S_i \vee
                             B \not\subseteq \overline{S_i} \Big] \\
<\ & \iDISJ{n}{k}(1) \cdot e^{-\frac{N}{4^k}} \\
<\ & \binom{n}{k} \binom{n-k}{k} \cdot e^{-\frac{N}{4^k}} \\
\ll\ & \frac{n^{2k}}{e^{-\frac{N}{4^k}}}
\end{align*}

\noindent
The above value is strictly less than $1$ for $N = \lceil 4^k 2k \ln{n}\rceil$. \\
Thus, $\N(\DISJ{n}{k}) \leqslant \log{\lceil 4^k 2k \ln{n}\rceil} = \bigO(k + \log{\log{n}})$.

\subsection{Proof of Lemma~\ref{det-disj_nk}}

In our discussion, we abbreviate the matrix $M_{\DISJ{n}{k}}$ of the function $\DISJ{n}{k}$ to $M_{n,k}$.

\noindent
For proving lemma~\ref{det-disj_nk} it is enough to show that,
$$
\forall k \in \zrange{}{\lfloor n/2 \rfloor} : \rank M_{n,k} = \binom{n}{k}
$$
i.e. the matrix $M_{n,k}$ has \textit{full} rank for $0 \leqslant k \leqslant \lfloor \frac{n}{2} \rfloor$. \\

\noindent
We prove this by induction on $k$. \\
Note that the base cases here are $k = 0$ and $k = \lfloor \frac{n}{2}\rfloor$, which are easily verified.
\begin{align*}
    k = 0 &\Rightarrow M_{n,k} = \mat{1}_{\binom{n}{k}} \\
          &\Rightarrow \rank M_{n,k} = 1 = \binom{n}{0}
\end{align*}
\begin{align*}
    k = \Big\lfloor \frac{n}{2} \Big\rfloor
        &\Rightarrow M_{n,k} = \mat{I}_{\binom{n}{k}} \\
        &\Rightarrow \rank M_{n,k} = \binom{n}{k}
\end{align*}

\noindent
Here \mat{1} denotes the \textit{all-ones} square matrix and \mat{I} denotes the identity matrix.

\subsubsection*{Proving the inductive case}

Note that, $M_{n,k}$ has the following block form:
$$ \arraycolsep=1.45pt \def\arraystretch{2}
  \begin{blockarray}{ccc}
    & n \in B & n \not\in B \\
    \begin{block}{c[c|c]}
      n \in A   & \mat{0} & * \\
      \cline{2-3}
      n \not\in A & * & M_{n-1,k} \\
    \end{block}
  \end{blockarray}
$$

\noindent
The above matrix $M_{n,k}$ can be transformed to:
$$ \arraycolsep=1.6pt \def\arraystretch{2.5}
  \begin{blockarray}{ccc}
    & n \in B & n \not\in B \\
    \begin{block}{c[c|c]}
      n \in A     & M_{n-1,k-1} & \mat{0} \\
      \cline{2-3}
      n \not\in A & * & M_{n-1,k} \\
    \end{block}
  \end{blockarray}
$$

\noindent
using elementary matrix operations:
\begin{align*}
M_{n,k}(A,B) &\mapsto -M_{n,k}(A,B) + \frac{1}{n - 2k + 1}
                                     \sum_{\{\widetilde{A} : A - \{n\} \subseteq \tilde{A}\}} {M_{n,k}(\widetilde{A},B)} \\
             &= -M_{n,k}(A,B) + \frac{1}{n - 2k + 1}
                                (n - 2k + 1)\DISJ{n}{k}(A-\{n\}, B-\{n\}) \\
             &= \begin{cases}
                  \DISJ{n-1}{k-1}(A-\{n\}, B-\{n\})
                        &\quad \text{if } n \in A \wedge n \in B \\
                  0
                        &\quad \text{if } n \in A \wedge n \not\in B \\
                  \DISJ{n}{k}(A, B)
                        &\quad \text{otherwise}
                \end{cases}
\end{align*}

\noindent
It is now easy to see that,
\begin{align*}
    \rank M_{n,k} &= \rank M_{n-1,k-1} + \rank M_{n-1,k} \\
                  &= \binom{n-1}{k-1} + \binom{n-1}{k} & \text{(Using the induction hypothesis)} \\
                  &= \binom{n}{k}
\end{align*}
Using the \complexity{Rank}-bound, we get lemma~\ref{det-disj_nk}.

\clearpage

\section{The \complexity{RectangleSize} (\RS{}) Bound}

\begin{definition}
For a function $f : \bit^n \times \bit^n \rightarrow \bit$, given a probability distribution $\mu$ over $f^{-1}(1)$, the rectangle size of $f$ with respect to $\mu$ is defined as:
$$
\RS{\mu}(f) = \max{\{\mu(R) : R \text{ is an $f$-monochromatic rectangle in } M_f\}}
$$
where $\displaystyle \mu(R) = \sum_{x \in R} \mu(x)$.
\end{definition}

\begin{example}
Consider the following matrix $M_f$ for a function $f$, and the associated probability distribution $\mu$: (superscripts indicate probabilities induced by $\mu$)
{\large $$
M_f = \begin{bmatrix}
        ^{(1/2)}1 & 1         & 0 \\
        0         & ^{(1/2)}\underline{1} & \underline{1} \\
        1         & \underline{1}         & \underline{1} \\
      \end{bmatrix}
$$
}
$\RS{\mu}(f) = \frac{1}{2}$, for the $2\times2$ rectangle defined by the underlined ones ($\underline{1}$).
\end{example}

\begin{example}
Now consider a minor variation of the function $f$:
{\large $$
M_f = \begin{bmatrix}
        ^{(1/2)}\underline{1} & \underline{1} & 0 \\
        \underline{1} & ^{(1/2)}\underline{1} & 1 \\
        \underline{1} & \underline{1}         & 1 \\
      \end{bmatrix}
$$
}
$\RS{\mu}(f) = 1$, for the $3\times2$ rectangle defined by the underlined ones ($\underline{1}$).
\end{example}

\begin{definition}
For a function $f : \bit^n \times \bit^n \rightarrow \bit$, the rectangle size of $f$ is defined as:
$$
\RS{}(f) = \min_{\mu \text{ on } f^{-1}(1)} \RS{\mu}(f)
$$
\end{definition}

\begin{example}
Consider a function $f$ with the following matrix $M_f$:
{\large $$
M_f = \begin{bmatrix}
        0 & 0 & ^{0.087}1 & ^{0.053}1 & ^{0.025}1 & ^{0.057}1 \\
        ^{0.082}1 & 0 & 0 & 0 & 1 & ^{0.14}1 \\
        0 & ^{0.029}1 & ^{0.031}1 & ^{0.051}1 & 0 & 0 \\
        ^{0.054}\underline{1} & ^{0.024}\underline{1} & 0 & ^{0.119}\underline{1} & ^{0.026}\underline{1} & 0 \\
        ^{0.054}1 & ^{0.058}1 & ^{0.104}1 & 0 & ^{0.006}1 & 0 \\
      \end{bmatrix}
$$
}
$\RS{}(f) \approx \frac{2}{9}$. The underlined ones ($\underline{1}$) show one particular $\mu$ which achieves this.
\footnote{The \href{http://www.sagemath.org/}{\texttt{SageMath}} script used to compute this is available on
  \href{https://github.com/SaswatPadhi/S16_CS289A/blob/master/Lec6/RectSize.sagews}{GitHub}}.
\end{example}

\begin{theorem}[The \complexity{RectangleSize} bound]
For any function $f : \bit^n \times \bit^n \rightarrow \bit$,
$$
\N(f) \geqslant \bigg\lceil \log{\frac{1}{\RS{}(f)}} \bigg\rceil
$$
\end{theorem}
\begin{proof}
Let $\mu$ be any probability distribution on $f^{-1}(1)$, \\
and the rectangles \range{R_}{c} be the cover of $f^{-1}(1)$. \\

\noindent
Then we have:
\begin{align*}
    1 =\ & \mu(f^{-1}(1)) \\
      =\ & \mu\bigg( \bigcup_{i=1}^{c}R_i \bigg) \\
      \leqslant\ & \sum_{i=1}^{c}\mu(R_i) \\
      =\ & c \ \RS{\mu}(f)
\end{align*}

\begin{flalign*}
    \text{Therefore,}
    \qquad
    &c \geqslant \frac{1}{\RS{\mu}(f)} \geqslant \frac{1}{\RS{}(f)}& \\
    \text{Further,}
    \qquad
    &\N(f) \geqslant \log{c} \geqslant \log{\bigg\lceil \frac{1}{\RS{}(f)} \bigg\rceil}&
\end{flalign*}
\end{proof}

\noindent
The following corollary follows immediately from the above theorem, since $\displaystyle \RS{}(f) \leqslant \frac{1}{\FS{}(f)}$.

\begin{corollary}$\label{nondet-fs-relation}
\displaystyle
\N(f) \geqslant \bigg\lceil \log{\FS(f)} \bigg\rceil
$\end{corollary}

\subsection*{Revisiting the \N(f) Bounds}

\subsubsection*{The Equality Function (\function{EQ}{n})}

It is easy to observe that $M_{\function{EQ}{n}} = \mat{I}_{2^n}$.

\begin{itemize}
  \item $\N(\function{EQ}{n})$: \\
  A 1-\complexity{FoolingSet} for $\mat{I}_{2^n}$ is simply the diagonal, which has $2^n$ elements. \\
  Using corollary~\ref{nondet-fs-relation}, $\N(\function{EQ}{n}) \geqslant n$.

  \item $\N(\neg\function{EQ}{n})$: \\
  Since $\D(\function{EQ}{n}) = n$, we have $\N(\function{EQ}{n}) \geqslant \log{(n-1)}$.
\end{itemize}

\subsubsection*{The Greater-Than Function (\function{GT}{n})}

It is easy to observe that $M_{\function{GT}{n}}$ is an upper-half (or lower-half) triangular matrix.

\begin{itemize}
  \item $\N(\function{GT}{n})$: \\
  A 1-\complexity{FoolingSet} for $M_{\function{GT}{n}}$ is simply the diagonal, which has $2^n$ elements. \\
  Using corollary~\ref{nondet-fs-relation}, $\N(\function{GT}{n}) \geqslant n$.

  \item $\N(\neg\function{GT}{n})$: \\
  A 0-\complexity{FoolingSet} for $M_{\function{GT}{n}}$ is the 0-diagonal next to main diagonal, with $2^n-1$ elements. \\
  Using corollary~\ref{nondet-fs-relation}, $\N(\neg\function{GT}{n}) \geqslant n$.
\end{itemize}

\subsubsection*{The Inner-Product Function (\function{IP}{n})}

Recall that \function{IP}{n} had no large \complexity{FoolingSet}:
$$
  \FS(\function{IP}{n}) \leqslant (n+1)^2
$$
Therefore, no monochromatic rectangle has a \textit{large} weight. We try to obtain a lower-bound on the weight of large monochromatic rectangles.

Consider the matrix $\displaystyle M_{\function{IP}{n}}$. Except the first row (which has all zeroes), the following $2^n-1$ rows are \textit{balanced}.

\begin{itemize}
  \item $\N(\neg\function{IP}{n})$: \\
    We define a uniform probability distribution $\mu$ on $\efunction{IP}{-1}{n}(0)$ as:
    {\large$$
    \mu(x,y) =
      \begin{cases}
        \frac{1}{2^n + (2^n - 1)2^{n-1} } &\quad \function{IP}{n}(x,y) = 0 \\
        0 &\quad \text{otherwise} \\
      \end{cases}
    $$}
    and claim that,

    \begin{claim}Over $\mathbb{F}_2$,
        $\displaystyle \RS{\mu}(\neg\function{IP}{n}) < \frac{1}{2^{n-1}}$
    \end{claim}
    \begin{proof}
        Over $\mathbb{F}_2$,
        $$
            \neg\function{IP}{n}(x,y) = 1 + \langle x,y \rangle =
              \begin{cases}
                1 &\quad \text{if } \langle x,y \rangle = 0 \\
                0 &\quad \text{otherwise}
              \end{cases}
        $$
        Let $R$ be a $0$-monochromatic rectangle $A \times B$. Then,
        \begin{align*}
          & \forall x \in A, y \in B : \langle x,y \rangle = 0 \\
          \Rightarrow\ & \forall x \in \vspan(A), y \in \vspan(B) : \langle x,y \rangle = 0 \\
          \Rightarrow\ & \vspan(A) \text{ and } \vspan(B) \text{ are \textit{orthogonal} in } \mathbb{F}_2 \\
          \Rightarrow\ & \vdim(\vspan(A)) + \vdim(\vspan(B)) \leqslant n \\
          ~\\
          |A \times B| \leqslant\ & |\vspan(A) \times \vspan(B)| \\
          \leqslant\ & 2^{\vdim(\vspan(A)) + \vdim(\vspan(B))} \\
          \leqslant\ & 2^n \\
          ~\\
          \mu(R) =\ & \frac{|\vspan(A) \times \vspan(B)|}{2^n + (2^n-1)2^{n-1}} \\
          <\ & \frac{1}{2^{n-1}}
        \end{align*}
    \end{proof}

    Since $\RS{}(f) \leqslant \RS{\mu}(f)$, we have $\N(\neg\function{IP}{n}) \geqslant n$.
  \item $\N(\function{IP}{n})$: \\
  Observe that,
  $$
  \neg\function{IP}{n-1}(\{x_1, \ldots , x_{n-1}, y_1, \ldots, y_{n-1}\}) = \function{IP}{n}(\{x_1, \ldots , x_{n-1}, 1, y_1, \ldots, y_{n-1}, 1\})
  $$
  Therefore, $\N(\neg\function{IP}{n-1}) \leqslant \N(\function{IP}{n})$. \\
  Using the previous result, $\N(\function{IP}{n}) \geqslant n-1$.
\end{itemize}

\noindent
Note that we have an \textit{exponential gap} between the bounds from \complexity{FoolingSet} ($\FS(f) \leqslant (n+1)^2$) and \complexity{RectangleSize} ($\RS{}(f) \leqslant 2^{1-n}$) for $f = \function{IP}{n}$.

\subsubsection*{The Disjoint Function (\function{DISJ}{n})}

\begin{itemize}
  \item $\N(\function{DISJ}{n})$: \\
  Recall that the set $\{\langle A, \overline{A} \rangle : A \subseteq \range{}{n}\}$ is a 1-\complexity{FoolingSet} on $M_{\function{DISJ}{n}}$. \\
  Using corollary~\ref{nondet-fs-relation}, $\N(\function{DISJ}{n}) \geqslant n$.

  \item $\N(\neg\function{DISJ}{n})$: \\
  Since $\D(\function{EQ}{n}) = n+1$, we have $\N(\function{EQ}{n}) \geqslant \log{n}$.
\end{itemize}

\end{document}


\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{geometry}
 \geometry{
 bottom=20mm,
 right=20mm,
 left=20mm,
 top=20mm,
 }

\newcommand{\pc}{\mbox{$\rm pc$}}
\newcommand{\kms}{\mbox{$\rm km\,s^{-1}$}}
\newcommand{\Msun}{\mbox{$\rm M_\odot$}}

\title{The Essentials of Molecular Clouds}
\author{Jiayi Sun}
\date{July 10, 2018}

\begin{document}

\maketitle

In the 1980s, the pioneering works done by Larson (1981) and Solomon et al. (1987)  offered a lot of insights on the structure and dynamical state of molecular clouds. The key results from these studies were the so-called ``Larson's relations''. Two of them are shown below:

\begin{figure}[htb]
\begin{center}
\includegraphics[width=0.60\textwidth]{1.png}
\includegraphics[width=0.61\textwidth]{2.png}
\caption{The size{--}line-width relation (top) and the mass{--}line-width relation (bottom), as reported by Larson (1981). {\bf We will adopt a slope $\approx 0.5$ for the former relation} (as suggested by Solomon et al. 1987), {\bf and slope $\approx 0.25$ for the latter} (though it looks more like 0.2 given these data). Note that $L$ stands for the ``maximum linear extent'' of each region identified as a cloud.}
\end{center}
\end{figure}

\begin{enumerate}

\item What are the average surface densities of the clouds? Do they depend on cloud size?

% \item[$\Rightarrow$] One can rewrite Larson's relations as
% \begin{align}
%     \left( \frac{\sigma}{\;\kms} \right) \approx
%     \left( \frac{L}{\pc} \right)^{0.5} \approx \left( \frac{M}{10^2\;\Msun} \right)^{0.25},
% \end{align}
% and thus the average surface density can be expressed as
% \begin{align}
%     \Sigma
%     \approx \frac{M}{\pi (L/2)^2}
%     \approx 10^2\;\Msun\,\pc^{-2},
% \end{align}
% which is not a function of cloud size.

% This is one of the deductions from Larson's relations -- all molecular clouds have roughly the same surface density. However, later works have shown that this likely came from observational bias, as early observations were limited by sensitivity. Cloud surface density clearly varies across a galaxy and among galaxies (e.g., see Figure 13 in Leroy et al. 2015).

\item What are the virial parameters of the clouds? Do they depend on cloud size? (Hint: for spherically symmetric objects with a given radial density profile, the virial parameter $\alpha_{\rm vir} \equiv 2K/U_g = 5\,\sigma^2 R/(f\,G M)$. Here $f$ is a dimensionless geometrical factor determined by the density profile, and it is typically of order unity.)

% \item[$\Rightarrow$] Substituting the $R$ and $M$ with Equation (1), we have
% \begin{align}
%     \alpha_{\rm vir}
%     \approx \frac{5\,\sigma^2 L}{2\,G M}
%     \approx \frac{5 \left(\frac{\sigma}{\kms}\right)^2 \left(\frac{\sigma}{\kms}\right)^2}{2 \times (4.3 \times 10^{-3}) \times 10^2 \left(\frac{\sigma}{\kms}\right)^4}
%     \approx 5.8,
% \end{align}
% which, again, is not a function of cloud size.

% This is yet another deduction from Larson's relations -- the ratio between molecular cloud kinetic energy and gravitational potential energy is roughly the same. Note that virialized objects have $\alpha_{\rm vir} \approx 1$, while marginally bound objects have $\alpha_{\rm vir} \approx 2$. More recent observations suggest that $\alpha_{\rm}$ is closer to 2, and the systematic uncertainty is still large.

\item Consider CO molecules at 10 K: how does the thermal sound speed compare to the observed line width? And does this depend on the linear scale that we consider?

% \item[$\Rightarrow$] The thermal sound speed can be expressed as
% \begin{align}
%     \sigma_{\rm S}
%     \approx \sqrt{\frac{k_{\rm B}T}{m_{\rm CO}}}
%     \approx \sqrt{\frac{1.38 \times 10^{-23} \times 10}{28 \times 1.66 \times 10^{-27}}}\rm\;m\,s^{-1}
%     \approx 50\rm\;m\,s^{-1}.
% \end{align}
% This is much smaller than the $\sim \kms$ CO line width that we observe on pc scale.

% This comparison, together with the fact that CO line width scales with linear size, suggests that turbulence broadening is much more important than thermal broadening on pc scale. However, if the size{--}line-width relation still holds on smaller scale, thermal motion becomes dominant as one goes down to sub-pc scale.

\item Turbulence is not long-lived. The kinetic energy associated with turbulence flows from large scales to small scales (also known as ``turbulence cascade''), and eventually it will dissipate and be converted to thermal energy. It is suggested that, if there is no source that generates turbulence, all the energy in turbulence will dissipate in one turbulence crossing time $\tau_{\rm cross} \sim L/\sigma$. Calculate the amount of dissipated energy per unit time per unit mass, and keep its scaling relation with cloud size $L$.

% \item[$\Rightarrow$] The total kinetic energy of a molecular cloud is $K \approx 3/2M\sigma^2$.
% % \begin{align}
% %     K \approx \frac{3}{2}M\sigma^2
% %     \approx 1.5\;(\kms)^2 \left(\frac{L}{\pc}\right) M.
% % \end{align}
% Since most of the kinetic energy is associated with turbulence, the energy dissipation rate per unt mass is thus
% \begin{align}
%     \frac{K}{M\tau_{\rm cross}}
%     \approx \frac{3\,\sigma^3}{2L}
%     \approx 1.5\;(\kms)^3\;\pc^{-1} \left(\frac{L}{\pc}\right)^{0.5}
%     \approx 5 \times 10^{-4}\rm\;ergs\,g^{-1}\,s^{-1} \left(\frac{L}{\pc}\right)^{0.5}.
% \end{align}

\item It seems that turbulence cascade is an efficient heating source. Will CO line cooling be efficient enough to balance it? (The CO cooling rate, according to Barbara's ISM textbook, is on average $\sim 10^{-27}\rm\;ergs\;s^{-1}$ per hydrogen nucleus at 10 K.)

% \item[$\Rightarrow$] The CO cooling rate per unit mass is
% \begin{align}
%     10^{-27}\rm\;ergs\;s^{-1} / (1.7 \times 10^{-24}\rm\;g) \approx 6 \times 10^{-4}\rm\;ergs\,g^{-1}\,s^{-1}.
% \end{align}
% The agreement is actually better than what we would expect. Generally speaking, CO is the dominant coolant in the density range $n \approx 10^3-10^5\rm\;cm^{-3}$, whereas shock heating is the dominant heating source for $n \geq 10^4\rm\;cm^{-3}$ (see Glover \& Clark 2012). Therefore, for most regions inside a molecular cloud (excluding the dense clumps), we do expect a good match between shock heating rate and CO line cooling rate.

\end{enumerate}

% \section*{References}

% \begin{itemize}
%     \item Glover S. C. O., Clark P. C., 2012, MNRAS, 412(1), 9
%     \item Larson R., 1981, MNRAS, 194(4), 809
%     \item Leroy A. K., Bolatto A. D., Ostriker E. C., et al., 2015, ApJ, 81, 25
%     \item Solomon P. M., Rivolo A. R., Barrett J., \& Yahil A., 1987, ApJ, 319, 730
% \end{itemize}

\end{document}


\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[gen]{eurosym}

\DeclareUnicodeCharacter{20AC}{\euro{}}

%\usepackage{palatino, eulervm} %fonts
\usepackage[left=1.5cm, right=2cm, top=3cm, bottom=2cm]{geometry}
\setlength{\headsep}{5mm}
\setlength{\headheight}{14pt}
\parindent=0mm
\parskip=3mm
\usepackage[ruled, vlined, linesnumbered]{algorithm2e}

\usepackage{graphicx}
\usepackage{tikz} % Let us start the fun
\usetikzlibrary{positioning, chains, calc, arrows, decorations.pathreplacing, fit, calc, patterns}

\newcommand{\bigO}[1]{\mathcal O\left( #1 \right)}
\newcommand{\bigOmega}[1]{\Omega\left( #1 \right)}
\newcommand{\bigTheta}[1]{\Theta\left( #1 \right)}
\newcommand{\smallTheta}[1]{\theta\left( #1 \right)}
\newcommand{\chicken}[2][]{\log_{#1}\left( #2 \right)} % because Hungarian chicken says "log"
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\K}{\mathbb{K}}
\newcommand{\eps}{\varepsilon}

\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\zo}{\set{0, 1}}
\newcommand{\abs}[1]{\left|#1\right|}

\newcommand{\prob}[1]{\mathbb{P}\left[ #1 \right]}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\EE}{\mathbb{E}}
\newcommand{\cA}{\mathcal{A}}
\newcommand{\cK}{\mathcal{K}}
\newcommand{\cC}{\mathcal{C}}
\newcommand{\cP}{\mathcal{P}}
\newcommand{\U}{\mathcal{U}}

\renewcommand{\bar}{\overline}

\newcommand{\Adv}{\mathrm{Adv}}

\usepackage[colorlinks=true,pdfusetitle]{hyperref}
\hypersetup{urlcolor=black,linkcolor=black}
\usepackage{amsmath,amsthm,amssymb,array,enumerate,cancel,nth,stmaryrd,fancyhdr,mathtools}
\usepackage{enumitem}
\setlist{nolistsep}
\newtheorem{lemma}{Lemma}
\newtheorem{thm}{Theorem}
\newtheorem{claim}{Claim}
\theoremstyle{example}
\newtheorem{ex}{Example}
\theoremstyle{remark}
\newtheorem{rk}{Remark}
\newtheorem{anecdote}{Anecdote}
\theoremstyle{definition}
\newtheorem{hw}{Homework}
\newtheorem{definition}{Definition}

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\title{Image processing\\Shape Indexing Project}

\author{Tom \textsc{Cornebize}\\Romain \textsc{Labolle}}

\date{May 4, 2015}

\begin{document}

\maketitle

\pagestyle{fancy}
\fancyhead[L]{Tom \textsc{Cornebize}}
\fancyhead[C]{Shape Indexing Project}
\fancyhead[R]{Romain \textsc{Labolle}}

\section{Introduction}

The objective of this project is to design a binary shape indexing/retrieval system. Given a binary shape and a database of binary shapes categorized in different classes, the goal is to find the class that best match the shape. To do so, we implemented several classical image processing algorithms in C++, using the DGtal library\footnote{\url{http://dgtal.org/}}. Our work is detailed in the present report.

\section{Overview of the algorithm}

The basic idea of the indexing algorithm is to extract different values from a given binary shape in order to build what we call a signature vector. Two similar shapes must have similar signature vectors. Thus, the values used to build the signature vector must be invariant by translation, rotation and scaling. Moreover, the given image may contain some extra noise that we must remove before computing the signature vector. We also want two non-similar images to have non-similar signature vectors, to be able to recognize the class of an image.

\section{Signature vector}

We have implemented three algorithms that extract a total of ten values from the image to generate a 10-dimensional signature vector that represents the image. All theses values are invariant from rotation, translation and scaling.

\subsection{Roughness}

The first value of the signature vector is the quotient of the area of the shape by the area of the circle of same perimeter. This value describes the roughness of the shape since to reduce the area of a shape of given perimeter, we have to add breaks in the outline of the shape.

This value is invariant by rotation, translation and scaling.

\subsection{Convexity}

The second value of the signature vector is the quotient of the area of the shape by the area of the convex hull of the shape. This describes how much convex the object is.

This value is invariant by rotation, translation and scaling.

One can think that these values are redundant. Indeed, $\mathrm{roughness}(circle) = \mathrm{convexity}(circle) = 1$.

But consider a rectangle of size $x\ell \times \ell$ where $x \in \R^+$.

The area of the rectangle is $x\ell^2$, its perimeter is $2\ell(x+1)$.

The area of a circle of perimeter $p$ is $\frac{p^2}{4\pi}$.

Thus, the area of the circle of same perimeter than the rectangle is $\frac{\ell^2(x+1)^2}{\pi}$.

In all, the roughness of the rectangle is:
\[\frac{x\ell^2}{\frac{\ell^2(x+1)^2}{\pi}} = \frac{\pi x}{(x+1)^2}\]

This value tends to $0$ when $x$ tends to $+\infty$, whereas the value of the convexity is always $1$ for the rectangle (the convex hull is the rectangle itself).

Therefore, it makes sense to consider both of these values.

\subsection{Invariant moments}

The remaining 8 values are invariant moments taken from Wikipedia's ``Image moment'' page \footnote{\url{https://en.wikipedia.org/wiki/Image_moment}}.

We define the following notions:

\begin{definition}[Intensity]
$ \forall x,y, ~ I(x,y) = \begin{cases}
1 \text{ if (x,y) is part of the shape (white pixels)}\\
0 \text{ otherwise}
\end{cases}$
\end{definition}
\begin{definition}[Raw moments]
$\forall i,j \geq 0, ~ M_{ij} = \sum\limits_x \sum\limits_y x^i y^j I(x,y)$
\end{definition}
\begin{definition}[Central moments]
$\forall p,q \geq 0, ~ \mu_{pq} = \sum\limits_{x} \sum\limits_{y} (x - \bar{x})^p(y - \bar{y})^q I(x,y)$ where $\bar{x} = \frac{M_{10}}{M_{00}}$ and $\bar{y} = \frac{M_{01}}{M_{00}}$

These moments are invariant from translation.
\end{definition}
\begin{definition}[Scale invariant moments]
$\forall i,j \geq 0, ~ \eta_{ij} = \frac{\mu_{ij}}{\mu_{00}^{\left(1 + \frac{i+j}{2}\right)}}$

These moments are invariant from translation and scaling.
\end{definition}
\begin{definition}[Rotation invariant moments]
\begin{align*}
I_1 =& \eta_{20} + \eta_{02} \\
I_2 =& (\eta_{20} - \eta_{02})^2 + 4\eta_{11}^2 \\
I_3 =& (\eta_{30} - 3\eta_{12})^2 + (3\eta_{21} - \eta_{03})^2 \\
I_4 =& (\eta_{30} + \eta_{12})^2 + (\eta_{21} + \eta_{03})^2 \\
I_5 =& (\eta_{30} - 3\eta_{12}) (\eta_{30} + \eta_{12})[ (\eta_{30} + \eta_{12})^2 - 3 (\eta_{21} + \eta_{03})^2] \\
&+ (3 \eta_{21} - \eta_{03}) (\eta_{21} + \eta_{03})[ 3(\eta_{30} + \eta_{12})^2 -  (\eta_{21} + \eta_{03})^2] \\
I_6 =&  (\eta_{20} - \eta_{02})[(\eta_{30} + \eta_{12})^2 - (\eta_{21} + \eta_{03})^2] + 4\eta_{11}(\eta_{30} + \eta_{12})(\eta_{21} + \eta_{03}) \\
I_7 =& (3 \eta_{21} - \eta_{03})(\eta_{30} + \eta_{12})[(\eta_{30} + \eta_{12})^2 - 3(\eta_{21} + \eta_{03})^2] \\
&- (\eta_{30} - 3\eta_{12})(\eta_{21} + \eta_{03})[3(\eta_{30} + \eta_{12})^2 - (\eta_{21} + \eta_{03})^2] \\
I_8 =& \eta_{11}[ ( \eta_{30} + \eta_{12})^2 - (\eta_{03} + \eta_{21})^2  ] - (\eta_{20}-\eta_{02}) (\eta_{30}+\eta_{12}) (\eta_{03}+\eta_{21})
\end{align*}

These moments are invariant from rotation, translation and scaling. We use these 8 moments for the signature vector
\end{definition}

\section{Image processing}

\subsection{Border extraction}

In order to calculate the perimeter of a given shape, we need to extract its border. To do so, we use the border extraction algorithm seen during the 6\textsuperscript{th} practical session.

%TODO: describe the actual algorithm ?

Since the shape may contain several connected components, we take the one with the largest border (in number of points).

\subsection{Convex hull extraction}

The convex hull of the shape is calculated from the extracted border using the Graham’s Scan algorithm seen in course.

%TODO: describe ?

Since it uses the previously extracted border, it also only considers the biggest connected component.

\subsection{Noise deletion}

The input file may contain some noise that may prevent our algorithm to run efficiently. In particular, the evaluation tool chain adds some Kanungo noise to the shape which is a local pixel swapping algorithm. To remove this noise, we use a binomial filter seen in course :

\[ \mathcal{F} = \frac{1}{16}\bordermatrix{ &&& \cr
& 1 & 2 & 1 \cr
& 2 & 4 & 2 \cr
& 1 & 2 & 1}\]

To obtain a binary image, we just round to the closest value between black and white.

This filter is used to smooth gray-scale images and when applied to binary images, it is an efficient way to remove isolated pixels, smooth the borders without affecting too much the original image.

See figure \ref{fig:noise} for example result.

\begin{figure}[!ht]

\centering
\includegraphics[width=.3\textwidth]{images/fly-5_orig.eps}\hfill
\includegraphics[width=.3\textwidth]{images/fly-5_noise.eps}\hfill
\includegraphics[width=.3\textwidth]{images/fly-5_filter.eps}

\caption{Noise deletion algorithm: original image, noisy image and filtered image}
\label{fig:noise}

\end{figure}

\section{Classification}

An image is characterized by a vector $v \in \R^d$.

A class is a set of image vectors.

We discuss here how to retrieve the class of an image. We suppose that we have computed the signature vector of the given image and that we know the signature vectors of all the images of all the classes.

\subsection{Distance computation}

The distance between two vectors $v_1 = \begin{pmatrix}v_{11}\\\vdots\\ v_{1d}\end{pmatrix}$ and $v_2 = \begin{pmatrix}v_{21}\\\vdots\\ v_{2d}\end{pmatrix}$ is defined as follows:

\[\mathrm{dist}(v_1, v_2) = \sqrt{\sum_{i=1}^d \left(\mathrm{normalize}(v_{1i}, i)-\mathrm{normalize}(v_{2i}, i)\right)^2}\]

Where
\[\mathrm{normalize}(x, i) = \frac{x}{\max_{\text{all vectors u}}u_i}\]

The aim of the normalization is to give the same weight to all the descriptors. Indeed, some descriptors are usually smaller than others. For instance, the maximal convexity descriptor that we found was about $2.17$ whereas the maximal $I_7$ descriptor was about $0.0036$.

\subsection{Choice of the class}

For each class, we compute the distances between each image of the class and the given image. We obtain a sequence of real numbers per class.

We can now compute some metrics about these sequences: minimum distance, maximum distance, mean distance, median distance.

The maximum and the mean distances do not seem to be good choices, since they are easily broken by some artifacts.

The median and the minimum distances seem to be better. We will discuss more about this choice in section \ref{exp}.

Then, the lower is this metric, the higher is the probability that our image belongs to the considered class.

\section{Experimental results}
\label{exp}

Thanks to the script \emph{scriptClassification.sh}, we tested the efficiency of our classifier.

We picked randomly $5$ images of each class and then computed the rank given by our classifier for each image (meaning: if the rank is near $1$, then the classification was successful). An image is considered correctly classified if the rank is lower or equal to $10$.

\paragraph{Choice of the class: median distance}

Here, we take the median distance between the considered image and all the images of the considered class.

We had a success rate of 72\%.

\paragraph{Choice of the class: minimum distance}

Here, we take the minimum distance between the considered image and all the images of the considered class.

We had a success rate of 97\%.

\paragraph{Conclusion on the choice}

It is clear from the previous results that the minimum distance is a better indication to retrieve the class of an image. An explanation can be that to generate new images to classify, we took an image already classified and modified it (rotation, scaling and noise). The distance between the new image and the old image should be small, since we remove the noise and compute descriptors invariant by scaling and rotation.

\section{Conclusion}

We created a program that classify shapes with a high success rate. It is based on ten simple values computed for each image.

We could improve our classification by adding other values to the signature vectors. For instance, the angles of the lines of the segmented image are often meaningful.

Decreasing the execution time of our programs would also be a great achievement: it took more than an hour to compute all the signature vectors of the database, which consists of only 1050 images.

\end{document}


\documentclass[12pt,a4paper,onecolumn]{article}
\usepackage[top=0.2in,left=0.6in,right=0.6in]{geometry}
\usepackage{breqn}

\usepackage{url}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\graphicspath{{../plots/}}

\begin{document}

\title{Evolution of Complexity, Assignment 2}
\author{Dionisio Perez-Mavrogenis}
\date{\today}
\maketitle

\section{Original Implementation}
\subsection{Introduction}
For this assignment I chose to re-implement and extend \emph{A cooperative Coevolutionary Approach to Function Optimization}\cite{PDJ} by Potter and De Jong(PDJ).

This paper is divided into two main parts. The first part describes my attempt at investigating and implementing the paper written by De Jong and Potter and presents the results. Furthermore I will also be discussing difficulties that arose during development and facts that were not clear about the original paper.

In the second part of the paper I will present my hypothesis as an extension. A discussion of the implementation of the extension and the results will conclude this paper.

\subsection{Overview}
\label{overview}
In their original paper PDJ presented their Cooperative Coevolutionary Genetic Algorithm (CCGA), an algorithm that they showed would outperform a traditional genetic algorithm (GA). They tested their hypothesis on the well studied domain of function optimisation, using the following function to compare the performances of GA and CCGA:
$$ \mathrm{Rastrigin} : 3.0n + \sum_{i=1}^{n} x_i^2 - 3.0\cos(2\pi x_i) $$
$$ \mathrm{Schwefel} : 418.9829n-\sum^{n}_{i=1}x_i\sin \left(\sqrt{|x|}\right) $$
$$ \mathrm{Griewangk} : 1+\sum^{n}_{i=1} \frac{x_i^2}{4000}-\prod^{n}_{i=1}\cos \left(\frac{x_i}{\sqrt{i}}\right) $$
$$\mathrm{Ackley} : 20 + \mathrm{e} - 20 \mathrm{exp}\left( -0.2\sqrt{\frac{1}{n}\sum^{n}_{i=1}x_i^2} \right) -\mathrm{exp}\left( \frac{1}{n}\sum^{n}_{i=1}\cos(2 \pi x_i) \right) $$

Table \ref{func_spec} lists the properties of each function. All the functions have a single global minimum $\mathbf{x^*} = \langle x_1, x_2,\ldots , x_n \rangle$  and $ f\left( \mathbf{x^*}\right) = \langle 0,0,\ldots,0 \rangle $.

In the GA approach, PDJ had a population of one-hundred $n$-vector elements (where $n$ is determined by each function) and each population was competing with the others to perform better. In the CCGA approach each dimension was represented by a subpopulation of size one-hundred and each element of the population was evaluated by combining it with the \emph{best} of all the other dimensions, effectively making the subpopulations cooperate with each other to produce the best solution.

Table \ref{env_params} outlines the rest of the parameters used in their simulations.

\begin{table}
\begin{center}
\begin{tabular}{ c | c | c }
Function & $n$ & Domain range \\
\hline
\hline
Rastrigin & 20 & $-5.12 \leq x_i \leq 5.12 $\\
Schwefel & 10 & $-500 \leq x_i \leq 500 $\\
Griewangk & 10 & $-600 \leq x_i \leq 600 $\\
Ackley & 30 & $-30 \leq x_i \leq 30 $\\
\end{tabular}
\caption{Evaluation function properties}
\label{func_spec}
\end{center}
\end{table}

\begin{table}
\begin{center}
\begin{tabular}{c  p{4.5cm}}
\hline
\emph{representation} & binary (16 bits per variable)\\ \hline
\emph{selection} & fitness proportionate \\ \hline
\emph{fitness scaling} & scaling window(width 5)\\ \hline
\emph{elitist strategy} & copy of best individual\\ \hline
\emph{genetic operators} & two-point crossover	 and brit-flip mutation \\ \hline
\emph{mutation probability} & 1/chromlength \\ \hline
\emph{crossover probability} & 0.6 \\ \hline
\emph{population size} & 100\\\hline
\end{tabular}
\caption{Environment variables used for the simulations of PDJ.}
\label{env_params}
\end{center}
\end{table}

\subsection{Implementation}
I re-implemented the paper by PDJ in the C programming language for a number of reasons. Firstly, the representation of each individual as 16-bit variables is a native datatype to C (type \texttt{unsigned short}). Secondly, the mutation operations of two-point crossover and bit-flip mutation were achieved by using bit masks and bitwise operations, again native to the C language. A third, equally important, reason was performance. The original paper is computationally intensive, mainly due to a lot of necessary looping over the population, making execution time a concern and C's performance made it a more attractive choice.

Another argument in favour of C is the fact that by representing the population as a collection of \texttt{unsigned short}, one consumes an average of 4,000 bytes for the population, just below 4 kilobytes of memory per simulation. In contrast, if one were to represent the population as a character array (in Java for example), they would have to use at least eight times as much memory (as each individual would need to be represented with 16 bytes - the size of a character) and would not have the additional benefit of being able to use the high performance bitwise operations that C provides.

Even though the members of the population can be kept as a collection of \texttt{unsigned short} type, the fitness functions require a real valued vector, and therefore a mapping from the population members to the function domain is needed. Since an individual is represented as a 16-bit binary variable there are $2^{16}$ possible candidates in the domain, and I chose to linearly scale the candidates over the function domain, making for an intuitive and simple to implement mapping function. As an example, in the Rastrigin function the population member $\overrightarrow{\mathbf{0}}$ would be value -5.12, while $\overrightarrow{\mathbf{1}}$ would map to 5.12.

\subsubsection{Challenges}
\label{challenges}
In this section I will describe the challenges I came across while re-implementing the original paper and things that were unclear about it.

\paragraph{Genetic Operations} It is reasonable to think that the candidate binary representation and its corresponding mapping are equivalent and therefore manipulation of either one should be fine, but this is not the case due to the nature of the machine representation of the floating point values involved (IEEE 754-1985 format). In particular, while applying bitwise operations to integer types makes sense, applying the same operations to floating point values does not.

Budin\cite{floats} outlines some of the problems with bitwise operations on floating point numbers and proposes a solution which involves treating the floating point as a binary string(ignoring the sign bit) and performing the genetic operations on that, while another solution includes adding some random small number to the floating point representation(to simulate mutation). These approaches might generate invalid values however and another solution was chosen. The genetic operations are applied to the integers representing the population, and this cascades down perfectly to their floating point counterparts. Therefore the loss of precision and generating invalid values is avoided.
\paragraph{Precision} Because of the way floating point numbers are represented there exists a potential for precision errors, as explained by Goldberg\cite{float_error}. The workaround to this is repeating the process and calculating an average value, which is implicitly done by PDJ when they calculate an average of the fitness values.
\paragraph{Comparison fairness} In order to compare GA's and CCGA's performance a scheme needed to be devised that would make the comparison fair, as the CCGA operates on $n$ dimensions and comparing it with a one-dimensional GA would not be meaningful. Therefore, the GA has a population of one-hundred $n$-dimensional vectors which it evolves, while the CCGA has $n$ hundred-dimensional vectors which it evolves, picking the best of each in every generation.
\paragraph{Malformed Schwefel function} The Schwefel function outlined in the paper is malformed, as $f(\mathbf{x}^*)$ is not $0$. The correct form of the function is the one presented in \ref{overview}(\cite{schwe_correct} and \cite{website:matlab_schwe}). The difference lies in the subtraction of the two terms of the equations, as opposed to addition. This might be a typographical error on the original paper.
\paragraph{Fitness scaling} When doing function maximisation a common fitness scaling method is to replace each member's fitness($g(\mathbf{x}_i)$) with $g(\mathbf{x}_i) - population\_worst\_fitness$, thus making the populations' fitness ratios bigger.

In our case however we are doing minimisation and this technique wouldn't work. My solution to that was to replace each member's fitness by $population\_worst\_fitness - g(\mathbf{x}_i)$ for doing fitness proportionate selection.

\emph{\textbf{Note}} : These operations are done on temporary fitnesses, as performing these alterations on the actual fitness values of a candidate would destroy the data gathered.
\paragraph{Mutation rates}
\label{res_orig}In the original paper the mutation rate is described as 1/chromlength, where chromlength can easily be assumed to be 16. That is wrong, as we are evaluating $16n$ bit variables at a time. Therefore the mutation rate is $1/(16n)$.

\subsubsection{Results and Discussion}
\begin{figure}[h]
	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{rastrigin.png}
		\caption{The Rastrigin function}
	\end{subfigure}
	~
	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{Scwefel.png}
		\caption{The Schwefel function}
	\end{subfigure}	\\

	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{griewangk.png}
		\caption{The Griewangk function}
	\end{subfigure}
	~
	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{ackley.png}
		\caption{The Ackley function}
	\end{subfigure}
\caption{Plots of the results generated when reimplementing PDJ's paper.}
\label{result_plots}
\end{figure}

The plots of Figure \ref{result_plots} summarize the results of my implementation with the parameters as specified by PDJ and the corrections reviewed in \ref{challenges}.

One can immediately tell by looking at the numbers in the plots that they do not match those in Figure 3 of PDJ\cite{PDJ}. While this might raise concern at first, one should also note that the general behavior and trends of the simulations do indeed follow the ones presented by PDJ. In particular, in all of the plots the CCGA outperforms the GA and, as in PDJ, the results of the Griewangk CCGA does not exhibit the notable performance difference that the rest of the functions do.\\

The value mismatch that the plots experience can be attributed to a number of different reasons. Firstly, the mismatch in the starting fitnesses can be attributed to the random generation of the individuals of a population and it is reasonably expected that the starting population of a simulation might not match the previous ones and this explains the starting fitness difference between mine and PDJ's simulations.

The other evident performance issue is the maximum achieved fitness of this implementation. While PDJ achieve a performance of (almost) 0, my CCGA and GA implementations seem to reach a plateau after 20,000 function evaluations with the GA improving in performance slowly after that point. This is most likely explained in the subtle implementation differences between mine and PDJ's implementations, as this implementation follows general guidelines in order to achieve the same result and has no knowledge of the internals of the original implementation.\\

Upon further investigation I found that a smaller mutation rate and population size does help improve the maximum achieved fitness. This is reasonably expected however because by having a smaller population size one works more intensely on the same candidates and has therefore got more room for improvement(while running the risk of diversity loss, however). Decreasing the number of dimensions helps as well, but this is not a realistic tweak to the model as one does not always have the option to change the size of the dimensions in a problem.

\section{Extension}
A useful extension that would be worth exploring is investigating the effect exerted on performance by imposing certain constraints in the crossover operation.
\subsection{Hypothesis}
In the current implementation crossover is being carried out with both parents being selected from the same population and the resulting child being placed in the same population, something that might negatively affect future populations. This might create a situation in which inbreeding occurs and  cause inbreeding depression to future populations, a situation in which population's fitness does not improve or deteriorates (PDJ guard against deteriorating fitness via their elitist strategy).

Inbreeding depression might be a possible explanation for the performance plateau observed in the results of this implementation. A way to work around this would be to select the parents from different groups and, taking it a step further, placing the child in a different population.

\subsection{Implementation}
Constrained crossover with the aim of avoiding inbreeding will be implemented differently for the GA and CCGA.

For the GA, while iterating over candidate solution $i$ the second parent will be selected as a random member from candidate solution $i+1$ and the offspring will replace the parent at $i$. The same will happen for parent $i+1$ at the same iteration as for parent $i$.

For the CCGA a slightly different approach is taken. When in dimension $i$ of the population that parent is crossed-over with a random individual from dimension $i+1$ and the resulting offspring is placed in dimension $i+2$. That way it is assured that offsprings will never mate with their parents.

\subsection{Results}
Figure \ref{ext_plots} shows the results obtained by implementing the constrained crossover. In Figure \ref{ext_plots} the results of CCGA and GA are also plotted for an easier overview and comparison of the two approaches.

\begin{figure}[h]
	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{rastrigin_ext.png}
		\caption{The Rastrigin function}
	\end{subfigure}
	~
	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{scwefel_ext.png}
		\caption{The Schwefel function}
	\end{subfigure}	\\

	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{griewangk_ext.png}
		\caption{The Griewangk function}
	\end{subfigure}
	~
	\begin{subfigure}[t]{0.5\textwidth}
		\includegraphics[scale=0.25]{ackley_ext.png}
		\caption{The Ackley function}
	\end{subfigure}
\caption{Plots of the results generated with constrained crossover.}
\label{ext_plots}
\end{figure}

The results indicate that while constrained crossover improves performance always for the GA, the extended CCGA does not always outperform CCGA1. Furthermore, in the Ackley function the extended GA outperforms the extended CCGA by a large margin. This might be explained by the fact that in GA-ext the children replace their parents while in CCGA-ext the children are placed in a completely different dimension.

While this solution somewhat improves performance it does not address the original issue. If one observes the CCGA plots of Figure \ref{ext_plots} they will notice that CCGA-ext still reaches a performance plateau after 20,000 function evaluations, as did CCGA1 originally.

\subsection{Discussion}
The experimental results show that the way this form of constrained optimization is not adequate for both the GA and the CCGA1. Their performance mismatch might be attributed to the fact that CCGA1 is more sophisticated than the GA and placing random members in the population of each dimension might somehow disrupt the cooperative nature of the algorithm.

This form of constrained optimization is cheap to perform, both in the sense of difficulty of programming implementation as well as in the number of extra instructions that need to be performed, and might be adequate in a scenario where an easy performance improvement to a GA would be desired.

In order to improve the performance of CCGA1 it is clear that this extension will not always be applicable. Since a performance plateau is still observed, this extension fails to provide an adequate solution to maintaining diversity. If the problem is indeed loss of diversity(as opposed to some internal implementation difference) then \cite{FODAVA} discusses an approach called \emph{Generalized Crowding} that aims to maintain diversity in a population by building upon De Jong's (\cite{FODAVA}) idea of crowding where a collection of $\gamma$ individuals is selected and the offspring replaces the most similar one.

\bibliographystyle{unsrt}
\bibliography{report}
\end{document}


%%% generic article type (pdf)latex file
%%% use together with Makefile

\documentclass[letterpaper]{scrartcl}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{eufrak}
\usepackage{mathabx}
\usepackage{siunitx}
\usepackage{url}
\usepackage{framed}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[colorlinks]{hyperref}
\hypersetup{
     colorlinks   = true,
     urlcolor     = blue,
     linkcolor    = red,
     citecolor    = black
}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage{cprotect}
\usepackage{minted}

%\usepackage{wrapfig}
%\usepackage{subfig}
\usepackage[format=plain,labelsep=period,font=small,labelfont=bf]{caption}

%------------------------------------------------------------
% assignment
%
\newcommand{\anumber}{2}
%
%------------------------------------------------------------

% hyperref https://en.wikibooks.org/wiki/LaTeX/Hyperlinks#.5Chref
\urlstyle{same}

%% not working yet...
\newcounter{TotalPoints}
\newcounter{TotalBonus}

\newcommand{\BONUS}{\textsc{Bonus: }}
\newcommand{\bonus}[1]{\textbf{[bonus +#1*]}\stepcounter{TotalBonus}}
\newcommand{\points}[1]{\textbf{[#1 points]}\stepcounter{TotalPoints}}
\newenvironment{enuma}{\begin{enumerate}[label=(\alph*)]}{\end{enumerate}}
\newenvironment{enumi}{\begin{enumerate}[label=(\roman*)]}{\end{enumerate}}
\newenvironment{solution}{\par\noindent\P{} }{\ \qedsymbol}

\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\pd}[3][]{\left(\frac{\partial #2}{\partial #3}\right)_{#1}}

\DeclareSIUnit{\revolutions}{rev}

\newcommand{\anum}{0\anumber}

\title{{\Large Project \anumber: Soccer Physics for the WIN!}}

\author{{\sffamily\large Project \emph{Comp. Methods Physics} ASU
    PHY494 (2018)}%
  \thanks{Current version of this document: \today. See
    Appendix~\protect\ref{sec:history} for a list of changes since v1
    from March 26, 2018.}}

\date{{\sffamily\large March 26, 2018 -- April 9, 2018}}

\begin{document}
\maketitle

\paragraph{Abstract}

In \emph{soccer} (or \emph{football} for the world outside the US) a
goal is scored when the entire ball fully crosses the goal line
between the goal posts and under the goal cross bar. There are a
number of set-piece situations that can directly lead to goals. Here
we look at two such opportunities that start from a ball at rest: the
\textbf{direct free kick} and the \textbf{corner kick}. You will write
Python code to simulate a realistic flight trajectory of the ball
(including spin and air resistance) and solve the problem to choose
initial kick parameters that could lead to directly scoring a
goal. You will write a \emph{short report} to communicate, discuss and
summarize your reasoning and your results. The work is carried out in
teams of two or three students.

\begin{framed}
  \noindent
  Due Monday, April 9, 2018, 11:59pm.
  \begin{itemize}
  \item Students work in teams of two or three students.
  \item \textbf{Admissible Collaboration:} Students are allowed to
    talk to other students in the class about the project and exchange
    ideas and tips. However, sharing/copying reports or full code
    solutions is not allowed. \textbf{Help from other students must be
      acknowledged in an Acknowledgments section}.  Direct help from
    outside the class is not allowed (except instructor/TA), e.g., you
    cannot ask for solutions (online or in person) but you can use
    books and resources on the internet to solve
    problems. \textbf{Cite all sources}. Code from the class can be
    used without explicit citation or acknowledgement.
  \item Each team should commit their  report (see
    Section~\ref{sec:report}) in \textbf{PDF} format to the team's
    \textbf{GitHub repository}; alternatively, combining report and
    code in a Jupyter notebook is also possible as long as the
    notebook can be read like a report (i.e., not just bullet points
    or short comments). If possible, also generate a PDF from your
    notebook and commit it together with everything else.
  \item The report \emph{must} contain a section
    \textbf{Contributions} at the end where the contributions of all
    team members are summarized.
  \item Each team should commit and push \textbf{all code} (see
    Section \ref{sec:code}) that is required to reproduce the results
    in the report to their \textbf{GitHub repository}. Include a
    text file \textbf{\texttt{README.txt}} that describes the commands
    to run calculations. The code must run in the standard
    anaconda-based environment used for the class. If it is a Jupyter
    notebook then it should be possible to \emph{Kernel $\rightarrow$
      Restart \& Run All} and to produce all the required figures and
    output.
  \end{itemize}
  Grading will take the following into consideration:
  \begin{itemize}
  \item The code runs and produces correct output.
  \item The report clearly and succinctly describes the question,
    approach, and results and contains sufficient evidence that the
    requirements (see below) have been met.
  \item All team members contributed to the work: assessed by (1)
    Contributions section in the report, (2) commit history of the
    repository and comments in code, (3) short oral examination of
    team members (at instructor's discretion if deemed necessary).
  \item Code from outside sources (see Admissible Collaboration) and
    help is thoroughly attributed (Acknowledgements and References).
  \item \BONUS Additional work that you want to include in an appendix to
    the report or additional simulations for the main report will be
    treated as bonus material and can be awarded bonus points.
  \item \BONUS Elegant and fast code can be awarded bonus points.
  \end{itemize}
\end{framed}

\newpage
\tableofcontents{}

\section{Submission instructions}

\noindent
%  \url{}
\fbox{\parbox{\linewidth}{Submission is to your private \textbf{team
      GitHub repository}. Follow the link provided to you by the
    instructor in order for the repository to be set up: It will have
    the name
    \emph{ASU-CompMethodsPhysics-PHY494/project-2-2018-\emph{YourTeamName}}
    and will only be visible your team and the instructor/TA. Follow the
    instructions below to submit this project.}}
Read the following instructions carefully. Ask if anything is unclear.
\begin{enumerate}
\item \texttt{git clone} your project repository (change
  \emph{YourTeamName} to your team's name)
  \begin{minted}[autogobble]{bash}
    repo="project-2-2018-YourTeamName.git"
    git clone https://github.com/ASU-CompMethodsPhysics-PHY494/${repo}
  \end{minted}
  %$
  or, if you already have done so, \mintinline{bash}{git pull} from
  within your assignments directory.
\item  Create three sub-directories \texttt{Submission},
  \texttt{Grade}, and
  \texttt{Work}.
\item You can try out code in the \texttt{Work}
  directory but you don't have to use it if you don't want to. Your
  grade with comments will appear in
  \texttt{Grade}.
\item Create your solution in
  \texttt{Submission}. Use Git to \texttt{git
    add} files and \texttt{git commit} changes.

  You can create a PDF file or Jupyter notebook inside the
  \texttt{Submission} directory as well as Python
  code (if required). \textbf{Name your files \texttt{project\anum.pdf} or
    or \texttt{project\anum.ipynb}}, depending on how
  you format your work. Files with code (if requested) should be named
  exactly as required in the assignment.
\item When you are ready to submit your solution, do a final
  \texttt{git status} to check that you haven't forgotten anything,
  commit any uncommitted changes, and \texttt{git push} to your GitHub
  repository. Check on \emph{your} GitHub repository web
  page\footnote{\texttt{https://github.com/ASU-CompMethodsPhysics-PHY494/project-2-2018-\emph{YourTeamName}}}
  that your files were properly submitted.

  You can push more updates up until the deadline. Changes after the
  deadline will not be taken into account for grading.
\end{enumerate}
Work must be legible and intelligible or may otherwise be
returned ungraded with 0 points.

\section{Problem description}
\label{sec:problem}

This section describes the model that we will use to study the
\emph{free kick with wall} and the \emph{corner kick} in the ball game
of soccer.

\subsection{Soccer physics}
\label{sec:system}

\subsubsection{Equations of motion}
\label{sec:eom}

The ball obeys Newton's equations of motion with the following
forces to be included:
\begin{enumerate}
\item gravity $\vec{F}_{G} = -g\,\hat{\vec{e}}_{y}$
\item quadratic air resistance $\vec{F_{d}}$ (see
  Eq.~\ref{eq:Fdrag})
\item lift due to spin (the Magnus force $\vec{F}_{M}$, see
  Eq.~\ref{eq:Fmagnus})
\end{enumerate}
(The coordinate system was assumed to have the $x$-direction from the
ball towards the goal and the $y$-direction perpendicular to the
ground and pointing to the sky.)

\paragraph{Air resistance}

An approximately quadratic dependence of the drag force on the
velocity occurs at high Reynolds numbers, i.e., turbulent flow. An
approximate expression is
\begin{gather}
\label{eq:Fdrag}
  \vec{F}_d = -\frac{1}{2} C_{D}(v) \rho A v^{2} \frac{\vec{v}}{v}
\end{gather}
The quadratic drag coefficient $C_{D}$ depends on the translational
(center of mass) velocity of the object and on the spin parameter $S$
(see Eq.~\ref{eq:S} below). If it spins slowly, it exhibits a ``drag
crisis'' whereby its aerodynamic drag sharply \emph{decreases} at a
critical velocity $v_{c}$ when the air flow switches from the laminar
to the turbulent regime, as shown in Figure 1 in
\citet{Goff:2010aa}. At higher spin with velocities above $v_{c}$, the
drag coefficient mainly depends on $S$. The experimental data can be
parametrized by the dimensionless drag coefficient $C_{D}(v, S)$ as
\citep{Goff:2010aa}
\begin{align}
  \label{eq:CDv}
  C_{D}(v, S) &=
             \begin{cases}
               a + \frac{b}{1 + \exp[(v - v_{c})/v_{s}]}, &
               \text{if}\quad v < v_{c} \quad \text{or}\quad S < 0.05\\
               c S^{d}, & \text{if} \quad v \ge v_{c} \quad \text{and}\quad S \ge 0.05
             \end{cases}\\
  v_{c} &= \SI{12.19}{m.s^{-1}}, \qquad v_{s} = \SI{1.309}{m.s^{-1}}, \qquad
  a = 0.155, \qquad b = 0.346, \notag\\
  c &= 0.4127, \qquad d = 0.3056. \notag
\end{align}

% Wang uses: ref 5
% T. Asai, K. Seo, O. Kobayashi, and R. Sakashita. Fundamental
% aerodynamics of the soccer ball. Sports Eng., 10:101–110, (2007).

\paragraph{Spin and lift}

The airflow is changed around a spinning object. The Magnus force is
\begin{gather}
  \vec{F}_M = \alpha \boldsymbol{\omega} \times \vec{v}
  \label{eq:Fmagnus}
\end{gather}
where $\boldsymbol{\omega}$ is the ball's angular velocity in
\si{rad.s^{-1}} (e.g., up to about \SI{75.4}{rad.s^{-1}} or about
\SI{12}{\revolutions\per\second} (revolutions per second) for a
typical soccer ball).\footnote{To convert from $\omega$ in
  \si{rad.s^{-1}} to \si{\revolutions\per\second} divide by $2\pi$:
  \begin{gather*}
    \frac{\omega}{\si{rad.s^{-1}}} \times \frac{1}{2\pi} = %
    \frac{\omega}{\si{\revolutions\per\second}}.
  \end{gather*}
}
%
For a sphere the proportionality constant $\alpha$ can be written
\begin{gather}
  \label{eq:sphere}
  \vec{F}_M = \frac{1}{2} C_L \rho A \frac{v}{\omega}
  \boldsymbol{\omega} \times \vec{v}
\end{gather}
where $C_L$ is the lift coefficient, $\rho$ the air density, $A$ the
ball's cross section.

$C_L$ is mainly a function of the \emph{spin parameter}
\begin{gather}
  \label{eq:S}
  S = \frac{r\omega}{v}
\end{gather}
with the radius $r$ of the ball. $S = v_{\text{spin}}/v$ is the ratio of the speed of a
point on the ball's surface to the translational velocity of the ball. In general we write
\begin{gather}
  \label{eq:FM}
  \vec{F}_M = \frac{1}{2} C_L(S) \frac{\rho A r}{S}
  \boldsymbol{\omega} \times \vec{v}.
\end{gather}
The lift coefficient is modelled as \citep{Wang:2015aa} (based on data
in \citet{Goff:2009aa})\footnote{A more accurate expression for the
  lift coefficient $C_{L}$ based on the newer data in
  \citet{Goff:2010aa} would need to be fitted and was not available.}
\begin{gather}
  \label{eq:CL}
  C_{L}(S) = \frac{1}{2} S^{0.4}
\end{gather}
where $S$ is the spin parameter.

\subsubsection{Parameters and constants}

The following constants should be used in setting up the simulations.

\paragraph{Environment}

Physical constants due to the environment:
\begin{description}
\item[air density] $\rho = \SI{1.2}{kg.m^{-3}}$
\item[acceleration due to gravity] $g = \SI{9.81}{kg.m.s^{-2}}$
\end{description}

\paragraph{Ball}

Choose values for the 2006 World Cup ball (Adidas Teamgeist)
\citep{Goff:2010aa} and parameters that are typical for professional
soccer players \citep{Goff:2009aa}:
\begin{description}
\item[mass] $m = \SI{0.436}{kg}$
\item[diameter] $D = \SI{0.218}{m}$ (i.e., radius $r = \SI{0.109}{m}$)
\item[speed]
  $\SI{4.5}{m.s^{-1}} \le v_{0} \le \SI{31}{m.s^{-1}}$ (these are
  values that can be observed in a wide range of situations; for the
  specific problem here, a more narrow range might occur)
\item[spin] (angular velocity of the ball)
  $0 \le \omega_{0} \le \SI{12}{\revolutions\per\second} =
  \SI{75.4}{rad.s^{-1}}$ (these are values that can be observed in a
  wide range of situations; for the specific problem here, a more
  narrow range might occur; for David Beckham's famous free kick
  goals, $\omega_{0} \approx \SI{10}{\revolutions\per\second}$ were
  estimated.)
\end{description}

\paragraph{Geometry}

\begin{figure}
  \centering
  \includegraphics[width=\textwidth]{figs/Football_pitch_metric_and_imperial_edited.pdf}
  \caption{Geometry of a soccer pitch according to FIFA rules. The
    length of the \emph{touchline} and \emph{goal line} are variable
    (gray) but for this project, adopt the numbers shown in red. Other
    numbers are for your information but are not needed for this
    project (except the width of the goal, see text and Figures
    \protect\ref{fig:freekickside} and \protect\ref{fig:cornerkick}).}
  \label{fig:pitch}
\end{figure}

The dimensions and markings of a soccer pitch are defined in the FIFA
rules, as shown in Figure \ref{fig:pitch}. The
overall size may vary within certain ranges. For this problem, adopt a
length of the touchline of \SI{105}{m} and of the goal line of
\SI{68.52}{m}. The goal has a width of \SI{7.32}{m} and a height of
\SI{2.44}{m}.

\paragraph{Free kick}

The geometry of the situation for the \textbf{free kick} with a wall
of defending players is shown in Fig.~\ref{fig:freekick}. This is just
one of many possible positions to take the shot. We assume that the
kicker scores if he or she can shoot the ball over or around the wall
into the target area, as specified in Fig.~\ref{fig:freekickside}.

\begin{figure}
  \begin{subfigure}[b]{0.4\linewidth}
    \includegraphics{figs/freekick-top}
    \caption{Top view. The initial velocity of the ball $\vec{v}_{0}$
      has an azimuthal (direction) angle $\phi$ that is positive when
      measured from the center line (dashed) in counterclockwise
      direction.}
    \label{fig:freekicktop}
  \end{subfigure}
  ~
  \begin{subfigure}[b]{0.4\linewidth}
    \includegraphics{figs/freekick-side}
    \caption{Side view. The initial velocity of the ball $\vec{v}_{0}$
      has a polar (launch) angle $\theta$ that is positive when
      measured above ground (dashed line).}
    \label{fig:freekickside}
  \end{subfigure}
  \caption{Sketch of the model for the free kick. The free kick is
    taken at the center at a distance of \SI{18.3}{m} from the
    goal. The wall made from defending players is positioned off
    center (dashed line) to guard the left half of the goal while the
    goal keeper defends the right half. The \emph{target} area for a
    scoring free kick (out of reach of the goalie and inside the goal)
    is in the upper left corner of the goal (as seen by the kicker);
    note that the target area is offset by the radius of the ball $r$
    from the top and left edges. The goal keeper is only shown for
    comparison and does not have to be included in any simulations.}
  \label{fig:freekick}
\end{figure}

\paragraph{Corner kick}

The geometry for the \textbf{corner kick} is shown in
Fig.~\ref{fig:cornerkick}. We assume the kicker scores when she or he
can shoot the ball into the target area inside the goal near the far
post. In order to accomplish this, the ball must have some spin so
that it may curve back towards the goal.

\begin{figure}
  \centering
  \includegraphics[width=0.5\linewidth]{figs/cornerkick-top.pdf}
  \caption{Sketch of the model for scoring from a corner kick. The
    ball has to be shot into the \emph{target area} (shown in the
    inset) near the far goal post (away from the corner). It is
    assumed that shots on goal but outside the target area can be
    easily caught by the goal keeper. For the shot to count as a goal,
    the ball may not cross the touchline or the goal line before
    entering the target area from the playing field side. The initial
    direction of the ball with velocity $\vec{v}_{0}$ is characterized
    by the azimuthal angle $\phi$ (in the plane of the field, here
    counted as positive into the field to the left) and the polar
    angle $\theta$ (launch angle measured from the ground up, not
    shown). Note that the target area is offset by the radius of the
    ball $r$ from the top and left edges. The goal keeper is only
    shown for comparison and does not have to be included in any
    simulations.}
  \label{fig:cornerkick}
\end{figure}

\subsection{Ball trajectories}
\label{sec:trajectories}

Your code should be able to generate realistic trajectories for balls
kicked in two set piece situations: the free kick (Section
\ref{sec:freekick}) and the corner kick (Section
\ref{sec:cornerkick}). You should plot a range of trajectories for
different initial conditions. The plots should show the elements on
the field (location of goal, target zone, and e.g., the wall of
defending players).

\subsubsection{Free kick}
\label{sec:freekick}

The geometry of the situation is described in
Fig.~\ref{fig:freekick}. A trajectory should start at the position of
the ball (\SI{18.3}{m} from the center of the goal). A trajectory
should end when the ball
\begin{enumerate}
\item leaves the field across the touchline or the goal line (this
  includes flying over the goal or crossing the goal line inside the
  goal but the latter will only count as a scored goal if it hits the
  target area --- see Section \ref{sec:scoring})
\item hits the ground (we make the highly simplifying assumption that
  in this situation no scoring will ever occur)
\item hits the wall.
\end{enumerate}

\paragraph{Initial conditions}

Sensible ranges of parameters are shown below (based on work by
\citet{Cook:2006aa})\footnote{For a related treatment of the problem
  see \citet{Bray:2003aa}.}  \textbf{although you should feel free to
  explore a wider range of parameters if necessary}---solutions are
not guaranteed with the parameters below.
\begin{itemize}
\item initial velocity $\SI{24}{m.s^{-1}} \le v_{0} \le \SI{30}{m.s^{-1}}$
\item initial spin
  $\SI{0}{\revolutions\per\second} \le \omega_{0} \le
  \SI{12}{\revolutions\per\second}$ and for the orientation of the
  spin you may focus on full sideways spin, i.e., the spin axis
  $\boldsymbol{\omega}$ is perpendicular to the ground and parallel to
  the direction of gravity. Nevertheless, you are free to explore
  other directions of the spin axis, including spin in the opposite
  direction.
\item polar (launch) angle $\ang{10} \le \theta \le \ang{20}$
\item azimuthal (direction) angle $\ang{-2} \le \phi \le \ang{5}$
\end{itemize}

\subsubsection{Corner kick}
\label{sec:cornerkick}

The geometry of the situation is described in
Fig.~\ref{fig:cornerkick}. A trajectory should start at the position
of the ball on the corner of the field; assume that the ball sits on
the corner. A trajectory should end when the ball
\begin{enumerate}
\item leaves the field across the touchline or the goal line (this
  includes flying over the goal or crossing the goal line inside the
  goal but the latter will only count as a scored goal if it hits the
  target area --- see Section \ref{sec:scoring})
\item hits the ground (we make the highly simplifying assumption that
  in this situation no scoring will ever occur).
\end{enumerate}

\paragraph{Initial conditions}

Sensible starting ranges of parameters are shown below (based on
\citet{Cook:2006aa}) \textbf{although you should feel free to explore
  a wider range of parameters if necessary}---solutions are not
guaranteed with the parameters below.
\begin{itemize}
\item initial velocity $\SI{24}{m.s^{-1}} \le v_{0} \le
  \SI{30}{m.s^{-1}}$
\item initial spin
  $\SI{0}{\revolutions\per\second} \le \omega_{0} \le
  \SI{12}{\revolutions\per\second}$ and for the orientation of the
  spin you may focus on full sideways spin, i.e., the spin axis
  $\boldsymbol{\omega}$ is perpendicular to the ground and parallel to
  the direction of gravity. Nevertheless, you are free to explore
  other directions of the spin axis.
\item polar (launch) angle $\ang{20} \le \theta \le \ang{30}$
\item azimuthal (direction) angle $\ang{-4} \le \phi \le \ang{4}$
\end{itemize}

\subsection{Goal-scoring trajectories}
\label{sec:scoring}

The aim of the project is to find parameters for the kicks that lead
to goals. In our model we consider a trajectory to be
\emph{goal-scoring} when it hits a \emph{target area}. This target
area is presumed to be a very difficult catch for the goal keeper. The
target areas are different for the two situations and are defined in
Figures \ref{fig:freekick} and \ref{fig:cornerkick}.

You can use any number of approaches to find goal-scoring
trajectories. Possible approaches are
\begin{description}
\item[exhaustive parameter scan] Run the simulation for combinations
  of parameters and store for each parameter combination if the
  trajectory was goal scoring; this is the approach taken by
  \citet{Cook:2006aa}.
\item[shooting algorithm] Combine the simulation algorithm with a root
  finding algorithm such as bisection to automatically find solutions
  to the problem; see Chapter 3.7 in \citet{Wang:2015aa}.
\item[manual experimentation] Manually rerun your simulation with
  different parameters, using intuition and previous trials to guide
  you. Record parameter sets that score a goal.
\end{description}
You are free to use whichever approach solves the problem, including
coming up with your own approach. However, you should not just ask
other students for the answer\dots (Make sure you read the notes on
the \emph{Acknowledgments} section in Section \ref{sec:report} below
if you heavily rely on the help of other people.)

At least one parameter set that leads to goal scoring trajectory
should be reported together with plots of the trajectory. The plots
must show clearly how the trajectory hits the target area.

\section{Report}
\label{sec:report}

Write a report in which you address the objectives in Section
\ref{sec:tasks} below in the context of the problem (Section
\ref{sec:problem}). The report should contain all results (figures,
tables, equations). It must contain a \emph{title}, \emph{author's
  name}, sections \emph{Background} (problem description, definitions,
any equations that you use), \emph{Results and Discussion}
(description and interpretation of results), and \emph{Summary} (short
summary of the main results).

The report \emph{must} contain a section \emph{Contributions} where
you summarize the contributions of each team member. For example, for
a team consisting of three members with initials A.B., C.D.E., and
F.G., the beginning of this section could be written along the lines
of
\begin{quotation}
  A.B.\ wrote the code to initialize the ball positions and velocities
  with help from C.D.E; A.B. also coded the geometry for the corner
  kick and free kick. F.G. wrote the functions for $C_{D}(v, S)$ and
  $C_{L}(S)$ and plotted the results. C.D.E.\ wrote the integration
  routine. A.B., C.D.E., and F.G. together wrote the simulation
  function \texttt{simulate\_soccerball()}. F.G.\ with help from A.B.\
  wrote the plotting code and produced figures 1 and 2. F.G.\
  also wrote the Background section \dots
\end{quotation}
(Note that all team members should have commits in the team
reporsitory.)

If you had any form of outside help you must describe it in an
\emph{Acknowledgments} section.

If you use code or material from elsewhere you \emph{must cite the
  source} (add a \emph{References} section).

Any bonus material can be shown in an optional \emph{Appendix}.

The report must be written in full sentences and read as a coherent
piece of work. Figures must have legends, labels, and captions. Type
set in an 11pt font with single line spacing (captions, labels, legend
may have smaller font sizes but must still be legible) and leave at
least 1~in margins.

Overall, a length of about four pages is expected for a written
document produced with a word processor; the report should
not be less than three pages. The written portion (excluding figures)
should generally not exceed six pages.

\section{Code}
\label{sec:code}

For all numerical calculations use Python 3.x. You may use any of the
Python packages that are part of the Anaconda 3 distribution such as
\texttt{numpy} and \texttt{matplotlib}.

\textbf{Include all the code that is needed to generate the results
  shown in your report.} This can consist of Python programs, modules,
a Jupyter notebook, or a mixture thereof. \textbf{Include a separate
  file \texttt{README.txt} that explains how to run your code} in
order to generate the results in your report. \textbf{Your code must
  run without errors} in order for you to be awarded full marks.

\section{Objectives}
\label{sec:tasks}
Address the following objectives in your report while taking all
requirements in Section \ref{sec:problem} into account:
\begin{enuma}
\item Briefly describe the behavior of the drag and lift coefficients
  of a soccer ball. Plot $C_{D}(v, S)$ (Eq.~\ref{eq:CDv}) in the range
  $0 < v < \SI{30}{m.s^{-1}}$ (1) for fixed $S=0$ and (2) for fixed
  $S=0.2$. Plot $C_{L}(S)$ (Eq.~\ref{eq:CL}) for $0 < S < 0.7$.
\item Simulate soccer ball trajectories of the
  \begin{enumi}
  \item \emph{free kick with wall} (\ref{sec:freekick}) and the
  \item \emph{corner kick} (\ref{sec:cornerkick})
  \end{enumi}
 with your own Python program.
\item For each case, show at least three typical trajectories using 2D
  plots (top and side views); as a bonus you can also show 3D
  plots. Describe the trajectories and list the parameters that were
  used to create them. ``Typical'' means that they should show a broad
  range of outcomes such as ``hits the goal'', ``hits the wall'',
  ``flies besides or over the goal'', \dots.
\item For each of the two cases, find at least one set of parameters
  that results in a \emph{goal-scoring trajectory} (see Section
  \ref{sec:scoring}). For each goal-scoring trajectory
  \begin{enumi}
  \item list the parameters
  \item show plots of the trajectory
  \item include a plot of a trajectory with the same parameters as the
    scoring trajectory \emph{except} that spin is set to zero
    ($\omega_{0} = 0$) to demonstrate the influence of spin
  \end{enumi}
\end{enuma}

\section{History}
\label{sec:history}

Changes and updates to this document.
\begin{description}
\item[2018-03-26] initial version
\item[2018-04-04] added soccer pitch dimensions, clarified ``ball
  out'' conditions, and emphasized that the initial choices of
  parameters can be expanded by students in order to find a solution
\end{description}

\bibliographystyle{physbiol-natbib}      % basic style, author-year citations
\bibliography{phy494}   % name your BibTeX data base

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: