\providecommand{\main}{..}
\documentclass[\main/thesis.tex]{subfiles}

\begin{document}
\graphicspath{{img/}{02_theory/img/}}

% \chapterimage{chapter_head_1.pdf}
\chapter{Position Estimation}

\section{Signal parameters}

There are two approaches for positioning: direct and two-step. In the direct approach, the signal is used for positioning itself. In the two-step approach, positioning is base on parameters extracted from the signal but not the signal itself. One consideration is that in two-step approach, parameters may be extracted from a similar but undesired signal; in the direct approach, it is possible to verify the signal's origin. The two-step approach imposes less complexity and is close in performance to the direct approach, os the two-step approach is more prevalent in practice and is the focus of this report.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{direct_positioning_vs_two_step_positioning}
    \caption{(a) Direct positioning, (b) Two-step positioning}
    \label{fig:direct_positioning_vs_two_step_positioning}
\end{figure}

\subsection{Received Signal Strength}
The strength of a received signal is decreased by path loss (PL) which is proportional to the distance between transmitter ana receiver. So we can estimate the range to target node by measuring RSS. Ideally, the RSS matches $\overline{P}(d)$ in the following:
\begin{equation}
    \overline{P}(d) = P\textsubscript{0}-10n\log_{10} \frac{d}{d\textsubscript{0}}
\end{equation}
where:
\begin{itemize}
    \item $n$ is passloss exponent
    \item $\overline{P}(d)$ is the received power at distance $d$
    \item $P\textsubscript{0}$ is the received signal at the reference distance
\end{itemize}

There are phenomena which affect the amount of PL. This first one is the multipath phenomena. Simply, it means that several components of one signal have followed some different paths to the receiver, experiencing different amounts of PL. We can overcome this problem by choosing a long enough interval for the following integration:
\begin{equation}
    P(d) = \frac{1}{T} \int_0^T \left| r(t) \right| ^2 dt
\end{equation}
where $P(d)$ is the received power and $r(t)$ is the received signal.

The second phenomenon is shadowing or large-scale fading. The main reason for this phenomenon is a changing environment over a long-distance propagation. The effect of shadowing is modeled with a log-normal random variable:

\begin{equation}
    \label{eq:received_signal_model}
    10\log_{10} P(d) \sim \mathcal{N}(\overline{P}(d), \sigma_{sh}^2)\
\end{equation}
where $\overline{P}(d)$ is the average received power and $\sigma_{sh}^2$ is the variance of a Gaussian random variable $\mathcal{N}$.

For this model \ref{eq:received_signal_model}, the Cramer-Rao lower bound (CRLB) for estimating distance can be expessed as:
\begin{equation}
    \sqrt{Var\{\hat{d}\}} \geq \frac{\ln{10}}{10} \frac{\sigma_{sh}}{n} d
\end{equation}

where $\hat{d}$ is an unbiased estimate of $d$. We observe that the bigger the PL exponent $n$ is, the smaller the lower bound is. In additional, a smaller distance $d$ and smaller $\sigma_{sh}$ gives a smaller lower bound.

In figure \ref{fig:limits_for_distance_estimation_based_on_rss_measurements}, the mininmum standard devariation $\sigma_{\hat{d}}=\sqrt{Var\{\hat{d}\}}$ of several channels are plotted. The PL exponents and the standard deviations of the shadowing are given in Table \ref{table:channel_parameters_for_the_environments}.

\begin{table}[htbp]
    \begin{tabularx}{1\textwidth} {
         >{\raggedright\arraybackslash}X
         >{\centering\arraybackslash}X
         >{\centering\arraybackslash}X }
            \hline \hline
            & n & $\sigma_{sh}$  \\
            \hline
            Residential LOS & 1.79 & 2.22  \\
            \hline
            Residential NLOS & 4.58 & 3.51 \\
            \hline
            Indoor office LOS & 1.63 & 1.90 \\
            \hline
            Indoor office NLOS & 3.07 & 3.90 \\
            \hline \hline
      \end{tabularx}
      \caption{Channel parameters for the environments}
      \label{table:channel_parameters_for_the_environments}
\end{table}

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.8\textwidth]{limits_for_distance_estimation_based_on_rss_measurements}
    \caption{Theoretical limits for distance estimation based on RSS measurements at different distances for various channel models}
    \label{fig:limits_for_distance_estimation_based_on_rss_measurements}
\end{figure}

\section{Time of arrival (TOA)}

The time of arrival (TOA) method gives us information about the distance between the target node and the source for which the position is known. The target node's position is on a circle of radius $d=c\tau$, for $c$ equal speed of light and $\tau$ equal time of arrival. The prerequisite of this information is a synchronization between the source and target node. The received signal at the source node is represented by:
\begin{equation}
    r(t) = \alpha(t-\tau) + n(t)
\end{equation}
where $\tau$ is the TOA, $\alpha$ is the channel coefficient and $n(t)$ is white Gaussian noise with zero mean and a spectral density of $\mathcal{N}_0/2$ watts per hertz for $\mathcal{N}$ is normal distribution. In order to extract TOA from received signal, we search for the maximum correlation between the shifted version of template signal ($s(t-\hat{\tau})$) and the received signal. The $\hat{\tau}$ which gives the peek correlation provides an estimation of the TOA. For signal model \ref{eq:received_signal_model} , the CRLB is:
\begin{equation}
    \sqrt{Var\{\hat{\tau}\}} \geq \frac{1}{2\sqrt{2}\pi\sqrt{SNR}\beta}
\end{equation}
where $\tau$ is the estimation of TOA, $SNR = \alpha^2 E / \mathcal{N}_0$ is the signal to noise ratio, $\beta$ is the effective signal bandwidth and $E$ is the signal energy. One important property of TOA is that, unlike RSS, its accuracy heavily depend on the bandwidth of the signal. Consequently, UWB systems can reach very precise ranging on he order of a few centimeters. Figure \ref{fig:toa_minimum_standard_deviation_versus_bw_snr} shows the effects of $SNR$ and band width on the accuracy of TOA estimation.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\textwidth]{toa_minimum_standard_deviation_versus_bw_snr}
    \caption{The minimum standard deviation versus SNR for various pulse widths}
    \label{fig:toa_minimum_standard_deviation_versus_bw_snr}
\end{figure}

\subsection{Time difference of arrival (TDOA)}

In this approach, the extracted parameter is the difference between the arrival time of the transmitted signal (from the target node) to two source nodes. This parameter, by multiplying TDOA by the speed of light, gives us an uncertainty of the target node's position in the shape of a hyperbola as shown:

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.5\textwidth]{tdoa_hyperbola}
    \caption{A TDOA measurement defines a hyperbola passing through the target node (gray node) with foci at the reference nodes (black nodes) }
    \label{fig:tdoa_hyperbola}
\end{figure}

The merit of TDOA in comparison with TOA is that there is no need for synchronization between source nodes and target nodes. Source nodes, however, do need to be synchronized. In the TOA base approach for measuring TDOA, TOA is measured at two source nodes which we call $\tau_1$ and $\tau_2$. As the source node and target node are not synchronized, there is a time offset in $\tau_1$ and $\tau_2$. Since the source are synchronized with themselves, this offset is equal in both measurements. Consequently, we can measure the TDOA as:
\begin{equation}
    \tau_{TDOA} = \tau_1 - \tau_2
\end{equation}
where $\tau_{TDOA}$ is the estimation of TDOA. In this approach, there is the same effect of bandwidth as in TOA measurements.
The second approach to measure the TDOA is using cross-correlation between two received signals. We know that there is some amount of offset between received signals so cross-correlation will reach maximum when one of the signals if shifted with correct offset. The cross-correlation equation is:
\begin{equation}
    \phi_{1,2}(\tau) = \frac{1}{T}\int_0^T r_1(t)r_2(t+\tau)dt
\end{equation}
where $r_1(t)$ and $r_2(t)$ are the received signals and $T$ is the observation interval. Then TDOA is estimated by:
\begin{equation}
    \tau_{TDOA}= \argmax_\tau \left| \phi_{1,2}(\tau) \right|
\end{equation}
where
\begin{equation}
    \argmax_x f(x) := \{x | \forall y: f(y) \leq f(x)\}
\end{equation}
The correlation approach work well for white noise and single path channels but in the case of multi-path channel or colored noise, its performance decrease significantly.

\subsection{Angle of arrival (AOA)}

AOA is another parameter of the signal which includes include information about position target node. In this case, we estimate the angle, $\psi$, between an array of antennas and the target node regards to the delay between arrival of the signal to the antenna. AOA fives us an uncertainty region with the shape of a line, as depicted in figure \ref{fig:aoa_uncertainty_region}.

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.3\textwidth]{aoa_uncertainty_region}
    \caption{The reference node (black node) measures the AOA and determines the angle $\psi$ between itself and the target node (gray node)  }
    \label{fig:aoa_uncertainty_region}
\end{figure}

The antenna array may be in different arrangements, the simplest one is the uniform linear array (ULA) as shown in figure \ref{fig:aoa_signal_arrival_at_a_ula}. In case of ULA, the delay between the arrival of the signals to the consecutive antenna is given by:
\begin{equation}
    \tau = \frac{l\sin{\psi}}{c}
\end{equation}

where $\tau$ is the delay, $l$ is the distance between consequent antennas, $\psi$ is the AOA and $c$ is the speed of light.

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.3\textwidth]{aoa_signal_arrival_at_a_ula}
    \caption{Signal arrival at a ULA, and relation between arrival time differences and AOA}
    \label{fig:aoa_signal_arrival_at_a_ula}
\end{figure}

In order to measure the accuracy if the AOA approach, we formulate the received signal to each $N_a$ antennas by:

\begin{equation}
    r_i(t) = \alpha s(t-\tau_i) + n_i(t)
\end{equation}

where $\alpha$ is the coefficient of the channel, $\tau_i$ is the delay for the $i$th antenna and $n_i(t)$ is the white Gaussian noise with zero mean and spectral density of $\mathcal{N}_0/2$. We can express the delay of the signal received by the $i$th antenna as:
\begin{equation}
    \tau_i \approx \frac{d}{c} + \frac{l_i \sin{\psi}}{c}
\end{equation}
where
\begin{equation}
    l_i = l \left( \frac{N_a+1}{2} - i \right)
\end{equation}
and $d$ is the distance between the target node and the center of the antenna array. The CRLB for estimating $\psi$ is:
\begin{equation}
    \sqrt{Var\{\hat{\psi}\}} \geq \frac{\sqrt{3}c}{\sqrt{2}\pi\sqrt{SNR}\beta\sqrt{N_a(N_a^2-1)}l\cos{\psi}}
\end{equation}
We observe that the accuracy of the AOA method is dependent on $SNR$, $\beta$, $N_a$, $l$ and $\psi$. Our main interest is the effect of bandwidth on the accuracy since we use signals width very small pulse in time in the UWB systems. Figure \ref{fig:aoa_crlb_ for_angle_of_arrival_versus_snr} depicts the effect of the pulse width and SNR on CRLB for angle of arrival. In this case, other parameters are assume to be fixed.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\textwidth]{aoa_crlb_for_angle_of_arrival_versus_snr}
    \caption{CRLB for the angle of arrival versus SNR for several pulse-widths}
    \label{fig:aoa_crlb_ for_angle_of_arrival_versus_snr}
\end{figure}
% We observe that increasing bandwidth (decreasing pulse-width) has a significant effect on the accuracy. In other words, with high bandwidth, we can gain high accuracy even with low SNR. Consequently, UWB is a very good candidate for the AOA approach.

% In figure \ref{fig:aoa_crlb_versus_psi_for_various_pulse_widths}, the effect of AOA on its estimation accuracy is depicted. We observe that even for wide-band signals, the accuracy will be decrease dramatically for angles bigger than 1 rad (57 degrees) or smaller than 1 rad. As a suggestion, we can use several antenna arrays and weight the estimation of each array by the inverse of estimated angle.
% \begin{figure}[!htbp]
%     \centering
%     \includegraphics[width=0.8\textwidth]{aoa_crlb_versus_psi_for_various_pulse_widths}
%     \caption{CRLB for the angle of arrival versus SNR for several pulse-widths}
%     \label{fig:aoa_crlb_versus_psi_for_various_pulse_widths}
% \end{figure}

\section{Trilateration}
True-range multilateration is a method to determine the location of a movable vehicle or stationary point in space using multiple ranges (distances) between the vehicle/point and multiple spatially-separated known locations (often termed 'stations'). The name is derived from trilateration, the geometrical problem of determining an unknown position on a plane based on the distance to other two known vertices of a triangle (the length of two sides). True range multilateration is both a mathematical topic and an applied technique used in several fields. A practical application involving a fixed location is the trilateration method of surveying. Applications involving vehicle location are termed navigation when on-board persons/equipment are informed of its location, and are termed surveillance when off-vehicle entities are informed of the vehicle's location.

Three Cartesian dimensions, three measured slant ranges
There are multiple algorithms that solve the 3-D Cartesian true range multilateration problem directly (i.e., in closed-form) – e.g., Fang.[11] Moreover, one can adopt closed-form algorithms developed for pseudo range multilateration.[12][8] Bancroft's algorithm[13] (adapted) employs vectors, which is an advantage in some situations.

Fig. 2 3-D True Range Multilateration Scenario. C1, C2 and C3 are known centers of spheres in the x,y plane. P is point whose (x,y,z) coordinates are desired based on its ranges to C1, C2 and C3.
The simplest algorithm corresponds to the sphere centers in Fig. 2. The figure  is the plane containing C1, C2 and C3.

\end{document}


% !TEX root=/home/tavant/these/manuscript/src/manuscript.tex

\section{Elements of the 2D PIC-MCC simulations}
  \label{sec-elements}
  \subsection{The PIC simulations}
    \label{subsec-intro}
    The \ac{PIC} simulation models particles moving freely on a grid.
    The grid is used to compute the electric field, in the electrostatic approximation by solving the Poisson equation
    \begin{equation}
      \label{eq-poisson}
      \Delta \phi = - \frac{\rho}{\epsilon_0}
    \end{equation}
    where $\phi$ is the electric potential, $\rho$ is the charge density, and $\epsilon_0$ the vacuum permittivity.
    If the electrostatic approximation is not correct, one needs to solve the Maxwell equations.

    The particles move following the Lorentz forces
    \begin{equation}
      \label{eq-Lor}
      m \deriv{\vec{v}}{t} = q \vect{E} + q \vec{v} \times \vec{B}
    \end{equation}
    with $m$ and $q$, the particle mass and electric charge, respectively.
    The numerical particles followed in the simulations correspond to $q_f$ physical particles, with
    \begin{equation}
      q_f = \frac{n V}{\Npc}
    \end{equation}
    with $n$ the particle density, $V$ the volume of a cell, and $\Npc$ the number of numerical particles in a cell.
    A large enough number of particles is needed in order to obtain physical results.
    Indeed, an insufficient number of particles leads to numerical heating \cite{ueda1994}.
    Usually, a minimum of 100 particles per cell is used, but recent results seem to encourage to use more particles \cite{janhunen2018}.

  \subsection{The Monte Carlo collisions}

    In \ac{PIC} simulations, collisions between charged and neutral particles can be modeled by binary collision, but this approach is computationally costly.
    Instead, a Monte-Carlo algorithm can be used \cite{vahedi1995}.
    This approach is very efficient and allows scattering, momentum transfer, and ionization to be consistently modeled.
    The propellant used in \ac{HET} is \ac{Xe}.
    The cross-sections used for modeling \ac{Xe} or other gases collisions are taken from the {\sc LXCat} database project \cite{LXCat_web,pancheshnyi2012}.
    Unless otherwise stated, the elastic, inelastic scattering and ionization reactions listed in \cref{tab-reactXe} are used.
    The cross-section values are summarized in \cref{fig-xexsection}.

    \begin{table}[hbt]
      \ra{1.3}
      \centering
      \caption{Reactions for xenon used in the PIC simulations}
      \label{tab-reactXe}
      \begin{tabular}{@{}lll@{}}  \toprule
        Reaction & Threshold & Reference\\ \midrule
        {\it Elastic scattering} & &\\
        e + Xe = e + Xe   & --   & \cite{Lxcat_Xe,Lxcat_Xe2} \\
        {\it Excitation} & &\\
        e + Xe = e + Xe$^*$   & 8.315eV   & \cite{Lxcat_Xe,Lxcat_Xe2} \\
        e + Xe = e + Xe$^*$   & 9.447eV   & \cite{Lxcat_Xe,Lxcat_Xe2} \\
        e + Xe = e + Xe$^*$   & 9.917eV   & \cite{Lxcat_Xe,Lxcat_Xe2} \\
        e + Xe = e + Xe$^*$   & 11.7eV    & \cite{Lxcat_Xe,Lxcat_Xe2} \\
        {\it Ionization} & &\\
        e + Xe = e + Xe$^+$   & 12.13eV   & \cite{Lxcat_Xe,Lxcat_Xe2} \\
        \bottomrule
      \end{tabular}
    \end{table}

    \begin{figure}[hbt]
      \centering
      \includegraphics[width=\defaultwidth]{figure/xenon_cross_section.pdf}
      \caption{Cross section values used in the Monte Carlo procedure \cite{Lxcat_Xe,Lxcat_Xe2}.}
      \label{fig-xexsection}
    \end{figure}

    In the context of this thesis, and except precised otherwise, the `\ac{PIC} simulation' refers to the `\ac{PIC}-\ac{MCC} simulation'.
    In the case where no collision is modeled, we also call it `collisionless simulation'.
\section{Numerical implementation of the Particle in cell simulation}

  \LPPic is an explicit electrostatic \ac{PIC}-\ac{MCC} simulation code.
  Every time-step, the simulation loop presented in \cref{fig-picloop} is computed.
  The different steps constituting the PIC-loop are described in the next subsections.
  \begin{figure}[hbt]
    \centering
    \smartdiagramset{circular distance=4.5cm,
    module minimum width=3.5cm,
    text width=3cm,
    arrow tip=to}
    \smartdiagram[circular diagram:clockwise]{Particle Motion ,Boundary,Collision,Density weighting, Poisson Equation, Field weighting}
    \caption{\acs{PIC}-\acs{MCC} loop executed every time step.}
    \label{fig-picloop}
  \end{figure}

  \subsection{Numerical characteristics}
    In \ac{PIC} simulations, there are two kinds of data used\string:
    \begin{itemize}
      \item Particles (electrons and ions; neutrals can be followed as well but not in the version of \LPPic I have used for my Ph.D.),
      \item Mesh, also named fields (densities, electric and magnetic fields, and so on).
    \end{itemize}

    \paragraph{Particles\\}
    For each particle, its position $\vec{x}$ and its velocity $\vec{v}$ are known.
    In most \ac{PIC}-\ac{MCC} simulations, the three directions of the velocity vector are followed in order to take into account scattering.
    It is abbreviated as \acs{3V}.
    The particle positions and velocity are not discretized, except to the numerical floating-point precision.

    One numerical particle represents a large number of physical particles.
    Therefore they can be called \emph{superparticle} or \emph{macroparticle} in the literature.
    We will simply call them particle, unless the context requires clarification.

    \paragraph{Fields\\}
    The fields are defined at the center of each cell of the mesh.
    The charge density $\rho$ is computed by depositing the particle on the mesh, using the Cloud-in-cell model \cite{birdsall1991}.
    The electric field at the position of the particle is also obtained by bilinear interpolation.
    The mesh dimension defines the dimension of the simulation.
    It is usual to find \acs{1D}\acs{3V} or \acs{2D}\acs{3V} \ac{PIC} simulations, for particles with 3 directions on the velocity but one or two dimension(s) in space, respectively.

    Early studies on the stability of the \ac{PIC} simulations gave conditions for the cell size and the time step as functions of the physical parameters \citep{birdsall1991,turner2013}
    \begin{align}
      \dt  \ope &\leq 0.2,  \label{eq-dt_limit} \\
      \dx &\leq 0.5 \lde, \label{eq-dx_limit}
    \end{align}
    where
    \begin{equation} \label{eq-def_ope}
      \ope =  \sqrt{\frac{e^2 n_e}{ \epsilon_0 m_e}}
    \end{equation}
    is the electron plasma frequency, and
    \nomenclature[Q]{\ensuremath{ \ope}}{  Electron plasma frequency $\ope =  \sqrt{\frac{e^2 n_e}{ \epsilon_0 m_e}}$}
    \begin{equation} \label{eq-def_lde}
        \lde = \sqrt{\frac{ \epsilon_0 e\Te}{e^2 n_e}}
    \end{equation}
    is the Debye length.
    We recall the relation $e \Te = k_B T_e$, with $T_e$ in Kelvin and $\Te$ in volt.
    \footnote{The Debye length usually refers to the spatial scale over with a charge is screened by the other charged particles. }
    The conditions \ref{eq-dt_limit} and \ref{eq-dx_limit} can be combined to produce
    \begin{equation} \label{eq-CFL}
      \frac{\dt}{\dx}\sqrt{\frac{e \Te}{m_e}} \leq 0.4,
    \end{equation}
    which can be seen as a constraint on the thermal electron velocity that must be much less than one cell per time step.
    Hence, condition \ref{eq-CFL} is usually referred as the CFL condition.

    As presented before in \cref{subsec-intro}, a third condition applies on the ratio between the superparticle density and the physical particle density.
    No universal rule exists, as a wide range of values may be appropriate to different contexts \citep{turner2006,turner2013}.
    A general consensus in low temperature plasma agrees on using approximately 100 numerical particles per cell but a careful convergence study has to be carried out to demonstrate that it is enough for the studied conditions.

    \subsection{The large memory requirement}
    Because of the particle discretization, the memory requirement for \ac{PIC} simulation can be tremendous.
    For instance, we estimate here the numerical parameters of a \acs{2D} \ac{HET} simulation.
    With a density $n_e = \sn{3}{17}\,\per\meter\cubed$, and an electron temperature $\Te=20\,\volt$, the Debye length is $\lde=\sn{6}{-5}\,\meter$.
    The simulation of a square domain of $2\,\centi\meter$ side needs a mesh of approximately 650 cells in each direction, hence more than $\sn{4}{5}$ cells in total.
    With 100 electrons and 100 ions per cell, it is 85 million particles that are simulated.

    For every particle, we need to store at least the two values of position and the three values of velocity, thus five real numbers.
    Using the double-precision floating-point format, it corresponds to approximately 400 bits per particles.
    In total, around 33 billion bits, or 4 Go (gigaoctet) are needed to store the particles !
    To give a reference to the reader, a modern laptop has a RAM of 8 Go.
    Adding a third dimension of size 2 cm increases the number of cells to 300 millions, and the memory requirement for the particles to 2.5 Terabytes of memory.

    \subsection{Solving the particles motion}
    The interaction of the motion equation \cref{eq-Lor} is different for magnetized and non-magnetized particles.
    For non-magnetized particles, we use the leapfrog scheme \cite{birdsall1991}
    \begin{align}\label{eq-leapfrog}
      \vect{v}^t &= \vect{v}^{t-1} + \frac{q}{m} \vect{E} \dt, \\
      \vect{x}^t &= \vect{x}^{t-1} + \vect{v}^t \dt, \label{eq-leapfrogtwo}
    \end{align}
    with the superscript $t$ designing the time step, $q$ and $m$ the particle electric charge and mass, $\vect{E}$ the electric field at the particle position, and \dt the time step duration.

    \paragraph{Magnetized particles}
    For magnetized particles, we use a modification of the leapfrog algorithm proposed by Boris \cite{boris1970}.
    It corresponds to an operator splitting between the electrostatic acceleration and the magnetic rotation.
    This splitting is described below\string:

    \begin{enumerate}
      \item accelerate the particle during $\frac{\dt}{2}$\string: $\vect{v}^{t-\frac{\dt}{2}} = \vect{v}^{t-1} + \frac{q}{m} \vect{E} \frac{\dt}{2}$
      \item rotate the particle velocity with the magnetic field
      \item accelerate the particle during $\frac{\dt}{2}$\string: $\vect{v}^t = \vect{v}^{t-\frac{\dt}{2}} + \frac{q}{m} \vect{E} \frac{\dt}{2}$
    \end{enumerate}

    It is important to note that the leapfrog and the Boris schemes induce a shift of $\frac{\dt}{2}$ between the position and the velocity\citep{birdsall1991}, as illustrated in \cref{fig-leapfrog}.
    This shift can lead to erroneous diagnostics when computing moments of the particles distribution.
    For instance, the mean velocity of a set of $N$ particles at time $t$ is computed as\string:
    \begin{equation} \label{eq-meanv}
      \mean{\vect{v}}^t = \frac{1}{N} \sum_i^N \lp \vect{v_i}^t + \frac{q}{m} \vect{E_i} \frac{\dt}{2} \rp.
    \end{equation}
    Other moments like the mean energy or heat flux follow the same correction.
    We can see that the error between $\mean{\vect{v}}$ defined above and
    $$ \tilde{\vect{v}} = \frac{1}{N} \sum_i^N  \vect{v_i}^t $$
    is
    $$ \mean{\vect{v}} - \tilde{\vect{v}} =\frac{q \dt}{2 m}  \frac{1}{N}  \sum_i^N  \vect{E_i} .$$
    Hence, the error in the diagnostic is larger in the region of large electric field (as in the sheaths).

    \begin{figure}[hbt]
      \centering
      \includegraphics[width=0.8\textwidth]{leapfrog.png}
      \caption{Illustration of the shift between the particle velocity and position due to the leapfrog scheme \cref{eq-leapfrog,eq-leapfrogtwo}.}
      \label{fig-leapfrog}
    \end{figure}
  \subsection{Poisson equation solver}
  \label{subsec-poissonintro}

    In order to compute the electric field due to the particle charge density, the Poisson equation \cref{eq-poisson}  needs to be discretized over the mesh.
    We can directly discretize the differential operator by using the finite volume approach over a cell of the mesh.
    The formal discretization is developed in \cref{sec-diel}, for the particular case of taking into account the presence of dielectric boundaries.

    In \ac{1D}, the obtained linear system is tridiagonal.
    It can be solved directly using {\sc Thomas}' algorithm, which stores the Gauss elimination's coefficient.
    In \ac{2D}, the linear system is pentadiagonal.
    A direct solver, like the $LU$ decomposition, would require a large amount of memory to store the factorization matrices.
    On the other hand, as the time step is usually small in \ac{PIC} simulation, we expect the plasma potential $\phi$ not to change rapidly.
    Hence, an iterative solver using the previous solution as an initial guess seems more reasonable from both the memory storage and the computational time.
    The choice of the Poisson solver is discussed later in \cref{sec-lppic}.


\chapter{Pipelines \& Algorithms}
\pagenumbering{arabic} \setcounter{page}{13}

This section examines the two most widely used pipelines that are used to generate OTUs and ASVs. The first pipeline employs the Divisive Amplicon Denoising Algorithm (DADA), which produces the ASVs. The second utilises the Unweighted UniFrac Algorithm (implemented through Mothur), which is used to make OTUs.

\section{DADA}
The DADA is a hierarchical clustering algorithm that works by removing PCR-amplified artefacts from the sequenced reads. The algorithm's goal is to infer the genotypes of the microbes present in the sample along with their error rates \cite{ref17}. The algorithm operates until the genotypes and errors rates from the noisy sequenced data converge to a mutually consistent set. DADA was compared against the AmpliconNoise algorithm, which it outperformed on various parameters. However, DADA assumes each error to be statistically independent, and there might be a case where a single DNA might produce many artefacts which could induce non-independent errors.\newline

\subsection*{Divisive Amplicon Denoising Algorithm}
The p-values ($p_{y}$,$p_{\alpha}$) forms the basis of the algorithms, through which it iteratively updates the partition set of sequence B and the nucleotide error probabilities T \cite{ref17}. After t iterations the partition set of sequence and the nucleotide error probabilities updates to $B^{t}$ and $T^{t}$. There are three levels of nesting in the algorithm and each of them is repeated until convergence. Beginning with $T^{0}$, the maximum likelihood nucleotide error probabilities are provided partition $B^{0}$ in a unique cluster, and the outermost loop recursively upgrade B \& T until T converges. The following loop begins with the partition, $B^{t}$ = $B^{0}$, and attaches blocks to $B^{t}$ until the $p_{y}$ and $p_{\alpha}$ does not permit rejection of model at common significance levels \cite{ref17}. If statistically significant families exist that supports both p-values, then a new cluster is formed. After this inner-most loop boosts the probability by reassigning each sequence to the block that would generate the most considerable required amount of reads of that sequence, this proceeds until sequences discontinue renewing clusters \cite{ref17}.\newline

\begin{figure}
  \centering
  \includegraphics[width=15cm]{../figures/Figure4.png}
  \caption{Schematic representation of DADA algorithm}
  \label{fig:figure4}
\end{figure}

The DADA is currently running in its second version, available as an R library, "DADA2". The DADA2 employ a novel QC-informed model of Illumina amplicon errors. The DADA2 pipeline commences with the command "fastqFilter()", which trims adaptors, removes short sequences and ambiguous bases. DADA can apply this to both paired-end and single-end reads \cite{ref17}. This step is accompanied by the "derep()" function, which performs the dereplication of the data. Lastly, the DADA's de-ionising algorithm is implemented, which is explained in  \ref{fig:figure4}; it estimates genotypes and calculates errors. One can also remove chimaeras by performing Needleman-Wunsch global alignment using the function "isBimeraDenovo()".

\section{MOTHUR}
The MOTHUR is a comprehensive tool written in C++ using Object-Oriented-Programming (OOPs) fundamentals. It integrates the algorithms from previous packages/tools, including SONS, DOTUR, and TreeClimber \cite{ref18}. MOTHUR operates on various clustering algorithms such as the nearest neighbour, OptiCLust, Unweighted-pair group method using average linkages (UPGMA). Here I discuss the OptiCLust algorithm, which is the default algorithm of MOTHUR that produces OTUs \cite{ref18}.

\subsection*{OptiClust}

\begin{figure}[!hb]
  \centering
  \includegraphics[width=10cm, height=12cm]{../figures/Figure5.png}
  \caption{Schematic representation of OptiClust algorithm}
  \label{fig:figure5}
\end{figure}

The OptiCLust begins by calculating the pairwise distance between all the sequences. It then removes the sequences having a pairwise distance less than a threshold. Once the filtered set is obtained, it seeds by assigning each sequence a distinct OTU \cite{ref18}. The convergence initiates by calculating Matthew's Correlation Coefficient (MCC) between the first singleton OTU and the other sequences. The MCC for singleton OTU itself is zero; therefore, it chooses the different available sequences that increase the MCC value. If the change in the MCC is the same between the two sequences then, it randomly selected either of the two. This step is repeated until the entire sequence set is converted into OTUs [Figure \ref{fig:figure5}]. To initiate OptiClust algorithm requires either a phylip-formatted distance matrix or a column-formatted distance matrix \cite{ref18}. The "cluster" command initiates the clustering process that creates the OTUs.


\subsubsection*{Quality of the New Design}
Upon having established the structure of the new database schemas, we then examined whether they are in TNF or BCNF (see section \ref{relational_databases}).
This was done by examining the functional dependencies of the relations seen in equation \ref{eq:newDatabaseRelationalModel}.

The \textit{occursIn} relation is in TNF.
This is verified when examining the functional dependency of its composite primary key:
\begin{equation*}
 \{text,article\_id\}\rightarrow \{count\}
\end{equation*}

A unique article cannot identify the text and number of times the text occurs in the article.
Similarly, the number of times the text occurs in the article and the $article\_id$ cannot identify the text of the word.

The \textit{article} relation is in TNF.
This is seen when considering the functional dependency of its single, primary key:
\begin{equation*}
    \{article\_id\} \rightarrow \{title, publisher\_name,total\_words\, file\_path\}
\end{equation*}

One could consider using only \textit{title} as key.
However, some article titles could occur multiple times; this is realized when considering the domain area of the \knox{} Search Engine.
For instance, the title "The first snow of the season" could occur every year for the same publisher.
Thus, the composite, primary key $\{ publisher,article\_title \}$ would not guaranteee uniqueness either.
One should notice that each of the files in the Search Engine (represented by the $file\_path$ attribute) can contain multiple articles.
An example of a $file\_path$ could be a path to a newspaper in PDF format, containing many articles about the weather.
Therefore neither $\{file\_path\}$ nor $\{ file\_path, article\_title \}$ guarantee unique primary keys.

The \textit{word} and the \textit{publisher} relations are in BCNF trivially:
\begin{equation*}
    \{ text\} \rightarrow \{text\} \textit{\ and\ } \{ publisher\_name \} \rightarrow \{ publisher\_name\}
\end{equation*}


\chapter{Conclusion}\label{ch:conclusion}
\section{Lessons from this paper}
Through this paper we have explored how mathematics can be used to model complex social systems from the evolution of cooperation to economic inequality. In particular we have focused on how to represent notions of agency and interrelations to develop two models of revolution inspired by mathematical epidemiology. The first compartmental model was able to provide many insights into the phenomena. However its clear restrictions showed the necessity of a more complex model. This led to the development of an ABM that could account for network dynamics and the inherent stochasticity of real life.

\section{Further work}
\subsection{Interesting theoretical extensions}
%This provides a suggestion for the general direction of research in this area. However there are also many smaller, lower-hanging fruit that would provide stimulating papers.
There are many possible routes for expanding this model. One possibility would be to more thoroughly investigate the role of supernodes in catalysing revolutions. For example Mohamed Bouazizi's highly symbolic self-immolation sparked the Tunisian revolution. More generally, people such as journalists and politicians have a unique reach and ability to spread a message. Modelling this would involve more careful study of how properties of scale-free graphs affect the revolution model as well as considering a probability distribution over the agents' $\beta$ values.\\
\\
Another option is to introduce the need for multiple contacts to be made before people truly take an idea on. This is based on the observation that social influence works quite differently to how diseases spread. In a paper on social contagion Thomas House justifies this approach\cite{thomas-house}:
\begin{quote}
[Experimental studies show] there is significant evidence that the form of ‘infection’ in social influence is different to that in a biological epidemic. The important difference is the number of exposures to infection that an individual must receive before becoming infected: in biological infection only one source of infection is required for a non-zero probability of infection, whereas in social influence multiple sources are required.
\end{quote}
Dodds and Watts have already built a model adopting the SIS model to this form of infection\cite{dodds-watts}. Future compartmental models of revolution should seek to accommodate a similar approach. It would also be both interesting and simple to adopt this idea into future ABMs too.\\
\\
A more data science flavoured extension would involve attempts to find more finely grained time series data on a revolution than currently available datasets\cite{NAVCO-2.0}. One interesting option would be to analyse sentiment data on Twitter during a revolution such as the Arab Spring. Whilst this is potentially very messy data it could be revealing. There is also some debate about the extent to which the Arab Spring was a `social media revolution'\cite{egypt-five-years}. A quantitative analysis of Twitter data throughout the Arab Spring would shed a light on this question.
%\\
%\\
%Specifically to ABMs, it would be revealing to perform this on a much larger network to more accurately model a population. To do so the algorithm would have to be improved. One way to do so would be to adopt a Hastings style algorithm.

\subsection{A suggestion for the general direction for the mathematical study of revolution}
The rigorous approach of Chenoweth's \textit{Why Civil Resistance Works: The Strategic Logic of Nonviolent Conflict}\cite{logic-non-violence} provides an important contribution to the quantitative analysis of revolutions. This text and accompanying dataset give a firm understanding of what the majority of successful revolutions in the last century have looked like: non-violent, democratic and broad-based. However, the text mainly offers a \textit{how}. The next step is to offer a \textit{why}.\\
\\
The goal of quantitative revolutionary research right now should be to account for these statistical findings. I believe a strong approach to explain their results theoretically is to pursue an epidemiologically-inspired route. The obvious next step in this direction would be to create a more nuanced ABM which is `tuned' to the data provided in the NAVCO dataset\cite{NAVCO-2.0}. This would involve including parameters such as the regime's legitimacy and the support of foreign states for the revolutionary campaign as inputs. In this way a desirable model would fuse the epidemiologically inspired models introduced in this paper with the global parameters present in Epstein's civil violence model\cite{epstein} and the hard data of the NAVCO dataset.


\subsection{ROT13}

Rotate 13. It is its own inverse.

\subsection{Atbash}

Revese the alphabet. It is its own inverse.


\documentclass[12pt,titlepage]{article}
\textwidth 468pt
\textheight 648pt
\voffset=-0.5in
%\evensidemargin=0pt
\oddsidemargin=0pt
\topmargin=0mm
\parskip 15pt
\parindent 0pt
\setlength{\rightskip}{0pt}
\setlength{\floatsep}{24pt}
\usepackage{graphicx}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%
\section{Smagrinsky model}
Conservation of mass:
\begin{equation}
    \frac{\partial \bar{\rho}^m}{\partial t} + \frac{\partial \bar{\rho}^m \tilde{u}_j^m}
    {\partial x_j}=0
\label{eq:lesmass}
\end{equation}

Conservation of momentum:
\begin{eqnarray}
    \lefteqn{\frac{\partial (\bar{\rho}^m \tilde{u}_i^m)}{\partial t} +
    \frac{\partial \bar{\rho}^m \tilde{u}_i^m \tilde{u}_j^m}{\partial x_j} =
    \theta^m \frac{\partial \tilde{\sigma}_{ij}}{\partial x_j} +\bar{\rho}^m \tilde{g}_i\nonumber}\\
    & & +\frac{\partial \theta^m (\tilde{\sigma}_{ij}^m-\tilde{\sigma}_{ij})}{\partial x_j}
    +\sum_{l=1}^N \tilde{f}^{lm}
    -\frac{\partial{\bar{\rho}^m (\widetilde{u_i^m u_j^m}-\tilde{u}_i^m \tilde{u}_j^m})}{\partial x_j}
\label{eq:lesmom}
\end{eqnarray}

\begin{displaymath}
\tau_{ij}=\bar{\rho}^m(\widetilde{u_i^m u_j^m}-\tilde{u}_i^m \tilde{u}_j^m) =
           - 2 \bar{\rho} \nu_t (\tilde{S}_{ij}-\frac{1}{3} \delta_{ij}\tilde{S}_{kk})
	   + \frac{1}{3} \delta_{ij}\tau_{kk}
\end{displaymath}

\begin{equation}
\nu_t = (C_s \Delta)^2\tilde{S} \label{eq:turbviscosity}
\end{equation}

$\tilde{S}_{ij}$ is the large scale strain rate tensor given by,
\begin{displaymath}
\tilde{S}_{ij}=\frac{1}{2} (\frac{\partial \tilde{u}_i^m}{\partial x_j}
               +\frac{\partial \tilde{u}_j^m}{\partial x_i})
\end{displaymath}
where $\tilde{S}$ is the resolved shear stress and is given by
\begin{displaymath}
\tilde{S}=\sqrt{2 \tilde{S}_{ij} \tilde{S}_{ij}}
\end{displaymath}

So the effective stress tensor $\tau^{eff}$
\begin{displaymath}
\tau_{ij}^{eff}=2 \mu_{eff} (\tilde{S}_{ij}-\frac{1}{3} \delta_{ij}\tilde{S}_{kk})
                + \frac{1}{3} \delta_{ij}\tau_{kk}
\end{displaymath}

With the isotropic part omitted, the SGS stresses is included in the governing equations
by replacing the molecular viscosity with
effective viscosity where $\mu_{eff} = \mu + \mu_{t}$.

\begin{eqnarray}
\lefteqn{\int_s \nabla \theta \tau_f dS = \int_s \nabla \theta (\mu + \mu_{t})_f
(2 S_{ij}-\frac{2}{3}\frac{\partial{u_k}}{\partial{x_k}}\delta_{ij})dS\nonumber}\\
& = & \int_s \nabla \theta (\mu + \rho\nu_{t})_f(2 S_{ij}-\frac{2}{3}\frac{\partial{u_k}}
 {\partial{x_k}}\delta_{ij})dS\nonumber
\end{eqnarray}

It need viscosity at the face center value $\nu_f$ to calculate $\tau_f$.
\begin{displaymath}
\nu_f=\frac{2(\nu_{c+}\nu_{c-})}{\nu_{c+}+\nu_{c-}}
\end{displaymath}

\begin{eqnarray}
\lefteqn{\nu_t^c = (C_s \Delta)^2\tilde{S}= (C_s \Delta)^2\sqrt{2 \tilde{S}_{ij}^c \tilde{S}_{ij}^c}\nonumber}\\
& & =(C_s\Delta)^2\sqrt{2(S_{11}^2+S_{22}^2+S_{33}^2+S_{12}S_{12}+S_{21}S_{21}+S_{13}S_{13}
     +S_{31}S_{31}+S_{23}S_{23}+S_{32}S_{32})}\nonumber\\
& & =(C_s\Delta)^2\sqrt{2(S_{11}^2+S_{22}^2+S_{33}^2+2(S_{12}S_{12}+S_{13}S_{13}+S_{23}S_{23}))}
\end{eqnarray}

\begin{displaymath}
\tilde{S}_{ij}^c=\frac{1}{2} (\frac{\partial \tilde{u}_i^f}{\partial x_j}
               +\frac{\partial \tilde{u}_j^f}{\partial x_i})
\end{displaymath}

\begin{displaymath}
\tilde{S}_{11}^c=\frac{\partial \tilde{u}^f}{\partial x}=\frac{\tilde{u_+}^f-\tilde{u_-}^f}{\Delta x}
\end{displaymath}
\begin{displaymath}
\tilde{S}_{22}^c=\frac{\partial \tilde{v}^f}{\partial y}=\frac{\tilde{v_+}^f-\tilde{v_-}^f}{\Delta y}
\end{displaymath}
\begin{displaymath}
\tilde{S}_{33}^c=\frac{\partial \tilde{w}^f}{\partial z}=\frac{\tilde{w_+}^f-\tilde{w_-}^f}{\Delta z}
\end{displaymath}
\begin{displaymath}
\tilde{S}_{12}^c=\frac{1}{2} (\frac{\partial \tilde{u}^f}{\partial y}+\frac{\partial \tilde{v}^f}{\partial x})
                =\frac{1}{2} (\frac{\tilde{u_+}^f-\tilde{u_-}^f}{\Delta y}
		 +\frac{\tilde{v_+}^f-\tilde{v_-}^f}{\Delta  x})
\end{displaymath}
\begin{displaymath}
\tilde{S}_{13}^c=\frac{1}{2} (\frac{\partial \tilde{u}^f}{\partial z}+\frac{\partial \tilde{w}^f}{\partial x})
                =\frac{1}{2} (\frac{\tilde{u_+}^f-\tilde{u_-}^f}{\Delta z}
		 +\frac{\tilde{w_+}^f-\tilde{w_-}^f}{\Delta  x})
\end{displaymath}
\begin{displaymath}
\tilde{S}_{23}^c=\frac{1}{2} (\frac{\partial \tilde{v}^f}{\partial z}+\frac{\partial \tilde{w}^f}{\partial y})
                =\frac{1}{2} (\frac{\tilde{v_+}^f-\tilde{v_-}^f}{\Delta z}
		 +\frac{\tilde{w_+}^f-\tilde{w_-}^f}{\Delta  y})
\end{displaymath}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Dynamic model}

To apply test filter $\hat{\Delta}=2\Delta$, we get

{\setlength\arraycolsep{2pt}
\begin{eqnarray}
\hat{\bar{u}}_{i,j,k} & = & \frac{1}{8} \bar{u}_{i  ,j  ,k  }+{} \nonumber\\
              & & {}    \frac{1}{16}\bar{u}_{i-1,j  ,k  }+\frac{1}{16}\bar{u}_{i+1,j,  k  } +
                        \frac{1}{16}\bar{u}_{i  ,j-1,k  }+\frac{1}{16}\bar{u}_{i  ,j+1,k  } +{} \nonumber\\
	      & & {} 	\frac{1}{32}\bar{u}_{i-1,j-1,k  }+\frac{1}{32}\bar{u}_{i+1,j-1,k  } +
	                \frac{1}{32}\bar{u}_{i-1,j+1,k  }+\frac{1}{32}\bar{u}_{i+1,j+1,k  } +{} \nonumber\\
  	      & & {}    \frac{1}{16}\bar{u}_{i,  j,  k-1}+ {} \nonumber\\
	      & & {}    \frac{1}{32}\bar{u}_{i-1,j,  k-1}+\frac{1}{32}\bar{u}_{i+1,j,  k-1} +
	                \frac{1}{32}\bar{u}_{i,  j-1,k-1}+\frac{1}{32}\bar{u}_{i,  j+1,k-1} +{} \nonumber\\
	      & & {}    \frac{1}{64}\bar{u}_{i-1,j-1,k-1}+\frac{1}{64}\bar{u}_{i+1,j-1,k-1} +
	                \frac{1}{64}\bar{u}_{i-1,j+1,k-1}+\frac{1}{64}\bar{u}_{i+1,j+1,k-1} +{} \nonumber\\
	      & & {}    \frac{1}{16}\bar{u}_{i,  j,  k+1}+{} \nonumber\\
	      & & {}    \frac{1}{32}\bar{u}_{i-1,j,  k+1}+\frac{1}{32}\bar{u}_{i+1,j,  k+1} +
	                \frac{1}{32}\bar{u}_{i,  j-1,k+1}+\frac{1}{32}\bar{u}_{i,  j+1,k+1} +{} \nonumber\\
	      & & {}    \frac{1}{64}\bar{u}_{i-1,j-1,k+1}+\frac{1}{64}\bar{u}_{i+1,j-1,k+1} +
	                \frac{1}{64}\bar{u}_{i-1,j+1,k+1}+\frac{1}{64}\bar{u}_{i+1,j+1,k+1}\nonumber
\end{eqnarray}}

\begin{displaymath}
\tau_{ij}=\bar{\rho}(\widetilde{u_i u_j}-\tilde{u}_i \tilde{u}_j)
        =\overline{\rho u_i u_j}-(\frac{\overline{\rho u_i} \overline{\rho u_j}}{\bar{\rho}})
\end{displaymath}

\begin{displaymath}
T_{ij} =\hat{\bar{\rho}}(\widehat{\overline{u_i u_j}}-\hat{\bar{u}}_i \hat{\bar{u}}_j)
       =\widehat{\overline{\rho u_i u_j}}- (\frac{\widehat{\overline{\rho u_i}}
\widehat{\overline{\rho u_j}}}{\hat{\bar{\rho}}})
\end{displaymath}
The difference between this tensor $T$ and the
filtered value of $\tau$ can be written in terms of quantities that can be resolved:

\begin{displaymath}
L_{ij}=T_{ij} - \hat{\tau_{ij}} = \widehat{(\frac{\overline{\rho u_i} \overline{\rho
u_j}}{\bar{\rho}})}-(\frac{\widehat{\overline{\rho u_i}} \widehat{\overline{\rho
u_j}}}{\hat{\bar{\rho}}})
=\widehat{(\bar{\rho}\tilde{u_i}\tilde{u_j})}-\frac{\widehat{\bar{\rho}\tilde{u_i}}
 \widehat{\bar{\rho}\tilde{u_j}}}{\hat{\bar{\rho}}}
\end{displaymath}

we can write out the Smagorinsky model for each filter

\begin{displaymath}
\tau_{ij}-\frac{1}{3} \delta_{ij}\tau_{kk}= - 2 \bar{\rho}(C_s \Delta)^2\tilde{S}
(\tilde{S}_{ij}-\frac{1}{3} \delta_{ij}\tilde{S}_{kk})
\end{displaymath}
\begin{displaymath}
T_{ij}-\frac{1}{3} \delta_{ij}T_{kk}= - 2\hat{\bar{\rho}}(C_s \hat{\Delta})^2
\hat{\tilde{S}} (\hat{\tilde{S}}_{ij}-\frac{1}{3} \delta_{ij}\hat{\tilde{S}}_{kk})
\end{displaymath}

Subtracting of the test-scale average of $\tau_{ij}$ from $T_{ij}$, we get

\begin{equation}
L_{ij} - \frac{1}{3} \delta_{ij}L_{kk} = 2 \hat{\bar{\rho}}(C_s
\Delta)^2\widehat{\tilde{S} (\tilde{S}_{ij}-\frac{1}{3} \delta_{ij}\tilde{S}_{kk})}
-2\hat{\bar{\rho}}(C_s\hat{\Delta})^2\hat{\tilde{S}} (\hat{\tilde{S_{ij}}}-\frac{1}{3}
\delta_{ij}\hat{\tilde{S}}_{kk}) = C_s^2M_{ij}
\label{eq:lij}
\end{equation}

where
\begin{displaymath}
M_{ij} =\alpha_{ij}-\hat{\beta}_{ij} = 2\hat{\bar{\rho}}(\Delta)^2\widehat{\tilde{S}
(\tilde{S}_{ij}-\frac{1}{3} \delta_{ij}\tilde{S}_{kk})}
-2\hat{\bar{\rho}}(\hat{\Delta})^2\hat{\tilde{S}} (\hat{\tilde{S_{ij}}}-\frac{1}{3}
\delta_{ij}\hat{\tilde{S}}_{kk})
\end{displaymath}

\begin{displaymath}
\alpha_{ij}=-2\hat{\bar{\rho}}(\hat{\Delta})^2\hat{\tilde{S}}
(\hat{\tilde{S_{ij}}}-\frac{1}{3} \delta_{ij}\hat{\tilde{S}}_{kk})
\end{displaymath}

\begin{displaymath}
\beta_{ij}=-2 \bar{\rho}(\Delta)^2\tilde{S}
(\tilde{S}_{ij}-\frac{1}{3} \delta_{ij}\tilde{S}_{kk})
\end{displaymath}

Equation \ref{eq:lij} is an overdetermined but closed system of equations for the
Smagorinsky constant $C_s$. The most common method is to use the
least-squares solution described by Lilly to minimize the difference
between the closure assumption and the resolved stresses.

\begin{displaymath}
C_s^2=\frac{L_{ij}M_{ij}}{M_{ij}M_{ij}}
\end{displaymath}

$C_s^2$ can be negative, and developers of the model
claim this provides a backscatter model. However, often in practice this term is
truncated to zero to inhibit the potential for diverging solutions. Sometimes the
numerator and denominator are averaged over some homogeneous region to avoid
excessively large values of $C_s$. This has been found to be necessary for stability.
Alternatively, isolated large values may simply be truncated.

\begin{displaymath}
L_{ij}M_{ij}=L_{11}M_{11}+L_{22}M_{22}+L_{33}M_{33}+2(L_{12}M_{12}+L_{13}M_{13}+L_{23}M_{23})
\end{displaymath}

\begin{displaymath}
M_{ij}M_{ij}=M_{11}M_{11}+M_{22}M_{22}+M_{33}M_{33}+2(M_{12}M_{12}+M_{13}M_{13}+M_{23}M_{23})
\end{displaymath}

\end{document}


\section{In Brief}

\emph{Algorithm portfolio} methods \cite{Huberman1997Economics} use information
about solvers and problem instances to allocate computational resources among
multiple solvers, attempting to maximize the time spent on those well suited to
each instance. Portfolio methods such as SATzilla \cite{Xu2008SATzilla} have
proved increasingly effective in satisfiability.

An algorithm portfolio must decide which solvers to run and for how long to run
them. These decisions rely entirely on expectations about solver behavior.

The {\tt borg} solver attempts to to learn predictable aspects of solver
behavior---such as how likely a solver is to succeed if it has previously
failed---given data on the successes and failures of solvers on many problem
instances. The version of this solver submitted to the 2010 pseudo-Boolean
competition, {\tt borg-pb-10.05.30}, assumes a specific \emph{latent class}
model of solver behavior, a mixture of Dirichlet compound multinomial (DCM)
distributions, which is used to identify groups of similar problem instances.
This model is examined in detail by Silverthorn and Miikkulainen
(2010)\nocite{Silverthorn2010latent}. It captures the basic correlations
between solvers, runs, and problem instances, as well as the tendency of solver
outcomes to recur. Unlike the classifier employed by SATzilla, the model
considers only the success or failure of each past solver run; it does
\emph{not} consider instance feature information.

This version of {\tt borg-pb} combines the DCM mixture model with a
deterministic greedy action selection policy, which yields a fixed execution
schedule followed for every problem instance. This policy choice is also
discussed further by Silverthorn and Miikulainen (2010).


\section{Protocol Parameters}
\label{sec:protocol-parameters}

The rules for the ledger depend on several parameters contained in the $\PParams$ type,
defined in \cite{byron_ledger_spec}.
The parameters are listed in Figure~\ref{fig:defs:protocol-parameters},
the first ten of which below are common to the Byron era.
We will explain the significance of each parameter as it comes up in
the calculations used in transition rules.

The type $\Coin$ is defined as an alias for the integers.
Negative values will not be allowed in UTxO outputs or reward accounts,
and $\Z$ is only chosen over $\N$ for its additive inverses.

Six global constants are defined.
As global constants, these values can only be changed by updating the software.
The constants $\SlotsPerEpoch$ and $\SlotsPerKESPeriod$
represent the number of slots in an epoch/KES period (for a brief explanation
of a KES period, see Section \ref{sec:crypto-primitives-shelley}).
The constants $\SlotsPrior$ and $\StartRewards$ concern the chain stability.
The maximum number of time a KES key can be evolved before a pool operator
must create a new operational certificate is given by $\MaxKESEvo$.
\textbf{Note that if } $\MaxKESEvo$
\textbf{is changed, the KES signature format may have to change as well.}

Finally, $\Quorum$ determines the quorum amount needed for votes on the
protocol parameter updates and the application version updates.

Some helper functions are defined in Figure~\ref{fig:defs:protocol-parameters-helpers}.
The $\fun{minfee}$ function calculates the minimum fee that must be paid by a transaction.
This value depends on the protocol parameters and the size of the transaction.

Two time related types are introduced, $\Epoch$ and $\type{Duration}$.
A $\type{Duration}$ is the difference between two slots, as given by $\slotminus{}{}$.

Lastly, there are two functions, $\fun{epoch}$ and $\fun{firstSlot}$ for converting
between epochs and slots and one function $\fun{kesPeriod}$ for getting the cycle of a slot.

\begin{figure*}[htb]
  \emph{Abstract types}
  %
  \begin{equation*}
    \begin{array}{r@{~\in~}lr}
      \var{dur} & \Duration & \text{difference between slots}\\
      \var{epoch} & \Epoch & \text{epoch} \\
      \var{kesPeriod} & \KESPeriod & \text{KES period} \\
    \end{array}
  \end{equation*}
  %
  \emph{Derived types}
  %
  \begin{equation*}
    \begin{array}{r@{~\in~}l@{\qquad=\qquad}lr}
      \var{pp}
      & \PParams
      & \Ppm \mapsto \Value
      & \text{protocol parameter map}
      \\
      \var{coin}
      & \Coin
      & \Z
      & \text{unit of value}
      \\
      \var{pv}
      & \ProtVer
      & \N\times\N\times\N
      & \text{protocol version}
    \end{array}
  \end{equation*}
  %
  \emph{Protocol Parameters}
  %
  \begin{equation*}
      \begin{array}{r@{~\in~}lr}
        \var{a} \mapsto \Z & \PParams & \text{min fee factor}\\
        \var{b} \mapsto \Z & \PParams & \text{min fee constant}\\
        \var{maxBlockSize} \mapsto \N & \PParams & \text{max block body size}\\
        \var{maxTxSize} \mapsto \N & \PParams & \text{max transaction size}\\
        \var{maxHeaderSize} \mapsto \N & \PParams & \text{max block header size}\\
        \var{keyDeposit} \mapsto \Coin & \PParams & \text{stake credential deposit}\\
        \var{keyMinRefund} \mapsto \unitInterval & \PParams & \text{stake credential min refund}\\
        \var{keyDecayRate} \mapsto \nonnegReals & \PParams & \text{stake credential decay rate}\\
        \var{poolDeposit} \mapsto \Coin & \PParams & \text{stake pool deposit}\\
        \var{poolMinRefund} \mapsto \unitInterval & \PParams & \text{stake pool min refund}\\
        \var{poolDecayRate} \mapsto \nonnegReals & \PParams & \text{stake pool decay rate}\\
        \var{E_{max}} \mapsto \Epoch & \PParams & \text{epoch bound on pool retirement}\\
        \var{n_{opt}} \mapsto \Npos & \PParams & \text{desired number of pools}\\
        \var{a_0} \mapsto \posReals & \PParams & \text{pool influence}\\
        \tau \mapsto \unitInterval & \PParams & \text{treasury expansion}\\
        \rho \mapsto \unitInterval & \PParams & \text{monetary expansion}\\
        \var{activeSlotCoeff} \mapsto \unitInterval & \PParams & f\text{ in \cite{ouroboros_praos}}\\
        \var{d} \mapsto \{0,~0.1,~0.2,~\ldots,~1\} & \PParams & \text{decentralization parameter}\\
        \var{extraEntropy} \mapsto \Seed & \PParams & \text{extra entropy}\\
        \var{pv} \mapsto \ProtVer & \PParams & \text{protocol version}\\
      \end{array}
  \end{equation*}
  %
  \emph{Accessor Functions}
  %
  \begin{center}
    \fun{a},
    \fun{b},
    \fun{maxBlockSize},
    \fun{maxTxSize},
    \fun{maxHeaderSize},
    \fun{keyDeposit},
    \fun{keyMinRefund},
    \fun{keyDecayRate},
    \fun{poolDeposit},
    \fun{poolMinRefund},
    \fun{poolDecayRate},
    \fun{emax},
    \fun{nopt},
    \fun{influence},
    \fun{tau},
    \fun{rho},
    \fun{activeSlotCoeff},
    \fun{d},
    \fun{extraEntropy},
    \fun{pv}
  \end{center}
  %
  \emph{Abstract Functions}
  %
  \begin{equation*}
    \begin{array}{r@{~\in~}lr}
      (\slotminus{}{}) & \Slot \to \Slot \to \Duration
                       & \text{duration between slots}
    \end{array}
  \end{equation*}
  %
  \emph{Global Constants}
  %
  \begin{equation*}
    \begin{array}{r@{~\in~}lr}
      \SlotsPerEpoch & \N & \text{slots per epoch} \\
      \SlotsPerKESPeriod & \N & \text{slots per KES period} \\
      \SlotsPrior & \Duration & \tau\text{ in \cite{ouroboros_praos}}\\
      \StartRewards & \Duration & \text{duration to start reward calculations}\\
      \MaxKESEvo & \N & \text{maximum KES key evolutions}\\
      \Quorum & \N & \text{quorum for update system votes}\\
    \end{array}
  \end{equation*}
  %
  \caption{Definitions Used in Protocol Parameters}
  \label{fig:defs:protocol-parameters}
\end{figure*}

\begin{figure*}[htb]
  \emph{Helper Functions}
  %
  \begin{align*}
    \fun{minfee} & \in \PParams \to \Tx \to \Coin & \text{minimum fee}\\
    \fun{minfee} & ~\var{pp}~\var{tx} =
    (\fun{a}~\var{pp}) \cdot \fun{txSize}~\var{tx} + (\fun{b}~\var{pp})
    \\
    \\
    \fun{epoch} & \in ~ \Slot \to \Epoch & \text{epoch of a slot}
    \\
    \fun{epoch} & ~\var{slot} = \var{slot}~/~\SlotsPerEpoch
    \\
    \\
    \fun{firstSlot} & \in ~ \Epoch \to \Slot
               & \text{first slot of an epoch}
    \\
    \fun{firstSlot} & ~\var{e} = \var{e}~\cdot~\SlotsPerEpoch
    \\
    \\
    \fun{kesPeriod} & \in ~ \Slot \to \KESPeriod & \text{KES period of a slot}
    \\
    \fun{kesPeriod} & ~\var{slot} = \var{slot}~/~\SlotsPerKESPeriod
  \end{align*}
  %
  \caption{Helper functions for the Protocol Parameters}
  \label{fig:defs:protocol-parameters-helpers}
\end{figure*}

\clearpage


\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage{filecontents}
\usepackage{csquotes}
\usepackage{graphicx}

\usepackage[colorlinks=false]{hyperref}
\usepackage[backend=bibtex,style=chem-angew,citestyle=numeric-comp,articletitle=true,hyperref=true,url=true]{biblatex}
\addbibresource{biblio.bib}
\usepackage{titlesec}
\usepackage{tocloft}

\begin{filecontents}{biblio.bib}
@article{Iványi+2014+54+1,
author = {Antal Iványi},
doi = {doi:10.2478/ausm-2014-0005},
url = {https://doi.org/10.2478/ausm-2014-0005},
title = {Leader election in synchronous networks},
journal = {Acta Universitatis Sapientiae, Mathematica},
number = {1},
volume = {5},
year = {2014},
pages = {54--1}
}
@article{10.1145/359024.359029,
author = {Hirschberg, D. S. and Sinclair, J. B.},
title = {Decentralized Extrema-Finding in Circular Configurations of Processors},
year = {1980},
issue_date = {Nov. 1980},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
volume = {23},
number = {11},
issn = {0001-0782},
url = {https://doi.org/10.1145/359024.359029},
doi = {10.1145/359024.359029},
abstract = {This note presents an efficient algorithm, requiring O(n log n) message passes, for finding the largest (or smallest) of a set of n uniquely numbered processors arranged in a circle, in which no central controller exists and the number of processors is not known a priori.},
journal = {Commun. ACM},
month = {nov},
pages = {627–628},
numpages = {2},
keywords = {distributed system, operating systems, decentralized algorithms}
}
\end{filecontents}

\begin{document}
\section{Leader election in synchronised undirected ring}
The goal is to elect a leader in an undirected ring with $n$ nodes, that communicate in synchronous rounds. We assume that the processors are identical, except for unique identifiers. The size of the network is unknown. Each node has a list of its neighbours in an arbitrary order.\par
The most straightforward solution is to make every node send its identifier to both neighbours. By passing the identifiers around processors can choose the node with the highest identifier to be the leader. This algorithm requires only $O(n)$ rounds, but it needs $O(n^2)$ messages to be sent. Here we present a synchronous version \cite{Iványi+2014+54+1} of an algorithm presented in 1980 by Hirschberg and Sinclair \cite{10.1145/359024.359029}, which only requires $O(n\log n)$ messages.

\section{The algorithm}
The idea is that nodes initiate messages that are passed around in both directions along paths of predetermined length (which are successive powers of 2). In the first round every processor sends a message containing its identifier, length 1 and an information that the message is going out. Then in every round they check for messages from both neighbours. There are five main cases:
\begin{enumerate}
    \item If the identifier in the message is higher than the processor's identifier:
    \begin{enumerate}
        \item If the message already visited the predetermined number of nodes, then we send it back, with the information that it's coming back.
        \item If the message has not yet visited the predetermined number of nodes or is already coming back, then we pass it to the next processor lowering its length by 1.
    \end{enumerate}
    \item If the identifier in the message is lower than the processor's identifier, then the message is ignored.
    \item If the identifier in the message is equal to the processor's identifier and the message is going out, then we win the election and now need to send an ending message to both neighbours.
    \item If the identifier in both messages is equal to the processor's identifier and the messages are coming back, then we initiate a new message with double the length of the previously initiated message and send it to both neighbours.
    \item If the message is an end message, we pass it to the next processor and ignore the other one.
\end{enumerate}

\section{Correctness}
Let $v$ be the node with the highest identifier. Any node that receives a message from $v$ must have a lower identifier. That means it will have to pass this message further or send it back to the source. It follows that every message with a length lower than $n$ will come back to $v$, so after $\lceil\log n\rceil$ initiated messages $v$ will send one with a length at least $n$. This message will visit $v$ again without being sent back at any point, which means $v$ will be declared the leader.\par
On the other hand for any node $w\neq v$ it is impossible to be declared the leader, because there exists $k<n$ such that a message with length $k$ sent from $w$ will visit $v$, where it will be ignored. Every such node will be relaying messages until it receives a stop message originating from the leader.

\section{Complexity analysis}
\begin{theorem}
Number of rounds is $O(n)$.
\end{theorem}
\begin{proof}
If a message with length $l$ is not ignored at some point, it must come back exactly in $2l$ rounds. Every node starts with a message with length 1 and every time the message comes back, a new one with double the length is initiated. We know that a leader is elected after receiving a message with length $2^{\lceil\log n\rceil}$ originating from itself. So the number of rounds needed for the leader to find out it won is bounded by:
$$2(1+2+\dots+2^{\lceil\log n\rceil})\leqslant 8n$$
At this point only $\lceil\frac{n}{2}\rceil$ rounds are needed for other nodes to receive the end message from the leader, so the number of rounds is clearly linear.
\end{proof}

\begin{theorem}
Number of messages is $O(n\log n)$.
\end{theorem}
\begin{proof}
A processor initiates a message with length $2^i$ only if it is not defeated by a processor within distance $2^{i-1}$, so within any group of $2^{i-1}+1$ processors only one will initiate a message with length $2^i$. As a result of that initiation at most $4\cdot2^i$ messages will be passed, because every message is sent in two directions and will either travel $2^i$ edges and return or will be ignored within the first $2^i$ steps. As mentioned before no message will have a length higher than $2^{\lceil\log n\rceil}$, so the total number of messages is bounded by:
$$4(1\cdot n +2\cdot\lceil\frac{n}{2}\rceil+4\cdot\lceil\frac{n}{3}\rceil+\dots+2^i\cdot\lceil\frac{n}{2^{i-1}+1}\rceil+\dots+2^{\lceil\log n\rceil}\cdot\lceil\frac{n}{2^{\lceil\log n\rceil-1}+1}\rceil)$$
Each of the $1+\lceil\log n\rceil$ terms is bounded by $2n$, so the number of messages is not greater than $8(n+n\log n)\in O(n\log n)$.
\end{proof}

\printbibliography
\end{document}


% envir.tex
% part of the VertEgg documentation
%
\chapter{Working in the MATLAB/Octave Environment}

MATLAB\index{MATLAB} and Octave\index{Octave} offer command-line
oriented interactive environments for numerical computations, data
analysis and visualisation. They also provide high level programming
languages. These programmes, called \emph{M-files}\index{M-files}, come
in two flavours, \emph{scripts} which are sequences of commands
executed in batch, and \emph{functions} which can take and return
arguments. Functions can also have local variables.  M-files may be
viewed as extensions of the basic system.  A collection of M-files for
a specific area is called a \emph{toolbox}\index{toolbox}.  For marine
research for example, there exists a free toolbox for analysis of
physical oceanographic data, named SEAWATER\index{SEAWATER}
\citep{morg94}.

The basic environments and the programming languages are quite
compatible. They provide the same basic data structure, arrays of
dimension up to two (scalars, vectors, matrices).  This makes it
possible to write M-files that work equally well for both systems. The
systems have simple but powerful systems for online help.
The main difference between the systems is the much stronger graphic
capabilities of MATLAB.

Octave is documented in \citep{eato95}.  MATLAB is documented in user
and reference manuals, there is also a nice little primer \citep{sigm94}.

\section{Implementation of the VertEgg Toolbox}

The geometric setup of the problem is basic for all other
work. This setup is therefore given by a set of global variables
which can be accessed in the work space and by all functions in the toolbox.

They are declared by the script \edbi{ve\_init} which
contain the following statements.
\begin{verbatim}
  global Ncell   % Number of grid cells
  global dz      % Vertical step size  [m]
  global Hcol    % Depth of water column [m]
  global ZE      % Ncell-vector of egg-point depths [m]
  global ZF      % Ncell+1-vector of flux-point depths [m]
\end{verbatim}
\index{Ncell@\texttt{Ncell}}\index{dz@\texttt{dz}}
\index{Hcol@\texttt{Hcol}}\index{ZE@\texttt{ZE}}
\index{ZF@\texttt{ZF}}

Given the depth $\edb{Hcol} = H$ and the grid height $\edb{dz} =
\Delta z$, the rest of the values can be calculated.
This is done by the function \edb{ve\_grid(Hcol,dz)}.
The vector $\mbox{\edb{ZE(i)}} = \bar z_i$ and
$\mbox{\edb{ZF(i)}} = z_i$ as defined
in chapter ....

The commands \edb{ve\_init} and \edbi{ve\_grid} can be reissued at any
time. The only limitation is that \edb{ve\_init} must be called once before
\edb{ve\_grid} and nearly all other VertEgg statements.

Many (but not all) of the commands have names starting with \edb{ve\_},
to not be mixed up with commands in the basic systems or other
toolboxes. This may be done more consequently in future versions.

A discretized egg distribution is represented by a column vector
of length \edb{Ncell}. The elements are cell averages.
A matrix of size $\edb{Ncell} \times \edb{n}$
can be viewed as a collection of \edb{n} distributions. The commands
in VertEgg and most general MATLAB/Octave commands work on
distributions as a whole. For example, plotting the vertical profile
is done by the command \edb{plot(A,ZE)}.

The vector languages give a nice environment for working on 1D
problems such as vertical distributions. For larger problems in 2D or
3D the limitation to 2D array\footnote{The restriction to 2D arrays is
removed in MATLAB version 5} and the performance penalty of an
interpreted language make MATLAB/Octave less interesting.
Even for 1D problems there are certain tricks that must be used to
gain acceptable performance. The most important is to use vector
constructs instead of loops. For instance, to compute the central
diffusive flux approximation (\ref{eq:centdifflux}) in Fortran 77
requires the loop.
\begin{verbatim}
      DO 11 I = 2, NCELL
        FDIFF(I) = - K(I) * (A(I-1) - A(I))
   11 CONTINUE
\end{verbatim}
A similar loop is also possible in MATLAB/Octave,
 but much better performance is achieved by the vector subscript
\begin{verbatim}
  Fdiff(2:Ncell) = - K(2:Ncell) * (A(1:Ncell-1) - A(2:Ncell)).
\end{verbatim}
Under Octave, the variable \edb{do\_fortran\_indexing} should be true.
This gives better compatibility with MATLAB for vector subscripts.


\section{Design of the experiments}\label{sec:experimentalDesign}

    We have conducted extensive experiments to evaluate performance of our algorithms. We have used
    four different datasets, described in detail in section~\ref{subsec:datasets}, and compared
    our implementation with a highly-optimized, open source Faiss library~\cite{faiss} released by
    Facebook AI Research group.

    \subsection{Evaluation metrics}\label{subsec:evaluationMetrics}

        We have compared the algorithms according to two metrics -- \texttt{test-time}
        and \texttt{precision@}$k$.

        \texttt{Test-time} is defined simply as a number of seconds it takes the index to return
        top-$100$ (approximate) nearest neighbours for each vector in a set of queries provided by the user.
        We assume that queries are available as a contiguous chunk of data kept in-memory.

        \texttt{Precision@}$k$ (P@$k$) can be intuitively described as a
        ``number of relevant items in the list of $k$ returned items, divided by $k$''.

        More formally, given a vector $\hat{\mathbf y} \in {\mathcal{R}}^{L}$ of scores assigned to each item, and a
        binary vector $\mathbf y \in \left\lbrace 0, 1 \right\rbrace^L$ indicating which items are relevant
        we can write
%
        \begin{equation*}
            \text{P}@k := \frac{1}{k} \sum_{l\in \text{rank}_k (\hat{\mathbf y})} y_l
        \end{equation*}
%
        where $\text{rank}_k(\hat {\mathbf y})$ returns indices of $k$ labels with the highest scores in $\hat{\mathbf y}$.

        We have decided not to focus on the training time of the evaluated indices. This
        decision is motivated by the fact, that in most practical use-cases, where
        approximate inference methods will be used, the training time is a one-time cost that
        often can be amortized (e.g by using more compute-power).
        Inference in these cases, however, is the time-sensitive component
        that cannot be easily sped-up (e.g the inference happens in real-time on a mobile device, or a small web-server).

    \subsection{Datasets}\label{subsec:datasets}

        We have used four datasets to evaluate performance of our algorithms.

        Two of them, SIFT and SIFTsmall were introduced in~\cite{jegou2011product} and their
        main purpose was to allow for evaluation of (approximate) $k$-nearest neighbors algorithms. They are freely
        available for download at~\cite{sift}.

        For these datasets a set of $n$ ``database'' vectors is given with dimensionality
        $d=128$, as well as a set of ``query'' vectors $\in \mathcal{R}^d$
        and the ``groundtruth'' indices. For every ``query'' vector there are $100$ ``groundtruth'' indices
        that point to the closest (according to $L_2$ distance) vectors in the database.

        First of all, for every query, we consider only the first vector in the groundtruth as relevant.
        Secondly, we recompute the groundtruth indices so that they're sorted accroding to the inner-product.

        For the two remaining datasets, we have used Wiki-LSHTC~\cite{lshtc} and
        Amazon-3M~\cite{a3m} datasets, publicly available at~\cite{exrepo}.
        Given the scope of our thesis, they are certainly the most interesting from the machine learning perspective,
        but at the same time pose several challanges.

        The reason these datasets are more meaningful than SIFT is because they allow us to test our
        algorithms in a real-world setting, where there is a linear model trained to perform multilabel
        classification, for which the inference procedure has to be sped up.
        This means that we need to first build a decent classifier, then plug in our approximate algorithms,
        and finally benchmark the whole system.

        We note that there are some constraints when it comes to the choice of the classifier. The first condition
        is that the model should be bottlenecked by a large number of inner products that have to be performed during
        inference step. The second is that these inner products should only deal with dense vectors,
        since both the reference Faiss library and our algorithms can only cope with such representation.

        We have experimented with several models, including deep neural networks, but finally decided to
        use the fastText~\cite{fasttext} classifier. It is a very simple, yet powerfull architecture, that
        can be efficiently trained on very large datasets. Its speed comes from the fact that it uses an efficient,
        asynchronous, stochastic gradient descent, and doesn't compute full softmax over the output space,
        but approximates it with a negative sampling~\cite{w2v}.

        Here, by stochastic gradient descent we mean a training procedure, in which weights of the model are updated
        after observing each sample in the dataset. This is in contrast with popular in deep learning
        mini-batch gradient descent, where a gradient is averaged over a number of samples (a mini-batch),
        and only then the update step is performed.

        We write that we use asynchronous gradient decent, since during trainin a number of threads is spawned. Each
        of those threads computes its own gradients, but updates a shared weight matrix. This is done without any
        form of synchronization.

        Finally, negative sampling is a technique used for training models with large numbers of output classess, where
        for each example and a set of positive labels, only a small set of negative labels is sampled from the dataset.
        This is in contrast with, for example, softmax, which uses positive and all negative labels to compute the loss.

        As for the model itself, fastText takes an input example in a form of a sparse vector
        (in our case, each index in that vector represents a word in the input sentence), and computes its hidden,
        dense representation. Then, this representation is multiplied with a weight vector for each output class,
        giving the final prediction. This last step is exactly the MIPS problem we are discussing in this work.

        Naturally, we wanted to use our approximate algorithms to avoid computing dot product between a hidden
        representation and a weight vector for each class. To be sure that our timings are as accurate as possible,
        we decided to not plug our methods directly into the model. Instead, we first computed the hidden representation
        for each example in the dataset, and saved those to disk. For each example we also saved a set of
        true labels associated with this example. These were our ``relevant'' classes for each item.
        Finally, we extracted the weight vectors associated with each class, and saved those as well. Given this setup,
        it was now straightforward to perfom experiments --- we just treated the weight vectors as our database vectors,
        and hidden representations as query vectors.

        For completeness, we summarize the descriptive statistics of the used datasets in Table~\ref{tab:dsz}.

        \begin{table}
          \caption{Data statistics: $d$ is the dimensionality of the feature vectors (for Wiki-LSHTC and Amazon-3M this
          is the dimensionality of the fastText hidden representation), $L$ is the number
          of database vectors (for Wiki-LSHTC and Amazon-3M this is the number of labels), and $n$ is the number of query vectors.}
          \label{tab:dsz}
          \centering
          {
          \begin{tabular}{l|c|c|c|}
            Dataset & $d$ &$L$& $n$ \\
            \hline
            SIFTsmall   & $128$ & $10000$   & $100$    \\
            SIFT        & $128$ & $1000000$ & $10000$  \\
            Wiki-LSHTC  & $256$ & $325056$  & $587084$ \\
            Amazon-3M   & $256$ & $2812281$ & $742507$ \\
          \end{tabular}
          }
        \end{table}

    \subsection{Baseline (IVF)}\label{subsec:baselineivf}

        We have compared our implementations with a highly-optimized Faiss~\cite{faiss} library.
        Specifically, we have decided to use the Inverted File Index algorithm it provides.

        This choice was motivated by two factors.
        Firstly, the authors of the library have empirically determined that this algorithm performs
        really well in settings similar to ours --- where we are not memory constrained, and whole dataset
        can fit in memory.
        Secondly, this algorithm is a special case of our hierarchical $K$-means, specifically
        it is equivalent to hierarchical $K$-means with the number of layers set to $1$.

    \subsection{Parameter grid}\label{subsec:parameterGrid}

        After an initial round of manual tests we have gained a pretty good understanding of
        each algorithm, and were able to design a grid of sensible parameters for each of them.

        For hierarchical $K$-means the core parameters are of course the depth of the hierarchy
        (we have experimented with depth up to $4$), the number of centroids on each level,
        and the number of nodes that are expanded during search procedure.

        For ALSH the most important parameters were the number of hash tables ($L$),
        and the number of hash functions ($K$). The rest of the parameters was mostly kept fixed, following
        recommendations of the original ALSH paper.

        For the quantization-based algorithm we have varied the number of subspaces as well as the number of centroids
        in each subspace.

        For a more detailed explanation of the parameters mentioned above, please see the sections
        dedicated to each of the algorithms.

    \subsection{Amazon Web Services}

        All of our experiments were conducted using the Amazon Web Services infrastructure.
        More concretely we have used compute-optimized \texttt{c4.4xlarge} instances. Each such
        instance provides $16$ virtual cores and $30$ gigabytes of RAM, and is powered
        by an Intel Xeon E5-2666 v3 (Haswell) processor optimized specifically for AWS.

        We have provisioned around $40$ machines, which allowed us to evaluate our parameter grid
        in just few days.
        At the same time, however, it was unfeasible to manage this number of machines manually.
        To overcome this problem, we have prepared a simple scheduler,
        that would take a grid of parameters and list of machines as inputs, and schedule
        jobs to be executed on those machines.
        An SSH tunnel was then established with each machine so that scheduler
        was able to request a job execution, and a machine was able to report the evaluation results.


% !TeX root = ../main.tex

\chapter{Numerical modelling method}

Since the subduction process contain slow deformation and the constrain for deep lithosphere evolution is not well understand from either geophysical observation in depth or geology study in time, computer model is a suitable way to  study subduction zone, especially the numerical model. While the analytic solution is hard to solve, numerical model has become a useful method for studying Earth evolution.

The numerical models in this study address the dynamics process of flat subduction, in which an oceanic plate subducts beneath continental plate. The goal of this work is to address the controls on subducting plate dynamics and to determine the conditions under which flat subduction may develop.

In this chapter, we introduce the method of numerical model and the initial model setup. In section 2.1, we discuss the governing equations. In section 2.2, the finite elements method will be briefly discuss. The material properties, phase transition and model boundary conditions are given in section 2.3 ,2.4 and 2.5, respectively. In section 2.6, we introduce the Fast Lagrangian Analysis of Continua technique. In section 2.7, the model geometry is presented.

\section{Governing equation}

\subsection{Continuum---Conservation of mass}

In geodynamics modelling, we consider major rock units as continuous geological media. The continuous description is described by field variables such as density, pressure, velocity, strain, etc.
The continuity can be transformed into quantitative mathematical formalism, that is, continuity equation.

The mass conservation equation in Lagrangian form is as follow
\begin{align}
\frac{\partial \sigma_{ij}}{\partial x_j}+\rho g_i = \rho \frac{\partial D_{vi}}{\partial t}
\end{align}
A Lagrangian points is strictly connected to a single material point and is moving with this point. Therefore, the same material point is always in same coordinate independent of the moment of time. On the other hand, Eulerian point is an immobile point.
The proof of eq.(2.1) is as follow
\begin{figure*}[ht!]
    \centering
    \includegraphics[width=4.5in]{eulerian_and_lagrangian.pdf}
    \caption{ Eulerian (a) and Lagrangian (b) elementary volumes considered for the derivation of continuity equation. }
    \label{fig::Lagrangian Volume}
\end{figure*}

Since the volume is always related to the same material points, the amount of mass in the moving Lagrangian volume remains constant. However, the volume change due to the internal expansion or contraction process. The initial average density $\rho_0$ in a Lagrangian volume ($V_0$) is given by:
\begin{align}
\rho_0 = \frac{m}{\Delta x_0 \Delta y_0 \Delta z_0}
\end{align}
After a small period of time ($\Delta t$), the Lagrangian volume undergo internal process, thus the volume become $V_1$ and the average density change to:
\begin{align}
\rho_1 = \frac{m}{\Delta x_1 \Delta y_1 \Delta z_1}
\end{align}

Lagrangian material in time derivative is:
\begin{align}
\frac{D\rho}{Dt} \approx \frac{\Delta \rho}{\Delta t} = \frac{\rho_1-\rho_0}{\Delta t}=\frac{m}{\Delta x_1 \Delta y_1 \Delta z_1\Delta t}-\frac{m}{\Delta x_0 \Delta y_0 \Delta z_0\Delta t}
\end{align}
The relationship between new and old dimensions of Lagrangian volume is base on the relative movements of the volume's boundary, the displacement is equal to the velocity times period of duration:
\begin{align}
\Delta x_1 = \Delta x_0+\Delta t\Delta v_x\\
\Delta y_1 = \Delta y_0+\Delta t\Delta v_y\\
\Delta z_1 = \Delta z_0+\Delta t\Delta v_z
\end{align}
By using the equation above (2.5-2.7), replace the $\Delta x_1$, $\Delta y_1$, $\Delta z_1$ to eq 2.4:
\begin{align}
\frac{D\rho}{Dt} \approx \frac{\Delta \rho}{\Delta t} =\frac{m\Delta x_0 \Delta y_0 \Delta z_0-m\Delta x_1 \Delta y_1 \Delta z_1}{\Delta x_1 \Delta y_1 \Delta z_1\Delta t\Delta x_0 \Delta y_0 \Delta z_0}
\end{align}
Since $\Delta x_0 \Delta y_0 \Delta z_0=\rho_0$, the following expression can be obtain:
\begin{align}
\frac{\Delta \rho}{\Delta t}+\rho_0\frac{\frac{\Delta v_x}{\Delta x_0}+\frac{\Delta v_y}{\Delta y_0}+\frac{\Delta v_z}{\Delta z_0}+K_1}{K_2} = 0
\end{align}
\begin{align}
K_1 = \Delta t(\frac{\Delta v_x}{\Delta x_0}\frac{\Delta v_y}{\Delta y_0}+\frac{\Delta v_x}{\Delta x_0}\frac{\Delta v_z}{\Delta z_0}+\frac{\Delta v_y}{\Delta y_0}\frac{\Delta v_z}{\Delta z_0}+\Delta t \frac{\Delta v_x}{\Delta x_0}\frac{\Delta v_y}{\Delta y_0}\frac{\Delta v_z}{\Delta z_0})
\end{align}
\begin{align}
K_2=(1+\Delta t\frac{\Delta v_x}{\Delta x_0})(1+\Delta t\frac{\Delta v_y}{\Delta y_0})(1+\Delta t\frac{\Delta v_z}{\Delta z_0})
\end{align}
where $K_1$ and $K_2$ are coefficients which respectively tend to zero and unity when $\Delta t$ tends to zero. Eq (2.9) can be rewrite to:
\begin{align}
\frac{D\rho}{Dt}+\rho\frac{\partial v_x}{\partial x}+\rho\frac{\partial v_y}{\partial y}+\rho\frac{\partial v_z}{\partial z} = 0
\end{align}
or
\begin{align}
\frac{D\rho}{Dt}+\rho div(\vec v) = 0
\end{align}

While in geodynamics modelling, the density variations are small enough to be ignored, which is the result of Boussinesq approximation. The Boussinesq approximation assume that the density is linear proportional to the temperature and the small density variation is then neglected, except the gravity term.
\begin{align}
\rho (T) = \rho_0[1-\alpha (T-T_0)]
\end{align}
where $\rho_0$ is the reference density at temperature $T_0$ and $\alpha$ is the volumetric thermal expansion coefficient. The boussinesq approximation also represent the incompressible condition, which mean the density of material points does no change with time. The incompressible continuity equation is broadly used in numerical geodynamic modelling, although on many cases it is rather big simplification.
\begin{align}
\nabla \cdot (\vec v) = 0
\end{align}
Eq. (2.15) is the conservation of mass in our numerical modelling approach.

\subsection{Motion---Conservation of momentum}
In geodynamics, the time-dependent phenomena involve deformation of continuous media, which is the effect of the balance of internal and external forces that act in these media. So as to relate forces and deformation, an equation of motion may be used --The momentum equation. The momentum equation is a differential equivalent of Newton’s second law to a continuous medium.
\begin{align}
f=ma
\end{align}
$f$ is the net force acting on the object and $m$ is the mass of material. The momentum equation for a continuous medium in the gravity field:
Eulerian Form:  \begin{align}
\frac{\partial \sigma_{ij}}{\partial x_j}+\rho g_i = \rho (\frac{\partial v_i}{\partial t}+v_j\frac{\partial v_i}{\partial x_j})
\end{align}
Lagrangian Form:  \begin{align}
\frac{\partial \sigma_{ij}}{\partial x_j}+\rho g_i = \rho \frac{\partial D_{vi}}{\partial t}
\end{align}
\begin{figure*}[ht!]
    \centering
    \includegraphics[width=4in]{momentum.pdf}
    \caption{ Lagrangian elementary Volume considered for the derivation of the respective form of x-momentum equation.}
    \label{fig::Lagrangian Volume}
\end{figure*}

While considering a small Lagrangian volume, the net force acting on the object which can be computed locally. We will proof the momentum equation of Lagrangian Form below:

For x-component
\begin{align}
f_x=f_{xA}+f_{xB}+f_{xC}+f_{xD}+f_{xE}+f_{xF}+mg_x
\end{align}
$f_{xA}- f_{xF}$ are stress-related forces, from the outside of the volume on the respective boundaries A-F.
$f_g=m_gx$ is the gravity force.
\begin{align}
f_{xA} = -\sigma_{xxA}\Delta y\Delta z\\
f_{xB} = +\sigma_{xxB}\Delta y\Delta z\\
f_{xC} = -\sigma_{xyC}\Delta x\Delta z\\
f_{xD} = +\sigma_{xyD}\Delta x\Delta z\\
f_{xE} = -\sigma_{xzE}\Delta x\Delta y\\
f_{xF} = +\sigma_{xzF}\Delta x\Delta y
\end{align}
We replace the force Eq(2.20-2.25) to Eq (2.19):
\begin{align}
(\sigma_{xxB}-\sigma_{xxA})\Delta y\Delta z+(\sigma_{xyD}-\sigma_{xyC})\Delta x\Delta z+(\sigma_{xzF}-\sigma_{xzE})\Delta x\Delta y+mg_x = ma_x
\end{align}
Normalising both sides by considered Lagrangian volume
\begin{align}
V=\Delta x\Delta y\Delta z
\end{align}
we obtain
\begin{align}
\frac{(\sigma_{xxB}-\sigma_{xxA})\Delta y\Delta z}{V}+\frac{(\sigma_{xyD}-\sigma_{xyC})\Delta x\Delta z}{V}+\frac{(\sigma_{xzF}-\sigma_{xzE})\Delta x\Delta y}{V}+\frac{m}{V}g_x=\frac{m}{V}a_x
\end{align}
or
\begin{align}
\frac{\Delta\sigma_{xx}}{\Delta x}+\frac{\Delta\sigma_{xy}}{\Delta y}+\frac{\Delta\sigma_{xz}}{\Delta z}+\rho g_x = \rho a_x
\end{align}
While the differences of the respective stresses components all tend to zero, we obtain:
\begin{align}
\frac{\partial\sigma_{xx}}{\partial x}+\frac{\partial\sigma_{xy}}{\partial y}+\frac{\partial\sigma_{xz}}{\partial z}+\rho g_x = \rho a_x
\end{align}
or
\begin{align}
\partial_j\sigma_{ij}+\rho g_i = \rho \ddot u
\end{align}
where $u$ is the displacement.
\subsection{Heat equation --- Conservation of energy}

To describe the balance of energy in a continuum material, heat equation is apply to measure the temperature change. The heat equation sloved the heat transport and porvided the temperature field. Below is the heat equation in Lagrangian form :
\begin{align}
\rho C_p \frac{DT}{Dt} = -\frac{\partial q_x}{\partial x}-\frac{\partial q_y}{\partial y}-\frac{\partial q_z}{\partial z}+H_s+H_L
\end{align}

where $\rho$ is the density, $C_p$ is the heat capacity at constant pressure (isobaric heat capacity), $H_s$ is shear heating and $H_L$ is the latent heat production.

The proof of heat equation is show below:

Base on the Boussinesq approximation, the imcompressible Lagrangian form governing equations are:
\begin{align}
\nabla \cdot (\vec v) = 0
\frac{\partial \sigma_{ij}}{\partial x_j}+\rho g_i = \rho \frac{\partial D_{vi}}{\partial t}
\rho C_p \frac{DT}{Dt} = -\frac{\partial q_x}{\partial x}-\frac{\partial q_y}{\partial y}-\frac{\partial q_z}{\partial z}+H_s+H_L
\end{align}

Describe conservation of mass, conservation of momentum and conservation of energy, respectively.

\section{Finite elements method}

finite elements method

\section{Rheological behavior}

**What is viscous and the viscous rheology of rock**

In the near-surface region, rocks undergo relatively low temperature and, therefore, the Earth's lithosphere easily result in brittle (at low pressure) and plastic (at high pressure) deformation.
While in the deep earth, temperature increasing with depth, rocks behave viscous with irreversible deformation.
Therefore, if a geodynamics model need to account for a wide range of rocks properties, it should consider the elasto-visco-plastic rheology of rocks.

Elastic rheology assume that the relationship between applied stress and strain is proportionality.

\begin{figure*}[ht!]
    \centering
    \includegraphics[width=3in]{elasticdeformaiton.pdf}
    \caption{ Elastic deformation  }
    \label{fig::elastic}
\end{figure*}

While plastic.......

Viscous rheology define....

\section{Phase change}

In this study, we use markers to trace the rocks phases, pressure and temperature.
At the time the pressure and temperature satisfy the phase transformation condition, the marker will turns to new rock phase.
A basalt element represent an element with more than 30 presents of the basalt phase markers.
In this case, the element behave the deformation as same as the basalt rheology.

\subsection{Peridotite --- Serpentinite}

Once the subducting plate sink into mantle, sediment on oceanic plate undergo higher pressure and temperature that release a large amount of fluids.
On the other hand, the oceanic plate itself also carries seawater into the mantle.
Fluids in subduction zone mostly concentrated in the mantle wedge.
The dry mantle wedge undergo hydration process, lead to the transformation of peridotite to serpentinite.
The serpentinite depth and thickness in subduction zone is not well understand since the seismic study constrain still contain high uncertainly, we model the phase transformation process of serpentinite in parameter way.

Serpentinite are stable in the colder mantle wedge relative to deeper mantle, and therefore once the serpentinite under unstable field, we assume that serpentinite rocks release fluid and transfer to peridotite.
The following equations are the conditional expressions of serpentinite---peridotite transformation. Figure is the phase diagram of mantle phases.

\subsection{Basalt --- Eclogite}

As the oceanic crust sink into deeper mantle, the mafic rocks enters the eclogite stability field in the condition of high pressure.
Therefore, basalt phases transform to eclogite.
In this model, oceanic crust are tracked and compared with the eclogite stability filed, the following equations are the conditional expressions of mafic rocks transformation.
Figure below is the mafic rocks phase diagram.
\begin{figure*}[ht!]
    \centering
    \includegraphics[width=3in]{basalt_phase_diagram.pdf}
    \caption{ Phase diagram showing the stability field for mafic rocks (Hacker et al., 2003).  }
    \label{fig::elastic}
\end{figure*}

\subsection{Sediment --- Schist}

Once sediment undergo higher pressure, the compression process and mataphase(變質作用)process occur.
In this model, the following equations are the conditional expressions of transformation process of sediment to schist.

$T > 650^{\circ} C$\\
$depth >  20 $km

The subducted sediments will turn into schist when temperature is greater than 650$^\circ$C and pressure is greater than (a number)

\subsection{Hydrated olivine --- Peridotite}

We considering a hydrated peridotite under the oceanic crust in our model.
The magma will only generated above the hydrated subducting oceanic lithosphere.
Once the tempertaure is too high to make the rock contain water, the hydrated olivine transform to normal perodotite.
The following equation is the conditional expression of this transgformation.

$T > 800-35\times 10^{-9}\times (depth-62)^{2\circ}C$

\section{Boundary condition}

\subsection{Kinematic boundary condition}

\subsection{Thermal boundary condition}

For oceanic lithosphere, we used half space cooling model in our model to defined the thermal condition.
The plate depth is proportional to the square root of oceanic lithosphere age, and therefore, the half space cooling model can predict well for the temperature of the oceanic plate.
Follow by David and Lister, 1974(mention in Stein, 1995):

$T=T_m\cdot {erf}(\frac{z}{2\sqrt{\kappa t}})$

$T$ is the temperature, $T_m$ is the mantle temperature, in this model the temperature is 1330 K,
$z$ is the depth from surface in kilometer and $\kappa$ is the thermal diffusivity coefficient, that is, $10^{-6}$ in this study.
$t$ is the lithosphere age in Myr.

For continental lithosphere, the thermal condition is defined in linearly.

\section{FLAC}

We used the Fast Lagrangian Analysis of Continua (FLAC) technique. FLAC is a two-dimensional, explicit finite element with Lagrangian gird of numerical program.

What is explicit?

An explicit form is any solution that is given in the form $y=y(t)$. That is, $y$ only shows up once on the ledt hand side and is only in first power. Ob the other hand, implicit form is any solution that is not in explicit form. In finite element method, explicit solution solve the acceleration. In most cases, only the diagonal elements in matrix are not equal to zero, in other words, it is simple to solve an inversion solution form inverse matrix.

Gird?

\section{Initial Model}

initial model