% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{tfrmmce}
\section*{\hspace*{-1.6cm} tfrmmce}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Minimum mean cross-entropy combination of spectrograms.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
[tfr,t,f] = tfrmmce(x)
[tfr,t,f] = tfrmmce(x,h)
[tfr,t,f] = tfrmmce(x,h,t)
[tfr,t,f] = tfrmmce(x,h,t,N)
[tfr,t,f] = tfrmmce(x,h,t,N,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty tfrmmce} computes the minimum mean cross-entropy combination
        of spectrograms using as windows the columns of the matrix {\ty
        h}. The expression of this distribution writes

\[\Pi_x(t,\nu)=\dfrac{E}{\| \Pi_{k=1}^N |F_x(t,\nu;h_k)|^{2/N}\|_1}\
{\displaystyle \Pi_{k=1}^N} |F_x(t,\nu;h_k)|^{2/N}, \]

where $\|\ \|_1$ denotes the $L_1$ norm, $E$ the energy of the signal\,:
\[E=\int_{-\infty}^{+\infty} |x(t)|^2\ dt=\iint_{-\infty}^{+\infty}
\Pi_x(t,\nu)\ dt\ d\nu=\|\Pi_x(t,\nu)\|_1,\] and $F_x(t,\nu;h_k)$ the
short-time Fourier transform of $x$, with analysis window $h_k(t)$.\\

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}
Name & Description & Default value\\
\hline
        {\ty x}     & signal ({\ty Nx=length(x)})\\
        {\ty h}     & frequency smoothing windows, the {\ty h(:,i)} being normalized
                so as to be of unit energy\\
        {\ty t}     & time instant(s)          & {\ty (1:Nx)}\\
        {\ty  N}    & number of frequency bins & {\ty Nx}\\
        {\ty trace} & if nonzero, the progression of the algorithm is shown
                                         & {\ty 0}\\
     \hline {\ty tfr}   & time-frequency representation \\
        {\ty f}     & vector of normalized frequencies\\

\hline
\end{tabular*}
\vspace*{.2cm}

When called without output arguments, {\ty tfrmmce} runs {\ty tfrqview}.
\end{minipage}

\newpage

{\bf \large \sf Example}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Here is a combination of three spectrograms with gaussian analysis windows
of different lengths :
\begin{verbatim}
         sig=fmlin(128,0.1,0.4); h=zeros(19,3);
         h(10+(-5:5),1)=window(11);
         h(10+(-7:7),2)=window(15);
         h(10+(-9:9),3)=window(19);
         tfrmmce(sig,h);
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
all the {\ty tfr*} functions.
\end{minipage}
\vspace*{.2cm}

{\bf \large \sf Reference}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] P. Loughlin, J. Pitton, B. Hannaford ``Approximating Time-Frequency
Density Functions via Optimal Combinations of Spectrograms'' IEEE Signal
Processing Letters, Vol. 1, No. 12, Dec. 1994.
\end{minipage}


\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{listings}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
%If you want to title your bold things something different just make another thing exactly like this but replace "problem" with the name of the thing you want, like theorem or lemma or whatever

\begin{document}

%\renewcommand{\qedsymbol}{\filledbox}
%Good resources for looking up how to do stuff:
%Binary operators: http://www.access2science.com/latex/Binary.html
%General help: http://en.wikibooks.org/wiki/LaTeX/Mathematics
%Or just google stuff

\title{Assignment 2\\ MEEN 357}
\author{Jacob Hartzer}
\maketitle

\section*{Task 5}
\begin{problem}{i}
What is the range of a 9-bit unsigned integer?\\

The range is from 0 to $2^9-1$ or \bf{0 to 511}.
\end{problem}

\begin{problem}{ii}
What is the range of a 9-bit signed integer? \\

The range is from $-2^8 to 2^8-1$ or \bf{-256 to 255}
\end{problem}

\begin{problem}{iii}
What is the binary representation of decimal 125 as a 9-bit unsigned integer? \\

I derived this by finding the largest power of 2 less than the original number and then subtracting and repeating. This processes looked like this: $125 - 2^6 = 61$. $61 - 2^5 = 29$. And so on. Then, I filled in each digit appropriately where if I used that power, the digit would be a 1.  \bf{001111101}
\end{problem}

\begin{problem}{iv}
What is the binary representation of decimal 125 as a 9-bit signed integer?\\

For a nine-bit signed integer, since the number is less than $2^8$ and positive, the answer remains the same: \bf{001111101}
\end{problem}

\begin{problem}{v}
What is the binary representation of decimal -125 as a 9-bit signed integer?\\

To obtain the negative counterpart, I found the 1’s complement and then added one. This gave an answer of: \bf{110000011}
\end{problem}
\end{document}


\section{The Rarita-Schwinger Field}
\begin{frame}
	\frametitle{The Spinor of the Rarita-Schwinger Field}
	Idea: Combine spin 1 $A^\mu$ and the spin $\sfrac{1}{2}$ Dirac spinor $\Psi$ into $\Psi^\mu$.
	It transforms according to the
	\begin{align*}
		(\sfrac{1}{2}, \sfrac{1}{2})\otimes\l[(\sfrac{1}{2}, 0)\oplus(0, \sfrac{1}{2})\r] =
		(\sfrac{1}{2}, 1)\oplus(\sfrac{1}{2}, 0)\oplus(1, \sfrac{1}{2})\oplus(0, \sfrac{1}{2})
	\end{align*}
	\pause
	To eliminate the Dirac component, we require
	\begin{align*}
		\gamma_\mu \Psi^\mu = 0
	\end{align*}
	which transforms like a Dirac spinor. (Remember: $\gamma_\mu$ does not transform)
	\pause
	Rarita-Schwinger-Equation
	\footnote{Solutions in the RF are in the appendix}:
	\begin{align*}
		\l(i\slashed{\partial} - m\r)\Psi^\mu = 0
	\end{align*}
\end{frame}
\begin{frame}
	\frametitle{Properties of the Rarita-Schwinger equation}
	Using $\{\gamma^\mu, \gamma^\nu\}_+=2g^{\mu\nu}\symbb{1}_4$:
	\begin{equation*}
		\l .
		\begin{aligned}
			\gamma_\mu \Psi^\mu                       & = 0 \\
			\l(i\gamma^\nu\partial_\nu - m\r)\Psi^\mu & = 0
		\end{aligned}
		\r \rbrace
		\l(-i\gamma^\nu\partial_\nu\gamma_\mu+2i \partial_\nu g_{\ \mu}^\nu - m\gamma_\mu\r)\Psi^\mu
		= 2i \partial_\mu \Psi^\mu
		= 0
		\Rightarrow
		\quad\partial_\mu \Psi^\mu = 0
	\end{equation*}
	\pause
	These equations impose each 4 conditions on the RS-Spinor giving
	\begin{equation*}
		4\times4-2\times4 = 16-8 = 8 \text{ degrees of freedom }=
		\l \lbrace
		\begin{aligned}
			\text{Particle: } s     & =-\sfrac{3}{2},-\sfrac{1}{2},\sfrac{1}{2},\sfrac{3}{2} \\
			\text{Antiparticle: } s & =-\sfrac{3}{2},-\sfrac{1}{2},\sfrac{1}{2},\sfrac{3}{2}
		\end{aligned}\r .
	\end{equation*}
\end{frame}
\begin{frame}
	\frametitle{Lagrangian}
	\begin{equation*}
		\symcal{L} = \frac{1}{2}\overline\Psi_\nu\l(-\epsilon^{\nu\mu\kappa\lambda}\gamma_5\gamma_\mu\partial_\kappa+\frac{1}{2}m[\gamma^\nu, \gamma^\lambda]\r)\Psi_\lambda
		\text{\footnotemark[1]}
	\end{equation*}
	\footnotetext[1]{Full derivation:\fullcite[334]{weinberg2005quantum}}
	\pause
	Getting back the field equations:
	\begin{align*}
		\frac{\delta \symcal{L}}{\delta \overline\Psi_\nu}=0=
		\l(-\epsilon^{\nu\mu\kappa\lambda}\gamma_5\gamma_\mu\partial_\kappa+\frac{1}{2}m[\gamma^\nu, \gamma^\lambda]\r)\Psi_\lambda
		= T^\nu
	\end{align*}
	\pause
	\begin{align*}
		\overset{\partial_\nu T^\nu}{\Rightarrow}
		[\slashed{\partial},\gamma^\lambda]\Psi_\lambda=0 \qquad
		\overset{\gamma_\nu T^\nu}{\Rightarrow}
		3m\gamma^\lambda \Psi_\lambda = \epsilon^{\nu\mu\kappa\lambda}\gamma_5\gamma_\nu\gamma_\mu\partial_\kappa\Psi_\lambda = i[\slashed \partial, \gamma^\lambda]\Psi_\lambda = 0 \\
		\Rightarrow \partial_{\lambda}\Psi^\lambda = \frac{1}{2}\l\{\slashed \partial, \gamma_\lambda \r\} \Psi^\lambda = \frac{1}{2}[\slashed \partial, \gamma_\lambda]\Psi^\lambda = 0
	\end{align*}
	Using
	\begin{equation*}
		\gamma^\mu\gamma^\nu\gamma^\rho = \eta^{\mu\nu}\gamma^\rho + \eta^{\nu\rho}\gamma^\mu - \eta^{\mu\rho}\gamma^\nu - i\epsilon^{\sigma\mu\nu\rho}\gamma_\sigma\gamma^5
	\end{equation*}
\end{frame}
\begin{frame}
	\frametitle{Lagrangian}
	\begin{align*}
	    0 =	\l(-\epsilon^{\nu\mu\kappa\lambda}\gamma_5\gamma_\mu\partial_\lambda+\frac{1}{2}m[\gamma^\nu, \gamma^\lambda]\r)\Psi_\lambda \\
		\gamma_\lambda\Psi^\lambda = 0 \qquad \partial_\lambda\Psi^\lambda = 0\\
	\end{align*}
	\pause
	\begin{align*}
		-\frac{1}{2}\gamma^\lambda\gamma^\nu \Psi_\lambda
		= -m\Psi^\nu
		= - \epsilon^{\mu\nu\kappa\lambda}\gamma_5\gamma_\mu\partial_\kappa \Psi_\lambda
		= -i\l(\gamma^\nu\gamma^\kappa\gamma^\lambda-g^{\nu\kappa}\gamma^\lambda-g^{\kappa\lambda}\gamma^\nu+g^{\nu\lambda}\gamma^\kappa\r)\partial_\kappa\Psi_{\lambda}
		= -i\slashed \partial \Psi^\nu\\
	\end{align*}
	\pause
	\centering
	\alert{
	With this lagrangian we arrive at the correct field equations:
	\begin{align*}
		\Rightarrow (i\slashed \partial-m)\Psi^\nu = 0
	\end{align*}}
\end{frame}
\begin{frame}
	\frametitle{But wait! Why don't we use $(\sfrac{3}{2}, 0)\oplus(0, \sfrac{3}{2})$?}
	\begin{itemize}
	\item Weinberg did the calculations in 1964\footnote{\fullcite{weinberg1964feynman}} to get an 8-Spinor
	\item \enquote{Intricate} calculations\footnotemark[2]
		\item Requires a generalised set of $\gamma$-matrices
	\end{itemize}
	\footnotetext[2]{Detailed discussion of ATS: \fullcite{pure}}
	\pause
	The antisymmetric Tensor-Spinor (ATS) is sometimes used
	\begin{equation*}
		\l[\l(1, 0\r)\oplus\l(0,1\r)\r]\otimes\l[\l(\sfrac{1}{2}, 0\r)\oplus\l(0,\sfrac{1}{2}\r)\r]
		=\l[\l(\sfrac{1}{2}, 0\r)\oplus\l(0,\sfrac{1}{2}\r)\r]\oplus\l[\l(\sfrac{3}{2}, 0\r)\oplus\l(0,\sfrac{3}{2}\r)\r]
		\oplus\l[\l(\sfrac{1}{2}, 1\r)\oplus\l(1,\sfrac{1}{2}\r)\r]
	\end{equation*}
	$\Rightarrow\Psi^{\mu\nu}=-\Psi^{\nu\mu}$ and the unphysical components are removed with $\gamma_\mu\Psi^{\mu\nu}=0$.
	\begin{itemize}
		\item Degrees of freedom$=6\times 4-4\times 4=8$
		\item Propagator has also (more on that later) problems in discribing $\Delta$ resonances
		\item Detailed discussion in 2
	\end{itemize}
	\vspace{1em}
\end{frame}


\section{Laboratory Methods}
This section is the most vague of all the PGRE topics.
I put information down that helped me, but please contact me if you notice a glaring omission or know more about this than I do (very likely).

\subsection{Dimensional Analysis}
Know how to deduce if a solution has the correct units.\\*
Also understand if a solution is reasonable (i.e. make sure the velocity you calculated is less than or equal to the speed of light).

\subsection{Poisson Distribution}
Also called the law of small numbers.\\\\*
\(\displaystyle p(k)=\frac{\lambda^k}{k!e^{\lambda}}\)\\*
\(\lambda\) is the rate at which the (rare) event occurs\\\\*
The mean and variance of the distribution are the same.
\begin{itemize}
\item The Poisson distribution describes mutually independent events, occurring at a known and constant rate (\(\lambda\)) per unit (time or space), and observed through a certain window: a unit of time or space
\item The probability of \(k\) occurrences in that unit can be calculated from \(p(k)\)
\item The rate is also the expected or most likely outcome (for whole number \(\lambda\) greater than 1, the outcome corresponding to \(\lambda-1\) is equally likely)
\end{itemize}
(This information was taken from the University of Massachusetts Amherst website on statistics.)

\subsection{Oscilloscopes}
Know how to read and interpret output from an oscilloscope including Lissajous curves.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written By Michael Brodskiy
% Class: Analytic Geometry & Calculus III (Math-292)
% Professor: V. Cherkassky
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[12pt]{article}
\usepackage{alphalph}
\usepackage[utf8]{inputenc}
\usepackage[russian,english]{babel}
\usepackage{titling}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage[super]{nth}
\usepackage{everysel}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{fancyhdr}
\geometry{top=1.0in,bottom=1.0in,left=1.0in,right=1.0in}
\newcommand{\subtitle}[1]{%
  \posttitle{%
    \par\end{center}
    \begin{center}\large#1\end{center}
    \vskip0.5em}%

}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=blue,
citecolor=blue,
}

\urlstyle{same}

\title{Lecture XVIII Notes}
\date{\today}
\author{Michael Brodskiy\\ \small Professor: V. Cherkassky}

% Mathematical Operations:

% Sum: $$\sum_{n=a}^{b} f(x) $$
% Integral: $$\int_{lower}^{upper} f(x) dx$$
% Limit: $$\lim_{x\to\infty} f(x)$$

\begin{document}

\maketitle

\section{Triple Integrals $-$ 15.6}

Given a region $B$ where:

$$B=\{(x,y,z)|a\leq x\leq b, c\leq y\leq d, r\leq z\leq s\}$$

If this region is filled with many smaller boxes, or sub-boxes, the triple Riemann sum would look as such:

$$\sum_{i=1}^l\sum_{j=1}^m\sum_{k=1}^n f(x_{ijk}^*,y_{ijk}^*,z_{ijk}^*)\,\Delta V$$

To form an integral, this triple Riemann must approach infiinty:

$$\iiint_B f(x,y,z)\,dV=\lim_{(l,m,n)\to\infty}\sum_{i=1}^l\sum_{j=1}^m\sum_{k=1}^n f(x_{ijk}^*,y_{ijk}^*,z_{ijk}^*)\,\Delta V$$

Furthermore, Fubini's Theorem, which was applied to double integrals, may be applied to triple integrals, if $f$ is continuous on $B=[a,b]\text{ x }[c,d]\text{ x }[r,s]$:

$$\iiint_B f(x,y,z)\,dV=\int_a^b\int_r^s\int_c^df(x,y,z)\,dy\,dz\,dx$$

\flushleft{
\textit{Example:}
Evaluate the following triple integral along $B=\{(x,y,z)|0\leq x\leq1, -1\leq y\leq2,0\leq z\leq3\}$:\\
}
$$\iiint_B xyz^2\,dV$$
$$\int_0^1\int_{-1}^2\int_0^3 xyz^2\,dz\,dy\,dx$$
$$\int_0^1\int_{-1}^2 3xy\,dy\,dx$$
$$\int_0^1\frac{27x}{2}\,dx$$
$$\frac{27x^2}{4}\Big|_0^1=\frac{27}{4}$$

\subsection{Triple Integrals over General Regions}

A Type I general region is defined by $E$, where:

$$E=\{(x,y,z)|(x,y)\in D, u_1(x,y)\leq z\leq u_2(x,y)\}$$

These boundaries result in the following Integral:

$$\iiint_E f(x,y,z)\,dV$$

This may be simplified, using Fubini's Theorem, to form the following:

$$\iiint_E f(x,y,z)\,dV= \iint_D \left[\int_{u_1(x,y)}^{u_2(x,y)}f(x,y,z)\,dz\right]\,dA$$

A more complicated region is formed when $D$ and $E$ are Type I regions, which means: $E=\{(x,y,z)|a\leq x\leq b, g_1(x)\leq y\leq g_2(x), u_1(x,y)\leq z\leq u_2(x,y)\}

This yields the triple integral:

$$\iiint_Ef(x,y,z)\,dV=\int_a^b\int_{g_1(x)}^{g_2(x)}\int_{u_1(x,y)}^{u_2(x,y)}f(x,y,z)\,dz\,dy\,dx$$

If $D$ is a Type II region, while $E$ is Type I, this results in:

$$\iiint_Ef(x,y,z)\,dV=\int_c^d\int_{h_1(y)}^{h_2(y)}\int_{u_1(x,y)}^{u_2(x,y)}f(x,y,z)\,dz\,dx\,dy$$

Region $E$ is a Type II region when $E=\{(x,y,z)|(y,z)\in D,u_1(y,z)\leq x\leq u_2(y,z)$

  $$\iiint_E f(x,y,z)\,dV= \iint_D \left[\int_{u_1(y,z)}^{u_2(y,z)}f(x,y,z)\,dx\right]\,dA$$

  Finally, region $E$ is Type III if $E=\{(x,y,z)|(x,z)\in D,u_1(x,z)\leq y\leq u_2(x,z)$

This forms the integral:

  $$\iiint_E f(x,y,z)\,dV= \iint_D \left[\int_{u_1(x,z)}^{u_2(x,z)}f(x,y,z)\,dy\right]\,dA$$

  Much like in double integrals, a function's mass, moments, and center of mass may be determined through triple integration. The formulas are as follows:
For mass:
  $$m=\iiint_E \rho(x,y,z)\,dV$$
For the moments about the three coordinate planes:
  $$ M_{yz} = \iiint_E x\rho(x,y,z)\,dV\,\,\,\,\,M_{xz}=\iiint_E y\rho(x,y,z)\,dV$$
  $$M_{xy}=\iiint_E z\rho(x,y,z)\,dV$$
The center of mass at $(\overline{x},\overline{y},\overline{z})$
$$\overline{x}=\frac{M_{yz}}{m}\,\,\,\overline{y}=\frac{M_{xz}}{m}\,\,\,\overline{z}=\frac{M_{xy}}{m}$$
Finally, the moment of inertia formulas are:
$$I_x=\iiint_E (y^2+z^2)\rho(x,y,z)\,dV$$
$$I_y=\iiint_E (x^2+z^2)\rho(x,y,z)\,dV$$
$$I_z=\iiint_E (x^2+y^2)\rho(x,y,z)\,dV$$

\subsection{Change of Variables in Triple Integrals}

In three dimensions, a change of variables revolves around the Jacobian. The Jacobian of a transformation where $x=g(u,v)$ and $y=h(u,v)$ looks as follows:

$$\frac{\partial(x,y)}{\partial(u,v)}=\Large{\begin{vmatrix} \frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} \\ \frac{\partial y}{\partial u} & \frac{\partial y}{\partial v}\\ \end{vmatrix}}=\frac{\partial x}{\partial u}\frac{\partial y}{\partial v} - \frac{\partial x}{\partial v}\frac{\partial y}{\partial u}$$

In a double integral, this change of variables would result in the integrand being multiplied by the Jacobian:

$$\iint_R f(x,y)\,dA = \iint_S f(x(u,v),y(u,v)) \Big{|}\frac{\partial(x,y)}{\partial(u,v)}\Big{|}\,du\,dv$$

\end{document}


%!TEX root = main.tex
\section{Results}
\subsection{With and without Olympic Games}
Choosing infection rate $\beta=2$, removal rate $\gamma=0.5$ and an transfer probability $p_{transfer} = 0.005$ we can run a simulation with and without the Olympic Games occurring. We start the simulation at the first day of the games in Rio De Janeiro and set the initial infected population in Rio to 1000. In the following we will look at the SIR curves of 6 major cities.

With the Olympics occurring we get the following curves:
\begin{figure}[H]
	\centering
	\includegraphics[width=1.0 \linewidth]{plots/rio-0-18-380000.pdf}
	\caption{10 simulations with Olympic Games. Time in days on the x-axis and number of people on the y-axis. Shown is susceptible (S), infected (I), removed (R) and total population (T).}
	\label{fig:rio-0-18-380000}
\end{figure}

From figure \ref{fig:rio-0-18-380000} it's seen that except for Rio where the infection started and New York which seems to be infected earliest, the other major cities all seem to reach its infection peak at approximately the same time.

\begin{figure}[H]
	\centering
	\includegraphics[width=1.0 \linewidth]{plots/no_rio.pdf}
	\caption{10 simulations without Olympic Games. Time in days on the x-axis and number of people on the y-axis. Shown is susceptible (S), infected (I), removed (R) and total population (T).}
	\label{fig:no_rio}
\end{figure}

When there is no Olympic Games, as seen in figure \ref{fig:no_rio}, the infection peaks occur later, especially for Moscow, Beijing and Sydney. The is emphasized in the summary table \ref{table:olympic-summary}.

\begin{table}[H]
	\centering
	\input{tables/result}
	\caption{Results of 10 simulations with and without Olympic Games. Table contains the peak times and amounts for the number of infected individuals. The standard $95\%$-confidence interval is marked with $\pm$ and the confidence interval using control variates is shown in the parenthesis.}
	\label{table:olympic-summary}
\end{table}

As mentioned, in table \ref{table:olympic-summary} one can see that when the Olympic Games occur the peak time is much less spread and generally happens earlier. This is particularly apparent when comparing with the global peak time, which in the case without Olympic Games, happens statistically significantly later than the shown cities. However, in the Olympic Games case, the city peak times are not statistical different from the global peak time (except for the New York and Rio).

The fact that Rio doesn't have a significantly difference in peak time makes sense because this is where the infection starts. Adding 380000 people (out of 12 million people) doesn't make much of a difference. The New York case is also interesting as there isn't a significant change. This is likely because New York being in north America and Rio being in South America is much more closely connected through airlines, compared to cities which are across the Pacific or Atlantic Ocean.

Using control variates generally appear to improve the variance, up to a factor of two in some cases, which seams reasonable. In some cases the control variate confidence interval is larger compared to crude confidence interval. This is because there is less degree of freedom when estimating the variance, which is a result of the extra parameter estimation of $c$. Thus if the control variates aren't sufficiently correlated, the variance of the estimate won't improve.

Finally table \ref{table:olympic-summary} also shows that the number of people infected globally is almost twice as big when including the Olympic Games compared to not including the Olympic Games.

\subsection{Visualization of result}
When studying a virus outbreak it is interesting to see exactly how the virus spreads. We have thus created an animation on a world map where each region is represented as a dot. Each dot is placed at the region center (airport), the dot size is scaled according to the population size, and the color represents the fraction infected.

\begin{figure}[H]
	\centering
	\includegraphics[width=1.0 \linewidth]{plots/gifs/frames/rio-46}
	\caption{Timestep 46, with Olympic Games. The full animation can be viewed at
		\url{https://andreasmadsen.github.io/course-02443-stochastic-virus-outbreaks/}}
	\label{fig:rio-46}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=1.0 \linewidth]{plots/gifs/frames/noRio-67}
	\caption{Timestep 67, without Olympic Games. The full animation can be viewed at
		\url{https://andreasmadsen.github.io/course-02443-stochastic-virus-outbreaks/}}
	\label{fig:noRio-67}
\end{figure}

Animations based on simulations with the Olympic Games shows a high activation across the global at the same time. In simulations without the games it is much more apparent how the virus first spread to regions in the following order:
\begin{enumerate}
	\item South and Latin America
	\item East coast of the USA and then Europe
	\item Africa
	\item Asia
	\item Australia
\end{enumerate}

This ordering is sensible because some regions are more connected than others. E.g. when we start the virus outbreak in Rio de Janeiro, but don't hold the Olympics, the virus naturally first spreads to nearby regions and to regions with which a lot of plane traffic is shared.


%!TEX root = da2020-06.tex

\Chapter{6}{Randomized Algorithms}

\noindent
All models of computing that we have studied so far were based on the formalism that we introduced in Chapter~\chapterref{3}: a distributed algorithm $A$ is a state machine whose state transitions are determined by functions $\Init_{A,d}$, $\Send_{A,d}$, and $\Receive_{A,d}$. Everything has been fully deterministic: for a given network and a given input, the algorithm will always produce the same output. In this chapter, we will extend the model so that we can study randomized distributed algorithms.

\section{Definitions}\label{sec:randomized}

Let us first define a \emph{randomized distributed algorithms in the $\PN$ model} or, in brief, a \emph{randomized $\PN$ algorithm}. We extend the definitions of Section~\longref{3.3}{sec:distr-alg} so that the state transitions are chosen randomly according to some probability distribution that may depend on the current state and incoming messages.

More formally, the values of the functions $\Init$ and $\Receive$ are discrete probability distributions over $\States_A$. The initial state of a node $u$ is a random variable $x_0(u)$ chosen from a discrete probability distribution \[\Init_{A,d}(f(u))\] that may depend on the local input $f(u)$. The state at time $t$ is a random variable $x_t(u)$ chosen from a discrete probability distribution \[\Receive_{A,d}\bigl(x_{t-1}(u), m_t(u) \bigr)\] that may depend on the previous state $x_{t-1}(u)$ and on the incoming messages $m_t(u)$. All other parts of the model are as before. In particular, function $\Send_{A,d}$ is deterministic.

Above we have defined randomized $\PN$ algorithms. We can now extend the definitions in a natural manner to define randomized algorithms in the $\LOCAL$ model (add unique identifiers) and randomized algorithms in the $\CONGEST$ model (add unique identifiers and limit the size of the messages).

\section{Probabilistic Analysis}

In randomized algorithms, performance guarantees are typically probabilistic. For example, we may claim that algorithm $A$ \emph{stops in time $T$ with probability $p$}.

Note that all probabilities here are over the random choices in the state transitions. We do not assume that our network or the local inputs are chosen randomly; we still require that the algorithm performs well with worst-case inputs. For example, if we claim that algorithm $A$ solves problem $\Pi$ on graph family $\calF$ in time $T(n)$ with probability $p$, then we can take \emph{any} graph $G \in \calF$ and \emph{any} port-numbered network $N$ with $G$ as its underlying graph, and we guarantee that with probability at least $p$ the execution of $A$ in $N$ stops in time $T(n)$ and produces a correct output $g \in \Pi(G)$; as usual, $n$ is the number of nodes in the network.

We may occasionally want to emphasize the distinction between ``Monte Carlo'' and ``Las Vegas'' type algorithms:
\begin{itemize}
    \item Monte Carlo: Algorithm $A$ always stops in time $T(n)$; the output is a correct solution to problem $\Pi$ with probability $p$.
    \item Las Vegas: Algorithm $A$ stops in time $T(n)$ with probability $p$; when it stops, the output is always a correct solution to problem $\Pi$.
\end{itemize}
However, Monte Carlo algorithms are not as useful in the field of distributed computing as they are in the context of classical centralized algorithms. In centralized algorithms, we can usually take a Monte Carlo algorithm and just run it repeatedly until it produces a feasible solution; hence we can turn a Monte Carlo algorithm into a Las Vegas algorithm. This is not necessarily the case with distributed algorithms: verifying the output of an algorithm may require global information on the entire output, and gathering such information may take a long time. In this chapter, we will mainly focus on Las Vegas algorithms, i.e., algorithms that are always correct but may occasionally be slow, but in the exercises we will also encounter Monte Carlo algorithms.

\section{With High Probability}

We will use the word \emph{failure} to refer to the event that the algorithm did not meet its guarantees\mydash in the case of a Las Vegas algorithm, it did not stop in time $T(n)$, and in the case of Monte Carlo algorithms, it did not produce a correct output. The word \emph{success} refers to the opposite case.

Usually we want to show that the probability of a failure is negligible. In computer science, we are usually interested in asymptotic analysis, and hence in the context of randomized algorithms, it is convenient if we can show that the success probability approaches $1$ when $n$ increases. Even better, we would like to let the user of the algorithm choose how quickly the success probability approaches~$1$.

This idea is captured in the phrase ``\emph{with high probability}'' (commonly abbreviated \emph{w.h.p.}). Please note that this phrase is not a vague subjective statement but it carries a precise mathematical meaning: it refers to the success probability of $1 - 1/n^c$, where we can choose any constant $c > 0$. (Unfortunately, different sources use slightly different definitions; for example, it may also refer to the success probability of $1 - O(1)/n^c$ for any constant $c > 0$.)

In our context, we say that algorithm $A$ solves problem $\Pi$ on graph family $\calF$ in time $O(T(n))$ \emph{with high probability} if the following holds:
\begin{itemize}
    \item I can choose any constant $c > 0$. Algorithm $A$ may depend on this constant.
    \item Then if I run $A$ in any network $N$ that has its underlying graph in $\calF$, the algorithm will stop in time $O(T(n))$ with probability at least $1 - 1/n^c$, and the output is a feasible solution to problem $\Pi$.
\end{itemize}
Note that the $O(\cdot)$ notation in the running time is used to hide the dependence on $c$. This is a crucial point. For example, it would not make much sense to say that the running time is at most $\log n$ with probability $1 - 1/n^c$ for any constant $c > 0$. However, it is perfectly reasonable to say that the running time is, e.g., at most $c \log n$ or $2^c \log n$ or simply $O(\log n)$ with probability $1 - 1/n^c$ for any constant $c > 0$.

\section{Randomized Coloring in Bounded-Degree Graphs}\label{sec:bdrand}

In Chapter~\chapterref{4} we presented a \emph{deterministic} algorithm that finds a ${(\Delta+1)}$-coloring in a graph of maximum degree $\Delta$. In this section, we will design a \emph{randomized} algorithm that solves the same problem. The running times are different:
\begin{itemize}[noitemsep]
    \item the deterministic algorithm runs in $O(\Delta + \log^* n)$ rounds.
    \item the randomized algorithm runs in $O(\log n)$ rounds with high probability.
\end{itemize}
Hence for large values of $\Delta$, the randomized algorithm can be much faster.

\subsection{Algorithm Idea}

A running time of $O(\log n)$ is very typical for a randomized distributed algorithm. Often randomized algorithms follow the strategy that in each step each node picks a value randomly from some probability distribution. If the value conflicts with the values of the neighbors, the node will try again next time; otherwise the node outputs the current value and stops. If we can prove that each node stops in each round with a constant probability, we can prove that after $\Theta(\log n)$ all nodes have stopped w.h.p. This is precisely what we saw in the analysis of the randomized path-coloring algorithm in Section~\longref{1.5}{sec:algo-p3crand}.

However, adapting the same strategy to graphs of maximum degree $\Delta$ requires some thought. If each node just repeatedly tries to pick a random color from $\{1,2,\dotsc,\Delta+1\}$, the success probability may be fairly low for large values of $\Delta$.

Therefore we will adopt a strategy in which nodes are slightly less aggressive. Nodes will first randomly choose whether they are \emph{active} or \emph{passive} in this round; each node is passive with probability $1/2$. Only active nodes will try to pick a random color among those colors that are not yet used by their neighbors.

Informally, the reason why this works well is the following. Assume that we have a node $v$ with $d$ neighbors that have not yet stopped. Then there are at least $d+1$ colors among which $v$ can choose whenever it is active. If all of the $d$ neighbors were also active and if they happened to pick distinct colors, we would have only a \[\frac{1}{d+1}\] chance of picking a color that is not used by any of the neighbors. However, in our algorithm on average only $d/2$ neighbors are active. If we have at most $d/2$ active neighbors, we will succeed in picking a free color with probability at least \[\frac{d+1 - d/2}{d+1} > \frac{1}{2},\] regardless of what the active neighbors do.

\subsection{Algorithm}

Let us now formalize the algorithm. For each node $u$, let
\[
    C(u) = \{1,2,\dotsc,\deg_G(u)+1\}
\]
be the \emph{color palette} of the node; node $u$ will output one of the colors of $C(u)$.

In the algorithm, node $u$ maintains the following variables:
\begin{itemize}[noitemsep]
    \item State $s(u) \in \{0,1\}$
    \item Color $c(u) \in \{\bot\} \cup C(u)$.
\end{itemize}
Initially, $s(u) \gets 1$ and $c(u) \gets \bot$. When $s(u) = 1$ and $c(u) \ne \bot$, node $u$ stops and outputs color $c(u)$.

In each round, node $u$ always sends $c(u)$ to each port. The incoming messages are processed as follows, depending on the current state of the node:
\begin{itemize}
    \item $s(u) = 1$ and $c(u) \ne \bot$:
    \begin{itemize}
        \item This is a stopping state; ignore incoming messages.
    \end{itemize}
    \item $s(u) = 1$ and $c(u) = \bot$:
    \begin{itemize}
        \item Let $M(u)$ be the set of messages received.
        \item Let $F(u) = C(u) \setminus M(u)$ be the set of \emph{free colors}.
        \item With probability $1/2$, set $c(u) \gets \bot$; otherwise choose a $c(u) \in F(u)$ uniformly at random.
        \item Set $s(u) \gets 0$.
    \end{itemize}
    \item $s(u) = 0$:
    \begin{itemize}
        \item Let $M(u)$ be the set of messages received.
        \item If $c(u) \in M(u)$, set $c(u) \gets \bot$.
        \item Set $s(u) \gets 1$.
    \end{itemize}
\end{itemize}

Informally, the algorithm proceeds as follows. For each node $u$, its state $s(u)$ alternates between $1$ and $0$:
\begin{itemize}
    \item When $s(u) = 1$, the node either decides to be \emph{passive} and sets $c(u) = \bot$, or it decides to be \emph{active} and picks a random color $c(u) \in F(u)$. Here $F(u)$ is the set of colors that are not yet used by any of the neighbors that are stopped.
    \item When $s(u) = 0$, the node \emph{verifies} its choice. If the current color $c(u)$ conflicts with one of the neighbors, we go back to the initial state $s(u) \gets 1$ and $c(u) \gets \bot$. However, if we were lucky and managed to pick a color that does not conflict with any of our neighbors, we keep the current value of $c(u)$ and switch to the stopping state.
\end{itemize}

\subsection{Analysis}

It is easy to see that if the algorithm stops, then the output is a proper ${(\Delta+1)}$-coloring of the underlying graph. Let us now analyze how long it takes for the nodes to stop.

In the analysis, we will write $s_t(u)$ and $c_t(u)$ for values of variables $s(u)$ and $c(u)$ after round $t = 0,1,\dotsc$, and $M_t(u)$ and $F_t(u)$ for the values of $M(u)$ and $F(u)$ during round $t=1,2,\dotsc$. We also write
\[
    K_t(u) = \bigl\{ v \in V : \{u,v\} \in E,\ s_{t-1}(v) = 1, c_{t-1}(v) = \bot \bigr\}
\]
for the set of \emph{competitors} of node $u$ during round $t = 1,3,5,\dotsc$; these are the neighbors of $u$ that have not yet stopped.

First, let us prove that with probability at least $1/4$, a running node succeeds in picking a color that does not conflict with any of its neighbors.
\begin{lemma}\label{lem:bdrand-onestep}
    Fix a node $u \in V$ and time $t = 1,3,5,\dotsc$. Assume that $s_{t-1}(u) = 1$ and $c_{t-1}(u) = \bot$, i.e., $u$ has not stopped before round $t$. Then with probability at least $1/4$, we have $s_{t+1}(u) = 1$ and $c_{t+1}(u) \ne \bot$, i.e., $u$ will stop after round $t+1$.
\end{lemma}
\begin{proof}
    Let $f = |F_t(u)|$ be the number of free colors during round $t$, and let $k = |K_t(u)|$ be the number of competitors during round $t$. Note that $f \ge k + 1$, as the size of the palette is one larger than the number of neighbors.

    Let us first study the case that $u$ is active. As we have got $f$ free colors, for any given color $x \in \NN$ we have
    \[
        \Pr\bigl[ c_t(u) = x \bigm| c_t(u) \ne \bot \bigr] \le 1/f.
    \]
    In particular, this holds for any color $x = c_t(v)$ chosen by any active competitor $v \in K_t(u)$:
    \[
        \Pr\bigl[ c_t(u) = c_t(v) \bigm| c_t(u) \ne \bot,\  c_t(v) \ne \bot \bigr] \le 1/f.
    \]
    That is, we conflict with an active competitor with probability at most $1/f$. Naturally, we cannot conflict with a passive competitor:
    \[
        \Pr\bigl[ c_t(u) = c_t(v) \bigm| c_t(u) \ne \bot,\  c_t(v) = \bot \bigr] = 0.
    \]
    As a competitor is active with probability
    \[
        \Pr\bigl[ c_t(v) \ne \bot \bigr] = 1/2,
    \]
    and the random variables $c_t(u)$ and $c_t(v)$ are independent, the probability that we conflict with a given competitor $v \in K_t(u)$ is
    \[
        \Pr\bigl[ c_t(u) = c_t(v) \bigm| c_t(u) \ne \bot \bigr] \le \frac{1}{2f}.
    \]
    By the union bound, the probability that we conflict with some competitor is
    \[
        \Pr\bigl[ c_t(u) = c_t(v) \text{ for some $v \in K_t(u)$} \bigm| c_t(u) \ne \bot \bigr] \le \frac{k}{2f},
    \]
    which is less than $1/2$ for all $k \ge 0$ and all $f \ge k+1$. Put otherwise, node $u$ will avoid conflicts with probability
    \[
        \Pr\bigl[ c_t(u) \ne c_t(v) \text{ for all $v \in K_t(u)$} \bigm| c_t(u) \ne \bot \bigr] > \frac{1}{2}.
    \]

    So far we have studied the conditional probabilities assuming that $u$ is active. This happens with probability
    \[
        \Pr\bigl[ c_t(u) \ne \bot \bigr] = 1/2.
    \]
    Therefore node $u$ will stop after round $t+1$ with probability
    \[
    \begin{split}
        &\Pr\bigl[ c_{t+1}(u) \ne \bot] = \\
        &\Pr\bigl[ c_t(u) \ne \bot \text { and } c_t(u) \ne c_t(v) \text{ for all $v \in K_t(u)$} ] > 1/4.
        \qedhere
    \end{split}
    \]
\end{proof}

Now we can continue with the same argument as what we used in Section~\longref{1.5}{sec:algo-p3crand} to analyze the running time. Fix a constant $c > 0$. Define
\[
    T(n) = 2(c+1) \log_{4/3} n.
\]
We will prove that the algorithm stops in $T(n)$ rounds. First, let us consider an individual node. Note the exponent $c+1$ instead of $c$ in the statement of the lemma; this will be helpful later.

\begin{lemma}\label{lem:bdrand-onenode}
    Fix a node $u \in V$. The probability that $u$ has not stopped after $T(n)$ rounds is at most $1/n^{c+1}$.
\end{lemma}
\begin{proof}
    By Lemma~\ref{lem:bdrand-onestep}, if node $u$ has not stopped after round $2i$, it will stop after round $2i+2$ with probability at least $1/4$. Hence the probability that it has not stopped after $T(n)$ rounds is at most
    \[
        (3/4)^{T(n)/2} = \frac{1}{(4/3)^{(c+1) \log_{4/3} n}} = \frac{1}{n^{c+1}}. \qedhere
    \]
\end{proof}

Now we are ready to analyze the time until all nodes stop.

\begin{theorem}\label{thm:bdrand}
    The probability that all nodes have stopped after $T(n)$ rounds is at least $1 - 1/n^c$.
\end{theorem}
\begin{proof}
    Follows from Lemma~\ref{lem:bdrand-onenode} by the union bound.
\end{proof}

Note that $T(n) = O(\log n)$ for any constant $c$. Hence we conclude that the algorithm stops in $O(\log n)$ rounds with high probability, and when it stops, it outputs a vertex coloring with $\Delta+1$ colors.

\section{Quiz}

Consider a cycle with $10$ nodes, and label the nodes with a random permutation of the numbers $1, 2, \dotsc, 10$ (uniformly at random). A node is a \emph{local maximum} if its label is larger than the labels of its two neighbors. Let $X$ be the number of local maxima. What is the expected value of $X$?

\section{Exercises}

\begin{ex}[larger palette]\label{ex:bdrand2delta}
    Assume that we have a graph without any isolated nodes. We will design a graph-coloring algorithm $A$ that is a bit easier to understand and analyze than the algorithm of Section~\ref{sec:bdrand}. In algorithm $A$, each node $u$ proceeds as follows until it stops:
    \begin{itemize}
        \item Node $u$ picks a color $c(u)$ from $\{1,2,\dotsc,2d\}$ uniformly at random; here $d$ is the degree of node~$u$.
        \item Node $u$ compares its value $c(u)$ with the values of all neighbors. If $c(u)$ is different from the values of its neighbors, $u$ outputs $c(u)$ and stops.
    \end{itemize}
    Present this algorithm in a formally precise manner, using the state-machine formalism. Analyze the algorithm, and prove that it finds a $2\Delta$-coloring in time $O(\log n)$ with high probability.
\end{ex}

\begin{ex}[unique identifiers]\label{ex:randomness-to-unique-ids}
    Design a randomized $\PN$ algorithm $A$ that solves the following problem in $O(1)$ rounds:
    \begin{itemize}[noitemsep]
        \item As input, all nodes get value $|V|$.
        \item Algorithm outputs a labeling $f\colon V \to \{1,2,\dotsc,\chi\}$ for some $\chi = |V|^{O(1)}$.
        \item With high probability, $f(u) \ne f(v)$ for all nodes $u \ne v$.
    \end{itemize}
    Analyze your algorithm and prove that it indeed solves the problem correctly.

    In essence, algorithm $A$ demonstrates that we can use randomness to construct unique identifiers, assuming that we have some information on the size of the network. Hence we can take any algorithm $B$ designed for the $\LOCAL$ model, and combine it with algorithm $A$ to obtain a $\PN$ algorithm $B'$ that solves the same problem as $B$ (with high probability).
    \hint{Pick the labels randomly from a sufficiently large set; this takes $0$ communication rounds.}
\end{ex}

\begin{ex}[large independent sets]
    Design a randomized $\PN$ algorithm $A$ with the following guarantee: in any graph $G = (V,E)$ of maximum degree $\Delta$, algorithm $A$ outputs an independent set $I$ such that the \emph{expected} size of the $I$ is $|V|/O(\Delta)$. The running time of the algorithm should be $O(1)$. You can assume that all nodes know $\Delta$.
    \hint{Each node $u$ picks a random number $f(u)$. Nodes that are local maxima with respect to the labeling $f$ will join $I$.}
\end{ex}

\begin{ex}[max cut problem]
    Let $G = (V,E)$ be a graph. A \emph{cut} is a function $f\colon V \to \{0,1\}$. An edge $\{u,v\} \in E$ is a \emph{cut edge} in $f$ if $f(u) \ne f(v)$. The \emph{size} of cut $f$ is the number of cut edges, and a \emph{maximum cut} is a cut of the largest possible size.
    \begin{subex}
        \item Prove: If $G = (V,E)$ is a bipartite graph, then a maximum cut has $|E|$ edges.
        \item Prove: If $G = (V,E)$ has a cut with $|E|$ edges, then $G$ is bipartite.
        \item Prove: For any $\alpha > 1/2$, there exists a graph $G = (V,E)$ in which the maximum cut has fewer than $\alpha |E|$ edges.
    \end{subex}
    \hint{For the last part, consider a complete graph with a sufficiently large number of nodes.}
\end{ex}

\begin{ex}[max cut algorithm]
    Design a randomized $\PN$ algorithm $A$ with the following guarantee: in any graph $G = (V,E)$, algorithm $A$ outputs a cut $f$ such that the \emph{expected} size of cut $f$ is at least $|E|/2$. The running time of the algorithm should be $O(1)$.

    Note that the analysis of algorithm $A$ also implies that for any graph there \emph{exists} a cut with at least $|E|/2$.

    \hint{Each node chooses an output $0$ or $1$ uniformly at random and stops; this takes $0$ communication rounds. To analyze the algorithm, prove that each edge is a cut edge with probability $1/2$.}
\end{ex}

\begin{ex}[maximal independent sets]
    Design a randomized $\PN$ algorithm that finds a maximal independent set in time $O(\Delta + \log n)$ with high probability.

    \hint{Use the randomized coloring algorithm.}
\end{ex}

\begin{exs}[maximal independent sets quickly]
    Design a randomized distributed algorithm that finds a maximal independent set in time $O(\log n)$ with high probability.

    \hint{Look up ``Luby's algorithm''.}
\end{exs}

\section{Bibliographic Notes}

Algorithm of Section~\ref{sec:bdrand} and the algorithm of Exercise~\ref{ex:bdrand2delta} are from Barenboim and Elkin's book \cite[Section 10.1]{barenboim13distributed}.


\documentclass[]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage{bm}
%\usepackage[margin=1in]{geometry}
\usepackage[a4paper]{geometry}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}

\theoremstyle{Simple}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}{Corollary}[thm]

\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]

\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}

\theoremstyle{example}
\newtheorem{eg}{Example}[section]

\title{Linear Algebra - MTH100\\ Lecture Notes}
\author{Jai Luthra}
\date{November, 2015}

\begin{document}

\maketitle

\section{Eigenvalues and Eigenvectors}

\begin{defn}

An \textbf{eigenvector} of an $n \times n$ matrix is $A$ is a \underline{non-zero} vector $\bm{x}$ such that $A\bm{x} = \lambda\bm{x}$; such a vector $\bm{x}$ is called an \textbf{eigenvector corresoponding} to $\lambda$.
Eigenvalues are sometimes also called \textit{characteristic values} or \textit{latent roots}. Eigenvectors are sometimes also called \textit{characteristic vectors}.

\end{defn}

\begin{rem}
The zero vector is \textbf{not considered as an eigenvector} since $A\bm{0} = \lambda \bm{0}$ for all matrices $A$ and all scalars $\lambda$
\end{rem}

\begin{rem}
However, $0$ is allowed to be an eigenvalue for a matrix $A$, in that case the equation $A\bm{x} = 0\bm{x}$ has a non-trivial solution.
But $A\bm{x} = \bm{0}$ has a non-trivial solution $\bm{\iff}$ A is not invertible. \textit{Therefore, an $n \times n$ matrix $A$ is invertible $\iff$ $0$ is not an eigenvalue of $A$}
\end{rem}

\begin{rem}
An eigenvector is not unique, since all scalar
multiples of an eigenvector are also eigenvectors.
Actually, the set of all eigenvectors corresponding to a
particular eigenvalue together with the zero vector forms a
subspace of $V = F^n$ for some n, More formally:

Put $X$ = \{$ \bm{v} \in V \mid \bm{v} $ is an eigenvector for $\lambda\} \cup \{\bm{0}$\} = \{$\bm{v} \in V \mid A \bm{v} = \lambda \bm{v}$\}

Then $X$ is a subspace of $V$, called the \textbf{eigenspace} of $A$
corresponding to $\lambda$. This can be proved using the subspace test, but follows easily from the fact that the eigenspace corresponding to $\lambda$ is nothing but the null space of the matrix $(A \mathbin{-} \lambda I)$.
\end{rem}

\begin{prop} \label{prop:50}
If $\bm{v_{1}, v_{2}, ... v_{p}}$ are eigenvectors corresponding to \underline{distinct} eigenvalues ${\lambda_{1}, \lambda_{2}, ... \lambda_{p}}$ of the matrix $A$, then the set $\{\bm{v_{1}, v_{2}, ... v_{p}}\}$ is linearly independent.
\end{prop}

\begin{cor}
An $n \times n$ matrix A can have at most $n$ distinct eigenvalues.
\end{cor}

\begin{proof}
Suppose, for the sake of contradiction, that $\bm{v_{1}, v_{2}, ... v_{p}}$ are linearly dependent. Let $m$ be the smallest number such that $\bm{v_{1}, v_{2}, ... v_{m}}$ are lin. ind. \underline{and} $\bm{v_{m+1}}$ is a linear combination of preceding vectors. Then:

\begin{equation} \label{eq:1}
c_{1}\bm{v_{1}} + c_{2}\bm{v_{2}} + ... + c_{m}\bm{v_{m}} = \bm{v_{m+1}}
\end{equation}

Left multiplying by $A$,

$$
c_{1}A\bm{v_{1}} + c_{2}A\bm{v_{2}} + ... + c_{m}A\bm{v_{m}} = A\bm{v_{m+1}}
$$

Since the $\bm{v_{i}}$ are eigenvectors:
$$
c_{1}\lambda_{1}\bm{v_{1}} + c_{2}\lambda_{2}\bm{v_{2}} + ... + c_{m}\lambda_{m}\bm{v_{m}} = \lambda_{m+1}\bm{v_{m+1}}
$$

Multiplying \eqref{eq:1} by $\lambda_{m+1}$ and subtracting we get:

\begin{equation} \label{eq:2}
c_{1}(\lambda_{1} - \lambda_{m+1})\bm{v_{1}} + ... + c_{m}(\lambda_{m} - \lambda_{m+1})\bm{v_{m}} = \bm{0}
\end{equation}

However, $\bm{v_{1}, v_{2}, ... v_{m}}$ are lin. indep. so all of the coefficients in \eqref{eq:2} have to be zero: $c_{1}(\lambda_{1} - \lambda_{m+1}) = 0 \implies c_{1} = 0$ since the $\lambda$'s are given to be distinct. Similarly, $c_{2} = c_{3} = ... = c_{m} = 0$.

But then from \eqref{eq:1} we get that $\bm{v_{m+1}} = \bm{0}$.

However, this is not possible, since all the $\bm{v}$'s are eigenvectors.
Since there is a contradiction, the original hypothesis must be wrong.
Therefore, $\bm{v_{1}, v_{2}, ... v_{p}}$ are lin. independent.

\end{proof}

\begin{rem}
It is easy to verify whether a particular vector is an eigenvector of a given matrix $A$ or not. Similarly, given some number, we can verify whether it is an eigenvalue or not.
However, in order to systematically find eigenvalues, we need to use the following result
\end{rem}

\begin{prop}
A scalar $\lambda$ is an eigenvalue of a $n \times n$ matrix $A$ $\iff$ $\lambda$ satisfies the \textbf{characteristic equation} $det(A - \lambda I) = 0$.
\end{prop}

\begin{note}
$det(A - \lambda I)$ is a polynomial of degree $n$ called the \textbf{characteristic polynomial} of $A$. It has at most $n$ roots, counting multiplicities. Hence an $n \times n$ matrix can have at most $n$ eigenvalues (counting multiplicities). \textbf{\textit{It is possible for a matrix with real entries to have no real eigenvalues.}}
\end{note}

\begin{note}
If complex roots are allowed, an $n \times n$ matrix has exactly $n$ eigenvalues (counting multiplicities). Therefore, we must clearly specify which field is being considered when we talk about the eigenvalues of a matrix. For the time being, however, we will only allow real eigenvalues.
\end{note}

\subsection{Eigenvalues of similar matrices}

Recall that an $n \times n$ matrix $B$ is said to be \textbf{similar} to an $n \times n$ matrix $A$ if $\exists$ an invertible matrix $P$ such that:
$B = PAP^{-1}$ (or $A = P^{-1}BP$).
Similarity of matrices is an equivalence relation on the set of $n \times n$ matrices.

\begin{rem}
Using the multiplicative property of
determinants, it is easy to see that similar matrices have
the same determinant. Using essentially the same idea,we
can derive the following result:
\end{rem}

\begin{prop}
If the $n \times n$ matrices $A$ and $B$ are similar, then they have the same characteristic polynomial, and hence the same eigenvalues with the same multiplicities.
\end{prop}

\section{Diagonalization of Matrices}

If $A$ is a diagonal matrix, then its diagonal elements are its
eigenvalues, and the standard basis vectors are its
eigenvectors. This is the motivation for the following:

\begin{defn}
An $n \times n$ matrix $A$ is said to be \textbf{diagonalizable}
if $A$ is similar to a diagonal matrix $D$, in other words if
there is an invertible matrix $P$ and a diagonal matrix $D$
such that $A = PDP^{-1}$
\end{defn}

\begin{rem}
If $A$ is diagonalizable, then its powers are easy
to compute.
\end{rem}

\begin{rem}
If $A$ is diagonalizable, then its eigenvalues can
be found by inspection of $D$. However, in practice, we
have to do things the other way round. First, we find the
eigenvalues from the characteristic equation, then we find
$P$, then we get the diagonal matrix $D$.
\end{rem}

\begin{thm}[Diagonalization Theorem - VIT]
\label{thm:dt-vit}
\hfill

\begin{enumerate}
\item An $n \times n$ matrix $A$ is diagonalizable $\iff$ $A$ has $n$ linearly independent eigenvectors.
\item In this case, $A = PDP^{-1}$, where the columns of $P$ are $n$ l.i. eigenvectors of $A$, and the diagonal entries of $D$ are eigenvalues corresponding to these eigenvectors.
\end{enumerate}

\end{thm}

\begin{rem}
Another way to express the above theorem is
that an $n \times n$ matrix $A$ is diagonalizable $\iff$ it has
enough (linearly independent) eigenvectors to form a
basis of $\mathbb{R}^{n}$. Such a basis is called an \textbf{eigenvector basis}.
\end{rem}

In practice, we can distinguish three cases:

\subsection{Case 1}
An $n \times n$ matrix $A$ has $n$ distinct (real) eigenvalues. Then we get the following results:

\begin{prop}
An $n \times n$ matrix $A$ with $n$ distinct eigenvalues is diagonalizable.
\end{prop}

\begin{proof}
By an earlier result Proposition~\ref{prop:50}, eigenvectors corresponding to distinct eigenvalues are linearly independent. Therefore in this case $A$ has $n$ linearly independent eigenvectors. Hence by the Thm.~\ref{thm:dt-vit} (DT-VIT), $A$ is diagonalizable.
\end{proof}

Given an eigenvalue $\lambda_{1}$ for a matrix $A$, we define:

\begin{defn}
The \textbf{algebraic multiplicity} of $\lambda_{1}$ is the power of the factor $(\lambda - \lambda_{1})$ in the characteristic polynomial of $A$
\end{defn}

\begin{defn}
The \textbf{geometric multiplicity} of $\lambda_{1}$ is the dimension of the eigenspace corresponding to $\lambda_{1}$
\end{defn}

\begin{rem}
The first definition is the one we have used for
multiplicity up to now, as it applies to polynomials in
general (not only the characteristic polynomial). The
second definition applies specifically to the characteristic
polynomial, since its roots are eigenvalues, which have
corresponding eigenspaces.
\end{rem}

\subsection{Case 2}
An $n \times n$ matrix $A$ has $p < n$ distinct eigenvalues, but counting the (algebraic) multiplicities, there are $n$ \underline{real} eigenvalues (\textit{\underline{not distinct}}). We now come to the weaker result for this case:

\begin{prop}
Let $A$ be an $n \times n$ matrix with n (real) eigenvalues (counting algebraic multiplicities) of which only $\lambda_{1}, \lambda_{2}, \dots, \lambda{p}$ are distinct ($p < n$). Then the following hold:

\begin{enumerate}
\item For $1 \leq k \leq p$, the geometric multiplicity is less than or equal to the algebraic multiplicity of $\lambda_{k}$.
\item $A$ is diagonalizable $\iff$ the sum of the dimensions of the distinct eigenspaces is n $\iff$ the geometric multiplicity for each $\lambda_{k}$ eequals its algebraic multiplicity.
\item If $A$ is diagonalizable, and $B_{k}$ is a basis for the eigenspace corresponding to $\lambda_{k}$ for each k, then the total collection of vectors in $B_{1}, \dots, B_{p}$ forms an eigenvector basis for $\mathbb{R}^{n}$.
\end{enumerate}

\end{prop}

\subsection{Case 3}

An $n \times n$ matrix $A$ has $p < n$ distinct eigenvalues, but even after counting the algebraic multiplicities, there are $< n$ (\underline{real}) eigenvalues (p could even be 0). Then $A$ is not diagonalizable over the real field. If we want to diagonalize, we have to admit complex eigenvalues and eigenvectors.

\begin{rem}
Even if we admit complex eigenvalues and
eigenvectors, a real matrix does not have to be
diagonalizable. The case is quite complicated, and we will
not go into the details. However, we will consider the case
of a $2 \times 2$ real matrix with a complex eigenvalue, and
describe the nature of such a matrix and its corresponding
transformation (i.e. a linear operator on $\mathbb{R}^{2}$).
\end{rem}

\section{Complex Eigenvalues}

In case $A$ has complex eigenvalues, we regard $A$ as a linear transformation on the vector space $\mathbb{C}^{n}$, where $\mathbb{C}$ is the field of complex numbers. Then:

A complex scalar $\lambda$ satisfies $det(A - \lambda I) = 0 \iff$ there is a nonzero vector $\bm{x}$ in $\mathbb{C}^{n}$ such that $A\bm{x} = \lambda \bm{x}$. $\lambda$ is called a complex eigenvalue and $\bm{x}$ is called a complex eigenvector.

If $A\bm{x} = \lambda \bm{x}$, then taking complex conjugates, $\overline{A\bm{x}} = \overline{\lambda \bm{x}}$, or $\overline{A}\overline{\bm{x}} = \overline{\lambda} \overline{\bm{x}}$. However since $A$ is real, $\overline{A} = A$. So $A\overline{\bm{x}} = \overline{\lambda} \overline{\bm{x}}$, or $\overline{\lambda}$ is also an eigenvalue with eigenvector $\overline{\bm{x}}$. \textit{In other words, If $A$ is real, then its complex eigenvalues occur in conjugate pairs.}

\begin{prop}[Basic result for Complex Eigenvalues]
Suppose $A$ is a real $2 \times 2$ matrix with a complex eigenvalue $\lambda = a - bi, b \neq 0$, and associated eigenvector $\bm{v}$ in $\mathbb{C}^{2}$. Then $A = PBP^{-1}$ where

$$
P =
\begin{bmatrix}
 \operatorname{Re}(\bm{v}) & \operatorname{Im}(\bm{v})
\end{bmatrix},
B =
\begin{bmatrix}
a & -b \\
b & a
\end{bmatrix}
$$

\begin{itemize}
\item Furthermore the transformation (left multiplication by $B$) corresponds to a rotation followed by scaling.
\item The rotation is through the angle $\phi$ between the positive x-axis and the ray from the origin to $(a,b)$. The angle $\phi$ is called the \textit{argument} of $\lambda$.
\item The scaling is by a factor $r = |\lambda| = \sqrt{a^{2} + b^{2}}$. The quantity $r = |\lambda|$ is known as the \textit{modulus} of $\lambda$.
\end{itemize}

\end{prop}

\begin{eg}
Suppose $A = \begin{bmatrix} 0 & 1 \\ -8 & 4 \end{bmatrix}$ then from its characteristic polynomial. Find its complex eigenvalues and eigenvectors, and briefly comment on what the matrix is doing.
\end{eg}

\begin{proof}[Solution]
From its characteristic polynomial $det(A - \lambda I) = 8 - 4\lambda + \lambda^{2}$ we get eigenvalues $2 \pm 2i$. Take $\lambda = 2 + 2i$ (in other words, $a = 2$ and $b = -2$) then the matrix

$$
A - \lambda I = \begin{bmatrix} -2 - 2i & 1 \\ -8 & 2 - 2i \end{bmatrix}
$$

The corresponding eigenvector $\bm{v} = (x,y)$ (considered as a column vector with $x$ and $y$ as complex numbers) is obtained as the solution derived from the above matrix.

This leads to two equations:

$$
(-2 - 2i)x + y = 0
$$
$$
(-8)x + (2 - 2i)y = 0
$$

Since the matrix $A - \lambda I$ has a non-trivial solution, its two
rows are linearly dependent. In other words, the two
equations represent the same relationship between $x$ and $y$.
We may give any value to one of them arbitrarily, and
obtain the second from either of the two equations.

Taking the first equation $(-2 -2i)x + y = 0$ and putting $x = 1$, we get:

$$
\begin{bmatrix}
x \\
y
\end{bmatrix}
=
\begin{bmatrix}
1 \\
2 + 2i
\end{bmatrix}
=
\begin{bmatrix}
1 \\
2
\end{bmatrix}
+ i
\begin{bmatrix}
0 \\
2
\end{bmatrix}
$$

Thus the matrix $P = \begin{bmatrix}1 & 0\\ 2 & 2\end{bmatrix}$
and the matrix $B = \begin{bmatrix}2 & 2\\-2 & 2\end{bmatrix}$

We can verify that $PBP^{-1} =
\end{proof}

\end{document}


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

\section{Quadrupole approximation}

The procedure to find the quadrupole approximation
for the GW emitted by a Newtonian system is in the form:
\begin{enumerate}
    \item determine the density \(\rho (\vec{x}, t)\);
    \item calculate the trace-free inertia tensor \(Q^{ij}(t)\);
    \item calculate the gravitational wave strain \(h_{ij}\).
\end{enumerate}

\subsection{Two point particles}

In order to model the point-like nature of the particles we can write an expression for the density as a sum of two delta-functions,
whose positions oscillate on the \(x\) axis with an amplitude \(R\):
%
\begin{align}
\rho (\vec{x}, t) = m\delta (\vec{x} - \vec{x}_1(t)) + m\delta (\vec{x} - \vec{x}_2 (t))                                                           \,,
\end{align}
%
where the positions of the particles, \(\vec{x}_1 (t)\) and \(\vec{x}_2 (t)\), will be the solutions to the differential equation \(\vec{F}_{12} = - k (\vec{x}_1 - \vec{x}_2)\).
If they start out along the \(x\) axis they will remain along it, so the equation will read \(F_{12} = - k (x_1 - x_2 )\), so \(\ddot{x}_1 = - \omega_0 ^2 (x_1 - x_2 )\) and \(\ddot{x}_2 = + \omega_0 ^2 (x_1 - x_2 )\), where \(\omega^2 = k / m\).

This can be rewritten, by taking the difference of the two, as \(\ddot{\Delta x} = - 2 \omega_0 ^2 \Delta x \), with \(\Delta x = x_1 - x_2 \).
Therefore, the pulsation of the system is \(\omega = \sqrt{2} \omega_0  \) --- this could also have been calculated as \(\sqrt{k / m_r}\), where \(m_r = m^2/ (m+m) = m/ 2\) is the reduced mass.

So, the position vectors will look like
%
\begin{align}
\vec{x}_1 (t) = R \left[\begin{array}{c}
\cos(\omega t) \\
0 \\
0
\end{array}\right]
\qquad \text{and} \qquad
\vec{x}_2 (t) = - \vec{x}_1 (t)
\,
\end{align}
%
up to a phase.

% For simplicity, we will also assume that the radius \(r\) is constant --- this cannot be precisely the case, since there will be some amount of power lost because of the GW emission, but it is a reasonable approximation.

So, the inertia tensor will be given by
%
\begin{align}
I^{ij} (t) &= \int \rho (\vec{x}, t) x^{i} x^{j} \dd[3]{x}  \\
&= m \sum _{k=1, 2} x_k^{i} x_k^{j}  \\
&= - m R^2 \left[\begin{array}{ccc}
\cos^2 (\omega t) & 0  & 0\\
0 & 0 & 0 \\
0 & 0 & 0
\end{array}\right]
\,.
\end{align}
%
% where we omit the argument of the sines and cosines (which is always \( \)).
Its trace is equal to its only nonzero component, \(I^{xx}\), therefore its traceless version will look like
%
\begin{align}
Q^{ij} (t) &= mR^2 \left[\begin{array}{ccc}
- (2/3) \cos^2\omega t & 0 & 0 \\
0 & (1/3) \cos^2 \omega t & 0 \\
0 & 0 & (1/3) \cos^2 \omega t
\end{array}\right]
\,.
\end{align}
%

The second derivative of this tensor will be given by
%
\begin{align}
\ddot{Q}^{ij}(t) = \frac{2 mR^2}{3} \omega^2
\left[\begin{array}{ccc}
2\cos(2 \omega t) & 0  & 0\\
0 & - \cos(2 \omega t)  & 0 \\
0 & 0 & - \cos(2 \omega t)
\end{array}\right]
\,.
\end{align}

Now, in order to compute the gravitational wave strain we need the projection tensor \(\Lambda_{ij, kl}\).
If the propagation direction we are interested in is \(\vec{k}\), then the tensor
%
\begin{align}
P_{ij} = \delta_{ij} - \frac{k_i k_j}{\abs{k}^2} = \delta_{ij} - n_i n_j
\,
\end{align}
%
will project a vector onto the subspace orthogonal to \(\vec{k}\); and the tensor
%
\begin{align}
\Lambda_{ij, kl} &= P_{ik} P_{jl} - \frac{1}{2} P_{ij} P_{kl}  \\
&= \delta_{ik} \delta_{jl} - n_i n_k \delta_{jl} - \delta_{ik} n_j n_l + \frac{1}{2} n_{i} n_k n_j n_l - \frac{1}{2} \delta_{ij} \delta_{kl} + \frac{1}{2} \delta_{ij} n_k n_l + \frac{1}{2} n_i n_j \delta_{kl}
\,,
\end{align}
%
will project a rank-2 tensor onto the corresponding subspace.

Then, the gravitational wave emission will look like:
%
\begin{align}
h_{ij} (t) &= \frac{2}{r} \frac{G}{c^{4}} \Lambda_{ij, kl} \ddot{Q}_{kl} (t - r/ c)  \\
&= \frac{2}{r} \frac{G}{c^{4}} \frac{2 m R^2 \omega^2}{3}
\cos(2 \omega (t - r/c)) F_{i j} (\theta , \varphi )
\,,
\end{align}
%
where \(F_{i j}(\theta , \varphi )\) is a tensor depending on the two angles which define the observation-direction unit vector:
%
\begin{align}
\vec{n} = \left[\begin{array}{c}
\sin \theta \cos \varphi  \\
\sin \theta \sin \varphi  \\
\cos \theta
\end{array}\right]
\,.
\end{align}

The explicit shape of \(F_{i j}\) depends on the shape of \(\ddot{Q}_{i j}\), the one for this specific case can be calculated analytically with a computer algebra system --- see \href{https://jacopok.github.io/tt_gauge_gw.html}{here}.

However, that specific analytic form is not really interesting --- we want to extract the two actual degrees of freedom of the gravitational wave.
If we define two vectors \(\vec{m}\) and \(\vec{l}\) which are orthogonal to \(\vec{n}\) and to each other, we will be able to extract the degrees of freedom as \(h_+ (t) = h_{ij} (t) m^i m^i\) and \(h_\times (t) = h_{ij} m^i l^{j}\).
We can select, for example, the \(\hat{\theta} \) and \(\hat{\varphi}\) unit vectors in a spherical coordinate system in which \(\vec{n} = \hat{r}\) is the radial vector for this purpose.

The computation yields:
%
\begin{align}
h_+ (t) &= \frac{2}{r} \frac{G}{c^{4}} m R^2 \omega^2  \qty(\cos^2 \theta \cos^2 \varphi + \cos^2 \varphi  - 1) \cos(2 \omega t) \\
h_\times (t) &= - \frac{2}{r} \frac{G}{c^{4}}  m R^2 \omega^2  \cos \theta \sin( 2 \varphi ) \cos(2 \omega t)
\,.
\end{align}

% The matrix \(h_{ij}\) is then
% %
% \begin{align}
% h_{ij} &= C \left[\begin{array}{ccc}
% (1 - n_x^2)^2/2  &
% (n_x^2 - 1) n_x n_y / 2 &
% (n_x^2 - 1) n_x n_z / 2 \\
%  &
%  \frac{1}{2} n_{y} n_x n_y n_x - \frac{1}{2}  + \frac{1}{2} n_x n_x + \frac{1}{2} n_y n_y
%   & (n_x^2 + 1) n_y n_z / 2  \\
%  &  &
%  \frac{1}{2} n_{z} n_x n_z n_x - \frac{1}{2} + \frac{1}{2}  n_x n_x + \frac{1}{2} n_z n_z

% \end{array}\right]
% \,,
% \end{align}
% %
% where
% %
% \begin{align}
% C = - \frac{2}{r} \frac{G}{c^{4}} \cos( 2 \omega \qty(t - \frac{r}{c}) + \phi )
% \,,
% \end{align}
%

% \subsection{A free-falling particle}

% In this case the motion will be determined by the equation
% %
% \begin{align}
% F = - \frac{GMm}{r^2} \implies \ddot{r} = - \frac{GM}{r^2}
% \,,
% \end{align}
% %
% for which we need to specify two initial conditions.

% \subsection{Ellipsoid rotating along its axis}

% The nonzero components of the inertia tensor of an ellipsoid with mass \(m\) and axes \(a\), \(b\), \(c\) are:
% %
% \begin{align}
% I_{11} = \frac{m}{5} (b^2 + c^2) \\
% I_{22} = \frac{m}{5} (a^2 + c^2) \\
% I_{33} = \frac{m}{5} (a^2 + b^2)
% \,.
% \end{align}

% We give a sketch of the computation, starting from the assumption that \((2/5) m r^2\) is the moment of inertia of a sphere along any axis which passes along the center.
% This means that if we select a Cartesian coordinate system the inertia tensor of the sphere is diagonal, and its components read
% %
% \begin{align}
% \frac{2}{5} m r^2 = I_{xx } = I_{yy} = I_{zz} = \int_{x^2 + y^2 + z^2 \leq r^2} \rho_s (y^2 + z^2) \dd[3]{x}
% \,,
% \end{align}
% %
% where the (assumed constant) density of the sphere is \(\rho_s = m / V = 3m / 4 \pi r^3\).
% The integral could be equivalently that of \(x^2 + y^2\) or \(x^2 + z^2\): therefore, each integral in the sphere's volume \(V\) in the form
% %
% \begin{align}
% \int_{V} \rho x_i^2 \dd[3]{x} = \frac{1}{5} m r^2
% \,
% \end{align}
% %
% must contribute for half of the total.

% With this knowledge, we can compute the moment of inertia along a certain axis, say \(z\), of an ellipsoid with axes \(a\), \(b\) and \(c\):
% %
% \begin{align}
% I_{zz} &= \int_{(x/a)^2 + (y/b)^2 + (z/c)^2 \leq 1} \rho_e (x^2 + y^2) \dd[3]{x}
% \,,
% \end{align}
% %
% where now the density of the ellipsoid reads \(\rho _e = m / V = 3m / 4 \pi abc\).

% We start out by only computing the integral of \(\rho x^2\). We can make a change of coordinates: \(X = x/ a\), \(Y = y / b\) and \(Z = z/c\). The volume element changes as \(\dd[3]{x} = abc \dd[3]{X}\).

% In these variables, the integral can be written in terms of the previously found result for a sphere of radius 1, with density \(\rho _1 = 3 m / 4 \pi \):
% %
% \begin{align}
% I_{zz}^{(x^2 \text{ term})} &= \rho_e \int_{X^2 +Y^2+ Z^2 \leq 1} X^2 a^2 abc \dd[3]{X}  \\
% &= \frac{\rho_e}{\rho _1} a^3 bc \int_{X^2 +Y^2+ Z^2 \leq 1} \rho_1 X^2 \dd[3]{X}  \\
% &= \frac{\rho_e}{\rho _1} a^3 bc \frac{m}{5} = \frac{m}{5} \frac{a^3 bc}{abc} = a^2 \frac{m}{5}
% \,,
% \end{align}
% %
% so the full component reads \(I_{zz} = (a^2 + b^2) m/ 5\).
% The off-diagonal components, instead, vanish by symmetry: integrals in the form \(\int \rho x^{i} x^{j} \dd[3]{x}\) with \(i \neq j\)

% \subsection{Two particles in circular Newtonian orbit}

% %
% \begin{align}
% \rho (\vec{x}, t) = m_1 \delta (\vec{x} - \vec{x}_1(t)) + m_2 \delta (\vec{x} - \vec{x}_2 (t))
% \,,
% \end{align}
% %
% where
% %
% \begin{align}in
% \vec{x}_1 (t) = r \left[\begin{array}{c}
% \cos(\omega t + \phi ) \\
% - \sin(\omega t + \phi ) \\
% 0
% \end{array}\right]
% \qquad \text{and} \qquad
% \vec{x}_2 (t) = - \vec{x}_1 (t)
% \,.
% \end{align}

% For simplicity, we will also assume that the radius \(r\) is constant --- this cannot be precisely the case, since there will be some amount of power lost because of the GW emission, but it is a reasonable approximation.

% So, the trace-free inertia tensor will be given by
% %
% \begin{align}
% Q^{ij} (t) &= \int \rho (\vec{x}, t) \qty( x^{i} x^{j} - \frac{1}{3} \delta^{ij} r^2) \dd[3]{x}  \\
% &= \sum _{k=1, 2} m_k \qty(x_k^{i} x_k^{j} - \frac{1}{3} \delta^{ij} r^2)  \\
% &= 2 m r^2 \left[\begin{array}{cc}
% \cos^2 - 1/3 & - \cos \sin \\
% - \cos \sin & \sin^2 - 1/3
% \end{array}\right]
% \,,
% \end{align}
% %
% where we write only the upper-left 2x2 submatrix in \(Q^{ij}\), since the other entries are constant, and we omit the argument of the sines and cosines (which is always \(\omega t + \phi \)).

% The second derivative of this tensor will be given by
% %
% \begin{align}
% \ddot{Q}^{ij}(t) = 4 m r^2 \omega^2 \left[\begin{array}{cc}
% \sin^2 - \cos^2 & 2 \sin \cos \\
% 2 \sin \cos & \cos^2 - \sin^2
% \end{array}\right]
% \,.
% \end{align}

\section{Estimate of GW magnitude}

We want a way to estimate the GW strain, \(h \sim \delta L / L\), by simple considerations about the parameters of the system which is generating the waves.
In the quadrupole approximation we have \(h \sim (G / c^{4} r) \ddot{I}\), where \(\ddot{I}\) is the typical magnitude of the second derivative of the inertia tensor, while \(r\) is the distance from the system to Earth.

We know that \(I \sim M R^2\), where \(M\) is the mass of the system while \(R\) is its characteristic radius (for example, a solid sphere has \(I = (2/5)  M R^2 \) --- the \(2/5\) factor is relevant but we will neglect it in this order-of-magnitude estimate).
If \(T\) is the characteristic timescale in which the components of the inertia tensor vary, we can estimate \(\ddot{I}\) as \(\ddot{I} \sim M R^2 / T^2 = M v^2\), where \(v\) is the typical velocity of the various parts of the system.

With this estimate, we have:
%
\begin{align}
h \sim \frac{G}{c^{4}r} M v^2 = \frac{GM}{c^2 r} \frac{v^2}{c^2} \sim \frac{R_s}{r} \frac{v^2}{c^2}
\,.
\end{align}

Let us compute this for a few simple examples:
\begin{enumerate}
    \item a car crash, with \(M \sim \SI{e3}{kg}\), \(v \sim \SI{100}{km/h}\), \(r \sim \SI{10}{m}\);
    \item a supernova explosion, with \(M \sim M_{\odot}\), \(v \sim \num{.2}c\), \(r \sim \SI{2}{kpc}\);
    \item a binary black hole system, with \(M \sim 50M_{\odot}\), \(v \sim \num{.1}c\), \(r \sim \SI{400}{Mpc}\).
\end{enumerate}

We shall use the \texttt{units} system\footnote{\url{https://docs.astropy.org/en/stable/units/index.html}} provided by the python library \texttt{astropy} in order to aid us in this computation:
we start out with the imports
\begin{lstlisting}[language=Python]
import astropy.units as u
from astropy.constants import codata2018 as ac
\end{lstlisting}

Now we may define a function yielding the desired estimate:
\begin{lstlisting}[language=Python]
@u.quantity_input(M='mass', D='length', v='speed')
def estimate_h(M, D, v) -> u.dimensionless_unscaled:
    h = ac.G * M / D / ac.c**2 * (v / ac.c)**2
    # the units system takes care of all the unit conversion for us
    # since we specified that we want the result to be a pure number
    return(h)

print(f'Car crash: {estimate_h(1e3*u.kg, 10*u.m, 100* u.km/u.hr):.0e}')
print(f'Supernova: {estimate_h(1*u.Msun, 2*u.kpc, .2 * ac.c):.0e}')
print(f'Binary BH: {estimate_h(50*u.Msun, 400*u.Mpc, .1 * ac.c):.0e}')
\end{lstlisting}
%
which yields as output
\begin{lstlisting}[language=Python]
Car crash: 6e-40
Supernova: 1e-18
Binary BH: 6e-23
\end{lstlisting}

The \texttt{u.quantity\_input} decorator is not strictly necessary, but this way the function will raise a very clear \texttt{UnitsError} if we try to give it something with the wrong dimensionality as an input.

% The supernova order of magnitude might be severely overestimated with this method:

\end{document}


%\nomenclature[]{GPS}{Global Positioning System}
%\nomenclature[]{WGS84}{World Geodetic System 1984}

\section{Generation of Waypoints}\label{sec:GenerationOfWaypoints}
We first address the issue of finding a discrete set of waypoints, referenced above in point 1 as $R$. We chose to formulate the problem using a discrete set of waypoints, rather than deal with the case of treating the region as continuous space, since it is much easier to accurately record sensor data when the RAV has settled at a given point.
%Discretising the space also allows the problem to be formulated in a manner that is easier to represent using software, since describing an arbitrary continuous region may take up a prohibitively large amount of memory.
%\begin{itemize}
    %\item It is more straightforward to describe the problem using a discrete set of points rather than a continuous one.
%    \item It is much easier to process sensor information if it is known exactly where this data has been captured. The RAVs may stop at each discrete waypoint to visit these locations. *Focus on this point, expand if possible*
%    \item The case of path-finding using discrete waypoints has a strong body of literature behind it
%    \item The RAVs run autopilot software which can guide them using the on-board GPS sensor
%\end{itemize}

%which are the center points of cells that partition the region of interest.
%\note{set of waypoints create a voronoi partition, might be worth talking about}

%\note{Above needs revision, will come back once rest of chapter has been fleshed out a bit more}
We began by assuming that the region which is to be surveyed, $R$, can be described by a polygon on the Cartesian plane, since it allows for a discrete representation by describing the coordinates of the corners of the polygon.
%As mentioned above, we favour statically recording images and sensor readings at fixed discrete locations will ensure the data can be accurately recorded and spatially referenced.
Given this polygon, the goal is to generate a set of points, $R$, which are a uniform distance from each other in the x and y directions and lie inside the polygonal grid. The set $R$ forms a regular tessellation of the region of interest. In order to do this, we employed the following methodology:
\begin{enumerate}
    \item Find the circum-rectangle that tightly bounds the polygon, which is oriented with the x-y plane. This is shown in \ref{fig:PolygonWithBoundingRect}
    \item Generate a set of grid points in the bounding rectangle. This is shown in \ref{fig:PolygonWithBoundingRectAndGridPoints}
    \item Prune the points that lie inside the rectangle but outside the polygon. This is shown in \ref{fig:PolygonWithBoundingRectAndGridPointsPruned}
\end{enumerate}

\vspace*{45mm}
\begin{figure}[H]
\centering
\subfloat[Arbitrary Polygonal Region]{
  \includegraphics[width=73mm]{Chapters/MultiAgentCoverage/Figs/Polygon.PNG}\label{fig:PolygonOnly}
}
\subfloat[Bounding Rectangle Found]{
  \includegraphics[width=73mm]{Chapters/MultiAgentCoverage/Figs/PolygonBoundingRect.PNG}\label{fig:PolygonWithBoundingRect}
}
\hspace{0mm}
\subfloat[Candidate Grid Points Generated in Bounding Rectangle]{
  \includegraphics[width=73mm]{Chapters/MultiAgentCoverage/Figs/PolygonBoundingRectGridPoints.PNG}\label{fig:PolygonWithBoundingRectAndGridPoints}
}
\subfloat[Grid Points Outside of Polygon Pruned]{
  \includegraphics[width=73mm]{Chapters/MultiAgentCoverage/Figs/PolygonBoundingRectGridPointsPruned.PNG}\label{fig:PolygonWithBoundingRectAndGridPointsPruned}
}
\caption{A visualisation of the steps involved in Algorithm \ref{alg:PointInPolygon}}
\label{fig:PointInPolygon}
\end{figure}

\begin{algorithm}[H]{}
\caption{Algorithm to Generate a Uniformly Spaced Grid of Points in an Arbitrary Polygon}
\label{alg:GridGeneration}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
%Input
\REQUIRE $ \newline R: \quad\text{ The set of (x, y) points defining the polygon which covers the region of interest}
\newline x\_spacing: \quad\text{ The desired spacing between points in the x direction}
\newline y\_spacing: \quad\text{ The desired spacing between points in the y direction}
$
%Output
\ENSURE $\newline grid\_points: \quad \text{ A set of uniformly spaced (x, y) points, which define a regular } \newline \text{ tessellation of the region of interest}$

\hfill\pagebreak
\STATE grid\_points $\leftarrow$ empty array

\STATE max\_x $\leftarrow$ maximum x value of all points in R
\STATE min\_x $\leftarrow$ minimum x value of all points in R
\STATE max\_y $\leftarrow$ maximum y value of all points in R
\STATE min\_y $\leftarrow$ minimum y value of all points in R

\STATE bounding\_rect $\leftarrow$ The tightest bounding rectangle which contains the polygon R defined by the points (min\_x, min\_y), (min\_x, max\_y), (max\_x, max\_y),(max\_x, min\_y).

\STATE no\_y\_points $\leftarrow \left \lfloor{\frac{max\_y - min\_y}{y\_spacing}}\right \rfloor$
\STATE no\_x\_points $\leftarrow \left \lfloor{\frac{max\_x - min\_x}{x\_spacing}}\right \rfloor$

\FOR{y\_spacing\_index = 0 to no\_y\_points}
\FOR{x\_spacing\_index = 0 to no\_x\_points}
\STATE p$\leftarrow$(min\_x+x\_spacing $\times$ x\_spacing\_index, min\_y+y\_spacing $\times$ y\_spacing\_index)
\IF{Point-in-Polygon(R, p)}
\STATE Add p to grid\_points
\ENDIF
\ENDFOR
\ENDFOR
\RETURN grid\_points
\end{algorithmic}
\end{algorithm}

%\par This procedure was devised with the aim of being straightforward to implement and modify. The algorithm used to carry out these steps is outlined in Algorithm \ref{alg:GridGeneration}, which we describe here.
We describe the grid point generation algorithm (Algorithm \ref{alg:GridGeneration}) here. First, the bounding circum-rectangle of the polygonal region of interest is constructed from the largest and smallest x and y coordinates of the points of the polygon, outlined in lines 2-6 and shown in Figure \ref{fig:PolygonWithBoundingRect}. Then candidate uniformly spaced grid points in the bounding rectangle are generated in lines 7-11, shown in Figure \ref{fig:PolygonWithBoundingRectAndGridPoints}. Finally in lines 12-13, a check is performed which adds the grid point to the set of grid point contained in the polygon if it passes a check, shown in Figure \ref{fig:PolygonWithBoundingRectAndGridPointsPruned}. This is done using the Point-in-Polygon routine which is provided separately in Algorithm \ref{alg:PointInPolygon}, with the details discussed in the next paragraph.

\begin{algorithm}[H]{}
%\caption{Crossing Test for Point in Polygon based on \cite{Shimrat1962Algorithms}}
\caption{Point-in-Polygon}
\label{alg:PointInPolygon}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
%Input
\REQUIRE $ \newline R: \quad \text{ The polygon which covers the region of interest}
%\newline R \quad \text{ The set of (x, y) points defining the polygon which covers the region of interest}
\newline P: \quad \text{ A point which will be tested for containment in the polygon }
$
%Output
\ENSURE $\newline \text{True if P is contained in R else False }$

\hfill\pagebreak
\STATE polygon\_points $\leftarrow$ The set of points defining the vertices of R
\IF{$P_X$ is greater than the largest value or less than the smallest value of the x coordinates of the points in $R$}
\RETURN False
\ELSIF{$P_Y$ is greater than the largest value or less than the smallest value of the y coordinates of the points in $R$}
\RETURN False

%\ELSIF{x coordinate of P is less than the smallest value of the x coordinate of all the points in R}
%\RETURN false
%\ELSIF{y coordinate of P is greater than the largest value of the y coordinate of all the points in R}
%\RETURN false
%\ELSIF{y coordinate of P is less than the smallest value of the y coordinate of all the points in R}
%\RETURN false

\ELSE
\STATE point\_in\_polygon $\leftarrow$ False
\STATE edges $\leftarrow$ the set of edges defining R
\FOR{each edge in edges}
\STATE P1 $\leftarrow$ the first point of edge
\STATE P2 $\leftarrow$ the second point of edge

\IF{($P_Y$ lies between $P1_y$ and  $P2_y$) \&
     $P_X$ is less than the x coordinate of the point of intersection between edge and the ray extended to +$\infty$ from $P$ in the +x direction}
\STATE point\_in\_polygon $\leftarrow \neg$ point\_in\_polygon
\ENDIF

\ENDFOR
\ENDIF
\RETURN point\_in\_polygon
\end{algorithmic}
\end{algorithm}

%\pagebreak
%\begin{figure}{r}{0.5\textwidth}
%\includegraphics[width=0.5\textwidth]{Chapters/MultiAgentCoverage/Figs/PointOutsidePolygon.PNG}\caption{Ray extended from point outside polygon intersects an even number of times}\label{fig:PointOutsidePolygon}
%\includegraphics[width=0.5\textwidth]{Chapters/MultiAgentCoverage/Figs/PointInsidePolygon.PNG}\caption{Ray extended from point inside polygon intersects an odd number of times}\label{fig:PointInsidePolygon}
%\end{figure}

\begin{figure}[h]%
    \centering
    \subfloat[Odd number of crossings\label{fig:oddCrossing}]{\includegraphics[width=9cm,height=6cm]{Chapters/MultiAgentCoverage/Figs/CrossingTestPos.PNG}}%
    %\vspace{2mm}
    \\
    \subfloat[Even number of crossings\label{fig:evenCrossing}]{\includegraphics[width=9cm,height=6cm]{Chapters/MultiAgentCoverage/Figs/CrossingTestNeg.PNG}}%
    \caption{Examples of a positive and negative results when applying the Crossing Test}%
    \label{fig:CrossingTest}%
\end{figure}

Algorithm \ref{alg:PointInPolygon} tests whether a point lies within a polygon, described by a set of edges. Its implementation uses the \textit{crossing test} \cite{Shimrat1962Algorithms}, which extends a ray from the point to be tested in the positive x-direction. If it crosses the boundary of the polygon an odd number of times, then it must be contained within the polygon, otherwise it must lie outside. This is illustrated in Figure \ref{fig:CrossingTest}. The implementation is provided in the Point-In-Polygon routine shown in Algorithm \ref{alg:PointInPolygon}.% The running time of this algorithm is dictated by the number of edges the polygon has and the size of the polygon relative to the desired tessellation spacing in the x and y directions. We did not make any optimizations other than the one outlined in lines 2-5 of Algorithm \ref{alg:PointInPolygon}, which checks whether the test point lies outside the largest and smallest x and y coordinates, but there is room to improve the running time significantly. This would be important if one is dealing with particularly large regions of interest or a relatively small spacing between grid points.

%\begin{figure}{}
%\subfloat[Ray extended from point outside polygon intersects an even number of times]{\includegraphics[width=60mm]{Chapters/MultiAgentCoverage/Figs/PointOutsidePolygon.PNG}\label{fig:PointOutsidePolygon}}
%\end{wrapfigure}
%\hspace{1em}
%\subfloat[Ray extended from point inside polygon intersects an odd number of times]{\includegraphics[width=60mm]{Chapters/MultiAgentCoverage/Figs/PointInsidePolygon.PNG}\label{fig:PointInsidePolygon}}
%\end{figure}

%From a practical perspective, the region specified is defined over the earth's surface, which is not planar. For small regions, it can be assumed that this region is planar, since at

%The generation of grid points takes this into account. The earth can be well described mathematically as an ellipsoid talk about WGS84

\subsection{Generating Waypoints as GPS Locations}
For the sake of real-world usage, it is necessary to refer to these points using some kind of reference coordinate system that RAVs can use. We provide a brief overview of how we accomplished this, without delving too far into Geographic Coordinate Systems (GCS). Since the \textit{Global Positioning System} (GPS) is by far the most common system that RAVs use for navigation, we chose to design an implementation based on the \textit{World Geodetic System 1984} (WGS84) coordinate system, which is the coordinate system that GPS relies upon. The WGS84 system was created by the US Department of Defence and is officially documented in the official government report entitled "\textit{Department of Defense World Geodetic System 1984 Its Definition and Relationships With Local Geodetic Systems}" \cite{ReportpreparedbytheDMAWGS84DevelopmentCommittee1991Department1984}. It assumes that the datum surface is an oblate spheroid.
%, and the coordinate system uses Greenwich as the starting point.
Coordinates are referenced using latitude, longitude and altitude, where longitude measurements range between [-180$^{\circ}$, 180$^{\circ}$], latitude measurements range between [-90$^{\circ}$, 90$^{\circ}$] and altitude measurements come in the form of meters above sea level. Greenwich is used as the \textit{prime meridian} for longitude, meaning Greenwich defines 0$^{\circ}$ longitude. The equator is used to define 0$^{\circ}$ latitude. In order to generate a grid of points in a bounding polygon as coordinates that can be referenced by the RAVs' GPS sensors, we had to make some modifications to the grid point generation algorithm outlined above. The main issue that arose was that the grid point generation algorithm assumes that the Cartesian coordinate system is used, which is not valid when assuming coordinates lie on a non-planar surface (the earth). As an example, we present results quoted from Robert G. Chamberlain, reviewed on the comp.infosystems.gis newsgroup in October 1996 \cite{GISL_LISTSERVER}:

"\textit{If the distance is less than about 20 km (12 mi) and the locations of the
 two points in Cartesian coordinates are X1,Y1 and X2,Y2 then using Pythogoras' theorem with Cartesian coordinates can generate errors of
\begin{enumerate}
    \item less than 30 meters (100 ft) for latitudes less than 70 degrees
    \item less than 20 meters ( 66 ft) for latitudes less than 50 degrees
    \item less than  9 meters ( 30 ft) for latitudes less than 30 degrees
\end{enumerate}}"

This is due to the non-uniform curvature of the earth and shows that the accuracy of the using Cartesian coordinates with Pythagoras' theorem depends on the latitude at which it is applied.
%We could have treated the WGS84 coordinates that make the bounding polygon defining the region of interest as a plane and continue using the unmodified Algorithm \ref{alg:GridGeneration}, but
For the sake of guaranteed accuracy we decided to use the methods which were first described by \citeauthor{Vincenty1975DirectEquations} \cite{Vincenty1975DirectEquations}, which gave a far superior accuracy:
\\
"\textit{The  latitudes of standpoints were from 0° to 80° in increments of 10' and the distances were in multiples of 2000 km up to 18000 km, which gave 81 test  lines. The maximum  disagreement  was  0·01 mm.}".
\\
Based on this, we made the following minor changes to the algorithm for use with WGS84 coordinates:
\begin{enumerate}
    \item When calculating distances, the \textit{inverse solution} \cite{Vincenty1975DirectEquations} to finding geodesics (shortest paths along the earth's surface) was used. We also used the \textit{direct solution} \cite{Vincenty1975DirectEquations} to find a destination given a start point, bearing and distance. These algorithms take into account the non-planar nature of the WGS84 coordinate system. The inverse solution can be used in place of subtraction of Cartesian Coordinates. It would replace the subtraction in lines 7 and 8 of Algorithm \ref{alg:GridGeneration} and line 12 of Algorithm \ref{alg:PointInPolygon}. The direct solution can be used in place of addition of distance to Cartesian coordinates and is used in line 11 of Algorithm \ref{alg:GridGeneration}.

    \item We created a specific WGS84 coordinate class, which can be used in place of regular Cartesian coordinates in Algorithms \ref{alg:GridGeneration} and \ref{alg:PointInPolygon}. We uploaded this to a publicly available  \href{https://github.com/DavidLSmyth/WGS84Coordinate}{Github repository}\footnote{\href {https://github.com/DavidLSmyth/WGS84Coordinate}{https://github.com/DavidLSmyth/WGS84Coordinate}} with an MIT licence. If the user is not interested in generating grids which have very accurately spaced points, they can use the Cartesian solution which approximates the region of interest as a plane, otherwise the solution using Vincenty's equations in the point above can be applied.
\end{enumerate}

%The code which allows the user to generate grids is hosted on github at <> \note{might be worth referencing how to pull it down using maven}

\subsection{User Interface and Results of Grid Generation Algorithm}\label{subsec:SceneSurveyingUI}
%to Facilitate Grid Generation
\begin{figure}[h]
\centering
\includegraphics[width=0.85\textwidth]{Chapters/MultiAgentCoverage/Figs/ShinyUI/UIWithButtons.PNG}
\caption{The UI developed to quickly generate uniformly spaced grid points in an arbitrary polygonal region to survey}
\label{fig:SceneSurveyingUI}
\end{figure}
We developed a User Interface (UI) in order to have the ability to quickly generate grids for use in simulations, as outlined in Section \ref{sec:SceneSurveying}. We also used the UI to visually validate that the grid generation code was performing as expected. We chose to use the  \href{https://shiny.rstudio.com/}{Shiny framework}\footnote{\href {https://shiny.rstudio.com/}{https://shiny.rstudio.com/}}, which is a web app development framework written in the \href{https://www.r-project.org/}{R language}\footnote{\href {https://www.r-project.org/}{https://www.r-project.org/}}.
%The Shiny framework is highly suited to prototyping web apps and abstracts away much of the more nuanced aspects of web development, at the cost of flexibility.
We used the \href{https://rstudio.github.io/leaflet/}{Leaflet Package}\footnote{\href {https://rstudio.github.io/leaflet/}{https://rstudio.github.io/leaflet/}}, which provides a high-level interface to the \href{https://wiki.openstreetmap.org/wiki/Develop}{Open Street Map}\footnote{\href {https://wiki.openstreetmap.org/wiki/Develop}{https://wiki.openstreetmap.org/wiki/Develop}} API to provide the interface to a map with WGS84 Coordinate reference system. We added an \textit{observeEvent} function to record when the user clicks on points on the map, adding an edge the previously clicked point to the current clicked point. The process of sequentially selecting the points on the map defining a polygonal region can be seen in Figure \ref{fig:AddClicks}.

\begin{figure}[h]
\centering
\subfloat{\includegraphics[width=72mm]{Chapters/MultiAgentCoverage/Figs/AdditionalClicks.PNG}}
%\end{wrapfigure}
\hspace{0.2em}
\subfloat{\includegraphics[width=72mm]{Chapters/MultiAgentCoverage/Figs/AdditionalClicksOne.PNG}}
\hspace{0.2em}
\subfloat{\includegraphics[width=72mm]{Chapters/MultiAgentCoverage/Figs/AdditionalClicksTwo.PNG}}
\caption{Creating the bounding polygon using the UI}
\label{fig:AddClicks}
\end{figure}

In order to actually generate and draw the grid points on the user interface, we added "Show planned waypoints" button, which can be seen in Figure \ref{fig:SceneSurveyingUI}. When this button is clicked, the polygon defining the region of interest that the user has selected is sent to the grid generation code, as well as the desired latitude and longitude spacing between the generated grid points. The grid points are generated and written to a file. The user interface then reads the points from the file and then overlays them on the map. Examples of visualisation of polygonal regions with grid points are shown in Figure \ref{fig:GridPointsOnUI}. We open-sourced this code with an MIT licence on Github \cite{SceneSurveyingUI}.

\begin{figure}[h]
\centering
%\subfloat[Grid points with a latitude spacing of 40m and a longitude spacing of 30m.]
\subfloat{\includegraphics[width=72mm, height=65mm]{Chapters/MultiAgentCoverage/Figs/RegionOne.PNG}}
%\end{wrapfigure}
\hspace{0.2em}
%\subfloat[Grid points with a latitude spacing of 30m and a longitude spacing of 25m.]
\subfloat{\includegraphics[width=72mm, height=65mm]{Chapters/MultiAgentCoverage/Figs/RegionTwo.PNG}}
\caption{Examples of generated grid points overlaid onto the UI}
\label{fig:GridPointsOnUI}
\end{figure}

%\note{Make sure to refer to target localisation}


\chapter{Heap Algorithms}
\Label{cha:heap}

The heap algorithms of the \cxx Standard
Library \cite[28.7.7]{cxx-17-draft}
were already part of \emph{\acsl by Example} from 2010--2012.
In this chapter we re-introduce them and discuss---based on the
bachelor thesis of one of the authors---the verification efforts in some
detail \cite{Lapawczyk_2016_bachelor}.

The \cxx standard\footnote{
  See \url{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf}
} introduces the concept of a \emph{heap} as follows:

\begin{small}
\begin{quote}
\begin{enumerate}
\item A \emph{heap} is a particular organization of elements in a range between two
random access iterators \inl{[a,b)}. Its two key properties are:
\begin{enumerate}
\item There is no element greater than \inl{*a} in the range and
\item \inl{*a} may be removed by \inl{pop_heap()}, or a new element added by \inl{push_heap()}, in
       $O(\log(N))$ time.
\end{enumerate}
\item These properties make heaps useful as priority queues.
\item \inl{make_heap()} converts a range into a heap and \inl{sort_heap()}
      turns a heap into an increasing sequence.
\end{enumerate}
\end{quote}
\end{small}

Figure~\ref{fig:heap-overview} gives an overview on the five heap algorithms
by means of an example.
Algorithms, which in a typical implementation are in a caller-callee relation, have the same color.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.85\linewidth]{Figures/heap-overview.pdf}
\caption{\Label{fig:heap-overview}Overview on heap algorithms}
\end{figure}

\clearpage

Roughly speaking, the algorithms from Figure~\ref{fig:heap-overview} have
the following behavior.

\begin{itemize}
\item In \S\ref{sec:heap-concepts} we briefly recapitulate basic
      heap concepts.

\item In \S\ref{sec:heap-acsl} we show how these heap concepts
      can be described in \acsl.

\item In \S\ref{sec:auxiliary-heap-functions} we verify two
      auxiliary heap functions.

\item The algorithms \isheapuntil and \isheap from
      \S\ref{sec:isheapuntil} and~\S\ref{sec:isheap}
      allow to test at run time whether a given array is arranged as a heap

\item The algorithm \pushheap from \S\ref{sec:pushheap} \emph{adds} an
        element to a given heap in such a way
        that resulting array is again a heap

\item The algorithm \popheap from \S\ref{sec:popheap}, on the other hand,
        \emph{removes} an element from a given heap in
        such a way that the resulting array is again a heap

\item The algorithm \makeheap from \S\ref{sec:makeheap} rearranges a given array
        into a heap.

\item Finally, the algorithm \sortheap from \S\ref{sec:sortheap} sorts a heap
        into an increasing range.
\end{itemize}

In \S\ref{sec:heap-concepts} we present in more detail how heaps are defined.
The \acsl logic functions and predicate that formalize the basic heap
properties of heaps are introduced in \S\ref{sec:heap-acsl}.

\clearpage

\input{heap/heap_concepts}
\input{heap/heap_acsl}
\input{heap/heap_parent_child}
\input{heap/is_heap_until}
\input{heap/is_heap}
\input{heap/fluctuations}
\input{heap/push_heap}
\input{heap/pop_heap}
\input{heap/make_heap}
\input{heap/sort_heap}


\section{Exogenous Model Specifications}
\label{appx: c}

\begin{table}[ht!]
    \caption{Exogenous Model Specifications}
    \label{table:1}
    \centering
    \begin{tabular}{|| c | c c c c c ||}
        \hline
        Model Reference & $\lambda_m:\lambda_w$  & $B_m,B_w$ & $F_m,F_w$ & $\delta$ & $u(\theta)$  \\ [0.5ex]
        \hline\hline
        \autoref{fig:swiping-rule}          & --       & 20         & Uniform(0,1) & 0.95       & Linear       \\
        \autoref{fig:discount-cs}           & --       & 20         & Uniform(0,1) & (0.87, 1)  & Linear       \\
        \autoref{fig:risk-cs}               & --       & 20         & Uniform(0,1) & 0.95       & CARA, with $r\in [-15,15]$         \\
        \autoref{fig:mkt-cs}                & 6:1      & 10         & Beta(2,2)    & 0.97       & Logarithmic  \\
        \autoref{fig:mkt-cs-bdiff}          & 6:1      & 10,40      & Beta(2,2)    & 0.97       & Logarithmic  \\
        \autoref{fig:abm-conv}              & 2:1      & 10         & Beta(2,2)    & 0.97       & Logarithmic  \\
        \autoref{fig:abm-conv-ssize}        & 1:1      & 10         & Beta(2,2)    & 0.97       & Logarithmic  \\
        \autoref{fig:abm-br}                & 2:1, 1:1 & 10         & Beta(2,2)    & 0.97       & Logarithmic  \\ [1ex]
        \hline
    \end{tabular}
\end{table}