There are many methods to create something new, but they all begin with an idea that needs to be realized. The path to realization in some cases can involve simply building the final project; however, with aerospace engineering that is not usually the case. In order to achieve the end goal, much planning is needed. An idea is formed, researched, designed, and then built. With many aerospace projects, designing cutting-edge technology requires accurate physical modeling in order confirm the feasibility of a design and examine the effects of changes. Therefore, the field of aerospace simulation and modeling is a large and extensive field. It is one which is constantly changing and expanding as computing power becomes exponentially stronger. The boom in computing power has opened the door to this thesis. \par

\begin{figure}[ht]
    \includegraphics[width=.45\textwidth]{figures/work.png}
    \centering
    \caption[Example of various engineering design tasks]{Example of various engineering design tasks \textmd{\cite{xkcd}}}
    \label{fig:xkcd}
\end{figure}

\section{Motivation}

\indent Computational Fluid Dynamics (CFD) is the field of study which deals with creating simulations of fluids. This is a critical part of aerospace design and analysis. Viscous fluid dynamics are completely described through the Navier-Stokes Equations.

\Needspace{12\baselineskip}
\begin{equation}
    \label{eqn:navier_1}
    \partial_t u_i + R u_j \partial_j u_i = -\partial_i \rho + \nabla^2 u_i + E_i
\end{equation}
\begin{equation}
    \label{eqn:navier_2}
        \partial_j u_j = 0
\end{equation}
\(u_i\) = Velocity components (m/s)\footnote{Throughout this thesis, repeated indices mean sum over that index.} \newline
\(R\) = Reynolds number \newline
\(\rho\) = Pressure (Pa) \newline
\(E_i\) = External Forces (N) \par

\indent The Navier-Stokes equations, seen in Equations \ref{eqn:navier_1} and \ref{eqn:navier_2} in the incompressible form \cite{navier_eqns}, have no known closed-form solution without making simplifying assumptions. They must be solved numerically and, to increase their accuracy, call for increases in computational power to match. CFD is currently an accepted and reliable industry tool for analysis across many disciplines. As computers continue to get stronger, more complicated modeling techniques can be used for unique and diverse scenarios. \par

\indent A large part of aerospace research involves states of matter where the particle density is low. Atmospheric re-entry of spacecraft, objects in Low Earth Orbit (LEO), planes flying at extremely high altitudes, and interactions with plasma all involve fluids whose particles are relatively far apart from each other. The relative spacing between particles can be measured through the Knudsen number, seen in Equation \ref{eqn:Knudsen}. \par

\Needspace{7\baselineskip}
\begin{equation}
    \label{eqn:Knudsen}
    Kn = \frac{\lambda}{L}
\end{equation}
\(Kn\) = Knudsen number \newline
\(\lambda\) = Mean free path \newline
\(L\) = Characteristic length \par

\begin{figure}
    \includegraphics[width=.55\textwidth]{figures/navier.JPG}
    \centering
    \caption[Appropriate Simulation Models by Knudsen number]{Appropriate Simulation Models by Knudsen number \textmd{\cite{navier} \(n_0\) is the density of air at standard temperature and pressure at sea level}}
    \label{fig:navier}
\end{figure}

\indent The mean free path is a measure of how far particles move before interacting with other particles and the characteristic length is a description of the basic length scale of the problem at hand. The ratio of the two (the Knudsen number) shows their relative differences and, therefore, quantifies whether continuum is a good assumption for that fluid. When the Knudsen number is very low ( \(\sim10^{-3}\) ) the particles collide much more often than they move the characteristic length, which means that a continuum assumption is valid. However, as seen in Figure \ref{fig:navier}, when the Knudsen number is large ( \(\sim10^{1}\) and up ) the continuum assumption, and by inference the Navier-Stokes equations, are no longer valid. One reason they are no longer valid is because in the Navier-Stokes Equations (\ref{eqn:navier_2}), where the divergence of the velocity is zero, the density of the fluid remains constant, and therefore is incompressible. High Knudsen number fluids are almost always compressible and therefore the divergence of their velocity is non-zero. \par

\indent There is another equation which can solve high Knudsen number problems. This is the Boltzmann equation, shown in kinematic form for elastic interaction of particles in a plasma by Equation \ref{eqn:boltzmann} \cite{boltzmann}. It is based upon the statistical distribution of particles and their momentum. \par

\Needspace{3\baselineskip}
\begin{equation}
    \label{eqn:boltzmann}
    \frac{\partial f_i}{\partial t} + \vec{v_i} \cdot \frac{\partial f_i}{\partial \vec{r}} + \vec{F_i} \cdot \frac{\partial f_i}{\partial \vec{v_i}} = \sum_j \int_0^\infty \int_0^{2\pi} \int_0^\infty  [ f_i(v_i^\prime) f_j (v_j^\prime) - f_i (v_i) f_j (v_j) ] g_{ij} b \text{d} b \text{d} \epsilon \text{d} v_j
\end{equation}
\(f(v)\) = Particle distribution function \newline
\(i \: \text{and} \: j\) =  \(i\)th and \(j\)th species \newline
\(v\) = Velocity  \newline
\(F\) = Force acting on the particle \newline
\(\prime\) = Functions for post-collision \newline
\(g_{ij}\) = Initial relative velocity between particles \newline
\(b\) = Impact parameter \newline
\(\epsilon\) = Azimuth angle \par

\indent The Boltzmann Equation can be solved for a few select unique fluid scenarios. These scenarios usually involve knowing the entirety of the initial state, being in a near equilibrium state or being in a near vacuum environment \cite{boltzmann_solved}. In order to model other more complicated scenarios the Boltzmann Equation is nominally solved numerically, like the Navier-Stokes equations. To solve the equation numerically is a large task, considering the triple integral, the unknown way to find an accurate function for the particle distribution, and the curse of dimensionality. It would follow that a discretion of the Boltzmann Equation would be helpful. This is where a particle-based code begins to make sense. \par

\indent The most basic algorithm for a particle-based simulation is to keep track of every particle in the domain and calculate each collision depending on the particles' relative distances. While this algorithm, called Molecular Dynamics (MD), is a valid algorithm, computers are not strong enough currently to create meaningful results from such a computationally heavy solution. This is where Direct Simulation Monte Carlo (DSMC) comes into play. DSMC was introduced in 1963 \cite{dsmc_speed}, one year before the computer language BASIC was created \cite{basic}. Back then, DSMC was seen as an inferior method to continuum solutions on account of the larger processing power required and the apparent abandonment of concrete mathematical solutions \cite{dsmc_speed}. Eventually it was shown that the limit as time-step and grid size approached zero of a DSMC simulation was a solution to the Boltzmann equation \cite{bird_dsmc}. Through the years, DSMC has gained respect and is now is well-known in the fluid modeling community as a standard for high Knudsen number flow simulation methods.\par

\begin{quote}
    ``The Direct Simulation Monte Carlo, or DSMC, method proved a probabilistic physical simulation of a gas flow by simultaneously following the motion of representative model molecules in a physical space." \cite{bird_dsmc}
\end{quote}

\begin{figure}
    \centering
  \begin{minipage}[b]{0.49\textwidth}
    \includegraphics[width=\textwidth]{figures/hover_rocket.JPG}
  \end{minipage} %
  \begin{minipage}[b]{0.49\textwidth}
    \includegraphics[width=\textwidth]{figures/mir_shuttle.JPG}

  \end{minipage}
  \caption[DSMC Application Examples]{DSMC Application Example \textmd{(left) A rocket lander hovering 5 m above the surface \cite{hover_rocket}. (right) Predicted surface pressure on Mir from the Space Shuttle RCS during docking \cite{mir_shuttle}.}}
  \label{fig:dsmc_application}
\end{figure}

\indent DSMC fits into an important gap in fluid simulation methods. It is a particle-based method, which allows it to accurately model high Knudsen number simulations in cases when continuum codes break down. Yet it does this while remaining based on statistical sampling and therefore allows critical computation time-saving mathematics and algorithms to allow DSMC to be on par with legacy continuum methods. DSMC simulates many super-particles in a domain, each of which is comprised of millions of physical particles. DSMC then uses statistics to determine collisions and surface interactions. The super-particles allow for a greater range of high Knudsen number scenarios to be simulated which is of particular interest in astronautics where Knudsen numbers are traditionally high. As seen in Figure \ref{fig:dsmc_application}, DSMC is now used for many important aerospace analysis tasks. \par

\indent Unfortunately, DSMC alone does not account for a large area of aerospace research: plasma. Plasma exists when there are a large number of ions and enough high-energy electrons to keep ionizing the gas. As seen in Table \ref{tab:plasma}, plasma can exist in many various situations and environments. Even commonplace things like candle flames or lightning bolts contain some plasma. Two large areas of aerospace research which take place within a plasma environment are atmospheric re-entry and electric propulsion. Both exist in a high Knudsen number environment but include charged particles. Therefore, while DSMC would be well-suited for the situation, it is not able to model the charged particles in these situations. \par

\indent Plasma is comprised, on average, of equal parts of negative electrons and positive ions, otherwise known as quasi-neutrality. However, there can be systematic (electric thruster) or random (solar wind) fluctuations that cause a local net charge. This fact means that the plasma can create electric forces, which in turn affect the charged particles in a plasma. DSMC cannot simulate charged particle flows because it only has mechanisms for collisional velocity updates. DSMC does not have a mechanism to calculate the electric force and update the particles velocities. This is where the Particle-In-Cell (PIC) method applies. \par

\begin{table}
\caption[Various Plasmas]{Various Plasmas \textmd{\cite{plasma_table}. \(n\) - Number Density, \(T\) - Plasma Temperature}}
\label{tab:plasma}
\vspace{0.3cm}
\begin{center}
\begin{tabular}{|lll|}
\hline
Plasma Type          & n (cm\textsuperscript{-3}) & T (eV)                  \\ \hline
Interstellar gas     & 1                        & 1                     \\
Solar Corona         & 10\textsuperscript{3}    & 1                     \\
Hot Plasma           & 10\textsuperscript{14}   & 10\textsuperscript{2} \\
Thermonuclear Plasma & 10\textsuperscript{15}   & 10\textsuperscript{4} \\
Laser Plasma         & 10\textsuperscript{20}   & 10\textsuperscript{2} \\ \hline
\end{tabular}
\end{center}
\end{table}

\indent The PIC method is a standard method to calculate the force on electrically charged particles in a particle type model. It is based on a mesh system comprised of nodes, upon which field calculations are made. The mathematics of charged particle forces in terms of PIC will be discussed in Chapter \ref{chap:charge}. PIC, however, does not account for collisions between particles. To accurately model a plasma for aerospace research, collisions between particles need to be taken into account. This naturally leads to the necessity for a DSMC-PIC hybrid method. A single mesh can be used for calculating collisions and macro-properties through DSMC as well as being used to calculate the fields in the domain and how they affect the particle's velocities with PIC. This allows for a program which can simulate a greater range of scenarios. However, it may be necessary with more complicated simulations to have different mesh sizes for the DSMC portion from the PIC portions. \par

\indent One scenario within aerospace research for which a DSMC-PIC simulation is optimal is electric propulsion. There are three main methods of spacecraft propulsion: chemical, cold gas, and electric. Chemical is the classic rocket engines used to put spacecraft and humans into orbit. Cold gas is simply expelling pressurized gas to provide thrust. Electric propulsion uses electricity to create more efficient engines for spacecraft. Electric propulsion can either be electrostatic, electrothermal, or electromagnetic. A nearly universal property of electric thrusters is that the exhaust is usually in a plasma state. An electric propulsion engine, in this case an ion engine, is shown in Figure \ref{fig:ion_thruster}. This figure shows the neutral propellant gas being ionized in the chamber, then the ions accelerated out through magnetic grids to create thrust\footnote{A more detailed explanation of ion engines and other information about electric propulsion can be found in Reference \cite{gobel}}. This results in a plasma plume. Since the spacecraft is in space and the thrusters do not expel dense amounts of gas, this plasma fits right into the realm of a DSMC-PIC simulation. Herein this lies the motivation for this thesis. \par

\begin{figure}
    \includegraphics[width=.85\textwidth]{figures/ion_thruster.png}
    \centering
    \caption[Diagram of an Ion Thruster]{Diagram of an Ion Thruster \textmd{\cite{ion_thruster} }}
    \label{fig:ion_thruster}
\end{figure}

%\footnote{By Oona Räisänen - Own work; self made in Inkscape. Based on File:Ion_engine.gif., CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=20308289}

%\section{Literature Review}

%As discussed above, the DSMC and PIC methods are not new innovations. Neither is the DSMC-PIC combination. Therefore, there are many resources from which to draw important information about algorithms, pitfalls, and challenges of implementing this method.

\section{Overarching Goal}
This thesis is one of a series of projects. The end goal is to have a Cal Poly homegrown simulation that can simulate an entire electric thruster. While the individual areas of modeling the discharge chamber \cite{discharge} and modeling the plasma plume \cite{justplume} are growing strongly, there is a distinct lack of complete electric thruster models in literature. It is technically possible to simulate the entirety of the thruster in DSMC, but the Knudsen number is so low inside of the thruster that computing a DSMC method would be nearly impossible. A simulation of a full electric thruster requires a continuum simulation for the gas inside the thruster and then a rarefied gas simulation for the exhaust plume where the Knudsen number is higher. In order to model a complete thruster, researchers have compromised by attempting to join together a fluid code and a rarefied gas code. Cal Poly's Aerospace Department is rare in that a fluid code and a rarefied gas code are being developed in the exact same manner from the ground up. Other institutions are also working in this area with success in the initial stages \cite{afrl,afrl_copy}. The early developers and advisors at Cal Poly worked together to establish these codes as being compatible from the beginning. \par

\indent This thesis is the third project of a homegrown DSMC code, code name SINATRA, which will eventually be able to simulate the thruster's plasma exhaust plume. The first three developers worked together in a staggered capacity to build SINATRA up to a working DSMC-PIC code. The first, Galvez, developed the base framework and kinematics \cite{Galvez2018a}. Next Alliston built up the collisions and particle models \cite{mac_thesis}. This thesis adds charged particle simulation capability to SINATRA. Concurrently with this thesis, Gay has been building the fluid side simulation \cite{Gay}. Intentionally, many properties will be common between the codes. They are both written in C++ and are class-based. They share the same process control items, including the execution style, distribution method, and the other systems items shown in Chapter \ref{chap:systems}. They share the same mesh type and input class to help them work together as one simulation. A future project will take both simulations and build the interaction system to connect them across each time-step.
%Is SINATRA a steady state or transient solver?]]
% Dom - able to be both! depending on output settings and how many times you rerun the same simulation


\subsection{Formal Definition}

\begin{description}
    \item[Name] Graph plane \vspace{2mm}
    \item[Word] \begin{definition}[action]
              A \textbf{\index{action}} is a representation of data that can be expressed as a $2$-tuple $(k,v)$, where
              \begin{enumerate}
                  \item $k$ is a unique identifier of the context
                  \item $v$ is an encoding of the data represented by the context
              \end{enumerate}
          \end{definition}
    \item[Description] Go deeper
\end{description}


\section{Batch comparison audits of a tolerable overstatement in votes}
\label{sec:comparisonError}

In this section we expand previous comparison auditing work to handle two new requirements.
The first relates to partitioning the permissible overstatement
through the parameters $\lambda_s$, as discussed in section~\ref{sec:hybrid}.
The second handles batch-level comparison audits.

To test whether the overstatement of any margin
(in votes) exceeds some fraction $\lambda$ of the overall margin $V_{w\ell}$ between
reported winner $w$ and reported loser $\ell$.
If the stratum contains all the ballots cast in the contest, then for $\lambda = 1$, this
would confirm the election outcome.
For stratified audits, we might want to test other values of $\lambda$, as described in Section~\ref{sec:hybrid}.

This section also addresses the second requirement by deriving a method for batches of arbitrary size, which might be useful
 to audit contests that include CVR counties and legacy counties.
We keep the \emph{a priori} error bounds tighter than the ``super-simple''
method~\cite{stark10d}.
To keep the notation simpler, we consider only a single contest, but the
MACRO test statistic \cite{stark09c,stark10d} automatically extends the result to
auditing $C>1$ contests simultaneously.
The derivation is for plurality contests, including ``vote-for-$k$'' plurality contests.
Majority and super-majority contests are a minor
modification~\cite{stark08a}.\footnote{%
  So are some forms of preferential and approval voting, such as Borda count, and
  proportional representation contests, such as D'Hondt~\cite{starkTeague14}.
  See \url{https://github.com/pbstark/S157F17/blob/master/audit.ipynb} for a derivation
  of ballot-level comparison risk-limiting audits for super-majority contests. (Last visited 14 May 2018.)
  Changes for IRV/STV are more complicated.
}

\subsection{Notation}
\begin{itemize}
    \item  $\mathcal{W}$: the set of reported winners of the contest
    \item  $\mathcal{L}$: the set of reported losers of the contest
    \item  $N_s$ ballots were cast in all in the stratum. (The contest might not appear on all $N_s$ ballots.)
    \item  $P$ ``batches'' of ballots are in stratum $s$. A batch contains one or more ballots. Every ballot in stratum $s$ is in exactly one batch.
    \item  $n_p$: number of ballots in batch $p$. $N_s = \sum_{p=1}^P n_p$.
    \item  $v_{pi} \in \{0, 1\}$: the reported votes for candidate $i$ in batch $p$
    \item  $a_{pi} \in \{0, 1\}$: actual votes for candidate $i$ in batch $p$.
                  If the contest does not appear on any ballot in batch $p$, then $a_{pi} = 0$.

    \item  $V_{w\ell,s} \equiv \sum_{p=1}^P (v_{pw} - v_{p\ell})$:
Reported margin in stratum $s$ of reported winner $w \in \mathcal{W}$ over reported loser
$\ell \in \mathcal{L}$, in votes.

    \item  $V_{w\ell}$:
Overall reported margin of reported winner $w \in \mathcal{W}$ over reported loser
$\ell \in \mathcal{L}$, in votes, for the entire contest (not just stratum $s$)

% If I'm not punch drunk, we really did manage to keep generalizations across multiple contests out of
% the subsequent exposition. However, we still use V
%
%    \item  $V_s$: smallest reported margin in the stratum among all $C$ contests audited using the same sample:
%$V_s \equiv \min_{w \in \mathcal{W}, \ell \in \mathcal{L}} V_{w \ell, s}$
%
%  \item  $V$: smallest reported overall margin among all $C$ contests audited using the same sample:
% $V \equiv \min_{w \in \mathcal{W}, \ell \in \mathcal{L}} V_{w \ell}$
    \item  $V$: smallest reported overall margin between any reported winner and reported loser:
$V \equiv \min_{w \in \mathcal{W}, \ell \in \mathcal{L}} V_{w \ell}$

    \item  $A_{w\ell,s} \equiv \sum_{p=1}^P (a_{pw} - a_{p\ell})$:
actual margin in the stratum of reported winner $w \in \mathcal{W}$ over reported loser
$\ell \in \mathcal{L}$, in votes

    \item  $A_{w\ell}$:
actual margin of reported winner $w \in \mathcal{W}$ over reported loser
$\ell \in \mathcal{L}$, in votes, for the entire contest (not just in stratum $s$)

\end{itemize}

\subsection{Reduction to maximum relative overstatement}
If the contest is entirely contained in stratum $s$, then
the reported winners of the contest are the actual winners if
$$
   \min_{w \in \mathcal{W}, \ell \in \mathcal{L}} A_{w\ell,s} > 0.
$$
Here, we address the case that the contest may include a portion outside the stratum.
To combine independent samples in different strata, it is convenient
to be able to test whether the net overstatement error in a stratum exceeds a given threshold.

Instead of testing that condition directly, we will test a condition that is sufficient
but not necessary for the inequality to hold, to get a computationally simple test that
is still conservative (i.e., the risk is not larger than its nominal value).

For every winner, loser pair $(w, \ell)$, we want to test
whether the overstatement error exceeds some threshold, generally
one tied to the reported margin between $w$ and $\ell$.
For instance, for a stratified hybrid audit, we set the threshold to be
$\lambda_s V_{w\ell}$.

We want to test whether
$$
   \sum_{p=1}^P (v_{pw}-a_{pw} - v_{p\ell} + a_{p\ell})/V_{w\ell} \ge \lambda_s.
$$
The maximum of sums is not larger than the sum of the maxima; that is,
$$
\max_{w \in \mathcal{W},  \ell \in \mathcal{L}}
   \sum_{p=1}^P (v_{pw}-a_{pw} - v_{p\ell} + a_{p\ell})/V_{w\ell}
   \le
  \sum_{p=1}^P  \max_{w \in \mathcal{W},  \ell \in \mathcal{L}}
  (v_{pw}-a_{pw} - v_{p\ell} + a_{p\ell})/V_{w\ell}.
$$

Define
$$
  e_p \equiv \max_{w \in \mathcal{W} \ell \in \mathcal{L}}
     (v_{pw}-a_{pw} - v_{p\ell} + a_{p\ell})/V_{w\ell}.
$$
Then no reported margin is overstated by a fraction $\lambda_s$ or more
if
$$
  E \equiv \sum_{p=1}^P e_p < \lambda_s.
$$

Thus if we can reject the hypothesis $E \ge \lambda_s$, we can conclude that
no pairwise margin was overstated by as much as a fraction $\lambda_s$.

Testing whether $E \ge \lambda_s$ would require a very large sample if we knew nothing at
all about $e_p$ without auditing batch $p$: a single large value of $e_p$ could make
$E$ arbitrarily large.
But there is an \emph{a priori} upper bound for $e_p$.
Whatever the reported votes $v_{pi}$ are in batch~$p$, we can find the
potential values of the actual votes $a_{pi}$ that would make the
error $e_p$ largest, because $a_{pi}$ must be between 0 and $n_p$,
the number of ballots in batch~$p$:
$$
    \frac{v_{pw}-a_{pw} - v_{p\ell} + a_{p\ell}}{V_{w\ell}} \le
    \frac{v_{pw}- 0 - v_{p\ell} + n_p}{V_{w\ell}}.
$$
Hence,
\begin{equation} \label{eq:uDef}
    e_p \le \max_{w \in \mathcal{W}, \ell \in \mathcal{L}}
    \frac{v_{pw} - v_{p\ell} + n_p}{V_{w\ell}} \equiv u_p.
\end{equation}

Knowing that $e_p \le u_p$ might let us conclude reliably that $E < \lambda_s$
by examining only a small number of batches---depending on the
values $\{ u_p\}_{p=1}^P$ and on the values of $\{e_p\}$ for the audited batches.

To make inferences about $E$, it is helpful to work with the \emph{taint}
$t_p \equiv \frac{e_p}{u_p} \le 1$.
Define $U \equiv \sum_{p=1}^P u_p$.
Suppose we draw batches at random with replacement, with probability $u_p/U$
of drawing batch $p$ in each draw, $p = 1, \ldots, P$.
(Since $u_p \ge 0$, these are all positive numbers, and they sum to 1,
so they define a probability distribution on the $P$ batches.)

Let $T_j$ be the value of $t_p$ for the batch $p$ selected in the $j$th draw.
Then $\{T_j\}_{j=1}^n$ are IID, $\mathbb{P} \{T_j \le 1\} = 1$, and
$$
  \mathbb{E} T_1 = \sum_{p=1}^P \frac{u_p}{U} t_p =
  \frac{1}{U}\sum_{p=1}^P u_p \frac{e_p}{u_p} =
  \frac{1}{U} \sum_{p=1}^P e_p = E/U.
$$
Thus $E = U \mathbb{E} T_1$.
So, if we have strong evidence that
$\mathbb{E} T_1 < \lambda_s/U$, we have
strong evidence that $E < \lambda_s$.

This approach can be simplified even further by noting that $u_p$ has
a simple upper bound that does not depend on $v_{pi}$.
At worst, the reported result for batch $p$ shows $n_p$ votes for the
``least-winning'' apparent winner of the contest with the smallest margin,
but a hand interpretation would show that all $n_p$ ballots in the batch
had votes for the runner-up in that contest.
Since $V_{w\ell} \ge V\equiv \min_{w \in \mathcal{W}, \ell \in \mathcal{L}} V_{w \ell}$ and $0 \le v_{pi} \le n_p$,
$$
    u_p =  \max_{w \in \mathcal{W}, \ell \in \mathcal{L}}
    \frac{v_{pw} - v_{p\ell} + n_p}{V_{w\ell}}
    \le  \max_{w \in \mathcal{W}, \ell \in \mathcal{L}}
    \frac{n_p - 0 + n_p}{V_{w\ell}}
    \le \frac{2n_p}{V}.
$$
Thus if we use $2n_p/V$ in lieu of $u_p$, we still get conservative results.
(We also need to re-define $U$ to be the sum of those upper bounds.)
An intermediate, still conservative approach would be to use this upper bound for
batches that consist of a single ballot, but use the sharper bound (\ref{eq:uDef})
when $n_p > 1$.
Regardless, for the new definition of $u_p$ and $U$,
$\{T_j\}_{j=1}^n$ are IID, $\mathbb{P} \{T_j \le 1\} = 1$,
and
$$
  \mathbb{E} T_1 = \sum_{p=1}^P \frac{u_p}{U} t_p =
  \frac{1}{U}\sum_{p=1}^P u_p \frac{e_p}{u_p} =
  \frac{1}{U} \sum_{p=1}^P e_p = E/U.
$$

So, if we have evidence that $\mathbb{E} T_1 < \lambda_s/U$, we have evidence that
$E < \lambda_s$.

\subsection{Testing $\mathbb{E} T_1 \ge \lambda_s/U$}

A variety of methods are available to test whether $\mathbb{E} T_1 < \lambda_s/U$.
One particularly ``clean'' sequential method is based on Wald's Sequential Probability
Ratio Test (SPRT) (\cite{wald45}).
Harold Kaplan pointed out this method on a website that no longer exists.
A derivation of this ``Kaplan-Wald'' method is given in Appendix A of~\cite{starkTeague14};
to apply the method here, take $t = \lambda_s$ in their equation~18.

A different sequential method, the Kaplan-Markov method (also due to Harold Kaplan),
is given in~\cite{stark09b}.


\section{Evaluation}\label{sec:Evaluation}
%Describe the evaluation set up briefly.
% 3 Graph that compares the precision/recall (F1) and time performance of our multiple approaches.
% Our approaches are:
% 1. Graphs for 2D CNN with simple linear projection on one of the axis.
% 2. 2D CNN with an improved transformation from 3D to 2D CNN
% 3. 2D CNN - with - separation and projection and then segmentation with DBSCAN
% 4. 3D CNN
% 5. Different No. of Layers up to 3 and 2 different sizes of the filter.
% - We should run it on a standard machine (better on EC2 because it is better reproducible) and show the processing time performance.
% - We present on our plots, Precision/Recall and Processing time.

We evaluated our implementation \footnote{Github Repository
of our Implementation \url{https://github.com/kiat/debs2019}} using the 4 different experiment
setups:
\begin{enumerate}
  \item 2-Layer CNN on projected data to 2D (Single View) and Object Segmentation with 3D DBSCAN
  \item 2-Layer CNN on projected data to 2D (Using perspective projection) and Object Segmentation with 3D DBSCAN
  \item 4-Layer CNN on projected data to 2D (Single View) and Object Segmentation with 3D DBSCAN
  \item 4-Layer CNN on projected data to 2D (Using perspective projection) and Object Segmentation with 3D DBSCAN
\end{enumerate}

Figure \ref{fig:evaluation2} depicts the precision, recall, accuracy, and processing time of each of the 4 different experiment settings on
DEBS2019 evaluation system. The Figure \ref{fig:evaluation2} also includes if in testing
all 500 scenes are processed in time or it failed to process them all in the given time limit. The
performance time results compared in Figure \ref{fig:evaluation2} includes end-to-end time include
http  data transmission time from and to the evaluation server.

%\usepackage{graphics} is needed for \includegraphics
\begin{figure*}[htp]
\begin{center}
  \includegraphics[width=1\linewidth]{images/evaluation2.pdf}
  \caption{Precision, Recall, Accuracy and Processing Time of 4 different our Experiment Variation}
  \label{fig:evaluation2}
\end{center}
\end{figure*}

All of the above settings have a data filtering step. The Figure \ref{fig:accloss} represents accuracy and loss while training the CNN model
on individual objects
using TensorFlow\footnote{\url{https://www.tensorflow.org/} TensorFlow is an open source platform
for machine learning, April 2019} to classify objects into 28 class types.

%\usepackage{graphics} is needed for \includegraphics
% \begin{figure}[htp]
% \begin{center}
%         \includegraphics[scale=0.5]{images/accuracy.png}
%         \caption{Training and Validation Accuracy}
%         \label{fig:accuracy}
% \end{center}
% \end{figure}
% \begin{figure}[htp]
% \begin{center}
%         \includegraphics[scale=0.5]{images/loss.png}
%         \caption{Training and Validation Loss}
%         \label{fig:loss}
% \end{center}
% \end{figure}

\begin{figure}[htp]
\begin{center}
        \includegraphics[scale=1]{images/one_to_one.pdf}
        \caption{Training and Validation Accuracy and Loss}
        \label{fig:accloss}
\end{center}
\end{figure}


\chapter{Background and past work}

This chapter will familiarize the reader with the various topics, strategies and technologies involved in this research. Namely, convolutional neural networks, convolutions, computer precision and integer representation, and other relevant topics will be discussed.

\section{Past work}
Previous work addressing the neural network number-representation problem has shown quantizing values to integers, or in some cases only as far as fixed-point representation, to be effective. One such example is research born out of the Watson Research Center and Almaden Research Center \cite{gupta}. This work shows that it is possible to reduce representation to 16-bit not only at inference time, but at training time, and without incurring a loss in accuracy. This furthers the case for the robustness of convolutional neural networks and highlights the potential for quantization of networks at inference. A second example is a work in which weights are kept in floating-point representation while activations are converted to fixed-point representation. This paper makes the claim that number representation range (the ability to represent large and small values) is more important than representation precision. \cite{dblp}. Google has also made great strides in regards to the quantization topic. One work emphasizes the real-time intensity of neural network processing through the example of speech recognition, and succeeds in optimizing performance of such processing at runtime on CPUs \cite{google}.

\section{Image recognition}
Image recognition is a subtask in the field of computer vision in which the goal is to correctly predict a text label for the most dominant object in the image \cite{history}. Convolutional neural networks are designed to handle the image recognition problem. They got their start at the ILSVRC challenege in 2012, where AlexNet, the first CNN, won by a significant factor \cite{history}. Since then, convolutional neural network architectures have been modified and experimented with, keeping the core concept of the convolution layer in mind. As a result of this research, there now exist CNNs which perform at near-human levels. One example is the popular LeNet architecture \cite{mnist}, where top-5 accuracy for the task of recognizing hand-written numbers has reached 100\%. Another example is the family of residual neural networks, whose very deep architectures and interwoven stacks of convolution layers have achieved an error of only 3.57\% on the famous Imagenet dataset \cite{resnets2}.

\section{Convolutional neural networks}
\subsection{Motivation}
\subsubsection{The limitations of non-convolutional neural networks}
In a traditional neural network, each node in each layer is fully-connected to each node in the preceding layer. This means that every activation is derived from the full scope of input from the previous layer, making the process computationally expensive and therefore slow. The memory needed for such a network is staggering. Imagine a modestly-sized network that takes images of size $224\times224$ and three channels (RGB), with perhaps only two hidden layers comprising of 4096 and 1000 nodes, sequentially. All together this network would require $224\times224\times3 \approx 150K$ values for the input layer, \~4K and 1K values to represent the first and second hidden layers, with $224\times224\times3\times4096 \approx 616M$ and $4096\times1000 \approx 4M$ values in weights for these hidden layers, respectively. This would amount to a total of $775M\times4 \approx 3 GB$ of storage needed---at floating-point precision---for this relatively simple network. It is also of note that in such a scheme in which there is a large amount of independent and individual parameters, it would be difficult not to overfit the data at training time. One can easily see that the traditional non-convolutional network is not ideal for image input. Although large CNN architectures such as VGG can reach a similar number of parameters, they are at the same time much deeper and expressive. In the case of VGG-19, the fully-connected layer (usually occurring at the end of a CNN network) brings the total parameter count to approximately 138.3M \cite{return}. However, a similar multi-layer perceptron network of similar layer-size would far exceed this number.

\bildklein{figures/nn.png}{A traditional neural network}{A traditional neural network. Notice how each node is connected to every previous node. Weights add up quickly and the image recognition problem soon becomes unmanageable. [CC Image courtesy of Chrislb on Wikimedia Commons]}{fig:nn}

\subsubsection{Convolutional neural networks as a solution}
Convolutional neural networks approach the image recognition problem differently. Namely, they make one main assumption and one crucial adjustment. These networks assume that the input is an image, and nothing else. They then introduce parameter recycling and the replacement of fully-connected layers with convolutions. Because of the nature of images, sharing of parameters across the network is possible, reducing their number drastically. By expecting image input, and by recognizing the regular ``nature of images'' to be consistent, one can build in premeditated adjustments to the network through various techniques \cite{convnets}. To understand why such an assumption works, one can consider how one section of an image may share properties with another section of the image. It is possible in such a situation to replace the fully-connected ``filter'' with local and smaller filters (e.g. $3\times3$), only looking at one section of the image at a time. This filter can then be moved, *with the same weight parameters*, to other sections of the image, keeping in mind that if the filter works at one location in the image it should also be applicable at another location. This again is realizable due to the aforementioned ``nature of images'': namely that they share properties throughout their field \cite{convnets}. Replacing our first fully-connected layer in our previous example with a reasonable convolution layer with, say, 64 outputs and a filter-size of $3\times3$ would result in a weight parameter matrix of only size $3\times3\times3\times64 \approx 1.7K$.

\bildgross{figures/cnn.png}{A basic convolutional neural network}{A basic convolutional neural network. Weight parameters are stored only for a predetermined amount of filters (here, ``f.maps'') of a certain dimension. For example, shown are five filters of size $5\times5$ for one convolution, followed by twelve filters of size $3\times3$ for the second). [CC Image courtesy of Aphex34 on Wikimedia Commons]}{fig:cnn}

\subsection{Architecture}
\subsubsection{Overview}
Popular convolutional neural network models, although diverse, tend to vary in systematic ways. In their most basic form, CNNs may be comprised of only a few types of layers: the input layer, the convolution, the pooling layer, activation layers (e.g. ReLU), and the fully-connected layer \cite{convnets}. Typically, most of the heavy lifting in terms of computational resources will be, by a strong margin, performed by the convolutional layers. Famous convolutional neural network architectures include AlexNet, GooglNet, ResNet and VGG, all of which differ in layer number, layer ordering, and convolution layer parameters, such as the number of filters, the size of the filters, and the stride of the filters. These layers are arranged in varying fashion to make up the skeletons of the well-known convolutional neural networks. To see some typical architectures outlined, refer to Table \ref{tbl:cnns} on page \pageref{tbl:cnns}.

\begin{table}[]
\centering
\caption[Some well-known CNN architectures]{The basic outline of some well-known CNN architectures.}
\label{tbl:cnns}
\begin{tabular}{llll}
\multicolumn{4}{l}{(ReLU layers omitted)}                              \\
\textbf{LeNet} & \textbf{cifar-10} & \textbf{VGG-16} & \textbf{VGG-19} \\
conv           & conv              & conv            & conv            \\
pool           & pool              & conv            & conv            \\
conv           & conv              & pool            & pool            \\
pool           & pool              & conv            & conv            \\
fc             & conv              & conv            & conv            \\
fc             & pool              & pool            & pool            \\
               & fc                & conv            & conv            \\
               & fc                & conv            & conv            \\
               &                   & conv            & conv            \\
               &                   & pool            & conv            \\
               &                   & conv            & pool            \\
               &                   & conv            & conv            \\
               &                   & conv            & conv            \\
               &                   & pool            & conv            \\
               &                   & conv            & conv            \\
               &                   & conv            & pool            \\
               &                   & conv            & conv            \\
               &                   & pool            & conv            \\
               &                   & fc              & conv            \\
               &                   & fc              & conv            \\
               &                   & fc              & pool            \\
               &                   &                 & fc              \\
               &                   &                 & fc              \\
               &                   &                 & fc
\end{tabular}
\end{table}

\subsubsection{The convolution layer}
The convolution layer is the cornerstone of the convolutional neural network, and is made up of several components.

The first component of a layer $l$ is the layer activation itself (the layer output). The general form of a layer activation $a_{l}$ in a convolutional neural network can be interpreted as a three-dimensional tensor $X\times Y\times D$ where $X$ and $Y$ are the activation dimensions and $D$, or the activation depth, is equal to the number of kernels applied to the input.

The second component, the input of the current layer $a_{l}$, is equivalent to the activation of the previous layer as follows:

\begin{equation}
\label{eqn:forward}
input_{a_{l}} = a_{l-1}.
\end{equation}
\myequations{Feeding forward}

Note that the initial image or first layer of a network is an $X\times Y\times 3$ tensor, where $D$ in this case represents the RGB color channels of the original image. Beyond the input layer, the value of $D$ at $a_{l}$ is then the number of kernels just applied to the input $a_{l-1}$.

The third component is the kernel set, made up of $D$ kernels. Each kernel $kernel_d$ of the kernel set is a three-dimensional tensor and is of shape $M\times M\times Z$, where $M$, representing the kernel width and height, is of a predetermined dimension (usually small, e.g. $3$, or perhaps $7$). $Z$ is the kernel depth, and is equivalent to $D_{l-1}$, or the previous activation's depth. Each kernel $kernel_d$ makes up a three-dimensional tensor reaching through the entire depth $Z$ of the input. The role of each kernel is to slide across the input at a predetermined ``stride'', much like a moving window, gathering a dot product at each slice of itself along $Z$ with the current input lying within this window, and summing each of these products to return a single value \cite{convnets}. Each of the kernels $kernel_d$ performs its task as described above, delivering a two-dimensional matrix product result. These two-dimensional results are then stacked along $D$ to form the three-dimensional volume $a_{l}$ seen in Figure \ref{fig:convlayer}.

\bildklein{figures/convlayer.png}{The convolution kernel at work}{Each set of kernels (here, of count five) focuses on a small section of the input (in pink) at a time, reaching through its entire depth. The result from each of these sets of three-dimensional kernels is a stack of two-dimensional activations, making up one three-dimensional section (small rectangle in blue) of the total output volume (large box in blue), having the depth of the number of kernels in the set. This operation is repeated all over the image. [CC Image courtesy of Aphex34 on Wikimedia Commons]}{fig:convlayer}

The remaining components make up what can be viewed as the hyperparameters of the kernel, and include its shape, its stride and the amount---if any---of padding it adds to the input layer. A typical size is $3\times3$, and a typical stride is one.

During the forward pass, each element $a_{l}[x,y,d]$ is computed by applying the $kernel_{d}$ to a region of $a_{l-1}$ of size $M\times M\times Z$, performing dot products along each dimension $Z$ and summing these products. After each such calculation, the kernel moves along from left-to-right, top-to-bottom at an increment equal to the stride parameter. This is then repeated for all kernels and the results are stacked along $D$. Equation \ref{eqn:conv} below shows this operation for one kernel, assuming that stride is set to one and there is no zero-padding. In practice, convolution reduces the size of the input volume along the length and width dimensions, and adding padding beforehand can amend this.

\begin{equation}
\label{eqn:conv}
a_{l}[x,y,d] = \sum_{i=0}^{M-1}\sum_{j=0}^{M-1}\sum_{z=0}^{Z-1}{a_{l-1}[x+i,y+j,z] * kernel_{d}[i,j,z]}
\end{equation}
\myequations{The convolution operation}

\subsubsection{Pooling and relu layers}
Pooling layers are also important in understanding how CNNs change the input volume. They are different in that they don't contain weights, and are therefore lightweight and not a natural candidate for optimization like the convolution layer.

The pooling layer takes three required hyperparameters: pooling size, pooling mode and stride (for the sake of simplicity, this description will assume a padding of zero). Pooling size, or the pooling dimensions $a$ and $b$, define the size of the pooling kernel, much like the kernel in the convolution layer. The pooling mode is typically average-pool or max-pool \cite{convnets}, denoting mathematical operations of mean-value or maximum-value, respectively.

The layer takes an input volume $p$ of size $[x,y]$ and, assuming a stride of one, returns a reduced input volume $p'$ of size $\frac{x}{a},\frac{y}{b}$, where $a$ and $b$ are the kernel dimensions. To determine an element at the output volume $p'$, with a pooling mode of maximum-value, a kernel with dimensions $a\times b$ and a stride of one, the pooling layer performs the following operation:

\begin{equation}
\label{eqn:pool}
p'[x,y] = \max_{i=0}^{a-1}\max_{j=0}^{b-1}{p[x+i,y+j]}.
\end{equation}
\myequations{Maximum-value pooling}

Notice that unlike convolution, the are no kernel parameters. The pooling layer serves to reduce the size of the input layer and in this sense, can indirectly have a dramatic effect on the speed of the network by reducing the input size of a subsequent convolution layer, thus reducing the total number of FLOPS needed for such an operation.

ReLU layers, like pooling layers, don't contain parameters. However unlike pooling layers, they do not change the input volume size. Their purpose is to apply an element-wise non-linearity to a layer, and are somewhat uninteresting in the context of this work.

\section{GEMM}
As previously mentioned, in the case of the famous AlexNet architecture, 89\% of computational processing time is taken up by convolutions. Thus, it is a worthy undertaking to optimize the mathematical operation itself, making it as efficient as possible for the computer. The agreed upon solution is the GEMM operation, or General Matrix to Matrix Multiplication, dating back to 1979 and described in ``Basic Linear Algebra Subprograms for Fortran Usage,'' or BLAS \cite{BLAS}. BLAS improves upon the normal convolution operation by transforming it into one single matrix-matrix multiplication. Normally, a convolution involves the process described in Equation \ref{eqn:conv} on page \pageref{eqn:conv}, where a filter performs tiny matrix-matrix multiplications all over the image. Instead, GEMM performs the ``image-to-column'' operation (commonly known as ``im2col'') \cite{im2col}, successfully translating the input volume and weight kernels such that the result of a convolution involves one and only one matrix multiplication between the im2col output of input and the im2col output of weights.

Behind the scenes, im2col is simply serializing each input selection (small pink box in Figure \ref{fig:convlayer} on page \pageref{fig:convlayer}) into one row of the new input matrix. Similarly, each kernel is serialized as a column of the new weight matrix. The result is now a classic matrix-matrix multiplication, visualized in Figure \ref{fig:mm}. Effectively, performing im2col and then matrix multiplication is equivalent to performing convolution as described in \ref{eqn:conv} on page \pageref{eqn:conv} for all values of $k$.

\bildklein{figures/matrixmult.png}{Matrix multiplication}{After GEMM prepares the input and weight volumes, the result of a convolution is obtained simply through traditional matrix-matrix multiplication. [CC Image courtesy of Quartl on Wikimedia Commons]}{fig:mm}

In the next section, now with a firm understanding of the inner workings of convolutional neural networks and the convolution operation itself, quantization, as a method to reduce computational overhead and increase inference speed, is discussed.

\section{Quantization}
\subsection{Computer number representation}
In order to understand why quantization is important, it would be beneficial to review how the computer stores numbers.

32-bit floating-point representation is a computer representation of real numbers. Although an estimation in itself---as real numbers are infinite and computer-representations cannot be---they offer a certain degree of precision in number representation and calculations \cite{ieee}. In a computer, they take scientific notation form (see Equation \ref{eqn:floatrep} below) and can represent $2^{32}$ individual values. They use one bit for the sign, eight bits for the exponent, and 23 bits for the fraction \cite{ieee}.

\begin{equation}
\label{eqn:floatrep}
-9.876 = \overbrace{\underbrace{-1}_\text{sign}}^\text{1 bit}\times\overbrace{\underbrace{9876}_\text{fraction}}^\text{23 bits}\times\overbrace{\underbrace{2^{-3}}_\text{exponent}}^\text{8 bits}
\end{equation}
\myequations{32-bit floating-point representation}

Integers, on the other hand, are represented by a fixed amount of bits, such as eight \cite{ieee}. 32-bit/ 64-bit processors are able to access large chunks of memory at a time, and it would in theory be faster to use integers rather than floating-point representation, as $\times4$ the amount of numbers would be accessed within a single memory-retrieval operation, reducing memory bandwidth by 75\%. However, 8-bit integers have the potential to represent only $2^{8}$ distinct numbers, and thus using them comes at a precision cost. It will be shown, despite this significantly reduced precision, that using integer representation in convolution calculations is still worthwhile.

\subsection{The quantization process}
In short, quantization is a conversion of floating-point representation, specifically 32-bit floating-point, to integer representation, or 8-bit fixed-point. The process of quantization is relatively straightforward. Taking the minimum and maximum of the floating-point representation, a new range is defined using an appropriate integer representation, such as 0 to 255. \cite{warden_quantize}. In other words, 0 will now represent the minimum value from the original unquantized matrix and 255 the maximum value (see Table \ref{tbl:quantize} below).

\begin{table}[]
\centering
\caption[Quantized value representation]{Quantized value representation.}
\label{tbl:quantize}
\begin{tabular}{ll}
\textbf{32-bit} & \textbf{8-bit} \\
-2.356          & 0              \\
1.201           & 127            \\
4.758           & 255
\end{tabular}
\end{table}

\subsection{The quantization process broken down}
\label{sec:quantization}
Mathematically, the conversion from a floating-point tensor $f$ to integer representation $q$ involves a few processes, the first of which is to derive a quantization scale parameter from the minimum and maximum of the floating-point representation as follows:

\begin{equation}
\label{eqn:scale}
scale = \frac{\max_{f} - \min_{f}}{255 - 0}.
\end{equation}
\myequations{Quantization: the scale parameter}

Next, the zero-point of the quantized representation is determined and rounded as an integer,

\begin{equation}
\label{eqn:zero}
zero point_{q} = round(\min_{f} - \frac{\min_{q}}{scale}),
\end{equation}
\myequations{Quantization: the zero-point parameter}

and finally the floating-point values are converted to integers with the scale and zero point parameters,

\begin{equation}
\label{eqn:convert}
q[x,y,z] = zero point_{q} + \frac{f[x,y,z]}{scale},
\end{equation}
\myequations{Quantization: converting to integer}

and confined within the constraints of the defined quantized range if they happen to fall outside of it \cite{gemmlowp} like so:

\begin{equation}
\label{eqn:clamp}
\begin{aligned}
u = \min_{255, q[x,y,z]}
\\
q[x,y,z]_{confined} = \max_{0, u},
\end{aligned}
\end{equation}
\myequations{Quantization: confining the input}

where $x$, $y$ and $z$ represent tensor coordinates.

After quantization, calculations are performed as usual. The result is then converted back into 32-bit float using more minimum and maximum parameters and passed along the network.

It may be apparent to the reader at this point that there is not insignificant overhead involved in this process: namely, determining parameters and converting back and forth between quantized and dequantized representations for each convolution layer. This will be addressed later in this work.


\subsubsection{Swaption}
\label{ss:swaption}

The \lstinline!SwaptionData!  node is the trade data container for the \emph{Swaption} trade type. The \lstinline!SwaptionData!
node has one and exactly one \lstinline!OptionData! trade component sub-node, and at least one \lstinline!LegData! trade
component sub-node.  These trade components are outlined in section \ref{ss:option_data} and section
\ref{ss:leg_data}.\\
\vspace{5mm}
Supported swaption exercise styles are \emph{European} and \emph{Bermudan}.  Swaptions of both exercise styles must have two legs, with
each leg represented by a \lstinline!LegData! sub-node.  Cross currency swaptions are not supported for either exercise style, i.e. the Currency element must
have the same value for all \lstinline!LegData! sub-nodes of a swaption. There must be at least one full coupon period after the exercise date for European
Swaptions, and after the last exercise date for Bermudan Swaptions. See Table \ref{tab:swaption_requirements} for further details on requirements for
 swaptions.\\
\vspace{5mm}
The structure of an example \lstinline!SwaptionData!  node of a European swaption is shown in Listing
\ref{lst:swaption_data}.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<SwaptionData>
    <OptionData>
        <LongShort>Long</LongShort>
        <Style>European</Style>
        <Settlement>Physical</Settlement>
        <ExerciseDates>
          <ExerciseDate>2027-03-02</ExerciseDate>
        </ExerciseDates>
        ...
        <Premiums>
          <Premium>
            <Amount>807000</Amount>
            <Currency>GBP</Currency>
            <PayDate>2021-06-15</PayDate>
          </Premium>
        </Premiums>
    </OptionData>
    <LegData>
        <LegType>Fixed</LegType>
        <Payer>false</Payer>
        <Currency>GBP</Currency>
        ...
    </LegData>
    <LegData>
        <LegType>Floating</LegType>
        <Payer>true</Payer>
        <Currency>GBP</Currency>
        ...
    </LegData>
</SwaptionData>
\end{minted}
\caption{Swaption data}
\label{lst:swaption_data}
\end{listing}

\begin{table}[H]
\centering
\begin{tabular} {|l|p{10cm}|}
    \hline
        & \bfseries{A  Swaption requires:} \\  \hline
    \lstinline!OptionData! & One \lstinline!OptionData! sub-node  \\  \hline
   \lstinline!Style! &  \emph{Bermudan} or \emph{European}\\ \hline
    \lstinline!ExerciseDates! & \emph{Bermudan} swaptions  require at least two \lstinline!ExerciseDate! child elements.  \emph{European} swaptions can only have one \lstinline!ExerciseDate! child element. Note that the exercise date of a \emph{European} swaption must be before or on the start date of the underlying swap. \\ \hline
    \lstinline!LegData! &  Two \lstinline!LegData! sub-nodes \\ \hline
    \lstinline!Currency! & The same currency for both nodes.\\ \hline
    \lstinline!LegType! & \emph{Bermudan} swaptions must have: \emph{Fixed} on one node and \emph{Floating} on the other.  No such requirement for \emph{European} swaptions.     \\ \hline
%    \lstinline!Notionals! & No accretion or amortisation, just a constant notional. Exactly one \lstinline!Notional! child element for each node.\\ \hline
%   \lstinline!Rates! & A constant rate. The fixed rate node should have exactly one \lstinline!Rate! child element.\\ \hline
%    \lstinline!Spreads! &  A constant spread. The floating rate node should have exactly one \lstinline!Spread! child element.\\ \hline
%    \bfseries{ScheduleData} &   \\ \hline
%    \lstinline!IsRuleBased! & Must be \emph{true} for both nodes. TBC: Fixed by Henning?\\ \hline
  \end{tabular}
  \caption{Requirements for Swaptions}
  \label{tab:swaption_requirements}
\end{table}

The \lstinline!OptionData! trade component sub-node is outlined in section \ref{ss:option_data}.
The relevant fields in the \lstinline!OptionData! node for a Swaption are:

\begin{itemize}
\item \lstinline!LongShort!: The allowable values are \emph{Long} or \emph{Short}. Note that the payer and receiver legs in the underlying swap are always from the perspective of the party that is \emph{Long}. E.g. for a \emph{Short} swaption with a fixed leg where the Payer flag is set to \emph{false}, it means that the counterparty receives the fixed flows.

\begin{table}[H]
\centering
\begin{tabular} {| c | c | c | c |}    \hline
        \lstinline!LongShort! & \makecell{\lstinline!Payer! for Fixed leg \\ on underlying Swap} & \makecell{\lstinline!Payer! for Floating leg \\ on underlying Swap} & Resulting Set Up and Flows \\  \hline
   \emph{Long} & \emph{true} & \emph{false} & \makecell[l]{The Party to the trade buys an \\ option to enter a swap where the \\ Party pays fixed and receives \\ floating}  \\  \hline
    \emph{Short} & \emph{true} & \emph{false} & \makecell[l]{The Party to the trade sells an \\ option to the Counterparty to enter \\ a swap where the Counterparty \\ pays fixed and receives floating}  \\  \hline
    \emph{Long} & \emph{false} & \emph{true} & \makecell[l]{The Party to the trade buys an \\ option to enter a swap where the \\ Party receives fixed and pays \\ floating}  \\  \hline
    \emph{Short} & \emph{false} & \emph{true} & \makecell[l]{The Party to the trade sells an \\ option to the Counterparty to enter \\ a swap where the Counterparty \\ receives fixed and pays floating}  \\  \hline
  \end{tabular}
  \caption{Swaption set up and resulting flows}
  \label{tab:swaption_setup}
\end{table}

\item \lstinline!OptionType![Optional]: This flag is optional for swaptions, and even if set, has no impact. Whether a swaption is a payer or receiver swaption is determined by the Payer flags on the legs of the underlying swap.

\item  \lstinline!Style!: The exercise style of the Swaption. The allowable values are \emph{European} or \emph{Bermudan}.

\item \lstinline!NoticePeriod![Optional]: The notice period defining the date (relative to the exercise date) on which the exercise
  decision has to be taken. If not given the notice period defaults to \emph{0D}, i.e. the notice date is identical to the
  exercise date. Allowable values: A number followed by \emph{D, W, M, or Y}

\item \lstinline!NoticeCalendar![Optional]: The calendar used to compute the notice date from the exercise date. If not given
  defaults to the \emph{NullCalendar} (no holidays, weekends are no holidays either). Allowable values: See Table \ref{tab:calendar} \lstinline!Calendar!.

\item \lstinline!NoticeConvention![Optional]: The convention used to compute the notice date from the exercise date. Defaults to
  \emph{Unadjusted} if not given. Allowable values: See \lstinline!Roll Convention! in Table \ref{tab:allow_stand_data}.

\item  \lstinline!Settlement!: Delivery Type. The allowable values are \emph{Cash} or \emph{Physical}.

\item \lstinline!SettlementMethod![Optional]: Specifies the method to calculate the settlement amount for Swaptions and CallableSwaps. Allowable values: \emph{PhysicalOTC}, \emph{PhysicalCleared}, \emph{CollateralizedCashPrice}, \emph{ParYieldCurve}. Defaults to \emph{ParYieldCurve} if Settlement is \emph{Cash} and defaults to \emph{PhysicalOTC} if Settlement is \emph{Physical}.

\emph{PhysicalOTC} = OTC traded swaptions with physical settlement\\
\emph{PhysicalCleared} = Cleared swaptions with physical settlement\\
\emph{CollateralizedCashPrice} = Cash settled swaptions with settlement price calculation using zero coupon curve discounting \\
\emph{ParYieldCurve}  = Cash settled swaptions with settlement price calculation using par yield discounting \footnote{https://www.isda.org/book/2006-isda-definitions/} \footnote{https://www.isda.org/a/TlAEE/Supplement-No-58-to-ISDA-2006-Definitions.pdf} \\

\item \lstinline!ExerciseFees![Optional]: This node contains child elements of type \lstinline!ExerciseFee!. Similar to a list of notionals
  (see \ref{ss:leg_data}) the fees can be given either

  \begin{itemize}
  \item as a list where each entry corresponds to an exercise date and the last entry is used for all remaining exercise
    dates if there are more exercise dates than exercise fee entries, or
  \item using the \verb+startDate+ attribute to specify a change in a fee from a certain day on (w.r.t. the exercise
    date schedule)
  \end{itemize}

  Fees can either be given as an absolute amount or relative to the current notional of the period immediately following
  the exercise date using the \verb+type+ attribute together with specifiers \verb+Absolute+ resp. \verb+Percentage+. If
  not given, the type defaults to \verb+Absolute+. \verb+Percentage+ fees are expressed in decimal form, e.g. 0.05 is a fee of 5\% of notional.

  If a fee is given as a positive number the option holder has to pay a corresponding amount if they exercise the
  option. If the fee is negative on the other hand, the option holder receives an amount on the option exercise.

  Only supported for Swaptions and Callable Swaps currently.

\item \lstinline!ExerciseFeeSettlementPeriod![Optional]: The settlement lag for exercise fee payments. Defaults to 0D if not
  given. This lag is relative to the exercise date (as opposed to the notice date). Allowable values: A number followed by \emph{D, W, M, or Y}

\item \lstinline!ExerciseFeeSettlementCalendar![Optional]: The calendar used to compute the exercise fee settlement date from the
  exercise date. If not given defaults to the \emph{NullCalendar} (no holidays, weekends are no holidays either). Allowable values: See Table \ref{tab:calendar} Calendar.

\item \lstinline!ExerciseFeeSettlementConvention![Optional]: The convention used to compute the exercise fee settlement date from
  the exercise date. Defaults to \emph{Unadjusted} if not given. Allowable values: See \lstinline!Roll Convention! in Table \ref{tab:allow_stand_data}.

\item An \lstinline!ExerciseDates! node where exactly one \lstinline!ExerciseDate! date element must be given for \emph{European} style swaptions, and for \emph{Bermudan} style swaptions  at least two \lstinline!ExerciseDate! date elements must be given. \\

\item Premiums [Optional]: Option premium amounts paid by the option buyer to the option seller.

Allowable values:  See section \ref{ss:premiums}

\end{itemize}


\chapter{Robust instrumental variables estimation}
\label{chap:iv}

\begin{itemize}
\item
    Robust IV/2SLS estimators   % Cohe Freue-Zamar method, the Amemyia 2 proposal, tests
\end{itemize}

\endinput


\section{Results}

In this section, we consider data for each research questions in more detail.

\subsection{{\bf RQ1}: Comparing news and Twitter }
\begin{figure}[t]
	\centering
	\includegraphics[width=.5\textwidth]{imgs/diff_sigma}
	\caption{Distribution of Sigmas}
	\label{fig:sig}
\end{figure}

While a host of comparisons could be made between the news and Twitter data we study, we restricted ourselves here to a subset of questions of particular interest. First, we are interested in the level of variance over time in discussions of particular themes in particular countries on Twitter as compared to in news.  Conveniently, our statistical model provides us with a parameter, $\sigma^2_{w,r}$ which captures the extent of this variability. Figure~\ref{fig:sig} shows a density plot detailing the distribution of values for $\sigma^2_{w,r}$ for the news and Twitter data.  As is clear, Twitter data is much more variable in the news, both in the average variability across a particular theme/country time series and with respect to the expected value of $\sigma^2_{w,r}$ in general.  This finding shows that news coverage of the Arab Spring was more stable than discussion on Twitter.  Our results correlate with the idea that while the propagation of content is similar in form in both Twitter and news media,  the social elements of Twitter introduce important variability in the diffusion and longevity of discussion \citep{yang_patterns_2011}.  Perhaps more importantly, our findings show that the extent to which a change in thematic focus is ``interesting'' differs when analyzing news versus Twitter data. Researchers using social media data to interpret change in social processes, our data suggests, must be more cautious than those with access to news data.

In addition to levels of variability in the two media, we are also interested in the extent to which news and Twitter data focused on the same topics at the same time.  That is, we are interested in the extent to which the time series of $\eta_{w,r,t}$ values for Twitter and news are correlated for a particular theme/country combination.  Importantly, this correlation cannot be measured directly with our $\eta_{w,r,t}$ - baked into our model is the assumption of autocorrelation with a one-month lag (Equation~\ref{eq:eta_eq}), which will lead to spuriously high correlation values.  To infer correlations between news and Twitter data, we therefore must remove the autocorrelation by subtracting the prior month's value from each activation score.  More specifically, for a given country $r$ and category $w$, we construct a vector of observations $\eta_{w,r,t}-\eta_{w,r,t-1} \quad \forall \, t > 1$ for both Twitter and news data. These vectors are, via the assumptions of our model, void of autocorrelation and can therefore be compared directly using, for example, a simple Pearson correlation.

The first question is whether or not there is a significant correlation between the news and Twitter across all countries and themes. Importantly, we would expect this correlation to be positive and significant for the non-stopword data, and to be close to zero for our stopword themes. Using the bootstrap procedure  with 10000 iterations, we construct 99\% confidence intervals using a pivot interval \citep{wasserman_all_2003} on the Pearson correlation between news and Twitter data. That is, we determine the extent to which the changes in activation from the previous month in Twitter data are linearly correlated with changes from the previous month in news data, taking as input all observations across all countries.  We perform this analysis twice, once for the non-noise (non-Stopword) themes and once for the noise-only themes.

The correlation for the non-noise data is .23 [.17,.28], indicating a moderate but significant correlation between news and Twitter.  There are several reasons for the existence of this correlation. Perhaps most importantly, it is well known that news agencies send tweets about their key stories, and retweets of these stories comprise an important component of discussion on Twitter. Thus news and Twitter should be correlated, as they form a part of a symbiotic media system.  In some sense, it is therefore interesting that the correlation between the two media is not higher.  One obvious reason is that personal, socially-focused discussions do of course occur on Twitter. Additionally, a large volume of tweets are known to be sent by bots on Twitter, many of which are just tweeting nonsense phrases.

The correlation for the noise-only data was .1 [-.001, .19].  Results suggest that correlations between non-noise themes is (significantly) greater than noise themes, and that the noise data was not significantly different from 0 at $\alpha=.01$. However, results do indicate that there may still be some level of correlation in the residual noise in our data between news and Twitter.  This may be due to a variety of factors, perhaps most obviously the fact that we treat each country independently.  While future work may consider means of addressing these biases, we instead choose here only to account for the possible existence of this spurious correlation when considering further results. We now turn to explore which themes had the strongest and weakest correlations between news and Twitter (across all countries).

\begin{figure}
	\centering
	\includegraphics[width=.5\textwidth]{imgs/cat_corr}
	\caption{News/Twitter correlations by category.  Confidence intervals are 99\% bootstrapped CIs calculated with a pivot interval and 10000 iterations}
	\label{fig:cat_corr}
\end{figure}

Figure~\ref{fig:cat_corr} presents the correlations between news and Twitter data for each category, with data aggregated across countries. Additionally, we have aggregated all noise categories into a single category, entitled "All Stopword Categories".  Confidence intervals are constructed in the same way as above, and are shown in the figure via the lines for each category. Mean estimates are shown with a dot.  Figure~\ref{fig:cat_corr} shows that the strongest correlations between news and Twitter occur in reference to general indicators of revolution, specifically, protest and violence. The general level of correlation across these categories supports the idea that news and Twitter discussions specific to the revolution fed off of each other \citep{cottle_media_2011,comunello_will_2012}. Additionally, we can expect that this may be due to the fact that the Tweets by news agencies are focusing in this area. In addition, we observe strong correlations between media in discussions of adaptation and change and to ethnicity.

On the other hand, in comparison to the Stopword categories,  there is no significant correlation\footnote{at a level of $\alpha=.001$ using the parametric test described in \citep{zou_toward_2007}} for discussions of national identity, youth movements, terrorist organizations and war.  With reference to the ``selecting on the dependent variable'' problem in social media research \citep{tufekci_big_2014}, our findings indicate that scholars focusing too heavily on particular topics may over or under-estimate the correlations between topical focuses of news and Twitter.  Perhaps most interesting is the fact that while discussion of Ethnic, or non-national, identities was highly correlated between the two media, discussion of national identities show little, if any, correlation between media  This difference is important in considering the extent to which news or Twitter data can be used to support the idea of an evolving national identity in contrast to factionalized identities, and suggests that the evolution of a national identity may be a factionated process that is not well monitored by using a single media source. Thus, in future study of \citeapos{goldstone_cross-class_2011} hypotheses on how the proliferation of national identity was important to the success of revolutions, one must consider both news media and Twitter separately in attempting to understand how the existence of a national identity played out in the media landscape surrounding the Arab Spring.

\begin{figure}
	\centering
	\includegraphics[width=.5\textwidth]{imgs/country_corr}
	\caption{News/Twitter correlations by country}
	\label{fig:corr_country}
\end{figure}

Finally, Figure~\ref{fig:corr_country}  shows correlations between news and Twitter across countries, aggregating across all non-noise themes.  Here, as there is no noise baseline to compare to, we only consider differences from zero in our interpretation.  In light of previous work, the most interesting point to be taken from Figure~\ref{fig:corr_country} is that countries where data has been compared across news and Twitter in the past differ in the ways in which news relates to Twitter. In particular, while there are high levels of correlation between news and Twitter in Libya, Syria and Egypt, no significant correlation exists between these two media in Tunisia.  This implicates the fact that consideration of a single country may also lead to biased conclusions on the relationship between news and Twitter during the Arab Spring. More specifically, it seems that in countries with sustained levels of civil unrest (Syria, Egypt and Libya), news and Twitter are more likely to converge on thematic discussions. In contrast, in countries like Tunisia, where the majority of the civil unrest was short-lived, thematic discussions appear to deviate between the two media. Similarly, correlations in nations where no massive government change occurred show only weak or non-existent correlations between the media.  This may be because in these countries the discussion in the news was on political, economic an global events, but in Twitter it focused on social, cultural and personal events.

\subsection{{\bf RQ2:} Relating to events on the ground}

\begin{table*}[t]
\centering
\begin{tabularx}{\textwidth}{|m{.3cm}| l| l| l| l| m{.7cm}|  X |}
  \hline
 N & Category & Country & Media & Date & +/- Change & Major Event \\
  \hline
1 & War & Syria & News & 3/2011 & - & Week of March 15-21 is considered to be the beginning of the Syrian uprising\footnote{\url{http://en.wikipedia.org/wiki/Syrian_Civil_War#Protests_and_armed_insurgency_.28July_.E2.80.93_October_2011.29}} \\   \hline
  2 & Protest & Syria & News & 3/2011 & + &Week of March 15-21 is considered to be the beginning of the Syrian uprising \\   \hline
  3 & Ethnic Groups & UAE & Twitter & 10/2012 & + & EU report condemning human rights climate in UAE \\   \hline
  4 & Protest & Tunisia & Twitter & 8/2012 & + & Tunisian women stage large protests\footnote{\url{http://www.aljazeera.com/indepth/features/2012/08/201281981854620325.html}} \\   \hline
  5 & War & Lebanon & News & 3/2011 &  - & Major rallies throughout the nation on various days\footnote{\url{http://en.wikipedia.org/wiki/2011_Lebanese_protests}}\\   \hline
  6 & Adaptation & Libya & Twitter & 8/2012 & + & First free elections were held in Libya in July, 2012   \\ \hline
  7 & Adaptation & Tunisia & Twitter & 10/2011 &  - & First free election in Tunisia since 1956\footnote{\url{http://en.wikipedia.org/wiki/Tunisian_Constituent_Assembly_election,_2011}} \\   \hline
  8 & Terrorist Orgs & Libya & News & 9/2012& + & Attack on U.S. consulate in Benghazi, Libya \\   \hline
  9 & Terrorist Orgs & Egypt & Twitter & 11/2012 & + & Major protests in Tahrir Square and the beginning of Parliamentary Elections \\  \hline
  10 & Adaptation & UAE & Twitter & 10/2012 &  - & EU report condemning human rights climate in UAE  \\
   \hline
\end{tabularx}
\caption{The top 10 most surprising changes in activation from the previous month.  The column ``+/- change'' indicates if the change was an increase or decrease in activation.  The column ``Major Events'' gives an explanation of the major events that occurred during that month or the previous month (as change is relative to the previous month), or none if no such event occurred.}
\label{tab:events}
\end{table*}

In this section, we explore the extent to which large, sudden changes in activation rates in particular theme/country pairs were indicative of important real-world changes occurring in the Arab world.  Table~\ref{tab:events} lists the ten most ``surprising'' jumps in terms of change in activation from one month to the next.  We ranked the extent to which events were surprising using absolute change in activation, controlling for the overall level of variance for a particular theme/country pair.  That is, for month $t$ in country $r$ for theme $w$, surprise was calculated as $\frac{|\eta_{w,r,t}-\eta_{w,r,t-1}|}{\sigma^2_{w,r}}$.  Table~\ref{tab:events} also shows whether the change was positive or negative (in the column ``+/- change'') and briefly details the major events we believe led to this change.

Model output shows that the beginning of the Syrian Civil War had the strongest impact on news media. Discussion of war decreased significantly relative to the previous month, as reporters sought to cover the increasing volume and intensity of protests throughout the country. These events, of course, marked the beginning of a civil war that is still well under way (as of the time of writing), showing the model’s propensity to capture important changes in events via news media. In general, sizeable changes in news media’s topical coverage were relevant to emergent protests. Interestingly, this focus appears to manifest in our model as a decrease in discussion of war as opposed to an increase in the discussion of protest. That is, the shift of news coverage away from war or the possibility of war is as indicative of critical protest events as is discussion of the protests themselves. We will see that this effect is significant in interpreting news discussion with respect to Libya, as we explore in our case study.

In contrast to news media, the most prominent events that caused observable large shifts on Twitter were elections. In Libya and Tunisia, elections led to differences in discussions of adaptation and change, a sign that these elections may have promoted an influx of hopeful discussion of a new era in these countries. In contrast, in Egypt, elections led to increased discussions on organizations with known connections to terrorism, for example, the Muslim Brotherhood or al-Qaeda. The difference in thematic focus in these different elections is an important implication of the differences regarding sentiments towards the elections in each country, and something of interest to future work In addition to elections, the gender equality protests in Tunisia, staged heavily on social media \citep{yuce_womens_2015}, appear as a signal in the Twitter data but not in the news data.

Finally, with respect to the Twitter data, two entries relating to the UAE in Table~\ref{tab:events}, both of which are relevant to the publication of a European Union report condemning human rights conditions for certain ethnic groups in the country, show up as events which captured a surprising level of discussion relative to the general level of focus on the themes of ethnic identity and adaptation to change in the UAE. Similarly, in the news data, a surprising level of discussion focuses on the attack of a U.S. consulate in Benghazi, Libya.  These issues were relatively minor with respect to their implications for the Arab Spring, but relatively major with respect to the interest drawn to them by U.S. and U.K. media.  The change in discussion that resulted from these events is thus a reminder that the Western-media centric data utilized for this study presents a possible roadblock in


\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{commath}

%\usepackage{siunitx}
\usepackage[margin=0.5in]{geometry}
\definecolor{darkgreen}{rgb}{0.0, 0.6, 0.0}
\usepackage[parfill]{parskip}

\bibliographystyle{acm}

\begin{document}

\title{A synthetic multicellular system to deliver a therapeutic "cargo"}
\date{}
\author{}
\maketitle

\section{Introduction}
This app demonstrates how simple ``rules'' for chemical- and contact-based
communication could be used for \emph{active} delivery of therapeutic
compounds, while overcoming traditional biotransport limits and using
hypoxia to target delivery. It is based on a published PhysiCell example
in Ghaffarizadeh et al.\cite{physicell-2018}. In this model, \textcolor{darkgreen}{cancer cells
(green)} rapidly divide while consuming oxygen, which drives the
emergence of hypoxic gradients. Greater availability of oxygen drives
faster proliferation, while low oxygen can trigger necrotic death,
creating a necrotic core ({brown cells}) in the center of the tumor.
After initial growth, we "inject" a multicellular synthetic therapy.

In this (for now theoretical) synthetic therapy, \textcolor{red}{"worker cells" (red)}
search for \textcolor{blue}{"cargo cells" (blue)}, form focal adhesions, and haul their
cargo towards hypoxic (oxygen-depleted) regions in the tissue. Once they
reach a region of sufficiently low oxygen, they release their cargo and
resume their initial search for more cargo. Released cargo cells secrete
a chemotherapeutic compound that can kill nearby tumor cells. (Cancer
cells are shaded according to their level of therapy-induced damage.)

This model and cloud-hosted demo are part of a course on computational
multicellular systems biology created and taught by Dr. Paul Macklin in
the Department of Intelligent Systems Engineering at Indiana University.
It is also part of the education and outreach for the NSF-funded IU Engineered
nanoBIO Node and the NCI-funded cancer systems biology grants.
The models are built using
\href{https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005991}{PhysiCell}:
a C++ framework for multicellular systems biology.

\section{Chemical components}
All chemical signals move by chemical diffusion in the simulated
environment, using
\href{http://dx.doi.org/10.1093/bioinformatics/btv730}{BioFVM}\cite{Ghaffarizadeh2016-ga}
to solve the reaction-diffusion equations. A key property is the
\emph{diffusion length scale}. Diffusion (with a diffusion coefficient
\emph{D}) helps spread a signal over large distances, while decay (and
uptake) (with coefficient $\lambda$) eliminates the signal to slow its
spread. These effects compete to determine the characteristic distance
\emph{L} that a chemical signal travels.

That length scale, \emph{L}, is given by \emph{L} = sqrt( \emph{D}/$\lambda$).

%Choosing \emph{D} and \emph{λ} can help to tune the chemical
Choosing \emph{D} and $\lambda$ can help to tune the chemical
communication distance in these models.

\subsection{Oxygen ($\sigma$)}
%(\emph{σ}):}{Oxygen (σ):}}\label{oxygen-ux3c3}}

This is released by the computational boundary (a simplified model of a
far-field vasculature), and consumed by tumor cells.
We use a far-field value of 38 mmHg (about 5\%), which is a typical
physioxic condition. See \cite{Ghaffarizadeh2016-ga} and \cite{physicell-2018} for more references. We use a
%length scale of 1000 μm, and cancer cell uptake gives a length scale of
length scale of 1000~$\mu$m, and cancer cell uptake gives a length scale of
100~$\mu$m  in densely packed regions.

\subsection{Chemoattractant (\emph{a}):}

This factor is released by undocked cargo cells to help guide chemotaxis
by worker cells.

The chemoattractant is nondimensionalized so that $0 \leq \emph{a} \leq 1$, and
we initially assign a length scale of 100~$\mu$m.

\subsection{Chemotherapeutic (\emph{c}):}
This factor is released by released cargo cells to kill cancer cells.

The therapeutic is nondimensionalized so that $0 \leq \emph{c} \leq 1$, and we
initially assign a length scale of 80~$\mu$m.

\section{Cell agents}
We use agent-based models to explore multicellular systems like this
one. Each cell is modeled as a software agent with an independent state,
and its own rules to change its behavior based on local environmental
conditions and communication. We use PhysiCell as our modeling platform
{[}1{]}.~

\subsection{Key features in the agent-based
models}

\paragraph{Birth and death:}\label{birth-and-death}

Cells can proliferate (divide into two daughter cells of half size),
with division rates regulated by cell rules. In our model, cells
continuously work to grow towards a "target" mature volume.

Note that birth and death are stochastic events for each cell agent: if
such a process occurs at rate \emph{r}, then between now (\emph{t}) and
soon (\emph{t} + $\Delta$\emph{t}), the probability of the event occurring for
that agent is \emph{r}$\Delta$\emph{t}.

\paragraph{Secretion and uptake:}\label{secretion-and-uptake}

Cells can secrete chemical factors, or they can remove them (i.e.,
consume or uptake). This can contribute to gradients in chemical
factors, and it's a key method of communication between cells. Moreover,
cells can "sample" the chemical state of their surrounding environment.
Secreting is sending a signal. Uptaking and sampling is receiving a
signal.

\paragraph{Biased migration:}\label{biased-migration}

Motile cells perform \emph{biased migration}. After traveling for
\emph{T}\textsubscript{persistence} time (the mean persistence time),
they choose a new migration direction $\mathbf{d}_{migrate}$. Based
on the environmental conditions, the cell chooses a directional bias
(intended direction) $\mathbf{d}_{bias}$ and a random unit vector
$\mathbf{r}$. The motile direction $\mathbf{d}_{migrate}$ is then determined
by according to:

%{d}\textsubscript{migrate} = b {d}\textsubscript{bias} + (1-b) {r}.
\begin{center}
$\mathbf{d}_{migrate} = b \: \mathbf{d}_{bias} + (1-b) \mathbf{r}$.
\end{center}

Here, \emph{b} is a \emph{bias} parameter (between 0 and 1) that
determines how strongly biased migration is towards
$\mathbf{d}_{bias}$. If \emph{b} =1, then migration is deterministic
towards $\mathbf{d}_{bias}$. If \emph{b} = 0, then migration is
completely random (Brownian).

Once the migration direction is chosen, it is normalized, and multiplied
by the cell's migration speed.

\paragraph{Mechanics:}\label{mechanics}

Cell agents can stick to one another within a prescribed interaction
distance (some multiple of their radius), and they can exert a pushing
force on neighbors. PhysiCell {[}1{]} uses potential functions to
implement these simple mechanics. Notably, PhysiCell is an off-lattice
model, meaning that cells can have variable sizes, and can move freely
without grid artifacts.

They aren't required to move some prescribed number of spatial steps.
They also can divide without checking for an open neighbor "site".
Instead, they can divide and push their neighbors out of the way.~

\paragraph{Focal adhesions:}

PhysiCell allows custom functions for any cell agents. We use this to
model focal cell-cell adhesions as spring-like forces. If two cells
\emph{i} and \emph{j} (with positions $\mathbf{x}_{i}$ and
$\mathbf{x}_{j}$) have a focal adhesion, then cell \emph{i} is
adhered to cell \emph{j} with a spring-like force that we model as:

\begin{center}
$\mathbf{F}_{ij} = \varepsilon (\mathbf{x}_{j} -
\mathbf{x}_{i})$,
\end{center}

where $\varepsilon$ is the elastic coefficient. Because PhysiCell has an
inertialess formatulation (see the method paper in {[}1{]}), this is
added directly to the cell's velocity, and so $\varepsilon$ has units
min\textsuperscript{-1}. To model the finite deformability of cells and
these elastic focal adhesions, we detach the cells if their distance
($\norm{\mathbf{x}_{i} - \mathbf{x}_{j}}$)
exceeds a set maximum distance $r_{max}$.

\subsubsection{Worker cells (\textcolor{red}{red})}
%({red})}{Worker cells (red)}}\label{worker-cells-red}

Worker cells do not divide, but they can be assigned an apoptotic death
rate to model normal "wear and tear." We model workers as non-adhesive
except by spring-like focal adhesions; see
\protect\hyperlink{focal_adhesions}{focal adhesions}. They are made more
"repulsive" (by default, fivefold more repulsive) to allow them to more
readily move through dense cellular regions. Worker cells consume
oxygen, but at a reduced rate (by default, 10\% of the rate of cancer
cells).

{Unattached} worker cells use the following as their migration bias
direction:~

\begin{center}
$\mathbf{d}_{bias} = \nabla a$,
\end{center}

where \emph{a} is the chemoattractant released by unattached cargo
cells. Note that $\nabla$ is the gradient operator that points towards higher
concentrations of a chemical factor.

Unattached worker cells test for near contact with unattached cargo
cells. If they detect an unattached cargo cell with active receptor
\emph{R} (\emph{R} $\approx$ 1), they form a focal adhesion (see
\protect\hyperlink{focal_adhesions}{focal adhesions}).

{Attached} worker cells change their migration bias direction to:

\begin{center}
$\mathbf{d}_{bias} = - \nabla \sigma$,
\end{center}

where $\sigma$ is the oxygen.

\subsubsection{Cargo cells (\textcolor{blue}{blue})}\label{cargo-cells-blue}

Cargo cells do not divide, but they can be assigned an apoptotic death
rate to model normal "wear and tear." We model cargo as non-adhesive
except by spring-like focal adhesions; see
\protect\hyperlink{focal_adhesions}{focal adhesions}. They are made more
"repulsive" (by default, fivefold more repulsive) to allow them to more
readily move through dense cellular regions. Cargo cells consume oxygen,
but at a reduced rate (by default, 10\% of the rate of cancer cells).
Note that all cargo cells are non-motile.

Initially, all cargo cells express a receptor \emph{R} with
dimensionless value 1, which is used to control their chemical
secretions. If \emph{R} = 1, they secrete chemoattractant \emph{a} to
help guide worker cells. If \emph{R} = 0 and they are unattached, then
they secrete the therapeutic \emph{c}.

Cargo cells permanently deactivate their receptor (set \emph{R} = 0)
once they are attached to a worker cell. They detach from worker cells
if $\sigma < \sigma_{release}$.

\subsubsection{Cancer cells (\textcolor{darkgreen}{green})}\label{cancer-cells-green}

Cancer cells divide at a rate proportional to oxygen availability, and
they experience necrotic death at a rate that increases as oxygen
decreases. We use the default parameter values from {[}1{]} for this
sample model; they cannot be adjusted by users in the current demo
version. Note that all cancer cells are non-motile in this example.

Beyond oxygen-driven birth and hypoxia-driven death, cancer cells are
have a basic damage-repair model. Exposure to the chemotherapeutic
compound \emph{c} causes damage ($\omega$, which can be repaired. We
simulate this as

\begin{center}
$\frac{d\omega}{dt} = r_{damage} \: c - r_{repair} \: \omega$
\end{center}

where \emph{c} is sampled at the cell's position. Cancer cells increase
their apoptotic death rate by their therapeutic death rate
\emph{d}\textsubscript{therapy}, which we model as

\begin{center}
$d_{therapy} = \frac{\omega}{\omega_{max}} \: d_{max}$,
\end{center}

where \emph{d}\textsubscript{max} is the maximum death rate that is
reach when damage ($\omega$) reaches \emph{ω}\textsubscript{max}.

In this model, we set $\omega_{max}$ by solving the damage
model to find the steady state damage at a maximum value of \emph{c}
(which is 1):

\begin{center}
$\omega_{max} = r_{damage} / r_{repair}$
\end{center}

\subsection{Basic
instructions}\label{basic-instructions}

Modify the parameters in the "Config Basics" and "User Params" tabs
and click the "Run" button.

To view simulation results, click the "Out: Plots" tab, and slide the bar to
advance through simulation frames. Note that as the simulation runs, the
"\# frames" field will increase, so you can view more
simulation frames.

Note that you can download full simulation data for further exploration
in your tools of choice.

\section{Additional information}
To learn more about our work, please visit \href{http://mathCancer.org}{MathCancer.org}.

Credits:

Scientific Staff:
Randy Heiland, Research Associate, Intelligent Systems Engineering, Indiana University.
\begin{itemize}
\item Lead software architect:
\end{itemize}

Paul Macklin, Ph.D. , Associate Professor, Intelligent Systems Engineering, Indiana University.
\begin{itemize}
\item Scientific lead, developed PhysiCell simulation model:
\end{itemize}

The following undergraduate students have contributed to this project:

Jupyter notebook and UI development:
\begin{itemize}
\item Eric Bower (IU Intelligent Systems Engineering, B.S., 2018-present)
\item Daniel Mishler (IU Intelligent Systems Engineering, B.S., 2018-present)
\item Tyler Zhang (IU Intelligent Systems Engineering, B.S., 2018)
\end{itemize}

\section{Sponsored by}
\begin{itemize}
\item NSF EEC-1720625. Network for Computational Nanotechnology - Engineered nanoBIO Node
\item Breast Cancer Research Foundation
\item Jayne Koskinas Ted Giovanis Foundation for Health and Policy
\item NIH U01CA232137
\end{itemize}
%\clearpage
\bibliography{refs}
\end{document}