% ========== Chapter on Artifact Rejection

\chapter {Aim 1.2: Algorithms to process neural data in context of ongoing stimulation}

\section{Introduction}

The interpretation of neural activity during concurrent electrical stimulation is a challenge. The stimulus artifact induced by electrical stimulation is often orders of magnitude greater than the neural signal of interest, confounding traditional neuroscience analytic techniques such as time-frequency analyses and event-related potential magnitudes \cite{Zhou2018}. How can we meaningfully interpret the neural response to stimulation during ongoing DCS?

Past approaches to dealing with the stimulus artifact problem have included template subtraction methods \cite{Hashimoto2002}.  Another employed locally fitting the recorded neural signals and subtracting the fit function for recordings from extracellular multielectrode array recordings on tissue slices \cite{Wagenaar2002}. For single pulse electrical stimulation, and the analysis of cortico-cortical evoked potentials \cite{Matsumoto2004b}, methods based off electrical modeling of the tissue-electrode interface to extract the physiological responses from artifacts have been implemented \cite{Trebaul2016}.

Filtering is another approach that has been used, but this runs into the issue of the overlap between the frequency spectra of the neural signal and that of the stimulus artifact, where subsequent filtering of frequency components of the artifact can induce distortions in the neural signal \cite{Nagel2000}. Recent progress has been made using a recursive Wiener filter to remove time domain artifacts in human electrocorticography recordings \cite{Mouthaan2016}.

Other groups have made software available for the analysis of neural signals with artifacts \cite{Erez2010, Herring2015}, but these from our experience tend to work on single trial, single pulse, or single channel bases. Additionally, SARGE, a generalized framework and MATLAB toolbox, by Erez et al., was developed in the context of tungsten microelectrode recordings from monkeys, and assumes saturation of an amplifier, yielding a period of non-usable signal. This presents an opportunity for analysis tools which process all channels simultaneously to allow for increased analytic throughput.

Additional methods decompose the signals into various components through methods such as independent component analysis (ICA), principal components analysis (PCA), and variants of empirical mode decomposition (EMD). Other recent work has employed sequential principal components regression, using generated templates across channels and sequential non-linear regression to extract neural signals \cite{OShea2017}. Another approach applied to deep brain stimulator recordings is an ensemble empirical mode decomposition based approach \cite{Al-ani2011}. Independent component analysis techniques have been applied to cochlear auditory evoked potential recordings \cite{Gilley2006} and optic nerve stimulation and subsequent visual cortex reactions in rabbits \cite{Lu2012}.  Work to separate spikes from retinal stimulation in primates has used an algorithm based on a structured Gaussian process \cite{Mena2017}.

With all of the work previously done, one may wonder why additional post-hoc tools are needed. Front-end hardware approaches that completely eliminate the need for post-processing would be ideal \cite{Zhou2018}, but these do not yet work without the need for further processing. Therefore, post-hoc processing algorithms are still valuable. Additionally, many existing algorithms and approaches have not been optimized or tuned for electrocorticography recordings or simultaneous electrocorticographic and deep brain stimulator recordings. Oftentimes software is written to handle single channels, or small groups of channels.

We here discuss the implementation of software for amplifiers that do not saturate during stimulation, to allow for analysis of ongoing trains or single pulses of electrical stimulation, during multi-channel macro-scale human electrocorticographic recordings from human subjects. We implement a suite of approaches for comparison metrics, which may prove useful for researchers in other fields. Additionally, we present sets of considerations and assumptions under which certain approaches may or may not be applicable. Also, we implement algorithms which extract the stimulation onset timing from a single channel, and using the knowledge of volume conduction timing relative to neural signal propagation, extract windows of artifacts for all other channels automatically. We provide options to recover within stimulation pulse evoked potentials, to dynamically detect the offset of stimuli pulses on a channel and trial-wise basis. In this way, we seek to create software that scales to the 128 channels or greater that are becoming common in human neurophysiology research.

Also important is the presentation of various curated human electrophysiologic data sets. These are all simple matrices of samples x channels x trials data, which may serve as test data sets for others in the field who seek to develop and compare algorithms. This hopefully serves as a catalyst towards more open science and data sharing in human electrophysiology.

\section{Methods}
By leveraging timing information on one channel, we are able to better detect and process signals on distant channels with smaller artifacts. We consider the recorded channel with the largest magnitude of artifact to be the channel to base the timing of all other artifacts off.

The first algorithms implemented were a simple linear interpolation scheme using the endpoints of the stimulus artifact onset and offset, and a shape-preserving piecewise cubic interpolation scheme using data points adjacent to the stimulus artifact. This has the disadvantage of discarding any high frequency content during this time period, which for trains of stimuli, can result in the loss of large amounts of information (Figure \ref{fig:exampInterp}). The next included an average across all individual stimulus pulses, which fails to capture individual variability in pulses and trials.

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.8\textwidth]{figures/artifactRejection/examp_trial_pchip_on_off}
	\caption[Example of linear interpolation]{Demonstrated is a simple linear interpolation scheme, which eliminates any information about the neural signal present during the stimulus artifact period. }
	\label{fig:exampInterp}
\end{figure}

\section{Template Extraction}

In order to address issues with slight temporal offsets between artifacts on given trials based on our windowing, as well as different stimulus artifacts across trials, we implement a dictionary discovery approach to discover all possible families of artifacts in a given window. Using a variant of the DBSCAN algorithm for clustering  \cite{Ester:1996:DAD:3001460.3001507}, we employ three different possible distance metrics, including euclidean distance, cosine similarity, and correlation, to extract possible templates  (Figure \ref{fig:templates}). These can be specified by the user, and modification to the distances required for grouping as part of a cluster may be needed depending on the data set.

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.8\textwidth]{figures/artifactRejection/templateClusters_33_dictMethod}
	\caption[Detected clusters for an example channel]{Example clusters on a given channel, across all trials. The thicker black lines represent the detected clusters, against which each individual artifact will be compared against and linearly subtracted from. }
	\label{fig:templates}
\end{figure}

\section{Template Matching}

Once a dictionary of templates has been discovered, we compare each detected artifact on each channel with the dictionary. The best matching artifact (correlation, euclidean distance, or cosine similarity) is subtracted linearly from the artifact, and the neural signal is recovered, allowing for further processing such as time-frequency analysis (Figures \ref{fig:693ffd_400ms_schematic}, \ref{fig:a1355e_priming_schematic}).

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.6\textwidth]{figures/artifactRejection/693ffd_400ms_schematic}
	\caption[Processing pipeline and subsequent time-frequency analysis for an example channel]{In the top plot, the raw, averaged time series during a 400 ms period of stimulation is demonstrated. The average, post-processed signal is shown in the middle plot, upon which time-frequency analysis, as shown in the bottom figure, can be performed. }
	\label{fig:693ffd_400ms_schematic}
\end{figure}

\begin{figure}[ht]
	\centering
	\includegraphics[width=1\textwidth]{figures/artifactRejection/a1355e_priming_schematic}
	\caption[Multiple electrode time series following stimulation extraction.]{This approach allows for the processing of many channels simultaneously. Demonstrated here are 10 example processed time series neural recordings, with the green box representing the duration during which the DCS was applied.
	}
	\label{fig:a1355e_priming_schematic}
\end{figure}

In order to assess the performance of our algorithm, we also compare the spectral information across the trials to quantify the reduction in frequency content at the stimulation pulse frequencies, as well as maintenance of other spectral content of interest. We quantify the reduction in artifact by the reduction in RMS value as measured in decibels. There is a trade off between decibel reduction and the loss of meaningful signal, which requires user oversight.

\section{Discussion}

We acknowledge that this approach is not appropriate for all instances of human electrophysiologic data. In particular, if a signal is relatively undersampled for short durations of stimuli, the performance of the algorithm will decrease to the point where the results are not satisfactory, and the neural activity recovered will. From our example data sets, our algorithm performed well with 12 kHz sampling, and poorly with 1.2 kHz sampling with pulse widths of 200 $ \mu s $. The use of upsampling is a future direction to explore for enhancing artifact rejection for slower sampling rates.

Furthermore, these recordings must be made on a system that does not saturate during stimulation, as if clipping occurs, this method will not be able to recover the underlying neural signals.

\section{Future Directions}

We will create a synthetic data set in order to establish as best we can a ground truth scenario. To do this, we will take an experiment where we have both stimulus-free and DCS periods. Upon the DCS period, we will run our algorithm to extract known clusters of activity. We will then apply a random amount of jitter in both time and amplitude to create synthetic artifacts similar to the distributions shown in Figure \ref{fig:templates}, and add these back to the the stimulus free period of recording from the same subject. This is inspired by O’Shea et al, who created synthetic data sets for their algorithm for processing stimulation contaminated recordings from penetrating electrodes in primates \cite{OShea2017}. We will then perform our artifact rejection steps, and compare both the evoked responses and time-frequency responses to validate performance of our algorithm.

As additional validation, and to ensure that the high frequency band information relevant to human physiology (High gamma band, 70-200 Hz), is minimally affected by our algorithm, we will perform analysis of cortical responses using the Lomb-Scargle periodogram \cite{Muller2017}. Briefly, this algorithm involves the elimination of any parts of the signal with known artifacts, and allows for the estimation of the power spectrum during this now unevenly sampled signal. By comparing the mean power across the signal using both our algorithm and the Lomb-Scargle periodogram, we can assess the effect of our processing on the frequency content of our signals.

To see if we can gain any increased performance we will attempt an alternative approach of upsampling each artifact period, and extract the most likely artifactual signal using a variant principal component regression \cite{OShea2017}. We will only use local components that have the same biphasic orientation as the recorded pulse in each channel, to best ensure that we recreate the signal.

A potential alternative to pursue would be the implementation of a Dirichlet Process Mixture Model \cite{Teh2010, Teh2006}, in order to use a non-parametric model to cluster the data.

\section{Code Availability}

Full MATLAB code and data sets are available at https://github.com/davidjuliancaldwell/artifactRejection

\section{Related Publications and presentations}

\noindent Caldwell DJ, “Understanding the Neural Response to Direct Cortical Stimulation”, UW Data Science Summit, April 2018 \\
\medskip

\noindent Caldwell DJ, "Engineering direct cortical stimulation in humans", UW Neural Computation and Engineering Connection, January 2018 \\
\medskip


\subsection{Hypercomplex numbers}


\section{Driver Classes}\label{chapter:ref:Drivers:Drivers}
The inversion minimizes an appropriate cost function $J$ to find the physical parameter distribution
(or more precisely the level set function) which gives the best fit to measured data. A
particular inversion case (gravity, magnetic or joint) is managed through
an instance of a specialization of the \class{InversionDriver} class. The task of the class instance
is to set up the appropriate cost function, to manage solution parameters and to run the optimization process.

\subsection{Template}
\begin{classdesc*}{InversionDriver}
template for inversion drivers.
\end{classdesc*}

\begin{methoddesc}[InversionDriver]{getCostFunction}{}
returns the cost function of the inversion. This will be an instance of the \class{InversionCostFunction} class, see Section~\ref{chapter:ref:inversion cost function}.
Use this method to access or alter attributes or call methods of the underlying cost function.
\end{methoddesc}

\begin{methoddesc}[InversionDriver]{getSolver}{}
returns the instance of the solver class used to minimize the cost function, see Chapter~\ref{chapter:ref:Minimization}.
Use this method to modify solver options.
\end{methoddesc}

\begin{methoddesc}[InversionDriver]{getDomain}{}
returns the domain of the inversion as an \escript \class{Domain} object.
\end{methoddesc}

\begin{methoddesc}[InversionDriver]{setSolverMaxIterations}{\optional{maxiter=\None}}
sets the maximum number of iteration steps for the solver used to minimize the cost function. The default value is 200.
If the maximum number is reached, the iteration will be terminated and \exception{MinimizerMaxIterReached} is thrown.
\end{methoddesc}

\begin{methoddesc}[InversionDriver]{setSolverTolerance}{\optional{m_tol=\None} \optional{, J_tol=\None}}
set the tolerance for the solver used to minimize the cost function. If \member{m_tol} is set the iteration is terminated
if the relative change of the level set function is less than or equal \member{m_tol}, see condition~\ref{EQU:MIN:3a}.
If \member{J_tol} is set the iteration is terminated if the change of the cost
function relative to the initial value is less than or equal \member{J_tol}, , see condition~\ref{EQU:MIN:3b}.
If both tolerances are set both stopping criteria need to be met.
By default \member{tol}=1e-4 and \member{J_tol}=\None.
\end{methoddesc}

\begin{methoddesc}[InversionDriver]{getLevelSetFunction}{}
returns the level set function as solution of the optimization problem.
This method can only be called if the optimization process as been completed.
If the iteration failed the last available approximation of the solution is returned.
\end{methoddesc}

\begin{methoddesc}[InversionDriver]{run}{}
this method runs the optimization solver and returns the physical parameter(s)
from the output of the inversion. Notice that the \method{setup} method must be
called before the first call of \method{run}.
The call can fail as the maximum number of iterations is reached in which case
a \exception{MinimizerMaxIterReached} exception is thrown or as there is an
incurable break down in the iteration in which case a \exception{MinimizerIterationIncurableBreakDown} exception is thrown.
\end{methoddesc}

\subsection{Gravity Inversion Driver}
For examples of usage please see Chapter~\ref{Chp:cook:gravity inversion}.

\begin{classdesc}{GravityInversion}{\optional{solverclass=None}
\optional{, fixGravityPotentialAtBottom=False}
}
Driver class to perform an inversion of Gravity (Bouguer) anomaly data.
This class is a sub-class of \class{InversionDriver}. The class uses the
standard \class{Regularization} for a single level set function,
see Chapter~\ref{Chp:ref:regularization}, \class{DensityMapping} mapping,
see Section~\ref{Chp:ref:mapping density}, and the gravity forward model
\class{GravityModel}, see Section~\ref{sec:forward gravity}.
\member{solverclass} set the solver class to be used for inversion,
see Chapter~\ref{chapter:ref:Minimization}.
 By default the limited-memory Broyden-Fletcher-Goldfarb-Shanno (\emph{L-BFGS})~\cite{Nocedal1980}\index{L-BFGS} solver is used.
If \member{fixGravityPotentialAtBottom} is set \optional{, fixGravityPotentialAtBottom=False}to \True the gravity potential at the bottom is set to zero.
\end{classdesc}

\begin{methoddesc}[GravityInversion]{fixGravityPotentialAtBottom}{\optional{status=\True}}
If \member{status} is \True the gravity potential at the bottom is set to zero. Otherwise  the gravity
 potential at the top is set to zero only.
\end{methoddesc}

\begin{methoddesc}[GravityInversion]{setup}{
domainbuilder
\optional{, rho0=\None}
\optional{, drho=\None}
\optional{, z0=\None}
\optional{, beta=\None}
\optional{, w0=\None}
\optional{, w1=\None}
\optional{, rho_at_depth=\None}
}

sets up the inversion from an instance \member{domainbuilder} of a \class{DomainBuilder}, see Section~\ref{Chp:ref:domain builder}.
Only gravitational data attached to the \member{domainbuilder} are considered in the inversion.
\member{rho0} defines a reference density anomaly (default is 0),
\member{drho} defines a density anomaly (default is $2750 \frac{kg}{m^3}$),
\member{z0} defines the depth weighting reference depth (default is \None), and
\member{beta} defines the depth weighting exponent (default is \None),
see \class{DensityMapping} in Section~\ref{Chp:ref:mapping density}.
\member{w0} and \member{w1} define the weighting factors
$\omega^{(0)}$ and
$\omega^{(1)}$, respectively (see Equation~\ref{EQU:REG:1}).
By default \member{w0}=\None and \member{w1}=1 are used.
\member{rho_at_depth} sets the value for density at depth. This is only used if density is fixed below a certain depth,
see \class{Domain Builder} in Section~\ref{Chp:ref:domain builder}.
\end{methoddesc}

\begin{methoddesc}[GravityInversion]{setInitialGuess}{\optional{rho=\None}}
sets an initial guess for the density anomaly. By default zero is used.
\end{methoddesc}

\subsection{Magnetic Inversion Driver}
For examples of usage please see Chapter~\ref{Chp:cook:magnetic inversion}.

\begin{classdesc}{MagneticInversion}{\optional{solverclass=None}, \optional{self_demagnetization=\False}
}
Driver class to perform an inversion of magnetic anomaly data. This class
is a sub-class of \class{InversionDriver}. The class uses the standard
\class{Regularization} class for a single level set function, see Chapter~\ref{Chp:ref:regularization},
\class{SusceptibilityMapping} mapping, see Section~\ref{Chp:ref:mapping susceptibility},
and the magnetic forward model \class{SelfDemagnetizationModel} (if \member{self_demagnetization}=\True,
see Section~\ref{sec:forward self demagnetic}) or \class{MagneticModel}
(if \member{self_demagnetization}=\False, see Section~\ref{sec:forward magnetic}).
\member{solverclass} set the solver class to be used for inversion,
see Chapter~\ref{chapter:ref:Minimization}.
 By default the limited-memory Broyden-Fletcher-Goldfarb-Shanno (\emph{L-BFGS})~\cite{Nocedal1980}\index{L-BFGS} solver is used.

\end{classdesc}

\begin{methoddesc}[MagneticInversion]{fixMagneticPotentialAtBottom}{\optional{status=\True}}
If \member{status} is \True the magnetic potential at the bottom is set to zero. Otherwise  the magnetic
 potential at the top is set to zero only.
\end{methoddesc}

\begin{methoddesc}[MagneticInversion]{setup}{
domainbuilder
\optional{, k0=\None}
\optional{, dk=\None}
\optional{, z0=\None}
\optional{, beta=\None}
\optional{, w0=\None}
\optional{, w1=\None}
\optional{, k_at_depth=\None}
}

sets up the inversion from an instance \member{domainbuilder} of a \class{DomainBuilder}, see Section~\ref{Chp:ref:domain builder}.
Only magnetic data attached to the \member{domainbuilder} are considered in the inversion.
\member{k0} defines a reference susceptibility anomaly (default is $0$),
\member{dk} defines a susceptibility anomaly scale (default is $1$),
\member{z0} defines the depth weighting reference depth (default is \None), and
\member{beta} defines the depth weighting exponent (default is \None),
see \class{SusceptibilityMapping} in Section~\ref{Chp:ref:mapping susceptibility}.
\member{w0} and \member{w1} define the weighting factors
$\omega^{(0)}$ and
$\omega^{(1)}$, respectively (see equation~\ref{EQU:REG:1}).
By default \member{w0}=\None and \member{w1}=1 are used.
\member{k_at_depth} sets the value for susceptibility at depth. This is only used if susceptibility is fixed below a certain depth,
see \class{Domain Builder} in Section~\ref{Chp:ref:domain builder}.
\end{methoddesc}

\begin{methoddesc}[MagneticInversion]{setInitialGuess}{\optional{k=\None}}
sets an initial guess for the susceptibility anomaly. By default zero is used.
\end{methoddesc}

\subsection{Gravity and Magnetic Joint Inversion Driver}
For examples of usage please see Chapter~\ref{Chp:cook:joint inversion}.

\begin{classdesc}{JointGravityMagneticInversion}{\optional{solverclass=None}
, \optional{self_demagnetization=\False}
}
Driver class to perform a joint inversion of Gravity (Bouguer) and magnetic anomaly data.
This class is a sub-class of \class{InversionDriver}.
The class uses the standard \class{Regularization} for two level set functions
with cross-gradient correlation, see Chapter~\ref{Chp:ref:regularization},
\class{DensityMapping} and \class{SusceptibilityMapping} mappings, see Section~\ref{Chp:ref:mapping}, the
gravity forward model \class{GravityModel}, see Section~\ref{sec:forward gravity}
and the magnetic forward model \class{SelfDemagnetizationModel} (if \member{self_demagnetization}=\True,
see Section~\ref{sec:forward self demagnetic}) or \class{MagneticModel}
(if \member{self_demagnetization}=\False, see Section~\ref{sec:forward magnetic}).
\member{solverclass} set the solver class to be used for inversion,
see Chapter~\ref{chapter:ref:Minimization}.
 By default the limited-memory Broyden-Fletcher-Goldfarb-Shanno (\emph{L-BFGS})~\cite{Nocedal1980}\index{L-BFGS} solver is used.
\end{classdesc}

\begin{methoddesc}[JointGravityMagneticInversion]{fixGravityPotentialAtBottom}{\optional{status=\True}}
If \member{status} is \True the gravity potential at the bottom is set to zero. Otherwise  the gravity
 potential at the top is set to zero only.
\end{methoddesc}

\begin{methoddesc}[JointGravityMagneticInversion]{fixMagneticPotentialAtBottom}{\optional{status=\True}}
If \member{status} is \True the magnetic potential at the bottom is set to zero. Otherwise  the magnetic
 potential at the top is set to zero only.
\end{methoddesc}

\begin{methoddesc}[JointGravityMagneticInversion]{setup}{
domainbuilder
\optional{, rho0=\None}
\optional{, drho=\None}
\optional{, rho_z0=\None}
\optional{, rho_beta=\None}
\optional{, k0=\None}
\optional{, dk=\None}
\optional{, k_z0=\None}
\optional{, k_beta=\None}
\optional{, w0=\None}
\optional{, w1=\None}
\optional{, w_gc=\None}
\optional{, rho_at_depth=\None}
\optional{, k_at_depth=\None}
}

sets up the inversion from an instance \member{domainbuilder} of a \class{DomainBuilder}, see Section~\ref{Chp:ref:domain builder}.
Gravity and magnetic data attached to the \member{domainbuilder} are considered in the inversion.
\member{rho0} defines a reference density anomaly (default is $0$),
\member{drho} defines a density anomaly (default is $2750 \frac{kg}{m^3}$),
\member{rho_z0} defines the depth weighting reference depth for density (default is \None), and
\member{rho_beta} defines the depth weighting exponent for density (default is \None),
see \class{DensityMapping} in Section~\ref{Chp:ref:mapping density}.
\member{k0} defines a reference susceptibility anomaly (default is $0$),
\member{dk} defines a susceptibility anomaly scale (default is $1$),
\member{k_z0} defines the depth weighting reference depth for susceptibility (default is \None), and
\member{k_beta} defines the depth weighting exponent for susceptibility (default is \None),
see \class{SusceptibilityMapping} in Section~\ref{Chp:ref:mapping susceptibility}.
\member{w0} and \member{w1} define the weighting factors
$\omega^{(0)}$ and
$\omega^{(1)}$, respectively (see Equation~\ref{EQU:REG:1}).
\member{w_gc} sets the weighting factor $\omega^{(c)}$ for the cross gradient term.
By default \member{w0}=\None, \member{w1}=1 and \member{w_gc}=1 are used.
\member{k_at_depth} sets the value for susceptibility at depth. This is only used if susceptibility is fixed below a certain depth,
see \class{Domain Builder} in Section~\ref{Chp:ref:domain builder}.
\member{rho_at_depth} sets the value for density at depth. This is only used if density is fixed below a certain depth,
see \class{Domain Builder} in Section~\ref{Chp:ref:domain builder}.
\end{methoddesc}

\begin{methoddesc}[JointGravityMagneticInversion]{setInitialGuess}{\optional{rho=\None, } \optional{k=\None}}
sets initial guesses for density and susceptibility anomaly.
By default zero is used for both.
\end{methoddesc}


\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}

\begin{document}
\section{List of runs}

\subsection{Glossary}
\begin{itemize}
    \item W : Only waves runs
    \item WR : Only waves runs with rotation
    \item WV : Wave-vortex runs
    \item WVR : Wave-vortex runs with rotation
    \item $t_{stat}$ : Time when the run is approximately stationary
    \item $t_{max}$ : Time until which the run was simulated
    \item $\frac{<\bf \Omega_0 >}{{(P k_f^2)}^{2/3}}$ : Initial enstrophy - forcing power ratio
\end{itemize}

\subsection{Tables}
\begin{tabular}{lrrrrrrr}
\toprule
{} &   $n$ &  $c$ &  $\nu_8$ &  $\epsilon$ &  $\frac{k_{diss}}{k_f}$ &   $F_f$ &  $t_{\max}$ \\
\midrule
W1  &   960 &   10 & 1.56e-10 &        1.04 &                    28.8 &   0.163 &          50 \\
W2  &  1920 &   10 & 9.68e-13 &        1.06 &                    57.7 &   0.164 &        49.9 \\
W3  &  3840 &   10 &    6e-15 &         1.1 &                     115 &   0.166 &          50 \\
W4  &  7680 &   10 & 3.72e-17 &         1.2 &                     231 &   0.171 &        25.2 \\
W5  &   960 &   20 & 1.56e-10 &           1 &                    28.8 &  0.0806 &          50 \\
W6  &  1920 &   20 & 9.69e-13 &        1.02 &                    57.7 &  0.0809 &         120 \\
W7  &  3840 &   20 & 6.01e-15 &        1.08 &                     115 &  0.0825 &         120 \\
W8  &  7680 &   20 & 3.72e-17 &        1.21 &                     231 &  0.0857 &         120 \\
W9  &   960 &   40 & 1.56e-10 &       0.996 &                    28.8 &  0.0402 &        49.9 \\
W10 &  1920 &   40 & 9.68e-13 &       0.998 &                    57.7 &  0.0402 &        49.9 \\
W11 &  3840 &   40 &    6e-15 &        1.06 &                     115 &  0.0411 &        49.9 \\
W12 &  7680 &   40 & 3.72e-17 &        1.17 &                     231 &  0.0424 &        40.8 \\
W13 &   960 &  100 & 1.56e-10 &       0.999 &                    28.8 &  0.0161 &        49.9 \\
W14 &  1920 &  100 & 9.69e-13 &        1.01 &                    57.7 &  0.0161 &         120 \\
W15 &  3840 &  100 & 6.01e-15 &        1.06 &                     115 &  0.0164 &         120 \\
W16 &  7680 &  100 & 3.72e-17 &        1.22 &                     231 &  0.0172 &        95.9 \\
W17 &   960 &  400 & 1.56e-10 &        1.14 &                    28.8 &  0.0042 &         120 \\
W18 &  1920 &  400 & 9.69e-13 &        1.15 &                    57.7 & 0.00422 &         120 \\
W19 &  3840 &  400 & 6.01e-15 &        1.12 &                     115 & 0.00418 &         120 \\
W20 &   960 &  700 & 1.56e-10 &        1.27 &                    28.8 & 0.00249 &        49.9 \\
W21 &  1920 &  700 & 9.68e-13 &        1.05 &                    57.7 & 0.00234 &        49.9 \\
\bottomrule
\end{tabular}
\begin{tabular}{lrrrrrrrrrrr}
\toprule
{} &   $n$ &  $c$ &  $\nu_8$ &  $f$ &  $\epsilon$ &  $\frac{k_{diss}}{k_f}$ &  $F_f$ &  $Ro_f$ &  $Bu$ &  $t_{stat}$ &  $t_{\max}$ \\
\midrule
WR1 &  1920 &   20 & 9.68e-13 & 21.3 &       0.838 &                    57.7 & 0.0759 &  0.0171 &   0.5 &          11 &         100 \\
WR2 &  1920 &   20 & 9.68e-13 & 15.1 &       0.894 &                    57.7 & 0.0775 &  0.0247 &     1 &        7.92 &        99.9 \\
WR3 &  1920 &   20 & 9.68e-13 & 10.7 &       0.938 &                    57.7 & 0.0788 &  0.0355 &     2 &        6.62 &        99.9 \\
WR4 &  1920 &   20 & 9.68e-13 & 7.54 &        0.98 &                    57.7 & 0.0799 &  0.0509 &     4 &        6.12 &        99.9 \\
\bottomrule
\end{tabular}
\begin{tabular}{lrrrrrrrrr}
\toprule
{} &   $n$ &  $c$ &  $\nu_8$ &  $\epsilon$ &  $\frac{k_{diss}}{k_f}$ &   $F_f$ &  $\frac{<\bf \Omega_0 >}{{(P k_f^2)}^{2/3}}$ &  $t_{stat}$ &  $t_{\max}$ \\
\midrule
WV1  &   960 &   20 &        0 &       0.926 &                     5.4 &  0.0784 &                                            1 &        4.88 &          25 \\
WV2  &  1920 &   20 & 1.11e-12 &        1.02 &                    56.6 &  0.0809 &                                         0.01 &        5.71 &        49.9 \\
WV3  &  1920 &   20 & 1.11e-12 &        1.02 &                    56.6 &  0.0811 &                                          0.1 &        5.71 &         100 \\
WV4  &  1920 &   20 & 1.11e-12 &           1 &                    56.6 &  0.0805 &                                            1 &        5.41 &          50 \\
WV5  &  1920 &   20 & 1.11e-12 &        1.16 &                    56.6 &  0.0846 &                                           10 &        4.12 &        49.9 \\
WV6  &  1920 &  100 & 1.11e-12 &        1.02 &                    56.6 &  0.0162 &                                         0.01 &        11.1 &         100 \\
WV7  &  1920 &  100 & 1.11e-12 &        1.02 &                    56.6 &  0.0162 &                                          0.1 &        11.1 &         100 \\
WV8  &  1920 &  100 & 1.11e-12 &        1.01 &                    56.6 &  0.0162 &                                            1 &        10.7 &          50 \\
WV9  &  1920 &  100 & 1.11e-12 &        1.07 &                    56.6 &  0.0164 &                                           10 &        8.72 &         100 \\
WV10 &  1920 &  100 & 1.11e-12 &        2.21 &                    56.6 &   0.021 &                                          100 &         1.5 &          50 \\
WV11 &  1920 &  400 & 1.11e-12 &        1.03 &                    56.6 & 0.00406 &                                         0.01 &        20.7 &        49.9 \\
WV12 &  1920 &  400 & 1.11e-12 &        1.08 &                    56.6 & 0.00413 &                                          0.1 &        19.3 &         100 \\
WV13 &  1920 &  400 & 1.11e-12 &        1.04 &                    56.6 & 0.00408 &                                            1 &        18.4 &        49.9 \\
WV14 &  1920 &  400 & 1.11e-12 &        1.17 &                    56.6 & 0.00424 &                                           10 &        18.3 &         100 \\
WV15 &  1920 &  400 & 1.11e-12 &        1.89 &                    56.6 & 0.00497 &                                          100 &           5 &        49.9 \\
\bottomrule
\end{tabular}
\begin{tabular}{lrrrrrrrrrrrr}
\toprule
{} &   $n$ &  $c$ &  $\nu_8$ &  $f$ &  $\epsilon$ &  $\frac{k_{diss}}{k_f}$ &  $F_f$ &  $Ro_f$ &  $Bu$ &  $\frac{<\bf \Omega_0 >}{{(P k_f^2)}^{2/3}}$ &  $t_{stat}$ &  $t_{\max}$ \\
\midrule
WVR1  &  1920 &   20 & 1.11e-12 & 7.54 &        1.03 &                    56.6 & 0.0813 &  0.0518 &     4 &                                         0.01 &           8 &         100 \\
WVR2  &  1920 &   20 & 1.11e-12 & 3.37 &        1.03 &                    56.6 & 0.0812 &   0.116 &    20 &                                            1 &        6.52 &        99.9 \\
WVR3  &  1920 &  100 & 1.11e-12 & 75.4 &       0.932 &                    56.6 & 0.0157 &   0.005 &     1 &                                         0.01 &        22.6 &        99.9 \\
WVR4  &  1920 &  100 & 1.11e-12 & 75.4 &       0.915 &                    56.6 & 0.0156 & 0.00497 &     1 &                                          0.1 &        22.9 &        99.9 \\
WVR5  &  1920 &  100 & 1.11e-12 & 75.4 &        1.14 &                    56.6 & 0.0168 & 0.00536 &     1 &                                            1 &        22.7 &        99.9 \\
WVR6  &  1920 &  100 & 1.11e-12 & 53.3 &       0.991 &                    56.6 &  0.016 & 0.00722 &     2 &                                         0.01 &        19.2 &        99.9 \\
WVR7  &  1920 &  100 & 1.11e-12 & 53.3 &       0.998 &                    56.6 & 0.0161 & 0.00724 &     2 &                                          0.1 &        19.3 &        99.9 \\
WVR8  &  1920 &  100 & 1.11e-12 & 53.3 &        1.06 &                    56.6 & 0.0164 & 0.00739 &     2 &                                            1 &        19.4 &        99.9 \\
WVR9  &  1920 &  100 & 1.11e-12 & 37.7 &        1.04 &                    56.6 & 0.0163 &  0.0104 &     4 &                                         0.01 &        16.8 &         100 \\
WVR10 &  1920 &  100 & 1.11e-12 & 37.7 &        1.04 &                    56.6 & 0.0163 &  0.0104 &     4 &                                          0.1 &        16.6 &         100 \\
WVR11 &  1920 &  100 & 1.11e-12 & 37.7 &        1.04 &                    56.6 & 0.0163 &  0.0104 &     4 &                                            1 &        16.3 &         100 \\
WVR12 &  1920 &  100 & 1.11e-12 & 37.7 &        1.25 &                    56.6 & 0.0173 &   0.011 &     4 &                                           10 &        12.7 &         100 \\
WVR13 &  1920 &  100 & 1.11e-12 & 37.7 &        1.66 &                    56.6 &  0.019 &  0.0121 &     4 &                                          100 &         1.6 &         100 \\
\bottomrule
\end{tabular}
\end{document}


\documentclass[10pt,preprint]{aastex}
\usepackage{natbib}
\usepackage[normalem]{ulem}
\bibliographystyle{apj}

\newcommand{\Ovec}{{\vec O}}
\newcommand{\east}{{\hat E}}
\newcommand{\rvec}{{\vec r}}
\newcommand{\uvec}{{\hat r}}
\newcommand{\zhat}{{\hat z}}
\newcommand{\alt}{\mathrm{Alt}_0}
\newcommand{\az}{\mathrm{Az}_0}
\newcommand{\ITRS}{\mathrm{ITRS}}
\newcommand{\GCRS}{\mathrm{GCRS}}
\newcommand{\JD}{\mathrm{JD}}
\newcommand{\UTone}{\mathrm{UT1}}
\newcommand{\UTC}{\mathrm{UTC}}
\newcommand{\ENU}{\mathrm{ENU}}
\newcommand{\NWU}{\mathrm{NWU}}
\newcommand{\UEN}{\mathrm{UEN}}
\newcommand{\LA}{\mathrm{LA}}
\newcommand{\IERS}{\mathrm{IERS}}

\newcommand{\rhat}{{\hat r}}
\newcommand{\rhorn}{{\hat r}_\mathrm{horn}}
\newcommand{\rfocal}{{\hat r}_\mathrm{focal}}
\newcommand{\robs}{{\hat r}_\mathrm{obs}}
\newcommand{\rtopo}{{\hat r}_\mathrm{topo}}
\newcommand{\rgcrs}{{\hat r}_\mathrm{GCRS}}
\newcommand{\rbcrs}{{\hat r}_\mathrm{BCRS}}

\begin{document}
\title{ACTpol Pointing}
\author{Mike Nolta\\\today}

\begin{abstract}
How \texttt{libactpol} converts from telescope to celestial coordinates.
See the appendix for a glossary of definitions, and see \citet{usno179} for more
information about the coordinate systems.
\end{abstract}

\section{Overview}

\begin{enumerate}
\item Convert telescope encoders to horizon coordinates.
\item Correct for atmospheric refraction.
\item Boost to cancel Earth's rotation (diurnal abberation).
\item Translate to Earth barycenter (diurnal parallax) [currently neglected].
\item Rotate to crust-fixed coordinates (the ITRS).
\item Rotate to Earth-centered celestial coordinates (the GCRS).
\item Boost to cancel Earth's orbital velocity (annual aberration).
\item Translate to Solar barycenter (the BCRS/ICRS) (annual parallax) [currently neglected].
\end{enumerate}

\section{Step 1: Telescope $\to$ Horizon}

We start by defining feedhorn-centric coordinates:
$\hat x$ and $\hat y$ along the detector polarization directions
and $\hat z$ pointing toward the sky along the line of sight.
Next, we need to define the rotation from feedhorn- to boresight-centric coordinates:
\begin{eqnarray}
\rfocal = R_1(f_y)R_2(-f_x)R_3(f_\phi) \rhorn
\end{eqnarray}
This convention was chosen so that $f_x,f_y,f_\phi$ match Ben's array layout spreadsheet.
Fig.~\ref{fig:focalplane} shows the expected PA1 focalplane layout.
Adopting NWU (``north, west, up'') as the axes of our horizon coordinates,
\begin{eqnarray}
\robs = R_3(\az)R_2(\alt-\pi/2)R_3(-\pi) \rfocal
\end{eqnarray}
where $\alt,\az$ are the boresight coordinates.

\begin{figure}
\plotone{focalplane.eps}
\caption{The ACTpol PA1 focalplane. The $x$-axis is $(\rfocal\cdot\hat x)(180/\pi)$,
and similarly for the $y$-axis.\label{fig:focalplane}}
\end{figure}

\section{Step 2: Miasma Theory}

Atmospheric refraction makes objects appear higher in the sky than they really are,
so we need to apply an \sout{attitude} altitude adjustment
\begin{eqnarray}
\rtopo = R_3(\az)R_2(-\xi_0)R_3(-\az) \robs.
\end{eqnarray}
Note that, for the moment, we have neglected the variation of $\xi$ across the array,
which is ${\cal O}(1\arcsec)$.

To calculate $\xi$, we use the \texttt{slalib:slaRefro} routine, which is
a function of the telescope position (elevation \& latitude), the observing
frequency, and the local weather conditions (pressure, temperature, relative humidity,
\& tropospheric lapse rate).
We fix the tropospheric lapse rate to its standard value, $6.5\,\mathrm{K/km}$.
Fig.~\ref{fig:ref} plots $\xi$ versus altitude for various weather conditions,
showing that $\xi$ is most sensitive to the temperature and humidity.

\begin{figure}
\plotone{refraction.eps}
\caption{ACTpol site refraction correction for various weather conditions.\label{fig:ref}}
\end{figure}

\section{Steps 3--5: Journey to the Center of the Earth}

Now we want to shift our coordinates to the Earth's barycenter, which requires
a combination of a boost (to cancel out the Earth's rotation), a rotation, and a translation.

Let $\vec v_r$ be ACTpol's velocity relative to the Earth's barycenter, and $\vec\beta_r\equiv\vec v_r/c$.
Since $|\vec\beta_r| \ll 1$, we can approximate the aberration correction as
\begin{eqnarray}
\rhat_\LA = R(\rtopo\times\vec\beta_r) \rtopo
\end{eqnarray}
where $R(\vec\delta)$ is a clockwise rotation about the $\hat\delta$-axis by $|\vec\delta|$ radians.

ACTpol's position on the surface of the Earth, in geocentric coordinates, is
\begin{eqnarray}
\Ovec_\ITRS &=& \left(\begin{array}{l}
(aC+h_G) \cos\phi_G \cos\lambda_G \\
(aC+h_G) \cos\phi_G \sin\lambda_G \\
(aS+h_G) \sin\phi_G \\
\end{array}\right)
\end{eqnarray}
where
\begin{eqnarray}
1/C^2 &=& \cos^2\phi_G + (1-f)^2\sin^2\phi_G \\
S &=& (1-f)^2 C \\
f &=& 1/298.257223563 \\
a &=& 6378137\,\mathrm{m}
\end{eqnarray}
The values of $a$ and $f$ are from WGS84.\footnote{
At our level of precision GPS $\approx$ WGS84 $\approx$ ITRS, so we'll use them interchangeably.}
Thus ACTpol's velocity due to the Earth's rotation is
\begin{eqnarray}
\vec\beta_r &=& \frac{\omega}{c}\zhat_\ITRS\times\Ovec_\ITRS
\\
&=& \frac{\omega}{c} (aC+h_G) \cos\phi_G \east
\\
&\approx& 0.295043 \arcsec\east
\end{eqnarray}
where $\omega = 7.292115\times10^{-5}\,\mathrm{rad/s}$ is the Earth's nominal mean angular speed,
and $\east$ is the unit vector pointing east.

Now that we've corrected for diurnal aberration, we need to translate and rotate into geocentric
coordinates. We'll assume the target is infinitely far away and ignore the translation.
Since we chose the NWU horizon basis,
\begin{eqnarray}
\rhat_\ITRS &=& R_3(-\lambda_G) R_2(\phi_G-\pi/2) R_3(-\pi) \rhat_\LA
\end{eqnarray}

\section{Step 6: ITRS $\to$ GCRS}

For our purposes the conversion from ITRS to GCRS is a black box, simply a complex time-dependent rotation matrix.
From Fig.~5.1 of \cite{iers2010}, we find
\begin{eqnarray}
\rhat_\GCRS &=& R_3(-E) R_2(-d) R_3(E + s - \theta - s')R_2(x_p)R_1(y_p) \rhat_\ITRS
\end{eqnarray}
where
\begin{enumerate}
\item $(\sin d \cos E, \sin d \sin E, \cos d) \equiv (X,Y,Z)
= (X,Y,\sqrt{1 - X^2 - Y^2})$.
\item $(X,Y,s)$ are calculated by \texttt{sofa:iauXys06a}.
We ignore the corrections $(\Delta X,\Delta Y)_{2006} \approx 0.1\,\mathrm{mas}$.
\item $\theta$ is calculated by \texttt{sofa:iauEra00}.
\item We ignore $s' = -47T\,\mu\mathrm{as}$, where $T$ is time in centuries since J2000.0.
\item $(x_p,y_p) \approx (x,y)_\IERS$ tabulated in IERS Bulletin A.
\end{enumerate}

\section{Steps 7--8: Stop the World, I Want to Get Off}

Let $\vec v_o$ be the velocity of Earth's barycenter relative to the solar barycenter, and $\vec\beta_o\equiv\vec v_o/c$.
\begin{eqnarray}
\rbcrs = R(\rgcrs\times\vec\beta_o) \rgcrs
\end{eqnarray}
We use the \texttt{sofa:iauEpv00} routine to calculate $\vec v_o$.
For efficiency, we only calculate $\vec v_o$ once every 2.4~seconds, which is approximately the time
it takes $\vec v_o$ to rotate by $0.1\arcsec$.

\nocite{*}
\bibliography{references}
\appendix

\section{Glossary}

\begin{tabular}{ll}
BCRS & Barycentric Celestial Reference System \\
CIO & Celestial Intermediate Origin \\
CIP & Celestial Intermediate Pole \\
GCRS & Geocentric Celestial Reference System \\
GPS & Global Positioning System \\
ICRS & International Celestial Reference System \\
IERS & International Earth Rotation \& Reference Systems Service \\
ITRS & International Terrestrial Reference System \\
JD & Julian date \\
UT1 & Universal Time \\
UTC & Coordinated Universal Time \\
WGS84 & World Geodetic System 1984 \\
$\az$ & observed boresight azimuth \\
$\alt$ & observed boresight elevation \\
$h_G$ & geodetic height (ACTpol = 5188 m) \\
$\lambda_G$ & geodetic east longitude (ACTpol = $-67.7876^\circ$) \\
$\phi_G$ & geodetic latitude (ACTpol = $-22.9585^\circ$) \\
$R_1(\psi)$ & $\hat x$-axis clockwise rotation matrix \\
$R_2(\psi)$ & $\hat y$-axis clockwise rotation matrix \\
$R_3(\psi)$ & $\hat z$-axis clockwise rotation matrix \\
$R(\vec\delta)$ & $\hat\delta$-axis rotation matrix \\
$s$ & CIO locator \\
$\theta$ & Earth Rotation Angle \\
$x_p$, $y_p$ & standard polar wobble parameters \\
$X$, $Y$, $Z$ & components of unit vector towards the CIP in the GCRS
\end{tabular}

\begin{eqnarray}
R_1(\alpha) &=&
\left(\begin{array}{ccc}
1 & 0 & 0 \\
0 & \cos\alpha & \sin\alpha \\
0 & -\sin\alpha & \cos\alpha \\
\end{array}\right)
\\
R_2(\alpha) &=&
\left(\begin{array}{ccc}
\cos\alpha & 0 & -\sin\alpha \\
0 & 1 & 0 \\
\sin\alpha & 0 & \cos\alpha \\
\end{array}\right)
\\
R_3(\alpha) &=&
\left(\begin{array}{ccc}
\cos\alpha & \sin\alpha & 0 \\
-\sin\alpha & \cos\alpha & 0 \\
0 & 0 & 1 \\
\end{array}\right)
\end{eqnarray}

\section{Polarization Convention}

Given a line of sight vector $\hat r$ and polarization direction $\hat p$,
$(\sin\gamma,\cos\gamma) = (\hat p \cdot \hat w, \hat p \cdot \hat n)$, where
\begin{eqnarray}
\hat w &\propto& \hat r \times \hat z
\\
\hat n &=& \hat w \times \hat r
\end{eqnarray}

\end{document}


% !TEX root = ./bursty_transcription.tex
\section{Finding the ``right'' model: Bayesian parameter inference}
\label{section_04_bayesian_inference}

In this section of the paper, we continue our program of providing one complete
description of the entire broad sweep of studies that have been made in the
context of the repressor-operator model, dating all the way back to the original
work of Jacob and Monod and including the visionary quantitative work of
M\"{u}ller-Hill and collaborators~\cite{Oehler1990} and up to more recent
studies \cite{Garcia2011a}. In addition, the aim is to reconcile the equilibrium
and non-equilibrium perspectives that have been brought to bear on this problem.
From Section~\ref{section_02_means}, this reconciliation depends on a key
quantitative question as codified by Eq.~\ref{eq:deltaFR_eq_noneq_equiv}: does
the free energy of repressor binding, as described in the equilibrium models and
indirectly inferred from gene expression measurements, agree with the
corresponding values of repressor binding and unbinding rates in the
non-equilibrium picture, measured or inferred more directly? In this section we
tackle the statistical inference problem of inferring these repressor rates from
single-cell mRNA counts data. But before we can turn to the full case of simple
repression, we must choose an appropriate model of the constitutive promoter and
infer the parameter values in that model. This is the problem we address first.

\subsection{Parameter inference for constitutive promoters}

From consideration of Fano factors in the previous section, we suspect that
model 5 in Figure~\ref{fig2:constit_cartoons}(A), a one-state bursty model of
constitutive promoters, achieves the right balance of complexity and simplicity,
by allowing both Fano factor $\nu>1$, but also by remedying, by design, the
problems of parameter degeneracy that model 4 in
Figure~\ref{fig2:constit_cartoons} suffered~\cite{Razo-Mejia2020}. Does this
stand up to closer scrutiny, namely, comparison to full mRNA distributions
rather than simply their moments? We will test this thoroughly on single-cell
mRNA counts for different unregulated promoters from Jones et.\
al.~\cite{Jones2014}.

It will be instructive, however, to first consider the Poisson promoter, model 1
in Figure~\ref{fig2:constit_cartoons}. As we alluded to earlier, since the
Poisson distribution has a Fano factor $\nu$ strictly equal to 1, and all of the
observed data in Figure~\ref{fig2:constit_cartoons}(B) has Fano factor $\nu>1$,
we might already suspect that this model is incapable of fitting the data. We
will verify that this is in fact the case. Using the same argument we can
immediately rule out models 2 and 3 from Figure~\ref{fig2:constit_cartoons}(A).
These models have Fano factors $\nu\le 1$ meaning they are underdispersed
relative to the Poisson distribution. We will also not explicitly consider model
4 from~\fig{fig2:constit_cartoons}(A) since it was already thoroughly analyzed
in~\cite{Razo-Mejia2020}, and since model 5 can be viewed as a special case of
it.

Our objective for this section will then be to assess whether or not model 5 is
quantitatively able to reproduce experimental data. In other words, if our claim
is that the level of coarse graining in this model is capable of capturing the
relevant features of the data, then we should be able to find values for the
model parameters that can match theoretical predictions with single-molecule
mRNA count distributions. A natural language for this parameter inference
problem is that of Bayesian probability. We will then build a Bayesian inference
pipeline to fit the model parameters to data. To gain intuition on how this
analysis is done we will begin with the ``wrong'' model 1 in
Figure~\ref{fig2:constit_cartoons}(A). We will use the full dataset of
single-cell mRNA counts from~\cite{Jones2014} used in
Figure~\ref{fig2:constit_cartoons}(B).

\subsubsection{Model 1: Poisson promoter}

For this model the master equation of interest is
Eq.~\ref{eq:poisson_promoter_cme} with repressor set to zero, i.e.,
\begin{equation}
{d\over dt}p_U(m)(t) =
        rp_U(m-1)(t)
        - rp_U(m)(t)
        + (m+1)\gamma p_U(m+1)(t)
        - \gamma p_U(m)(t),
\end{equation}
whose steady-state solution is given by a Poisson distribution with parameter
$\lambda \equiv r / \gamma$~\cite{Sanchez2013}. The goal of our inference
problem is then to find the probability distribution for the parameter value
$\lambda$ given the experimental data. By Bayes' theorem this can be written as
\begin{equation}
p(\lambda \mid D) = {p(D \mid \lambda) p(\lambda) \over p(D)},
\end{equation}
where $D = \{m_1, m_2, \ldots, m_N \}$ are the single-cell mRNA experimental
counts. As is standard we will neglect the denominator $p(D)$ on the right
hand side since it is independent of $\lambda$ and serves only as a
normalization factor.

The steady-state solution for the master equation defines the likelihood term
for a single cell $p(m \mid \lambda)$. What this means is that for a given
choice of parameter $\lambda$, under model 1 of
Figure~\ref{fig2:constit_cartoons}(A), we expect to observe $m$ mRNAs in a
single cell with probability
\begin{equation}
p(m\mid\lambda) = \frac{\lambda^m e^{-\lambda}}{m!}.
\label{eq:poisson_inference010}
\end{equation}
Assuming each cell's mRNA count in our dataset is independent of others, the
likelihood of the full inference problem $p(D\mid\lambda)$ is simply a product
of the single cell likelihoods given by Eq.~\ref{eq:poisson_inference010} above, so
\begin{equation}
p(D\mid\lambda) = \prod_{k=1}^N \frac{\lambda^{m_k}e^{-\lambda}}{m_k!}.
\end{equation}

To proceed we need to specify a prior distribution $p(\lambda)$. In this case we
are extremely data-rich, as the dataset from Jones et.\ al~\cite{Jones2014} has
of order 1000-3000 single-cell measurements for each promoter, so our choice of
prior matters little here, as long as it is sufficiently broad. For details on
the prior selection we refer the reader to Appendix~\ref{sec:bayesian}. For our
purpose here it suffices to specify that we use as prior a Gamma distribution.
This particular choice of prior introduces two new parameters, $\alpha$ and
$\beta$, which parametrize the gamma distribution itself, which we use to encode
the range of $\lambda$ values we view as reasonable. Recall $\lambda$ is the
mean steady-state mRNA count per cell, which \textit{a priori} could plausibly
be anywhere from 0 to a few hundred. $\alpha=1$ and $\beta=1/50$ achieve this,
since the gamma distribution is strictly positive with mean $\alpha/\beta$ and
standard deviation $\sqrt{\alpha}/\beta$.

As detailed in Appendix~\ref{sec:bayesian} this particular choice of prior is
known as the \textit{conjugate} prior for a Poisson likelihood.
Conjugate priors have the convenient properties that a closed form exists for the posterior distribution $p(\lambda \mid D)$ - unusual in Bayesian inference problems - and the closed form posterior takes the same form as the prior. For
our case of a Poisson distribution likelihood with its
Gamma distribution conjugate prior, the posterior distribution is also a Gamma
distribution~\cite{Gelman2013}. Specifically the two parameters $\alpha'$ and
$\beta'$ for this posterior distribution take the form $\alpha' = \alpha +
\bar{m} N$ and $\beta' = \beta + N$, where we defined the sample mean $\bar{m} =
\frac{1}{N}\sum_{k=1}^N m_k$ for notational convenience, and $N$ is the number
of cells in our dataset. Furthermore, given that $N$ is $\mathcal{O}(10^3)$ and
$\langle m\rangle \gtrsim 0.1$ for all promoters measured in~\cite{Jones2014}
our data easily overwhelms the choice of prior, and allows us to approximate the
Gamma distribution with a Gaussian distribution with mean $\bar{m}$ and variance
$\bar{m} / N$ with marginal errors. As an example with real numbers, for the
\textit{lacUV5} promoter, Jones et.\ al~\cite{Jones2014} measured 2648 cells
with an average mRNA count per cell of $\bar{m} \approx 18.7$. For this case our
posterior distribution $P(\lambda \mid D)$ would be a Gaussian distribution with
mean $\mu = 18.7$, and a standard deviation $\sigma \approx 0.08$. This suggests
we have inferred our model's one parameter to a precision of order 1\%.

We remind the reader that we began this section claiming that the Poisson model
was ``wrong'' since it could not reproduce features of the data such as a Fano
factor $> 1$. The fact that we obtain such a narrow posterior distribution for our
parameter $P(\lambda \mid D)$ does not equate to the model being adequate to
describe the data. What this means is that given the data $D$, only values
in a narrow range are remotely plausible for the parameter $\lambda$,
but a narrow posterior distribution does not necessarily
mean the model accurately depicts reality.
As we will see later in Figure~\ref{fig:constit_post_full} after
exploring the bursty promoter model, indeed the correspondence
when contrasting the Poisson model with the experimental data is quite poor.

\subsubsection{Model 5 - Bursty promoter}

Let us now consider the problem of parameter inference for model five
from~\fig{fig1:means_cartoons}(C). As derived in
Appendix~\ref{sec:gen_fcn_appdx}, the steady-state mRNA distribution in this
model is a negative binomial distribution, given by
\begin{equation}
p(m) = \frac{\Gamma(m+k_i)}{\Gamma(m+1)\Gamma(k_i)}
        \left(\frac{1}{1+b}\right)^{k_i}
        \left(\frac{b}{1+b}\right)^m,
\label{eq:neg_bionom}
\end{equation}
where $b$ is the mean burst size and $k_i$ is the burst rate in units of the
mRNA degradation rate $\gamma$. As sketched earlier, to think of the negative
binomial distribution in terms of an intuitive ``story,'' in the precise
meaning of~\cite{Blitzstein2015}, we imagine the arrival of
bursts as a Poisson process with rate $k_i$, where each burst has a
geometrically-distributed size with mean size $b$.

As for the Poisson promoter model, this expression for the steady-state mRNA
distribution is exactly the likelihood we want to use when stating Bayes
theorem. Again denoting the single-cell mRNA count data as $D=\{m_1, m_2,\dots,
m_N\}$, here Bayes' theorem takes the form
\begin{equation}
p(k_i, b \mid D) \propto p(D\mid k_i,b)p(k_i, b).
\end{equation}
We already have our likelihood -- the product of $N$ negative binomials as
Eq.~\ref{eq:neg_bionom} -- so we only need to choose priors on $k_i$ and $b$.
For the datasets from~\cite{Jones2014} that we are analyzing, as for the Poisson
promoter model above we are still data-rich so the prior's influence remains
weak, but not nearly as weak because the dimensionality of our model has
increased from one parameter to two. Details on the arguments behind our prior
distribution selection are left for Appendix~\ref{sec:bayesian}. We state here
that the natural scale to explore these parameters is logarithmic. This is
commonly the case for parameters for which our previous knowledge based on our
domain expertise spans several orders of magnitude. For this we chose log-normal
distributions for both $k_i$ and $b$. Details on the mean and variance of these
distributions can be found in Appendix~\ref{sec:bayesian}.

We carried out Markov-Chain Monte Carlo (MCMC) sampling on the posterior of this
model, starting with the constitutive \textit{lacUV5} dataset
from~\cite{Jones2014}. The resulting MCMC samples are shown in
Figure~\ref{fig:constit_post_full}(A). In contrast to the active/inactive
constitutive model considered in~\cite{Razo-Mejia2020} (nonequilibrium model 4
in Figure~\ref{fig2:constit_cartoons}(A)), this model is well-identified with both
parameters determined to a fractional uncertainty of 5-10\%. The strong
correlation reflects the fact that their product sets the mean of the mRNA
distribution, which is tightly constrained by the data, but there is weak
``sloppiness''~\cite{Transtrum2015} along a set of values with a similar
product.

Having found the model's posterior to be well-identified as with the Poisson
promoter, the next step is to compare both models with experimental data. To do
this for the case of the bursty promoter, for each of the parameter samples
shown in Figure~\ref{fig:constit_post_full}(A) we generated negative
bionomial-distributed mRNA counts. As MCMC samples parameter space
proportionally to the posterior distribution, this set of random samples span
the range of possible values that we would expect given the correspondence
between our theoretical model and the experimental data. A similar procedure can
be applied to the Poisson promoter. To compare so many samples with the actual
observed data, we can use empirical cumulative distribution functions (ECDF) of
the distribution quantiles. This representation is shown in
Figure~\ref{fig:constit_post_full}(B). In this example, the median for each
possible mRNA count for the Poisson distribution is shown as a dark green line,
while the lighter green contains 95\% of the randomly generated samples. This
way of representing the fit of the model to the data gives us a sense of the
range of data we might consider plausible, under the assumption that the model
is true. For this case, as we expected given our premise of the Poisson promoter
being wrong, it is quite obvious that the observed data, plotted in black is not
consistent with the Poisson promoter model. An equivalent plot for the bursty
promoter model is shown in blue. Again the darker tone shows the median, while
the lighter color encompasses 95\% of the randomly generated samples. Unlike the
Poisson promoter model, the experimental ECDF closely tracks the posterior
predictive ECDF, indicating this model is actually able to generate the observed
data and increasing our confidence that this model
is sufficient to parametrize the physical reality of the system.

The commonly used promoter sequence \textit{lacUV5} is our primary
target here, since it forms the core of all the
simple repression constructs of~\cite{Jones2014} that we consider in
Section~\ref{sec:rep_kinetics_inference}. Nevertheless, we thought it wise to
apply our bursty promoter model to the other 17 unregulated promoters available
in the single-cell mRNA count dataset from~\cite{Jones2014} as a test that the
model is capturing the essential phenomenology. If the model fit well to all the
different promoters, this would increase our confidence that it would serve well
as a foundation for inferring repressor kinetics later in
Section~\ref{sec:rep_kinetics_inference}. Conversely, were the model to fail on
more than a couple of the other promoters, it would give us pause.

\begin{figure}%[h!]
\centering
\includegraphics[width=\textwidth]{../figures/main/fig03.pdf}
\caption{\textbf{Constitutive promoter posterior inference and model
comparison.} (A) The joint posterior density of model 5, the bursty promoter
with negative binomially-distributed steady state, is plotted with MCMC samples.
1D marginal probability densities are plotted as flanking histograms. The model
was fit on \textit{lacUV5} data from~\cite{Jones2014}. (B) The empirical
distribution function (ECDF) of the observed population distribution of mRNA
transcripts under the control of a constitutive \textit{lacUV5} promoter is
shown in black. The median posterior predictive ECDFs for models (1), Poisson,
and (5), negative binomial, are plotted in dark green and dark blue,
respectively. Lighter green and blue regions enclose 95\% of all posterior
predictive samples from their respective models. Model (1) is in obvious
contradiction with the data while model (5) is not. Single-cell mRNA count data
is again from~\cite{Jones2014}. (C) Joint posterior distributions for burst rate
$k_i$ and mean burst size $b$ for 18 unregulated promoters
from~\cite{Jones2014}. Each contour indicates the 95\% highest posterior
probability density region for a particular promoter. Note that the vertical
axis is shared with (D). (D) Plots of the burst rate $k_i$ vs.\ the binding
energy for each promoter as predicted in~\cite{Brewster2012}. The dotted line
shows the predicted slope according to Eq.~\ref{eq:bursty_equil_corresp1},
described in text. Each individual promoter is labeled with a unique number in
both (C) and (D) for cross comparison and for comparison with
Figure~\ref{fig2:constit_cartoons}(B).}
\label{fig:constit_post_full}
\end{figure}

\fig{fig:constit_post_full}(C) shows the results, plotting the posterior
distribution from individually MCMC sampling all 18 constitutive promoter
datasets from~\cite{Jones2014}. To aid visualization, rather than plotting
samples for each promoter's posterior as in \fig{fig:constit_post_full}(A), for
each posterior we find and plot the curve that surrounds the 95\% highest
probability density region. What this means is that each contour
encloses approximately 95\% of the samples, and thus 95\% of the probability
mass, of its posterior distribution. Theory-experiment comparisons,
shown in Figure~\ref{figS:ppc_unreg} in Appendix~\ref{sec:bayesian},
display a similar level of agreement between data and predictive samples as for
the bursty model with \textit{lacUV5} in \fig{fig:constit_post_full}(B).

One interesting feature from \fig{fig:constit_post_full}(C) is that burst rate
varies far more widely, over a range of $\sim10^2$, than burst size, confined to
a range of $\lesssim10^1$ (and with the exception of promoter 6, just a span of
3 to 5-fold). This suggests that $k_i$, not $b$, is the key dynamic variable that
promoter sequence tunes.

\subsubsection{Connecting inferred parameters to prior work}
It is interesting to connect these inferences on $k_i$ and $b$ to the work
of~\cite{Brewster2012}, where these same 18 promoters were considered through
the lens of the three-state equilibrium model (model 2 in
Figure~\ref{fig1:means_cartoons}(B)) and binding energies $\Delta\varepsilon_P$
were predicted from an energy matrix model derived from~\cite{Kinney2010}. As
previously discussed the thermodynamic models of gene regulation can only make
statements about the mean gene expression. This implies that we can draw the
connection between both frameworks by equating the mean mRNA $\left\langle m
\right\rangle$. This results in
\begin{equation}
\langle m \rangle = \frac{k_i b}{\gamma}
        = \frac{r}{\gamma}
        \frac{\frac{P}{N_{NS}}\exp(-\beta\Delta\varepsilon_P)}
                {1+\frac{P}{N_{NS}}\exp(-\beta\Delta\varepsilon_P)}.
\end{equation}
By taking the weak promoter approximation for the equilibrium model ($P/N_{NS}
\exp(-\beta\Delta\varepsilon_r) \ll 1$) results in
\begin{equation}
\langle m \rangle = \frac{k_i b}{\gamma}
        = \frac{r}{\gamma} \frac{P}{N_{NS}}\exp(-\beta\Delta\varepsilon_P),
\end{equation}
valid for all the binding energies considered here.

Given this result, how are the two coarse-grainings related? A quick estimate
can shed some light. Consider for instance the \textit{lacUV5} promoter, which
we see from Figure~\ref{fig:constit_post_full}(A) has $k_i/\gamma \sim b \sim
\text{few}$, from Figure~\ref{fig:constit_post_full}(B) has $\langle m \rangle
\sim 20$, and from~\cite{Brewster2012} has $\beta\Delta\varepsilon_P \sim -
6.5$. Further we generally assume $P/N_{NS} \sim 10^{-3}$ since
$N_{NS}\approx4.6\times10^6$ and $P\sim10^3$. After some guess-and-check with
these values, one finds the only association that makes dimensional sense and
produces the correct order-of-magnitude for the known parameters is to take
\begin{equation}
\frac{k_i}{\gamma} = \frac{P}{N_{NS}} \exp(-\beta\Delta\varepsilon_P)
\label{eq:bursty_equil_corresp1}
\end{equation}
and
\begin{equation}
b = \frac{r}{\gamma}.
\label{eq:bursty_equil_corresp2}
\end{equation}
Figure~\ref{fig:constit_post_full}(D) shows that this linear scaling between
$\ln k_i$ and $-\beta\Delta\varepsilon_P$ is approximately true for all 18
constitutive promoters considered. The plotted line is simply
Eq.~\ref{eq:bursty_equil_corresp1} and assumes $P\approx 5000$.

While the associations represented by Eq.~\ref{eq:bursty_equil_corresp1} and
Eq.~\ref{eq:bursty_equil_corresp2} appear to be borne out by the data in
Figure~\ref{fig:constit_post_full}, we do not find the association of parameters
they imply to be intuitive. We are also cautious to ascribe too much physical
reality to the parameters. Indeed, part of our point in comparing the various
constitutive promoter models is to demonstrate that these models each provide an
internally self-consistent framework that adequately describes the data, but
attempting to translate between models reveals the dubious physical
interpretation of their parameters.

We mention one further comparison, between our inferred parameters and the
work of Chong et.\ al.~\cite{Chong2014}, which is interesting and puzzling.
Beautiful experiments in~\cite{Chong2014} convincingly argue that
supercoiling accumulated from the production of mRNA transcripts is key
in setting the burstiness of mRNA production.
In their model, this supercoiling occurs on the scale of $\sim100$~kb
domains of DNA. This suggests that all genes on a given domain should burst
in synchrony, and that the difference between highly and lowly expressed
genes is the \textit{size} of transcriptional bursts, not the
\textit{time between} bursts.
But here, all burst sizes we infer in Figure~\ref{fig:constit_post_full}(C)
are comparable and burst rates vary wildly. It is not immediately clear
how to square this circle. Furthermore, Figure~7E in~\cite{Chong2014}
reports values of the quantity they label $\beta/\alpha$ and we label
$k^+/k^-$ in model 4 from Figure~\ref{fig2:constit_cartoons}. In contrast
to the findings of~\cite{Razo-Mejia2020}, Chong et.\ al.\ do not find
$k^+/k^-\ll1$ for most of the genes they consider. This begs the question:
is the \textit{galK} chromosomal locus used for the reporter constructs
in~\cite{Razo-Mejia2020} and~\cite{Jones2014} merely an outlier,
or is there a deeper puzzle here waiting to be resolved? Without more
apples-to-apples data we can only speculate, and we leave it as an
intriguing open question for the field.

Despite such puzzles, our goal here is not to unravel the mysterious origins
of burstiness in transcription. Our remaining task in this work is a
determination of the physical reality of equilibrium binding energies in
Figure~\ref{fig1:means_cartoons}, as codified by the equilibrium-nonequilibrium
equivalence of Eq.~\ref{eq:deltaFR_eq_noneq_equiv}.
For our phenomenological needs here model 5 in
Figure~\ref{fig2:constit_cartoons} is more than adequate: the posterior
distributions in Figure~\ref{fig:constit_post_full}(C) are cleanly
identifiable and the predictive checks in Figure~\ref{figS:ppc_unreg}
indicate no discrepancies between the model and the mRNA single-moleucle
count data of~\cite{Jones2014}. Of the models we have considered it
is unique in satisfying both these requirements. So we will happily use
it as a foundation to build upon in the next section when we add regulation.

\subsection{Transcription factor kinetics can be inferred from single-cell mRNA
distribution measurements}\label{sec:rep_kinetics_inference}
\subsubsection{Building the model and performing parameter inference}

Now that we have a satisfactory model in hand for constitutive promoters, we
would like to return to the main thread: can we reconcile the equilibrium and
nonequilibrium models by putting to the test
Eq.~\ref{eq:deltaFR_eq_noneq_equiv}, the correspondence between indirectly
inferred equilibrium binding energies and nonequilibrium kinetic rates? To make
this comparison, is it possible to infer repressor binding and unbinding rates
from mRNA distributions over a population of cells as measured by
single-molecule Fluorescence \textit{in situ} Hybridization in~\cite{Jones2014}?
If so, how do these inferred rates compare to direct single-molecule
measurements such as from~\cite{Hammar2014} and to binding energies such as
from~\cite{Garcia2011a} and~\cite{Razo-Mejia2018}, which were inferred under the
assumptions of the equilibrium models in Figure~\ref{fig1:means_cartoons}(B)?
And can this comparison shed light on the unreasonable effectiveness of the
equilibrium models, for instance, in their application in~\cite{Chure2019,
Chure2019a}?

\begin{figure}%[h!]
\centering
\includegraphics[width=\textwidth]{../figures/main/fig04.pdf}
\caption{\textbf{Simple repression parameter inference and comparison.}
(A) Contours which enclose 50\% and 95\% of the posterior probability mass are
shown for each of several 2D slices of the 9D posterior distribution. The model
assumes one unbinding rate for each operator (Oid, O1, O2) and one binding rate
for each aTc induction concentration (corresponding to an unknown mean repressor
copy number).
(B, upper) Ratios of our inferred unbinding rates are
compared with operator binding energy differences measured by Garcia and
Phillips~\cite{Garcia2011a} (triangles) and Razo-Mejia et.\
al.~\cite{Razo-Mejia2018} (circles). Blue glyphs compare O2-O1, while orange
compare O1-Oid. Points with perfect agreement would lie on the dotted line.
(B, lower) Unbinding rates for O1 (cyan) and Oid (red)
inferred in this work are compared with single-molecule measurements
from Hammar et.\ al.~\cite{Hammar2014}. We plot the comparison assuming illustrative mRNA
lifetimes of $\gamma^{-1}=3$~min (triangles) or $\gamma^{-1}=5$~min
(squares). Dotted line is as in upper panel.
(C) Theory-experiment comparison are shown for each of the datasets
used in the inference of the model in (A). Observed single-molecule mRNA counts
data from~\cite{Jones2014} are plotted as black lines. The median of the randomly
generated samples for each condition is plotted as a dark colored line. Lighter
colored bands enclose 95\% of all samples for a given operator/repressor copy
number pair.
%Samples are sorted by operator and plotted separately for visual clarity.
The unregulated promoter, \textit{lacUV5}, is shown with each as a reference.}
\label{fig4:repressed_post_full}
\end{figure}

As we found in Section~\ref{sec:beyond_means}, for our purposes the ``right''
model of a constitutive promoter is the bursty picture, model five in
Figure~\ref{fig2:constit_cartoons}(A). Therefore our starting point here is the
analogous model with repressor added, model 5 in
Figure~\ref{fig1:means_cartoons}(C). For a given repressor binding site and copy
number, this model has four rate parameters to be inferred: the repressor
binding and unbinding rates $k_R^+$, and $k_R^-$, the initiation rate of bursts,
$k_i$, and the mean burst size $b$ (we nondimensionalize all of these by the
mRNA degradation rate $\gamma$).

Before showing the mathematical formulation of our statistical inference model,
we would like to sketch the intuitive structure. The dataset
from~\cite{Jones2014} we consider consists of single-cell mRNA counts data of
nine different conditions, spanning several combinations of three unique
repressor binding sites and four unique repressor copy numbers. We assume that
the values of $k_i$ and $b$ are known, since we have already cleanly inferred
them from constitutive promoter data, and further we assume that these values
are the same across datasets with different repressor binding sites and copy
numbers. In other words, we assume that the regulation of the transcription
factor does not affect the mean burst size nor the burst initiation rate. The
regulation occurs as the promoter is taken away from the transcriptionally
active state when the promoter is bound by repressor. We assume that there is
one unbinding rate parameter for each repressor binding site, and likewise one
binding rate for each unique repressor copy number. This makes our model seven
dimensional, or nine if one counts $k_i$ and $b$ as well. Note that we use only
a subset of the datasets from Jones et.\ al.~\cite{Jones2014}, as discussed more
in Appendix~\ref{sec:bayesian}.

Formally now, denote the set of seven repressor rates to be inferred as
\begin{equation}
\vect{k} =\{k_{Oid}^-, k_{O1}^-, k_{O2}^-,
k_{0.5}^+, k_{1}^+, k_{2}^+, k_{10}^+\},
\end{equation}
where subscripts for dissociation rates $k^-$  indicate the different repressor
binding sites, and subscripts for association rates $k^+$ indicate the
concentration of the small-molecule that controlled the expression of the LacI
repressor (see Appendix~\ref{sec:bayesian}). This is because for this particular
dataset the repressor copy numbers were not measured directly, but it is safe to
assume that a given concentration of the inducer resulted in a specific mean
repressor copy number~\cite{Chure2019a}. Also note that the authors
of~\cite{Jones2014} report estimates of LacI copy number per cell rather than
direct measurements. However, these estimates were made assuming the validity of
the equilibrium models in Figure~\ref{fig1:means_cartoons}, and since testing
these models is our present goal, it would be circular logic if we were to make
the same assumption. Therefore we will make no assumptions about the LacI copy
number for a given inducer concentrations.

Having stated the problem, Bayes' theorem reads
\begin{equation}
p(\vect{k}, k_i, b \mid D)
\propto
p(D \mid\vect{k}, k_i, b) p(\vect{k}, k_i, b),
\end{equation}
where $D$ is again the set of all $N$ observed single-cell mRNA counts
across the various conditions. We assume that individual single-cell
measurements are independent so that the likelihood factorizes as
\begin{equation}
p(D \mid\vect{k}, k_i, b)
= \prod_{j=1}^N p(m\mid \vect{k}, k_i, b)
= \prod_{j=1}^N p(m\mid k_j^+, k_j^-, k_i, b)
\end{equation}
where $k_j^\pm$ represent the appropriate binding and unbinding
rates out of $\vect{k}$ for the $j$-th measured cell. The probability
$p(m\mid k_j^+, k_j^-, k_i, b)$ appearing in the last expression
is exactly Eq.~\ref{eq:p_m_bursty+rep_appdx}, the steady-state
distribution for our bursty model with repression derived in
Section~\ref{sec:gen_fcn_appdx}, which for completeness we reproduce here as
\begin{equation}
\begin{split}
p(m \mid k_R^+, k_R^-, k_i, b) = & ~\frac{
        \Gamma(\alpha + m)\Gamma(\beta + m)\Gamma(k_R^+ + k_R^-)
        }
        {
        \Gamma(\alpha)\Gamma(\beta)\Gamma(k_R^+ + k_R^- + m)
        }
\frac{b^m}{m!}
\\
&\times {_2F_1}(\alpha+m, \beta+m, k_R^++k_R^-+m; -b).
\end{split}
\label{eq:p_m_bursty+rep}
\end{equation}
where $_2F_1$ is the confluent hypergeometric function of the second kind and
$\alpha$ and $\beta$, defined for notational convenience, are
\begin{align}
\begin{split}
\alpha &= \frac{1}{2}
\left(k_i+k_R^-+k_R^+ + \sqrt{(k_i+k_R^-+k_R^+)^2 - 4k_i k_R^-}\right)
\\
\beta &= \frac{1}{2}
\left(k_i+k_R^-+k_R^+ - \sqrt{(k_i+k_R^-+k_R^+)^2 - 4k_i k_R^-}\right).
\end{split}
\end{align}

This likelihood is rather inscrutable. We did not find any of the known
analytical approximations for ${_2F_1}$ terribly useful in gaining intuition, so
we instead resorted to numerics. One insight we found
was that for very strong or very weak repression, the distribution in
Eq.~\ref{eq:p_m_bursty+rep} is well approximated by a negative binomial with
burst size $b$ and burst rate $k_i$ equal to their constitutive \textit{lacUV5}
values, except with $k_i$ multiplied by the fold-change
$\left(1+k_R^+/k_R^-\right)^{-1}$. In other words, once again only the ratio
$k_R^+/k_R^-$ was detectable. But for intermediate repression, the distribution
was visibly broadened with Fano factor greater than $1+b$, the value for the
corresponding constitutive case. This indicates that the repressor rates had
left an imprint on the distribution, and perhaps intuitively, this intermediate
regime occurs for values of $k_R^\pm$ comparable to the burst rate $k_i$. Put
another way, if the repressor rates are much faster or much slower than $k_i$,
then there is a timescale separation and effectively only one timescale remains,
$k_i\left(1+k_R^+/k_R^-\right)^{-1}$. Only when all three rates in the problem
are comparable does the mRNA distribution retain detectable information about
them.

Next we specify priors. As for the constitutive model, weakly informative
log-normal priors are a natural choice for all our rates. We found that if the
priors were too weak, our MCMC sampler would often become stuck in regions of
parameter space with very low probability density, unable to move. We struck a
balance in choosing our prior widths between helping the sampler run while
simultaneously verifying that the marginal posteriors for each parameter were
not artificially constrained or distorted by the presence of the prior.
% The only
% exception to this is the highly informative priors we placed on $k_i$ and $b$,
% since we have strong knowledge of them from our inference of constitutive
% promoters above.
All details for our prior distributions are listed in
Appendix~\ref{sec:bayesian}.

We ran MCMC sampling on the full nine dimensional posterior specified by this
model. To attempt to visualize this object, in
Figure~\ref{fig4:repressed_post_full}(A) we plot several two-dimensional slices
as contour plots, analogous to Figure~\ref{fig:constit_post_full}(C). Each of
these nine slices corresponds to the $(k_R^+, k_R^-)$ pair of rates for one of
the conditions from the dataset used to fit the model and gives a
sense of the uncertainty and correlations in the posterior.
We note that the 95\% uncertainties of all the rates span about $\sim0.3$
log units, or about a factor of two, with the exception of $k_{0.5}^+$, the
association rate for the lowest repressor copy number which is somewhat larger.

\subsubsection{Comparison with prior measurements of repressor binding energies}
Our primary goal in this work is to reconcile the kinetic and equilibrium
pictures of simple repression. Towards this end we would like to compare the
repressor kinetic rates we have inferred with the repressor binding energies
inferred through multiple methods in~\cite{Garcia2011a}
and~\cite{Razo-Mejia2018}. If the agreement is close, then it suggests that the
equilibrium models are not wrong and the repressor binding energies they contain
correspond to physically real free energies, not mere fit parameters.

Figure~\ref{fig4:repressed_post_full}(B) shows both comparisons, with the top
panel comparing to equilibrium binding energies and the bottom panel comparing
to single-molecule measurements. First consider the top panel and its comparison
between repressor kinetic rates and binding energies. As described in
section~\ref{section_02_means}, if the equilibrium binding energies
from~\cite{Garcia2011a} and~\cite{Razo-Mejia2018} indeed are the physically real
binding energies we believe them to be, then they should be related to the
repressor kinetic rates via Eq.~\ref{eq:deltaFR_eq_noneq_equiv}, which we
restate here,
\begin{equation}
\Delta F_R = \beta\Delta\varepsilon_R - \log(R/N_{NS})
        = - \log(k_R^+/k_R^-).
\label{eq:deltaFR_eq_noneq_equiv_repeat}
\end{equation}
Assuming mass action kinetics implies that $k_R^+$ is proportional to repressor
copy number $R$, or more precisely, it can be thought of as repressor copy
number times some intrinsic per molecule association rate. But since $R$ is not
directly known for our data from~\cite{Jones2014}, we cannot use this equation
directly. Instead we can consider two different repressor binding sites and
compute the \textit{difference} in binding energy between them, since this
difference depends only on the unbinding rates and not on the binding rates.
This can be seen by evaluating Eq.~\ref{eq:deltaFR_eq_noneq_equiv_repeat} for
two different repressor binding sites, labeled (1) and (2), but with the same
repressor copy number $R$, and taking the difference to find
\begin{equation}
\Delta F_R^{(1)} - \Delta F_R^{(2)}
= \beta\Delta\varepsilon_1 - \beta\Delta\varepsilon_2
= - \log(k_R^+/k_1^-) + \log(k_R^+/k_2^-),
\end{equation}
or simply
\begin{equation}
\beta\Delta\varepsilon_1 - \beta\Delta\varepsilon_2
= \log(k_2^-/k_1^-).
\end{equation}
The left and right hand sides of this equation are exactly the horizontal and
vertical axes of the top panel of Figure~\ref{fig4:repressed_post_full}. Since
we inferred rates for three repressor binding sites (O1, O2, and Oid), there are
only two independent differences that can be constructed, and we arbitrarily
chose to plot O2-O1 and O1-Oid in Figure~\ref{fig4:repressed_post_full}(B).
Numerically, we compute values of $k_{O1}^- / k_{Oid}^-$ and $k_{O2}^- /
k_{O1}^-$ directly from our full posterior samples, which conveniently provides
uncertainties as well, as detailed in Appendix~\ref{sec:bayesian}.
% \mmnote{Explain in appendix how marginalization with sampling makes this
% ``trivial'' to compute from samples of the joint posterior, b/c sampling makes
% marginalization trivial.}
We then compare these log ratios of rates to the
binding energy differences $\Delta\varepsilon_{O1} - \Delta\varepsilon_{Oid}$
and from $\Delta\varepsilon_{O2} - \Delta\varepsilon_{O1}$ as computed from the
values from both~\cite{Garcia2011a} and~\cite{Razo-Mejia2018}. Three of the four
values are within $\sim0.5~k_BT$ of the diagonal representing perfect agreement,
which is comparable to the $\sim\text{few}\times0.1~k_BT$ variability between
the independent determinations of the same quantities between~\cite{Garcia2011a}
and~\cite{Razo-Mejia2018}. The only outlier involves Oid measurements
from~\cite{Razo-Mejia2018}, and as the authors of~\cite{Razo-Mejia2018} note,
this is a difficult measurement of low fluorescence signal against high
background since Oid represses so strongly. We are therefore inclined to regard
the failure of this point to fall near the diagonal as a testament to the
difficulty of the measurement and not as a failure of our theory.

On the whole then, we regard this as striking confirmation of the validity of
the equilibrium models. Their lynchpin parameter is a phenomenological free
energy of repressor binding that has previously only been inferred indirectly.
Our result shows that the microscopic interpretation of this free energy, as the
log of a ratio of transition rates, does indeed hold true to within the inherent
uncertainties that remain in the entire theory-experiment dialogue.
%\mmnote{Does this deserve qualifiers, like ``to a good approximation,'' or ``as a first order model'' or something? I like the simple finality without, but I worry it's too brazen or subtlely misleading.}

\subsubsection{Comparison with prior measurements of repressor kinetics}
In the previous section we established the equivalence between the equilibrium
models' binding energies and the repressor kinetics we infer from mRNA
population distributions. But one might worry that the repressor rates we infer
from mRNA distributions are \textit{themselves} merely fitting parameters and
that they do not actually correspond to the binding and unbinding rates of the
repressor in vivo. To verify that this is not the case, we next compare our
kinetic rates with a different measurement of the same rates using a radically
different method: single molecule measurements as performed in Hammar et.\
al.~\cite{Hammar2014}. This is plotted in the lower panel of
Figure~\ref{fig4:repressed_post_full}(B).

Since we do not have access to repressor copy number for either the
single-cell mRNA data from~\cite{Jones2014} or the single-molecule data
from~\cite{Hammar2014}, we cannot make an apples-to-apples comparison of
association rates $k_R^+$. Further, while Hammar et.\ al.\ directly measure the
dissociation rates $k_R^-$, our inference procedure returns $k_R^-/\gamma$,
i.e., the repressor dissociation rate nondimensionalized by the mRNA degradation
rate $\gamma$. So to make the comparison, we must make an assumption for the
value of $\gamma$ since it was not directly measured. For most mRNAs in
\textit{E.\ coli}, quoted values for the typical mRNA lifetime $\gamma^{-1}$
range between about 2.5~min~\cite{Chen2015} to 8~min. We chose $\gamma^{-1} =
3$~min and $\gamma^{-1} = 5$~min as representative values and plot a comparison
of $k_{O1}^-$ and $k_{Oid}^-$ from our inference with corresponding values
reported in~\cite{Hammar2014} for both these choices of $\gamma$.

The degree of quantitative agreement in the lower panel of
Figure~\ref{fig4:repressed_post_full}(B) clearly depends on the precise choice
of $\gamma$. Nevertheless we find this comparison very satisfying, when two
wildly different approaches to a measurement of the same quantity yield broadly
compatible results. We emphasize the agreement between our rates and the rates
reported in~\cite{Hammar2014} for any reasonable $\gamma$: values differ by at
most a factor of 2 and possibly agree to within our uncertainties of 10-20\%.
From this we feel confident asserting that the parameters we have inferred from
Jones et.\ al.'s single-cell mRNA counts data do in fact correspond to repressor
binding and unbinding rates, and therefore our conclusions on the agreement of
these rates with binding energies from~\cite{Garcia2011a}
and~\cite{Razo-Mejia2018} are valid.

\subsubsection{Model checking}
In Figure~\ref{fig:constit_post_full}(B) we saw that the simple Poisson model of
a constitutive promoter, despite having a well behaved posterior, was clearly
insufficient to describe the data. It behooves us to carry out a similar check
for our model of simple repression, codified by Eq.~\ref{eq:p_m_bursty+rep} for
the steady-state mRNA copy number distribution. As derived in
Sections~\ref{section_02_means} and~\ref{sec:beyond_means}, we have compelling
theoretical reasons to believe it is a good model, but if it nevertheless turned
out to be badly contradicted by the data we should like to know.

The details are deferred to Appendix~\ref{sec:bayesian}, and here we only
attempt to summarize the intuitive ideas, as detailed at greater length by
Jaynes~\cite{Jaynes2003} as well as Gelman and
coauthors~\cite{Gelman2013,Gelman2013a}. From our samples of the posterior
distribution, plotted in Figure~\ref{fig4:repressed_post_full}(A), we generate
many replicate data using a random number generator. In
Figure~\ref{fig4:repressed_post_full}(C), we plot empirical cumulative
distribution functions of the middle 95\% quantiles of these replicate data with
the actual experimental data from Jones et.\ al.~\cite{Jones2014} overlaid,
covering all ten experimental conditions spanning repressor binding sites and
copy numbers (as well as the constitutive baseline UV5).

The purpose of Figure~\ref{fig4:repressed_post_full}(C) is simply a graphical,
qualitative assessment of the model: do the experimental data systematically
disagree with the simulated data, which would suggest that our model is missing
important features? A further question is not just whether there is a detectable
difference between simulated and experimental data, but whether this difference
is likely to materially affect the conclusions we draw from the posterior in
Figure~\ref{fig4:repressed_post_full}(A). More rigorous and quantitative
statistical tests are possible~\cite{Gelman2013}, but their quantitativeness
does not necessarily make them more useful. As stated in~\cite{Gelman2013a}, we
often find this graphical comparison more enlightening because it better engages
our intuition for the model, not merely telling \textit{if} the model is wrong
but suggesting \textit{how} the model may be incomplete.

Our broad brush takeaway from Figure~\ref{fig4:repressed_post_full}(C) is
overall of good agreement. There some oddities, in particular the long tails in
the data for Oid, 1~ng/mL, and O2, 0.5~ng/mL. The latter is especially odd since
it extends beyond the tail of the unregulated UV5 distribution. This is a
relatively small number of cells, however, so whether this is a peculiarity of
the experimental data, a statistical fluke of small numbers, or a real
biological effect is unclear. It is conceivable that there is some very slow
timescale switching dynamics that could cause this bimodality, although it is
unclear why it would only appear for specific repressor copy numbers. There is
also a small offset between experiment and simulation for O2 at the higher
repressor copy numbers, especially at 2 and 10~ng/mL.
From the estimate of repressor copy numbers from~\cite{Jones2014}, it is
possible that the repressor copy numbers here are becoming large enough to
partially invalidate our assumption of a separation of timescales between
burst duration and repressor association rate. Another possibility is that
the very large number of zero mRNA counts for Oid, 2~ng/mL is skewing its partner
datasets through the shared association rate.
None of these fairly minor quibbles cause us to
seriously doubt the overall correctness of our model, which further validates
its use to compare the equilibrium models' binding energies to the
nonequilibrium models' repressor kinetics, as we originally set out to do.


%%%%% Point Pillar Lidar Deep Learning Face Finding %%%%%%
%%%%% Karissa Stisser, Zach Larson, Naseem Alfaqueh, Anjali Patil, Adrian Lindsey, Omar Rizk
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\title{Point Pillar Lidar Deep Learning Face Finding}
\author{Karissa Stisser, Zach Larson, Naseem Alfaqueh\\
\\Anjali Patil, Adrian Lindsey, Omar Rizk }
\date{April 2021- https://github.com/kstisser/DeepLearningPointCloud}

\begin{document}

\maketitle

\section{Introduction}
We have created a system that uses deep learning to recognize a face in point cloud data using time series data in real time for surgical applications. As this use case is very specific, we focused on leveraging knowledge of the space and procedure to optimize the output rather than try to create a solution for all scenarios. We build a preprocessing pipeline that eliminated unnecessary points, leveraged the point pillars deep learning architecture\cite{pointpillars}, and modified the output for a point by point decision on whether that pixel belonged to the face. Development was done in two stages. First, separate pieces were developed in Jupyter notebooks. Second those notebooks were integrated into the final product. Many but not all components made it to the second stage.
\section{Data Augmentation}
As we started with 7 point clouds, we developed a data augmentation plan to be used on both the train and test data that involves background mixing, translation, rotation, scaling, and flipping as we would like the trained algorithm to be more robust to camera placement in relation to the face. We only modified in the x and y directions, as modifications in the z directions would actually add and remove points, which we weren't confident in accurately augmenting.

We start by matching each face with each other background points. If we have n point clouds, this creates an additional n choose 2 combination of point clouds.
For each of these background mixed point clouds we added translation in a spiral format starting from the face center and moving outwards in 30 different locations. We continually increment the angle by 4 * pi/30 to ensure two spiral loops, and use the following equation for center face placement:
\[rt = e^{0.306*angle}\]
\[x = rt * cos(angle) + originalX\]
\[y = rt * sin(angle) + originalY\]
At each different translation we are rotating the face 10 times in addition to the original, which we consider 0 degrees, and we evenly space the other 10 between 0 and 360. We are scaling at ${2\%}$, ${4\%}$, and ${6\%}$, both bigger and smaller to make an additional 6 point clouds, keeping the face a reasonable size within the anticipated space. Because we are using random downsampling the space between the points at these scales are not a concern as it is possible we would randomly increase or decrease the scaling of the proximity of points.
Finally, we flopped the face in each of the scaled point clouds, doubling the final count, which is:
\[
    3600 * \frac{n!}{2!(n-2)!} + n
\]
where n = the number of original point clouds. As we started with 7 point clouds, we are able to produce a total of 151,207 point clouds. As all 7 point clouds were of the same face, the next step would be to collect data of different faces with a variation on age, size, races, and distinctive features.
\section{Data Preprocessing}
\begin{figure}[htp]
    \centering
    \includegraphics[scale=0.4]{PreprocessingPipeline.jpg}
    \caption{Preprocessing Pipeline}
    \label{fig:preprocessingPipeline}
\end{figure}
Because we are not able to use all points in the point cloud given due to computational speed, we chose to add preprocessing steps to eliminate unnecessary points. As this problem is meant for a specific application with specific hardware, we were able to make certain assumptions. Because we were told there will be a table or floor under the patient being operated on, we chose to begin our algorithm with a RANSAC plane finder to eliminate all points within a reasonable plane. We then randomly downsampled to 1000 points.

Next, we developed a clustering architecture which consists of a Clusterer and Cluster Profiler. The clusterer starts by running DBSCAN with eps = 0.05 and the minimum number of samples are 10. The Cluster Profiler maintains profiles of faces using number of points in the cluster, width of the cluster, and height of the cluster. We store an ideal face (an average of our downsampled data) with 200 points, 0.1907 meters width, and 0.2487 meters height to compute a score to compare each incoming cluster against. Our score calculation is:

\[
    numPointsScore= \frac{(averageFace.numPoints - incomingFace.numPoints)}{0.5 * (maxFace.numPoints - minFace.numPoints)}
\]
\[
    widthScore= \frac{(averageFace.width - incomingFace.width)}{0.5 * (maxFace.width - minFace.width)}
\]
\[
    heightScore= \frac{(averageFace.height - incomingFace.height)}{0.5 * (maxFace.height - minFace.height)}
\]
\[
    score = numPointsScore + widthScore + heightScore
\]

We also maintain a profile for a minimum face with 100 points, 0.1 meters width, and 0.2 meters height, and a maximum face with 300 points, 0.4 meters width, and 0.6 meters height. If the incoming cluster has any value lower than the minimum face or larger than the maximum face it is given a score of -1 and is eliminated. If the cluster is not eliminated by this, its score is computed when compared to the average face, and if the score is above the threshold 0.7, it is kept for further parallel evaluation in the Machine Learning pipeline.

\begin{figure}[htp]
    \centering
    \includegraphics[scale=0.8]{pointPillars.png}
    \caption{PointPillars}
    \label{fig:pointPillars}
\end{figure}
While the clustering seems to be working well, the parameters don't seem consistent enough yet to send each cluster through the model, which was our goal. So, we are currently sending one large cluster of all data through an embedding to become a point pillar\cite{pointpillars}. However, we are using 8 feature variables, not including the reflectance value as it is not available. These pillars are formed by projecting all points in the point cloud onto the x-y plane and binning them with a simple grid. The arithmetic mean of the x, y, z values of the points in each bin are taken, as well as the x and y offset of each point from the center of the pillar (the mean values). These statistics are then combined with the three dimensional coordinates of each point to give an eight dimensional vector for each point. Once processed into point pillars, we normalize the data to be between 0 and 1 before sending it through the deep learning model. The labels also need to be processed to contain a 1 or 0 for each pillar to match in dimensions. Something that was interesting and highlighted when visualizing the point pillars were that about half of them had at least one noisy label away from the face, as shown in figure \ref{fig:pointPillars} where the blue is a pillar with a face label, the red is a pillar which have only non-face points, and the green are empty pillars. This highlights that mislabelled data being fed into the model is accentuated.

\section{Architecture}
Once the data has been preprocessed, a vector of downsampled, clustered, point pillars are ready to enter the deep learning network. As we are working with 1200 pillars, 20 maximum points per pillar, and 8 features, the incoming shape of the data is (number of samples, 1200, 20, 8). We struggled with our model, as we failed to run due to resource constraints in a Jupyter notebook with and without TPU/GPU, locally, and with several cloud instances. Finally, with reducing to 1 batch, reducing the max points per pillar to 20, which was closer to the max points, and simplifying the model with fewer layers we were able to run locally. This resulted in the following model summary:
\begin{figure}[htp]
    \centering
    \includegraphics[scale=0.8]{model2.png}
    \caption{Model Summary}
    \label{fig:modelSummary}
\end{figure}
We compiled with an Adam optimizer with a learning rate of 0.0001 and a Binary Crossentropy loss function. We then need to remap that to the point pillars that were fed in before delivering the result.
\section{Training}
We implement the traditional 80/20 train-test split in dividing the pre-processed data. The training and test data is treated by the point pillar method and the training data is passed to the model. The labels are per pillar where a pillar that includes at least one face point (1) or a pillar that includes no face points (0). Initially we were achieving a low accuracy of 0.2, but were able to increase the accuracy by reducing the learning rate to 0.0001. We also added he{\_}normal initialization weights to the first Dense layer to try to help overcome the problem of vanishing gradients. We analyzed what labels were being labelled incorrectly. For instance, for one face, 75{\%} of the missed labels were incorrectly labelling face labels no-face labels, and another face had 45{\%} face points being labelled incorrectly. This tells me that although we were getting 73{\%} accuracy, much more work needs to be done to improve focusing on the face being labelled accurately.
\section{Conclusion}
While there are far too many points in a point cloud to process all points in real time, we developed a method to smartly eliminate points through RANSAC, cluster elimination, and downsampling. We developed a simple but efficient model that can achieve an accuracy of 0.73 in labeling each point as a face in the incoming point cloud. Significant speedup is necessary but possible for this system to be able to run in real time. We also have future ideas for kalman filter tracking on the face cluster to predict the location of the face in the next frame, as a face can only move a certain distance at a certain time frame. If the kalman filter has an accurate enough prediction, we will be able to eliminate all points outside of a bounding box barely larger than any head to significantly reduce the number of unnecessary points prior to running the data through the model.
\begin{thebibliography}{9}
\bibitem{pointpillars}
PointPillars: Fast Encoders for Object Detection from Point Clouds, Dec 14, 2018
\\\texttt{arXiv:1812.05784}
\bibitem{githubrepo}
Point Pillars in TensorFlow (2020), GitHub, https://github.com/tyagi-iiitv/PointPillars
\end{thebibliography}
\end{document}