\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{graphicx,caption}
\graphicspath{ {./images/} }
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[unicode]{hyperref}
\usepackage{amsmath}
\usepackage[shortlabels]{enumitem}

\title{Homework 3 - Theory}
\author{Dainese Fabio, 857661}
\date{March 22, 2020}

\begin{document}

\maketitle

\section{Exercise 1}
    \begin{figure}[H]
        \centering
        \includegraphics[width=0.5\textwidth]{1.png}
        \caption{Graph \(G=(V,E)\)}
        \label{fig:figure-1}
    \end{figure}

    \begin{enumerate}[a)]
        \item The \textit{clique number} of \(G\) is \(w(G) = 3\). This also means that the \textit{chromatic number} (\(c(G)\)) has a lower bound of:
        \begin{align*}
            c(G) &\geq w(G) \\
            c(G) &\geq 3
        \end{align*}

        \item The \textit{max degree} of \(G\) is \(\triangle(G) = max\{d(V) | v \in V\} = 4\). This also means that the \textit{chromatic number} (\(c(G)\)) has a upper bound of:
        \begin{align*}
            c(G) &\leq \triangle(G)+1 \\
            c(G) &\leq 5
        \end{align*}
    \end{enumerate}

    \begin{figure}[H]
        \centering
        \includegraphics[width=0.5\textwidth]{2.png}
        \caption{Graph \(G=(V,E)\)}
        \label{fig:figure-2}
    \end{figure}

    \begin{enumerate}[c)]
        \item The coloring illustrated in the 'Figure \ref{fig:figure-2}' is not a proper 3-colouring of \(G\), since the vertices \(v_{2}\) and \(v_{4}\) are adjacent and with the same color.

        \item The partitions of the vertex set induced by the provided colouring are:
        \begin{align*}
            V_{black} &= \{v_{2},v_{4},v_{5},v_{9},v_{11},v_{15},\} \\
            V_{red} &= \{v_{1},v_{3},v_{7},v_{8},v_{13},v_{14},\} \\
            V_{blue} &= \{v_{6},v_{10},v_{12},v_{16},\} \\
        \end{align*}
    \end{enumerate}

\section{Exercise 2}
    \begin{figure}[H]
        \centering
        \includegraphics[width=\textwidth]{3.png}
        \caption{Multi-layer network}
        \label{fig:figure-3}
    \end{figure}
    The multi-layer network pictured in the 'Figure \ref{fig:figure-3}' has its vertex and edge sets equals to:

    \begin{align*}
        V_{M}=&\{v_{1}=\{1,A\},v_{2}=\{2,A\},v_{3}=\{3,A\},v_{4}=\{5,A\},v_{5}=\{1,B\},v_{6}=\{2,B\},\\
        &v_{7}=\{3,B\},v_{8}=\{4,B\},v_{9}=\{5,B\},v_{10}=\{1,C\},v_{11}=\{2,C\},v_{12}=\{4,C\},\\
        &v_{13}=\{5,C\},v_{14}=\{2,D\},v_{15}=\{3,D\},v_{16}=\{4,D\},v_{17}=\{5,D\}\}
    \end{align*}
    \begin{align*}
        E_{M}=&\{\{v_{1},v_{2}\}, \{v_{2},v_{3}\}, \{v_{3},v_{4}\}, \{v_{1},v_{5}\}, \{v_{7},v_{8}\}, \{v_{9},v_{10}\}, \{v_{10},v_{11}\}, \{v_{12},v_{13}\}, \\ &\{v_{11},v_{14}\}, \{v_{12},v_{16}\}, \{v_{13},v_{17}\}, \{v_{14},v_{15}\}, \{v_{15},v_{16}\}\}
    \end{align*}

    \noindent With that said, it also has the following characteristics:

    \begin{enumerate}[a)]
        \item Intra-layer edge sets:
        \begin{align*}
            E_{A,A}&=\{\{v_{1},v_{2}\}, \{v_{2},v_{3}\}, \{v_{3},v_{4}\}\} \\
            E_{A,B}&=\{\{v_{7},v_{8}\}\} \\
            E_{A,C}&=\{\{v_{10},v_{11}\},\{v_{12},v_{13}\}\} \\
            E_{A,D}&=\{\{v_{14},v_{15}\},\{v_{15},v_{16}\}\} \\ \\
            E_{A}&= E_{A,A} \cup E_{A,B} \cup E_{A,C} \cup E_{A,D} \\
            &= \{\{v_{1},v_{2}\}, \{v_{2},v_{3}\}, \{v_{3},v_{4}\},\{v_{7},v_{8}\},\\ &\quad\quad\{v_{10},v_{11}\},\{v_{12},v_{13}\},\{v_{14},v_{15}\},\{v_{15},v_{16}\}\}
        \end{align*}

        \par\noindent Inter-layer edge sets:
        \begin{align*}
            E_{C,A,B}&=\{\{v_{1},v_{5}\}\} \\
            E_{C,B,C}&=\{\{v_{9},v_{10}\}\} \\
            E_{C,C,D}&=\{\{v_{11},v_{14}\}, \{v_{12},v_{16}\},\{v_{13},v_{17}\}\} \\ \\
            E_{C}&=E_{C,A,B} \cup E_{C,B,C} \cup E_{C,C,D} = E_{M} \setminus E_{A} \\
            &= \{\{v_{1},v_{5}\},\{v_{9},v_{10}\},\{v_{11},v_{14}\}, \{v_{12},v_{16}\}, \{v_{13},v_{17}\}\}
        \end{align*}

        \par\noindent Coupling edge set:
        \begin{align*}
            E_{\widetilde{C},A,B}&=\{\{v_{1},v_{5}\}\} \\
            E_{\widetilde{C},C,D}&=\{\{v_{11},v_{14}\}, \{v_{12},v_{16}\}, \{v_{13},v_{17}\}\} \\ \\
            E_{\widetilde{C}}&=E_{\widetilde{C},A,B} \cup E_{\widetilde{C},C,D} \\ &=\{\{v_{1},v_{5}\},\{v_{11},v_{14}\}, \{v_{12},v_{16}\}, \{v_{13},v_{17}\}\}
        \end{align*}

        \item The provided network is not \textit{fully interconnected} since not all the layers contain all the nodes.

        \item The tensor representation of the network is:
        \begin{align*}
            A_{::,A,A} &=
            \begin{bmatrix}
            0 & 1 & 0 & 0 & 0 \\
            1 & 0 & 1 & 0 & 0 \\
            0 & 1 & 0 & 0 & 1 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,B,B} &=
            \begin{bmatrix}
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 1 & 0 \\
            0 & 0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,C,C} &=
            \begin{bmatrix}
            0 & 1 & 0 & 0 & 0 \\
            1 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 1 \\
            0 & 0 & 0 & 1 & 0 \\
            \end{bmatrix}\\
            A_{::,D,D} &=
            \begin{bmatrix}
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 & 0 \\
            0 & 1 & 0 & 1 & 0 \\
            0 & 0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,A,B} = A_{::,B,A} &=
            \begin{bmatrix}
            1 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,B,C} = A_{::,C,B} &=
            \begin{bmatrix}
            0 & 0 & 0 & 0 & 1 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            1 & 0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,C,D} = A_{::,D,C} &=
            \begin{bmatrix}
            0 & 0 & 0 & 0 & 0 \\
            0 & 1 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 1 & 0 \\
            0 & 0 & 0 & 0 & 1 \\
            \end{bmatrix}
        \end{align*}

        \noindent Just to clarify, the rest of the tensors combinations has not been reported for brevity, since they all are equals to the null matrix.

    \end{enumerate}

\section{Exercise 3}
    \begin{figure}[H]
        \centering
        \includegraphics[width=0.6\textwidth]{4.png}
        \caption{Multi-layer graph}
        \label{fig:figure-4}
    \end{figure}
    \begin{enumerate}[a)]
    \item The multi-layer graph pictured in the 'Figure \ref{fig:figure-4}' has the following tensor representation:
    \begin{align*}
            A_{::,A,A} &=
            \begin{bmatrix}
            0 & 1 & 0 & 0 \\
            1 & 0 & 1 & 0 \\
            0 & 1 & 0 & 1 \\
            0 & 0 & 1 & 0 \\
            \end{bmatrix}\\
            A_{::,B,B} &=
            \begin{bmatrix}
            0 & 1 & 0 & 0 \\
            1 & 0 & 1 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,C,C} &=
            \begin{bmatrix}
            0 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 1 & 0 & 1 \\
            0 & 0 & 1 & 0 \\
            \end{bmatrix}\\
            A_{::,D,D} &=
            \begin{bmatrix}
            0 & 1 & 0 & 0 \\
            1 & 0 & 0 & 0 \\
            0 & 0 & 0 & 1 \\
            0 & 0 & 1 & 0 \\
            \end{bmatrix}\\
            A_{::,A,B} = A_{::,B,A} &=
            \begin{bmatrix}
            1 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
            A_{::,B,C} = A_{::,B,C}&=
            \begin{bmatrix}
            0 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 1 \\
            \end{bmatrix}\\
            A_{::,C,D} = A_{::,D,C} &=
            \begin{bmatrix}
            1 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 \\
            \end{bmatrix}\\
    \end{align*}

    \noindent As before, the rest of the tensors combinations has not been reported for brevity, since they all are equals to the null matrix.

    \item The degree of each node are:
    \begin{align*}
        d_{1} &= (1,1,0,1) \\
        d_{2} &= (2,2,1,1) \\
        d_{3} &= (2,1,2,1) \\
        d_{4} &= (1,0,1,1) \\
    \end{align*}

    \par\noindent Meanwhile the overlapping degree are:
    \begin{align*}
        o_{1} &= 3 \\
        o_{2} &= 6 \\
        o_{3} &= 6 \\
        o_{4} &= 3 \\
    \end{align*}

    \par\noindent Finally by applying the uniform-vector-like eigenvector centrality we obtain:

    \begin{align*}
    \Tilde{A} = A_{::,A,A}^{T} + A_{::,B,B}^{T} + A_{::,C,C}^{T} + A_{::,D,D}^{T} =
        \begin{bmatrix}
            0 & 3 & 0 & 0 \\
            3 & 0 & 3 & 0 \\
            0 & 3 & 0 & 3 \\
            0 & 0 & 3 & 0 \\
        \end{bmatrix}\\
    \end{align*}

    \noindent In which every column, and also every row since it's a symmetric matrix, identifies the eigenvector of the relative node (e.g. first row = first column = eigenvector of \(v_{1}\)).

    \end{enumerate}

\end{document}


% Created 2019-09-05 jue 11:37
\documentclass[letterpaper,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\geometry{top=20mm, bottom=20mm, left=24mm, right=18mm}
\author{Kjartan Halvorsen}
\date{}
\title{Pole-placement exercise}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 25.3.50.2 (Org mode 8.2.10)}}
\begin{document}

\maketitle

\section*{Plot the poles}
\label{sec-1}
\begin{center}
\textbf{s-plane} \hspace*{0.4\linewidth} \textbf{z-plane}\\
\includegraphics[height=0.34\textheight]{../../figures/sgrid-crop} \hspace*{3mm}
\includegraphics[height=0.34\textheight]{../../figures/zgrid-crop}\\
\end{center}

Plot the poles of the following closed-loop discrete-time systems (as crosses in the z-plane). Plot also the corresponding continous-time poles (in the s-plane) using the sampling period \(h=0.2\). Rank the systems from 1 to 5 according to how desirable the performance of each system is.
\begin{description}
\item[{a}] \( G_c(z) = \frac{0.026z + 0.024}{z(z-0.95)}\)
\item[{b}] \( G_c(z) = \frac{0.13z + 0.12}{z^2 - z + 0.25} \)
\item[{c}] \(G_c(z) = \frac{0.54z + 0.52}{(z-0.5)^2 + 0.81}\)
\item[{d}] \(G_c(z) = \frac{0.025z + 0.025}{(z-0.8)^2 - 0.09}\)
\item[{e}] \(G_c(z) = \frac{0.068z + 0.062}{(z-0.8)^2 + 0.09}\)
\end{description}

\newpage

\section*{Pole placement and step response}
\label{sec-2}
Pair each of the discrete-time systems in the previous exercise with the correct step response below.
\begin{center}
\includegraphics[width=\linewidth]{../../figures/closed-loop-step-responsen}
\end{center}
% Emacs 25.3.50.2 (Org mode 8.2.10)
\end{document}


\documentclass[11pt]{article}
\usepackage[
top    = 2.50cm,% presumably you don't want it to be 0pt as well?
bottom = 2.50cm,
left   = 2cm,
right  = 2cm,
marginparsep = 0pt,
marginparwidth=0pt,
]{geometry}

\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage[most]{tcolorbox}
\usepackage{siunitx}
\usetikzlibrary{calc,patterns,angles,quotes}
\usepackage{amsmath}
\usepackage{tikz, tikz-3dplot}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{multicol}
\pagestyle{fancy}
\fancyhead[l]{Waves - Abridged edition}
\fancyhead[r]{Giorgio Grigolo {\textcopyright}}
\newcommand\textcenter[1]{
	\begin{center}
		#1
	\end{center}
}
\begin{document}
	\section{Simmple Harmonic Motion: }
	\subsection{Definition: }
\begin{center}
		The type of oscillatory motion in which the acceleration of the oscillating body is proportinal  to the body's displacement from the equilibrium position and always acts towards the equilibrium position.
\end{center}
	\subsection{Graph: }
	\begin{center}
		{\begin{tikzpicture}[scale=1]
				\begin{axis}[
					x=1cm,y=1cm,
					axis lines=middle,
					ymajorgrids=true,
					xmajorgrids=true,
					xmin=0,
					xmax=12,
					ymin=-3,
					x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
					y label style={at={(axis description cs:-0.1,0.5)},rotate=90,anchor=south},
					xlabel=$t$ time,
					ylabel=$s$ displacement,
					ymax=3,
					xtick={0,1,...,12},
					ytick={-3,-2,...,3},]
					\addplot[color=red, domain=0:12,samples=1000]{2*sin(90*(x+1))};
				\end{axis}
			\end{tikzpicture}
			\captionof*{figure}{}}
	\end{center}
	\subsection{Diagram: }
	\begin{center}
		\begin{tikzpicture}[scale=1.6]
			% save length of g-vector and theta to macros
			\pgfmathsetmacro{\Gvec}{1.5}
			\pgfmathsetmacro{\myAngle}{45}
			% calculate lengths of vector components
			\pgfmathsetmacro{\Gcos}{\Gvec*cos(\myAngle)}
			\pgfmathsetmacro{\Gsin}{\Gvec*sin(\myAngle)}

			\coordinate (centro) at (0,0);
			\draw[dashed,gray,-] (centro) -- ++ (0,-3.5) node (mary) [black,below]{$ $};
			\draw[thick] (centro) -- ++(270+\myAngle:3) coordinate (bob);
			\pic [draw, ->, "$\theta$", angle eccentricity=1.5] {angle = mary--centro--bob};
			\draw [blue,-stealth] (bob) -- ($(bob)!\Gcos cm!(centro)$);
			\draw [-stealth] (bob) -- ($(bob)!-\Gcos cm!(centro)$)
			coordinate (gcos)
			node[midway,above right] {$mg\cos\theta$};
			\draw [-stealth] (bob) -- ($(bob)!\Gsin cm!90:(centro)$)
			coordinate (gsin)
			node[midway,above left] {$mg\sin\theta$};
			\draw [-stealth] (bob) -- ++(0,-\Gvec)
			coordinate (g)
			node[near end,left] {$mg$};
			\pic [draw, ->, "$\theta$", angle eccentricity=1.5] {angle = g--bob--gcos};
			\filldraw [fill=black!40,draw=black] (bob) circle[radius=0.1];
		\end{tikzpicture}
	\end{center}
	\subsection{Equation: }
	\begin{equation}
		a = -\frac{4\pi^2}{T^2} \times x\tag{\si{\meter\per\second\squared}}
	\end{equation}

\begin{center}
	Where $T$ is the \textbf{periodic time} (\si{\second}).
\end{center}

	\section{Phase difference: }
\subsection{\textcolor{blue}{$\frac{T}{4}$}, \textcolor{green}{$\frac{T}{2}$} phase difference: }
	\begin{center}
		\begin{tikzpicture}[scale=1.2]
				\begin{axis}[
					x=1cm,y=1cm,
					axis lines=middle,
					ymajorgrids=true,
					xmajorgrids=true,
					xmin=0,
					xmax=12,
					ymin=-3,
					x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
					y label style={at={(axis description cs:-0.1,0.5)},rotate=90,anchor=south},
					xlabel=$t$ time,
					ylabel=$s$ displacement,
					ymax=3,
					xtick={0,1,...,12},
					ytick={-3,-2,...,3},]
					\addplot[color=red, domain=0:12,samples=1000]{2*sin(80*(x+1))};
					\addplot[color=blue, domain=0:12,samples=1000]{2*sin(80*(x))};
					\addplot[color=green, domain=0:12,samples=1000]{2*sin(80*(x-1))};
				\end{axis}
			\end{tikzpicture}
	\end{center}

\subsection{Full representation of SHM: }
\begin{center}
\begin{tikzpicture}[scale=1.2]
		\begin{axis}[
			x=1cm,y=1cm,
			axis lines=middle,
			ymajorgrids=true,
			xmajorgrids=true,
			xmin=0,
			xmax=12,
			ymin=-3,
			x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
			y label style={at={(axis description cs:-0.1,0.5)},rotate=90,anchor=south},
			xlabel=$t$ time,
			ymax=3,
			xtick={0,1,...,12},
			ytick={-3,-2,...,3},]
			\addplot[color=red, domain=0:12,samples=1000]{2*sin(45*(x))};
			\addplot[color=blue, domain=0:12,samples=1000]{2*sin(45*(-x))};
			\addplot[color=green, domain=0:12,samples=1000]{2*sin(45*(x+2};
		\end{axis}
	\end{tikzpicture}
	\begin{tikzpicture}[
		blacknode/.style={shape=circle, draw=black, line width=2},
		bluenode/.style={shape=circle, draw=blue, line width=2},
		greennode/.style={shape=circle, draw=green, line width=2},
		rednode/.style={shape=circle, draw=red, line width=2}
		]
		\matrix [draw,below left] at (0,0) {
			\node [greennode,label=right:Velocity] {}; \\
			\node [bluenode,label=right:Acceleration] {}; \\
			\node [rednode,label=right:Displacement] {}; \\
		};
	\end{tikzpicture}
\end{center}

\section{$n$\textsuperscript{th} harmonic}

\begin{equation}
	f_n = \frac{n }{2l}\sqrt{\frac{T}{\mu}}
\end{equation}

\begin{center}
	Where $l$ is the \textbf{length} (\si\meter) of the given string, $T$ the \textbf{tension} (\si\newton) present through it and $\mu$ its \textbf{linear mass density} (\si{\kilogram\per\meter}).
\end{center}
\section{Young's Double Slit Experiment}

\begin{center}
	 \begin{tikzpicture}[scale=1.5,every node/.append style={transform shape}]
	 	\foreach \x in {-0.5,-0.25,0} {
	 		\draw (\x,-1) -- (\x,1);
	 	}
	 	\foreach \x in {-0.375,-0.125,-0.125} {
	 		\draw[dashed] (\x,-1) -- (\x,1);
	 	}
	 	\draw[fill=black!10] (0.5,-2,-1) -- (0.5,-2,1) -- (0.5,2,1) -- (0.5,2,-1) -- (0.5,-2,-1);
	 	\fill (0.5,0,0) circle (0.05);
	 	\foreach \r in {0.25,0.5,...,1.75} {
	 		\draw (0.5,0) ++(-60:\r) arc (-60:60:\r);
	 	}
	 	\foreach \r in {0.125,0.375,...,1.875} {
	 		\draw[dashed] (0.5,0) ++(-60:\r) arc (-60:60:\r);
	 	}
	 	\draw[fill=black!10] (2,-2,-1) -- (2,-2,1) -- (2,2,1) -- (2,2,-1) -- (2,-2,-1);
	 	\fill (2,0.5) circle (0.05) (2,-0.5) circle (0.05);
	 	\foreach \r in {0.25,0.5,...,2} {
	 		\draw (2,0.5) ++(-60:\r) arc (-60:60:\r);
	 		\draw (2,-0.5) ++(-60:\r) arc (-60:60:\r);
	 	}
	 	\foreach \r in {0.125,0.375,...,2.125} {
	 		\draw[dashed] (2,0.5) ++(-60:\r) arc (-60:60:\r);
	 		\draw[dashed] (2,-0.5) ++(-60:\r) arc (-60:60:\r);
	 	}
	 	\draw (2,0.5,0.625) -- (2,0.5,0.5);
	 	\draw (2,-0.5,0.625) -- (2,-0.5,0.5);
	 	\draw (2,0.5,0.5) -- (2,-0.5,0.5);
	 	\draw[densely dotted] (2,0.5,0.5) -- (2,0.5,0);
	 	\draw[densely dotted] (2,-0.5,0.5) -- (2,-0.5,0);
	 	\draw[fill=black!10] (4,-2,-1) -- (4,-2,1) -- (4,2,1) -- (4,2,-1) -- (4,-2,-1);
	 	%       LABELLING
	 	\begin{scope}[canvas is yz plane at x=2,rotate=-90]
	 		\node[above] at (0,0.5) {A};
	 		\node[below] at (0,-0.5) {B};
	 		\node[left] at (-0.5,0) {d};
	 	\end{scope}
	 	\begin{scope}[canvas is yz plane at x=0.5,rotate=-90]
	 		\node[below left=-0.1cm] at (0,0) {S${}_0$};
	 	\end{scope}
	 	\begin{scope}[xshift=4cm,yshift=2cm,rotate=-90,canvas is xy plane at z=0]
	 		\fill[white] (0,0) rectangle (4,1);
	 		\begin{axis}[
	 			width=5.575cm,
	 			xmin=-0.62,
	 			xmax=0.62,
	 			ymin=0,
	 			ticks=none
	 			]
	 			\addplot [samples=500,black,smooth
	 			]
	 			{(cos(deg(5*pi*sin(deg(x)))))^(2)*((sin(deg(4*pi*sin(deg(x)))))/(4*pi*sin(deg(x))))^(2)};
	 			\draw[thin, densely dashed,blue] (axis cs:0.1593,0.1327) -- (axis cs:0.1593,0);
	 			\draw[thin, densely dashed,blue] (axis cs:-0.1593,0.1327) -- (axis cs:-0.1593,0);
	 			\draw[thin, densely dashed,blue] (axis cs:0.3941,0.03938) -- (axis cs:0.3941,0);
	 			\draw[thin, densely dashed,blue] (axis cs:-0.3941,0.03938) -- (axis cs:-0.3941,0);
	 		\end{axis}
	 	\end{scope}
	 	\draw[thin,densely dashed,blue] (2,0) -- (6.9,0);
	 	\begin{scope}
	 		\clip (2,-2) rectangle (4,2);
	 		\draw[thin,densely dashed,blue] (2,0) --    +(15:4);
	 		\draw[thin,densely dashed,blue] (2,0) --    +(-15:4);
	 		\draw[thin,densely dashed,blue] (2,0) --    +(32:4);
	 		\draw[thin,densely dashed,blue] (2,0) --    +(-32:4);
	 		\draw[thin,densely dashed,red] (2,0) --     +(8:4);
	 		\draw[thin,densely dashed,red] (2,0) --     +(-8:4);
	 		\draw[thin,densely dashed,red] (2,0) --     +(24:4);
	 		\draw[thin,densely dashed,red] (2,0) --     +(-24:4);
	 	\end{scope}
	 \end{tikzpicture}\\
The observable pattern achieved in this experiment can be seen above. It consists of alternate dark and bright bands. The centreal band, the one equidistant from both slits is always bright ($AO - BO = 0\lambda$)
\begin{multicols}{2}
	destructive interference $\implies$ dark\\
	constructive interference $\implies$ bright
\end{multicols}
\end{center}
\subsection{Path difference}
\begin{multicols}{2}
	\begin{center}
		\textbf{\underline{Bright band}}\\
		~\\
		$n\lambda,\, n \in \mathbb{N}$
	\end{center}
	\begin{center}
	\textbf{\underline{Dark band}}\\
	~\\
	$n\frac12\lambda,\, n \in \mathbb{N}$
\end{center}
\end{multicols}
\subsection{Bright slit interval distance: }
\begin{equation}
	y=\frac{D\lambda}{d}\tag{\si{\meter}}
\end{equation}
\begin{center}
	Where $D$ is the \textbf{distance} (\si{\meter}) between the slits and the screen, $d$ is the \textbf{seperation} ({\si{\meter}}) between the two slits and $\lambda$ the \textbf{wavelength} (\si{\meter}) of the wave at the source.
\end{center}
\end{document}


    \foldertitle{modellang}{Model File Language}{modellang/Contents}

	Model file language is used to write model files. The model files are
plain text files (saved under any filename with any extension) that
describes the model: its equations, variables, parameters, etc. The
model file, on the other hand, does not describe what to do with the
model. To run the tasks you want to perform with the model, you need
first to load the model file into Matlab using the
\href{model/model}{\texttt{model}} function. This function creates a
model object. Then you write your own m-files using Matlab and IRIS
functions to perform the desired tasks with the model object.

Why do all the keywords (except pseudofunctions) start with an
exclamation point? Why do the comments have the same style as in Matlab?
Why do substitutions and steady-state references use the dollar sign?
Because this way, you can get the model files syntax-highlighted in the
Matlab editor. Syntax highlighting improves enormously the readability
of the files, and helps understand the model more quickly. See
\href{setup/Contents}{the setup instructions} for more details.

\paragraph{Variables, parameters, substitutions and
functions}\label{variables-parameters-substitutions-and-functions}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \href{modellang/transitionvariables}{\texttt{!transition\_variables}}
  - List of transition variables.
\item
  \href{modellang/transitionshocks}{\texttt{!transition\_shocks}} - List
  of transition shocks.
\item
  \href{modellang/measurementvariables}{\texttt{!measurement\_variables}}
  - List of measurement variables.
\item
  \href{modellang/measurementshocks}{\texttt{!measurement\_shocks}} -
  List of measurement shocks.
\item
  \href{modellang/exogenousvariables}{\texttt{!exogenous\_variables}} -
  List of exogenous variables.
\item
  \href{modellang/parameters}{\texttt{!parameters}} - List of
  parameters.
\item
  \href{modellang/autoexogenise}{\texttt{!autoexogenise}} - Definition
  of variable/shock pairs for use in autoexogenised simulation plans.
\end{itemize}

\paragraph{Equations}\label{equations}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \href{modellang/transitionequations}{\texttt{!transition\_equations}}
  - Block of transition equations.
\item
  \href{modellang/measurementequations}{\texttt{!measurement\_equations}}
  - Block of measurement equations.
\item
  \href{modellang/dtrends}{\texttt{!dtrends}} - Block of deterministic
  trend equations.
\item
  \href{modellang/links}{\texttt{!links}} - Define dynamic links.
\end{itemize}

\paragraph{Linearised and log-linearised
variables}\label{linearised-and-log-linearised-variables}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \href{modellang/logvariables}{\texttt{!log\_variables}} - List of
  log-linearised variables.
\item
  \href{modellang/allbut}{\texttt{!all\_but}} - Inverse list of
  log-linearised variables.
\item
  \href{modellang/regexpression}{\texttt{\textless{}...\textgreater{}}}
  - Regular expression in log-variable list.
\end{itemize}

\paragraph{Special operators}\label{special-operators}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \href{modellang/sstateversion}{\texttt{!!}} - Steady-state version of
  an equation.
\item
  \href{modellang/ttrend}{\texttt{!ttrend}} - Linear time trend in
  deterministic trend equations.
\item
  \href{modellang/laglead}{\texttt{\{...\}}} - Lag or lead.
\item
  \href{modellang/sstateref}{\texttt{\&}} - Reference to the
  steady-state level of a variable.
\item
  \href{modellang/exactnonlin}{\texttt{=\#}} - Mark an equation for
  exact non-linear simulation.
\item
  \href{modellang/alias}{\texttt{'...!!...'}} - Beginning of aliasing
  inside descriptions and labels.
\end{itemize}

\paragraph{Pseudofunctions}\label{pseudofunctions}

Pseudofunctions do not start with an exclamation point.

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \href{modellang/min}{\texttt{min}} - Define loss function for optimal
  policy.
\item
  \href{modellang/diff}{\texttt{diff}} - First difference
  pseudofunction.
\item
  \href{modellang/dot}{\texttt{dot}} - Gross rate of growth
  pseudofunction.
\item
  \href{modellang/difflog}{\texttt{difflog}} - First log-difference
  pseudofunction.
\item
  \href{modellang/movavg}{\texttt{movavg}} - Moving average
  pseudofunction.
\item
  \href{modellang/movprod}{\texttt{movprod}} - Moving product
  pseudofunction.
\item
  \href{modellang/movsum}{\texttt{movsum}} - Moving sum pseudofunction.
\end{itemize}

\paragraph{Preparser control commands}\label{preparser-control-commands}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \href{modellang/substitutions}{\texttt{!substitutions}} - Define text
  substitutions.
\item
  \href{modellang/pseudosubs}{\texttt{\${[}...{]}\$}} -
  Pseudosubstitutions.
\item
  \href{modellang/import}{\texttt{!import}} - Include the content of
  another model file.
\item
  \href{modellang/export}{\texttt{!export}} - Create a carry-around file
  to be saved on the disk.
\item
  \href{modellang/if}{\texttt{!if...!elseif...!else...!end}} - Choose
  block of code based on logical condition.
\item
  \href{modellang/switch}{\texttt{!switch...!case...!end}} - Switch
  among several cases based on expression.
\item
  \href{modellang/for}{\texttt{!for...!do...!end}} - For loop for
  automated creation of model code.
\item
  \href{modellang/linecomments}{\texttt{\%}} - Line comments.
\item
  \href{modellang/blockcomments}{\texttt{\%\{...\%\}}} - Block comments.
\end{itemize}

\paragraph{Getting on-line help on model file
language}\label{getting-on-line-help-on-model-file-language}

When getting help on model file language, type the names of the keywords
and commands without the exclamation point:

\begin{verbatim}
help modellang
help modellang/keyword
help modellang/command
help modellang/pseudofunction
\end{verbatim}

\paragraph{Matlab functions and user functions in model
files}\label{matlab-functions-and-user-functions-in-model-files}

You can use any of the built-in functions (Matlab functions, functions
within the Toolboxes you have on your computer, and so on). In addition,
you can also use your own functions (written as an m-file) as long as
the m-file is on the Matlab search path or in the current directory.

In your own m-file functions, you can also (optionally) supply the first
derivatives that will be used to compute Taylor expansions when the
model is being solved, and the second derivatives that will be used when
the function occurs in a loss function.

When asked for the derivatives, the function is called with two extra
input arguments on top of that function's regular input arguments. The
first extra input argument is a text string \texttt{'diff'} (indicating
the call to the function is supposed to return a derivative). The second
extra input argument is a number or a vector of two numbers; it
determines with respect to which input argument or arguments the first
derivative or the second derivative is requested.

For instance, your function takes three input arguments,
\texttt{myfunc(x,y,z)}. To be able to supply derivates avoiding thus
numerical differentiation, the function must be written so that the
following three calls

\begin{verbatim}
myfunc(x,y,z,'diff',1)
myfunc(x,y,z,'diff',2)
myfunc(x,y,z,'diff',3)
\end{verbatim}

return the first derivative wrt to the first, second, and third input
argument, respectively, while

\begin{verbatim}
myfunc(x,y,z,'diff',[1,2])
\end{verbatim}

returns the second derivative wrt to the first and second input
arguments. Note that second derivatives are only needed for functions
that occur in an equation defining optimal policy objective,
\href{modellang/min}{min}.

If any of these calls fail, the respective derivative will be simply
evaluated numerically.

\paragraph{Basic rules IRIS model
files}\label{basic-rules-iris-model-files}

\begin{itemize}
\item
  There can be four types of equations in IRIS models: transition
  equations which are simply the endogenous dynamic equations,
  measurement equations which link the model to observables,
  deterministic trend equations which can be added at the top of
  measurement equations, and dynamic links which can be used to link
  some parameters or steady-state values to each other.
\item
  There can be two types of variables and two types of shocks in IRIS
  models: transition variables and shocks, and measurement variables and
  shocks.
\item
  Each model must have at least one transition (aka endogenous) variable
  and one transition equation.
\item
  Each variable, shock, or parameter must be declared in the appropriate
  declaration section.
\item
  The declaration sections and equations sections can be written in any
  order.
\item
  You can have as many declaration sections or equations sections of the
  same kind as you wish in one model file; they all get combined
  together at the time the model is being loaded.
\item
  Transition variables can occur with lags and leads in transition
  equations. Transition variables cannot, though, have leads in
  measurement equations.
\item
  Measurement variables and the shocks cannot have any lags or leads.
\item
  Transition shocks cannot occur in measurement equations, and the
  measurement shocks cannot occur in transition equations.
\item
  Exogenous variables can only occur in dtrends (deterministic trend
  equations), and must be always supplied in the input database to
  commands like \texttt{model/simulate}, \texttt{model/jforecast},
  \texttt{model/filter}, \texttt{model/estimate}, etc. They are not
  returned in the output databases.
\item
  You can choose between linearisation and log-linearisation for each
  individual transition and measurement variable. Shocks are always
  linearised. Exogenous variables must be always introduced so that
  their effect on the respective measurement variable is linear.
\end{itemize}


\section{Nearness functions}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tocloft}
\include{common_symbols_and_format}
\renewcommand{\cfttoctitlefont}{\Large\bfseries}
\begin{document}

\logo

\rulename{Differential Moving Average Momentum}
\tblofcontents
\ruledescription{This trading rules takes the slope, or derivative or momentum of two different price moving averages and subtracts one slope from the other to determine position size. The parameters accepted are the momentum length, the look back length of the short moving average and the look back length of the long moving average.}

\ruleparameters
{Short price average length}{20}{Number of days in the short price
average.}{$\averagelengthshort^{\price}$}
{Long price average length}{100}{Number of additional days in the longer price average (added to the number in the short price average).}{$\averagelengthlong^{\price}$}
{Moving average momentum length}{5}{Number of days in the moving
average slope calculation.}{$M^{\price}$}
\stoptable

\section{Equation}

\begin{equation}
\bigcontribution(\averagelengthshort, \price) = \frac{1}{\averagelengthshort} \sum_{\dummyiterator=0}^{\averagelengthshort} \price_{n}
\end{equation}

\begin{equation}
\bigcontribution(\averagelengthlong, \price) = \frac{1}{\averagelengthlong} \sum_{\dummyiterator=0}^{\averagelengthlong} \price_{n}
\end{equation}

\begin{equation}
\bigcontribution(\bigcontribution(\averagelengthshort, \price), M^{\price}, \currenttime) = \frac
{(\bigcontribution(\averagelengthshort, \price)(t) -
(\bigcontribution(\averagelengthshort, \price)(\currenttime - M^{\price}))}
{M^{\price}}
\end{equation}

\begin{equation}
\bigcontribution(\bigcontribution(\averagelengthlong, \price), M^{\price}, \currenttime) = \frac
{(\bigcontribution(\averagelengthlong, \price)(t) -
(\bigcontribution(\averagelengthlong, \price)(\currenttime - M^{\price}))}
{M^{\price}}
\end{equation}

\begin{equation}
\position(\currenttime) =
\bigcontribution(\bigcontribution(\averagelengthshort, \price), M^{\price}, \currenttime) - \bigcontribution(\bigcontribution(\averagelengthlong, \price), M^{\price}, \currenttime)
\end{equation}

\hspace{200mm}

\noindent where $\position_\currenttime$ is the portfolio allocation at time $\currenttime$ and $\price = \price(\currenttime)$ is the value of the price series.

\hspace{200mm}
\hspace{200mm}

\keyterms

\furtherlinks

\end{document}


\documentclass{article}

\usepackage{mathtools}
\usepackage[margin=0.5in]{geometry}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{float}
\usepackage{multirow}

\setlength{\parindent}{0pt}
\graphicspath{ {./experiment/data/} }

\title{Edge Detection Evaluation of HEp-2 Cells in Fluorescent Images}
\author{Ossama Edbali - ID: 1466610}

\begin{document}

	\maketitle

	\section{Aim}

	This study aims to analyse the results and efficacy of several edge detection algorithms
	on HEp-2 cells.

	The edge detection/segmentation algorithms used are: Otsu, Sobel, Roberts, Canny,
	Canny using anisotropic diffusion,
	Laplacian of Gaussian, Difference of Gaussians and dilate-erode method.

	The evaluation of each method is carried by ROC curves, sensitivity-specificity variation graphs and correspondence analysis.

	\textbf{All the Matlab code and full data can be found here: \url{http://uobcs.github.io/hep2-edge-detection/}.}

	\section{Method}

	First of all the experiments where conducted using three main scripts (one for each
	image):
	\verb|x9343AM_task|, \verb|x10905JL_task| and \verb|x43590AM_task|.

	Each script loads the relative image and true edge image. Then produces a greyscale image using the \texttt{rgb2gray} Matlab function.
	Finally, it performs all the edge detection algorithms described above (delegating
		to the class \texttt{EdgeDetection.m}).
	A pre-analysis (qualitative) of the input has been carried out using the
	background approximation image as a surface to see where illumination varies (using \verb|show_background| function).
	It can be seen that the various input images are the outcome of different fluorescence patterns on	the HEp-2 cells.

	For all edge detectors there is a method inside the \texttt{EdgeDetection} class
	as well as methods for generating the ROC space and specificity and sensitivity
	in function of some parameters (e.g. threshold, sigma, number of iterations).

	For Roberts and Sobel a function \verb|detect_edges(img, filterX, filterY)| was developed which convolves \verb|img| with the two filters and uses
	\verb|magnitude| to produce the final result (before thresholding).

	In regards to LoG, Gaussian smoothing was performed using \verb|gaussian_smoothing(image, sigma)|. Then convolve the smoothed image with the laplacian
	operator and finally find the zero crossings using \verb|edge(res, 'zerocross')|.

	\subsection*{Otsu's method}
	One of the algorithms used in this study is Otsu's algorithm.
	The aim is to find the threshold value where the sum of foreground and background spreads is at its minimum. First of all I calculate the weighted mean and variance
	for both the background and foreground ($\mu_b$, $\sigma_b^2$ and
	$\mu_f$, $\sigma_f^2$). Then I compute the \textbf{within-class variance} (two variances multiplied by their associated weights): $\sigma_W^2 = W_b \sigma_b^2+W_f \sigma_f^2$. I do the same calculation for candidate thresholds and the one that has the lowest within-class variance will be chosen. This algorithm is implemented in Matlab's
	\verb|graythresh|. This will produce a binary image which edges' can be detected
	easily by any of the edge detectors (Sobel in the experiment).

	\subsection*{Dilate-erode method}

	The dilate-erode method is a 4-step algorithm that uses a combination of  morphological operators before using Sobel edge detector. The reason why this method
	has been used is that when Sobel (or Roberts) is performed on the greyscale image, there are some lines of high contrast surrounding
	the actual edge (like noise). The gaps between these small lines and the actual edge
	can be filled using a \textbf{dilate morphological operator} (or non-linear neighbourhood
	operator) with a structuring element (from the \verb|strel| function). Then
	\verb|imfill| has been used to fill the holes inside the cell - this step can
	be skipped but it will result in a lower performance.
	The next step is to "reduce" the cell to get it back to its state before
	dilation using
	the \textbf{erosion} operator. Finally the Sobel filter has been used to detect
	edges.
	There are various ways to create the  morphological operators. Here is the one
	used in this study (erode example using a 5x5 mask): \verb|erode = @(x) min(x(:)); out = nlfilter(in,[5 5],erode)|.

	\subsection*{Canny with anisotropic diffusion (CAD)}

	From the study it has been noted that Canny performed with sensitivity lower than
	0.4 in all input images. To enhance the images but still preserving true edges,
	\textbf{anisotropic diffusion} has been used.
	Anisotropic diffusion is a non-linear diffusion filtering for avoiding the
	blurring problems of Gaussian smoothing (and others). It is an iterative
	process to perform edge-preserving smoothing on the cells.
	The algorithm is described mathematically as follows:

	\begin{center}
	$\frac{\partial}{\partial t}I(x, t) = \nabla \bullet (c(x, t) \nabla I(x, t))$
	\end{center}

	Here $t$ is the iteration step, $c(x, t)$ is a decreasing diffusion function
	of the image gradient magnitude.

	The \verb|anisodiff2D(im, num_iter, delta_t, kappa, option)| function in the codebase
	has been implemented to accomplish anisotropic diffusion. Here \verb|im| is the
	input image, \verb|num_iter| is the number of iterations, \verb|delta_t| is
	the integration constant, \verb|kappa| is the diffusion constant and
	\verb|option| defines which diffusion function to use.
	\newline

	I adopted three evaluation methods in order to assess the accuracy/efficacy of each edge
	detector technique:

	\subsection*{ROC curve}

	The ROC curve has been used to detect which parameter to choose according
	to a \textbf{diagnosis line} (in the experiment
	(0, 1) to (1, 0) has been used). The implementation can be found under
	the \verb|compute_roc(ID, IT)| function, where ID is the image
	with detected edges and \verb|IT| is the image with true edges.
	Basically it takes the two binary images and performs logical operations
	for all possible cases (e.g. true positive, false positive etc\ldots) and
	calculates the sum of "on" pixels in the resulting images. Then it combines
	the results to find sensitivity and specificity:

	\begin{center}
	\verb|sensitivity = TP / (TP + FN)| and \verb|specificity = TN / (TN + FP);|
	\end{center}

	\subsection*{Sensitivity/Specificity variation}

	This evaluation method simply uses the sensitivity and specificity parameters in function
	of a variable (threshold, sigma, kappa or number of iterations). From this we
	can see how different algorithms respond to the variation of some parameters.
	This is implemented by the \verb|roc_params_comparison| static method in the
	\verb|EdgeDetection| class.

	\subsection*{Correspondence analysis (intra-method analysis)}

	From $N$ edge detection results (using the same edge detector) test for
	correspondence as follows: a pixel location identified as an edge by
	all $N$ detector configurations (i.e. changing parameter)
	will have the highest correspondence ($N$), and a
	location identified as an edge by only one detector setup will have the lowest.

	This is computed by the \verb|correspondence_analysis| function in the codebase which
	adds all the input image matrices and, using Matlab's \verb|bar|, plots a bar diagram
	with frequencies for each correspondence level (using \verb|histc|).

	\section{Results}

	A very interesting result is the comparison between Canny and Canny with anisotropic diffusion (using 9343 AM as a reference).

\begin{figure}[htp]

\centering
\includegraphics[width=.3\textwidth]{x9343AM/comparison.png}\hfill
\includegraphics[width=.3\textwidth]{x9343AM/canny/result.png}\hfill
\includegraphics[width=.3\textwidth]{x9343AM/cad/result_15_iterations.png}

\caption{(1) ROC space comparison, (2) Canny, (3) Canny with anisotropic diffusion }
\label{fig:figure3}

\end{figure}

	It can be noted that Canny does not perform very well (sensitivity under 0.4).
	However if we apply anisotropic diffusion,
	sensitivity drastically increases (over 0.8). This happens because the input image
	is very dark at the borders and Canny looses information in the smoothing
	step as well as in the non-maximum suppression step. Supporting this statement
	are the results of applying Canny to 43590 AM (which is very dark compared to
	the other two images and therefore a high smoothing).

	A summary of the whole data using the optimal parameters (\textbf{for the FULL evaluation graphs, tables and image results please visit this site: \url{http://uobcs.github.io/hep2-edge-detection/}}):

\begin{table}[H]
\centering
\caption{Overall results (1: 9343 AM, 2: 10905JL, 3: 43590AM)}
\label{my-label}
\begin{tabular}{|c|c|l|l|}
\hline
\multicolumn{1}{|l|}{Edge detector} & \multicolumn{1}{l|}{Image} & Sensitivity & Specificity \\ \hline
\multirow{3}{*}{Otsu}               & 1                          & 0.9225      & 0.9974      \\ \cline{2-4}
                                    & 2                          & 0.9279      & 0.9957      \\ \cline{2-4}
                                    & 3                          & 0.8813      & 0.9958      \\ \hline
\multirow{3}{*}{Sobel}              & 1                          & 0.8498      & 0.8638      \\ \cline{2-4}
                                    & 2                          & 0.8953      & 0.8852      \\ \cline{2-4}
                                    & 3                          & 0.8195      & 0.8237      \\ \hline
\multirow{3}{*}{Roberts}            & 1                          & 0.8477      & 0.8400      \\ \cline{2-4}
                                    & 2                          & 0.8646      & 0.8779      \\ \cline{2-4}
                                    & 3                          & 0.7540      & 0.8215      \\ \hline
\multirow{3}{*}{Canny}              & 1                          & 0.3404      & 0.9408      \\ \cline{2-4}
                                    & 2                          & 0.3057      & 0.9863      \\ \cline{2-4}
                                    & 3                          & 0.2396      & 0.9808      \\ \hline
\multirow{3}{*}{CAD}                & 1                          & 0.7910      & 0.86651     \\ \cline{2-4}
                                    & 2                          & 0.8139      & 0.9204      \\ \cline{2-4}
                                    & 3                          & 0.6734      & 0.8921      \\ \hline
\multirow{3}{*}{Dilate-Erode}       & 1                          & 0.8299      & 0.8058      \\ \cline{2-4}
                                    & 2                          & 0.8003      & 0.8119      \\ \cline{2-4}
                                    & 3                          & 0.7446      & 0.7863      \\ \hline
\multirow{3}{*}{LoG}                & 1                          & 0.2250      & 0.9419      \\ \cline{2-4}
                                    & 2                          & 0.2135      & 0.9324      \\ \cline{2-4}
                                    & 3                          & 0.1996      & 0.9207      \\ \hline
\multirow{3}{*}{DoG}                & 1                          & 0.2137      & 0.9857      \\ \cline{2-4}
                                    & 2                          & 0.2446      & 0.9941      \\ \cline{2-4}
                                    & 3                          & 0.17301     & 0.99094     \\ \hline
\end{tabular}
\end{table}

\begin{table}[H]
\centering
\caption{Otsu evaluation}
\label{otsu}
\begin{tabular}{@{}llll@{}}
\toprule
Image    & Sensitivity & Specificity & Threshold \\ \midrule
9343 AM  & 0.9225      & 0.9974      & 0.0902    \\
10905 JL & 0.9279      & 0.9957      & 0.1333    \\
43590 AM & 0.8813      & 0.9958      & 0.0510    \\ \bottomrule
\end{tabular}
\end{table}

Overall Otsu has proven to be the best choice in all the images. Although
computationally expensive, Otsu's method takes into account foreground and
background and gives satisfactory results only when the numbers of pixels in each class are close to each other (which is the case here).

Sobel and Roberts have performed almost equally in all images however Sobel has
higher specificity because it is less sensitive to isolated high intensity point variations. Thus it gives correct results when the edge do not exist in a given point.

In regards to the dilate-erode method
we can notice that the sensitivity decreases very fast compared to Sobel (or Roberts). This is because during the erode process some edges might be removed and this propagates to the Sobel edge detection and thresholding.

	\section{Conclusion}

	In this study various alternatives to the traditional edge detectors have been
	tried because of their specific application to cell edge detection. For example
	Canny is very sensitive to the fluorescence around the cells. LoG and DoG have
	low sensitivity (for optimal parameters) because they highlight regions
	of rapid intensity changes but the input images have gradual
	change from the cell to the background (fluorescence effect). Some extensions to
	the edge detectors (such as dilate-erode, adjust and anisotropic diffusion)
	have proven to increase the efficacy of the edge detection.

\end{document}


\documentclass{article}

\usepackage{tikz}
\usepackage{amsthm,amsmath,amssymb}
\usepackage{csquotes}
\usetikzlibrary{automata}
\usetikzlibrary{graphs}

\theoremstyle{definition}
\newtheorem{defn}{Definition}

\begin{document}

\section{Formal Verification of Flexibility in Swarm Robotics}

Microscopic v.s. macroscopic
approach to model checking
swarm robotics.

"The first approach consists of building a model by first creating a corresponding
finite state machine for each robot behavior and then by taking the composition of
all those finite state machines. The second approach consists of building a single
finite state machine containing a state for each different sub-behavior of the robots.
Each state is associated with a counter that keep track of the number of robot
currently in that state."

\section{Transition System Representing a Battle}

\begin{tikzpicture}
    \matrix[row sep=2cm, column sep=1cm]{
        \node (E) {$E$} ; &
        \node (K) {$K$} ; &
        \node (G) {$G$} ; \\
    } ;

    \graph[use existing nodes] {
         E -> [edge label={atk},loop above]
         E ->[edge label={atk}]
         K ->[edge label={atk},loop above]
         K ->[edge label={done}] G ;
    } ;
\end{tikzpicture}

At the beginning of each battle, some number
of robots are assigned to fit enemy $ i $,
which is represented in state E. In state E,
the action "attack" can be taken. This action
will probabilistically result in the defeat
of the enemy, or require additional attacks.

The probability of neutralizing an enemy
is given in the next section.

If the attack succeeds, then the battle transitions
to the "complete" phase (state K), upon which
all robots get redistributed to the other
battles that are being fought (concurrently)!
Furthermore, we must set the base level of the
freshly defeated enemy as 0.

Because we create a product transition system
in which the action "attack" is a handshake action,
we include a dummy "attack" action in state K
that goes to itself, in order to allow other
battles to continue.

Upon the completion of all battles, there is a
"done" action that can be taken (also a handshake action)
that allows all battles to reach
the "goal" state simultaneously, thus
concluding the engagement.

Future extensions: Attacks could probabilistically result
in casualties.

\section{The Role of Probability}

As discussed, the event of defeating some enemy
occurs probabilistically. We have heterogeneous
enemies, which we model by assigning them
"levels". Conceptually, enemies with higher
levels are more difficult to defeat than other
enemies (i.e. the probability of defeating an
enemy in an attack is lower).

However, conceptually it also makes sense that
a higher number of robots attacking the same
enemy would make it more likely that an enemy
is defeated in a round of combat.

Hence, we define the probability of \textbf{not defeating}
an enemy in a round of combat using the following
function of the level of the enemy
(the cumulative distribution function of the
exponential distribution).

$$ f(l_i) = 1 - e^{-\lambda_i l_i} $$

This is motivated by the idea of dynamically adjusting the
probability of not defeating an enemy as there
are more robots fighting it.

$ \mathcal{l}_i $ is the base level of an enemy.
Then, we say that $ \lambda_i = \frac{1}{cn_i + 1} $ is the adjustment
factor, where $ n_i $ is the number of robots
currently fighting enemy $ i $, and $ c $ is a
hyperparameter that describes robot neutralization efficiency.
1 must be added to avoid division by zero problems.

\section{Optimization}

Roughly stated, the ultimate goal is to find the optimal
portioning of robots to minimize the number of rounds of
combat in order to successively neutralize all targets.

\begin{displayquote}

    We have N robots.

    Let $ \mathcal{M} = \{m_1, m_2, \ldots, m_k \} $ be the set of all enemies.

    Further, let L be the bound in $ \mathcal{L} = \{ 1, \ldots, L \} $.

    Our goal is to find a function $ L^\mathcal{M} \to [0,1]^\mathcal{M} $
    such that the expected number of turns to neutralize all enemies
    is minimized.

\end{displayquote}

This function takes ordered tuples of enemies levels (the remaining battles),
and produces a probability distribution
over them that is used to inform the proportions by which the newly unallocated
robots are distributed among the remaining battles.

Because arbitrary functions cannot be described in PRISM, we have assumed
that the distribution of robots over the remaining battles will simply be the weighted distribution
by current adjusted level (what we previously called $ \lambda_i l_i $).

However, we would like to be able to tune the function in order
to optimize how robots are (re)distributed among battles.
For our initial experiment, we choose the function $ g(x) = x^a $,
where $ a $ is a parameter that will be tuned using
simulated annealing (by verifying desired properties repeatedly
using different values of $ a $). This function can be interchanged
with any other function in order to achieve the desired scaling amount
for redistribution.

Thus, we can now define our
function $ L^\mathcal{M} \to [0,1]^\mathcal{M} $ as follows:

$$ f(\langle l_1, \ldots, l_k \rangle) = \frac{g(\langle \lambda_1 l_1, \ldots, \lambda_k l_k \rangle)}{\sum_j^{g(\langle \lambda_j l_j \ldots \lambda_k l_k \rangle)}} i \in \{1, \ldots, M\} $$

We assume that the functions g and f operate element-wise on tuples.

We assume that all of our robots are homogeneous.
However, our enemies are assumed to be heterogeneous
(as defined using our level system).

\end{document}