\documentclass[./\jobname.tex]{subfiles}
\begin{document}
\section {Experiment 3: Gauss-Sinus Kernel}
\label{chap:experimet_3}
Up until now, the results on \gls{pde} 5 were always considerably worse than on all other testbed functions. The idea discussed in this section is the usage of a new kernel. Theoretically, the Gauss Sine kernel (\gls{gsk}) should be able to solve the testbed \gls{pde}s 0A and 0B exactly.
\subsection{Hypotheses}
Attempting to solve \gls{pde} 5 with more \gls{nfe} results in a worse solution quality. The adaptive kernel scheme could not improve the results. This means that the fitness function must be reconsidered. A simple approach to change the fitness function is by introducing a new kernel type. The \gls{gsk} has the features of a Gauss kernel and a sine function and is potentially able to approximate more \gls{pde} solutions. This experiment tries to answer the question if the new \gls{gsk} kernel type can effectively improve the results on \gls{pde} 5.
\subsection{Experiment Setup}

Machine 2 runs the experiment at the full computational budget of $10^6$ \gls{nfe}. Because the last experiment was not entirely conclusive, only a memetic pJADE without kernel-adaption is tested. Since the new kernel has 6 parameters, the dimension and the population size change. To ensure that the algorithm is able to solve \gls{pde} 0A, 5 \gls{gsk} are used. This results in a dimension of 30 parameters and a population size of 60. All other parameters for the experiments are taken from table \ref{tab:ci_parameter}.

\subsection{Results}
The following table shows the statistical test. The comparison between the \gls{gsk} and the \gls{gak} on the memetic parallel JADE is shown in table \ref{tab:compare_mpj_mpjgsk_10^6}. The comparison is done with a budget of $10^6$ \gls{nfe}.
\begin{table}[h]
	\centering
	\noindent\adjustbox{max width=\linewidth}{
		\begin{tabular}{|c|c|c|c|c|l|}

			\hline
			\rowcolor[HTML]{\farbeTabA}

			Algorithm & \multicolumn{2}{|c|}{parallel JADE \gls{gak} $10^6$ \gls{nfe}} & \multicolumn{2}{|c|}{parallel JADE \gls{gsk} $10^6$ \gls{nfe}} & \\ \hline
			stat & mean & median & mean & median & Wilcoxon Test \\ \hline \hline
			\gls{pde} 0A & 0.6939 $\pm$ 0.6635 & 0.9243 & 0.8106 $\pm$ 0.7929 & 0.6765 & unsig. undecided \\ \hline
			\gls{pde} 0B & 0.2809 $\pm$ 0.3071 & 0.2035 & 0.0667 $\pm$ 0.0470 & 0.0614 & sig. better \\ \hline
			\gls{pde} 1 & 0.0239 $\pm$ 0.0467 & 0.0146 & 0.1665 $\pm$ 0.1015 & 0.1952 & sig. worse \\ \hline
			\gls{pde} 2 & 0.0300 $\pm$ 0.0157 & 0.0255 & 0.0448 $\pm$ 0.0224 & 0.0416 & unsig. worse \\ \hline
			\gls{pde} 3 & 0.0371 $\pm$ 0.0206 & 0.0295 & 0.0263 $\pm$ 0.0111 & 0.0269 & unsig. better \\ \hline
			\gls{pde} 4 & 0.0505 $\pm$ 0.0121 & 0.0481 & 0.0470 $\pm$ 0.0078 & 0.0458 & unsig. better \\ \hline
			\gls{pde} 5 & 1.2030 $\pm$ 0.0465 & 1.2053 & 0.5860 $\pm$ 0.2149 & 0.6841 & sig. better \\ \hline
			\gls{pde} 6 & 0.5814 $\pm$ 1.3550 & 0.0000 & 3.7321 $\pm$ 0.6397 & 3.9079 & sig. worse\\ \hline
			\gls{pde} 7 & 0.0228 $\pm$ 0.0025 & 0.0226 & 0.0243 $\pm$ 0.0046 & 0.0241 & unsig. worse\\ \hline
			\gls{pde} 8 & 0.2167 $\pm$ 0.0017 & 0.2169 & 0.2154 $\pm$ 0.0018 & 0.2150 & sig. better\\ \hline
			\gls{pde} 9 & 0.0426 $\pm$ 0.0115 & 0.0463 & 0.0351 $\pm$ 0.0099 & 0.0333 & unsig. better\\ \hline

		\end{tabular}
	}
	\unterschrift{Statistical comparison of the the parallel JADE using the \gls{gak} and the \gls{gsk}.}{}{}
	\label{tab:compare_mpj_mpjgsk_10^6}
\end{table}
\newpage
\subsection{Discussion}
\subsubsection{PDE 5}
The hypothesis of the \gls{gsk} is that it significantly increases the approximation quality of \gls{pde} 5. Further, it should overcome the phenomenon where the L2 norm increases with more \gls{nfe}. As table \ref{tab:compare_mpj_mpjgsk_10^6} shows, the results are indeed significantly better. Again, this can be confirmed from a visual perspective by looking at the 3D plot of the approximation. Figure \ref{fig:pde5_ex3_compare_best_worst} depicts the best and the worst approximation of the 20 replications. Although the results are clearly better and the global structure is described more accurately, the \gls{ci} solver can not compete with the \gls{fem} solver.
\begin{figure}[h]
	\centering
	\begin{subfigure}[b]{0.3333\linewidth}
		\centering
		\includegraphics[width=1\textwidth]{../../code/experiments/experiment_3/pde5_best_solution_non-adaptive.pdf}
		\caption{best run  \gls{gsk} \\L2 norm: 0.252574}
		\label{fig:pde5_ex3_worst_solution_non-adaptive}
	\end{subfigure}%
	%
	\begin{subfigure}[b]{0.3333\linewidth}
		\centering
		\includegraphics[width=1\textwidth]{../../code/experiments/experiment_3/pde5_worst_solution_non-adaptive.pdf}
		\caption{worst run \gls{gsk} \\L2 norm: 0.883869}
		\label{fig:pde5_ex3_best_solution_adaptive}
	\end{subfigure}%
	%
	\begin{subfigure}[b]{0.3333\linewidth}
		\centering
		\includegraphics[width=1\textwidth]{../../code/testbed/pde5/sol_pde_5.pdf}
		\caption{solution \\ \gls{pde} 5.}
		\label{fig:pde5_analytical_solution_3}
	\end{subfigure}%
	\unterschrift{Comparison of the best and the worst result generated by memetic pJADE with \gls{gsk} after $10^6$ \gls{nfe}. }{}{}%
	\label{fig:pde5_ex3_compare_best_worst}
\end{figure}
The following histograms in figure \ref{fig:pde5_L2norm_histogram_gsk} compare the experimental distribution of the L2 norm with the \gls{gak} and the \gls{gsk}. As inferred from the Wilcoxon test, the distributions are significantly different. Further, the mean and the median of the ``\gls{gsk}-data'' are smaller than the same statistical indicators of the ``\gls{gak}-data''. The histogram of the fitness values is shown in figure \ref{fig:pde5_fitness_histogram_gsk}. Contrary, the fitness values of the \gls{gak} are smaller than the fitness values of the \gls{gsk}. Because the fitness function changes with the usage of the \gls{gsk}, the numerical values can not be compared directly.
\begin{figure}[h]
	\centering
	\begin{subfigure}[b]{0.5\linewidth}
		\centering
		\includegraphics[width=1\textwidth]{../../code/experiments/experiment_3/pde5_non-adaptive_histogram_fit.pdf}
		\caption{Histogram of fitness value using \gls{gsk} and \gls{gak}.}
		\label{fig:pde5_fitness_histogram_gsk}
	\end{subfigure}%
	%
	\begin{subfigure}[b]{0.48\linewidth}
		\centering
		\includegraphics[width=1\textwidth]{../../code/experiments/experiment_3/pde5_non-adaptive_histogram_L2.pdf}
		\caption{Histogram of L2 norm using \gls{gsk} and \gls{gak}.}
		\label{fig:pde5_L2norm_histogram_gsk}
	\end{subfigure}%
	\unterschrift{Histograms of \gls{gsk} and \gls{gak} L2 norm and fitness value on \gls{pde} 5 after $10^6$ \gls{nfe}. }{}{}%
	\label{fig:pde5_ex3_histogram}
\end{figure}
Similar to the plot in section \ref{chap:ex0_pde5}, figure \ref{fig:ex3_pde5_gsk_fit_vs_l2} connects the L2 norm of one individual with its fitness value at every generation. Although the effect of a raising L2 norm with increasing \gls{nfe} is mitigated, it can be seen that the best quality is not reached after $10^6$ \gls{nfe}. After generation 5000, the L2 norm settles in at around 0.4, while the fitness value continues to decrease.
\begin{figure}[h]
	\centering
	\noindent\adjustbox{max width=0.8\linewidth}{
		\includegraphics[width=\textwidth]{../../code/experiments/misc/pde5_gsk_fit_l2_history.pdf}
	}
	\unterschrift{Fitness value and L2 Norm of an exemplary individual at every generation on \mbox{\gls{pde} 5} using a \gls{gsk}. }{}{}
		\label{fig:ex3_pde5_gsk_fit_vs_l2}
\end{figure}
This again shows that a good fitness value does not necessarily indicate a good approximation quality. Although this property is only shown on \gls{pde} 5, it might also be true on other \gls{pde}s. This issue demonstrates that the fitness function suffers from a fundamental problem, but currently this is the best indicator for good solutions that only use the information posed in the original problem definition. It can be concluded that choosing an appropriate kernel is not trivial, especially in the common case where the analytical solution to the \gls{pde} is not known.
\end{document}


\documentclass{beamer}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathbbol}
\usepackage{mathtools}
\usepackage{stmaryrd}
\DeclarePairedDelimiter\Parens{\lparen}{\rparen}
\DeclarePairedDelimiter\Floor{\lfloor}{\rfloor}
\usepackage{gauss}
\usepackage{relsize}

\usepackage{xcolor}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\usepackage{url}
\usepackage{hyperref}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[links]{agda}
\usepackage{newunicodechar}
\newunicodechar{λ}{\ensuremath{\mathnormal\lambda}}
\newunicodechar{→}{\ensuremath{\mathnormal\to}}
\newunicodechar{∀}{\ensuremath{\mathnormal\forall}}
\newunicodechar{𝔹}{\ensuremath{\mathbb{B}}}
\newunicodechar{ℕ}{\ensuremath{\mathbb{N}}}
\newunicodechar{₁}{\ensuremath{{}_1}}
\newunicodechar{¹}{\ensuremath{{}^1}}
\newunicodechar{₂}{\ensuremath{{}_2}}
\newunicodechar{²}{\ensuremath{{}^2}}
\newunicodechar{₃}{\ensuremath{{}_3}}
\newunicodechar{³}{\ensuremath{{}^3}}
\newunicodechar{₄}{\ensuremath{{}_4}}
\newunicodechar{⁴}{\ensuremath{{}^4}}
\newunicodechar{ᵇ}{\ensuremath{{}^b}}
\newunicodechar{⁺}{\ensuremath{{}^+}}
\newunicodechar{≡}{\small {\ensuremath{\equiv}}}
\newunicodechar{≢}{\small {\ensuremath{\not\equiv}}}
\newunicodechar{≟}{\small {\ensuremath{\stackrel{?}{=}}}}
\newunicodechar{∙}{\ensuremath{\cdot}}
\newunicodechar{×}{\ensuremath{\times}}
\newunicodechar{ε}{\ensuremath{\varepsilon}}
\newunicodechar{∎}{\ensuremath{\rule{1ex}{1.2ex}}}
\newunicodechar{⟨}{\ensuremath{\langle}}
\newunicodechar{⟩}{\ensuremath{\rangle}}
\newunicodechar{ˡ}{\ensuremath{{}^l}}
\newunicodechar{ʳ}{\ensuremath{{}^r}}
\newunicodechar{∷}{\ensuremath{::}}
\newunicodechar{ⁱ}{\ensuremath{{}^i}}
\newunicodechar{ʰ}{\ensuremath{{}^h}}
\newunicodechar{ℓ}{\ensuremath{\ell}}
\newunicodechar{⁻}{\ensuremath{{}^{-}}}
\newunicodechar{≈}{\ensuremath{\approx}}
\newunicodechar{𝕓}{\ensuremath{\mathbb{b}}}
\newunicodechar{⇓}{\ensuremath{\Downarrow}}
\newunicodechar{⇑}{\ensuremath{\Uparrow}}
\newunicodechar{⇒}{\ensuremath{\Rightarrow}}
\newunicodechar{⇐}{\ensuremath{\Leftarrow}}
\newunicodechar{⟦}{\ensuremath{\llbracket}}
\newunicodechar{⟧}{\ensuremath{\rrbracket}}
\newunicodechar{✓}{\ensuremath{\checkmark}}
\newunicodechar{∣}{\ensuremath{\mid}}
\newunicodechar{∤}{\ensuremath{\nmid}}
\newunicodechar{¬}{\ensuremath{\neg}}
\newunicodechar{⊥}{\ensuremath{\bot}}
\newcommand{\Dotdiv}{%
  \mathbin{%
    \vphantom{+}%
    \text{%
      \mathsurround=0pt%
      \ooalign{%
        \noalign{\kern-.35ex}%
        \hidewidth$\smash{\cdot}$\hidewidth\cr%
        \noalign{\kern.35ex}%
        $-$\cr%
      }%
    }%
  }%
}
\newunicodechar{∸}{\ensuremath{\Dotdiv}}
\newunicodechar{≤}{\ensuremath{\leq}}
\newunicodechar{≱}{\ensuremath{\not\geq}}
\newunicodechar{≮}{\ensuremath{\not<}}
\newunicodechar{≺}{\ensuremath{\prec}}
\newunicodechar{⊂}{\ensuremath{\subset}}
\newunicodechar{∨}{\ensuremath{\wedge}}

\usepackage{pifont}
\newcommand{\cmark}{\text{\ding{51}}}
\newcommand{\xmark}{\text{\ding{55}}}

\newcommand{\Agda}[0]{Agda}

\newcommand{\BigO}[1]{\ensuremath{O\Parens{#1}}}

\newcommand{\Lg}[1]{\ensuremath{\text{lg}\Parens{#1}}}

\setlength{\parindent}{0pt}

\usetheme{metropolis}
\title{
  A Replication of the AKS\\
  Primality Decision Algorithm
}
\date{8 May 2020}
\author{Alice McKean}
\institute{
  The Division of Mathematical and Natural Sciences \\
  Reed College
}

\begin{document}

\maketitle

\begin{frame}{\Agda{} Introduction}
  % Imagine not having to grade any math homework ever again or mathematics journals not
  % needing peer review. This is the world \Agda{} and other \textit{proof assistants}
  % hope to bring about. \\
  \Agda{} is a \textit{proof assistant}. It can verify the correctness of
  arbitrarily complex proofs in higher order logic \cite{agda}. \\
  Its not magic though, it can only perform the most basic proof search. This
  sets it apart from other tools in this area, like SAT solvers. \\
  In this thesis, we will attempt to verify the AKS primality decision procedure
  in \Agda{}.
\end{frame}

\section{Primality Decision Algorithms}

\begin{frame}{Problem Definition}
  In this thesis we investigate \textit{decision algorithms} for the following
  language.
  \begin{align*}
    \text{PRIMES} = \{ \, p \, | \text{ such that } p \text{ is a prime number } \}
  \end{align*}
  An obvious brute force solution follows from the definition of prime numbers.
  Just try all the divisors less than $p$ and if nothing divides $p$ return YES. \\

  This algorithm is linear in the size of the input $\BigO{n}$ we desire an
  algorithm with polynomial run-time in the size of the description of
  the input $\BigO{\Lg{n}^c}$.
\end{frame}
\begin{frame}{Algorithm Characterization}
  These three dimensions are how we will compare primality decision algorithms.
  \begin{itemize}
    \item \textit{Computational Complexity} standard run-time analysis
    \item \textit{Determinism} if the algorithm requires probabilistic primitives
    \item \textit{Conditionality} an algorithm is conditional it's correctness
      depends on unproven conjecture
  \end{itemize}
\end{frame}

\begin{frame}{History}
  Now we will discuss a rough history of the development of primality decision
  algorithms.
  \begin{itemize}
    \item<1-> Miller's Primality Test, deterministic, polynomial time but requires
      \textit{Extended Riemann Hypothesis} \cite{miller}
    \item<2-> Rabin's Primality Test, polynomial time, unconditional but
      non-deterministic \cite{rabin}
    \item<3-> Adleman, Pomerance, and Rumely, deterministic, unconditional and
      sub-exponential
      $\BigO{\Lg{n}^{c \, \text{lg} \, \text{lg} \, \text{lg} \, n}}$ \cite{apr}.
  \end{itemize}
\end{frame}

\begin{frame}{AKS}
  Agrawal, Kayal,and Saxena created a unconditional, deterministic, polynomial
  time $\BigO{\Lg{n}^{15/2}}$ primality decision algorithm. \cite{aks}. \\

  The correctness proof of this algorithm is comparably simpler to all the
  previous algorithms listed above, requiring only undergraduate levels of number
  theory. This property makes AKS a great candidate for a ``replication'' in
  \Agda{}. \\

  Next we explore some psuedo-code describing AKS adapted from Micheal Smid's
  AKS analysis \cite{smid}.
\end{frame}

\begin{frame}{AKS (Pseudo Code)}
  \scriptsize
  \begin{algorithmic}
    \Function{IsPrime}{$n$}
    \State $r \leftarrow 2$
    \While{true}
      \If{$gcd(r, n) = 1$}
        \State \textbf{return} NO
      \EndIf
      \State $q \leftarrow$ largest prime factor of $r - 1$
      \If{$q \geq 2 \sqrt{r} \, \Lg{n} + 2$ and
        $n^{(r - 1) / q} \not\equiv 1 \text{ mod } r$}
        \State \textbf{break}
      \EndIf
      \State $r \leftarrow$ next prime after $r$
    \EndWhile
    \For{$a \leftarrow 1$ \textbf{to} $\Floor[\big]{2 \sqrt{r} \, \Lg{n}} + 1$}
      \If{$(x - a)^n \not\equiv (x^n - a) \text{ mod } (x^r - 1) \text{ in } \mathbb{Z}_n[x]$}
        \State \textbf{return} NO
      \EndIf
    \EndFor
    \If{$n$ is a perfect power}
      \State \textbf{return} NO
    \Else
      \State \textbf{return} YES
    \EndIf
    \EndFunction
  \end{algorithmic}
\end{frame}

\begin{frame}{Primitive Concepts}
  \begin{center}
    \begin{tabular}{c|c|c}
      Concept & Formalized & In Thesis \\
      \hline
      Define Primality & \cmark & \cmark \\
      Looping Constructs & \cmark & \cmark \\
      Prime Stream & \cmark & \cmark \\
      Square Root & \xmark & \xmark \\
      Binary Logarithm & \cmark & \cmark \\
      Modular Field & \cmark & \xmark \\
      Polynomials & \cmark & \xmark \\
      Polynomial Division & \cmark & \xmark \\
      Exponentiation & \cmark & \cmark \\
      Testing Perfect Powers & \xmark & \xmark \\
    \end{tabular}
  \end{center}
\end{frame}

\section{Formalized Proofs}

\begin{frame}{Type Theory}
The primitive concept underlying Type Theory is the \textit{typing relation},
namely a \textit{term} $a$ has \textit{type} $A$ written $a : A$. \\
In the language of Set Theory this would represent ``a is an element of the set A''
denoted $a \in A$. \\
Types differ from sets in many ways. For instance the perfectly valid set
$\{ \, \text{true}, \, 0, \, \emptyset \, \}$
is inexpressible in Type Theory as types are ``homogeneous''. \\
``Is $b$ a member of $B$ for some pre-existing objects $b$ and $B$?'' is
nonsense in Type Theory. One can not talk about objects without their type.
\end{frame}

\begin{frame}{Booleans}
  \begin{code}[hide]
    open import Relation.Binary.PropositionalEquality
      using (_≡_; _≢_; module ≡-Reasoning)
      renaming (refl to ≡-refl; sym to ≡-sym; cong to ≡-cong)
    open ≡-Reasoning
  \end{code}
  \begin{code}
    data 𝔹 : Set where
      false : 𝔹
      true  : 𝔹

    not : 𝔹 → 𝔹
    not false = true
    not true  = false

    not-example : 𝔹
    not-example = not false

    not-involution : ∀ (b : 𝔹) → not (not b) ≡ b
    not-involution false = ≡-refl
    not-involution true = ≡-refl
  \end{code}
\end{frame}

\begin{frame}{Natural Numbers}
  \begin{code}
    data ℕ : Set where
      zero : ℕ
      suc  : ℕ → ℕ

    three : ℕ
    three = suc (suc (suc zero))

    _+_ : ℕ → ℕ → ℕ
    zero + n = n
    suc n + m = suc (n + m)
  \end{code}
\end{frame}

\begin{frame}{Addition is Associative}
  \begin{code}
    Associative : ∀ {A : Set} → (A → A → A) → Set
    Associative {A} _∙_
      = ∀ (x y z : A) → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z)

    +-assoc : Associative _+_
    +-assoc zero y z = ≡-refl
    +-assoc (suc x) y z = begin
      suc x + (y + z)   ≡⟨⟩
      suc (x + (y + z)) ≡⟨ ≡-cong suc (+-assoc x y z) ⟩
      suc ((x + y) + z) ≡⟨⟩
      (suc (x + y) + z) ≡⟨⟩
      (suc x + y) + z   ∎
  \end{code}
\end{frame}

\begin{frame}[allowframebreaks]{Citations}
  \nocite{gnu-parallel}
  \bibliographystyle{apalike}
  \bibliography{citations}
\end{frame}

\end{document}


\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{float}
\usepackage[colorinlistoftodos]{todonotes}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{Overleaf}
\fancyhead[RE,LO]{Assignment-01}
\fancyfoot[CE,CO]{\leftmark}
\fancyfoot[LE,RO]{\thepage}

\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}

\begin{document}

\begin{titlepage}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here

\center % Center everything on the page

%----------------------------------------------------------------------------------------
%	HEADING SECTIONS
%----------------------------------------------------------------------------------------

\textsc{\LARGE BRAC University}\\[1.5cm] % Name of your university/college
\includegraphics[scale=.3]{bracu_logo.png}\\[1cm] % Include a department/university logo - this will require the graphicx package
\textsc{\Large Complex Variables \& Laplace Transformations}\\[0.5cm] % Major heading such as course name
\textsc{\large MAT215}\\[0.5cm] % Minor heading such as course title

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------

\HRule \\[0.4cm]
{ \huge \bfseries Assignment-01}\\[0.4cm] % Title of your document
\HRule \\[1.5cm]

%----------------------------------------------------------------------------------------
%	AUTHOR SECTION
%----------------------------------------------------------------------------------------

%\begin{minipage}{0.4\textwidth}
%\begin{flushleft} \large
%\emph{Author:}\\
%Syed Zuhair \textsc{Hossain}\\ % Your name
%\end{flushleft}

%\end{minipage}\\[2cm]

% If you don't want a supervisor, uncomment the two lines below and remove the section above
\Large \emph{Author:}\\
Syed Zuhair Hossain\\\textsc{St.ID-19101573\\Section-10 \\ \textbf{SET-A}}\\[2cm] % Your name

%----------------------------------------------------------------------------------------
%	DATE SECTION
%----------------------------------------------------------------------------------------

{\large \today}\\[2cm] % Date, change the \today to a set date if you want to be precise

\vfill % Fill the rest of the page with whitespace

\end{titlepage}
\pagebreak

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

                %Solution Number 01%

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

\chapter{01}
\textbf{Use the help of the polar representations of complex numbers to express $(1+i)^3$ in the form a + bi, where a and b are real.}

\begin{align*}
    Let,
    z &= 1 + i
    \\
    \therefore r &= \sqrt{1^2 + 1^2}
    \\
    &= \sqrt{2}
    \\
    \theta &= \frac{\pi}{4}
    \\ \\
    \textit{According to De Moivr's theorem,}
    \\
    \therefore z&= r xos\theta + i r sin\theta
    \\
    &= \sqrt{2} cos \frac{\pi}{4} + i \left(\sqrt{2} sin \frac{\pi}{4}\right)
    \\
    \therefore (1+i)^3 &= \left[\sqrt{2} (cos(\frac{\pi}{4}) + i \cdot \sqrt{2} \left(sin \frac{\pi}{4} \right)z \right]^3
    \\
    &= (\sqrt{2})^3 \left(cos\frac{\pi}{4} + i sin \frac{\pi}{4} \right)^3
    \\
    &= 2\sqrt{2} \cdot (e^{i \cdot \frac{\pi}{4}})^3 \hspace{10mm} [\therefore cos\theta + sin\theta = e^{i\theta}]
    \\
    &= 2\sqrt{2} \cdot e^{i \frac{3\pi}{4}}
    \\
    &= 2\sqrt{2} \left(cos \frac{3\pi}{4} + i sin \frac{3 \pi }{4}\right)
    \\
    &= 2\sqrt{2} \left(-\frac{1}{\sqrt{2}} + \frac{1}{\sqrt{2}}\right)
    \\
    &= -\frac{2\sqrt{2}}{\sqrt{2}} + i \cdot \frac{2\sqrt{2}}{\sqrt{2}}
    \\
    &= -2 + 2 i
    \\
    &\hspace{50mm}[Answer]
\end{align*}
\pagebreak

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

                %Solution Number 02%

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

\chapter{02}
\textbf{Express $e^{2+i \pi 2}$ in the a + bi form.}

\begin{align*}
    Given,
    \\
    e^{2+i\pi 2} &= e^2 \cdot e^{i (\pi 2)}
    \\ \\
    \textit{According to De Moivre's theorem,}
    \\
    z^n &= r^n e^{i n \theta}
    \\
    \textit{By applying this formula here -}
    \\
    z &= e^2 e^{i (2\pi)}
    \\
    \therefore r &= e^2
    \\
    \theta &= 2\pi
    \\
    \textit{we know,}
    \\
    X &= r cos \theta
    \\
    Y &= r sin \theta
    \\\\
    z &= x + i y
    \\
    &= r cos\theta + i r sin \theta
    \\
    z &= x + iy
    \\
    &= r cos \theta + i r sin \theta
    \\
    &= e^2 cos(2\pi) + i \cdot e^2 \cdot sin(2\pi)
    \\
    &= 7.389 + i \cdot 0
    \\
    &= 7.389
    \\ \\ \\
    &\hspace{50mm}[Answer]
\end{align*}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                %Solution Number 03%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{03}
\textbf{Express $\frac{1}{1+i} + \frac{2}{3+2i}$ in the a + bi}

\begin{align*}
    \textit{From the equations we get,}
    \\
    \frac{1}{1+i} &= \frac{1}{1+i} \times \frac{1-i}{1-i}
    \\
    &= \frac{1-i}{1-i^2}
    \\
    &= \frac{1-i}{1-(-1)} \hspace{10mm}[\therefore i^2 = -1]
    \\
    &= \frac{1-i}{2}
    \\
    \\
    \texttt{Again,}
    \\
    \frac{2}{3+2i} &= \frac{2}{3+2i} \times \frac{3-2i}{3-2i}
    \\
    &= \frac{6-4i}{3^2 - (2i)^2}
    \\
    &= \frac{6-4i}{9-(4i)^2}
    \\
    &= \frac{6-4i}{9+4} \hspace{10mm}[\therefore i^2=-1]
    \\
    &= \frac{6-4i}{13}
    \\ \\
    \therefore \frac{1}{1+i} + \frac{2}{3+2i} &= \frac{1-i}{2} + \frac{6-4i}{13}
    \\
    &= \frac{1}{2} - \frac{i}{2} + \frac{6}{13} - \frac{4i}{13}
    \\
    &= \frac{25}{26} - \frac{21i}{26}
    \\ \\
    &\hspace{50mm}[Answer]
\end{align*}
\newpage

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

                %Solution Number 04%

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

\chapter{04}
\textbf{Find the distinct roots of z for the following equation, z^4 = 3i}

\begin{align*}
    z^4 &= 3i
    \\
    \Rightarrow z^4 &= 0 + 3i
    \\
    \Rightarrow r^4 e^{i4\theta} &= r_0 e^{i \theta_0}
    \\
    \therefore r_0 &= r^4
    \\
    \Rightarrow (r_0)^{\frac{1}{4}} &= r
    \\
    \Rightarrow r &= \left(\sqrt{(3i^2)^2}^{\frac{1}{4}}\right)
    \\
    &= 3^{\frac{1}{4}}
    \\
    \\
    \theta_0 &= 4\theta
    \\
    \Rightarrow 4\theta &= \theta_0 + 2 \pi k
    \\
    &= \frac{\pi}{2\pi k}
    \\
    \therefore \theta &= \frac{\pi}{8} + \frac{\pi k}{2}
    \\
    \texttt{1st root,}
    \\
    z_1 &= (3)^{\frac{1}{4}} \cdot \left[cos(\frac{\pi}{8} + \frac{\pi}{2} \times 0) + isin sin(\frac{\pi}{8} + \frac{\pi}{2} \times 0) \right]
    \\
    &= 1.216 + 0.504 i
    \\
    \\
    \texttt{2nd root,}
    \\
    z_2 &= (3)^{\frac{1}{4}} \left[cos(\frac{\pi}{8} + \frac{\pi}{2} \times (-1)) + i sin(\frac{\pi}{8} + \frac{\pi}{2} \times 1)
    \right]
    \\
    &= -0.504 + 1.216 i
    \\ \\
    \textit{3rd root,}
    \\
    z_3 &= (3)^{\frac{1}{4}} \left[cos(\frac{\pi}{8} + \frac{\pi}{2} \times (-1)) + i sin(\frac{\pi}{8} + \frac{\pi}{2} \times (-1))\right]
    \\
    &= 0.504 - 1.216 i
\end{align*}

\newpage
\begin{align*}
    \textit{4th root,}
    \\
    z_4 &= (3)^{\frac{1}{4}} \left[cos(\frac{\pi}{8} + \frac{\pi}{2} \times 2) + i sin(\frac{\pi}{8} + \frac{\pi}{2} \times 2)
    \right]
    \\
    &= -1.216 - 0.504 i
    \\
    \\
    &\hspace{50mm}[Answer]
\end{align*}

\vspace{20mm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                %Solution Number 05%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{05}
\texttt{Prove by taking z = a + bi, z - \overline{z} = 2iIm z.}

\begin{align*}
    \text{Given that,}
    \\
    z &= a + bi
    \\
    \therefore \overline{z} &= a - b i
    \\ \\
    \therefore L. H. S. &= z - \overline{z}
    \\
    &= a + bi - a + bi
    \\
    &= 2 ib
    \\ \\
    R. H. S. &= 2 i Im (z)
    \\
    &= 2 i Im(a+bi)
    \\
    &= 2 ib
    \\ \\
    \therefore L. H. S. &= R. H. S.
    \\
    \vspace{20mm}
    &\hspace{50mm} [Answer]
\end{align*}

\end{document}

MAT215 - Complex Variables & Laplace/Assignment-01/main.tex


% content (c) 2018 chris wallace under Creative Commons Share Alike (CC BY-SA 4.0)
% class notes from vim week 3
\documentclass{article}

\usepackage[hidelinks]{hyperref}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{paralist}
\lstset{language=bash}
\lstset{basicstyle=\footnotesize\ttfamily,breaklines=true}

\title{Vim class notes}
\author{Chris Wallace}
\date{Week 3}

\begin{document}
\maketitle

\noindent Recap: What did we talk about last week?
\begin{compactitem}
    \item file commands (touch, mv, cp, rm, etc\dots)
    \item folder commands (mkdir, rmdir, cd, etc\dots)
    \item input and output redirection (and cowsay, of course)
    \item the echo command
    \item variables
\end{compactitem}

\section*{Variables}
Let's talk again about variables, since they are actually used in almost every
language!

How do we \textit{statically assign} content to a variable?
\begin{lstlisting}
name="chris"
\end{lstlisting}

How do we \textit{dynamically assign} content to a variable?
\begin{lstlisting}
read name
\end{lstlisting}

How do we print the contents of a variable?
\begin{lstlisting}
echo "$name"
echo "$other_variable"
\end{lstlisting}

Variables are some of the most important things of programming. If you have
taken pre algebra, you should be familiar with something like this:
\[
    y = x + 2
\]

To represent this in bash, we first introduce that there is a way to do math:
\lstinline|$((math))|. See the example below, notice we use the ``\$'' only
when \textit{accessing} a variable's contents.
\begin{lstlisting}
x=2
echo "$x" # shows 2
y=$(($x+2)) # y is now 4
\end{lstlisting}

In programming, we use variables to keep track of \textit{state}. We want our
programs to be able to make decisions based on what they receive and know.

\section*{Conditionals}
Almost every programming language has a thing called \textit{Conditionals}. If
you've done scratch or python, you've seen these already: ``if this then that''
is the general idea.

Let's look at some examples. In the following, we can see a simple \textbf{if}
statement. Notice that the square brackets have some pretty specific spacing,
and we use the \$ to access the choice. Also important are the \textbf{then}
statement, and the \textbf{fi} to end. We additionally indent our code for
readability.
\begin{lstlisting}
choice=0
if [ $choice -eq 0 ]
then
    echo "choice was rock!"
fi
\end{lstlisting}

In the following example, we'll see "if else". The \textbf{else} block will
happen if the \textbf{if} condition was not true. What do you think this
program will print?
\begin{lstlisting}
choice=999
if [ $choice -eq 0 ]
then
    echo "choice was rock!"
else
    echo "choice was not rock! :("
fi
\end{lstlisting}

Finally, we have one more tool at our disposal: \textbf{elif}. We use this to
handle \textit{multiple} conditions. What do you think will be printed by this?
\begin{lstlisting}
choice=1
if [ $choice -eq 0 ]
then
    echo "choice was rock!"
elif [ $choice -eq 1 ]
then
    echo "choice was paper!"
else
    echo "choice was not rock, or paper.. hmmmm"
fi
\end{lstlisting}

\section*{Rock Paper Scissors}
In the case of the rock paper scissors project, we can make decisions based on
what the user inputs. Before we do that, however, we need to discuss algorithms.
\subsection*{Algorithms}
An \textit{algorithm} is the set of rules, or steps, that the computer will
take to solve a problem. As a software engineer, you'll have to not just type
code into the computer, but actually come up with solutions that work.

For Rock Paper Scissors, can you think of the steps involved? Here's the
simplest steps we came up with:
\begin{enumerate}
    \item Both players come up with a choice.
    \item A winner is determined.
\end{enumerate}

Let's break down each individual part of that. in \#1, we already know how to
get human input using \textbf{read}, so the hard part is figuring out the
computer's choice.

\subsection*{The Computer's Choice}
Remember remainder division, your favorite part of elementary school math? There's one
thing that's important from what you learned back then. Check out the following
example, notice the pattern of the remainder:
\begin{align*}
    \frac{2}{2} = 1, \text{remainder } 0\\
    \frac{3}{2} = 1, \text{remainder } 1\\
    \frac{4}{2} = 2, \text{remainder } 0\\
    \frac{5}{2} = 2, \text{remainder } 1\\
\end{align*}
Whenever we divide by 2, we always get a remainder of either 0 or 1.

What happens when we divide by 3? The possible remainders then become 0, 1, and 2.
\begin{align*}
    \frac{0}{3} = 0, \text{remainder } 0\\
    \frac{1}{3} = 0, \text{remainder } 1\\
    \frac{2}{3} = 0, \text{remainder } 2\\
    \frac{3}{3} = 1, \text{remainder } 0\\
    \frac{4}{3} = 1, \text{remainder } 1\\
    \frac{5}{3} = 1, \text{remainder } 2\\
\end{align*}

In programming, most languages have a shortcut to get ``the remainder from a
division of this number''. It's called \textit{modulo}, or \textbf{mod} for
short. You can use it in bash with: \lstinline|%|, for example:
\begin{lstlisting}
x=3
echo "$(($x % 3))" # prints 0
x=4
echo "$(($x % 3))" # prints 1
x=5
echo "$(($x % 3))" # prints 2
\end{lstlisting}

Now that we have a way to take any number to 0, 1, or 2, we need a way to get
random numbers. Luckily, there is a \textit{system variable} that gives you a
random number for free. It's called \lstinline|RANDOM|, simply enough. To use:
\begin{lstlisting}
# get a random number between 0 and 2
computerchoice=$(($RANDOM % 3))
\end{lstlisting}

\subsection*{Determining a winner}
To determine a winner, we'll use the \textbf{if} statements we learned earlier,
by \textit{nesting} the if statements (putting them inside each other):

\begin{lstlisting}
if [ $playerchoice -eq 0 ]
then
    echo "player chose rock"
    if [ $computerchoice -eq 0 ]
    then
        echo "there was a tie"
        # you do the rest
    fi
elif [ $playerchoice -eq 1 ]
then
    echo "player chose paper"
    # you do the rest...
elif [ $playerchoice -eq 2 ]
then
    echo "player chose scissors"
    # you do the rest...
else
    echo "player didn't make the right choice"
fi
\end{lstlisting}

\end{document}


%
\section{Introduction}%
%
\begin{frame}%
\frametitle{Quick Overview}%
\begin{itemize}%
\item Concept of optimization algorithms%
\item<2-> How to \alert<4>{benchmark} optimization algorithms%
\item<3-> How to \alert<4>{evaluate data} obtained from benchmarking and how to compare algorithms%
\item<4-> \alert<4>{The \optimizationBenchmarking\ Framework can help with this!}%
\end{itemize}%
\end{frame}%
%
%
\begin{frame}[t]%
\frametitle{Optimization}%
\begin{itemize}%
\item Many questions in the real world are actually optimization problems\only<2->{, e.g.,\only<-7>{%
\begin{itemize}%
%
\item \only<-5>{Find the \emph{shortest} tour for a salesman to visit certain set of cities\only<-2>{ in China and return to Hefei!}}\only<6->{\alert<6>{Traveling Salesman Problem}\scitep{ABCC2006TTSPACS,LLKS1985TTSPAGTOCO,GP2004TTSPAIV,L2011SGEFTSPIMSS}}%
%
\item<3-> \only<-5>{I need to transport $n$ items from here to another city\only<-3>{ but they are too big to transport them all at once. How can I load them best into my car so that I have to travel back and forth the least times?}}\only<6->{\alert<6>{Bin Packing Problem}\scitep{KSH1995EHFTBPP}}%
%
\item<4-> \only<-5>{Which setting of $x_1$, $x_2$, $x_3$, and $x_4$ can make $(x_1\lor\lnot x_2 \lor x_3)\land(\lnot x_2\lor\lnot x_3 \lor x_4) \land (\lnot x_1\lor\lnot x_3 \lor \lnot x_4)$ become true\only<-4>{ (or, at least, as \emph{many} of its terms as possible)?}}\only<6->{\alert<6>{Maximum (3-)Satisfiability Problem}\scitep{HS2000SAORFROS,TH2004UAIAEEFSAFSAMS,S1978TCOSP,RMK2000EASP}}%
%
\item<5-> \only<-5>{I want to build a large factory with $n$ workshops. I know the flow of material between each two workshops and now need to choose the locations of the workshops such that the overall running cost incurred by material transportation is \emph{minimized}.}\only<6->{\alert<6>{Quadratic Assignment Problem}\scitep{MF1999ACOMATSAACFTQAP,GTD1999ACOQAP}}%
\end{itemize}%
}\only<8->{ the Traveling Salesman Problem\scitep{ABCC2006TTSPACS,LLKS1985TTSPAGTOCO,GP2004TTSPAIV,L2011SGEFTSPIMSS}}%
}%
%
\item<7-> Many optimization problems are \NPHard, meaning that finding the \textcolor<9-11>{green}{best possible solution} will often take \textcolor<9-11>{green}{way too long}.%
%
\item<10-> Of course, it is easy to get \textcolor<10-11>{red}{\emph{some} solutions (usually of bad quality)}%
%
\item<11-> We use metaheuristic optimization algorithms to give us good approximate solutions within acceptable runtime.%
\item<12-> Examples of such algorithms are\only<-22>{ %
Evolutionary Algorithms\scitep{BFM1997EA,CWM2011VOEAFRWA,BFM2000EC1BAAO,BFM2000EC2BAAO,DLJD2000EC,EM1999EC,CDGDMPP1999NIIO,GT2002AIECTAA,WGOEB}\uncover<13->{, %
Ant Colony Optimization\scitep{DMC1996ACO,DS2004ACO,GM2002APBATDOP,ZBMD2004MBSFCOACS,WGOEB}\uncover<14->{, %
Evolution Strategies\scitep{R1965ES,R1973ES,R1994ES,S1965KYASDEFIDS,S1968EOEZDT1,S1975EUNO,WGOEB}\uncover<15->{, %
Differential Evolution\scitep{PSL2005DE,F2006DE,WGOEB}\uncover<16->{, %
Particle Swarm Optimization\scitep{KE1995PSO,C2006PSO,WGOEB}\uncover<17->{, %
Estimation of Distribution Algorithms\scitep{PSL2005DE,F2006DE,MMVRCC2006DE,BZSM2006DE,LZ2000DE,MM2005DE,BVPK2006DE,S2010DEFCFOAABKPARS}\uncover<18->{, %
CMA-ES\scitep{HOG1995ESAD,HO1996AANMDIESTCMA,HO2001ESCMA,HMK2003RTTCOTDESWCMACE,HK2004ETCESOMTF,H2006TCESACR,AH2005ARCESWIPS,AH2005PEOAALSEA}\uncover<19->{, and %
Local Search methods\scitep{HS2005SLSFAA,AL1997LSICO,DBSD2001DOILSA}\uncover<20->{ such as %
Simulated Annealing\scitep{SSF2002FCAIFSA,LA1987SATAA,B1987GAASA,JCS2003HC,KGV1983SA,VC1985SA,DPSW1982MCTICO,DPSW1982MCTICO2,P1970AMCMFTASOCTOCOP,WGOEB}\uncover<21->{ or %
Tabu Search\scitep{G1989TSPI,G1990TSPII,GL1993TABU,DWH1989TSTATAAATNN,BT1994TABU}\uncover<22->{, %
as well as hybrids of local and global search, such as Memetic Algorithms\scitep{M1989MA,M2002MA,MC2003AGITMA,ES2003HWOTMA,HKS2005RAIMA,DM2004MA,RS1994FMA}%
}}}}}}}}}}}\only<23->{\dots\ \alert{many}}%
%
\item<24-> \alert<24>{Which of them is best (for my problem)?}%
\item<25-> \alert<25>{How can I make a good algorithm better (for my problem)?}%
%
\end{itemize}%
~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\~\\%
%
\locateGraphic{2}{width=0.6\paperwidth}{graphics/problem_examples/tsp/tsp}{0.2}{0.29}%
\locateGraphic{3}{width=0.875\paperwidth}{graphics/problem_examples/bin_packing/bin_packing}{0.0625}{0.495}%
\locateGraphic{4}{width=0.55\paperwidth}{graphics/problem_examples/sat/sat}{0.225}{0.5}%
\locateGraphic{5}{width=0.85\paperwidth}{graphics/problem_examples/qap/qap}{0.075}{0.625}%
\locateGraphic{7}{width=0.75\paperwidth}{graphics/exponential_functions/exponential_functions}{0.1625}{0.55}%
%
\locateGraphic{8}{width=0.75\paperwidth}{graphics/optimization_concept/optimization_concept_1}{0.125}{0.53}%
\locateGraphic{9}{width=0.75\paperwidth}{graphics/optimization_concept/optimization_concept_2}{0.125}{0.53}%
\locateGraphic{10}{width=0.75\paperwidth}{graphics/optimization_concept/optimization_concept_3}{0.125}{0.53}%
\locateGraphic{11}{width=0.75\paperwidth}{graphics/optimization_concept/optimization_concept}{0.125}{0.53}%
%
\end{frame}%
%
%
\begin{frame}[t]%
\frametitle{Performance and Anytime Algorithms}%
%
\emph{\inQuotes{We use metaheuristic optimization algorithms to give us \alert<3->{good approximate solutions} within \alert<4->{acceptable runtime}.}}%
%
\uncover<2->{%
\begin{itemize}%
\item Algorithm performance has two dimensions\scitep{NAFR2010RPBBOB2ES,WCTLTCMY2014BOAAOSFFTTSP}:\uncover<3->{ solution quality\uncover<4->{ and required runtime}}%
\only<-9>{%
\item<5-> Anytime Algorithms\scitep{BD1989STDPP2} are optimization methods which maintain an approximate solution at \emph{any time} during their run and iteratively improve this guess.%
\item<6-> All metaheuristics are Anytime Algorithms.%
\item<7-> Several exact methods like Branch-and-Bound\scitep{LMSK1963AAFTTSP,Z1993TBABACSOTATSP,Z1999TAADFBABACSOTATSP} are Anytime Algorithms.%
\item<8-> Consequence: Most optimization algorithms produce approximate solutions of different qualities at different points during their process.%
\item<9-> \alert{Experiments must capture data on the whole runtime behavior!}%
}%
\item<10-> If we just compare \inQuotes{final} results, we may arrive at incomplete \only<12->{or entirely wrong} conclusions%
\end{itemize}%
}%
%
\locateGraphic{3}{width=0.55\paperwidth}{graphics/performance/performance_dimensions/performance_dimensions_1}{0.225}{0.542}%
\locateGraphic{4}{width=0.55\paperwidth}{graphics/performance/performance_dimensions/performance_dimensions_2}{0.225}{0.542}%
\locateGraphic{5,10}{width=0.55\paperwidth}{graphics/performance/performance_dimensions/performance_dimensions}{0.225}{0.542}%
\locateGraphic{11}{width=0.55\paperwidth}{graphics/performance/performance_dimensions/performance_cuts}{0.225}{0.542}%
\locateGraphic{12}{width=0.55\paperwidth}{graphics/problems_with_points/points}{0.225}{0.542}%
\locateGraphic{13}{width=0.55\paperwidth}{graphics/problems_with_points/lines}{0.225}{0.542}%
%
\end{frame}%
%
%
\begin{frame}[t]%
\frametitle{Experimentation Procedure}%
\begin{itemize}%
\item The following experimentation procedure is suitable for optimization and Machine Learning\uncover<2->{:%
\begin{enumerate}%
\item Select a set of (well-known) benchmark instances which covers some \textcolor<18>{red}{different problem features}\only<5->{ \alert{(done)}}\only<3-4>{:%
\begin{itemize}%
%
\only<-3>{%
\item<3-> e.g., \tspLib\expandafter\scitep{\tspLibReferences} for the TSP has instances with different numbers of cities and geometries%
}%
\only<-4>{%
\item<4-> e.g., \bbob\expandafter\scitep{\bbobReferences} offers different benchmark functions for numerical optimization problems%
}%
%
\end{itemize}%
}%
\item<5-> Do experiments\only<11->{ with \textcolor<18>{red}{different algorithms/setups}\only<11->{ \alert{(done)}}}\only<6-10>{:%
\begin{itemize}%
\item several independent runs of algorithm for each benchmark instance%
\item<7-> collect algorithm progress information, e.g., as \emph{\inQuotes{(runtime, best-objective-value-so-far)}} tuples%
\item<8-> one log file per run, each log file has several such tuples%
\item<9-> repeat for different algorithm parameter settings (e.g., different population sizes of an EA)%
\item<10-> repeat with other algorithms for comparison purposes%
\end{itemize}%
}%
\item<12-> Evaluate the gathered data\only<13->{, e.g.:%
\begin{itemize}%
\item \textcolor<17>{green}{draw diagrams of progress of solution quality over time}%
\item<14-> \textcolor<17>{green}{draw diagrams of advanced statistical parameters such as ECDF\scitep{HAFR2012RPBBOBES,HS1998ELVAPAR,TH2004UAIAEEFSAFSAMS,WCTLTCMY2014BOAAOSFFTTSP}\only<15->{ and ERT\scitep{HAFR2012RPBBOBES,WCTLTCMY2014BOAAOSFFTTSP}} (over time)}%
\end{itemize}%
}%
%
\item<16-> But doing this is cumbersome\dots%
\end{enumerate}%
}%
\item<17-> The \optimizationBenchmarking\ framework \textcolor<17>{green}{can automatize} much of the evaluation procedure\uncover<18>{\dots}%
\item<18-> {\dots}and make use of \textcolor<18>{red}{meta-data} about experiments to group and aggregate information.%
\end{itemize}%
%
\locateWithCaption{3}{%
\includegraphics[width=0.925\paperwidth]{graphics/tspLib_features/tspLib_features_symmetric}%
}{%
The relative amounts of the instances of the 110 symmetric instances of \tspLib\expandafter\scitep{\tspLibReferences} according to their features (the 10 asymmetric instances are not plotted).%
}{0.0375}{0.51}{0.925}%
%
\locateWithCaption{4}{%
\includegraphics[width=0.925\paperwidth]{graphics/bbob_features/bbob_features}%
}{%
The relative amounts of \bbob\expandafter\scitep{\bbobReferences} benchmark functions according to their features.%
}{0.0375}{0.51}{0.925}%
%
\locateWithCaption{7-8}{%
\includegraphics[width=0.8\paperwidth]{graphics/tspSuite_logfile_example/tspSuite_logfile_example}%
}{%
Example for data collected in a log file by \tspSuite\expandafter\scitep{\tspSuiteReferences}.%
}{0.0375}{0.53}{0.925}%
%
\locateWithCaption{13-15}{
\strut%
\includegraphics[width=0.28\paperwidth]{graphics/performance/progress_example/progress_example}%
\uncover<14->{%
\strut\hfill\strut%
\includegraphics[width=0.28\paperwidth]{graphics/performance/ecdf_example/ecdf_example}%
\uncover<15->{%
\strut\hfill\strut%
\includegraphics[width=0.28\paperwidth]{graphics/performance/ert_example/ert_example}%
}}\strut%
}{%
Examples for progress\only<14->{ and ECDF}\only<15->{, ERT, and ECDF} diagrams from \tspSuite\expandafter\scitep{\tspSuiteReferences} for different algorithms (signified by different colors) over different sub-sets of the \tspLib\expandafter\scitep{\tspLibReferences} data.%
}{0.0375}{0.545}{0.925}%
%
\end{frame}%


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%

%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage{fancyvrb} % packages needed for verbatim environments

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% --- fancyhdr package for fancy headers ---
\usepackage{fancyhdr}
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[LE,RO]{\thepage}
% Ensure copyright on titlepage (article style) and chapter pages (book style)
\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[C]{{\footnotesize \copyright\ 1999-2018, "Computational Physics I FYS3150/FYS4150":"http://www.uio.no/studier/emner/matnat/fys/FYS3150/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
%  \renewcommand{\footrulewidth}{0mm}
  \renewcommand{\headrulewidth}{0mm}
}
% Ensure copyright on titlepages with \thispagestyle{empty}
\fancypagestyle{empty}{
  \fancyhf{}
  \fancyfoot[C]{{\footnotesize \copyright\ 1999-2018, "Computational Physics I FYS3150/FYS4150":"http://www.uio.no/studier/emner/matnat/fys/FYS3150/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
  \renewcommand{\footrulewidth}{0mm}
  \renewcommand{\headrulewidth}{0mm}
}

\pagestyle{fancy}

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE

\newcommand{\exercisesection}[1]{\subsection*{#1}}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
Project 4, deadline  November 19
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf \href{{http://www.uio.no/studier/emner/matnat/fys/FYS3150/index-eng.html}}{Computational Physics I FYS3150/FYS4150}}
\end{center}

    \begin{center}
% List of all institutions:
\centerline{{\small Department of Physics, University of Oslo, Norway}}
\end{center}

% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Fall semester 2018
\end{center}
% --- end date ---

\vspace{1cm}

\subsection*{Studies of phase transitions in magnetic systems}

\paragraph{Introduction.}
The aim of this project is to study a widely popular model to simulate phase transitions, the so-called Ising model in two dimensions. At a given critical temperature, this model exhbits a phase transition from a magnetic phase (a system with a finite magnetic moment) to a phase with zero magnetization.
This is a so-called binary system where the objects at each lattice site can only take two values. These could be $0$ and $1$ or other values. Here we will use spins pointing up or down as the model for our system. But we could replace the spins with blue and green balls for example.
The \href{{https://en.wikipedia.org/wiki/Ising_model}}{Ising model} has been extremely popular, with applications spanning from studies of phase transitions to simulations in statistics. In one and two dimensions its has analytical solutions to several expectation values and it gives a qualitatively  good underatanding of several types of phase transitions.

In its simplest form
the energy of the Ising model is expressed as, without an externally applied magnetic field,
\[
E=-J\sum_{< kl >}^{N}s_ks_l
\]
with
$s_k=\pm 1$. The quantity $N$ represents the total number of spins and $J$ is a coupling
constant expressing the strength of the interaction between
neighboring spins.  The symbol $<kl>$ indicates that we sum over
nearest neighbors only. We will assume that we have a ferromagnetic
ordering, viz $J> 0$.  We will use periodic boundary conditions and
the Metropolis algorithm only. The material on the Ising model can be found in chapter 13 of the lecture notes. The Metropolis algorithm is discussed in chapter 12.

\textbf{For this project you can collaborate with fellow students but you have to hand in an individual report.}
This project (together with projects 3 and 5) counts 1/3 of the final mark.

\paragraph{Project 4a): A simple $2\times 2$ lattice, analytical expressions.}
Assume we have only two spins in each dimension, that is $L=2$.
Find the analytical expression
for the partition function and the corresponding
expectations values for the energy $E$, the mean absolute value of the magnetic moment $\vert M\vert$ (we will refer to this as the mean magnetization),
the specific heat $C_V$ and the susceptibility $\chi$
as functions of  $T$ using periodic boundary conditions. These results will serve as benchmark calculations for our next steps.

\paragraph{Project 4b): Writing a code for the Ising model.}
Write now a code for the Ising model which computes the mean energy
$E$, mean magnetization
$\vert M\vert$, the specific heat $C_V$ and the susceptibility $\chi$
as functions of  $T$ using periodic boundary conditions for
$L=2$ in the $x$ and $y$ directions.
Compare your results with the expressions from a)
for  a  temperature $T=1.0$ (in units of $kT/J$).

How many Monte Carlo cycles do you need in order to achieve a
good agreeement?

\paragraph{Project 4c): When is the most likely state reached?}
We choose now a square lattice with $L=20$ spins in the $x$ and $y$ directions.

In the previous exercise  we did not study carefully how many Monte Carlo cycles were needed in order to reach the most likely state. Here
we want to perform a study of the time (here it corresponds to the number
of Monte Carlo sweeps of the lattice) one needs before one reaches an equilibrium situation
and can start computing various expectations values. Our
first attempt is a rough and plain graphical
one, where we plot various expectations values as functions of the number of Monte Carlo cycles.

Choose first a temperature of $T=1.0$ (in units of $kT/J$) and study the
mean energy and magnetisation (absolute value) as functions of the number of Monte Carlo cycles. Let the number of Monte Carlo cycles (sweeps per lattice)
represent time.
Use both an ordered (all spins pointing in one direction) and a random
spin orientation as starting configuration.
How many Monte Carlo cycles do you need before you reach an equilibrium situation?
Repeat this analysis for $T=2.4$.
Can you, based on these values estimate an equilibration time?
Make also a plot of the total number of accepted configurations
as function of the total number of Monte Carlo cycles. How does the number of
accepted configurations behave as function of temperature $T$?

\paragraph{Project 4d): Analyzing the probability distribution.}
Compute thereafter the probability
$P(E)$ for the previous system with $L=20$ and the same temperatures, that is at $T=1.0$ and $T=2.4$.
You compute this probability by simply counting the number of times a
given energy appears in your computation. Start the computation after
the steady state situation has been reached.
Compare your results with the computed variance in energy
$\sigma^2_E$ and discuss the behavior you observe.

\paragraph{Studies of phase transitions.}
Near $T_C$ we can characterize the behavior of many physical quantities
by a power law behavior.
As an example, for the Ising class of models,
the mean magnetization is given by
\[
  \langle M(T) \rangle \sim \left(T-T_C\right)^{\beta},
\]
where $\beta=1/8$ is a so-called critical exponent. A similar relation
applies to the heat capacity

\[
  C_V(T) \sim \left|T_C-T\right|^{\alpha},
\]
and the susceptibility
\begin{equation}
  \chi(T) \sim \left|T_C-T\right|^{\gamma},
\end{equation}
with $\alpha = 0$ and $\gamma = 7/4$.
Another important quantity is the correlation length, which is expected
to be of the order of the lattice spacing for $T>> T_C$. Because the spins
become more and more correlated as $T$ approaches $T_C$, the correlation
length increases as we get closer to the critical temperature. The divergent
behavior of $\xi$ near $T_C$
is

\begin{equation}
  \xi(T) \sim \left|T_C-T\right|^{-\nu}.
  \label{eq:xi}
\end{equation}
A second-order phase transition is characterized by a
correlation length which spans the whole system.
Since we are always limited to a finite lattice, $\xi$ will
be proportional with the size of the lattice.
Through so-called finite size scaling relations
it is possible to relate the behavior at finite lattices with the
results for an infinitely large lattice.
The critical temperature scales then as

\begin{equation}
 T_C(L)-T_C(L=\infty) = aL^{-1/\nu},
 \label{eq:tc}
\end{equation}
with  $a$ a constant and  $\nu$ defined in Eq. (\ref{eq:xi}).
We set $T=T_C$ and obtain a mean magnetisation

\begin{equation}
  \langle {\cal M}(T) \rangle \sim \left(T-T_C\right)^{\beta}
  \rightarrow L^{-\beta/\nu},
  \label{eq:scale1}
\end{equation}
a heat capacity

\begin{equation}
  C_V(T) \sim \left|T_C-T\right|^{-\gamma} \rightarrow L^{\alpha/\nu},
  \label{eq:scale2}
\end{equation}
and susceptibility

\begin{equation}
  \chi(T) \sim \left|T_C-T\right|^{-\alpha} \rightarrow L^{\gamma/\nu}.
  \label{eq:scale3}
\end{equation}

\paragraph{Project 4e): Numerical studies of phase transitions.}
We wish to study the behavior of the Ising model
in two dimensions close to the critical temperature as a function of
the lattice size $L\times L$. Calculate the expectation values for
$\langle E\rangle$ and $\langle \vert M\vert \rangle$, the specific heat
$C_V$ and the susceptibility $\chi$ as functions of $T$ for $L=40$,
$L=60$, $L=80$ and $L=100$ for $T\in [2.0,2.3]$ with a step in
temperature $\Delta T=0.05$ or smaller.  You may find it convenient to narrow the domain for $T$.

Plot $\langle E\rangle$,
$\langle \vert M\vert\rangle$, $C_V$ and $\chi$ as functions of $T$. Can
you see an indication of a phase transition?  Use the absolute value
$\langle \vert M\vert\rangle$ when you evaluate $\chi$.  For these production runs you should
parallelize the code using MPI (recommended). Alternatively OpenMP can be used. Use optimization flags when compiling. Perform a timing analysis of some selected runs in order to see that you get an optimal speedup when parallelizing your code.

\paragraph{Project 4f): Extracting the critical temperature.}
Use Eq.~(\ref{eq:tc}) and the exact result
$\nu=1$ in order to estimate $T_C$ in the thermodynamic limit
$L\rightarrow \infty$
using your simulations with $L=40$, $L=60$, $L=80$ and $L=100$
The exact result for the critical temperature (\href{{http://journals.aps.org/pr/abstract/10.1103/PhysRev.65.117}}{after Lars Onsager}) is
$kT_C/J=2/ln(1+\sqrt{2})\approx 2.269$ with $\nu=1$.

\subsection*{Background literature}

If you wish to read more about the Ising model and statistical physics here are three suggestions.

\begin{itemize}
  \item \href{{http://www.worldscientific.com/worldscibooks/10.1142/5660}}{M. Plischke and B. Bergersen}, \emph{Equilibrium Statistical Physics}, World Scientific, see chapters 5 and 6.

  \item \href{{http://www.cambridge.org/no/academic/subjects/physics/computational-science-and-modelling/guide-monte-carlo-simulations-statistical-physics-4th-edition?format=HB}}{D. P. Landau and K. Binder}, \emph{A Guide to Monte Carlo Simulations in Statistical Physics}, Cambridge, see chapters 2,3 and 4.

  \item \href{{https://global.oup.com/academic/product/monte-carlo-methods-in-statistical-physics-9780198517979?cc=no&lang=en&}}{M. E. J. Newman and T. Barkema}, \emph{Monte Carlo Methods in Statistical Physics}, Oxford, see chapters 3 and 4.
\end{itemize}

\noindent
\subsection*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.

\begin{itemize}
  \item Give a short description of the nature of the problem and the eventual  numerical methods you have used.

  \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.

  \item Include the source code of your program. Comment your program properly.

  \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.

  \item Include your results either in figure form or in a table. Remember to        label your results. All tables and figures should have relevant captions        and labels on the axes.

  \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.

  \item Try to give an interpretation of you results in your answers to  the problems.

  \item Critique: if possible include your comments and reflections about the  exercise, whether you felt you learnt something, ideas for improvements and  other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.

  \item Try to establish a practice where you log your work at the  computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember  what a previous test version  of your program did. Here you could also record  the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
\end{itemize}

\noindent
\subsection*{Format for electronic delivery of report and programs}

The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file.  As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:

\begin{itemize}
  \item Use Devilry to hand in your projects, log in  at  \href{{http://devilry.ifi.uio.no}}{\nolinkurl{http://devilry.ifi.uio.no}} with your normal UiO username and password and choose either 'fys3150' or 'fys4150'. There you can load up the files within the deadline.

  \item Upload \textbf{only} the report file!  For the source code file(s) you have developed please provide us with your link to your github domain.  The report file should include all of your discussions and a list of the codes you have developed.  Do not include library files which are available at the course homepage, unless you have made specific changes to them.

  \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parametxers.

  \item In this and all later projects, you should include tests (for example unit tests) of your code(s).

  \item Comments  from us on your projects, approval or not, corrections to be made  etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
\end{itemize}

\noindent
Finally,
we encourage you to work two and two together. Optimal working groups consist of
2-3 students. For this specific report you need to hand in an individual report.

\subsection*{How to install openmpi and/or OpenMP on your PC/laptop}

If you use your own laptop, for linux/ubuntu users, you need to install two packages (alternatively use the synaptic package manager)
\begin{verbatim}
  sudo apt-get install libopenmpi-dev
  sudo apt-get install openmpi-bin
\end{verbatim}
For OS X users, install brew (after having installed xcode and gcc, needed for the
gfortran compiler of openmpi) and then run
\begin{verbatim}
brew install open-mpi
\end{verbatim}
When compiling from the command line, depending on your choice of programming language you need to compile and link as for example
\begin{verbatim}
mpic++ -O3 -o <executable> <programname.cpp>
\end{verbatim}
if you use c++ (alternatively mpicxx) and
\begin{verbatim}
mpif90 -O3 -o <executable> <programname.f90>
\end{verbatim}
if you use Fortran90.

When running an executable, run as
\begin{verbatim}
mpirun -n 10 ./<executable>
\end{verbatim}
where -n indicates the number of processes, 10 here.

With openmpi installed, when using Qt, add to your .pro file the instructions at \href{{http://dragly.org/2012/03/14/developing-mpi-applications-in-qt-creator/}}{Svenn-Arne Dragly's site}

You may need to tell Qt where opempi is stored.

For the machines at the computer lab, openmpi is located  at /usr/lib64/openmpi/bin
Add to your .bashrc file the following
\begin{verbatim}
export PATH=/usr/lib64/openmpi/bin:$PATH
\end{verbatim}
For Windows users we recommend to follow the instructions at the \href{{https://www.open-mpi.org/software/ompi/v1.6/ms-windows.php}}{Open MPI site}.

If you use OpenMP, for linux users, compile and link with for example
\begin{verbatim}
c++ -O3 -fopenmp -o <executable>  <programname.cpp>
\end{verbatim}
For OS X users, you need to install clang-omp using brew, that is
\begin{verbatim}
brew install clang-omp
\end{verbatim}
and then compile and link with for example
\begin{verbatim}
clang-omp++ -O3 -fopenmp -o <executable>  <programname.cpp>
\end{verbatim}

If you program in Fortran and use \textbf{gfortran}, compile as for example
\begin{verbatim}
gfortran -O3 -fopenmp -o <executable>  <programname.f90>
\end{verbatim}
If you have access to Intel's \textbf{ifort} compiler, compile as
\begin{verbatim}
ifort -O3 -fopenmp -o <executable>  <programname.f90>
\end{verbatim}

% ------------------- end of main content ---------------

\end{document}