\section{Codon IMM}

A protein can be modelled by a HMM with states that emit amino acids. For example,
\Cref{fig:core-model} shows a possible HMM architecture for aligning sequences of amino acids, for
which indels are modelled by insert ($\state{I}$) and delete ($\state{D}$) states and matched
positions are modelled by match ($\state{M}$) states. Each match state defines a potentially
distinct probability distribution over amino acids so as to model position-specific amino acid
frequencies. Insert states might instead define the same background probability distribution over
amino acids. Delete states are silent states and therefore do not emit any amino acid: it represents
position-specific missing amino acids. $\state{B}$ and $\state{E}$ are special states that represent
the end and start positions of an alignment. In particular, the probability of $\state{B}$ being the
first state is one: $p(Q_1=\state{B})=1$.

\begin{figure}[htbp]
  \centering
  \captionsetup{width=.5\linewidth}
  \includegraphics[width=.5\linewidth]{figure/core-model}
  \caption{HMM architecture for aligning sequences of four positions. $\state{B}$ and $\state{E}$
  are silent states denoting the start and the end positions of an aligment. States $\state{M}$
  represent matches while states $\state{I}$ and $\state{D}$ model indels.}\label{fig:core-model}
\end{figure}

HMMs are widely used to model proteins and are used to search for homologous subsequences in target
sequences made of amino acids. However, the researcher ocasionally do not have a ready-to-use amido
acid sequence but instead a sequence of nucleotides that might contain homologous subsequences that
code for proteins. Some nucleotides of those homologous subsquences might be missing or might have
been inserted by whatever reason. Still, one should be able to uncover error-prone subsequences when
compared against their homologous protein HMMs.

Let $(Q_t, S_t)$ be a HMM with the amino acid alphabet $\set{A}$ representing a protein profile. We
want to replace it by an IMM that preserves the model architecture (i.e., same set of states, state
transitions and initial state probabilities) but instead have states that emit sequences of
nucleotides instead of amino acid symbols. In particular, the new match and insert states will emit
nucleotide sequences that varies in length: from one to five nucleotides. The emission distribution
of silent states (e.g., delete states and special ones) will stay the same: probability one of
emitting an empty sequence in the IMM parlance. With such model, we hope to uncover error-prone
sequences of nucleotides that are homologous to protein profiles.

Let $\set{B}$ be a nucleotide alphabet (e.g., $\set{B} \eqdef \{\res{A}, \res{C}, \res{G},
\res{T}\}$), and let $\state{M}$ be a state that in the protein HMM would emit an amino acid. From
its amino acid distribution together with any other relevant source of information (codon usage
bias, for instance), one can define the probability $p(X_t=x_1x_2x_3 \gv Q_t=\state{M})$ of
$\state{M}$ emitting the codon $(x_1, x_2, x_3) \in \set{B}^3$.

\begin{example}
  Suppose that a state $\state{M}$ has the amino acid distribution defined by
  \begin{equation*}
    p(S_t=\res{Y} \gv Q_t=\state{M}) = 0.8 ~~\text{and}~~ p(S_t=\res{C} \gv Q_t=\state{M}) = 0.2,
  \end{equation*}
  where $\res{Y}$ and $\res{C}$ are the Tyrosine and Cysteine amino acids from the original alphabet
  $\set{A}$. Based on the canonical genetic code alone, we could define the codon distribution as
  follows:
  \begin{equation*}
    \begin{split}
      p(X_t=\res{TAT}\gv Q_t=\state{M})= 0.8/2, &\quad p(S_t=\res{TAC}\gv Q_t=\state{M})=0.8/2\\
      p(X_t=\res{TGT}\gv Q_t=\state{M})= 0.2/2, &\quad p(S_t=\res{TGC}\gv Q_t=\state{M})=0.2/2,
    \end{split}
  \end{equation*}
  where $\res{A}$, $\res{C}$, $\res{T}$, and $\res{G}$ are nucleotides from $\set{B}$.
\end{example}

Defining $p(X_t=x_1x_2x_3 \gv Q_t=q_t)$ as we did in the previous example for every state $q_t \in
\set{Q}$ of a given protein HMM produces an IMM $(Q_t, X_t)$ that instead emits codon sequences.
This model could in principle be used to evaluate sequences of nucleotides against the modelled
protein. However, such a model would fail to match sequences that present indels at the base level:
a match state that mainly emits Tyrosine (codons $\res{TAT}$ and $\res{TAC}$ in the canonical
genetic code) should be able to consider the sequence $\res{TAAT}$ as a possible Tyrosine codon that
happens to have a base insertion. We therefore propose an additional, crucial modification: the
emitted codon has to go through two steps of base deletions and two steps of base insertions. In
each of those steps, there will be a (small) probability $\e$ of a modification happening.
\Cref{fig:hmm-to-imm} summarizes the proposed modifications.

\begin{figure}[htbp]
  \centering
  \captionsetup{width=.5\linewidth}
  \includegraphics[width=.5\linewidth]{figure/hmm-to-imm}
  \caption{Conversion of protein HMM into codon IMM.\@ Amino acid distributions are first converted
  into codon distributions. Generated codons go through four indel steps, each of which has a
  probability $\e$ of actually modifiying the current sequence. At the end, we have a distribution
  of error-prone codons: variable-length sequences of one, two, three, four, or five
  nucleotides.}\label{fig:hmm-to-imm}
\end{figure}

The base-indel steps of our proposed mofication is graphically detailed in \Cref{fig:codon-hmm-tree}
and is further explained in the following. The deletion can happen in any of the three codon
positions with equal probability. If a deletion has already happened (i.e., the first deletion step
has indeed modified the emitted codon), the next deletion can happen in any of the remaining two
positions with equal probability. The insertion can happen between any two bases, before the first
base, or after the last base with equal probability. One remains to define the nucleotide
distribution of the insertion process, which we shall assume to have been established for now.

\subsection{Sequence distribution}

Let us assume that we already have the error-free codon distribution $p(X_t=x_1x_2x_3 \gv Q_t=q_t)$
from the amino acid distribution of state $q_t$. Given that a base insertion occurs, let $p(x)$
denote the probability of $x \in \set{B}$ being the inserted base. This section will formally define
the error-prone codon distribution $p(Z_t=z_1z_2\dots \gv Q_t=q_t)$ from distribution
$p(X_t=x_1x_2x_3 \gv Q_t = q_t)$ and parameter $\e$ based on the outlined method. We will omit the
index $t$ and the conditional part of the probability for simplicity. The next sections will also
use an underscore $\s$ to denote a summation over the corresponding sequence positions. For example,
$p(X=x_1\s\s)=\sum_{x_2,x_3}p(X=x_1x_2x_3)$.

\subsubsection{Sequences of length 1}

\begin{equation*}
  p(Z=z_1) = \e^2(1-\e)^2(p(X=z_1\s\s) + p(X=\s z_1\s) + p(X=\s\s z_1)) / 3
\end{equation*}

\subsubsection{Sequences of length 2}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2)
        &= 2\e(1-\e)^3(p(X=\s z_1z_2) + p(X=z_1\s z_2) + p(X=z_1z_2\s))/3\\
        &+ \e^3(1-\e)(p(X=z_1\s\s) + p(X=\s z_1\s) + p(X=\s\s z_1))p(z_2)/3\\
        &+ \e^3(1-\e)(p(X=z_2\s\s) + p(X=\s z_2\s) + p(X=\s\s z_2))p(z_1)/3
  \end{split}
\end{equation*}

\subsubsection{Sequences of length 3}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2z_3) &= (1-\e)^4 p(X=z_1z_2z_3)\\
        &+ 4\e^2(1-\e)^2 (p(X=\s z_2 z_3) + p(X=z_2\s z_3) + p(X=z_2 z_3\s))p(z_1)/9\\
        &+ 4\e^2(1-\e)^2 (p(X=\s z_1 z_3) + p(X=z_1\s z_3) + p(X=z_1 z_3\s))p(z_2)/9\\
        &+ 4\e^2(1-\e)^2 (p(X=\s z_1 z_2) + p(X=z_1\s z_2) + p(X=z_1 z_2\s))p(z_3)/9\\
        &+ \e^4 (p(X=z_3\s\s) + p(X=\s z_3\s) + p(X=\s\s z_3))p(z_1)p(z_2)/9\\
        &+ \e^4 (p(X=z_2\s\s) + p(X=\s z_2\s) + p(X=\s\s z_2))p(z_1)p(z_3)/9\\
        &+ \e^4 (p(X=z_1\s\s) + p(X=\s z_1\s) + p(X=\s\s z_1))p(z_2)p(z_3)/9
  \end{split}
\end{equation*}

\subsubsection{Sequences of length 4}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2z_3z_4) &= \e(1-\e)^3 (p(X=z_2z_3z_4)p(z_1)+p(X=z_1z_3z_4)p(z_2)\\
        &+p(X=z_1z_2z_4)p(z_3)+p(X=z_1z_2z_3)p(z_4))/2\\
        &+\e^3(1-\e)(\\
        &+ p(X=\s z_3z_4)p(z_1)p(z_2) + p(X=\s z_2z_4)p(z_1)p(z_3)\\
        &+ p(X=\s z_2z_3)p(z_1)p(z_4) + p(X=\s z_1z_4)p(z_2)p(z_3)\\
        &+ p(X=\s z_1z_3)p(z_2)p(z_4) + p(X=\s z_1z_2)p(z_3)p(z_4)\\
        &+ p(X=z_3\s z_4)p(z_1)p(z_2) + p(X=z_2\s z_4)p(z_1)p(z_3)\\
        &+ p(X=z_2\s z_3)p(z_1)p(z_4) + p(X=z_1\s z_4)p(z_2)p(z_3)\\
        &+ p(X=z_1\s z_3)p(z_2)p(z_4) + p(X=z_1\s z_2)p(z_3)p(z_4)\\
        &+ p(X=z_3z_4\s)p(z_1)p(z_2) + p(X=z_2z_4\s)p(z_1)p(z_3)\\
        &+ p(X=z_2z_3\s)p(z_1)p(z_4) + p(X=z_1z_4\s)p(z_2)p(z_3)\\
        &+ p(X=z_1z_3\s)p(z_2)p(z_4) + p(X=z_1z_2\s)p(z_3)p(z_4))/9
  \end{split}
\end{equation*}

\subsubsection{Sequences of length 5}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2z_3z_4z_5)
        &= \e^2(1-\e)^2(\\
        &+p(z_1)p(z_2)p(X=z_3z_4z_5)+p(z_1)p(z_3)p(X=z_2z_4z_5)\\
        &+p(z_1)p(z_4)p(X=z_2z_3z_5)+p(z_1)p(z_5)p(X=z_2z_3z_4)\\
        &+p(z_2)p(z_3)p(X=z_1z_4z_5)+p(z_2)p(z_4)p(X=z_1z_3z_5)\\
        &+p(z_2)p(z_5)p(X=z_1z_3z_4)+p(z_3)p(z_4)p(X=z_1z_2z_5)\\
        &+p(z_3)p(z_5)p(X=z_1z_2z_4)+p(z_4)p(z_5)p(X=z_1z_2z_3))/10
  \end{split}
\end{equation*}

\subsection{Codon decoding}

The codon $x_1x_2x_3$ that maximizes the posterior $p(X=x_1x_2x_3 \gv Z=\arr{z})$ is the decoded
codon for the given matched or inserted subsequence $\arr{z}$. Note that
\begin{equation*}
  p(X=x_1x_2x_3 \gv Z=\arr{z}) \propto p(Z=\arr{z} \gv X=x_1x_2x_3) p(X=x_1x_2x_3).
\end{equation*}
It therefore remains to compute
\begin{equation*}
  p(Z=\arr{z} \gv X=x_1x_2x_3) = \sum_{\pi}p(Z=\arr{z} \gv \Pi=\pi, X=x_1x_2x_3) p(\Pi=\pi),
\end{equation*}
for which $\pi$ is a path of the base-indel process.

\subsubsection{Sequences of length 1}

\begin{equation*}
  p(Z=z_1 \gv X=x_1x_2x_3) = \e^2(1-\e)^2(\I(x_1, z_1) + \I(x_2, z_1) + \I(x_3, z_1))/3
\end{equation*}

\subsubsection{Sequences of length 2}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2 \gv X=x_1x_2x_3)
        &= 2\e(1-\e)^3(\I(x_2, z_1)\I(x_3, z_2) + \I(x_1, z_1)\I(x_3, z_2) + \I(x_1, z_1)\I(x_2, z_2))/3\\
        &+ \e^3(1-\e)(\I(x_1, z_1) + \I(x_2, z_1) + \I(x_3, z_1))p(z_2)/3\\
        &+ \e^3(1-\e)(\I(x_1, z_2) + \I(x_2, z_2) + \I(x_3, z_2))p(z_1)/3
  \end{split}
\end{equation*}

\subsubsection{Sequences of length 3}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2z_3 \gv X=x_1x_2x_3) &= (1-\e)^4\I(x_1, z_1)\I(x_2, z_2)\I(x_3, z_3)\\
        &+ 4\e^2(1-\e)^2 (\I(x_2, z_2)\I(x_3, z_3) + \I(x_1, z_2)\I(x_3, z_ 3) + \I(x_1, z_2)\I(x_2, z_3)) p(z_1)/9\\
        &+ 4\e^2(1-\e)^2 (\I(x_2, z_1)\I(x_3, z_3) + \I(x_1, z_1)\I(x_3, z_3) + \I(x_1, z_1)\I(x_2, z_3))p(z_2)/9\\
        &+ 4\e^2(1-\e)^2 (\I(x_2, z_1)\I(x_3, z_2) + \I(x_1, z_1)\I(x_3, z_2) + \I(x_1, z_1)\I(x_2, z_2))p(z_3)/9\\
        &+ \e^4 (\I(x_1, z_3) + \I(x_2, z_3) + \I(x_3, z_3))p(z_1)p(z_2)/9\\
        &+ \e^4 (\I(x_1, z_2) + \I(x_2, z_2) + \I(x_3, z_2))p(z_1)p(z_3)/9\\
        &+ \e^4 (\I(x_1, z_1) + \I(x_2, z_1) + \I(x_3, z_1))p(z_2)p(z_3)/9
  \end{split}
\end{equation*}

\subsubsection{Sequences of length 4}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2z_3z_4 \gv X=x_1x_2x_3)
      &= \e(1-\e)^3 (\I(x_1, z_2)\I(x_2, z_3)\I(x_3, z_4)p(z_1)
      +\I(x_1, z_1)\I(x_2, z_3)\I(x_3, z_4)p(z_2)\\
      &+\I(x_1, z_1)\I(x_2, z_2)\I(x_3, z_4)p(z_3)
      +\I(x_1, z_1)\I(x_2, z_2)\I(x_3, z_3)p(z_4))/2\\
      &+\e^3(1-\e)(\\
      &+ \I(x_2, z_3)\I(x_3, z_4)p(z_1)p(z_2) + \I(x_2, z_2)\I(x_3, z_4)p(z_1)p(z_3)\\
      &+ \I(x_2, z_2)\I(x_3, z_3)p(z_1)p(z_4) + \I(x_2, z_1)\I(x_3, z_4)p(z_2)p(z_3)\\
      &+ \I(x_2, z_1)\I(x_3, z_3)p(z_2)p(z_4) + \I(x_2, z_1)\I(x_3, z_2)p(z_3)p(z_4)\\
      &+ \I(x_1, z_3)\I(x _3, z_4)p(z_1)p(z_2) + \I(x_1, z_2)\I(x_3, z_4)p(z_1)p(z_3)\\
      &+ \I(x_1, z_2)\I(x_3, z_3)p(z_1)p(z_4) + \I(x_1, z_1)\I(x_3, z_4)p(z_2)p(z_3)\\
      &+ \I(x_1, z_1)\I(x_3, z_3)p(z_2)p(z_4) + \I(x_1, z_1)\I(x_3, z_2)p(z_3)p(z_4)\\
      &+ \I(x_1, z_3)\I(x_2, z_4)p(z_1)p(z_2) + \I(x_1, z_2)\I(x_2, z_4)p(z_1)p(z_3)\\
      &+ \I(x_1, z_2)\I(x_2, z_3)p(z_1)p(z_4) + \I(x_1, z_1)\I(x_2, z_4)p(z_2)p(z_3)\\
      &+ \I(x_1, z_1)\I(x_2, z_3)p(z_2)p(z_4) + \I(x_1, z_1)\I(x_2, z_2)p(z_3)p(z_4))/9
  \end{split}
\end{equation*}

\subsubsection{Sequences of length 5}

\begin{equation*}
  \begin{split}
    p(Z=z_1z_2z_3z_4z_5 \gv X=x_1x_2x_3)
        &= \e^2(1-\e)^2(\\
        &+p(z_1)p(z_2)\I(x_1, z_3)\I(x_2, z_4)\I(x_3, z_5)+p(z_1)p(z_3)\I(x_1, z_2)\I(x_2, z_4)\I(x_3, z_5)\\
        &+p(z_1)p(z_4)\I(x_1, z_2)\I(x_2, z_3)\I(x_3, z_5)+p(z_1)p(z_5)\I(x_1, z_2)\I(x_2, z_3)\I(x_3, z_4)\\
        &+p(z_2)p(z_3)\I(x_1, z_1)\I(x_2, z_4)\I(x_3, z_5)+p(z_2)p(z_4)\I(x_1, z_1)\I(x_2, z_3)\I(x_3, z_5)\\
        &+p(z_2)p(z_5)\I(x_1, z_1)\I(x_2, z_3)\I(x_3, z_4)+p(z_3)p(z_4)\I(x_1, z_1)\I(x_2, z_2)\I(x_3, z_5)\\
        &+p(z_3)p(z_5)\I(x_1, z_1)\I(x_2, z_2)\I(x_3, z_4)+p(z_4)p(z_5)\I(x_1, z_1)\I(x_2, z_2)\I(x_3, z_3))/10
  \end{split}
\end{equation*}

\subsection{Analysis}

The codon emitted at node $\state{M}$ in \Cref{fig:codon-hmm-tree} can go through $m\in\{0, 1, 2, 3,
4\}$ base indels during the node transitions that end at some leaf-node. The probability of
it undergoing $m$ indels is given by
\begin{equation*}
  p(M=m) = \binom{4}{4-m} (1 - \e)^{4-m} \e^m,
\end{equation*}
where the coefficient $\binom{4}{m}$ counts the number of paths corresponding to $m$ base indels.
\Cref{fig:indel-dist} shows the base indel distributions over different values of $\e$.
Let $F$ be a random variable representing the final sequence length generated by the model in
\Cref{fig:codon-hmm-tree}.
We have the probabilities
\begin{equation*}
  \begin{split}
    p(F=1) = p(F=5) &= \e^2(1-\e)^2, \\
    p(F=2) = p(F=4) &= 2\e^3(1-\e) + 2\e(1-\e)^3,~\text{and} \\
    p(F=3)          &= \e^4 + 4\e^2(1-\e)^2 + (1-\e)^4,
  \end{split}
\end{equation*}
illustrated in \Cref{fig:len-dist} over different values of $\e$.

\begin{figure}[htbp]
  \centering
  \captionsetup{width=0.85\linewidth}
  \begin{subfigure}{.5\linewidth}
    \centering
    \includegraphics[width=.7\linewidth]{figure/indel-prob}
    \caption{Base indel distribution.}\label{fig:indel-dist}
  \end{subfigure}%
  \begin{subfigure}{.5\linewidth}
    \centering
    \includegraphics[width=.7\linewidth]{figure/seq-len-prob}
    \caption{Sequence length distribution.}\label{fig:len-dist}
  \end{subfigure}
  \caption{ Distribution of base indels and sequence length over the modification probability
  $\e$. It seems reasonable to choose a $\e$ value that is smaller than $1/5$ such that
  $p(M=m)<p(M=m+1)$, as per \Cref{fig:indel-dist}. }\label{fig:dist}
\end{figure}

\newpage
\begin{sidewaysfigure}[ht]
    \centering
    \includegraphics[scale=0.9]{figure/codon-hmm-tree}
    \caption{Matched codon HMM tree.
        The $\e$-transitions occur infrequently and exist to account for sequence errors.
        The most probably path ends at the first leaf-node from left to right.}\label{fig:codon-hmm-tree}
\end{sidewaysfigure}


\chapter{Methodology}
\label{methods}
%promises made in other sections:
% * description of disease enrichment method

%intro to the methods
This chapter describes the use of two probabilistic models to construct a weighted PPI network.
The first of these is a supervised binary classifier, implemented from a selection of either logistic regression, \ac{SVM} or random forest.
As the project progressed this method was unsuccessful and a second conditionally independent probabilistic model was used to update on prior knowledge and produce the final weightings.
Feature extraction was the predominant component in this project and involved turning the various data sources involved into usable features in a machine learning framework.
%FIN: what would a non-traditional way be?
The chosen Community Detection method, the fast and efficient Spectral Modularity algorithm, is also described.
%FIN:why was it chosen?

\section{Feature vectors}

%Features are the processed form of the data we use to make predictions about a given interaction between pairs of proteins and is defined mathematically in the following text.
The set of biologically relevant information associated with a given protein interaction is referred to as a feature vector and the constituent elements features.
The process of retrieving these from biological databases is referred to as feature extraction.
%FIN: typo
This is a task which commonly involved mapping between non-standardised protein identifiers and indexing large tables of biological data automatically.
%FIN: mention non-standardisation/alternative identifiers used in different data sources -I think you need to make it clear how difficult the data collection was especially as a novice to the available databases and data formats

% going through posing the problem in terms of probability
In supervised learning problems we wish to learn a mapping between input variables and output variables given a training set.
Defining this training set rigorously, it consists of input variables $\pmb{x}$, which are typically vectors of values known as features.
The output variables in a classification problems are a set of labels\autocite[2]{murphy_machine_2012} which are denoted as $y$.
In the case of binary classification these are simply either 0 or 1.
Given $N$ training vectors, $\pmb{x}_{i}$, corresponding to $N$ interactions in the network and training labels $y_{i}$ we can define our training set $\mathcal{D}$ for $N$ data points as:

\begin{align}
    \mathcal{D} = \left( ( \pmb{x}_{i}, y_{i} ) \right)_{i=1}^{N}
\end{align}

%an example?

%pose our problem
Our problem involves taking various types of biological data, such as entries from biological databases indicating that proteins are involved in the same part of a cell and using these as features.
The training labels are either an interaction (a one) or a non-interaction (a zero).
Interactions are taken to be any interactions in the iRefIndex\autocite{razick_irefindex:_2008} consolidated database.
This database was chosen for reasons described in section \ref{gold}.
%FIN: why, what is this db? consolidated database
Non-interactions are random binary combinations of Entrez protein IDs, which is a method applied in other works\autocite{qi_evaluation_2006} to create negative training examples.
%FIN: created by you how and from what dataset, hell cite the script/ipynb you used
These are also checked against the iRefIndex database to ensure they are not accidentally known interactions.
The full training set contained 188,833 true interactions and 997,760 non-interactions, but only a sub-sample of this was used for training to ensure a ratio of 600 non-interactions per true interaction.
%There are approximately 600 non-interactions for every true interaction.

What we would like to estimate is the posterior probability of an interaction existing given a new feature vector after training our classifier.
%FIN: typo/missing word
For any model $\mathcal{H}$ and a new feature vector $\pmb{x}^{*}$ we can express this using Bayes theorem:

\begin{align}
    p(y^{*} = 1 | \pmb{x}^{*}, \mathcal{D}, \mathcal{H}) = \frac{ p(\pmb{x}^{*}| y^{*} = 1 , \mathcal{D}, \mathcal{H}) p( y^{*} = 1 | \mathcal{D}, \mathcal{H})}{ \sum{y^{*}} p( \pmb{x}^{*} | y^{*}, \mathcal{D}, \mathcal{H})}
    \label{eq:bayes}
\end{align}

Where in equation \ref{eq:bayes} posterior probability of an interaction $y^{*} = 1$ conditioned on a novel feature vector $\pmb{x}^{*}$ is $p(y^{*} = 1 | \pmb{x}^{*}, \mathcal{D}, \mathcal{H})$ and the prior is $p( y^{*} = 1 | \mathcal{D}, \mathcal{H})$.

We explicitly apply a prior to the probability of interaction based on the expected ratio of interactions to non-interactions stated in \autocite{qi_evaluation_2006}.
%FIN: what was Qi's justification for this value? Presumably observed ratios - cite the justifying paper if it wasn't Qi - unfortunately, it was Qi - other papers sometimes choose one in 350 or one in 400 (PIPs)
This is described in more detail in section \ref{bayes}.

\subsection{Protein identifier mapping}

Mapping from one protein identifier to another became a significant problem in this project.
%FIN: so a few of my earlier comments will be redundant to this section so reference from those sections to here
Unfortunately, most Biological databases maintain their own indexing method to identify different genes and proteins.
New data sources being integrated into this project would often be using a different identification scheme to the NCBI Entrez GeneID originally chosen to use in the \ac{PPI} network.

%what the Entrez identifier is -  as opposed to other protein identifier schemes - cite NCBI web pages
Genes are uniquely defined by their amino acid sequence, which is a long series of letters.
However, for the sake of posterity, databases containing information about genes typically apply an identifier for each gene that is much shorter than the sequence and can encode other information about the gene, typically referred to as an accession.
%FIN: commonly referred to as accessions
The Entrez GeneID identifier is relatively simple, just consisting of a number generated when the gene was added to the database\autocite{maglott_entrez_2007}.

%other protein identifier schemes and mapping between them
Other popular schemes include the Ensembl identifier from the Ensembl database\autocite{hubbard_ensembl_2002}, Uniprot identifiers from the Uniprot database\autocite{the_uniprot_consortium_universal_2008} and even those used only for specific databases such as \ac{DIP} identifiers\autocite{xenarios_dip_2002}.
Mapping between these different identifiers is difficult as each identifier may map to none or many in another database.
The reason this happens is due to isoforms of different proteins; different amino acid sequences can code for a protein with the same name.
This can be due to, for example, alternative splicing\autocite{black_mechanisms_2003} or simple submission errors\autocite{zeeberg_mistaken_2004}.
%FIN: alternative splices of the same gene can produce different proteins, every gene is made of introns and exons, substrings which don't code for the amino acids in the protein and those that do respecitvely.  Expressed proteins are generated from any of several combinations of introns and exons (see http://en.wikipedia.org/wiki/Alternative_splicing).  Alt splicing is really important in eukaryotes and is one of the big explanations between the very low number of genes we found when we sequenced the human genome compared to the predicitions.
%FIN: the other source of 'isoforms' is when a piece of DNA is duplicated and have diverged a little in sequence between copies (older literature referred to alleles as isoforms which are slightly different as these are alternative forms of a gene such as say a gene for blue eyes or brown eyes (although that may actually be a polygenetic trait))
%FIN: you've also missed an issue with the multiple mappings of mistakes and errors, also these mistakes and errors being differentially fixed or propagated through databases.  A lot of the big source databases are public goods where many author's contribute and curation is mostly automated so have problems.  A fun and amusing example of finding accessions in databases that have been reformatted automatically by someone using excel and not noticing http://www.biomedcentral.com/1471-2105/5/80

%methods used during the project, with references to appendix notebooks
Various tools exist to map from one protein identifier to another: Ensembl's BioMart\autocite{smedley_biomart_2009} is a versatile web-based tool, for example.
In this project, simple conversion tables from NCBI's Gene\autocite{maglott_entrez_2007} ftp server were primarily used.
Another tool used was the Uniprot\autocite{the_uniprot_consortium_universal_2008} online service web service.

% talk about the problem of canonicalisation
Unfortunately, using any of these services there will be a number of identifiers which cannot be converted and many IDs mapping to the same Entrez identifier as different protein isoforms are picked up.
%FIN: this isn't always the explanation - for example one database might contain say several different crystal structures done of a protein which will all theoretically map from many identifiers relating to each of these structures to one identifier of the raw sequence in genbank
One way to avoid this problem is to only refer to a single canonical form of any given protein and find this protein in other databases through its amino acid sequence.
%FIN: a benefit of this method is also that it can be used to find mis-labelled proteins: if you searched just for all data related to protein X, but someone had done a load of work on something they called protein Y but was actually protein X. If you didn't search by sequence you wouldn't find data
This ensures that when referring to an interaction between two identifiers the interaction is always simply between two proteins.
%FIN: also note why the amino acid sequence is better than using the nucleotide sequence because it is the actual form of the protein and is derived after all the alternative splicing/isoform issues

% how using Entrez identifiers risks becoming gene interaction prediction
% or "What Entrez isn't"
Otherwise, as in this project, the interaction is detected between two Entrez identifiers; which corresponds to an interaction between genes - possibly only a single interaction between combinations of the isoforms of each gene.
%FIN: exactly, also worth putting the limitation in of not directly testing co-localisation and co-expression (i.e. temporal and spatial localisation allowing interaction)
Unfortunately, this means that this project is only concerned with gene interaction prediction until the Entrez identifiers have been carefully canonicalized.
This is not really a problem, as we are only aiming to provide a weighting to a graph, rather than provide an accurate prediction of interaction between proteins.
%FIN: to be less negative maybe say you will still identify possible interactions but may not identify all of them (as you are only checking one isoform etc).  This can still be informative if it is a new predicition which is later validated

% how iRefIndex solves this problem and should have been used from the start
% with reference to storing the sequences of each protein involved to maintain unambiguity
A solution to this problem is provided by the iRefIndex\autocite{razick_irefindex:_2008} database, which combines many databases and stores canonicalized entries.
Using this database, it would be possible to ensure that the proteins used in a future project would be reliable canonical proteins.
Additionally, each protein of interest should ideally be stored with reference to its sequence in, for example, FASTA format.
%FIN: be explicit amino acid sequence rather than protein sequence

%description of feature extraction code
%\subsection{Dedicated code: ocbio.extract}

\section{Supervised model}
\label{gold}
%material on the problems with choosing between gold-standard datasets
% with reference here to the section in Qi's thesis

%original work on \ac{DIP} (justified choice from previous work)
To begin supervised learning, the model required a set of accepted true interactions.
The database of interacting proteins (\ac{DIP}) is a database of interactions proven by small-scale experiments\autocite{xenarios_dip_2002}.
Each interaction added is hand curated so it was expected to be a reliable training set.
This database was also used as a training set in \textcite{qi_evaluation_2006}, who used the same supervised training method.

%problems with \ac{DIP}
%why \ac{HIPPIE} is better suited
Unfortunately, problems were found with \ac{DIP} as a training set.
%FIN: I don't understand - explain what these problems are/were
Features derived from interaction other databases, such as STRING, would win out in importance versus all indirect features as shown in figure \ref{fig:unbalanced}.
\ac{HIPPIE} was also tested as a training set, but this lead to the same problem.
%FIN: so which did you use?

%example feature importance graph
\begin{figure}
    \centering
    \setlength\figureheight{3in}
    \setlength\figurewidth{4in}
    \InputIfFileExists{\imagedir/unbalanced.weighting.tikz}{}{\textbf{!! Missing graphics !!}}
    \caption{An example of an unbalanced set of feature importances plotted after fitting a Random Forest classifier to a dataset containing interaction database derived features. Feature indexes are not as described in table \ref{tab:fvectors}. Importances are dimensionless and show that only a small number of features are important to the classifier.}
    \label{fig:unbalanced}
\end{figure}

%After removing interaction databases
It was decided that only indirect features, as described in section \ref{back:sources} should be used in the trained supervised classifier and direct evidence integrated into the final weightings in an explicit Bayesian method described in section \ref{bayes}; the results of which are described in section \ref{bayesresults}.
Once these databases were removed the performance of the classifier was drastically lower.
However, all of the available features had more closely distributed importances in the final classifier, as shown in section \ref{importances}.
%FIN: this isn't obvious to me - you need to explain why balance set of features is important

%iRefIndex as a final solution?
To train the final classifier the iRefIndex\autocite{razick_irefindex:_2008} database was used to find real interactions due to its canonicalisation of identifiers and the number of databases it includes.
Again, non-interactions were generated as random combinations of Entrez Gene IDs.
These were also checked against the positive interactions to ensure known interactions were not present.

\subsection{Labeling feature vectors}

%planned features, describe the list of possible features which was created
%put it in the appendix as a table, or otherwise somehow
\ac{PPI} prediction features are a set of values for each interaction considered, if it is a real or non-interaction.
This arrangement is illustrated in figure \ref{fig:fvectors}.
The features used are described by index in table \ref{tab:fvectors}.

% link to the notebook on using this code
% but update it to explain what custom generator options are
To keep track of the various different data sources and assemble the features into vectors to be used in the classifiers a dedicated piece of code was required.
The code developed is written as a python module called ocbio.extract.
Usage and development notes for this program are referenced in Appendix \ref{app:ocbio}.

%this could be a good place to put that diagram of exactly what a feature vector is
\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{fvectors.png}
    \caption{A diagram showing the structure of feature vectors and their relationship to the project as a whole. This figure is based on a similar flow chart shown in the project proposal.}
    \label{fig:fvectors}
\end{figure}

\begin{table}
    \centering
    \begin{tabular}{l c p{0.5\textwidth}}
        Feature         & Indices & Description \\
        \hline
        Gene Ontology   & 1-90    & Described in section \ref{go}, with individual indices described in Appendix \ref{app:go}. \\
        Y2H             & 91      & Y2H experimentally derived feature \\
        ENTS derived    & 92-198  & Features used by the ENTS classifier, described by index in supplementary table for \textcite{rodgers-melnick_predicting_2013}. \\
        ENTS summary    & 199     & Prediction result of the classifier in \textcite{rodgers-melnick_predicting_2013}. \\
    \end{tabular}
    \caption{Each feature used in the final classifier is described by index.}
    \label{tab:fvectors}
\end{table}

%details of what classifiers were chosen and about scikit-learning
\subsection{Model Selection}

%classification as a weighting tool
The classification problem we are solving is different in that we are really trying to obtain a realistic weighting of interactions for use in a \ac{PPI} network.
%FIN: different from what?
Classification is normally concerned about picking a decision threshold to classify examples into categories.
However, in this case the output of our process is the posterior probability of the model $\mathcal{H}$ as in equation \ref{eq:bayes}.
Where $\mathcal{H}$ is any of the following classification models, such as logistic regression.

%introduce scikit-learn
The posterior probability was constructed using the Python package Scikit-learn\autocite{pedregosa_scikit-learn:_2011}.
Each classifier implemented in this package has a similar interface allowing modular code to be written.
In addition, this package is actively developed with all the required classifiers having efficient implementations.
%FIN: also one of most widely used packages

% explain why we tried the algorithms that we tried
%The following sections describe the three classifiers chosen.
There were three classifiers chosen: a logistic regression model, a random forest model and a \ac{SVM}.
%Each of these involved tuning a number of hyper-parameters.

%\subsubsection*{Hyper-parameters}
%describe the different parameters varied in scikit-learn by name
%FIN: explain what a hyper-parameter actually is
Each classifier used requires tuning of hyper-parameters which will affect its overall performance.
These hyper-parameters are described in table \ref{tab:hyper} for each of the models used in the project.
The optimal values for these found can be found in table \ref{tab:gridresults}.

%table of the different hyper-parameters
\begin{table}
    \centering
    \small
    \begin{tabular}{p{0.2\textwidth} c p{0.5\textwidth}}

        Classifier                                  & Hyper-parameters     & Description \\
        \hline
        Logistic Regression                         & C                         &  Inverse of regularisation strength, the $\alpha$ parameter in section \ref{logreg}. \\
        \hline
        \multirow{3}{*}{\parbox{0.2\textwidth}{Support Vector Machine}}     & kernel                    &  The kernel used. Three options: linear, \ac{RBF} and polynomial. \\
                                                    & Gamma($\gamma$)           &  Kernel coefficient. \\
                                                    & C                         &  As with Logistic Regression, a penalty parameter. \\
        \hline
        \multirow{2}{*}{\parbox{0.2\textwidth}{Random Forest}}              & N estimators              &  Number of trees used in the forest. \\
                                                    & Max features              &  Number of features considered when looking for splits, part of the problem of finding the best decision at each node described in section \ref{randomforest}. \\
        \hline
        \multirow{2}{*}{\parbox{0.2\textwidth}{Extremely Randomized Trees}} & N estimators              &  As with Random Forest. \\
                                                    & Max features              &  As with Random Forest. \\
    \end{tabular}
    \caption{Summary of the hyper-parameters described in the Scikit-learn \autocite{pedregosa_scikit-learn:_2011} documentation to be tuned for each of the models considered.}
    \label{tab:hyper}
\end{table}

\subsubsection*{Logistic Regression}
\label{logreg}

%with reference to Murphy
Logistic regression is a linear model being used for binary classification.
%FIN:binary classification
It is equivalent to a linear regression model transformed through a sigmoid function\autocite[376]{murphy_machine_2012}, denoted here by $\sigma$:

\begin{align}
    p(c=1|\pmb{x}) = \sigma(b + \pmb{x}^{T}*\pmb{w})
    \label{sigmoidtransform}
\end{align}

Where in equation \ref{sigmoidtransform} $\pmb{x}$ is the vector of features and $c$ is the class label - using $1$ for a real interaction and $0$ for a non-interaction.
The weights and biases are the parameters of this model, expressed in the above equation as $b$ and $\pmb{w}$, respectively.

This divides the points, feature vectors, in the dataset by a hyperplane, classifying the points on each side of the hyperplane into different classes.
For data that is linearly separable, this produces a classifier that will make no mistakes on the test data.
Unfortunately, the data we are working with is not linearly separable as shown by visualization in section \ref{dataviz}.

%How is it trained?
To find the parameters in this model the log likelihood must be maximised; corresponding to the maximum likelihood solution.
The log likelihood, for N feature vectors, is given by:

\begin{align}
    L(\pmb{w},b) = \sum_{n=1}^{N} c^{n} \log \sigma(b + \pmb{w}^{T}\pmb{x}^{n}) + (1 - c^{n})\log (1 - \sigma(b + \pmb{w}^{T}\pmb{x}^{n}))
\end{align}

%describe what the C parameter is
Regularisation of the weights represents a prior belief that the weights should not increase without bound.
In a case where the data is linearly separable and where regularisation is not applied the weights will increase without bound to produce extremely confident classifications\autocite[381]{barber_bayesian_2012}.
To stop this from happening we apply a penalty term, $\frac{1}{C}$, to the size of the weights:

\begin{align}
    L'(\pmb{w},b) = L(\pmb{w},b) - \frac{1}{C} \pmb{w}^{T}\pmb{w}
\end{align}

Tuning this hyper-parameter is the goal of a grid search, which is discussed in section \ref{classifierverification}, and the optimal value found in this case was 0.0215 as shown in table \ref{tab:gridresults}.
%FIN: explain grid-search

\subsubsection*{Support Vector Machines}
%FIN: you are a big fan of Murphy
%GAV: it is kind of a joke, it's probably my least favourite ML textbook, but it is thorough
%with reference to Murphy
Logistic regression can be generalised to apply kernel functions to the input features to obtain better classifications.
Support Vector Machines exploit this while also applying a different objective function intended to avoid overfitting\autocite[383]{murphy_machine_2012}.
The objective in placing the hyperplane for a \ac{SVM} is ``maximum margin'' in that it attempts to maintain the same distance from the closest opposing class points.
%FIN: typo/missing word

%success of these models?
These are often successful classifiers in practice.
Applications include text categorisation, hand-written character recognition, image classification and biosequences analysis\autocite{cristianini_introduction_2000}.

%describe the hyper-parameters?
The hyper-parameters for a SVM control the kernels, along with the regularisation parameter as described for logistic regression in section \ref{logreg}.
%FIN: explain what a kernel is and how \ac{SVM}s can classify non-linearly seperable unlink logit by transformation to feature space
Two of the three hyper-parameters which can be tuned during a grid search operation are the degree of polynomial kernels if chosen and the gamma coefficient of the kernels.
In table \ref{tab:gridresults} it can be seen that the best performance was achieved with a \ac{RBF} kernel, C of 10.0 and gamma of 10.0.

\subsubsection*{Random Forest}
\label{randomforest}

A random forest is a another of these models.
It operates as a combination of many decision trees.
Decision trees are intuitively simple in that they consist of a series of comparisons arranged in a tree as shown in figure \ref{fig:dectree}.
Each feature is tested at a node to come to a final conclusion about the state of the interaction.

\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{decisiontree.png}
    \caption{A simple example decision tree, illustrating the process of sequential, dependent decisions. The example feature vector f follows a path through the tree indicated by a dashed line. Based on an image obtained through Wikimedia\autocite{wkmdacommons}.}
    \label{fig:dectree}
\end{figure}

In this way decision trees are both simple and tractable methods for using a feature vector to classify interactions as real or false and there are many automated ways to generate effective decision trees.
The problem in the design of a decision tree is which comparison to choose at each node, which is beyond the scope of this report, a full description can be found in \textcite[544]{murphy_machine_2012}.
Other advantages of decision trees include the ability to handle a mixture of discrete and continuous inputs, automatic variable selection, scaling to large datasets readily and the ability to handle missing inputs, with modification.
%other strengths of decision trees?

%describe split function? probably not worth going into this.

%then explain the problems with decision trees, variance etc
Unfortunately, despite the strengths of decision trees there are still problems with stability: small changes in the input data can produce large changes in the output\autocite[550]{murphy_machine_2012}.
The random forest algorithm addresses this problem by providing redundancy; multiple trees are grown and their results averaged.
%FIN: how many trees?
For M trees trained on different subsets of the data\autocite[551]{murphy_machine_2012} we obtain:

\begin{align}
    f(x) = \sum_{m=1}^{M} \frac{1}{M} f_{m}(x)
\end{align}

Where $f_{m}(x)$ is $m$th tree. This is simply averaging the results of the trees and is known as bagging.

%with reference to Qi and ENTS, showing good performance on this problem
With the ability to work on large datasets and mixing continuous and discrete data these types of classifiers would appear to already be well suited to this problem.
%FIN: maybe say well theoretically suited and then show in reality with the citations
This is what has been observed in the literature, with these classifiers achieving the best performance despite different types of biological data being used\autocites{qi_evaluation_2006,rodgers-melnick_predicting_2013}.
Due to these reports in the literature it appeared that this classifier would be the best choice for our protein interaction prediction task.

%hyper-parameters found
The two hyper-parameters varied in our search were the number of trees, or estimators and the max features described in table \ref{tab:hyper}.
In table \ref{tab:gridresults} it can be seen that 44 estimators and a max feature value of 25 were found to be optimal.

%expand on how much better they were etc? in different places?

\subsubsection*{Other options}

% what other algorithms could we have tried but didn't
Other options considered for our classification problem, but not included in the project due to time constraints included Feedforward neural networks, Naive Bayes and Beta regression.
Naive Bayes in particular would have required modifying the code from Scikit-learn to deal with data from multiple different distributions or implementing Weka's solution of kernel density estimated distributions for each different feature\autocite{john_estimating_1995} due to current Python implementations being limited to either the Gaussian or Bernoulli case.
%FIN: explain why

%\subsubsection*{Beta regression}
%
%%what is beta regression? quickly
%Beta regression is a generalised linear model is one in which the output variable is distributed according to a Beta distribution\autocite{smithson_better_2006}.
%%FIN: typo/missing word
%A maximum-likelihood solution to this model can be found and the resulting model fit in the same way as a standard regression model.
%%FIN: typo/missing word
%
%%why this would also have been a good idea, if we didn't have to implement it ourselves
%True protein interactions are not something which can be assumed in a protein interaction prediction task.
%Many proteins are known to be very likely, but others are less confidently classified, as reflected in the \ac{HIPPIE} database's confidence scoring system\autocite{schaefer_hippie:_2012}.
%%FIN: typo/missing word
%
%To train a classifier a training set of true and false interactions is required and this cannot be supplied without thresholding the database at an arbitrary confidence value.
%
%Beta regression avoids this problem as it allows the confidence values to remain a part of the regression process.
%Using this we can build a model and update our belief on the likelihood of interaction in a Bayesian framework much more easily.
%
%%FIN: actually this is pretty cool, note to self read up on Beta regression

\subsection{Model testing}
\label{classifierverification}

%Tests we planned to use on each classifier:
%  mention cross-validation
%  learning curves
%  simple accuracy value
%  grid search
%  \ac{ROC}
%  Precision recall
%  test interactions
%

% consider using paragraph headings in this section
Various measures, such as accuracy, \ac{ROC} and precision-recall, were applied to each model to estimate their performance in different ways.
These tests included simple accuracy measures applied over learning curve and grid searches along with plotting \ac{ROC} and precision-recall curves.
Grid searches of parameter values were used to find optimal hyper-parameters in all three models.

% was or will be?
Cross-validation is the practice of repetitively splitting the data into training and test sets and was applied to tests during hyper-parameter searches\autocite[152]{witten_data_2011}.
It was also applied when plotting learning curves to get a statistical estimate of the reliability of the metrics applied to the classifier.
%FIN: you don't really explain what CV and why you can't just optimise the models performance directly on the test set
As the training set is approximately $10^{6}$ samples, these were applied as random sub-samples of the full data set, but stratified to maintain the same proportion of non-interactions to interactions as in the full training set.
This is important as it must reflect the expected ratio for real protein interactions to non-interactions.
The use of pipelines and learning curves in this process is described in Appendix \ref{app:notebooks}.

%\subsubsection*{Grid search}
% grid search
A grid search is a cross-validated test measuring accuracy testing the classifier with a variety of different hyper-parameters.
Classifiers, such as a Logistic Regression model, have some number of hyper-parameters.
A Logistic Regression model, for example, has a single hyper-parameter so that the grid search for this model simply involves varying this parameter to obtain the optimum performance on the test set.
%FIN:repeat hyper-parameter identity in logististc regression - regularisation

%\subsection{Missing data}
%how was missing data dealt with?
Before classification could be performed the missing data in the feature vectors had to be imputed.
This was performed by filling the missing values with the mean value of that feature.
This is a common technique that is applied if it is likely the data is missing at random.
In this case the data that is missing is due to mismatches in protein identifier mapping dictionaries, which is likely random and independent of the interaction prediction task.
%FIN: link back to imputer discussed earlier, if you are having a section on this you could add a section on data normalization

\subsubsection*{Accuracy}
% accuracy value
The accuracy value plotted in the learning curve and used in grid searches of parameters values is simply the proportional of correctly classified instances in a training or validation set.
Typically, the protein interaction prediction problem is sparse, in that there are very few interactions for the large number of non-interactions.
This is reflected in the accuracy in that a classifier that simply always predicts zero can still achieve a very high accuracy.
Using this accuracy value is therefore problematic and this requires the other measures employed, such as \ac{ROC} and precision-recall \ac{AUC} values.

\subsubsection*{\ac{ROC} curve}
% explain what those are
A Receiver Operating Characteristic, or \ac{ROC}, curve plots the variation in true positive to false positive rate as the threshold of classification is varied.
This makes it useful as an illustration of the tradeoff possible with this particular classifier.
The Area Under Curve, or \ac{AUC}, value is the area under this line.
A higher \ac{AUC} value corresponds to a better classifier, although there is some controversy surrounding this\autocite{hanczar_small-sample_2010}.
These concerns center on the problems of small sample sizes, which are not the case in this project.
%FIN: maybe add in a wee truth table of TP, TF, FP, FF

\subsubsection*{Precision-recall curve}
%precision recall
A precision-recall curve plots the precision of a classifier against its recall as the threshold of classification is varied.
The precision is defined as the number of true positive results over the number of total positive results.
Recall is defined as the number of true positive results against the number of available positive examples
The area under the curve is used to gauge the classifier's effectiveness.
%FIN: may as well add the equations in for precision and recall, TP, TF, FP, FF - I mean you did put down baye's rule earlier
%example \ac{ROC} curve?
%example precision recall curve?

\section{Conditionally independent probabilistic model}
\label{bayes}
%description of the method used to weight interactions after the classifier was found to be insufficient

%justification for using this method, the problem with supervised classification?
%CHECK THIS ISN'T FOUND ELSEWHERE ALREADY
Weighting interactions using the posterior distribution of a probabilistic model requires that the model accurately represents beliefs about the system being modelled.
Supervised classification requires that true interactions are known in order to find the parameters of the model.
Unfortunately, in this problem we cannot know for certain whether an interaction is real or false.
Therefore, when fitting a supervised model we only obtain, at best, an accurate predictor for the interaction database used to fit the model as shown in figure \ref{fig:unbalanced}.

%the prior on the edgelist
As the \ac{PPI} network edges we plan to weight have already been defined through combining different interaction databases we already have a strong prior on the existence of these interactions.

Using the classifier on its own can then, at best, reproduce one of the databases used to create this network and many of the interactions will be incorrectly weighted much lower than expected.
The solution is to treat both the result of the classifier and the edgelist inclusion as observable events dependent on the latent ``interaction'' variable.
Along with these variables, we can also include other protein interaction prediction resources, such as \ac{STRING}\autocite{von_mering_string:_2005}.

%naive bayes model, advantages, disadvantages
The model we have chosen to update our prior belief assumes conditional independence of the observable variables given the hidden interaction variable.
This equates to a Naive Bayes model with a belief network as shown in figure \ref{fig:naive}.
An advantage of this model is the simplicity of its analysis.
The disadvantage is that our variables could be dependent, as the classifier is trained on some of the same interaction databases that the \ac{HIPPIE} database is composed of.
%FIN: typo/missing word

%belief network for naive bayes
\begin{figure}
    \centering
    \includegraphics[width=0.6\textwidth]{naive.png}
    \caption{A belief network illustrating the Naive Bayes model, equivalent to that used for inference when weighting the interactions of the \ac{PPI} network.}
    \label{fig:naive}
\end{figure}

%updating on evidence? equations

%the importance of conservative estimates
The class label, interaction, is not observed in this model so we cannot solve to find the parameters.
%FIN: \ac{PPI} or not
To define the model, the only way to proceed is to manually define them by conservatively estimating the conditional true positive and false positive rates of the Bernoulli distributions.
Continuous distributions, such as the classifier predictions or prediction databases, were estimated in a supervised way using a sample of the training set used to train the supervised classification model.
%FIN: explain \ac{KDE} acronym

%kernel density estimation, justification from Weka
%Using \ac{KDE} in conjunction with Naive Bayes is the approach used by Weka to deal with arbitrary conditional distributions\autocite{john_estimating_1995}.
%FIN: you need to explain what Weka is
%Unfortunately, this distribution is estimated using samples labeled using the protein interaction databases, so we cannot be fully confident in its predictions.
%As before, a conservative estimate of its accuracy is applied through increasing the smoothing bandwidth.

\section{Comparison of weighted and unweighted \ac{PPI} networks}

%why do we want to try weighted networks? and intro
It is hoped that a weighted network will provide new insight into the interactions of proteins in the active zone described in table \ref{tab:synsys}.
%FIN: I think at this stage you need a refresher to the reader on what active zone you are talking about
For this reason, comparing the unweighted and weighted cases of the graph produced is a major goal of this project.
The following sections describe this process and the measures applied to both networks.

\subsection{Community detection}
\label{communitydetection}
%FIN: section needs expansion in the areas you have noted
%description of each of the algorithms available
%three:
%  Geodesic edge Betweenness
%  Random edge Betweenness
%  Spectral Betweenness
Three algorithms were identified for use in this project for community detection, the first two are described in \textcite{newman_finding_2004}.
Geodesic edge betweenness and random edge betweenness are based on betweenness measures to partition the graph, making them optimisation approaches.
The third, spectral modularity, was the chosen algorithm in this project.

%with reference to Colin's paper, why this is a good choice
The original advantages of spectral modularity techniques were compatible results on generated test data in less time than competing methods in \textcite{newman_modularity_2006}.
In a recent paper, this method was compared favourably to other methods in terms of CPU time\autocite{mcleanunpub}.
%Although it detected fewer communities, it maintained a higher modularity score.

%community detection code, what it does, which algorithm was used
%pending use - will see if I have time to use more than one

\subsection{Normalised Mutual Information}

%NMI theory, what is a measure of
Mutual information intuitively is the reduction in uncertainty about one random variable by observing another
Defined in terms of entropy it is\autocite{mackay_information_2003}:

%could move that citation next to the equation?
\begin{align}
    I(X;Y) = H(X) - H(X|Y)
\end{align}

Where $H(X)$ is the entropy of the random variable $X$ and $H(X|Y)$ is the conditional entropy of $X$ given $Y$.

In the case of the function we are using to perform this from Scikit-learn the mutual information is normalised by $\sqrt{H(X)\times H(Y)}$\autocite{pedregosa_scikit-learn:_2011}.
This produces a value between zero and one which reflects the redundancy of the distributions - 1.0 being exactly the same and 0.0 being independent.

\subsection{Disease Enrichment}
\label{diseaseenrichment}

%Primer on what this test actually does
By linking the proteins in a cluster to known disease annotations it is possible to estimate the likelihood that a given community is involved in a particular disease.
Using a list of known genes involved in the disease of interest the test finds if the number of these genes in the communities detected is significant\autocites{kirov_novo_2012,lips_functional_2012}.
The code being used produces uses a hypergeometric test to find this likelihood and returns a p-value.

%FIN: explain a p-val? GAV: no space

In the case of this project, due to the aims of the SYNSYS\autocite{synsys} project and for simplicity, only two diseases were investigated: Schizophrenia and Alzheimer's.
The genes associated with schizophrenia and Alzheimer's used are part of the internal code used.
%interaction between significance level and p-value

\section*{Conclusion}

%This project involved a large number of varied techniques and algorithms being used on large data sets.
%Many problems had to be solved in order to piece together the full project.
%As each of these steps were sequential, the results section describes the results as they were gathered, in the same structure as seen above.
This chapter described how the weighted network was constructed using both a supervised probabilistic model and another conditionally independent model.
After the failings of the supervised method were apparent, this combined method was the best solution found to the prediction problem.
The next chapter will discuss the results of both of these techniques and the analysis of the weighted and unweighted networks produced.


\section{09/02}
The Ben-Or algorithm can be used to solve Binary Consensus with faults.
\begin{algorithm}
    \caption[\AlgName{Ben-Or}]{Ben-Or Algorithm from view of processor $p$ with initial value $\chi_p$}
    \label{alg:ben-or}
    \begin{algorithmic}[1]
        \Procedure{\nameref*{alg:ben-or}}{}
            \State $\texttt{decided} \gets \False$
            \State $\texttt{round} \gets 1$
            \While{not \texttt{decided}}
                \State $\Call{Broadcast}{1, \texttt{round}, \chi_p}$
                \State wait for $n - f$ messages of type $(1, \texttt{round}, \cdot)$
                \If{there are more than $\sfrac{n}{2}$ messages of type $(1, \texttt{round}, v)$}
                    \State $\Call{Broadcast}{2, \texttt{round}, D, v}$
                \Else
                    \State $\Call{Broadcast}{2, \texttt{round}, U}$
                \EndIf
                \State wait for $n - f$ messages of type $(2, \texttt{round}, \cdot)$
                \State $t \gets$ number of messages of type $(2, \texttt{round}, D, v)$
                \If{$t > 0$}
                    \State $\chi_p \gets v$
                    \If{$t > f$}
                        \State $\texttt{decided} \gets \True$
                        \State $\Call{Broadcast}{1, \texttt{round}, \chi_p}$
                    \EndIf
                \Else \Comment{All messages are of type $(2, \texttt{round}, U)$}
                    \State $\chi_p \gets \Call{Sample}{\set{0,1}}$
                \EndIf
                \State $\texttt{round} \gets \texttt{round} + 1$
            \EndWhile
        \EndProcedure
    \end{algorithmic}
\end{algorithm}
\begin{theorem}{}{}
    The above algorithm is correct.
\end{theorem}

\begin{proof}
    Validity is clear: if all nodes start with $v$, then we skip to
    %TODO finish proof
\end{proof}

\begin{theorem}{}{}
    The expected number of rounds of \nameref{alg:ben-or} is $2^{n-1}$.
    Additionally, with high probability, the number of rounds is less than
    $2^{n-1}\ln{n}$.
\end{theorem}

\begin{proof}
    If all nodes are of type $(2, \texttt{round}, ?)$, then with probability
    $\sfrac{2}{2^n} = \sfrac{1}{2^{n-1}}$ all nodes will choose the same value.
    Thus, we can upper bound the probability of failure after $k$ rounds by
    \begin{align*}\prob{\text{failure}}
        &\leq \left(1 - \frac{1}{2^{n-1}}\right)^k \leq e^{\frac{-k}{2^{n-1}}}\\
        \shortintertext{setting $k=2^{n-1}\ln{n}$}
        &=\frac{1}{n}
    \end{align*}
    Thus, the probability of success after $2^{n-1}\ln{n}$ rounds is at least $1
    - \sfrac{1}{n}$. Additionally, the expected number of rounds is at most
    $2^{n-1}$.
\end{proof}

\subsection{Graphs}
\begin{problem}{Min-Cut}{}
    Given a graph $G = (V, E)$, find a minimum set of \emph{edges} whose removal
    disconnects the graph.
\end{problem}

\begin{definition}{Graph Cut}{}
    A \emph{cut} is a partition of the vertices into two non-empty subsets, $A$
    and $B$.
\end{definition}

Notice that any edge from $A$ to $B$ crosses the cut, and when all such edges
are removed, the graph becomes disconnected.

%TODO example figures

In general, there are $\binom{n}{2}$ possible min-cuts.

%TODO draw cycle

\begin{algorithm}
    \caption{Karger's Algorithm}
    \label{alg:karger}
    \begin{algorithmic}[1]
        \Procedure{Karger}{}
            \ForRange{$i$}{1}{$n - 2$}
                \State Choose a random edge $e$ \label{line:kargersample}
                \State Contract edge $e$ \label{line:kargercontraction}
            \EndForRange
            \State Output remaining edges
        \EndProcedure
    \end{algorithmic}
\end{algorithm}

Observe that \cref{line:kargersample} requires $\bigO{1}$ operations and
\cref{line:kargercontraction} requires $\bigO{n}$ operations, for a total of
$\bigO{n^2}$. Additionally, a cut set in the contracted graph is a cut set in
the original graph, thus we can only \emph{increase} the size of the min-cut via
\cref{line:kargercontraction}.

\begin{theorem}{}{}
    \nameref{alg:karger} outputs a min-cut with probability at least
    $\sfrac{1}{n^2}$.
\end{theorem}

\begin{proof}
    Suppose $C$ is some min-cut in $G$ and write $\card{C} = k$. In that case,
    every node must have degree at least $k$, and $m \geq \sfrac{nk}{2}$.

    Let $E_i$ denote the event that no edge in $C$ is contracted in iteration
    $i$. Notice that the event that $C$ is output is simply
    \begin{align*}\prob{\bigcap E_i}
        &=\prob{E_1}\prob{E_2 \given E_1}\cdots\prob{E_{n-1} \given E_1 \cap E_2 \cap \dots \cap E_{n - 2}}\\
        &=\left(1 - \frac{2}{n}\right)\left(1 - \frac{2}{n-1}\right)\cdots\left(\frac{2}{3}\right)\\
        &=\frac{2}{n(n-1)}\\
        &=\frac{1}{\binom{n}{2}}\\
        &\geq\frac{1}{n^2}
    \end{align*}
\end{proof}

Thus, we can repeat this process $n^2\ln{n}$ times to achieve a high probability
that the algorithm outputs a min-cut.


\documentclass[11pt]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ...
%\geometry{landscape}                % Activate for for rotated page geometry
%\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{Brief Article}
\author{The Author}
%\date{}                                           % Activate to display a given date or no date

\begin{document}
%\maketitle
%\section{}
%\subsection{}
Let $X$ and $Y$ be two Banach spaces.
$C(X, Y)$ is the set of all continuous mappings $f: X\mapsto Y$.
For $f, g\in C(X, Y)$, we define
$$\|f - g\|= \sup_{x\in X} \|f(x) - g(x)\|.$$
\begin{enumerate}
\item
Prove that $C(X, Y)$ is a Banach space.
\item If $K \subset Y$ are compact in their own spaces, is $C(X, K)$ compact?
\end{enumerate}

\end{document}


\unnumberedchapter{Glossary}
\chapter*{Glossary}

Because accelerator physics is a small branch of applied physics, and because this dissertation introduces several terms that are not frequently used in the accelerator physics community, the following glossary has been included for the reader.

\textbf{Beta function} — A function that scales the amplitude of single-particle oscillations in the linear approximation.

\textbf{Beam envelope} — The root-mean-square ellipsoid defined by the covariance matrix.

\textbf{Beam perveance} — A dimensionless measure of space charge strength.

\textbf{Circular mode} — A beam with small four-dimensional emittance. It could also refer to the circular motion of the eigenvectors of a coupled transfer matrix.

\textbf{Courant-Snyder ellipse} — Particles move along this ellipse in the linear approximation. Its area is conserved.

\textbf{Danilov distribution} — A self-consistent distribution in two spatial dimensions. It is characterized by an elliptical shape, uniform charge density, and zero four-dimensional emittance.

\textbf{Effective lattice} —

\textbf{Emittance} — The root-mean-square volume or area of a phase space distribution.

\textbf{Kapchinskij-Vladimirskij (KV) distribution} — A self-consistent distribution in two spatial dimensions. Its particles are uniformly distributed on an ellipsoid in four-dimensional phase space.

\textbf{Matched beam} — A beam whose envelope oscillates with the same periodicity as the external focusing.

\textbf{Ring} — A circular accelerator.

\textbf{Painting} — An beam injection method in which the relative transverse distance and angle between the circulating and injected beam is varied.

\textbf{Phase advance} — The integral of the inverse of the beta function.

\textbf{Self-consistent distribution} — A phase space distribution which produces linear space charge forces under any linear transformation of the coordinates.

\textbf{Space charge} — The charge density of a beam in free space.

\textbf{Tune} — The number of phase space oscillations per performed by a single particle in one turn around a ring.

\textbf{Space charge tune shift} — The reduction in tune caused by the beam space charge. The linear space charge component results in the same reduction for every particle (tune shift), while the nonlinear component results in an amplitude-dependent reduction (tune spread).


\documentclass{article}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{titling}
\usepackage{amssymb}
\usepackage[skip=0.25em]{parskip}
\usepackage{amsthm}

\newtheorem{thm}{Theorem}
\renewcommand\qedsymbol{Amen.}

\setlength\droptitle{-5em}

\title{On the Possibility of Mapping the Samples to the Pitches}
\author{Varik Valefor}
\begin{document}
	\maketitle
	\section{Executive Summary}
		There exists a map $f$ such that for all sequences $n$ of a set size, $f(n)$ equals the loudest pitch of $n$.
	\section{Definitions}
		Let $S$ denote the set of all samples.

		Let $C$ equal $\bigcup_{x=1}^\infty \mathbb C^x$.

		Let $P$ denote the set of all frequencies/pitches.

		Let $w$ denote the window size.

		Let $\mathbb S$ denote the class of all sets.

		Let $F$ denote the set of all maps.

		Let $\Omega$ denote the universal set.

		For all subsets of $\Omega$ $A$ and $B$, for all $f \in F$, let $g(f,\ A,\ B)$ iff $d(f) = A$ and $r(f) = B$.
	\section{``Proper'' Maps}
		\[
			\mathrm{fft} \colon S^w \mapsto \mathbb C^w.
		\]
		For all $s \in S^w$, $\mathrm{fft}(s)$ equals the output of the FOURIER transform on $s$.
		\[
			\mathrm{pitch} \colon C \mapsto \mathbb P.
		\]
		For all $j \in C$, $\mathrm{pitch}(j)$ equals the loudest pitch/frequency of the FOURIER transform output $j$.
		\[
			d : F \mapsto \mathbb S.
		\]
		For all $f \in F$, $d(f)$ equals the domain of $f$.
		\[
			r : F \mapsto \mathbb S.
		\]
		For all $f \in F$, $r(f)$ equals the range of $f$.
	\section{In the Pudding}
		\begin{thm}
			$\exists f \in F \colon g(f,\ S^w,\ P)$.
		\end{thm}
		\begin{proof}
			\[
				\forall K \in F^2,\
				r(K_1) \subseteq d(K_2) \implies
				\exists f \in F \colon g\big(f,\ d(K_1),\ r(K_2)\big).
			\]
			\[
				\forall A \in \Omega,\
				A_1 = A_2 = A_3 \implies
				A_1 = A_3.
			\]
			\[
				d(\mathrm{fft}) = S^w.
			\]
			\[
				r(\mathrm{fft}) = \mathbb C^w.
			\]
			\[
				d(\mathrm{pitch}) = C.
			\]
			\[
				r(\mathrm{pitch}) = P.
			\]
			\[
				\mathbb C^w \subset C.
			\]
			\[
				\therefore \exists f \in F \colon g(f,\ S^w,\ P).\qedhere
			\]
		\end{proof}
\end{document}


\chapter{Traffic models}
	\section{Introduction to traffic simulators}
		One of the main branch of the traffic simulators are the so called macroscopic or hydrodynamic models. These deal with traffic as a fluid flow and they do not take individual driver actions into consideration, namely, they are based on the vehicle density.

		The other type of simulators use the microscopic or car following models. These models take individual driver behavior into consideration. So they are simulating each cars in a particular traffic situation. Two examples of these car following models are the optimal velocity model and velocity difference model.

		In this thesis the second type will be investigated since the goal is that every car should be simulated as realistic as possible which cannot be expected from the first type. Then from the experience a new model should be developed which consists the longitudinal and transversal movement models. Based on the literature review it seems that one of the most widespread microscopic model is the Intelligent Driver Model (IDM) \cite{arne1} - \cite{modified}. IDM is an excellent start for the longitudinal model.
	\section{Intelligent Driver Model} \label{sec:IDM}
		IDM is a time continuous car following model which belongs to the Optimal Velocity model family. IDM is designed to be accident-free. It can only represents longitudinal motions. The fundamental idea behind the model is that every car chooses its speed based on the car before and its individual parameters. In case when there is no car before then it can freely accelerate to its desired speed.

		IDM is defined by its acceleration function. The model is constructed by two parts. The first part represents the \textit{free acceleration} when there is no leading car or it is far away:
		\begin{equation}
			\afree=\amax\left [ 1 - \left ( \frac{\vt}{\vd} \right )^{\delta} \right ]\,,
			\label{eq:afree}
		\end{equation}
		where
		\begin{itemize}
			\item $\amax$ $\rm [m/s^2]$ is the maximum acceleration of the vehicle,
			\item $\vt$ $\rm [m/s]$ is the velocity of the vehicle at $t$,
			\item $\vd$ $\rm [m/s]$ is the desired velocity of the vehicle,
			\item $\delta$ $\rm [-]$ is the free acceleration exponent of the vehicle.
		\end{itemize}
		Equation~\eqref{eq:afree} produces zero when the current speed equals to the desired speed ($\vt=\vd$) and it reaches its maximum value when the car is not moving ($\vt=0$).

		The second part corresponds to the \textit{follower behavior} or \textit{breaking strategy} of the model:
		\begin{equation}
			\afollower=-\amax\cdot \left ( \frac{\hd}{\h} \right )^2\,,
			\label{eq:afollower}
		\end{equation}
		where
		\begin{itemize}
			\item $\hd$ $\rm [m]$ is the desired safe headway of the vehicle at $t$,
			\item $\h$ $\rm [m]$ is the current headway of the vehicle at $t$.
		\end{itemize}
		The desired safe headway is calculated from:
		\begin{equation}
			\hd=h_0 + \vt\cdot T + \frac{\vt\cdot(\vt-\vleader)}{2\sqrt{\amax\cdot\bmax}}\,,
		\end{equation}
		where $h_0$ is the bumper to bumper gap or jam distance, $T$ is the desired safety time headway, $\vleader$ is the velocity of its leader car, $\bmax$ is the maximum value of comfortable deceleration.
		The current headway at a given $t$ can be calculated from:
		\begin{equation}
		\h=\posleader-\lengthleader- x(t)
		\end{equation}
		where $x(t)$ is the position of the car along the straight road, $\posleader$ and $\lengthleader$ are the position and length of the car's leader vehicle, respectively.
		Equation~\eqref{eq:afollower} decreases with increasing own speed, increasing velocity difference and decreasing distance to the front car.
		\begin{figure}
			\centering
			\includegraphics[width=.95\textwidth]{common/idm}
			\caption{3 cases of IDM}
			\label{fig:idm}
		\end{figure}
		The sum of equations \eqref{eq:afree} and \eqref{eq:afollower} is the IDM equation which reads as follows:
		\begin{equation}
			a(t)=\afree+\afollower=\amax\left [ 1 - \left ( \frac{\vt}{\vd} \right )^{\delta} - \left ( \frac{\hd}{\h} \right )^2 \right ]\,.
			\label{eq:aidm}
		\end{equation}
		Equation~\eqref{eq:aidm} represents the longitudinal behavior mechanism of a human driven car. 3 cases of traffic situation were drawn in Figure~\ref{fig:idm} with their representative parameters.
	\section{MOBIL -- lane changing model} \label{sec:MOBIL}
		As mentioned in Section \ref{sec:IDM}, there is a need for transversal motion model of the cars, namely a lane changing model. It has not been studied nearly as exhaustive as longitudinal behaviors. However it can have great impact on the overall traffic flow so it is worth investigating. The model should be able to decide based on the local traffic conditions that changing lane is beneficial and safe to a specific driver or not. If both conditions met the model will start to change lanes.

		The first condition to satisfy is that lane changing should be safe. The model should check that how will a possible lane change effect the upstream vehicles in the target lane. MOBIL \cite{arne2} states if the deceleration of the new follower car does not exceed a given safe limit then changing lanes is safe. It can be expressed with an inequality as well:
		\begin{equation}
			\hat{a}_{n}\geq -b_{\rm safe}\,,
		\end{equation}
		where $\hat{a}_{n}$ is the new follower car's acceleration if car $c$ changes lanes and $b_{\rm safe}$ is a parameter of car $n$. The mechanism is illustrated in Figure~\ref{fig:mobil}. This criterion ensures that the model remains accident free even for edge cases.
			\begin{figure}
				\centering
				\includegraphics[width=.95\textwidth]{common/mobil}
				\caption{Based on the local traffic conditions vehicle \textit{c} is considering changing lanes to the right. Vehicle \textit{n} and \textit{o} will be the new and old followers of car \textit{c} respectively.}
				\label{fig:mobil}
			\end{figure}

			The other condition is the incentive criterion which states that a possible lane change should improve the local traffic situation around the vehicle. The base model is the following:
			\begin{equation}
				\hat{a}_{\rm c} + \hat{a}_{\rm o} + \hat{a}_{\rm n} > a_{\rm c} + a_{\rm o} + a_{\rm n}\,,
				\label{eq:mobil_first}
			\end{equation}
			where accelerations after a possible lane change are denoted with hats.
			Based on Eq.~\eqref{eq:mobil_first} a lane change should occur only if the sum of the accelerations after the lane change is greater than before. This inequality reflects the name of the model which is \textbf{m}inimizing \textbf{o}verall \textbf{b}raking \textbf{i}nduced by \textbf{l}ane change (MOBIL).

			However Eq.~\eqref{eq:mobil_first} is not as realistic as it should be. The first problem is that vehicles would change lanes even for a negligible acceleration advantage which is not the case in a realistic traffic situation. This issue can be solved with a threshold value $\Delta a_{\rm th}$. After this modification Eq.~\eqref{eq:mobil_first} would look like below:
			\begin{equation}
				\hat{a}_{\rm c} - a_{\rm c} + \hat{a}_{\rm o} - a_{\rm o} + \hat{a}_{\rm n} - a_{\rm n} > \Delta a_{\rm th}\,,
				\label{eq:mobil_with_tr}
			\end{equation}
			It can be stated that with this modification individual drivers only change lanes if the acceleration sum is significantly greater than before the lane change. The other problem with the previously discussed model is that they cannot distinguish between driving style. Driver styles can vary from complete selfish to the altruistic driver. Selfish drivers would only care about their own acceleration ($\hat{a}_{\rm c} - a_{\rm c} > \Delta a_{\rm th}$) while altruistic ones would change lanes even if that would result in a disadvantageous position for them but with that change the local traffic situation would improve sufficiently ($\hat{a}_{\rm o} - a_{\rm o} + \hat{a}_{\rm n} - a_{\rm n} > \Delta a_{\rm th}$). A $p$ politeness factor should be introduced to fix that. Including $p$ in Eq.~\eqref{eq:mobil_with_tr} results in the final form of the model:
			\begin{equation}
				\hat{a}_{\rm c} - a_{\rm c} + p(\hat{a}_{\rm o} - a_{\rm o} + \hat{a}_{\rm n} - a_{\rm n}) > \Delta a_{\rm th}\,.
				\label{eq:mobil}
			\end{equation}
			A completely selfish driver would get $p=0$ factor, while an altruistic one $p>1$. In the special case where $p=1$ Eq.~\eqref{eq:mobil} simplifies back to Eq.~\eqref{eq:mobil_with_tr}, which means a lane change is performed only if the sum of all involved vehicles' acceleration will improved at least by the threshold value.
		\section{Numerical solver}
			In Section \ref{sec:IDM} and \ref{sec:MOBIL} a vehicle behavior in traffic has been shown and modeled. The mathematical model of a driver is a second order nonlinear differential equation. There is no analytical solution, so a numerical simulation can be carried out. To be able to use one of the common numerical solvers (like Explict Euler or 4th order Runge Kutta) the second order differential equation should be transformed into a system of first order differential equation. Using the notations $v=\dot{x}$ and $a=\ddot{x}$, the governing equation \eqref{eq:aidm} can be given as:
			\begin{equation}
				\ddot{x}=\amax\left [ 1 - \left ( \frac{\dot{x}}{\vd} \right )^\delta - \left ( \frac{h_0 + \dot{x}\cdot T + \frac{\dot{x}(\dot{x}-v_{\rm lead})}{{\rm c}}}{x_{\rm lead}-L_{\rm lead} - x} \right )^2 \right ]\,.
				\label{eq:idm_num1}
			\end{equation}
			Let's say
			\begin{equation}
				\textbf{y}=
				\begin{pmatrix}
					y_1\\
					y_2
				\end{pmatrix}
				=
				\begin{pmatrix}
					x\\
					\dot{x}
				\end{pmatrix}\,,
				\label{eq:idm_num2}
			\end{equation}
			then the derivative of $\textbf{y}$ would be
			\begin{equation}
				\dot{\textbf{y}}=
				\begin{pmatrix}
					\dot{y_1}\\
					\dot{y_2}
				\end{pmatrix}
				=
				\begin{pmatrix}
					\dot{x}\\
					\ddot{x}
				\end{pmatrix}\,,
				\label{eq:idm_num3}
			\end{equation}
			From Eq.~\eqref{eq:idm_num1}, \eqref{eq:idm_num2} and \eqref{eq:idm_num3} it can be concluded that the differential equation system will be the following:
			\begin{equation}
				\dot{\textbf{y}}
				=
				\begin{pmatrix}
					f_1(y_2)\\
					f_2(y_1,y_2,x_{\rm lead},v_{\rm lead})\\
				\end{pmatrix}
				=
				\begin{pmatrix}
					y_2\\
					\amax\left [ 1 - \left ( \frac{y_2}{\vd} \right )^{\delta} - \left ( \frac{h_0 + y_2\cdot T + \frac{y_2(y_2-v_{\rm lead})}{{\rm c}}}{x_{\rm lead} - L_{\rm lead} - y_1} \right )^2 \right ]
				\end{pmatrix}.
				\label{eq:numerical_idm}
			\end{equation}


%\begin{document}
\section{Tunneling Rates}%
\label{sec:tunneling_rates}
% \subsection{Tunneling Rates}%
% \label{subsec:tunneling_rates}
%
For inference, we generate \(M\times N\) configurations (batch of \(M\) chains in
parallel, for \(N\) MH-Accept/Rejects), and drop the first \(25\%\)
percent of the data before computing observables to account for
burn-in\footnote{For computing statistics of observables, we use bootstrap
resampling.}.
%
We compute the topological charge, \(\mathcal{Q} =
\frac{1}{2\pi}\sum_{x}\mathrm{Arg}\left(\phi_{\mu\nu}(x)\right) \in
\mathbb{Z}\), with \( \mathrm{Arg}\left(\phi_{\mu\nu}(x)\right) \in \left[-\pi,
\pi\right]\) for each configuration.
%
For the \(m^{\mathrm{th}}\) chain in our batch, we define
%
\begin{align}
  \delta\mathcal{Q}_{m}(n) &\coloneqq |\mathcal{Q}{(n+1)} - \mathcal{Q}{(n)}|\\
  \langle\delta\mathcal{Q}_{m}\rangle &\coloneqq
  \frac{1}{N}\sum_{n=0}\delta\mathcal{Q}_{m}(n).
\end{align}
%
We can then compute the average tunneling rate over all chains (i.e.\@ the
number of tunneling events per step) as
%
\begin{equation}
  \langle \delta\mathcal{Q}\rangle%
  \coloneqq \frac{1}{M}\sum_{m=1}^{M}\langle\delta\mathcal{Q}_{m}\rangle
  =\frac{1}{M}\sum_{m=1}^{M}\left[\frac{1}{N}\sum_{n=0}^{N} \delta\mathcal{Q}_{m}(n)\right]
\end{equation}
%

\begin{figure}[htpb]
  \centering
  \includegraphics[width=\textwidth]{tunneling_rates/dq_vs_beta}
  \caption{Comparison of the tunneling rates,
  \(\langle\delta\mathcal{Q}\rangle\) for HMC and L2HMC}
\end{figure}

% \begin{figure}[htpb]
%   \centering
%   \begin{subfigure}{0.48\textwidth}
%     % \input{/Users/saforem2/l2hmc-qcd/doc/figures/updates_2020_10_13/dq_lf10_beta2.tex}
%     \includegraphics[width=\textwidth]{updates_2020_10_13/dq_lf10_beta2.pdf}
%   \end{subfigure}
%   \begin{subfigure}{0.48\textwidth}
%     % \input{/Users/saforem2/l2hmc-qcd/doc/figures/updates_2020_10_13/dq_lf10_beta3.tex}
%     % \input{../figures/updates_2020_10_13/dq_lf10_beta3.tex}
%     \includegraphics[width=\textwidth]{updates_2020_10_13/dq_lf10_beta3.pdf}
%   \end{subfigure}
%   \begin{subfigure}{0.48\textwidth}
%     % \input{/Users/saforem2/l2hmc-qcd/doc/figures/updates_2020_10_13/dq_lf10_beta3.tex}
%     % \input{../figures/updates_2020_10_13/dq_lf10_beta4.tex}
%     \includegraphics[width=\textwidth]{updates_2020_10_13/dq_lf10_beta4.pdf}
%   \end{subfigure}
%   \begin{subfigure}{0.48\textwidth}
%     % \input{/Users/saforem2/l2hmc-qcd/doc/figures/updates_2020_10_13/dq_lf10_beta5.tex}
%     % \input{../figures/updates_2020_10_13/dq_lf10_beta5.tex}
%     \includegraphics[width=\textwidth]{updates_2020_10_13/dq_lf10_beta5.pdf}
%   \end{subfigure}
%   % \includegraphics[width=\textwidth]{updates_2020_10_13/tunneling_rates_lf10_row1.pdf}
%   \caption{Comparison of the tunneling rates,
%   \(\langle\delta\mathcal{Q}\rangle\) for HMC and L2HMC}
% \end{figure}

% \input{/Users/saforem2/l2hmc-qcd/logs/tunneling_rates/2020-10-16/figs/dq_lf10_stats_beta_2020-10-16-141354_tikz.tex}
%\end{document}


This module implements an adapted version of the \emph{cylindrical algebraic decomposition} (CAD) for a conjunction of constraints as described in \cite{Article_Collins_75}.
It extends the original algorithm to be SMT compliant and implements the ideas from \cite{Article_Loup_TubeCAD}.

The CAD method consists of two basic routines: the projection (or elimination) of polynomials and the lifting (or construction) of samples.
The projection transforms a set of polynomials over a set of variables to a new set of polynomials that do not contain some of the variables.
The lifting starts with a sample point of degree $k$ and constructs a sample point of degree $k+1$ using the polynomial sets from the projection.
Both routines work in an incremental fashion: polynomials are only projected if needed and the construction is performed as a depth-first search.

\paragraph{Efficiency}
The worst case complexity of this algorithm is doubly exponential in the number of variables, the base being the sum of the number of polynomials and the maximum degree of any polynomial.
This is due to an quadratic increase of polynomials in each projection step and a number of possible sample points that grows with the number of polynomials.

The practical performance heavily depends on the number and degree of polynomials created during the elimination.
It benefits greatly if the real roots of the polynomials are rational, as irrational root operation may take quite some time.