\chapter{Background}
\label{sec:background}

\section{Term Representation and Rewriting}
\label{sec:rewriting}

The most common and easily understood
 program representation is the venerable
 \textit{abstract syntax tree} (AST).
An AST is a recursive tree data structure
 where a node is an operator and
 some number---potentially zero---of children ASTs.
For example, the program $(a * 2) / 2$
 is represented by the AST shown in \autoref{fig:ast1}.
The operators $*$ and $/$ each take two children;
 the variable $a$ and the number $2$ are leaf operators
 that take no children.

ASTs are the primary data structures used in most programming tools,
 but they are not the only ones.
A common alternate representation is the \textit{term graph},
 which can be viewed as a variant of ASTs that
 allows directed acyclic graphs instead of just trees.
Term graphs can therefore capture sharing across common parts of a
 program (also known as a term).
\autoref{fig:ast2} shows a term graph for the program $(a * 2) / 2$.
% Term graphs can be ``unfolded'' into ASTs be duplicating the shared subgraphs,
%  but the resulting ASTs can be exponentially larger than the term graph.

\begin{figure}
  \subcaptionbox{AST without sharing.\label{fig:ast1}}
    [0.5\linewidth]{\includegraphics[height=3cm]{ast}}
  \subcaptionbox{Term graph with sharing.\label{fig:ast2}}
    [0.5\linewidth]{\includegraphics[height=3cm]{ast-sharing}}
  \caption{
    Different representations of the program $(a * 2) / 2$ have
     different characteristics.
    The syntax tree is simpler \subref{fig:ast1},
     but the term graph is smaller since it captures sharing \subref{fig:ast2}.
  }\label{fig:ast}
\end{figure}

Regardless of the choice of program representation,
 a common technique for program manipulation is rewriting.
In this paradigm,
 program transformations are given as a set of rewrites,
 where each
 rewrite $\ell \to r$ specifies a pattern $\ell$ to search for
 and a another pattern $r$ with
 which to replace each instance of $\ell$ found
 in the program.
For example, applying the rewrite $x * 2 \to x + x$
 to our term $(a * 2) / 2$ yields $(a + a) / 2$.

Stated more formally,
 applying rewrite $\ell \to r$ on a term $t$
 works as follows.
First, search for the $\ell$ within $t$,
 yielding a substitution $\sigma$ and a subterm $s$ of $t$
 such that $\sigma$ maps variables from $\ell$ to terms
 and $\ell[\sigma] = s$,
 where $\ell[\sigma]$ denotes replacing the variables in $l$
 with the corresponding terms in $\sigma$.
With the substitution in hand,
 applying the rewrite simply replaces
 $\ell[\sigma]$ with $r[\sigma]$ in $t$
 (since $\ell[\sigma]$ equals some subterm $s$ of $t$).

Rewriting offers an
 intuitive, compositional, and efficient
 method to transform programs
 that is used in programming tools of all shapes and sizes.
It is a well-researched technique with a wealth of literature
 (surveyed in~\cite{nachum-rewrites, rewritesystems}),
 and many programming language tools implement and rely on it.

Term rewriting (in its traditional directed form) does, however,
 suffer from pitfalls that can complicate or prevent the building
 of certain rewrite-based systems.
Many of these weaknesses boil down to the fact that
 term rewriting operates on \emph{one term at a time};
 once a term is rewritten,
 you are left with the new version and have
 essentially forgotten the old version.
The quality of a rewriting system's output can heavily depend on
 the order and manner in which is applies its rewrites.
In other words, \emph{choices really matter} in this paradigm.
The compilers community refers to this as the
 \textit{phase-ordering} problem~\cite{phase-ordering,eqsat}.

\begin{figure}
  \centering
  \subcaptionbox{
    Sometimes a locally ``good'' rewrite can be a poor choice down the road.
    In this case, we would ultimately like to rewrite $(a * 2) / 2$ to $2$.
    But applying $x * 2 \to x \ll 1$ is hard to pass up,
     since replacing a (relatively) expensive multiplication with a
     cheap bitshift is nearly always a good decision.
    Applying that locally beneficial rewrite makes canceling out the
     2s much more difficult.\label{fig:bad-rewrites-a}
  }[\linewidth]{\includegraphics[height=35mm]{figures/bad-rewrites-a}}

  \vspace{1cm}
  \subcaptionbox{
    Seemingly innocuous rewrites like commutativity of multiplication
     ($x * y \to y * x$)
    can send a rewriting system into a loop.
    Directed rewriting systems can avoid this by applying
     these rewrites in only one direction or trying to observe when they have
     encountered a term they have seen before.\label{fig:bad-rewrites-b}
  }[\linewidth]{\includegraphics[height=35mm]{figures/bad-rewrites-b}}

  \vspace{1cm}
  \subcaptionbox{
    Expansive rewrites like $x \to x * 1$
     can enable other rewrites,
     but they are problematic for traditional rewriting systems
     since they can always be applied,
     potentially leading to infinitely large terms.
   \label{fig:bad-rewrites-c}
  }[\linewidth]{\includegraphics[height=35mm]{figures/bad-rewrites-c}}

  \vspace{5mm}
  \caption{
    Conventional directed rewriting can go wrong in various ways
    if the wrong rewriting is applied at the wrong time.
    Orange highlighting indicates what changed from the initial term in each subfigure.
  }\label{fig:bad-rewrites}
\end{figure}

\autoref{fig:bad-rewrites} shows some concrete examples of how
 poor rewrite choice can cause undesirable results.

% \section{Term Rewriting}

% \egg builds on \egraphs and equality saturation.
%   This section describes those techniques and
%   presents the challenges that \egg addresses.

% Many problems in program optimization, theorem proving,
%   and other domains have a similar shape:
% given an input expression, search for a ``better'' equivalent
%   expression.
% This paper puts forward the case that, with our proposed advances, equality
%   saturation is now the right tool for the job in many cases like
%   these.

% We will work through an extended example around optimizing
%   the expression
%   $(a \times 2) / 2$
%   and discover the benefits of \egraphs and equality saturation,
%   current limitations of using and implementing this approach,
%   and how \egg addresses those limitations.

\section{E-Graphs}
\label{sec:egraphs}

An \textit{\egraph} is a data structure that stores a set of terms and a
  congruence relation over those terms.
Originally developed for and still used in the
  heart of theorem provers~\cite{nelson, simplify, z3},
  \egraphs have also been used to power a program optimization technique
  called \textit{equality saturation}~%
  \cite{denali, eqsat, eqsat-llvm, szalinski, yogo-pldi20, spores, herbie}.

\subsection{Definitions}

Intuitively,
  an \egraph is a set of equivalence classes (\textit{\eclasses}).
Each \eclass is a set of \textit{\enodes} representing equivalent terms from a given language,
  and an \enode is a function symbol paired with a list of children \eclasses.
More precisely:

\begin{figure}
  \centering
  \begin{align*}
     \text{function symbols} \quad & f,g                                   \\[-0.2em]
     \text{\eclass ids} \quad & a,b & \text{opaque identifiers}            \\[-0.2em]
     \text{terms}     \quad & t  ::= f \mid f(t_1, \ldots, t_m) & m \geq 1 \\[-0.2em]
     \text{\enodes}   \quad & n  ::= f \mid f(a_1, \ldots, a_m) & m \geq 1 \\[-0.2em]
     \text{\eclasses} \quad & c  ::= \{ n_1, \ldots, n_m \}     & m \geq 1
  \end{align*}
  \caption{
    Syntax and metavariables for the components of an \egraph.
    Function symbols may stand alone as constant \enodes and terms.
    An \eclass id is an opaque identifier that can be compared for equality with $=$.
  }
  \label{fig:syntax}
\end{figure}

\begin{definition}[Definition of an E-Graph]
  \label{def:egraph}

  Given the definitions and syntax in \autoref{fig:syntax},
  an \textit{\egraph} is a tuple $(U, M, H)$ where:
  \begin{itemize}
    \item
    A union-find data structure~\cite{unionfind} $U$
      stores an equivalence relation (denoted with $\equivid$)
      over \eclass ids.

    \item
    The \textit{\eclass map} $M$ maps \eclass ids to \eclasses.
    All equivalent \eclass ids map to the same \eclass, i.e.,
      $a \equivid b$ iff $M[a]$ is the same set as $M[b]$.
    An \eclass id $a$ is said to \textit{refer to} the \eclass $M[\find(a)]$.

    \item The \textit{hashcons}\footnote{
      We use the term \textit{hashcons} to evoke the memoization technique,
      since both avoid creating new duplicates of existing objects.
    }
    $H$ is a map from \enodes to \eclass ids.
  \end{itemize}

  % An \textit{\eclass} is a set of \enodes.
  % An \textit{\enode} $f(a_{1}, ..., a_{n})$ is
  %   a function symbol $f$ from the given language
  %   and a (potentially empty) list of \eclass ids.

  Note that an e-class has an identity
   (its canonical \eclass id),
   but an \enode does not.\footnote{
    Our definition of an \egraph reflects \egg's design
      and therefore differs with some other \egraph definitions and implementations.
    In particular, making e-classes but not e-nodes identifiable is unique to
      our definition.
  }
  We use \eclass id $a$ and the \eclass $M[\find(a)]$ synonymously when clear from the context.

\end{definition}

\begin{definition}[Canonicalization]
    An \egraph's union-find $U$ provides a \find operation that canonicalizes \eclass ids
      such that ${\find(U, a) = \find(U, b)}$ iff ${a \equivid b}$.
    We omit the first argument of \find where clear from context.
    \begin{itemize}
      \item An \eclass id $a$ is canonical iff $\find(a) = a$.
      \item \raggedright
            An \enode $n$ is canonical iff $n = \texttt{canonicalize}(n)$,
            where ${\texttt{canonicalize}(f(a_{1}, a_{2}, ...)) = f(\find(a_{1}), \find(a_{2}), ...)}$.
    \end{itemize}
\end{definition}

\begin{definition}[Representation of Terms]
  An \egraph, \eclass, or \enode is said to \textit{represent} a term $t$ if $t$ can be
    ``found'' within it. Representation is defined recursively:
  \begin{itemize}
    \item An \egraph represents a term if any of its \eclasses do.
    \item An \eclass $c$ represents a term if any \enode $n \in c$ does.
    \item An \enode $f(a_{1}, a_{2}, ...)$ represents a term $f(t_{1}, t_{2}, ...)$
          if they have the same function symbol $f$
          and \eclass $M[a_{i}]$ represents term $t_{i}$.
  \end{itemize}

  When each \eclass is a singleton (containing only one \enode),
    an \egraph is essentially a term graph with sharing.
  \autoref{fig:egraph-rewrite1} shows an \egraph that represents the
    expression $(a \times 2) / 2$.
\end{definition}

\begin{definition}[Equivalence]
  An \egraph defines three equivalence relations.
  \begin{itemize}
    \item Over \eclass ids: $a \equivid b$ iff $\find(a) = \find(b)$.
    \item Over \enodes: $n_{1} \equivnode n_{2}$ iff \enodes $n_{1}, n_{2}$ are in the same \eclass,
          i.e., $\exists a.\ n_{1}, n_{2} \in M[a]$.
    \item Over terms: $t_{1} \equivterm t_{2}$ iff terms $t_{1}, t_{2}$ are represented in the same \eclass.
  \end{itemize}

  We use $\equiv$ without the subscript when the relation is clear from context.
\end{definition}

\begin{definition}[Congruence]
  For a given \egraph, let $\cong$ denote a congruence relation over \enodes such that
  ${f(a_{1}, a_{2}, ...) \cong f(b_{1}, b_{2}, ...)}$ iff $a_{i} \equivid b_{i}$.
  Let $\cong^{*}$ denote the congruence closure of $\equivnode$,
   i.e., the smallest superset of $\equivnode$ that is also a superset of $\cong$.
  Note that there may be two \enodes such that
    $n_{1} \cong^{*} n_{2}$ but
    $n_{1} \not\cong n_{2}$ and
    $n_{1} \not\equivnode n_{2}$.
  The relation $\cong$ only represents a single step of congruence;
  more than one step may be required to compute the congruence closure.
\end{definition}

\subsection{E-Graph Invariants}
\label{sec:invariants}

The \egraph must maintain invariants in order to
  correctly and efficiently implement the operations given in \autoref{sec:interface}.
This section only defines the invariants,
  discussion of how they are maintained is deferred to \autoref{sec:rebuild}.
These are collectively referred to as the \textit{e-graph invariants}.

\begin{definition}[The Congruence Invariant]
  \label{def:cong-inv}
  The equivalence relation over \enodes must be closed over congruence,
    i.e., $(\equivnode) = (\cong^{*})$.
  The \egraph must ensure that congruent \enodes are in the same \eclass.
  Since identical \enodes are trivially congruent,
   this implies that an \enode must be uniquely contained in a single \eclass.
\end{definition}

\begin{definition}[The Hashcons Invariant]
  \label{def:hash-inv}
  The hashcons $H$ must map all canonical \enodes to their \eclass ids.
  In other words:
  $$ \enode\ n \in M[a] \iff H[\texttt{canonicalize}(n)] = \find(a) $$
 % for each pair $(n, a) \in H$, \enode $n$ must be canonical and $n \in M[a]$.

  If the hashcons invariant holds, then a procedure $\texttt{lookup}$
    can quickly find which \eclass (if any) has an \enode congruent to a given \enode $n$:
  $\texttt{lookup}(n) = H[\texttt{canonicalize}(n)]$.
\end{definition}

%   \Remy{How can add violate deduplication?}
% Traditionally, \egraphs employ two techniques to maintain the invariants on
%   every call to \texttt{add} or \texttt{merge}.

% As \eclasses grow, the \egraph represents exponentially (or even infinitely) many terms,
%   one for every choice of representative \enode for each \eclass.
% The \egraph in \autoref{fig:egraph-rewrite-before} is essentially an AST with
%   sharing, since each \eclass is a singleton.

% \Egraphs are manipulated by two main operations:
%   adding new \enodes (into new \eclasses)
%   and merging \eclasses (sometimes called \textit{asserting} equivalences).
% \Chandra{since this is POPL, I feel that we might be expected to
% write invariants like the following a bit more formally?}
% These operations maintain two important invariants, which we will call the
%   \textit{\egraph invariants}:
% \begin{enumerate}
%   \item Deduplication:
%     The \egraph must not contain two \enodes with the same operator and
%     equivalent children.
%     \Leo{clarify dedup; distinguish identical and equivalent}
%     \Leo{this doesn't necessarity hold in modern \egraphs}
%   \item Congruence:
%     The equivalence relation on terms must also be a congruence relation, i.e.
%     if $a = b$ then $f(a) = f(b)$.
% \end{enumerate}

% Both operations can violate the two \egraph's congruence invariant.

% Deduplication is typically maintained by \textit{hashconsing}, or memoizing,
%   the add operation.
% If the user tries to add an \enode that is already represented in the \egraph,
%   the \egraph should simply return the \eclass representing the \enode instead of
%   inserting the \enode.
% Congruence is traditionally maintained by keeping a list of
%   \textit{parent pointers} for each \eclass that stores which \enodes have that
%   \eclass as children.
% On the merge operation, the parents of the merged classes must be checked to see
%   if any pairs of them became equivalent, proceeding recursively until no
%   additional equivalences are found.

\begin{figure}
  \begin{subfigure}[t]{0.45\linewidth}
    \centering
    \includegraphics[height=50mm]{overview1.pdf}
    \caption{Initial \egraph contains ${(a \times 2) / 2}$.}
    \label{fig:egraph-rewrite1}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.45\linewidth}
    \centering
    \includegraphics[height=50mm]{overview2.pdf}
    \caption{
      Applied ${x \times 2 \to x \ll 1}$.
    }\label{fig:egraph-rewrite2}
  \end{subfigure}
  \\[1em]
  \begin{subfigure}[t]{0.45\linewidth}
    \centering
    \includegraphics[height=50mm]{overview3.pdf}
    \caption{
      Applied rewrite ${(x \times y) / z \to x \times (y / z)}$.
    }\label{fig:egraph-rewrite3}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.45\linewidth}
    \centering
    \includegraphics[height=50mm]{overview4.pdf}
    \caption{
      Applied ${x / x \to 1}$ and ${1 \times x \to x}$.
    }\label{fig:egraph-rewrite4}
  \end{subfigure}
  \caption{
    An \egraph consists of \eclasses (dashed boxes) containing
      equivalent \enodes (solid boxes).
    Edges connect \enodes to their child \eclasses.
    Additions and modifications are emphasized in black.
    Applying rewrites to an \egraph adds new \enodes and edges,
      but nothing is removed.
    Expressions added by rewrites are merged with the matched \eclass.
    In \autoref{fig:egraph-rewrite4}, the rewrites do not add any new nodes,
      they only merge \eclasses;
      so the \egraph gets \emph{smaller} but represents \emph{more} terms.
    Since the resulting \egraph has a cycle,
      it actually represents infinitely many expressions:
      $a$, $a \times 1$, $a \times 1 \times 1$, and so on.
  }
  \label{fig:egraph-rewrite}
\end{figure}

\subsection{Interface and Rewriting}
\label{sec:interface}

\Egraphs bear many similarities to the classic union-find data
  structure that they employ internally,
  and they inherit much of the terminology.
\Egraphs provide two main low-level mutating operations:
\begin{itemize}
    \item \texttt{add} takes an \enode $n$ and:
    \begin{itemize}
        \item if $\texttt{lookup}(n) = a$, return $a$;
        \item if $\texttt{lookup}(n) = \emptyset$,
              then set $M[a] = \{ n \}$ and return the id $a$.
    \end{itemize}
    \item \texttt{merge} (sometimes called \texttt{assert} or \texttt{union})
    takes two \eclass ids $a$ and $b$,
    unions them in the union-find $U$,
    and combines the \eclasses by setting both $M[a]$ and $M[b]$ to $M[a] \cup M[b]$.
\end{itemize}

Both of these operations must take additional steps to maintain the congruence
  invariant.
Invariant maintenance is discussed in \autoref{sec:rebuilding}.

\Egraphs also offers operations for querying the data structure.
\begin{itemize}
    \item \texttt{find} canonicalizes \eclass ids using the union-find $U$ as described in definition \ref{def:egraph}.
    \item \texttt{ematch} performs the
          \textit{e-matching}~\cite{simplify, ematching}
          procedure for finding patterns in the \egraph.
          \texttt{ematch} takes a pattern term $p$ with variable placeholders
          and returns a list of tuples $(\sigma, c)$ where $\sigma$ is a substitution of
          variables to \eclass ids such that $p[\sigma]$ is represented in \eclass $c$.
\end{itemize}
These can be composed to perform rewriting over the
  \egraph.
To apply a rewrite $\ell \to r$ to an \egraph,
  \texttt{ematch}
  finds tuples $(\sigma, c)$ where \eclass $c$ represents $\ell[\sigma]$.
Then, for each tuple,
  \mbox{\texttt{merge($c$, add($r[\sigma]$))}} adds $r[\sigma]$ to the \egraph
  and unifies it with the matching \eclass c.

\autoref{fig:egraph-rewrite} shows an \egraph undergoing a series of rewrites.
Note how the process is only additive; the initial term $(a \times 2) / 2$ is
  still represented in the \egraph.
Rewriting in an \egraph can also saturate, meaning the \egraph has
  learned every possible equivalence derivable from the given rewrites.
% This not only solves the phase ordering problem, but also handles rules like
%   commutativity that can be troublesome to a conventional rewrite system.
If the user tried to apply $x \times y \to y \times x$ to an \egraph twice,
  the second time would add no additional \enodes and perform no new merges;
  the \egraph can detect this and stop applying that rule.

\section{Equality Saturation}
\label{sec:eqsat}

Term rewriting~\cite{nachum-rewrites} is a time-tested approach
  for equational reasoning in
  program optimization~\cite{eqsat, denali},
  theorem proving~\cite{simplify, z3},
  and program transformation~\cite{graphs}.
In this setting, a tool repeatedly chooses one of a set of axiomatic rewrites,
  searches for matches of the left-hand pattern in the given
  expression, and replaces matching instances with the substituted
  right-hand side.
It does, however, suffer from drawbacks such as the phase ordering
 problem (\autoref{sec:rewriting}).

% Term rewriting is typically destructive and ``forgets'' the matched
%   left-hand side.
% Consider applying a simple strength reduction rewrite:
%   ${ (a \times 2) / 2 \to (a \ll 1) / 2 }$.
% The new term carries no
%   information about the initial term.
% Applying strength reduction at this point prevents us from canceling out $2/2$.
% In the compilers community, this classically tricky question of when to apply
%   which rewrite is called the \textit{phase ordering} problem.

One solution to the phase ordering problem would simply apply all
  rewrites simultaneously, keeping track of every expression seen.
This eliminates the problem of choosing the correct rule, but
  a naive implementation would require space exponential in the number
  of given rewrites.
\textit{Equality saturation}~\cite{eqsat, eqsat-llvm} is a technique to do this
  rewriting efficiently using an \egraph.

\begin{figure}
  \centering
  \begin{lstlisting}[language=Python, gobble=4, numbers=left, basicstyle=\small\ttfamily, xleftmargin=40mm]
    def equality_saturation(expr, rewrites):
      egraph = initial_egraph(expr)

      while not egraph.is_saturated_or_timeout():

        for rw in rewrites:
          for (subst, eclass) in egraph.ematch(rw.lhs):
            eclass2 = egraph.add(rw.rhs.subst(subst))
            egraph.merge(eclass, eclass2)

      return egraph.extract_best()
  \end{lstlisting}
  \caption{
    Pseudocode for equality saturation.
    Traditionally, equality saturation maintains the \egraph data structure
      invariants throughout the algorithm.
  }
  \label{fig:eq-sat-bg}
\end{figure}

\autoref{fig:eq-sat-bg} shows the equality saturation workflow.
First, an initial \egraph is created from the input term.
The core of the algorithm runs a set of rewrite rules until the \egraph is
  saturated (or a timeout is reached).
Finally, a procedure called \textit{extraction} selects the optimal represented
  term according to some cost function.
For simple cost functions, a bottom-up, greedy traversal of the \egraph suffices
  to find the best term.
Other extraction procedures have been explored for more complex cost
  functions~\cite{spores, wu_siga19}.

Equality saturation eliminates the tedious and often error-prone
  task of choosing when to apply which rewrites,
%Equality saturation turns a correctness problem into a performance problem,
  promising an appealingly simple workflow: state the
  relevant rewrites for the language, create an initial \egraph from a given
  expression, fire the rules until saturation,
  and finally extract the cheapest equivalent expression.
Unfortunately, the technique remains ad hoc; prospective equality saturation
  users must implement their own \egraphs customized to their language, avoid
  performance pitfalls, and hack in the ability to do interpreted reasoning
  that is not supported by purely syntactic rewrites.
\egg aims to address each aspect of these difficulties.

\paragraph{Equality Saturation and Theorem Proving}
An equality saturation engine and a theorem prover each have capabilities that
  would be impractical to replicate in the other.
Automated theorem provers like satisfiability modulo theory (SMT) solvers are
  general tools that, in addition to supporting satisfiability queries,
  incorporate sophisticated, domain-specific solvers to allow interpreted
  reasoning within the supported theories.
On the other hand, equality saturation is specialized for optimization, and its
  extraction procedure directly produces an optimal term with respect to a given
  cost function.
% To replicate extraction with an SMT solver, one would have to resort to a more
%   expensive enumerative approach.

% \James{What enumerative approach? How do you know that one would "have to" resort to it?}

While SMT solvers are indeed the more general tool,
  equality saturation is not superseded by SMT;
  the specialized approach can be much faster when the full generality of SMT is
  not needed.
To demonstrate this, we replicated a portion of the recent TASO paper~\cite{taso},
  which optimizes deep learning models.
As part of the work, they must verify a set of synthesized equalities with
  respect to a trusted set of universally quantified axioms.
TASO uses Z3~\cite{z3} to perform the
  verification even though most of Z3's features
  (disjunctions, backtracking, theories, etc.)
  were not required.
An equality saturation engine can also be used for verifying these equalities
  by adding the left and right sides of
  each equality to an \egraph,
  running the axioms as rewrites,
  and then checking if both sides end up in the same \eclass.
Z3 takes 24.65 seconds to perform the verification;
  \egg performs the same task in 1.56 seconds ($15\times$ faster),
  or only 0.52 seconds ($47\times$ faster) when using
  \egg's batched evaluation (\autoref{sec:egg-batched}).

\paragraph{Equality Saturation and Superoptimization}
The Denali~\cite{denali} superoptimizer first demonstrated how to use \egraphs
for optimized code generation as an alternative to hand-optimized machine code
and prior exhaustive approaches~\cite{massalin}, both of which were less
scalable. The inputs to Denali are programs in a C-like language from which it
produces assembly programs. Denali supported three types of
rewrites---arithmetic, architectural, and program-specific. After applying these
rewrites till saturation, it used architectural description of the hardware to
generate constraints that were solved using a SAT solver to output a
near-optimal program. While Denali's approach was a significant improvement over
prior work, it was intended to be used on straight line code only and therefore,
did not apply to large real programs.

Equality saturation~\cite{eqsat, eqsat-llvm} developed a compiler optimization
phase that works for complex language constructs like loops and conditionals.
The first equality saturation paper used an intermediate representation called
Program Expression Graphs (PEGs) to encode loops and conditionals. PEGs have
specialized nodes that can represent infinite sequences, which allows them to
represent loops. It uses a global profitability heuristic for extraction which
is implemented using a pseudo-boolean solver. Recently, \cite{yogo-pldi20} used
PEGs for code search.
\egg can support PEGs as a user-defined language,
and thus their technique could be ported.

% \James{
  % The experimental/perf numbers in the last par of 2.4 feel out of place. Not sure how to fix...
% }

% However, their abilities overlap on a specific kind of theorem proving:
%   given a list of axioms in the form of universal quantified equalities,
%   prove two (or more) terms equal.
% Some SMT solvers support these kinds of queries, albeit in a limited fashion
%   since they are undecidable.
% \footnotetext{
%   Since these queries are undecidable, both SMT solvers and equality
%   saturation engines can either prove the inputs equal or fail to; they cannot
%   prove them unequal.
% }

%%% Local Variables:
%%% TeX-master: "../thesis"
%%% End:


\glsresetall

\section{Guiding longitudinal sampling in inflammatory bowel diseases
cohorts}\label{section_ibd}

The volatile microbial signatures of \gls{cd} patients greatly hinder our
ability to classify healthy from affected subjects using 16S rRNA profiles from
stool. The recent work by Pascal et al. \cite{RN4208} overcomes this issue and
other complications \cite{RN4219}, producing a decision tree that classifies
subjects with \gls{cd}, \gls{uc}, irritable bowel syndrome and anorexia.
Although the authors note that both subtypes of \gls{ibd}, particularly
\gls{cd}, have increased microbial community instability, this information is
not used as a feature to improve classifier accuracy. Could microbiome
instability become actionable by creating a new classifier that benefits from
repeated measurements? If so, how many samples per individual are needed to
assess instability?

We collected daily stool samples for up to six weeks from 19 \gls{cd} subjects and 12 controls (see the analysis notebook for cohort description\footnote{\label{footlongibd}\url{https://github.com/knightlab-analyses/longitudinal-ibd}}) over 2 separate periods of 2 or 4 weeks spread over 2 and 5 months, for a total of 960 samples. We believe this is the most densely sampled longitudinal study of \gls{cd}; previous studies collected samples every 1-3 months \cite{RN1515, RN4208}. Our cohort shows decreased alpha diversity and increased stability, as previously reported in \gls{cd} and other subtypes of \gls{ibd} \cite{RN4217, RN154, RN1515, RN4208}.  We also noted that subjects who underwent resection have lower alpha diversity than other \gls{cd}-affected subjects (see analysis notebooks\textsuperscript{\ref{footlongibd}}).

A critical experimental design question for clinical studies is whether a finite budget should best be spent collecting samples from more patients, or collecting more serial samples from each patient? Therefore, we created a Random Forests \cite{RN4205} model based on per-subject aggregation of longitudinal data for alpha diversity \cite{RN4007}, beta diversity \cite{RN83} and abundances of two phylogenetic factors found to be associated with \gls{cd} in ileal biopsies \cite{RN154, RN4204} (Figure~\ref{ibd-fig1}). With one sample per subject, our model performs worse than a classifier that uses microbial relative abundances at a single time point, but when more samples per-subject are added, the classifier outperforms that approach and results previously only attained with biopsy samples \cite{RN154}. Furthermore, we replicate this observation with a different cohort (Table~\ref{ibd-table1}).

\begin{sidewaysfigure}[htbp]
\includegraphics[width=0.95\textheight]{ibd-figures/figure-1}
\caption[Diagram for the model creation, and comparison of four receiver operating characteristic (ROC) curves.]{Diagram for the model creation, and comparison of four receiver operating characteristic (ROC) curves. (A) Diagram describing the origin for the classifying features. (B) ROC curve for a model that relies on relative abundances and one sample per subject (as used in previous publications). (C-D) ROC curve for our new model at 1, 2 and 8 samples per subject. The gray lines represent the performance at each of the 100 iterations. The dotted black diagonal line represents the performance of a classifier that guesses the labels at random.}\label{ibd-fig1}
\end{sidewaysfigure}

\begin{table}[htbp]
\centering
\caption[Performance summary of the classifier at increased samples per subject for this cohort (daily samples) and a previously published cohort.]{Performance summary of the classifier at increased samples per subject for this cohort (daily samples) and a previously published cohort. The area under the curve (AUC) summarizes the performance; closer to 1 is better, of the model trained on the different sample sizes as described by the other columns. The row marked with † represents the performance of a classifier that relies on non-longitudinal relative abundances only.}\label{ibd-table1}
\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular*}{\textwidth}{ccccc}
\toprule
AUC &	Samples per Subject &	Controls &	Crohn's Disease & Sampling\\
\midrule
0.80	&1†&	12 &	19 & \multirow{12}{*}{Daily samples}\\
0.77	&1	& 12 &	19 &\\
0.82	&2	& 12 &	19 &\\
0.85	&3	& 12 &	18 &\\
0.86	&4	& 12 &	18 &\\
0.87	&5	& 12 &	18 &\\
0.87	&6	& 12 &	18 &\\
0.88	&7	& 12 &	18 &\\
0.88	&8	& 12 &	18 &\\
0.87	&9	& 12 &	18 &\\
0.87	&10	& 12 &	17 &\\
0.86	&11	& 12 &	16 &\\
\midrule
0.80	&1†	& 9	& 19 & \multirow{5}{*}{Monthly samples \cite{RN1515}}\\
0.80	&1	& 9	& 19 &\\
0.83	&2	& 9	& 15 &\\
0.86	&3	& 8	& 14 &\\
0.92	&4	& 8	& 12 &\\
\bottomrule
\end{tabular*}
\end{table}
\renewcommand{\arraystretch}{1}% Restore original value

Novel analyses aggregating features over time and combining both alpha and beta diversity over time using our intensive daily sampling demonstrates that the main benefits are already obtained by collecting between 3-5 fecal specimens, and no additional benefits are obtained beyond 7 serial samples.  Similar results are found for monthly sampling. These results highlight the importance of treating \gls{cd} as a volatile, time-varying condition, even during clinical remission, but provide hope to clinicians in that a relatively small number of samples yields large additional benefits, facilitating patient compliance. This information can be used to design collection of fecal samples for a large prospective cohort of \gls{cd} patients for longitudinal studies of host-microbial interactions over time.

The methods demonstrated here have not previously been used for microbiome analyses but have been used for other engineering applications, for example in production lines to predict product specification outcomes in a steel manufacturer's facility \cite{RN4216}. We expect the results to generalize in other systems, including other gastrointestinal and hepatic disorders, where dynamic features of the microbiome, host gene expression, or other accessible features can act as indicators of underlying dysbiotic states.

\subsection{Methods}

\subsubsection{Data Processing}

Demultiplexed sequences were filtered using \glspl{qiime} \cite{RN110} default
parameters for quality control using (version 1.8.0-dev). To account for the
fact that a subset of the sequences were processed using a MiSeq instrument and
the rest using a HiSeq instrument, the resulting reads were trimmed to an even
length of 99 nucleotides \cite{RN4221, RN4222}. The resulting sequences were
clustered using the closed-reference \gls{otu}-picking protocol (utilizing
UCLUST as the clustering algorithm \cite{RN81}) against the Greengenes database
(release 13\textunderscore 8) \cite{RN165}. Distance matrices were calculated
using the UniFrac \cite{RN83} distance metric. Bimodality tests were performed
using Hartigan's dip test \cite{RN4017}. To account for uneven sampling efforts
in the samples, the resulting \gls{otu} table was rarefied at 7,400 sequences
per sample. The number was selected so the main category of interest (health
status of the patient) had a balanced number of classes.

\subsubsection{Classifier}

To assess the benefits of increased number of samples per subject, we used a
Random Forests \cite{RN4205} model and we created the features following these
steps. First we randomly selected $N$ samples for each subject.  For this set
of $N$ samples, we created features based on alpha diversity, beta diversity
and microbial relative abundances. We then split the dataset into training and
testing subsets and evaluated the classifier's sensitivity and specificity.
Finally, we repeated the selection of $N$ random samples for $M$ iterations,
and summarized the results using a \gls{roc} curve and the \gls{auc}. After the
$M$ iterations, we increased $N$ by one and repeated the procedure until we
reached $N'$. The result is a total of $N'-N$ \gls{roc} curves and \gls{auc}
scores (one for each number of samples per subject).

The features are created based on longitudinal patterns of the different data
types (alpha diversity, beta diversity and relative abundances). In all cases,
we relied on the sample collection date to order the data and measured a series
of summary statistics. For alpha diversity and the microbial relative
abundances, the per-sample summaries were ordered and treated as vectors. For
beta diversity, we considered only the distances between ordered and subsequent
timepoints and treated this as a vector. Features were extracted from these
vectors as described in the TSFRESH package \cite{RN4216}, for example by
counting the number of samples where an individual \gls{otu} is not zero, to
include the mean of alpha or beta diversity distances, the mean rate of change
of the alpha diversity vector, etc.

In the case of the microbial abundances, we performed a feature selection step
using phylofactor \cite{RN4204}. Phylofactorization was performed by maximizing
the F-statistic from logistic regression on disease state in patients with
\gls{cd}. Over 200 factors were found as significant predictors of \gls{cd} in
the terminal ileum, even when controlling for multiple comparisons by a
Bonferroni correction. Two factors identified large clades ($>$100 \glspl{otu})
used for feature selection. Factor 3 identified a monophyletic clade of 518
\glspl{otu} in the Lachnospiraceae family which decreases in the terminal ileum
of patients with \gls{cd} relative to healthy patients, and factor 26
identified a monophyletic clade containing 737 \glspl{otu} of the
\textit{Gammaproteobacteria} and \textit{Betaproteobacteria} classes which
increases in relative abundance in the terminal ileum of patients with \gls{cd}
relative to healthy patients (Supplementary
Figure~1\footnote{\url{https://static-content.springer.com/esm/art\%3A10.1186\%2Fs40168-017-0269-3/MediaObjects/40168_2017_269_MOESM2_ESM.tif}}).
The dataset used for feature selection \cite{RN154}, was not used during the
training or testing stages of the classifier construction.

Jupyter notebooks and source code describing all the analyses in this paper can
be found
online\footnote{\url{https://github.com/knightlab-analyses/longitudinal-ibd}}.

Cohort demographics, sample collection and sample processing details can be
found in Appendix~\ref{appendix_ibd}.

\subsection{Acknowledgments}

This section, in full, is a reprint of the material as it appears in ``Guiding
longitudinal sampling in inflammatory bowel diseases cohorts''. Y.
V\'azquez-Baeza, A. Gonzalez, Z. Zech Xu, A. Washburne, H.  Herfarth, R.  B.
Sartor, R. Knight. \emph{Gut}. 2017. The dissertation author was the
primary investigator and author of this paper. We acknowledge grant support by
NIH (P01-DK094779), the Crohn's and Colitis Foundation, and the research
coordinators of the UNC Multidisciplinary IBD Center at UNC for patient
recruitment. Additionally, we thank Gail Ackermann, Jamie Morton and Justin
Silverman for their invaluable feedback and discussion provided in the
preparation of this manuscript.


\subsubsection{Metric}
\label{MetricPP}
The \textbf{Metric} PostProcessor is specifically used to calculate the distance values among points from PointSets and histories from HistorySets,
while the \textbf{Metrics} block (See Chapter \ref{sec:Metrics}) allows the user to specify the similarity/dissimilarity metrics to be used in this
post-processor. Both \textbf{PointSet} and \textbf{HistorySet} can be accepted by this post-processor.
If the name of given variable is unique, it can be used directly, otherwise the variable can be specified
with $DataObjectName|InputOrOutput|VariableName$ like other places in RAVEN.
Some of the Metrics also accept distributions to calculate the distance against.
These are specified by using the name of the distribution.
%
\ppType{Metric}{Metric}
%
\begin{itemize}
  \item \xmlNode{Features}, \xmlDesc{comma separated string, required field}, specifies the names of the features.
    This xml-node accepts the following attribute:
    \begin{itemize}
      \item \xmlAttr{type}, \xmlDesc{required string attribute}, the type of provided features. Currently only
        accept `variable'.
    \end{itemize}
  \item \xmlNode{Targets}, \xmlDesc{comma separated string, required field}, contains a comma separated list of
    the targets. \nb Each target is paired with a feature listed in xml node \xmlNode{Features}. In this case, the
    number of targets should be equal to the number of features.
    This xml-node accepts the following attribute:
    \begin{itemize}
      \item \xmlAttr{type}, \xmlDesc{required string attribute}, the type of provided features. Currently only
        accept `variable'.
    \end{itemize}
  \item \xmlNode{multiOutput}, \xmlDesc{optional string attribute}, only used when \textbf{HistorySet} is used as
    input. Defines aggregating of time-dependent metrics' calculations. Available options include:
    \textbf{mean, max, min, raw\_values} over the time. For example, when `mean' is used, the metrics' calculations
    will be averaged over the time. When `raw\_values' is used, the full set of  metrics' calculations will be dumped.
    \default{raw\_values}
  \item \xmlNode{weight}, \xmlDesc{comma separated floats, optional field}, when `mean' is provided for \xmlNode{multiOutput},
    the user can specify the weights that can be used for the average calculation of all outputs.
  \item \xmlNode{pivotParameter}, \xmlDesc{optional string attribute}, only used when \textbf{HistorySet}
    is used as input. The pivotParameter for given metrics' calculations.
    \default{time}
  \item \xmlNode{Metric}, \xmlDesc{string, required field}, specifies the \textbf{Metric} name that is defined via
    \textbf{Metrics} entity. In this xml-node, the following xml attributes need to be specified:
    \begin{itemize}
      \item \xmlAttr{class}, \xmlDesc{required string attribute}, the class of this metric (e.g. Metrics)
      \item \xmlAttr{type}, \xmlDesc{required string attribute}, the sub-type of this Metric (e.g. SKL, Minkowski)
    \end{itemize}
\end{itemize}

\textbf{Example:}

\begin{lstlisting}[style=XML]
<Simulation>
 ...
  <Models>
    ...
    <PostProcessor name="pp1" subType="Metric">
      <Features type="variable">ans</Features>
      <Targets type="variable">ans2</Targets>
      <Metric class="Metrics" type="SKL">euclidean</Metric>
      <Metric class="Metrics" type="SKL">cosine</Metric>
      <Metric class="Metrics" type="SKL">manhattan</Metric>
      <Metric class="Metrics" type="ScipyMetric">braycurtis</Metric>
      <Metric class="Metrics" type="ScipyMetric">canberra</Metric>
      <Metric class="Metrics" type="ScipyMetric">correlation</Metric>
      <Metric class="Metrics" type="ScipyMetric">minkowski</Metric>
    </PostProcessor>
    ...
  </Models>
 ...
</Simulation>
\end{lstlisting}

In order to access the results from this post-processor, RAVEN will define the variables as ``MetricName'' +
``\_'' + ``TargetVariableName'' + ``\_'' + ``FeatureVariableName'' to store the calculation results, and these
variables are also accessible by the users through RAVEN entities \textbf{DataObjects} and \textbf{OutStreams}.
\nb We will replace ``|'' in ``TargetVariableName'' and ``FeatureVariableName'' with ``\_''.
In previous example, variables such as \textit{euclidean\_ans2\_ans, cosine\_ans2\_ans, poly\_ans2\_ans} are accessible
by the users.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}\label{chap:intro}
A long-standing challenge for research in computer science is the understanding of written text and extraction of useful information from it. Text that is created by humans is often unstructured and ambiguous, whereas machine learning algorithms typically prefer fixed-length inputs and outputs. Thus, they cannot work directly with raw text directly and convert it into vectors of features.
\\
\begin{figure}
\centering
\resizebox{0.3\textwidth}{0.25\textwidth}{
\input{images/vector_space_models.tex}
}
\caption{An example of dense vector representation of words in a 3-dimensional space, that maps words with similar meaning to nearby points.}
\label{fig:vsmodels}
\end{figure}
Traditional \emph{Natural Language Processing} (NLP) systems treat words as atomic units, represented as vectors, where each word is treated as a one-hot vector (with $1$ in a single position and zero for the rest) to the size of the vocabulary. These vectors are sparse and orthogonal, and therefore, contain no notion of similarity among themselves. For example, if a user is searching for \emph{``Heidelberg Hotel''}, documents containing \emph{``Heidelberg Motel''} are to be disregarded since the dot product of the one-hot vectors of \emph{``Hotel''} and \emph{``Motel''} is zero. On the other hand, distributed vector space models represent words in a continuous vector space, where a word is represented by its relation to the surrounding words. These models are based on the idea that similar words tend to occur in a similar context or as the British linguist J.R. Firth said:\\ \\
\noindent
\say{You shall know a word by the company it keeps.} (J.R. Firth 1957)\\
\\
These distributed representations or so-called \emph{wod embeddings}, map words of a vocabulary to a dense vector, such that words with closer meanings are mapped to the nearby points and the similarity between them is computed based on their distance in the embedding space. An example of the embedding space is illustrated in Figure~\ref{fig:vsmodels}, where the vectors of \emph{``dog''},  \emph{``pet''} and, \emph{``labrador''} are mapped to nearby points and are farther away from unrelated words like \emph{``snowboard''}.\\
Learning dense vector representations of words dates back to $2000$ in the paper by Bengio et al., where they presented a neural probabilistic language model~\brackettext{\cite{DBLP:conf/nips/BengioDV00}}. The first simple and scalable algorithm, however, is \emph{word2vec} presented by Mikolov et al., where the aim is to capture the meaning of a word based on the surrounding context\brackettext{\cite{DBLP:journals/corr/abs-1301-3781}}. There exist numerous variations of this model, from taking the character level information into account ~\brackettext{\cite{DBLP:journals/tacl/BojanowskiGJM17}} to incorporating the statistics of the whole corpus, namely the \emph{GloVe} model~\brackettext{\cite{DBLP:conf/emnlp/PenningtonSM14}}. The GloVe model in particular, speeds up the learning and when trained on a large corpus tends to generate more promising results on downstream tasks such as named entity recognition.\\
Methods based on word2vec, despite being good at capturing semantics, have some drawbacks. They treat all words equally as terms and cannot be directly used to represent named entities. \emph{Named Entities} (NEs) refer to proper names or nouns and numerical expressions, such as dates and quantities~\brackettext{\cite{DBLP:conf/lrec/ToralMM08}}.
Many NLP tasks either depend on or use named entities as input. Identifying these references and classifying them has given rise to named entity recognition and disambiguation tasks. They are also extensively used in \emph{Information Retrial} (IR) and search engines. Disregarding the named entities while generating a word embeddings creates several challenges for downstream tasks that use them as input. Named entities often contain compound words and phrases that if not grouped together from the start, result in ambiguous and unclear representations. Although some work has been done on embedding phrases~\brackettext{\cite{DBLP:journals/tacl/HillCKB16,DBLP:conf/acl/YinS14}} or combining compound words after training with averaging, adding, or multiplying~\brackettext{\cite{DBLP:conf/eacl/DurmeRPM17,DBLP:journals/cogsci/MitchellL10}}, none of these focus on entities. The models that do focus on embedding entities, however, are designed for task specific applications, such as named entity disambiguation~\brackettext{\cite{DBLP:conf/conll/YamadaS0T16,DBLP:conf/conll/FangZWCL16}}. These models are not only task-specific but also are focused on learning representations of \emph{knowledge base} (databases containing information about named entities and their relation in a collection of documents) and do not focus on learning general purpose embedding of entities and words directly form a textual corpus.\\
A term-based model fails to distinguish between entity homographs such as  \emph{``Paris''},  which can refer to the French capital, the American heiress, or even the Trojan prince. Moreover, it cannot recognize compound word, as any word separated by space is considered its own token, whereas many companies and actors names consist of two word that not necessarily separate.  In a term-based model, if an entity is repeated several times with different names, each name is treated independently that result in loss of valuable context information for the entity. Another drawback of term-based models is their inability to deal with date information. There exist multiple form of representing date and time in text, e.g, $1$ January $1998$ or $1998$-$01$-$01$T$15$:$53$:$00$. Most models disregard any numeric information in text and limit themselves to a certain alphabet, with the exception of a few studies that try to add a temporal dimension to a paragraph or word embeddings, still they mostly focus on how the embeddings evolve or change with time and do not achieve a vector representation of dates~\brackettext{\cite{DBLP:conf/coling/MirzaT16a,DBLP:conf/ecir/YoonMWLK18}}.  \\
Another drawback of classical word embeddings in general is the lack of interpretability. In many cases, the semantic structure is heterogeneously distributed across the embedding dimensions, which makes interpretation challenging. Recently, some research has been done to make the embedding less ambiguous~\brackettext{\cite{DBLP:journals/corr/FaruquiTYDS15,DBLP:conf/emnlp/ParkBO17,DBLP:conf/aaai/SubramanianPJBH18}}. However, none of them show any insight about possible entity relations and most are applied as a post-processing step to the trained embedding. They offer no solution to learn the embeddings as an interpretable component during training time or an efficient method that can produce interpretable embeddings based on the entities surrounding a word. It is still unknown, what the implications are if a model predicts, for example,  \emph{``London''} and \emph{``Berlin''} as similar. Dense vectors representing these words do not show the reason behind their similarity. It is not obvious, whether they both appeared in the same context location-wise, e.g., both are capitals and are situated in Europe or because they share the same organizations, e.g., many companies planned to move their offices from London to Berlin after the Brexit and are mentioned in the same context. \\
Since named entities play an important rule in many NLP and IR tasks, a more intelligent representation of them enhances the performance of systems that utilize them as input features. Word embeddings are used for named entity recognition, linkage, and entity ranking~\brackettext{\cite{DBLP:conf/conll/EshelCRMYL17,DBLP:conf/nodalida/Siencnik15,DBLP:conf/icassp/MaKBK16,DBLP:conf/naacl/LampleBSKD16}}, where a unique and unambiguous representation of entities can boost their performance.
Search engines, query expansion~\brackettext{\cite{DBLP:conf/acl/0001MC16,DBLP:conf/cikm/KuziSK16}}, and document ranking~\brackettext{\cite{DBLP:conf/sigir/ZamaniC17}} that utilize named entities can also benefit from a joint representation of words and entities.
On the other hand, annotating the text with named entities, requires extensive pre-processing, from sentence splitting and tokenization to part-of-speech tagging. Not only are these steps prone to errors, but also the task of recognizing and classifying entities, even with the state-of-the-art tools, is far from perfect. Therefore, naively applying the word embedding methods to entity annotated text might cause more problems than benefits. It is important that the drawbacks of such an approach alongside its advantages are analysed.

% BR
%
% Good introduction, but it gets quickly bogged down in details.
% Everything important is there but you should rather present a single
% use case and expand from there. The idea of interspersing related work
% within the introduction is nice, but this could also become a separate
% section.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Objective and Contributions}
In this thesis, we address the problems of term-based models for generating embeddings for named entities as well as terms using an annotated corpus. In addition, to further analyse the importance of each entity type we experiment with faceted embeddings as a method to better understand the semantic structures and increase the interpretability of vector space models. Therefore, this thesis discusses two main models, one the entity and term embeddings and one for the faceted model. Below, we will discuss the contribution of each separately.\\
By analysing the entity-based models we make the following contributions:
\begin{itemize}
\item We apply the state-of-the-art word embedding methods on an annotated corpus to jointly train embeddings for terms and entities.
\item We use graph embedding techniques to embed the nodes of a co-occurrence graph, extracted from an annotated text as an alternative means of obtaining entity embeddings.
\item We evaluate both of our models against well-established word embedding methods on a set of intrinsic evaluation tasks.
\item Since a few test datasets contain any entities, we create some of our own, to better analyse the effect of entity annotation.
\item Through visualization and experimental analysis, we investigate the underlying semantics that entity embeddings capture,  and discuss the implications for entity-centric downstream tasks.
\item By comparing the entity-based and term-based methods, we identify their strengths, weaknesses and application scenarios.
\end{itemize}
To further analyse the impact of different types of entities on a word semantics and to make the embeddings more interpretable, we introduce faceted embeddings. With the faceted model, we make following contributions:
\begin{itemize}
\item We modify well-established word embedding techniques to include separable parts, where each part of the embedding corresponds to a specific types of entities.
\item We use graph embedding techniques on a co-occurrence graph extracted from an annotated corpus to examine the relation of each word to the neighbours of a specific type. By embedding the nodes of such a graph we introduce an alternative way to achieve the faceted model.
\item We evaluate our faceted models against the term-based methods on raw text, on a set of intrinsic evaluation tasks.
\item Since separate parts of faceted embeddings divide the embedding space into the different type of entities available in text, we investigate the effect of each type on intrinsic tasks.
\item By visualizing the embedding parts separately, we explore potential use cases and the underlying semantics of such models.
\end{itemize}

% BR: A good section, but the structure should be more succinct. When
% this is read (by the grader), I should immediately see what the
% objectives were and how they have been achieved. Maybe a different
% layout with 'at-a-glance' contributions would be helpful here. It is
% good that you use concrete examples, but there should be a brief
% summary about them.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Overview of the Thesis Structure}
The remainder of this thesis is structured as follows:
In Chapter~\ref{chap:background},  we discuss the background information required for the model and related work, with a brief introduction to the basics of NLP and neural networks. This discussion is followed by, an explanation of well-established word embedding and graph embedding methods, which are the base of the entity-based models. In Chapter~\ref{chap:entity}, we present two types of models for learning terms and entity embeddings jointly on an annotated corpus. One method focuses on learning the vector representation from a textual corpus, while the other method requires a co-occurrence graph extracted from the annotated text.
Chapter~\ref{chap:faceted} contains an in-depth definition of the faceted embeddings, where different models are proposed based on the input data (textual or graph-based).
In Chapter~\ref{chap:eval}, we present the test cases and evaluation results. The entity embeddings and faceted models are analysed using visualizations and also tested against well-known analogy, word similarity and categorization datasets. The work is closed with a conclusion and outlook on possible future work in Chapter~\ref{chap:concl}.

% BR: Very nice in total. I would recommend the following, though:
%  - make the claims more concise and precise
%  - formulate the objectives and how this was achieved.
%  - ideally, you can formulate both at the same time and place
%  - for example, I had 'Contributions' in my dissertation as well, you
%    may want to look at these (text me if you have troubles finding
%    that)


\chapter{Simulations} \label{chap-3}

One purpose of this chapter is to briefly describe the computational model used in the PyORBIT code before displaying any simulation results. The second purpose of this chapter is to review the work of Holmes et al., who performed particle-in-cell (PIC) simulations in the original ORBIT code to determine the feasibility of elliptical painting in the SNS \cite{Holmes2018}.

\section{Computational model}

\subsection{Single-particle tracking}

PyORBIT tracks a Bunch object containing a set of 6D phase space coordinates. The accelerator is modeled as a series of nodes, each of which modifies the coordinates in some way. The core of PyORBIT is comprised of single-particle tracking routines. For dipoles, quadrupoles, and solenoids, full linear transport is used. The approach to handling nonlinear elements is inspired by TEAPOT (Thin-Element Accelerator Program for Optics and Tracking), where particles pass through a series of drifts and "kicks" from thin elements — elements with infinitesimal length \cite{Schachinger1987}. Each drift changes the particle's position without changing its momentum, while each kick changes the particle's momentum without changing its position. Thick elements are then approximated as a series of thin elements connected with drifts. The momentum kicks are derived from the Hamiltonian of a charged particle in an electromagnetic field. It can be shown that for a Hamiltonian $H$ that does not explicitly depend on $s$ (the time-like variable), then over a distance $L$, a function $g$ of the canonical coordinates will transform as
%
\begin{equation}
    g \rightarrow
    = e^{-L:H:} g
    = \sum_{n=0}^{\infty}{\frac{L^n}{n!} (-:H:)^n g},
\end{equation}
%
where the operator $:H:$ is defined by
%
\begin{equation}
    \{H, g\} \equiv \, :H: g =
    \frac{\partial{H}}{\partial{\mathbf{q}}}
    \cdot
    \frac{\partial{g}}{\partial{\mathbf{p}}}
    -
    \frac{\partial{H}}{\partial{\mathbf{p}}}
    \cdot
    \frac{\partial{g}}{\partial{\mathbf{q}}}
\end{equation}
%
\cite{Dragt2018, Forest1998}. Symplectic maps connecting the initial and final phase space coordinates are then derived for various elements.

Fringe fields need to be taken into account for elements of finite length, that is, the fields outside the start and end of the element. For example, the magnetic field in a solenoid has a transverse component near the edges that vanishes in the limit of infinite length. The strength of fringe fields generally increases with the transverse distance from the center of the magnet; they are especially important in the injection region, where the closed orbit is significantly displaced from the quadrupole centers. PyORBIT handles fringe fields using a hard-edge model in which a nonlinear mapping is applied at the start and end of the magnet \cite{Forest1998}.

Longitudinal dynamics have not yet been discussed. Longitudinal focusing in the SNS ring is provided by four RF cavities. The harmonic number $h$, which is defined as the RF frequency divided by the revolution frequency of the beam, takes the value $h = 1$ in three cavities and $h = 2$ in one cavity. resulting in two peaks in the distribution. The cavities were designed to operate at 40 kV total for the first harmonic and 20 kV for the second harmonic, but after years of operational experience, they were lowered to their current values of approximately 5 kV. The energy gain for a particle passing through the cavity is approximated as $q V \sin(h \phi + \phi_0)$ where the particle phase $\phi$ is zero for the synchronous particle.\footnote{Since there is no net acceleration in the SNS ring, $\phi_0 = 0$.} Since particles see different accelerating voltages depending on their arrival time, they oscillate in a stable region of longitudinal phase space. The longitudinal tune is four orders of magnitude smaller than the transverse tune in the SNS ring.

\subsection{Collective effects}

The calculation of collective effects is a major component of high-intensity beam physics simulations. We focus first on space charge. PyORBIT uses the particle-in-cell (PIC) approach in which an $N$ particle bunch is represented by $M$ macroparticles, where $M \ll N$. The macroparticles are tracked according to the single-particle equation of motion (Eq.~\eqref{eq:eom_with_spacecharge}). The electric field is obtained by solving the Poisson equation (Eq.~\eqref{eq:Poisson}) on a grid. The key step is transforming between the discrete and continuous representations of the bunch.

The PIC loop is shown in Fig.~\ref{fig:pic_loop}.
%
\begin{figure}[!p]
    \centering
    \includegraphics[width=\textwidth]{Images/chapter3/pic_loop.png}
    \caption{\label{fig:pic_loop}The particle-in-cell loop.}
\end{figure}
%
First, the charge density $\rho_{i,j}$ is obtained on a grid. A common method is to treat each macroparticle as a rectangular, uniform density cloud of charge with dimensions equal to the grid spacing, assigning a fractional charge to each bin according to the fraction of the cloud overlapping with that bin \cite{Birdsall1975}. Second, the Poisson equation is solved on the grid. The method used in PyORBIT follows \cite{Hockney1981}, where the potential is written as the convolution ($*$) of a Green's function\footnote{Here we take a stand on the ``Green's function" vs. ``Green function" debate \cite{Wright2006}.} $G(\mathbf{x})$ with the charge density $\rho(\mathbf{x})$:
%
\begin{equation}
    \Phi(\mathbf{x}) = G(\mathbf{x}) * \rho(\mathbf{x}).
\end{equation}
%
We then exploit the convolution theorem \cite{Arfken1985} to write the Fourier transform ($\mathcal{F}$) of the potential as the direct product of the Fourier transforms of the Green's function and charge density:
%
\begin{equation}
    \mathcal{F}[\Phi(\mathbf{x})]
    =
    \mathcal{F}[G(\mathbf{x})] \cdot \mathcal{F}[\rho(\mathbf{x})].
\end{equation}
%
For a grid with $N$ total points, the time-complexity of the convolution is $O(N^2)$. The Fourier transform reduces this to $O(N \log N)$. To create periodic boundary conditions, the grid is doubled in each dimension; in the new regions, the Green's function is mirror-reflected and the charge density is set to zero. The potential is then solved for on the doubled grid, after which only the original region is kept. An example is shown in Fig.~\ref{fig:poisson}.
%
\begin{figure}[!p]
    \centering
    \includegraphics[width=\textwidth]{Images/chapter3/poisson.pdf}
    \caption{Solution of the Poisson equation on a doubled grid.}
    \label{fig:poisson}
\end{figure}
%
Third, the gradient of the potential is calculated, then interpolated at the particle positions using the same weighting method as in the first step. Finally, the particle momenta are updated using an appropriate integration scheme.

In rings where the coasting beam approximation is valid, the longitudinal and transverse dimensions can be treated separately. In PyORBIT, a longitudinal space charge node, which solves the Poisson equation for the 1D projection of the distribution onto the $z$ axis, acts on the bunch once per turn. Transverse space charge nodes are distributed throughout the ring. The model used in this work is known as the sliced model: the bunch is sliced into longitudinal segments, and the Poisson equation is individually solved for each segment's projection onto the $x$-$y$ plane.

In the discussion of space charge thus far, the beam was assumed to be in free space; in reality, the beam is in a vacuum chamber such as a conducting pipe. This has two effects. First, the boundary conditions must be applied when solving the Poisson equation. Second, each charged particle interacts with the vacuum chamber, leaving a wake field that affects trailing particles or the same particle on subsequent turns, possibly leading to instability. The treatment of wake fields is introduced in \cite{Chao1993}. No details are described here; we only mention that PyORBIT takes these effects into account and has been benchmarked against experiments \cite{Holmes2011}.

\subsection{Simulation procedure}

PyORBIT employs a two-language scheme: the core algorithms are written in C++ but are accessed at the Python level. All PyORBIT scripts are written in Python. The scripts used in this work are modified versions of previously benchmarked injection scripts.

For space charge calculations, a 128 $\times$ 128 $\times$ 64 grid is used with the sliced model. No more than 1 meter is allowed between solver nodes. The final number of particles is $5 \times 10^{5}$.\footnote{These settings are not hard-wired into PyORBIT.} With these settings, a 1000-turn injection simulation takes several days to run on a 2014 MacBook Pro with a 2.5 GHz Intel Core i7 processor, 16 GB of memory, and the macOS Mojave operating system.

In all simulations, the turn-by-turn covariance matrix of the distribution at the injection point is saved to a file. If space permits, the turn-by-turn 6D phase space coordinates at the injection point are saved to a single file as an array of size $n T (T + 1) / 2 \times 6$, where $n$ is the number of macroparticles injected per turn and $T$ is the total number of turns. (The array is reshaped during analysis to obtain a $T$-element list of coordinate arrays.) Additionally, the distribution is periodically saved at the ring extraction point so that it can be transported to the target in a separate simulation.

\section{Painting simulations}

\subsection{Injection}

Injection is simulated by adding particles to the bunch at the foil location on each turn. Since each pulse is the sum of many minipulses from the linac, it is only necessary to use an approximate representation of the minipulse. The distribution used in this work resembles a truncated Gaussian in the transverse plane. The design RMS emittance is approximately 0.3 mm~mrad, but recent measurements indicate that the emittance may be closer to 0.5 mm~mrad. Additionally, although the Twiss parameters are usually assumed to be matched to the ring ($\beta_x \approx \beta_y \approx 10$ m, $\alpha_x \approx \alpha_y \approx 0$), the measurements indicated that the $\beta$ functions may be closer to 4 m/rad and the alpha functions may be closer to -0.5. We use values close to these measurements. In the longitudinal plane, the spatial distribution is uniform and the energy distribution is a Gaussian with a mean of 1 GeV and a standard deviation of less than 1 MeV.

An important effect during charge-exchange injection is the scattering and energy loss that occurs during passage through the stripper foil, which increases the effective emittance of the injected bunch. The relevant processes are multiple Coloumb scattering, ionization energy loss, and single scattering interactions such as Rutherford elastic scattering, nuclear elastic scattering, and nuclear inelastic absorption \cite{Chao2012, Cousineau2003}. These are implemented as Monte Carlo routines in a foil node that acts on the bunch once per turn.

Phase space painting can be simulated by adding an artificial time-dependent bump to the coordinates on each turn; however, it is more realistic to vary the strengths of the eight injection kickers in the model with the inclusion of element offsets from the closed orbit. The following procedure is used to set the coordinates at the injection point: Let $(x_o, x'_o, y_o, y'_o)$ be the desired coordinates. First, a particle is launched from the injection point with $x = x_o$, $x' = x'_o$, and $y = y' = 0$. The particle is tracked to the end of the injection region. An optimizer varies two kicker strengths to flatten the downstream orbit, i.e., obtain $x = x' = 0$ after tracking. Then, the particle is launched with $x = x_o$, $x' = -x'_o$ and tracked backwards to the start of the injection region. Two kickers are varied to flatten the upstream orbit, i.e., obtain $x = x' = 0$ at the start of the injection region. The process is repeated with the vertical orbit.

\subsection{Best-case scenario}

Holmes et al. performed realistic simulations of elliptical painting in the SNS using the original ORBIT code \cite{Holmes2018}. Their final simulation produced an approximate Danilov distribution. Only the final 1D projections of the distribution were displayed in the publication, and the intrinsic emittances were not calculated, so it is worth revisiting these results.

The beam emittances and the projections of the 4D phase space distribution during accumulation are shown in Fig.~\ref{fig:Holmes}.
%
\begin{figure}[!p]
    \centering
    \begin{subfigure}{\textwidth}
        \includegraphics[width=\textwidth]{Images/chapter3/Holmes_snapshots.png}
    \end{subfigure}
    \vfill
    \vspace*{1.0cm}
    \vfill
    \begin{subfigure}{0.8\textwidth}
        \includegraphics[width=\textwidth]{Images/chapter3/Holmes_emittances.pdf}
    \end{subfigure}
    \caption{Simulation of elliptical painting in the SNS from \cite{Holmes2018}.}
    \label{fig:Holmes}
\end{figure}
%
The faint pink ellipses represent the projections of an ideal Danilov distribution with the same Twiss parameters and apparent emittances as the final simulated distribution. The $x$-$y$ projection has an elliptical shape and an approximately uniform density with small halo. The most striking features are the $x$-$y'$ and $y$-$x'$ projections, which, although broadened by nonlinear effects, exhibit strong correlations. As a consequence, the smaller intrinsic emittance $\varepsilon_2$ remains close to its lower limit throughout injection; particles have been injected mostly into one mode, as intended.

Several steps were necessary to achieve this simulated result. First, the painting path was chosen to follow a line in the $x$-$y'$ plane and the apparent emittances were kept somewhat equal; both these steps were discussed in Chapter \ref{chap-2}. Third, the ring RF cavity voltages were decreased to better approximate a coasting beam. Fourth, the beam energy was lowered to 0.6 GeV to increase the effective kicker strength; additionally, orbit corrector dipoles in the injection region provided a closed vertical bump. These modifications allowed a vertical injection angle of 1.58 mrad at the injection point. Fifth, the number of injected turns was reduced from 1000 to 300 to compensate for the increased space charge strength at the lower energy. Finally, a solenoid magnet was added to the ring to mitigate the effect of fringe fields. (The stabilizing effect of solenoids on the motion is examined in Appendix \ref{app-C}.)

It is encouraging that even with the inclusion of space charge, wake fields, nonlinear external fields, beam bunching, foil scattering, chromaticity, limited kicker strengths, etc., simulations predict that an approximate Danilov distribution can be produced. This is likely the best-case scenario in the SNS. But as will be discussed in Chapter \ref{chap-5}, new experimental constraints have come to light. The SNS cannot easily reach 0.6 GeV, and the use of orbit correctors in the injection region is difficult. The net result is that the maximum vertical injection angle may be limited (at least in initial experiments). Additionally, the minipulse may be mismatched at the injection point, but we expect this to have only a small effect if a sizeable beam is painted. Finally, solenoid magnets will not be installed in the SNS ring until a later date, so initial experiments will create elliptical modes in the ring by setting equal horizontal and vertical tunes. The distribution is expected to be less stable with such a machine configuration.\footnote{Holmes found that the beam should be somewhat insensitive to the tune split in the ring, but as mentioned in Chapter \ref{chap-3}, his studies were performed with a solenoid to the ring — the tune split was calculated without the solenoid.} Simulations with these constraints will be shown after several of the experiments in Chapter \ref{chap-5}.


\section{Introduction}
The study of Supersymmetry provides a fruitful playground for physicists to test various aspects of  physics beyond the Standard Model (BSM) ranging from Early Universe Cosmology and Dark Matter to modern theoretical frameworks such as String Theory or the AdS/CFT-correspondence.\\
At the end of the first part of our talk we concluded the discussion of the theoretical foundations of the MSSM with a parameter count that left us with the unsatisfying observation that one would need to determine 124 independent parameters in total to fully characterize the model. Such a large amount of relevant parameters makes the MSSM not phenomenologically viable \cite{MSSMGroup1998}.\\
The phenomenology of the MSSM is to a large extend determined by the SUSY breaking mechanism and the associated SUSY breaking scale \cite{PDG20182019}. We will motivate phenomenological constraints we want to put on the MSSM and see how they are implemented technically. Additionally we want to highlight the (possible) importance of gravity at high energies. This will help us to reduce the number of relevant parameters and may provide a starting point for actual experimental tests. For a schematic overview of the main concepts we want to discuss, have a look at Figure \ref{fig:roadmap} at the beginning of the next page.

\begin{figure}[t]
\centering
\includegraphics{figures/overview}
\caption{Schematic overview of the \enquote{roadmap} of our talk.}
\label{fig:roadmap}
\end{figure}
\newpage


% -*- root: ../gvoysey-thesis.tex -*-
\chapter{Aims}
\label{chapter:Aims}
\thispagestyle{myheadings}
This thesis investigates several models of the peripheral and central auditory systems and the utility of their predictive abilities for cochlear synaptopathy in simulations of human audition.

Three aims were established.  First, to develop a coherent modeling environment that combines models of the middle ear, auditory nerve, and auditory brainstem and midbrain from~\cite{Zilany2014Updated,Verhulst2015Functional,Nelson2004Phenomenological,Carney2015Speech} into one software package where the utility of each model could be compared head to head.  Second, to advance the state of the models of the auditory periphery by extending them with new capabilities supported by available anatomical and physiological research.  Third, to use the developed tool to explore the proposed mechanisms underlying psychophysical and large-scale electrophysiological studies of cochlear synaptopathy with higher fidelity.

\section{Aim I. Simulate the ABR Response of a Noise-Masking Task with Variable SR Contributions and Model Parameters}
A modeling environment was created.  It incorporates two peripheral models of the auditory system: the Zilany model with humanized parameters \citep{Zilany2014Updated} and the Verhulst model \citep{Verhulst2015Functional}.

The Cochlea modeling environment \citep{Rudnicki2014Cochlea} was used to provide easy incorporation of the Zilany model into the new modeling environment. The transmission-line model of~\cite{Verhulst2015Functional}, which has the potential to perform better in broadband noise due to its  accounting for cochlear dispersion, was directly integrated.
At the conclusion of this aim, direct comparisons between the estimates of ABR Wave I and Wave V by~\cite{Zilany2014Updated} and~\cite{Verhulst2015Functional} were performed for a variety of experimental conditions.

\section{Aim II. Integrate Improved Brainstem Models}

We hypothesized that the current approach to IC modeling taken in~\cite{Verhulst2015Functional,Mehraei2016Auditory} does not fully account for the responses to a low-SR knockout AN model, and consequently under-represents the effects on the ABR Wave V that have been experimentally measured.

In particular, an extension of the approach currently taken by~\cite{Verhulst2015Functional} was presented by~\cite{Carney2015Speech}.  It provides multiple classes of IC neurons that were shown to track complex tones (vowel formants) in noise.  To guide the selection of model weights and connectivities, relevant neuroanatomical literature was consulted.  Crucially, studies by~\cite{Ryugo2008Projections} and others have shown selectivities in SR projections to the small cap of the DCN, which will guide  our modeling work by introducing specificities in weighting.

Further, while the latency change trend is preserved between both the models proposed by~\cite{Zilany2014Updated} and~\cite{Verhulst2015Functional}, the magnitude of the effect is greatly different.  This discrepancy may be remedied by introduction of new IC modeling components, which are better incorporated in the~\cite{Zilany2014Updated} model.

\section{Aim III. Relate Model Responses to Psychophysical Measures}

We will compare subject Wave V latency data from \cite{Mehraei2015Auditory} and \cite{Mehraei2015Individual} as ground truth to the improved model output.  Interpreting the relative effects of different modeling parameters may elucidate which aspects of the auditory periphery are important in the further study of cochlear synaptopathy and its contribution to hidden hearing loss.


\section{Additional Results}
\label{ssec:allresults}

Table~\ref{tab:confintmain} displays the point estimates from all estimators as well as confidence intervals calculated either (a) leave-one-state-out jackknife on the adjusted dataset (``CI (states)''); (b) leave-one-state-out jackknife repeating the entire adjusted leaving each state out (``CI (proc)''). This table also includes all analyses calculated on a second version of the adjusted data where we model a separate $\kappa$ for all values (heterogeneous). The confidence intervals are identical for ``None'' because this is the unadjusted dataset. ``Homogeneous'' is our preferred covariate adjustment, and the results presented in the main paper.

\begin{table}[h!]
\centering
\caption{Point estimates and confidence intervals, primary dataset}
\label{tab:confintmain}
\begin{tabular}{llrll}
  \hline
Weight type & Adjustment & $\hat{\psi}$ & CI (states) & CI (proc) \\
  \hline
H-SBW & Homogeneous & -2.33 & (-3.49, -1.16) & (-3.47, -1.19) \\
  H-SBW & Heterogeneous & -2.24 & (-3.23, -1.24) & (-3.40, -1.08) \\
  H-SBW & None & -2.34 & (-2.85, -1.82) & (-2.85, -1.82) \\
  BC-HSBW & Homogeneous & -2.05 & (-3.27, -0.82) & (-3.22, -0.87) \\
  BC-HSBW & Heterogeneous & -1.98 & (-3.20, -0.76) & (-3.13, -0.83) \\
  BC-HSBW & None & -2.22 & (-2.87, -1.56) & (-2.87, -1.56) \\
  SBW & Homogeneous & -2.35 & (-3.65, -1.06) & (-3.67, -1.03) \\
  SBW & Heterogeneous & -2.28 & (-3.33, -1.22) & (-3.50, -1.05) \\
  SBW & None & -2.39 & (-2.95, -1.83) & (-2.95, -1.83) \\
  BC-SBW & Homogeneous & -2.07 & (-3.17, -0.97) & (-3.07, -1.06) \\
  BC-SBW & Heterogeneous & -2.00 & (-2.98, -1.01) & (-3.00, -0.99) \\
  BC-SBW & None & -2.19 & (-2.90, -1.49) & (-2.90, -1.49) \\
   \hline
\end{tabular}
\end{table}

Table~\ref{tab:confintmainc2} presents the same results when excluding the early expansion states.

\begin{table}[h!]
\centering
\caption{Point estimates and confidence intervals, early expansion excluded}
\label{tab:confintmainc2}
\begin{tabular}{llrll}
  \hline
Weight type & Adjustment & $\hat{\psi}$ & CI (states) & CI (proc) \\
  \hline
H-SBW & Homogeneous & -2.09 & (-2.85, -1.33) & (-3.15, -1.03) \\
  H-SBW & Heterogeneous & -2.06 & (-2.91, -1.22) & (-3.26, -0.87) \\
  H-SBW & None & -2.28 & (-2.82, -1.74) & (-2.82, -1.74) \\
  BC-HSBW & Homogeneous & -1.94 & (-2.96, -0.92) & (-3.17, -0.72) \\
  BC-HSBW & Heterogeneous & -1.93 & (-3.10, -0.76) & (-3.42, -0.45) \\
  BC-HSBW & None & -2.22 & (-3.07, -1.38) & (-3.07, -1.38) \\
  SBW & Homogeneous & -2.05 & (-2.75, -1.35) & (-3.10, -1.00) \\
  SBW & Heterogeneous & -2.03 & (-2.77, -1.29) & (-3.24, -0.82) \\
  SBW & None & -2.21 & (-2.71, -1.72) & (-2.71, -1.72) \\
  BC-SBW & Homogeneous & -1.99 & (-3, -0.99) & (-3.22, -0.77) \\
  BC-SBW & Heterogeneous & -2.00 & (-3.09, -0.9) & (-3.52, -0.47) \\
  BC-SBW & None & -2.23 & (-3.05, -1.40) & (-3.05, -1.40) \\
   \hline
\end{tabular}
\end{table}

Figure~\ref{fig:loostateplot} displays the change in our estimator when removing each state for all four of our estimators on the adjusted dataset (``homogeneous'') and the unadjusted dataset (``none''). These results condition on the covariate adjustment, but are similar when recalculating the entire adjustment procedure. Additional results are available on request.

\begin{figure}[H]
\begin{center}
    \caption{Estimator sensitivity to states}
    \label{fig:loostateplot}
    \includegraphics[scale=0.6]{01_Plots/loostate-sensitivityc1-state-uu-i.png}
\end{center}
\end{figure}

\clearpage


%% ****** Start of file template.aps ****** %
%%
%%
%%   This file is part of the APS files in the REVTeX 4 distribution.
%%   Version 4.0 of REVTeX, August 2001
%%
%%
%%   Copyright (c) 2001 The American Physical Society.
%%
%%   See the REVTeX 4 README file for restrictions and more information.
%%
%
% This is a template for producing manuscripts for use with REVTEX 4.0
% Copy this file to another name and then work on that file.
% That way, you always have this original template file to use.
%
% Group addresses by affiliation; use superscriptaddress for long
% author lists, or if there are many overlapping affiliations.
% For Phys. Rev. appearance, change preprint to twocolumn.
% Choose pra, prb, prc, prd, pre, prl, prstab, or rmp for journal
%  Add 'draft' option to mark overfull boxes with black boxes
%  Add 'showpacs' option to make PACS codes appear
\documentclass[aps,preprint,superscriptaddress,groupedaddress]{revtex4}  % for review and submission
%\documentclass[aps,preprint,showpacs,superscriptaddress,groupedaddress]{revtex4}  % for double-spaced preprint
\usepackage{graphicx}  % needed for figures
\usepackage{dcolumn}   % needed for some tables
\usepackage{bm}        % for math
\usepackage{amssymb}   % for math
\usepackage{subfigure}
\usepackage{epstopdf}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\allowdisplaybreaks[4]
\usepackage{accents}
\newlength{\dhatheight}
\newcommand{\doublehat}[1]{%
    \settoheight{\dhatheight}{\ensuremath{\hat{#1}}}%
    \addtolength{\dhatheight}{-0.35ex}%
    \hat{\vphantom{\rule{1pt}{\dhatheight}}%
    \smash{\hat{#1}}}}
\newcommand{\ycwu}[1]{{\bf \color{red} YW: #1}}
\usepackage{hyperref}

\begin{document}

% The following information is for internal review, please remove them for submission
%\widetext
%\leftline{Version xx as of \today}
%\leftline{Primary authors: Joe E. Physics}
%\leftline{To be submitted to (PRL, PRD-RC, PRD, PLB; choose one.)}
%\leftline{Comment to {\tt d0-run2eb-nnn@fnal.gov} by xxx, yyy}
%\centerline{\em D\O\ INTERNAL DOCUMENT -- NOT FOR PUBLIC DISTRIBUTION}

% the following line is for submission, including submission to the arXiv!!
%\hspace{5.2in} \mbox{Fermilab-Pub-04/xxx-E}

\title{The Lagrangian used in `Heavy\_Scalar\_EFT' Model File}
%\input author_list.tex       % D0 authors (remove the first 3 lines
                             % of this file prior to submission, they
                             % contain a time stamp for the authorlist)
                             % (includes institutions and visitors)
\author{Yongcheng Wu}\affiliation{Ottawa-Carleton Institute for Physics, Carleton University, \\
1125 Colonel By Drive, Ottawa, Ontario K1S 5B6, Canada}
\author{Yue Xu}\affiliation{Department of Physics, Tsinghua University, Beijing 100084, China}
\author{Xin Chen}\affiliation{Department of Physics, Tsinghua University, Beijing 100084, China}\affiliation{Collaborative Innovation Center of Quantum Matter, Beijing 100084, China}\affiliation{Center for High Energy Physics, Peking University, Beijing 100084, China}

%\date{\today}

\begin{abstract}
Here we list the Lagrangian we used in constructing the model files.
\end{abstract}

\maketitle

%\section{\label{sec:level1}First-level heading}
% sections are not used for PRL papers
\section{Two Extra Dimension 6 Operator for SM Higgs}
\label{sec:D6_SMHiggs}

We add two extra EFT vertex for SM Higgs:
\begin{align}
    \mathcal{L} = g_h^{\gamma\gamma} h F_{\mu\nu} F^{\mu\nu} + g_h^{Z\gamma} h Z_{\mu\nu}F^{\mu\nu}
\end{align}
where
\begin{align}
    g_h^{\gamma\gamma} &= -\frac{\alpha_{\rm EW}}{8\pi v} \mathcal{A}_{\gamma\gamma} \\
    g_h^{Z\gamma} &= -\frac{\alpha_{\rm EW}}{4\pi v} \mathcal{A}_{Z\gamma}
\end{align}

\section{Two Dimension 4 Operator for the Heavy Scalar}

At dimension-4, we add two operator for the heavy scalar
\begin{align}
    \mathcal{L} = g_{4,H}^{WW}g^{\mu\nu} H W^+_\mu W^-_\nu + g_{4,H}^{ZZ}g^{\mu\nu} H Z_\mu Z_\nu
\end{align}
where we choose the coupling as
\begin{align}
    g_{4,H}^{WW} &= g m_W \rho_H \\
    g_{4,H}^{ZZ} &= \frac{g}{2c_W^2} m_W \rho_H
\end{align}
with $g$ the weak coupling, $c_W$ the cosine of the Weinberg angle. $\rho_H$ is a factor characterizing the contribution of $H$ to the EWSB (or to $m_W/m_Z$).

\section{Dimension 6 Operator for the Heavy Scalar}

At dimension-6, we have several simplified EFT operators for the heavy scalar
\begin{align}
    \mathcal{L} =& g_{6,H}^{WW} (\partial_\nu H)W^{\dagger}_{\mu} W^{\mu\nu} + h.c. + g_{6,H}^{\prime WW} H W^{\mu\nu}W^\dagger_{\mu\nu} \nonumber \\
    & + g_{6,H}^{ZZ} (\partial_\nu H) Z_\mu Z^{\mu\nu} + h.c. + g_{6,H}^{\prime ZZ} H Z^{\mu\nu}Z_{\mu\nu} +\nonumber \\
    & + g_{6,H}^{Z\gamma} (\partial_\nu H) Z_\mu F^{\mu\nu} + g_{6,H}^{\prime Z\gamma} F^{\mu\nu}Z_{\mu\nu} \nonumber \\
    & + g_{6,H}^{\gamma\gamma} H F^{\mu\nu}F_{\mu\nu}
\end{align}
where
\begin{align}
    g_{6,H}^{WW} &= \frac{g m_W \rho_H f_W}{2\Lambda^2}\\
    g_{6,H}^{\prime WW} &= -\frac{g m_W \rho_H f_{WW}}{\Lambda^2} \\
    g_{6,H}^{ZZ} &=  \frac{g m_W \rho_H (c_W^2 f_W + s_W^2 f_B)}{2 c_W^2 \Lambda^2} \\
    g_{6,H}^{\prime ZZ} &= -\frac{g m_W \rho_H (s_W^4 f_{BB} + c_W^4 f_{WW})}{2 c_W^2 \Lambda^2} \\
    g_{6,H}^{Z\gamma} &= \frac{g m_W \rho_H s_W(f_W - f_B)}{2c_W\Lambda^2} \\
    g_{6,H}^{\prime Z\gamma} &= \frac{g m_W \rho_H s_W(s_W^2f_{BB}-c_W^2f_{WW})}{c_W \Lambda^2}\\
    g_{6,H}^{\gamma\gamma} &= -\frac{g m_W \rho_H s_W^2(f_{BB} + f_{WW})}{2\Lambda^2}
\end{align}

\ycwu{Add references for above Lagrangians.}
%\input acknowledgement.tex   % input acknowledgement

% \bibliography{references}

\end{document}
%
% ****** End of file template.aps ******