%!TEX root = ../thesis.tex
%*******************************************************************************
%****************************** Fifth Chapter **********************************
%*******************************************************************************

\chapter{Discussion}
\label{chapter6}

\section{Summary and contributions}
In this work, we provided an overview of common quantum many-body methods, with a special focus on Monte Carlo and Machine Learning methods, as well as an introduction to stochastic processes. We then derived a novel loss function termed the variance $\log \text{RN}$ loss with fixed endpoints, which when optimised yields a trajectory distribution of a stoquastic lattice model. This new method is closely related to previous work of Barr et al.~\cite{barr2020quantum}, which uses a similar loss function but for continuous systems where there is no need for fixed endpoint trajectories. The method is also closely related to work of Gispen et al.~\cite{gispen2020ground}, which is based on much of the same theoretical foundation, but uses reinforcement learning to find ground states of lattice models. The main disadvantage of our method over standard methods is its limited applicability. It can only be applied to stoquastic Hamiltonians, and the batch generation process must be tailored to the system at hand. The main advantage of our method is at inference time, where it is much more efficient at sampling from the ground state than vanilla Metropolis-Hastings as no transitions are ever rejected.

Based on this, the main contributions of this thesis are twofold:

\begin{enumerate}
	\item We provide a clear and thorough introduction to the many very diverse topics needed to understand, derive, and implement the $\log {RN}$ loss.
	\item We implement the $\log {RN}$ loss and analyse its properties on the TFIM in both one and two dimensions. Most notably, we show that while the loss has nice convergence properties in theory, the restriction to \emph{fixed endpoint} trajectories is very impractical. Since such trajectories cannot be sampled, they need to be constructed in some way. We propose three batch generation methods for the TFIM, identify a family of Hamiltonians which pose problems for the $\log{\text{RN}}$ loss, and discuss their failure modes.
\end{enumerate}

\section{Direction for further work}
As with any scientific work, this thesis leaves many questions unanswered and many more new questions uncovered. Future work should focus on:

\begin{enumerate}
	\item \textbf{Questions regarding the loss and trajectories:}
	\begin{itemize}
		\item Answering the most pressing question the thesis leaves unanswered, why does the \emph{construct} method not work?

		\item Is there a batch construction method that will behave nicely for TFIM like models?

		\item How do we construct batches in models where the actions are not independent (e.g. XY), and we cannot just permute them. Can we devise a general way to construct fixed endpoint trajectories under certain constraints?

		\item More general questions regarding the generalisation properties of the loss. Since we artificially construct trajectories to feed into the loss, does this hinder its learning? Can the loss overfit to certain trajectories? Do trajectories that are very \emph{instructive} and expedite the training process exist? Can we specifically engineer trajectories to facilitate learning?

	\end{itemize}

	\item \textbf{Technical improvements:}
	\begin{itemize}
		\item Improve the implementation of the gCNN and conduct more extensive tests.
		\item Reduce the memory requirement of the method to facilitate larger computations.
		\item Can our method be used effectively in tandem with some other standard method?
		\item Further exploration of the effects of equivariance on learning.
		\item Randomly choose the time for each epoch, perhaps from the Erlang distribution. Does this stabilise learning?
	\end{itemize}

	\item \textbf{Theoretical considerations:}
	\begin{itemize}
		\item How can we extend the method to a broader range of Hamiltonians? Perhaps using the fixed-node Feynman-Kac formula?~\cite{caffarel2015talking}.
		\item Does a lattice model with an analytical solution for the rates exist?
	\end{itemize}

\end{enumerate}


% Autogenerated translation of about.md by Texpad
% To stop this file being overwritten during the typeset process, please move or remove this header

\documentclass[12pt]{book}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,left=.5in,right=.5in,top=.3in,bottom=0.3in]{geometry}
\setlength\parindent{0pt}
\setlength{\parskip}{\baselineskip}
\renewcommand*\familydefault{\sfdefault}
\usepackage{hyperref}
\pagestyle{plain}
\begin{document}
\Large

\hrule
permalink: /
title: "Bogdan Mazoure - Math \& Stats graduate student @ McGill University"
excerpt: "About me"
author\emph{profile: true
redirect}from:
  - /about/

\section*{  - /about.html}

\chapter*{About me}

I am currently a PhD student at the Montreal Institute for Learning Algorithms (MILA) and McGill University, co-supervised by Devon Hjelm and Doina Precup. My research interests include deep reinforcement learning, probabilistic modeling, variational inference and representation learning.

I have completed my Master's in Statistics at McGill University under the supervision of Prof. \href{http://www.math.mcgill.ca/neslehova/}{Johanna Neslehova}. My thesis focuses on reconstructing graphical models from discrete data with variational inference and multiarmed bandits. It can be found here: \href{https://bmazoure.github.io/files/thesis_Msc_2018.pdf}{link}.

I was also a research intern at Nuance during the summer of 2018 where I collaborated with Dr. \href{https://scholar.google.ca/citations?user=KRPMXqYAAAAJ&hl=en}{Atta Norouzian}. My work there focused on modeling acoustic signals such as speech with deep neural architectures.

Previously, I obtained a Bachelor's in Computer Science and Statistics in 2017 from McGill University.

\chapter*{Research interests}

\begin{itemize}
\item Deep and distributional reinforcement learning;
\item Multivariate statistics;
\item Parametric and Non-parametric Bayesian methods (Gaussian processes and variational inference);
\item Probabilistic graphical models;
\item Uncertainty representation in neural networks;
\item Generative models (auto-encoding variational Bayes and generative nets);
\item Dependence modeling for discrete marginals.
\end{itemize}

\end{document}


\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[top=3cm,left=2.5cm,right=2.5cm,bottom=3cm]{geometry}
\usepackage{listings}
\usepackage{hyperref}

\title{\vspace{-5ex}lat2eps v2.0}
\author{}
\date{\vspace{-5ex}}

\begin{document}

\maketitle

\section{Introduction}

lat2eps is a small command-line utility for Linux, Unix and macOS that generates graphics in the Encapsulated PostScript (EPS) format, depicting the contents of square/rectangular lattices.
\bigbreak

lat2eps reads the lattice data from the standard input and outputs the EPS data to the standard output. The input file should be a simple text file where data lines contain at least 3 integer fields separated by spaces, where the first two fields are the horizontal and vertical coordinates of the lattice site, and the third is the site value. Lines beginning with the \# character are considered comments and ignored, unless they contain embedded internal commands, described below.
\bigbreak

There are 256 different color indexes, ranging from 0 to 255, which can be used to draw lattice sites of different values. Site values are mapped to color indexes according to a simple rule: $index = value \bmod 256$. Negative values are first converted to unsigned values (e.g., -1 is converted to 255, -2 to 254, and so on). Note: a palette of only 16 different colors is initially defined, repeated over the 256 possible indexes. Thus, if more than 16 colors are needed, they must be redefined, as described below.
\bigbreak

\section{Installation}

lat2eps is open source software supplied in source code form. It can be built with the \textit{make} command, which will generate the \texttt{lat2eps} executable, which can be manually copied to a directory within the user's path, like, e.g., \texttt{/usr/local/bin}. The \textit{gcc} or \textit{clang} compiler must be installed in the system for the build process to succeed.
\bigbreak

\section{Usage}

The basic command usage is:
\bigbreak

\texttt{lat2eps  xoff yoff width height border scale  <input.dat  >output.eps}
\bigbreak

Where \textit{xoff}, \textit{yoff}, \textit{width} and \textit{height} define offsets and dimensions (in sites) of a region within the lattice, which will be used to generate the EPS output.
\bigbreak

\textit{border} is the width of a black border generated around the lattice graphic, or 0 for generating a borderless graphic.
\bigbreak

\textit{scale} is a positive integer value defining the scale used in the conversion of the lattice data to EPS. E.g., when the scale is set to 3, each lattice site will generate a 3x3 pixel square in the EPS output.
\bigbreak

\section{Embedded commands}
\bigbreak

Embedded commands can be placed within a lattice data file passed as input to lat2eps, inside comment lines, which begin with the \# character (the commands must immediately follow the \# character). Each embedded command can contain multiple parameters. The commands and their parameters can be separated by spaces or commas. The supported embedded commands are:
\bigbreak\bigbreak

\texttt{TXT <X>, <Y>, <AX>, <AY>, <ANGLE>, <SIZE>, <COLOR>, <TEXT>}
\bigbreak

The TXT embedded command is used to generate text entries over the lattice graphic. It can be used to generate text lines to appear in the graphic as they are, or tags that can be later replaced by LaTeX text using PSFrag. The parameters are the following:

\begin{itemize}
  \item \textit{X} is the horizontal coordinate where the text will be positioned. 0 is the leftmost coordinate, while the maximum horizontal coordinate is defined by the lattice width.
  \item \textit{Y} is the vertical coordinate where the text will be positioned. 0 is the topmost coordinate, while the maximum vertical coordinate is defined by the lattice height.
  \item \textit{AX} defines the horizontal alignment. 0 for left-aligning the text relative to the X coordinate, 0.5 for centering it on the X coordinate, 1 for right-aligning it, etc.
  \item \textit{AY} defines the vertical alignment. 0 for placing the top of the text on the Y coordinate, 0.5 for centering it on the Y coordinate, 1 for placing the bottom of the text on the Y coordinate, etc.
  \item \textit{ANGLE} defines the angle to rotate the text, in degrees (0 for horizontal).
  \item \textit{SIZE} defines the font size.
  \item \textit{COLOR} defines the color index used to draw the text.
  \item \textit{TEXT} is the text to be generated. It can contain any characters including spaces and commas; parentheses characters, however, must be escaped with backslashes.
\end{itemize}
\bigbreak\bigbreak

\texttt{PAL <COLOR\_0\_PALETTE>, <COLOR\_1\_PALETTE>, <COLOR\_2\_PALETTE>, ...}
\bigbreak

The PAL embedded command can be used to redefine the color palette. It can receive a variable number of parameters. The first parameter will redefine the color index 0, the second will redefine color index 1, and so on. Each parameter is a hexadecimal number in the RRGGBB format (i.e., the first byte defines the red component for the color index, from 00 to FF, while the second byte defines the green component, and the third byte defines the blue component).
\bigbreak\bigbreak

\texttt{COL <COLOR\_INDEX>, <COLOR\_PALETTE>}
\bigbreak

The COL embedded command can be used to redefine a single color index. It receives 2 arguments. The first is the color index, from 0 to 255, and the second is a hexadecimal color definition in the same format described for the PAL command.
\bigbreak\bigbreak

Sample lattice data file with embedded commands:
\bigbreak

\begin{lstlisting}[frame=single]
# Embedded commands here:
#TXT 128, 250, 0.5, 1, 0, 20, 1, X
#TXT 6, 128, 0.5, 0, 90, 20, 6, Y
#TXT 128, 128, 0.5, 1, 45, 20, 5, lat2eps test
#PAL 555577, FFFFFF, 334455, 66778A, 4433ff
#COL 2, 00ffff
#COL 5, 123456

# Lattice data:
0 0 2
1 0 1
2 0 1
3 0 2
4 0 2
5 0 3
\end{lstlisting}

\bigbreak

Embedded commands can also be supplied through the command line, as optional parameters to the lat2eps command, after the required parameters. In this case, they should not be preceded by the \# character, and the embedded commands and their parameters must be separated by commas only (or the spaces escaped), so that each embedded command together with its parameters are recognized by the shell as a single parameter to the lat2eps command. For instance, to generate text and redefine color number 6:
\bigbreak

\texttt{lat2eps 0 0 320 320 1 1 TXT,25,25,0,0,0,20,6,Test COL,6,2245FF <lat.dat >lat.eps}
\bigbreak

\section{Default configuration}

Default configuration parameters can be supplied through a file named \texttt{.lat2epsrc}, placed within the user's home directory. This file can contain embedded commands, exactly in the same way as used in lattice data files, which can be used, for instance, to define a custom color palette to be used by default for the lattice graphics generated by the user.
\bigbreak

The color palette optionally defined in the \texttt{.lat2epsrc} file redefines the initial lat2eps color definition. Afterwards, the lattice data file is processed, which may contain embedded commands to further redefine the colors. After the lattice data is processed, embedded commands supplied through the lat2eps command line are processed, which may again redefine the colors.
\bigbreak

\section{License}

lat2eps v2.0 is open source software copyrighted by André R. de la Rocha and licensed under the Apache License Version 2.0. A copy of the license can be obtained at: \url{http://www.apache.org/licenses/LICENSE-2.0}

\end{document}


\section{Source code}
\subsection{Non-fixed Population Wright-Morain dynamics}
I created a public github repository to store the source code (c++):
\url{https://github.com/eMaerthin/non-fixed-population-dynamics}

\subsection{Data-driven null hypothesis verification pipeline}
TODO: Short description required here

\url{https://github.com/eMaerthin/microevolution-lang-phones}

\subsection{Voter-Local Majority Continuous Time model}
TODO: Code needs to be shipped into my personal github account


\par
\section{Data Structure}
\label{section:PatchAndGoInfo:dataStructure}
\par
\par
The {\tt PatchAndGoInfo} structure has five fields.
\begin{itemize}
\item
{\tt int strategy} : type of patch-and-go strategy
\begin{itemize}
\item {\tt 1} --- used with optimization matrices,
if $|A_{i,i}| \le \mbox{\tt toosmall}$ then set
$A_{i,i} = 1$ and $L_{j,i} = 0$ for $j > i$.
\item {\tt 2} --- used with structural analysis matrices,
if $|A_{i,i}| \le \mbox{\tt fudge}$ then
set $A_{i,i} = \mbox{\tt fudge} \cdot
\max\{1, \max_{j>i}\{ |A_{i,j}|, |A_{j,i}| \} \}$
\end{itemize}
\item
{\tt double toosmall} : cutoff for diagonal entry magnitude
\item
{\tt double fudge} : pertubation multiplier for modification
\item
{\tt IV *fudgeIV} : vector to collect locations of perturbations,
may be {\tt NULL}.
\item
{\tt DV *fudgeDV} : vector to collect perturbations,
may be {\tt NULL}.
\end{itemize}


    \filetitle{!all\_but}{Inverse list of log-linearised variables}{modellang/allbut}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
!log_variables
    !all_but
    VariableName, VariableName,
    VariableName, ...
\end{verbatim}

\paragraph{Description}\label{description}

See help on \href{modellang/logvariables}{\texttt{!log\_variables}}.


\subsection{The Euclidan group}


This manual illustrates the functionalities of  the IRST Language  Modeling (LM)  toolkit ({\IRSTLM}). It  should
put you quickly  in  the condition of:
\begin{itemize}
\item extracting the dictionary from a corpus
\item extracting n-gram statistics from it
\item estimating n-gram LMs using different smoothing criteria
\item saving a LM into several textual and binary file
\item adapting a LM on task-specific data
\item estimating and handling gigantic LMs
\item pruning a LM
\item reducing LM size through quantization
\item querying a LM through a command or script
\end{itemize}

\noindent
{\IRSTLM} features very efficient algorithms and data structures suitable to estimate, store, and access very  large LMs.

\noindent
{\IRSTLM} provides adaptation methods to effectively adapt generic LM to specific task when only little task-related data are available.

\noindent
{\IRSTLM} provides standalone programs for all its functionalities, as well as library for its exploitation in other softwares, like for instance speech recognizers, machine translation decoders, and POS taggers.

\noindent
{\IRSTLM} has been integrated into a popular open source SMT decoder  called {\tt Moses}\footnote{http://www.statmt.org/moses/}, and is compatible with LMs created with other tools, such as the SRILM Tooolkit\footnote{http://www.speech.sri.com/projects/srilm}.

\paragraph{Acknowledgments.}Users of this toolkit  might cite in their publications:
\begin{quote}
M. Federico,  N. Bertoldi,  M. Cettolo, {\em IRSTLM: an Open Source Toolkit for Handling Large Scale Language Models}, Proceedings of Interspeech, Brisbane, Australia, pp. 1618-1621, 2008.
\end{quote}

\noindent
References to introductory material on $n$-gram LMs are given in Appendix~\ref{sec:ReferenceMaterial}.


\documentclass{article}

\usepackage{arxiv}

\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc}    % use 8-bit T1 fonts
\usepackage{hyperref}       % hyperlinks
\usepackage{url}            % simple URL typesetting
\usepackage{booktabs}       % professional-quality tables
\usepackage{amsfonts}       % blackboard math symbols
\usepackage{nicefrac}       % compact symbols for 1/2, etc.
\usepackage{microtype}      % microtypography
\usepackage{lipsum}		% Can be removed after putting your text content
\usepackage{amssymb,amsmath}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{verbatim}
%\usepackage{apacite}

\title{Decentralised, privacy-preserving Bayesian inference for mobile phone contact tracing}

%\date{September 9, 1985}	% Here you can change the date presented in the paper title
%\date{} 					% Or removing it

\author{
  Daniel Tang\\
  Leeds Institute for Data Analytics\thanks{This project has received funding from the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No. 757455)}\\
  University of Leeds\\
  Leeds, UK\\
  \texttt{D.Tang@leeds.ac.uk} \\
  %% examples of more authors
  %% \AND
  %% Coauthor \\
  %% Affiliation \\
  %% Address \\
}

\begin{document}
\maketitle

\begin{abstract}
Many countries are currently gearing up to use smart-phone apps to perform contact tracing as part of the effort to manage the COVID-19 pandemic and prevent resurgences of the disease after the initial outbreak. With the announcement of the Apple/Google partnership to introduce contact-tracing functionality to iOS and Android\cite{applegoogle}, it seems likely that this will be adopted in many countries.

An important part of the functionality of the app will be to decide whether a person should be advised to self-isolate, be tested or end isolation. However, the privacy preserving nature of the Apple/Google contact tracing algorithm means that centralised curation of these decisions is not possible so each phone must use its own ``risk model'' to inform decisions. Ideally, the risk model should use Bayesian inference to decide the best course of action given the test results of the user and those of other users. Here we present a decentralised algorithm that estimates the Bayesian posterior probability of viral transmission events and evaluates when a user should be notified, tested or released from isolation while preserving user privacy. The algorithm also allows the disease models on the phones to learn from everyone's contact-tracing data and will allow Epidemiologists to better understand the dynamics of the disease.

The algorithm is a message passing algorithm, based on belief propagation, so each smart-phone can be used to execute a small part of the algorithm without releasing any sensitive information. In this way, the network of all participating smart-phones forms a distributed computation device that performs Bayesian inference, informs each user when they should start/end isolation or be tested and learns about the disease from user's data.
\end{abstract}

% keywords can be removed
\keywords{COVID-19, SARS-CoV-2, contact tracing, Bayesian inference, belief propagation}

\section{Introduction: the need for Bayesian inference}

While much has been said about how to use smart-phones to inform people that they have been in close proximity to an infected person\cite{dp3t}\cite{applegoogle}\cite{pepppt}, relatively little has been said about how to evaluate the best course of action given information about one's own test results and those of one's contacts.

Since clinical tests for SARS-CoV-2 have been found to have quite high rates of false-negatives\cite{fang2020sensitivity}, accurately diagnosing whether someone is infected isn't as easy as just testing them. However, by taking into account symptoms and test results of a user \textbf{and} of the user's close contacts we can potentially increase the sensitivity of the diagnosis. For example, suppose a contact of a confirmed case is symptomatic but tests negative, yet on the next day a contact of his independently becomes symptomatic and tests positive. If the newly confirmed case was in contact only with the negative case around the inferred time of infection, we may have enough information to deem the negative test a false-negative and contact trace/isolate them in any case.

Also, there is evidence that there is a high proportion of asymptomatic transmission of SARS-CoV-2\cite{lavezzo2020suppression}. This means that it is important to identify asymptomatic carriers. So, if someone is confirmed infected, it is important to trace who they caught the disease from, as well as who they may have passed the disease on to, so that a potential asymptomatic carrier can be identified and their contacts traced. For example, if two people become symptomatic and test positive, we know that each of them must have been infected a few days before their respective symptoms began. Each person is likely to have had a number of contacts in that window of time but if they have one contact in common then it becomes much more probable that the common contact was the original source of the infection. If it turns out the suspected source was symptomatic around 5 days ago (but opted not to be tested) then this evidence may be enough to immediately trace their contacts to identify other possible infectees (it would be less important to isolate the original source at this point as they may be less infectious at this point. However, if that person had a tendency to have a very large number of contacts a day and the timing meant there was still a chance of residual infectiousness, it may be deemed prudent to isolate for a number of days).

Finally, if a person is traced as a contact of a confirmed case, but the contact occurred a few hours ago, there is little point in testing that person immediately as the test is unlikely to be positive even if the person will go on to develop the disease. There is also no need for the person to immediately isolate as they are probably not infectious at this point. However, at some time in the near future we will want to test and possibly isolate that person, but when is the optimal time to do this?

Doing this kind of inference automatically, while maintaining the privacy of a user's close contacts, requires a reasonably sophisticated inference algorithm. Simply alerting close contacts of confirmed cases is not enough. Here we present an algorithm that uses a modification of the belief propagation algorithm\cite{pearl2014probabilistic} to do Bayesian inference in order to decide on a testing schedule and isolation timings that minimise expected overall cost. The algorithm also allows the disease model to learn from user's data and allows Epidemiologists to gain information about the dynamics of the disease.

\section{Description of the problem}
%===================================

Suppose mobile-phone contact tracing is in operation using the Apple/Google contact tracing specification\cite{applegoogle}. Each day, enabled phones randomly choose a ``daily exposure key''. When enabled phones come close they exchange proximity IDs (PIDs) which are numbers derived from their daily exposure key. The phones keep a log of the exchanged PIDs along with the time of the contact and their own daily exposure keys. If a person is deemed at risk, a subset of their daily exposure keys are published on a public server along with a payload containing some data. Each day, everyone's phone checks for newly published exposure keys and checks them against the PIDs of their close contacts. If there is a match, the phone learns the user has been in close proximity to a person at risk.

The problem we consider here is how to calculate whether and when to notify the user to self-isolate, perform tests and release from isolation, while maintaining the privacy of a user's close contacts. In addition, we would like to use user's contact and test result data to update a set of epidemiological parameters about the natural history of the disease, again without compromising the privacy of the users contacts.

\section{Expressing the joint probability over transmission events}
%==============================================================================

If two people, A and B, come within close proximity and broadcast PIDs $a$ and $b$ respectively, then there is a chance $P(\tau_{a \rightarrow b})$ that A will transmit the virus to B and a chance $P(\tau_{b \rightarrow a})$ that B will transmit the virus to A. Our first aim is to calculate the joint probability of all transmission events and all the tests/observations that have been done on all people to date. When we talk about transmission, we mean the transfer of viruses from one person to another such that if the other person was susceptible, they would become infected. Transmission to an already infected person is still a transmission event, but has no effect.

The binary random variables $\tau_{a\rightarrow b}$ take values either 1 or 0. A value of 1 denotes the event that a transmission occurred from A to B, while a value of 0 denotes the event that A and B had a close contact but no transmission occurred from A to B.

When a contact first occurs, the user has no information about the other participant so the probability of transmission from others is set to a prior probability. Up-to-date regional prior probabilities can be downloaded from publicly available servers and the phone can estimate its current region from recent events such as the name/ID of the most recently connected cell tower (this information will always stay local on the phone).

\subsection{The disease model}
%===================================================

Consider the phone of person A at time $t$ with a log of contacts $C(t) = \left< t_{1},a_1,b_1 \right> ... \left< t_{n},a_n,b_n \right>$, where $t_i$ is the time of the contact relative to the start of the log and $a_i$ and $b_i$ are the exchanged PIDs.

Define the \textit{first-exposure time} to be the earliest time that A was exposed to the virus and let $\epsilon(t)$ be the event that the first exposure is at time $t$. We assume that there is a continuous and slowly changing risk of exposure from the environment (e.g. from surfaces or close contacts that were missed for any reason) at a rate $\rho$. $\rho$ can be calculated from the local prevalence of the disease, the uptake of the app and the rate of contacts of the user. Given this, the probability density of first exposure since the start of the log is
\begin{equation}
P\left(\epsilon(t)|C(t)\right) = \left(\rho + \sum_{i=1}^n \delta(t - t_i)\tau_{b_i\rightarrow a_i} \prod_{j<i}(1-\tau_{b_j\rightarrow a_j})\right) e^{-\rho t}
\label{firstExposure}
\end{equation}
where $\delta$ is the Dirac delta function.

Define the \textit{disease onset time} to be the earliest time that an infected person has a non-zero probability of transmitting the disease and let $\omega(t)$ be the event that disease onset occurs at time $t$. If we assume that there was no infection at the start of the contact log then
\begin{equation}
P(\omega(t)|C(t)) = \int_0^{t} P(\omega(t)|\epsilon(t_\epsilon))P(\epsilon(t_\epsilon)|C(t)) dt_\epsilon
\end{equation}
where $P(\omega(t)|\epsilon(t_\epsilon))$ represents the incubation time of the disease. This could be an analytical distribution such as a Weibull distribution $P_w(t-t_\epsilon)$, or some more complex model.

After disease onset, the amount of viral shedding will vary with time. Let $\iota(t) = \rho_i$ be the event that a person is shedding viruses at a rate $\rho_i$ at time $t$, then the probability density of viral shedding is
\begin{equation}
P(\iota(t) = \rho_i|C(t),\alpha) = \int_0^t \delta(\iota(t|\omega(t_\omega),\alpha)-\rho_i)P(\omega(t_\omega)|C(t)) dt_\omega
\end{equation}
where $\iota(t|\omega(t_\omega),\alpha)$ represents the clinical course of the disease and $\alpha$ is a binary random variable indicating whether the person is an asymptomatic carrier (in which case, their infectiousness curve may be different from symptomatics). This could be a Beta distribution $P_\beta(t-t_\omega)$ or something more complex. Asymptomatics may have a completely different distribution, or may have the same distribution multiplied by a constant $\iota_\alpha$.

Given a person's infectiousness, we assume that a close contact is a Bernoulli draw, based on that person's infectiousness.
\begin{equation}
P(\tau|\iota(t)) = B(\tau, \iota(t))
\end{equation}
If detailed information about the contact is logged (e.g. duration and proximity), the Bernoulli distribution could be replaced with a more sophisticated model of the contact to get a more accurate probability of transmission (e.g. \cite{sattler2020risk}). Here we will assume a Bernoulli distribution to demonstrate the algorithm, but the same development could be applied to a more complex transmission model.

Suppose we have a number of tests $\xi_1...\xi_n$ that give us information about whether a person is infected with SARS-CoV-2. The characteristics of the $n^{th}$ test are defined by it's specificity, $P(\xi^-_n|\bar{i})$, which gives the probability that a person will test negative on test $n$ given that they are not infected, and it's sensitivity $P(\xi^+_n(t)|\omega(t_\omega),\alpha)$ which gives the probability that a person tests positive on test $n$ at time $t$ given that they had disease onset at time $t_\omega$ and whether they are asymptomatic carriers.

Tests may take the form of clinical tests (e.g. PCR tests, antigen tests or antibody tests) but may also be simple observations of the presence or absence of symptoms (e.g. fever, persistent-cough or loss of taste).

The conditional probability of a positive test result is given by
\[
P(\xi^+_n(t)|C(t),\alpha) = \int_0^t P(\xi^+_n(t)|\omega(t_\omega),\alpha)P(\omega(t_\omega)|C(t)) dt_\omega + \left(1-\int_0^tP(\omega(t_\omega)|C(t)) dt_\omega\right)(1-P(\xi^-_n|\bar{i}))
\]

\subsection{The joint probabilities}
%====================================

The above conditional probabilities for each individual can be put together to create the joint probability over all people.

The probability that a contact with a person at time $t$ ends in a transmission event from that person is independent of other variables given the transmission events to that person before $t$, so we can imagine building up the joint from conditionals starting with the earliest contact and moving one at a time to the latest. If the $i^{th}$ user has a log of contacts $C_i$ and we let $\mathcal{C} = \cup_{i=1}^N C_i$ be the set of all close contacts in the logs of all people, and $\mathcal{T}$ be the set of all transmission events, it can be seen that the joint probability is given by
\begin{equation}
P(\mathcal{T},\theta) =
P(\theta)
\prod_{\left<t,a,b\right> \in \mathcal{C}}
P\left(\tau_{a\rightarrow b}|
  \left\{ \tau_{b' \rightarrow a} :
    \left<t',b',a\right> \in \mathcal{C} \wedge
    t' < t
  \right\},\theta
\right)
\label{allJoint}
\end{equation}
where $\theta$ is the set of epidemiological parameters that specify, for example, the incubation period distribution and the course of viral shedding, and $P(\theta)$ are our prior beliefs in those parameter values based on current scientific understanding.

We can group the terms in equation \ref{allJoint} by onward transmission from each user, giving

\[
P(\mathcal{T},\theta) =
P(\theta)\prod_{i}
\prod_{\left<t,a,b\right> \in C_i}
P\left(\tau_{a\rightarrow b}|
  \left\{ \tau_{b'\rightarrow a'}:
    \left<t',a',b'\right> \in C_i \wedge
    t' < t
  \right\},\theta
\right)
\]

If we note that the probability of a positive/negative test result also depends only on the user's contacts prior to the test and whether the user is an asymptomatic carrier, then we can also add test results to the joint. If $T_i$ is the set of tests taken by user $i$,  and $\alpha_i$ indicates whether they are asymptomatic carriers, the joint becomes
\begin{equation}
P(\mathcal{T}, T_{1..N}, \alpha_{1..N},\theta) =
P(\theta)
\prod_{i} P(\alpha_i)
\prod_{\left<t,a,b\right> \in C_i}
P\left(\tau_{a\rightarrow b}|\mathcal{L}(C_i,t),\alpha_i, \theta \right)
\prod_{\xi_{n}(t) \in T_i}
P(\xi_{n}(t)|\mathcal{L}(C_i,t),\alpha_i)
\label{joint}
\end{equation}
where $P(\alpha)$ is the prior probability of being an asymptomatic carrier, and
\[
\mathcal{L}(C,t) =   \left\{ \tau_{b\rightarrow a}:\left<t',a,b\right> \in C \wedge t' < t \right\}
\]
This joint can be expanded to include each user's infectiousness at the time of each contact. For ease of notation, we imagine an ``augmented contact log'' which  includes the infectiousness in the Tuple of each contact so $\left<t,a,b,\iota\right> \in C_i$ is a contact at time $t$ where the broadcaster of PID $a$ had infectiousness $\iota$. So, the joint now looks like this
\begin{equation}
P(\mathcal{T},\mathcal{I}, T_{1..N}, \alpha_{1..N},\theta) =
P(\theta)
\prod_{i} P(\alpha_i)
\prod_{\left< t,a,b, \iota \right> \in C_i}
B(\tau_{a\rightarrow b}|\iota)
P\left(\iota|\mathcal{L}(C_i,t),\alpha_i,\theta \right)
\prod_{\xi_{n}(t) \in T_i}
P(\xi_{n}(t)|\mathcal{L}(C_i,t),\alpha_i)
\label{ijoint}
\end{equation}
where $\mathcal{I}$ is the set of all infectiousnesses.

\section{Calculating posterior marginal probabilities of transmission events}
%============================================================================

\begin{figure}
\begin{center}
\includegraphics[width=10cm]{clusterGraph.pdf}
\end{center}
\caption{Layout of cluster graph for two phones that have exchanged PIDs}
\label{ClusterGraph}
\end{figure}

We can now calculate the posterior marginal probabilities of all transmission events, given all the test results. We do this by embedding the joint in a cluster graph and performing belief propagation\cite{pearl2014probabilistic}\cite{koller2009probabilistic}. Figure \ref{ClusterGraph} shows the layout of the cluster graph for two phones that have exchanged PIDs. Each phone, $i$, has authority over a cluster that represents the disease model of the user
\begin{equation}
\Phi_i(\iota_{1..j},\tau_{1..j}, \theta) =
\sum_{\alpha_i}P(\alpha_i)
\prod_{\left< t,a,b, \iota_{a\rightarrow b} \right> \in C_i}
P\left(\iota_{a\rightarrow b}|\mathcal{L}(C_i,t),\alpha_i, \theta \right)
\prod_{\xi_{n}(t) \in T_i}
P(\xi_{n}(t)|\mathcal{L}(C_i,t),\alpha_i)
\label{ijoint}
\end{equation}
where $\iota_{1..j} = \left\{\iota_{a\rightarrow b}:\left< t,a,b, \iota \right> \in C_i\right\}$ and $\tau_{1..j} = \left\{\tau_{b\rightarrow a}:\left< t,a,b, \iota \right> \in C_i\right\}$.

Each phone also has authority over one Bernoulli cluster for each onward transmission event from the user
\begin{equation}
\left\{ \Phi_{B}(\tau_{a\rightarrow b},\iota_{a\rightarrow b}) = B(\tau_{a\rightarrow b}|\iota_{a\rightarrow b}) : \left<t,a,b,\iota\right> \in C_i \right\}
\end{equation}

Finally, there is a cluster containing the epidemiological model parameters which is held on a central server, from which all phones can obtain an up-to-date posterior distribution of the disease model parameters.

By splitting the joint into clusters in this way, we end up with a Bethe cluster graph which has good properties for performing belief propagation\cite{koller2009probabilistic}, so we would expect belief propagation to perform well on this graph both in terms of the accuracy of the results and the number of messages passed.

Given the cluster graph, belief propagation calculates the marginal probability of each cluster. The marginals can be conditioned on the results of all tests by simply setting the values of each test when calculating the messages to pass.

\subsection{Passing of messages}
%===============================

We now describe how belief propagation can be achieved on the network of mobile phones, and the parameter server, without the need to expose any sensitive information.

Consider the messages sent from the $i^{th}$ phone. There are three types of message that need to be sent: ``forward'' messages from the phone's Bernoulli clusters to the $\Phi_j$ clusters of other phones, ``backward'' messages from the phone's $\Phi_i$ cluster to the Bernoulli clusters on other phones and ``epidemiological'' messages giving the parameter server information about the nature of the disease. We use the notation $\delta$ for forward messages and $\delta'$ for backward messages.

In order to reduce the total number of messages sent, messages are only sent if the information contained within them exceeds a threshold value. Since all edges that span phones represent binary variables, the information content of a message between phones (once normalised) is just
\[
I(\delta) = 1 + \delta\log_2(\delta) + (1-\delta)\log_2(1-\delta)
\]

Information is transferred between phones by publishing a data payload along with a daily exposure key on a public server. The payload and exposure key is periodically downloaded by all mobiles, if any mobile has a PID in its log that can be derived from the exposure key then the payload is deemed delivered to that phone.

However, a daily exposure key will match all contacts in a given day, but in order to implement belief propagation we need to send different messages to different contacts on the same day. So somehow we need to deliver different messages to all contacts on a given day by publishing a single data payload. We want to do this in an efficient way that protects information about the contacts.

For forward messages we do this by publishing the phone's current belief in the posterior marginal infectiousness distribution for the day of the exposure key (under the approximation that the infectiousness of the person was constant over that period. In practice, we can take the infectiousness at the mean of the contact times for that day). From this single distribution all contacts can calculate their own forward messages.

To see this, suppose the posterior infectiousness distribution for the day in question is given by $\Phi_i(\iota)$. This is known to phone $i$. Consider now one of the same phone's Bernoulli clusters for this day $\Phi_{B}$, and suppose this is connected to cluster $\Phi_j$ on the other participant's phone. If there have been no backward messages from $\Phi_j$ to $\Phi_{B}$, the forward message from $\Phi_{B}$ to $\Phi_j$ will be equal to
\[
\delta = \int B(\tau_{a\rightarrow b}(t)|\iota)\Phi_i(\iota) d\iota = \int \iota\Phi_i(\iota) d\iota
\]
If on the other hand $\Phi_{B}$ has received a backwards message, $\delta'$,  from $\Phi_j$, we need to remove the effect of this backward message before calculating the forward message. The backward message to $\Phi_{B}$ would in turn create another backward message from $\Phi_{B}$ to $\Phi_i(\iota)$ with value
\[
\delta'\iota + (1-\delta')(1-\iota) = (1 - \delta') + (2\delta' - 1)\iota
\]
So, the posterior belief about $\iota$ must be
\[
\Phi_i(\iota) = \alpha((1 - \delta') + (2\delta' - 1)\iota)\Phi'_i(\iota)
\]
where $\Phi'_i(\iota)$ is the belief with the backward message removed and $\alpha$ is a normalising constant. So, the correct forward message from $\Phi_{B}$ to $\Phi_j$ must be
\begin{equation}
\delta = \int i \Phi'_i(\iota) d\iota = \frac{1}{\alpha}\int \frac{\iota\Phi_i(\iota)}{(1 - \delta') + (2\delta' - 1)\iota} d\iota
\label{forwardMessage}
\end{equation}
where
\begin{equation}
\alpha = \int \frac{\Phi_i(\iota)}{(1 - \delta') + (2\delta' - 1)\iota} d\iota
\label{normalisation}
\end{equation}
but since the receiving phone, $j$, knows the value of $\delta'$ (i.e. the backward message it sent) it can reconstruct the correct forward message from the Bernoulli cluster given only $\Phi_i(\iota)$.

So, if phone $i$ publishes a parameterised version of $\Phi_i(\iota)$ along with a daily exposure key, all contacts for that day can derive their individual forward messages. We suggest publishing $\Phi_i(\iota)$ in terms of its first $n$ moments. By taking the Taylor expansion of equations \ref{forwardMessage} and \ref{normalisation} about $\delta' = 0.5$, the forward message can be expressed as a series in the moments of $\Phi_i(\iota)$.

There is a similar problem with backward messages if we wish to publish them with the user's daily exposure key; different backward messages would need to be sent to contacts that happened on the same day.

However, suppose for all contacts in a day $\left<t_1,a_1,b_1,\iota_1\right>...\left<t_n,a_n,b_n,\iota_n\right>$, we imagine an additional cluster that sits between the the Bernoulli clusters on the contacts' phones, $ \Phi_B(\tau_{b_1\rightarrow a_1},\_) ... \Phi_B(\tau_{b_n\rightarrow a_n},\_)$, and the local $\Phi_i$ cluster. The new cluster aggregates all incoming transmission edges for one day into a single effective transmission using a logical OR operation, so that the effective transmission is true if any of the transmissions for that day are true. The $\Phi_i$ cluster now sends a single message to the OR cluster, $\delta_\Phi$, which is its posterior likelihood function of the aggregated transmission for the day, divided by any messages sent from the OR cluster. Since we're not interested in normalisation constants we'll assume that $\delta_\Phi$ has been normalised and so can be sent as a single number. Suppose also that that we've received forward messages $\delta_1...\delta_m$ from the remote Bernoulli clusters. The OR cluster needs to send the following backward message to Bernoulli cluster $j$
\[
\delta'_j = \frac{\delta_\phi}{\delta_\phi + (1-\delta_\phi)\prod_{i\ne j}(1-\delta_i) + \delta_\phi(1 - \prod_{i\ne j}(1-\delta_i))}
\]
\[
= \frac{\delta_\phi}{ (1-2\delta_\phi)\prod_{i\ne j}(1-\delta_i) + 2\delta_\phi}
\]
\[
= \frac{\delta_\phi}{ \frac{1-2\delta_\phi}{1-\delta_j}\prod_{i}(1-\delta_i) + 2\delta_\phi}
\]
where we've normalised the backward message for convenience even though it's a likelihood.

So, instead of sending separate backward messages to each Bernoulli cluster, we publish $\delta_\phi$ and $\prod_i (1-\delta_i)$ along with the daily exposure key. Then, since each phone already knows it's own $\delta_j$ (i.e. the forward message it passed for that contact) they can each calculate their own backward message from the published values. In this way we only need to make a single publication to send backward messages to all contacts on that day.

\subsection{Training the model: The parameter server}
%================================

``Epidemiological'' messages from a phone to the parameter server will consist of the likelihood function of the parameters for any new test results. If there are many parameters, an approximation could be sent in order to reduce bandwidth requirements; for example, by assuming independence between certain parameter sets. Since the parameter server doesn't need to know the identity of the sender in order to update its belief, the updates can be sent anonymously.

Forward messages from the parameter server to each phone could be sent by publishing the posterior belief in the parameters. Phones could update their values on a daily basis. In a similar way to that described above, if a user has sent a backward message to the parameter server, the effects of that message can be removed from the published posterior by simply dividing, in order to calculate the correct forward message from the parameter server.

The prior of the parameter server could also be updated centrally in response to new scientific understanding of the dynamics of the disease.

\section{Inference over multiple encounters between the same two people}
%=======================================================================

If every pair of people meet at most once, the belief propagation algorithm will result in beliefs that are equal to the Bayesian marginal posteriors. However, when the same two people have many encounters, this can lead to beliefs that do not correspond exactly to the Bayesian posterior. To demonstrate this, suppose A and B meet twice within a short space of time, and suppose A is infected. The variables of interest here are $\iota$, the infectiousness of A at the time of the meetings, $\epsilon(t)$, B's first exposure time and $\tau_1$ and $\tau_2$, the transmission events from A to B for each meeting. The joint of these is given by
\[
P(\iota, \tau_1, \tau_2, \epsilon(t)) = P(\iota)B(\tau_1|\iota)B(\tau_2|\iota)P(\epsilon(t)|\tau_1,\tau_2)
\]
where $B(\tau|\iota)$ is the Bernoulli distribution, and, from equation \ref{firstExposure}
\[
P(\epsilon(t)|\tau_1,\tau_2) = \delta(t-t_1)\tau_1 + \delta(t-t_2)\tau_2(1-\tau_1)
\]
where, $t_1$ and $t_2$ are the times of the encounters. In order to keep the demonstration simple, we set $\rho$ to zero and assume no other contacts, although the same argument applies in the presence of other contacts and non-zero $\rho$.

Starting with forward inference, the correct marginal for $P(\epsilon(t))$ is
\[
P(\epsilon(t)) = \int \delta(t-t_1)\iota + \delta(t-t_2)\iota(1-\iota) P(\iota) d\iota = \delta(t-t_1)\overline{\iota} + \delta(t-t_2)\left(\overline{\iota} - \overline{\iota^2}\right)
\]
However, the belief propagation algorithm will end up with a belief
\[
B(\epsilon(t)) = \delta(t-t_1)\overline{\iota} + \delta(t-t_2)\overline{\iota}(1-\overline{\iota}) = \delta(t-t_1)\overline{\iota} + \delta(t-t_2)\left(\overline{\iota}-\overline{\iota}^2\right)
\]
So the the belief that the first encounter was a first exposure is correct, but the belief that the second encounter was a first exposure is in error by the variance of $P(\iota)$.

To give a sense of the size of error in reverse inference, we take the worst case scenario which is that B is certainly infected, and has only been in contact with $A$, so either $\tau_1$ or $\tau_2$ must be the first exposure. This is equivalent to saying $\tau_1 \vee \tau_2 = true$. The correct posterior marginal is
\[
P(\iota | \tau_1 \vee \tau_2 = true) = A\left(2\iota - \iota^2\right)P(\iota)
\]
where $A$ is a normalising constant. Expressing $\iota$ as a perturbation from the mean $\iota = \overline{\iota} + \delta$ and expanding in powers of $\delta$ gives
\[
P(\delta | \tau_1 \vee \tau_2 = true) = A\left(\overline{\iota}(2 - \overline{\iota}) + 2(1-\overline{\iota})\delta - \delta^2\right)P(\overline{\iota}+\delta)
\]
 However, the propagation algorithm would give, after one cycle of message passing,
\[
B(\iota | \tau_1 \vee \tau_2 = true) = A' (\iota(1 - \overline\iota) + \overline{\iota})^2P(\iota)
\]
Expanding this in powers of $\delta$ gives
\[
B(\delta | \tau_1 \vee \tau_2 = true) = A'(\overline{\iota}(2 - \overline{\iota})) \left(
\overline{\iota}(2 - \overline{\iota}) +
2(1-\overline{\iota})\delta +
\frac{(1-\overline{\iota})^2}{\overline{\iota}(2 - \overline{\iota})}\delta^2
\right)P(\overline{\iota}+\delta)
\]
However, since $\overline{\iota}$ and $\delta$ will be small (of the order 0.01\cite{luo2020modes}), the expected error is in the order $\mathcal{O}\left(\frac{\overline{\iota^2}}{2\overline{\iota}}\right)$. Further loops of message passing would introduce higher order terms in $\delta$ but since $\delta$ is small these can be ignored.

We may wish to simply neglect these errors, or if we want more accuracy we could identify repeated encounters.

\subsection{Identifying repeated encounters}
%===========================================

If the phone receiving a message is able to identify transmission events that involve the same person, the corresponding Bernoulli clusters can be bundled into a single cluster and belief propagation will again be exact.

If the repeated encounters occur on the same day, the phone that receives the message can easily identify them since the daily exposure key will match multiple PIDs in its log. However, if the encounters were on different days, the matching is more difficult as they will have different daily exposure keys and, by design, these cannot be tracked to an individual.

Repeated encounters will most often be between members of the same household, close friends or work colleagues. Users could be given the option to match encounters with known contacts by allowing their phones to communicate directly in any convenient way (e.g. Bluetooth). Suppose person A has published a number of daily exposure keys. For any genuine close contacts with person B, both A and B know the daily exposure key and the PIDs that were exchanged during the encounter. If B's PIDs match multiple published exposure keys, B's phone can choose one, use the exchanged PIDs to encrypt the corresponding daily exposure key and send the encrypted message to A's phone. A's phone can then try to decrypt the message using the PID pairs corresponding to its encounters. If the decrypted message successfully matches A's daily exposure key, a message can be sent back to B confirming that the encounter was between A and B. In order for B's phone to keep the number of PID matches secret, it can send a number of dummy requests to make up the total number of requests to some randomly chosen number. In this way, the only information either phone can gain is which encounters involved the two parties. Since this is not a secret between the two parties in any case, no private information is revealed.

In order to match repeated encounters with strangers, the user could be prompted when the probability of two messages being from the same person goes above some threshold. The user could then use information about the times of the contacts, their memory of events and knowledge of their daily behaviour to try to work out whether they were repeated encounters. For example, if the user goes to the same coffee shop every morning, then the pattern of encounters at the same time every morning may allow them to assign them as repeated encounters.

\section{Deciding when to self-isolate, test and release}
%========================================================
Now we have a way of estimating posterior marginal probabilities, we can use these to make decisions. We adopt a decision theoretic approach by calculating the expected cost of each option and taking the one that has the lowest cost. We measure cost in days of life lost. If a person dies of COVID-19, the cost of that death is the expected number of extra days of life that person would have had, had they not contracted the disease.

From this, we can calculate the cost of someone becoming infected when $R<1$. In this case, a single infection will result in an average of $-\frac{1}{\ln(R)}$ total infections. If $P_d$ is the case fatality ratio, then we would expect $-\frac{P_d}{\ln(R)}$ deaths and an average of
\[
c_{id} = -\frac{P_dL}{\ln(R)}
\]
days of life lost, where $L$ is the average number of days lost when someone dies of COVID-19, considering age distribution and life expectancy.

There is also a cost, $\chi$, associated with a person being hospitalised for a day (this covers the personal, inter-personal and financial costs). If $\bar{h}$ is the average number of days of hospitalisation per infection then we have a total expected cost of a single infection
\[
c_{i} = -\frac{P_dL + \chi\bar{h}}{\ln(R)}
\]

Let the cost of a person having to self-isolate for a day be $c_s$ and let $c_{Tn}$ be the cost of taking the $n^{th}$ test. These are subjective values which must weigh up the social, personal and economic costs.

If we assume decisions are made on a daily basis then on each day we need to decide whether to self-isolate for that day and whether to take test $n \in 1...N$. Clearly, any tests with immediate results should be taken before the decision whether to self isolate for that day so the decision which tests to take should be made first. Given any test results, a person should self isolate on that day if
\[
c_s < \bar{\iota}(t)\rho_cc_i
\]
where $\rho_c$ is the user's average daily rate of close contacts and $\bar{\iota}(t)$ is the user's expected infectiousness on that day, given all the evidence to date.

If we decide to test, there is a fixed immediate cost of taking a test, $c_{Tn}$, but in return we gain information about the disease onset distribution. We can put a value on that information by calculating the difference in expected cost with and without that information. If having the information reduces our expected cost by more than the cost of obtaining the information then, on average, it is worth paying the price of the test for the information. So, the expected cost at time $t$ is
\[
\bar{c}(t) = \min(\bar{c_0}(t), c_{Tn} + P(\xi_n^+(t)|C(t))\bar{c}(\xi_n^+(t)) + P(\xi_n^-(t)|C(t))\bar{c}(\xi_n^-(t)))
\]
where $\bar{c}(\xi_n^+(t))$ and $\bar{c}(\xi_n^-(t))$ is the expected cost given a positive/negative test result and $\bar{c}_0(t)$ is the expected cost of not testing.
\[
\bar{c}_0(t) = (c_s - \bar{\iota}(t)\rho_cc_i)H(\bar{\iota}(t)\rho_cc_i - c_s) + \bar{c}(t+1)
\]
where $H(.)$ is the Heaviside step function.
\[
\bar{c}(\xi_n^-(t)) = (c_s - \bar{\iota}(t|\xi_n^-)\rho_cc_i)H(\bar{\iota}(t|\xi_n^-)\rho_cc_i - c_s) + \bar{c}(t+1)
\]
If we assume that information that raises the probability of a transmission event above some threshold, $p_t$ will trigger isolation and contact tracing of a close contact, then the expected cost of getting a positive test is
\[
\bar{c}(\xi_n^+(t)) =
  (c_s - \bar{\iota}(t|\xi_n^+)\rho_cc_i)H(\bar{\iota}(t|\xi_n^+)\rho_cc_i - c_s) +
  \sum_{A} c_a^\rightarrow(t-t_c)
+   \sum_{B} c_a^\leftarrow(t-t_c)
+ \bar{c}(t+1)
\]
where
\[
A = \left\{
    \left<t_c,a,b\right> \in C(t): P(\tau_{a\rightarrow b}|\xi_n^+) > p_{t} \wedge P(\tau_{a\rightarrow b}) \le p_{t}
  \right\}
\]
\[
B = \left\{
    \left<t_c,a,b\right> \in C(t): P(\tau_{b\rightarrow a}|\xi_n^+) > p_{t} \wedge P(\tau_{b\rightarrow a}) \le p_{t}
  \right\}
\]
$\bar{c}_a^\leftarrow(\Delta t)$ is the expected cost saving of isolating and contact tracing an infector at a time $\Delta t$ after the contact and $\bar{c}_a^\rightarrow(\Delta t)$ is the expected cost saving of isolating and contact tracing an infectee at a time $\Delta t$ after the contact. These expected values can be pre-calculated using Monte-Carlo simulation.

Notice that calculation of $\bar{c}(t)$ requires calculation of $\bar{c}(t+1)$ so we have a recursion.

To make the recursion tractable, we make a few assumptions. First, since the logging of symptoms can be done with very little cost, we assume that symptoms should be logged every day unconditionally (in practice, this will consist of the logging of the onset of and recovery from any relevant symptoms, with the assumption of no symptoms otherwise). Secondly, we assume that we take at most one clinical test a day, and that the appropriate clinical test (i.e. PCR, antigen or antibody) can be decided by clinical considerations based on our belief about onset time and whether there have been previous positive tests (i.e. whether we are trying to show that a person has been infected or is safe to release).

With these assumptions, we can easily calculate the recursion 7 days into the future without putting a significant computational load on the phone. Since on each day either no test is performed, or a test is performed and returns positive, or a test is performed and returns negative, there are three scenarios to evaluate each day and $3^7 = 2187$ scenarios in total. Beyond the 7 day horizon, we assume that if isolated the user will remain isolated until no danger is posed or if not isolated, the user will remain out of isolation. Since we don't know what the result of symptom tests will be, we take a Monte-Carlo sample of symptom onset times (say 100 samples) and run each scenario with each sample, giving a total of just over $200,000$ scenarios to run. This is not a large computational load, but can be reduced further if desired by pruning highly unlikely scenarios (such as getting two consecutive negative tests at the peak of viral shedding after positive confirmation) and unreasonable testing schedules (e.g. performing a test around symptom onset if a positive test has already been obtained).

\section{Discussion and further work}

We have described a privacy-preserving way of doing distributed Bayesian inference on a network of mobile phones in order to inform decisions made by a contact tracing app. The algorithm also allows the disease model on each phone to be updated in response to the data collected during contact tracing and allows Epidemiologists to learn about the dynamics of the disease.

Further work is necessary to ensure that the network can withstand malicious attack, and a full analysis should be made to ensure that there is no way that the content of the messages could be used to identify a person. However, we have shown that Bayesian inference and epidemiological data collection is possible within the context of decentralised contact tracing as described in the Apple/Google specification.

%\bibliographystyle{unsrtnat}
\bibliographystyle{unsrturl}
%\bibliographystyle{alpha}
%\bibliographystyle{plainurl}
%\bibliographystyle{apalike}
%\bibliographystyle{apacite}
\bibliography{inferenceRefs}

\end{document}


\section{Rational numbers}


\documentclass{article}
\begin{document}

Some structure:
\section{One}
Hm,
\begin{itemize}
\item $a>b$
\item second item
\end{itemize}

\end{document}


\subsection{Greedy pretraining}


\chapter{Future Work}\label{ch:futureWork}
In this chapter, we discuss the next steps associated with our research.

\section{Evolutionary Simulator}\label{sec:evolutionarySimulator}
The focus of this project was to find an appropriate evolutionary simulator and model for a single population.
We believe that we have constructed a fast evolutionary simulator, but it could be more efficient.
As of now, the running time of our evolutionary simulator is dependent on $n$ and $N$.
$n$ must be large enough to account for the variance in this problem, but we can remove our reliance on $N$ by
drawing our mutations from some distribution instead of iterating from generation to generation.
This increases the noise associated with our mutation model, but may make our simulator much faster.

\section{Implementation Updates}\label{sec:implementationUpdates}
All code for this project is current written in Python 3.7.
We were able to get reasonable speedup using Numba to compile certain sections of our code (as opposed to only
interpreting it), but it might be of interest to move to a compiled language like C++ altogether.
It might also be of interest to start moving certain sections of the sampler (simulator, $\delta$, etc\ldots) to the
GPU.
This problem is highly parallelizable, but we are only running at most 20 tasks in parallel on the CPU.
The GPU would allow us to run thousands of tasks in parallel, (ideally) resulting in less runtime.

\section{Mutation Model}\label{sec:mutationModel}
We were able to obtain estimates for our mutation model, but we need to further verify that these parameters are
correct.
There exists three main areas of future work:
\begin{enumerate}
    \item Verifying the model using more populations.
        We were only able to use the Columbian populace here, but using the same methodology with other groups would
        give us different $\hat{c}$ and $\hat{d}$ values to compare to.
    \item Comparing the total mutation rate to that of other \texttt{GATA} microsatellites in different literature.
    \item Running our MCMC longer.
        As seen in the previous section, our trace was not the ideal shape but it showed hints toward convergence.
        The easiest solution here to increase our number of iterations $T_2$, which would show a straighter and thicker
        line if we have truly converged.
    \item Retrieving more statistics about our Metropolis sampler.
        We visually assessed Markov chain convergence by looking at the trace plot, but there exist other metrics
        that could be explored (see~\cite{cowlesMarkovChainMonte1996}).
        This would allow us to tune our sampler with more precision, and possibly find better estimates for $\hat{c}$
        and $\hat{d}$.
\end{enumerate}

\section{Demographic Models}\label{sec:demographicModels}
Once we are confident in our mutation model, we can extend our work toward using the same methodology with
\emph{multiple} populations.
The mutation model parameters then become hyperparameters to these demographic models as we try to estimate
additional parameters such as population size, admixture, and divergence times.
Below, we present several multi-population models from Stoneking and Krause that can be used to make various
inferences~\cite{stonekingLearningHumanPopulation2011}.
\begin{enumerate}
    \item Three population models: (Ancestors, African vs.\ Non African), (Ancestors, Modern Humans vs.\ Neanderthals),
        (Ancestors, Modern Humans vs.\ Denisovans).
        We can determine the population sizes of all populations and the time of each split.
    \item A five population model: Ancestors, African One, African Two, Non African One, Non African Two.
        We can determine the admixture between the African and Non African populations, as well as the time associated
        with each split.
    \item A seven population model: Ancestors, Modern Humans One, Modern Humans Two, Neanderthals One, Neanderthals Two,
        Denisovan One, Denisovan Two.
        Again, we can determine the admixture between each population as well as the time associated with each split.
\end{enumerate}
%
%\section{Summary}\label{sec:summary}
%Human inferences can be made by tracking variations in DNA.
%In this paper we went over how we can use microsatellite DNA, a form of genetic variation in humans, to infer
%human evolution.
%Our first approach was to use a forward simulator model to simulate generation to generation transitions, but we
%ended up using a backward simulator model because it required less individuals to simulate.
%Our two parameter $c, d$ mutation model was selected for its simplicity and flexibility.
%To estimate the most likely parameter values $\hat{c},\hat{d}$, we used an ABC-MCMC approach.
%Future work includes verifying these parameters further and extending our methodology to more demographic models.


% !TEX root = ../../main.tex
\chapter{Statistical Analysis}
\label{ch:stats}

In this chapter, the quantitative strategy used to compare the recorded data to SM predictions, and to set limits on BSM theoretical models, is outlined. The invariant mass distribution, $m(\ell\nu J)$, is used as a discriminant in this search, with an optimized binning strategy as detailed in~\Sect{\ref{ch:stats:vb}}. In \Sect{\ref{ch:stats:ml}}, a maximum-likelihood (ML) fit of the data to a background-only hypothesis, to determine the normalizations of the \Wjets and \ttbar backgrounds, is described. The systematic uncertainties described in~\Ch{\ref{ch:syst}} are included in the fit as nuisance parameters (NP), and the SRs and CRs are fit simultaneously. In \Sect{\ref{ch:stats:ul}}, a test statistic based on the profiled log likelihood ratio, used to create upper limits on production cross sections, is outlined.

%
\section{Variable Binning}
\label{ch:stats:vb}
In the ML fit (\Sect{\ref{ch:stats:ml}}), the $m(\ell\nu J)$ distribution is binned. In order to optimize the number of bins, and the width of each bin, simulated signal samples are used to find the mass resolution of the signal model as a function of signal mass.  For each mass point, the $m(\ell\nu J)$ distribution is fit with a Breit-Wigner function\footnote{
	Although using a model with a Breit-Wigner convolved with a Gaussian would extract a width close to the simulated width, the approximate experimental resolution of the width is of interest for determining the binning.
}. The mean and width are extracted from the fit, where the width is used as an estimate of the signal mass resolution. In~\Fig{\ref{fig:sig_fit}}, an HVT $Z'$ signal model at $m=2\,\TeV$ is used to illustrate the fit and extraction of the mass resolution. In~\Tab{\ref{tab:resns}}, the natural resonance width and the extracted resonance width are provided for the HVT $Z'$ and RS $G^*$ signal models. In~\Fig{\ref{fig:binning}}, a linear fit is used to parameterize the extracted mass resolutions for both signal models.  For the HVT $Z'$ (RS $G^{*}$) model, the natural width is approximately 3\,\% (6\,\%) the resonance mass, while the extracted resolution is approximately 5\,\% (9\,\%) the resonance mass, indicating detector effects inflate the natural resonance width by approximately 2-3\,\%.

\begin{wrapfigure}{r}{.5\textwidth}
\includegraphics[width=.99\linewidth]{figures/StatisticalAnalysis/fit_HVT_WW_15}
\caption[Extraction of signal mass resolution]{An HVT $Z'$ signal sample at $m=2\,\TeV$\,is fit with a Breit-Wigner function to extract the width, $\Gamma$, and estimate the signal mass resolution.}
\label{fig:sig_fit}
\end{wrapfigure}

The final binning is optimized using the HVT $Z'$
signal model with ggF selection. This search uses 500\,\GeV\, as the lowest bin edge, adding bins with a width at least as large as the resolution determined from the extracted linear fit. In the high mass region, there are low background statistics. To avoid bins with too few entries, in this region bin widths are enlarged such that the ratio of the statistical uncertainty to the background expectation in a bin is below a threshold. The final binning for the ggF selection includes 20 bins, with all overflows included in the last bin. For the VBF selection, background statistics decrease much more rapidly, and only 11 bins are used. The first nine bins are identical to the ggF selection, while the final two bins are enlarged to address the decreasing background statistics.

\begin{table}[htb]
\centering
\begin{tabular}{c|c|c|c|c}
\hline\hline
Signal Mass [\TeV] & \multicolumn{2}{c|}{HVT $Z'$} & \multicolumn{2}{c}{RSG $G^{*}$} \\\cline{2-5}
& $\Gamma_{\rm exp.}$ [\GeV] & $\Gamma_{\rm meas.}$ [\GeV]& $\Gamma_{\rm exp.}$ [\GeV] & $\Gamma_{\rm meas.}$ [\GeV]\\\hline
0.8 & 32 & 74 & 46 & 90 \\
1.6 & 51 & 113 & 96 & 149 \\
2.4 & 74 & 153 & 148 & 238 \\\hline\hline
\end{tabular}
\caption[Expected and measured resonance widths]{Theoretical and measured resonance widths for HVT $Z'$ (model-B, $g_v=3$) and RS $G^{*}$ ($k/\overline{M}_{\rm Pl}=1.0$) signal models. The natural width for the HVT $Z'$ (RS $G^{*}$) signal model is approximately 3\,\% (6\,\%) the mass of the resonance, while experimental effects inflate the resolution by approximately 2\,\% (3\,\%).}
\label{tab:resns}
\end{table}

\begin{figure}[htb]
\centering
%\subfloat[]{\includegraphics[width=.49\textwidth]{figures/StatisticalAnalysis/HVT_WZ}\label{fig:binning:a}}
\subfloat[]{\includegraphics[width=.49\textwidth]{figures/StatisticalAnalysis/HVT_WW}\label{fig:binning:b}} %\\
\subfloat[]{\includegraphics[width=.49\textwidth]{figures/StatisticalAnalysis/RS_G_WW}\label{fig:binning:c}}
\caption[Resolution of simulated signal samples]{Mass resolution of simulated signal samples as a function of $m(WV)$ for %\protect\subref{fig:binning:a} HVT $W'$,
\protect\subref{fig:binning:b} HVT $Z'$ and \protect\subref{fig:binning:c} RS $G^*$ signal models. The fit to the HVT $Z'$ signal model was used to determine the binning in this analysis.}
\label{fig:binning}
\end{figure}

%
\section{Binned Maximum Likelihood Fit}
\label{ch:stats:ml}
A simultaneous binned ML fit~\cite{lh_stats} of the $m(\ell\nu J)$ distribution in the SRs and CRs is performed on the MC prediction to the recorded data. Due to their large overlap, the $WW$ and $WZ$ channels are analyzed separately. Additionally, the VBF and ggF selections are fit separately. Signal models with ggF (or qqF) production are analyzed with the fit to the ggF selection, while signal models with VBF production are analyzed with the fit to the VBF selection. A summary of which of the four fits is considered for each benchmark signal model is given in~\Tab{\ref{tab:sig_fits}}. For each fit, there is a common normalization factor for the HP and LP regions, for each of the two main backgrounds ($\Wjets$ and $\ttbar$). These normalizations are free to float in the fit and constrained by the dedicated CRs.

\begin{table}[b!]
\bigskip
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{l|cc|cc}
\hline\hline
Model&\multicolumn{2}{c|}{ggF Selection (SRs \& CRs)}&\multicolumn{2}{c}{VBF Selection (SRs \& CRs)}\\\cline{2-5}
&$WW$&$WZ$&$WW$&$WZ$\\\hline
\textbf{Scalar Heavy Higgs}&&&&\\
\,\hfill ggF prod.&\checkmark&&&\\
\,\hfill VBF prod.&&&\checkmark&\\\hline
\textbf{HVT} $\mathbf{Z'}$&&&&\\
\,\hfill qqF prod.&\checkmark&&&\\
\,\hfill VBF prod.&&&\checkmark&\\\hline
\textbf{HVT} $\mathbf {W'}$&&&&\\
\,\hfill qqF prod.&&\checkmark&&\\
\,\hfill VBF prod.&&&&\checkmark\\\hline
\textbf{RS} $\mathbf{G^{*}}$&\checkmark&&&\\\hline\hline
\end{tabular}
}
\caption[Selection regions used in the simultaneous maximum likelihood fit for the benchmark signal models]{Summary of the selection regions included in the maximum likelihood fit for each benchmark signal model. For each selection, all of the corresponding high purity (HP) and low purity (LP) signal regions (SR) and control regions (CR) are included. For example, in the fit corresponding to the ggF selection, $WW$ channel, the following regions are included in the simultaneous fit: HP SR ($WW$), LP SR ($WW$), HP \Wjets CR, LP \Wjets CR, HP \ttbar CR and LP \ttbar CR, with all regions passing the ggF selection.}
\label{tab:sig_fits}
\end{table}

The likelihood function is a product of the Poisson distributions for each selection region and bin included in the fit. The Poisson distribution for observing a number of events, $n_{\rm obs}$, with an expected number of events, $n_{\rm exp}$, is given in~\Eqn{\ref{eq:pois_prob}}. Systematic uncertainties are included as constrained NPs in the fit with Gaussian, or log-normal distributions.
The histograms for the backgrounds are based on MC samples with finite statistics. The Barlow-Beeston ``lite'' method~\cite{bin_stats} is used to account for bin-by-bin statistical uncertainties by adding a NP for each bin in each region. These NPs represent the statistical uncertainty in a bin from each background, added in quadrature.
The normalizations for the minor backgrounds are included as NPs in the fit, with Gaussian constraints on the production cross section of 11\,\%, 11\,\%, and 30\,\% for the \Zjets, \Singlet, and SM diboson backgrounds, respectively, according to SM measurements. The full likelihood function is expressed in~\Eqn{\ref{eq:lh_func}}.
\begin{eqnarray}
P(n_{\rm obs}|n_{\rm exp}) &=& \frac{\left(n_{\rm exp}\right)^{n_{\rm obs}}e^{-n_{\rm exp}}}{n_{\rm obs}!} \label{eq:pois_prob}\\
L(\mu,\bm{\theta})&=&\prod_{j\in\{\rm SRs,\, CRs\}}\prod_{i\in\{\rm bins\}} P(N_{ij}|\mu s_{ij}+ B_{ij})\prod_{l\in\{\rm NPs\}}{\rm Nuis}(\theta_l) \label{eq:lh_func} \\
B_{ij}&=&\mu_{\ttbar} b_{ij}^{\ttbar} + \mu_{\Wjets}b_{ij}^{\Wjets}+ b_{ij}^{\rm other} \label{eq:bkg_exp}
\end{eqnarray}
The signal strength, $\mu$, parameterizes the production of signal events, where $\mu=1$ corresponds to the nominal signal hypothesis and $\mu=0$ corresponds to the background-only hypothesis.  The parameter $\bm{\theta}$ represents the collection of all NPs. In the likelihood function, the index $j$ runs over the SRs and CRs in the fit, the index $i$ runs over the bins of the $m(\ell\nu J)$ distribution in each region, and the index $l$ runs over all of the NPs considered. In the Poisson distribution functions, for each bin $i$ and region $j$, $N_{ij}$, is the number of observed data events, $s_{ij}$ is the number of expected signal events, and $B_{ij}$ is the number of expected background events. $B_{ij}$ is defined in~\Eqn{\ref{eq:bkg_exp}}, where $\mu_{\ttbar}$ ($\mu_{\Wjets}$) is the normalization factor for the \ttbar (\Wjets) background, and $b_{ij}^{x}$ is the expected number of background events for background process $x$ (i.e. \ttbar, \Wjets, or other = \Singlet, \Zjets, and SM dibosons).

For each systematic uncertainty, ``up'' and ``down'' histograms are generated, corresponding to the variation of the systematic uncertainty by $\pm 1\sigma$. The impact of the systematic uncertainty on the nominal event yield is parameterized by a NP, $\theta$, such that $\theta=\pm1$ corresponds to the variation of the systematic uncertainty by $\pm 1 \sigma$. The event yield is thus factored according to the separate contributions from each NP, as shown in~\Eqns{\ref{eq:syst_imp}}{\ref{eq:delta_np}}, where $(\mu s +B)^{\pm,\,0}$ corresponds to the event yield from the ``up'' ($+$), ``down'' ($-$), or nominal ($0$) variations. The NPs have an applied Gaussian or log-normal constraint, centered at 0 with width 1. This parameterization of the impact of the systematic uncertainty variations is denoted by $\text{Nuis}(\theta_l)$ in~\Eqn{\ref{eq:lh_func}}. For each NP, correlations are taken into account between bins in the final discriminant, between regions in the fit, and between background and signal distributions.

\begin{eqnarray}
\mu s+B&=&(\mu s+B)^0\prod_l\left(1+\Delta_l\theta_l\right)\label{eq:syst_imp}\\
\Delta_l&=& \begin{cases}\frac{(\mu s+B)^+-(\mu s+B)^0}{(\mu s+B)^0} & \theta_l\geq 0 \\ \frac{(\mu s+B)^0-(\mu s+B)^-}{(\mu s+B)^0} & \theta_l<0  \end{cases} \label{eq:delta_np}
\end{eqnarray}

For some of the systematic uncertainties, their estimated variations were calculated using MC samples with limited statistics. In order to avoid the effects of statistical fluctuations, some of the variations of the systematic uncertainties are smoothed. The event yield in bin $i$ for the ``up'' or ``down'' histogram of a smoothed systematic uncertainty is set according to the prescription in~\Eqns{\ref{eq:smoothing:a}}{\ref{eq:smoothing:b}}.

\begin{eqnarray}
(\mu s+B)^{\pm}_i&=&(\mu s + B)^0_i\left[1+\lambda_i^{\pm}\right] \label{eq:smoothing:a}\\
\lambda_i^{\pm}&=&\frac{1}{4}\left( \left[(\mu s+B)^{\pm}_{i-1}-(\mu s+B)^0_{i-1}\right] +2\left[(\mu s+B)^{\pm}_{i} - (\mu s+B)^0_{i}\right]  \right.\nonumber \\
& & \left.+ \left[(\mu s+B)^{\pm}_{i+1}-(\mu s+B)^0_{i+1}\right]  \right) \label{eq:smoothing:b}
\end{eqnarray}

%
\section{Upper Limits on Cross Section}
\label{ch:stats:ul}
A test statistic, $\tilde{q}_{\mu}$, based on the log of the profile likelihood ratio~\cite{lh_stats}, is used to test values of the signal strength, $\mu$, for each signal model, and set upper limits on the production cross section. The profile likelihood ratio, $\tilde{\lambda}(\mu)$, is defined in~\Eqn{\ref{eq:plr}}, where the signal strength is constrained to be non-negative ($\mu\geq0$) because the contribution to the event yield from a signal model is assumed to be non-negative.

\begin{equation}
\tilde{\lambda}(\mu)=\begin{cases} \frac{L(\mu,\hat{\hat{\bm{\theta}}}(\mu))}{L(\hat{\mu},\hat{\bm{\theta}})}&\hat{\mu}\geq 0 \\ \frac{L(\mu,\hat{\hat{\bm{\theta}}}(\mu))}{L(0,\hat{\hat{\bm{\theta}}}(0))} & \hat{\mu}< 0 \end{cases}
\label{eq:plr}
\end{equation}

In the numerator, $\hat{\hat{\bm{\theta}}}(\mu)$ represents the value of $\bm{\theta}$ that maximizes the likelihood function, $L$, for a fixed value of $\mu$. This is the conditional ML estimator of $\bm{\theta}$, and is a function of $\mu$. The denominator is the ML function; that is, $\hat{\mu}$ and $\hat{\bm{\theta}}$ are the unconditional ML estimators of $\mu$ and $\bm{\theta}$. The value of the estimator, $\hat{\mu}$, that maximizes the likelihood function is allowed to be negative so that it can be modeled by a Gaussian distributed variable. For cases where $\hat{\mu}<0$, the denominator in the profile likelihood ratio is fixed to the physical value that best describes the data, with $\mu=0$ and $\hat{\hat{\bm{\theta}}}(\mu=0)$.

The value of $\tilde{\lambda}$ is constrained by $0\leq\tilde{\lambda}\leq 1$, where values closer to 1 indicate better agreement between the observed data and the hypothesized signal model with signal strength, $\mu$. The test statistic, $\tilde{q}_{\mu}$, is defined in~\Eqn{\ref{eq:qmu}}, where larger values of $\tilde{q}_{\mu}$ indicate less compatibility between the observed data and the hypothesized signal strength. The test statistic is set to zero for $\hat{\mu}>\mu$ because an estimated $\hat{\mu}$ larger than the hypothesized value does not represent lower compatibility with the observed data, and is not part of the region rejected by a one-sided upper limit.

\begin{equation}
\tilde{q}_{\mu} = \begin{cases}-2\ln\tilde{\lambda}(\mu)&\hat{\mu}\leq \mu\\ 0 & \hat{\mu}>\mu \end{cases} \label{eq:qmu}
\end{equation}

In order to quantify the level of agreement, a $p$-value can be calculated from the test statistic with the probability distribution function (PDF) of the test statistic, $f(\tilde{q}_{\mu}|\mu)$, as shown in~\Eqn{\ref{eq:pmu}}. Asymptotic distributions of $f(\tilde{q}_{\mu}|\mu)$ are taken from~\Ref{\cite{lh_stats}} and used for tested signal mass points below $1.6\,\TeV$\,($1.0\,\TeV$) for fits to regions with ggF (VBF) selection. For higher signal masses, the PDFs are estimated with an ensemble of 50,000 generated pseudo-experiments using toy MC methods. Near the boundary between the two regimes, the asymptotic and pseudo-experiment limits are found to agree well, while in the highest mass region above $4\,\TeV$, a discrepancy of approximately 20-30\,\% is found, with the pseudo-experiment distributions producing more conservative upper limits.

\begin{equation}
p_{\mu} = \int_{\tilde{q}_{\mu,\,\rm obs}}^{\infty} f(\tilde{q}_{\mu}|\mu) d\tilde{q}_{\mu}  \label{eq:pmu}
\end{equation}

A modified frequentist approach, called the $CL_s$ method~\cite{cls_stats}, is employed to set the final upper limits. The $CL_s$ method uses the ratio of two frequentist confidence levels (CL) as shown in~\Eqnrange{\ref{eq:cls:a}}{\ref{eq:cls:d}}.
Values of $CL_{s+b}$ close to zero indicate the signal model is highly disfavored.
%Values of $CL_b$ close to one indicate the background-only hypothesis is highly disfavored.
A model with signal strength, $\mu$, is excluded if $CL_s<0.05$, corresponding to a CL of 95\,\%. By scanning values of $\mu$ for a specific model, the 95\,\% CL upper limit is set by finding $\mu^{\rm up}$ such that $CL_s=0.05$. In \Eqn{\ref{eq:cls:c}}, $p_{s+b}$ describes the probability, under the assumption of the signal plus background hypothesis with signal strength $\mu$, of measuring a test statistic, $\tilde{q}_{\mu}$, that is equally or less compatible with the tested signal strength than the observed test statistic, $\tilde{q}_{\mu,\,\rm obs}$.  Likewise,~\Eqn{\ref{eq:cls:d}} describes the probability, under the assumption of the background-only hypothesis, of measuring a value of the test statistic greater than or equal to the value observed. That is, the probability to correctly reject the tested value of $\mu$ when the background-only hypothesis is correct.

\begin{eqnarray}
CL_s&=&\frac{CL_{s+b}}{CL_b}\label{eq:cls:a} \\
&=&\frac{p_{s+b}}{1-p_b}\label{eq:cls:b}\\
p_{s+b}&=& \int_{\tilde{q}_{\mu,\,\rm obs}}^{\infty} f(\tilde{q}_{\mu}|\mu) d\tilde{q}_{\mu} \label{eq:cls:c}\\
1-p_b&=& \int_{\tilde{q}_{\mu,\,\rm obs}}^{\infty} f(\tilde{q}_{\mu}|\mu=0) d\tilde{q}_{\mu}  \label{eq:cls:d}
\end{eqnarray}

With respect to a true frequentist CL, the $CL_s$ method is conservative~\cite{cls_stats}. The denominator ($1-p_b$) is always less than or equal to one, thus the requirement $CL_s<0.05$ is more stringent than $p_{s+b}<0.05$.  The benefit of the $CL_s$ approach is that the p-value is penalized for regions where the search has no sensitivity. If a search has a small sensitivity to $\mu$ (expected signal yield is small or zero with respect to the background yield), the model will still be rejected with a probability close to 5\,\%. In the $CL_s$ method, the PDFs of the test statistic for the signal model and for the background-only model have a large overlap if the search has a low sensitivity; thus, as $p_{s+b}$ decreases so does $(1-p_b)$, preventing $CL_s<0.05$.

% HVT WZ
% bins: 500 559 622 689 760 835 915 1000 1090 1185 1286 1393 1507 1628 1756 1892 2036 2189 2351 2523 3593 3841
% bw: 59 63 67 71 75 80 85 90 95 101 107 114 121 128 136 144 153 162 172 1070 248
% No stats
% bins: 500 559 622 689 760 835 915 1000 1090 1185 1286 1393 1507 1628 1756 1892 2036 2189 2351 2523 2706 2900 3106 3324 3556 3802
% bw: 59 63 67 71 75 80 85 90 95 101 107 114 121 128 136 144 153 162 172 183 194 206 218 232 246

% HVTWW
% bins: 500 557 617 680 747 817 891 969 1051 1137 1227 1322 1422 1527 1638 1754 1876 2005 2140 2282 2432 2589
% bw: 57 60 63 67 70 74 78 82 86 90 95 100 105 111 116 122 129 135 142 150 157
% No stats
% bins: 500 557 617 680 747 817 891 969 1051 1137 1227 1322 1422 1527 1638 1754 1876 2005 2140 2282 2432 2589 2755 2967 3152 3347 3552 3768
% bw: 57 60 63 67 70 74 78 82 86 90 95 100 105 111 116 122 129 135 142 150 157 166 212 185 195 205 216

% RSGWW
% bins: 500 556 617 684 757 837 924 1019 1122 1235 1358 1492 1639 1799 1974 2165 2373 2600
% bw: 56 61 67 73 80 87 95 103 113 123 134 147 160 175 191 208 227
% No stats
% bins: 500 556 617 684 757 837 924 1019 1122 1235 1358 1492 1639 1799 1974 2165 2373 2600 2848 3118 3413 3735
% bw: 56 61 67 73 80 87 95 103 113 123 134 147 160 175 191 208 227 248 270 295 322


% $Id$

\subsubsection{ESMC\_MESHELEMTYPE}
\label{const:cmeshelemtype}

 {\sf DESCRIPTION:\\}
 An ESMF Mesh can be constructed from a combination of different elements. The type of elements that can
be used in a Mesh depends on the Mesh's parametric dimension, which is set during Mesh creation. The
following are the valid Mesh element types for each valid Mesh parametric dimension (2D or 3D) .

\medskip

\begin{verbatim}

                     3                          4 ---------- 3
                    / \                         |            |
                   /   \                        |            |
                  /     \                       |            |
                 /       \                      |            |
                /         \                     |            |
               1 --------- 2                    1 ---------- 2

           ESMC_MESHELEMTYPE_TRI            ESMC_MESHELEMTYPE_QUAD

2D element types (numbers are the order for elementConn during
                  Mesh create)

\end{verbatim}

For a Mesh with parametric dimension of 2 the valid element types (illustrated above) are:

\smallskip

\begin{tabular}{|l|c|l|}
\hline
Element Type &  Number of Nodes  & Description \\
\hline
ESMC\_MESHELEMTYPE\_TRI  & 3 & A triangle \\
ESMC\_MESHELEMTYPE\_QUAD & 4 & A quadrilateral (e.g. a rectangle) \\
\hline
\end{tabular}

\medskip
\medskip

\begin{verbatim}

                 3                               8---------------7
                /|\                             /|              /|
               / | \                           / |             / |
              /  |  \                         /  |            /  |
             /   |   \                       /   |           /   |
            /    |    \                     5---------------6    |
           4-----|-----2                    |    |          |    |
            \    |    /                     |    4----------|----3
             \   |   /                      |   /           |   /
              \  |  /                       |  /            |  /
               \ | /                        | /             | /
                \|/                         |/              |/
                 1                          1---------------2

       ESMC_MESHELEMTYPE_TETRA             ESMC_MESHELEMTYPE_HEX

3D element types (numbers are the order for elementConn during
                  Mesh create)

\end{verbatim}

For a Mesh with parametric dimension of 3 the valid element types (illustrated above) are:

\smallskip

\begin{tabular}{|l|c|l|}
\hline
Element Type & Number of Nodes & Description \\
\hline
ESMC\_MESHELEMTYPE\_TETRA & 4 & A tetrahedron (CAN'T BE USED IN REGRID) \\
ESMC\_MESHELEMTYPE\_HEX  & 8 & A hexahedron (e.g. a cube) \\
\hline
\end{tabular}

\subsubsection{ESMF\_FILEFORMAT}
\label{const:mesh:cfileformat}

{\sf DESCRIPTION:\\}
This option is used by {\tt ESMF\_MeshCreate} to specify the type of the input grid file.
%See sections~\ref{sec:fileformat:scrip}, \ref{sec:fileformat:esmf} and \ref{sec:fileformat:ugrid} for a more
%detailed description of the supported file formats.

The type of this flag is:

{\tt type(ESMF\_FileFormat\_Flag)}

The valid values are:
\begin{description}
\item [ESMF\_FILEFORMAT\_SCRIP] SCRIP format grid file. The SCRIP format is the format accepted by the SCRIP regridding tool~\cite{ref:SCRIP}.   For Mesh creation, files of this type only work when the {\tt grid\_rank} in the file is equal to 1.

\item [ESMF\_FILEFORMAT\_ESMFMESH] ESMF unstructured grid file format. This format was developed by the ESMF team to match the capabilities of the Mesh class and to be efficient to convert to that class.

\item [ESMF\_FILEFORMAT\_UGRID] CF-convention unstructured grid file format. This format is a proposed extension to the
CF-conventions for unstructured grid data model. Currently, only the 2D flexible mesh topology is supported in ESMF.
\end{description}