% !TEX root = Presentation.tex
% Change "draft" to "final" when you're done.
\documentclass[compress]{beamer}

\input{preamble.tex}

%\usetheme{Frankfurt}
%\usecolortheme{lily}

\definecolor{uoit-light-blue}{RGB}{0,119,202}
\definecolor{uoit-dark-blue}{RGB}{0,60,113}

\definecolor{UniBlue}{RGB}{83,121,170}
%\setbeamercolor{title}{fg=UniBlue}
%\setbeamercolor{frametitle}{fg=UniBlue}

%\setbeamercolor{primary text}{fg=uoit-dark-blue}
%\setbeamercolor{palette primary}{fg=uoit-dark-blue}
\setbeamercolor{palette tertiary}{fg=uoit-light-blue}
\setbeamercolor{structure}{fg=uoit-light-blue}
\setbeamercolor{alerted text}{fg=uoit-light-blue}

%\setbeameroption{show notes}

\setbeamertemplate{footline}[frame number]

\newcommand{\prop}[2]{\ensuremath\textsc{#1}[#2]}

\newcommand{\attributes}[1]{\prop{Attr}{#1}}
\newcommand{\fields}[1]{\prop{Field}{#1}}
\newcommand{\uid}[1]{\prop{UID}{#1}}

\newcommand{\attribute}{\alpha}
\newcommand{\tuple}{t}
\newcommand{\doc}{d}
\newcommand{\field}{f}
\newcommand{\egraph}{T}

\title[M.Sc. Thesis -- \insertframenumber/\inserttotalframenumber]{Towards a Concurrent Implementation of Keyword Search Over Relational Databases}
\subtitle{M.Sc. Thesis}
\author[\copyright 2014 Richard Drake]{Richard Drake \\ \vspace{0.3em} \scriptsize{\texttt{richard.drake@uoit.ca}} \\ \vspace{1em} \tiny Supervisor:  Dr. Ken Q. Pu}
\institute[UOIT]{University of Ontario Institute of Technology \\ Oshawa, Ontario, Canada}
\date{\tiny 9 June 2014}

\usefonttheme{serif}

\begin{document}
	%\input{../document/acronyms.tex}

	\frame{\maketitle}

	%- transformation from relational to document model
	%- reversibility of the transformation
	%- the flexibility of the document model (spelling correction + entity group search)
	%- using document model to perform graph based search

	\section{Introduction}
		\begin{frame}{Motivation}
			\begin{itemize}
				\item Two important data models:
					\begin{itemize}
						\item The \alert{relational model} is rigid in structure and highly normalized
						\item The \alert{document model} is flexible and provides keyword search
					\end{itemize}
				\item Choice between data \alert{integrity} and \alert{accessibility}
				\item Why can't we have both?
			\end{itemize}
		\end{frame}

		%\begin{frame}{Data Model Evolution}
		%	\begin{itemize}
		%		\item Structured Data (1970 -- 2000)
		%			\begin{itemize}
		%				\item Relational databases
		%			\end{itemize}
		%		\item Textual Data and Keyword Search (1970 -- Present)
		%			\begin{itemize}
		%				\item Natural language
		%			\end{itemize}
		%		\item Semi-Structured Data (1990 -- 2010)
		%			\begin{itemize}
		%				\item Well-formed natural language
		%			\end{itemize}
		%		\item Hybrid Data Model (2010 -- Present)
		%			\begin{itemize}
		%				\item Mixture of structured and unstructured data
		%			\end{itemize}
		%	\end{itemize}
		%\end{frame}

	%\section{Background}

	%\section{Approach}
		\begin{frame}{Thesis Statement}
			\begin{quotation}
				A system could be built that is capable of \alert{transforming data from the relational model to the document model}.  The transformation is \alert{reversible}, allowing the original data model to be recovered.  This system would use the \alert{keyword search} capabilities, along with the \alert{relational information}, to quickly \alert{discover related fragments of information}.
			\end{quotation}
		\end{frame}

		\begin{frame}{Research Goals}
			\begin{itemize}
				\item Define a \alert{formal framework} for transforming data from the relational to document model
				\item Design a collection of expressive \alert{query operators} for analyzing text from relational data sets
				\item Perform \alert{graph search} over the document model
				\item Investigate implementation techniques to make the query operators performant on modern, \alert{multicore machines}
			\end{itemize}
		\end{frame}

		\begin{frame}{Relational Model}
			\begin{itemize}
				\item A \alert{database} is a collection of relations
				\item A \alert{relation} is a set of named tuples
				\item Each \alert{named tuple} consists of a set of attributes corresponding to values
				\item An \alert{entity group} is a set of related tuples (joined by foreign key constraints)
			\end{itemize}
		\end{frame}

		\begin{frame}{Document Model}
			\begin{itemize}
				\item A \alert{document collection} is a set of documents
				\item A \alert{document} may have one or more fields
				\item A \alert{field} is a bag of tokens
				\item A prescribed lexical \alert{analyzer} converts bodies of text into a bag of \alert{tokens}
			\end{itemize}
		\end{frame}

	\section{Implementation}
		\begin{frame}{Framework Overview}
			\begin{itemize}
				\item Indexing
					\begin{enumerate}
						\item \alert{Iterate} over all named tuples in relational database
						\item \alert{Convert} each named tuple into a document
						\item \alert{Encode} relational information into one or more \alert{indexing document(s)}
					\end{enumerate}
				\item Search
					\begin{enumerate}
						\item \alert{Fuzzy value search} at the tuple-level
						\item \alert{Graph search} for connections among entity groups
					\end{enumerate}
			\end{itemize}
		\end{frame}

		\begin{frame}[fragile]{Iterate}
			\begin{itemize}
				\item Each entity and entity group defined in a configuration file
				\item Configuration specifies the SQL query to retrieve all entities from database
				\item This query is executed and each row is converted
			\end{itemize}

			\begin{figure}
				\begin{verbatim}
  (crawl
    [this db-conn idx-w]
    (let [sql (S :sql)]
      (execute-query db-conn sql (fn [row] ...))))
				\end{verbatim}
				\caption{Code to iterate over every named tuple in entity group}
				\label{lst:crawl}
			\end{figure}
		\end{frame}

		\begin{frame}{Convert}
			\begin{itemize}
				\item Each attribute of a named tuple directly maps to a field in a document
				\item Analysis is performed on each attribute before storing in a field
				\item The framework supports multiple analyzers
			\end{itemize}

			\begin{align}
				\attributes{\tuple} &\xrightarrow{analyzed} \fields{\doc} \\
				\attribute_1, \attribute_2, \dotsc, \attribute_n &\xrightarrow{analyzed} \field_1, \field_2, \dotsc, \field_n
			\end{align}

			Where \(\alpha_i\) is the value of an attribute, and \(f_i\) are the resulting tokens in a document.
		\end{frame}

		\begin{frame}{Encode}
			\begin{itemize}
				\item Relational information between related named tuples is encoded in the \alert{indexing document}
				\item This document, \(x\), is the concatenation of unique identifiers of every related document
			\end{itemize}

			\begin{align}
				x[\text{``entities''}] = \left\{\uid{\tuple} : \tuple \in V(\egraph)\right\}
			\end{align}

			Where \(\egraph\) is the entity group, and \(V(\egraph)\) is the set of named tuples in the entity group.
		\end{frame}

		\begin{frame}{Fuzzy Search at Tuple-Level}
			The encoding allows us to perform the following:

			\begin{itemize}
				\item Fuzzy search of relational attributes
				\item Search of named tuples in relations
				\item Find entity groups
			\end{itemize}
		\end{frame}

		\begin{frame}[fragile]{Graph Search Over Document Space}
			\begin{itemize}
				\item Use the indexing document to discover adjacent nodes
				\item Issue search query to discover all entity groups containing \(\uid{u}\)
			\end{itemize}

			\begin{verbatim}
(boolean-query [[(query :type :group) :and]
                [(query :entities id) :and]])
			\end{verbatim}
		\end{frame}

		\begin{frame}{Graph Search Algorithm and Implementation}
			\begin{itemize}
				\item Chose \alert{Breadth-First Search (BFS)} as search algorithm
				\item Adapted BFS to run concurrently without locking using Clojure's \alert{Software Transactional Memory (STM)}
				\item Utilized Clojure's concurrency primitives (atoms, references) in the concurrent implementation of BFS
			\end{itemize}
		\end{frame}

	\section{Evaluation}
		\begin{frame}{Data Corpus}
			\begin{itemize}
				\item Derived from MyCampus data\footnote{\url{http://uoit.ca/mycampus/}}
			\end{itemize}

			\begin{footnotesize}
				\begin{table}
					\centering

					\begin{tabular}{ll}
						\toprule
						Relation & Attributes \\
						\midrule
						Course & \underline{code}, title, subject \\
						Section & \underline{id}, actual, campus, capacity, credits, levels, registration\_start, \\
						 & registration\_end, semester, sec\_code, sec\_number, year, course \\
						Schedule & \underline{id}, date\_start, date\_end, day, schedtype, hour\_start, hour\_end, \\
						 & min\_start, min\_end, classtype, location, section\_id \\
						Instructor & \underline{id}, name \\
						Teaches & \underline{id}, schedule\_id, instructor\_id, position \\
						\bottomrule
					\end{tabular}

					\caption{Subset of mycampus dataset schema}
					\label{tbl:schema}
				\end{table}
			\end{footnotesize}
		\end{frame}

		\begin{frame}{Benchmarking Queries}
			\begin{itemize}
				\item Keywords are sampled from the database to form search queries
					\begin{itemize}
						\item May not occur within the same entity group
						\item Sampled from instructor name, course code, section id, etc.
					\end{itemize}
				\item Search for connections between these keywords
					\begin{itemize}
						\item Must utilize graph search to discover connections between keywords
						\item Monitor distance (hops) between keywords and measure performance
					\end{itemize}
			\end{itemize}
		\end{frame}

		\begin{frame}{Results}
			\begin{figure}
				\centering
				\includegraphics[scale=0.5]{../document/figures/charts/growth}
				\caption{Growth of runtime of each implementation, by hops}
			\end{figure}
		\end{frame}

		\begin{frame}{Results}
			\begin{figure}
				\centering
				\includegraphics[scale=0.5]{../document/figures/charts/1_hops}
				\caption{Runtime of implementations, 1 Hop}
			\end{figure}
		\end{frame}

		\begin{frame}{Results}
			\begin{figure}
				\centering
				\includegraphics[scale=0.5]{../document/figures/charts/4_hops}
				\caption{Runtime of implementations, 4 Hops}
			\end{figure}
		\end{frame}

		\begin{frame}{Results}
			\begin{figure}
				\centering
				\includegraphics[scale=0.5]{../document/figures/charts/6_hops}
				\caption{Runtime of implementations, 6 Hops}
			\end{figure}
		\end{frame}

	\section{Conclusion}
		\begin{frame}{Contributions}
			\begin{itemize}
				\item Provided a framework to transform data from the relational to document model
				\item Demonstrated the reversibility of this transformation
				\item Utilized the flexibility of the document model
					\begin{itemize}
						\item e.g.~spelling correction, entity group search
					\end{itemize}
				\item Performed graph search over document space
				\item Investigated the reduction in runtime from a concurrent graph search
			\end{itemize}
		\end{frame}

		\begin{frame}{Lessons Learned}
			\begin{itemize}
				\item Simple algorithms are easiest to parallelize
				\item Clojure's STM implementation is simple and effective
				\item Clojure is powerful and encouraged correct code that was easier to optimize later
			\end{itemize}
		\end{frame}

		\begin{frame}{Publication}
			This work has been submitted to the 15th IEEE conference on Information Reuse and Integration.

			\begin{figure}
				\centering
				\includegraphics[scale=0.3]{paper-thumbnail}
			\end{figure}
		\end{frame}

		\begin{frame}{Future Work}
			\begin{itemize}
				\item Simplify configuration
				\item Incremental indexing
				\item Generalize results by benchmarking standard datasets
			\end{itemize}
		\end{frame}

	\section*{}

	\frame{\titlepage}
\end{document}


\section{Real Time Trajectory Prediction Using Deep Conditional
Generative Models}\label{header-n953}

\emph{IEEE ROBOTICS AND AUTOMATION LETTERS, VOL. 5, NO. 2, APRIL 2020}
{[}36{]}

\subsection{Introduction}\label{header-n955}

Dynamic high-speed robotics tasks often require accurate methods to
forecast the future value of a physical quantity and these methods must
respect the application's real-time constraints. For example, to hit or
catch a flying ball, a robot needs to predict accurately and fast the
trajectory of the ball. Note that the time it takes to compute the
predictions, called \emph{latency}, is as important for the application
as the accuracy in the prediction. Physics-based models are often used
to trajectory forecasting because of their velocity in making a
prediction. Despite this, in some applications, the best known
physics-based model is not accurate enough or, even if the physics is
accurate, estimating all its relevant variables can be difficult. On the
other hand, a data-driven model could overcome these limitations and,
generally, their predictions are more accurate. However, the modern
data-driven approaches, like those based on recurrent neural networks,
suffer from cumulative errors. This work proposes a novel method for
trajectory prediction that mixes the power of deep learning and
conditional generative models to provide a data-driven approach for
accurate trajectory forecasting with the low latency required by
real-time applications. The system is tested using a table tennis
system, in which two robotic arms has to correctly hit a ball. The
figure below shows this system.

\begin{figure}[h!]
\centering
\includegraphics[width=0.7\linewidth]{images/tabletennis.png}
\caption{Table tennis robotic system}
\end{figure}

\subsection{Proposed method}\label{header-n958}

\subsubsection{Trajectory definition}\label{header-n959}

The term trajectory is commonly used to refer to a realization of a time
series or Markov decision process. A trajectory is defined as
$\tau=\{y_t^{n}\}^{T_n}_{t=1}$, where $T_n$ is a sequence of
multiple observations $y_t^{n}$ ($n$ represents the time and $t$
is the index of a trajectory in the data set). For the tennis example,
an observation $y^{n}_t$ is a three-dimensional vector representing
the ball position at time $t$ of the ball trajectory $n$. Each
trajectory $\tau_n∼ P(\tau)$ is assumed to be independently sampled
from the trajectory distribution $P(\tau)$. Formally, the goal of
trajectory forecasting is to compute the conditional distribution
$p(y_t,..., y_T | y_1,..., y_{t−1})$, representing the distribution of
the future values of a trajectory $\{y_t,..., y_T \}$ given the
previous observations $\{y_1,...., y_{t-1}\}$ ($y_t$ is a random
variable representing the observation indexed by time $t$ in any
trajectory). Some models use the factorization property of probability
theory
\newline
$ p(\boldsymbol{y}_{t:T} \, | \,\boldsymbol{y}_{1:t-1}) = \prod _{i=t}^{T}{p(\boldsymbol{y}_{i} \, | \,\boldsymbol{y}_{1:i-1})}, $
\newline
but they predict directly a single observation, while the others are
calculated by using the past predictions as input. This is a
\emph{recursive} approach: it uses its predictions as input to predict
farther into the future. These approaches can predict sequences of
arbitrary length, but they have the disadvantage that errors are
cumulative. However, for trajectory prediction in physical systems,
where we are measuring all the relevant variables, the authors would
expect long term prediction to be more accurate. In fact, this is not
true and even a data-driven model, implemented for example with LTSM, is
heavily penalized by the cumulative error, that renders long term
predictions less accurate.

\subsubsection{Deep conditional generative models}\label{header-n963}

The goal is to find a way to represent the conditional distribution
$p(y_{t:T} | y_{1:t−1})$ directly, in a way where the model
predictions are not fed back into the model. In addition, we want to use
a powerful model that can capture non-linear relationships between the
future and past observations. To do this, a complex non-linear
regression model, such as a neural network, can be used. The authors use
two auxiliary input variables $x^{t}$ and $\hat x^{t}$ that
represent a zero-padded input observation and an observation mask. In
particular, $x^{t} = 1$ represent the observations viewed so far,
while the non-observed parts of the trajectory are tagged with
$x^{t} = 0$. Similarly, the variable $\hat x^{t} \in \{0, 1\}$
indicates which values were observed and which values were not. Using
the auxiliary variables the model can make predictions with any number
of input observations $t \in \{0, 1,...,T\} $. The proposed approach
assumes a fixed maximum prediction horizon $T$ for all trajectories.

\subsubsection{Capturing Uncertainty and Variability}\label{header-n965}

Quantifying the uncertainty of the trajectory predicted by the model is
important for decision making. In robot table tennis, for example, the
robot could wait for more ball observations if there is high uncertainty
about the ball trajectory, but waiting too long will result in failure
to hit the ball. Uncertainty can be captured using a latent variable
$z_n$, that can be mapped to a trajectory using a complex non-linear
function. The authors want to emphasize that the limitation of a fixed
prediction horizon $T$ means that prediction beyond $T$ can't be
done, but the model can be trained with trajectories of any length
$T_n$. The proposed approach is based on variational auto-encoders.
The decoder network takes as input the previous observations
$y_{1:t−1}$ represented by $(x^{t} , \hat x^{t} )$ as well as the
latent variable $z$ that encodes one of the possible future
trajectories $\hat y$ (which contains the predicted future
observations $y_{t:T}$. The encoder network produces the variational
distribution $q\varphi(z | y1:t)$, which is a partial trajectory with
observations $y_{1:t}$ to the latent space $z$.

\begin{figure}[h!]
\centering
\includegraphics[width=0.8\linewidth]{images/encdec.png}
\caption{Encoder and decoder networks for the proposed approach}
\end{figure}

\subsubsection{Inference and training procedure}\label{header-n968}

At prediction time, the encoder computes the latent space distribution
using the given past observations. It produces a mean $\mu_z$ and a
standard deviation $\sigma_z$. Next, several values
$z^l \sim {\mathcal N}(z | \mu_z, \sigma_z)$ are sampled and they are
passed, with the past observations, to the decoder module to predict the
future trajectory. The training set consists of a set of trajectories
$\tau_n$ each of a possibly different length $T_n$. Sampled
mini-batches are used to train the model: for any trajectory, a cut
point $t : 0 <t $ is randomly selected and the lower bound for
$p(y_{t:T} | y_{1:t−1})$ is computed for the particular $t$. In this
way, the model will learn to make predictions for any number of given
observations, including an empty set. Finally, to make our model more
robust, the authors randomly generate missing observations and outliers
for the previous observations $y_{1:t−1}$ in each of the trajectories
included in the training mini-batch. To generate outliers, an
observation is simply replaced with a random value within the input
domain.

\subsection{Experiments}\label{header-n970}

The authors evaluate the proposed method (which predicts the trajectory
of a table tennis ball) both in a real and simulated system. The
proposed method is called "TVAE" (Trajectory Variational Auto-Encoder).
The metric measured is the prediction error and latency. The baseline
methods, used to compare and evaluate the performance of the proposed
method, are an LTSM and the physics-based approach. The ball's physics
is described in {[}37{]}, while the initial velocity and position are
calculated as described in {[}38{]}. The latter method consists of
fitting a polynomial to the first $n$ observations and evaluating the
polynomial of degree $k$ and its derivative in $t = 0$. These
parameters are set to $n = 30$ and $k = 2$, that provided the
highest predictive performance on the training data set.

\subsubsection{Prediction accuracy in simulation}\label{header-n972}

The results should be optimal for the physics-based model on simulation,
where the only source of error is the initial position and velocity
estimation from noisy ball observations. The authors generated 2000 ball
trajectories for training and another 200 for the test. The training
results obtained in a simulated environment are plotted in the following
figure. In simulation, the error distribution of the proposed method and
the physics-based model is almost identical. The results of the LSTM are
slightly better than the proposed model for the first 10 observations,
but the error for long term prediction grows uncontrollably.

\begin{figure}[h!]
\centering
\includegraphics[width=0.37\linewidth]{images/accuracyballres.png}
\caption{Distribution of the error in the test set for simulated data as a function of the number of observations}
\end{figure}

\subsubsection{Prediction accuracy in the real
system}\label{header-n975}

There are several issues that make ball prediction harder on the real
system: there are missing observations, the error is not the same in all
the space due to the effects of lens distortion, and the ball spin can
not be observed directly. The training set has 614 samples, while the
test set is composed of 35 trajectories. All samples are collected in a
real environment: the ball is thrown using the hand, using a mechanical
launcher, and hitting them with a table tennis racket. Since the
trajectories have typically a duration between 0.8 and 1.2 seconds, the
time horizon is set to $T = 1.2$ seconds. The figure below shows the
training results obtained using real-time data. The proposed method
outperforms the long term prediction accuracy of the other models. The
LSTM, as expected, is very precise at the beginning but starts to
accumulate errors and becomes quickly less accurate. The physics-based
model is in the middle: more accurate than the LTSM approach but less
accurate than TVAE.

\begin{figure}[h!]
\centering
\includegraphics[width=0.37\linewidth]{images/accuracyballresreal.png}
\caption{Distribution of the error in the test set for real data as a function of the number of observations}
\end{figure}

\subsubsection{A real robot table tennis system}\label{header-n978}

The authors implemented the proposed method in a real robot table tennis
system, to test the performance in a real game. To do this, they
modified the ProMP approach {[}39{]} to use the proposed ball model.
ProMP works as follows:

\begin{itemize}
\item
  first, the initial time and duration of the movement primitive are
  computed by maximizing the likelihood of hitting the ball;
\item
  second, the movement primitive is adapted to hit the ball using a
  probability distribution by conditioning the racket distribution to
  intersect the ball distribution;
\item
  third, to avoid dangerous movements, the robot does not hit if the
  likelihood is lower than a certain threshold.
\end{itemize}

To compute the ball distribution, the authors took 30 trajectory samples
from the proposed model and computed empirically its mean and
covariance. The adapted method obtained a hitting rate of 98.9\%
compared to 96.7\% obtained using a ProMP. This experiment also shows
that the presented approach can be used in a system with hard real-time
constraints. The proposed system can infer the future ball trajectory
from past observations with a latency between 8 ms and 10 ms.


\subsection{Online and offline recognition}

\begin{frame}{What is my Bachelor's thesis about?}
    \begin{itemize}
        \item Recognition of handwritten mathematical symbols
        \item On-line recognition, not OCR!
        \item Given a series of points $(x(t), y(t), b(t))$\\
              I want to get the proper \LaTeX{} code.
    \end{itemize}
\end{frame}

\begin{frame}{Why do I work on this topic?}
    \begin{itemize}
        \item \LaTeX{} is easy as soon as you know the \textbackslash{}codes.
        \item It's hard to find the \LaTeX{} code of single symbols.
        \item It's much harder to find complete formulas.
    \end{itemize}

    % I want to
    % \begin{itemize}
    %     \item provide a tool that enables beginners to get the best \LaTeX{} code
    %           for their formula,
    %     \item find out what works best for symbol recognition
    %     \item and provide data and a platform to test new ideas for classifiers
    % \end{itemize}

    For now: recognition of isolated symbols. That means:

    single symbol \enquote{formulae} rather than multi symbol formulae
\end{frame}


%!TEX root = ../data-imputation.tex

\section{Methods}
\label{sec:methods}
%
One of the main goals of this work is to provide a comprehensive evaluation of missing value imputation methods under realistic conditions. In particular, we focus on two aspects: (a) a broad suite of real-world data sets and tasks and (b) realistic missingness patterns. The following sections describe the data sets and missingness patterns we considered and the data preprocessing steps. Then follows a detailed description of the compared imputation methods, the used hyperparameter optimization strategies, and metrics for evaluation.

\subsection{Data sets}
\label{sec:datasets}
%
We focus on a comprehensive evaluation with several numeric data sets and tasks (regression, binary classification, and multi-class classification). The OpenML database~\citep{OpenML2013} contains thousands of data sets and provides an API. The Python package \code{scikit-learn} \citep{scikit-learn} can use this API to download data sets and create well-formatted \code{DataFrames} that encode the data properly.

We filter available data sets as follows. To calculate the imputation performance, we need ground truth data sets without missing values. Moreover, especially deep learning models need sufficient data to learn their task properly. However, because we plan to run many experiments, the data sets must not be too big to keep training times feasible. For this reason, we choose data sets without missing values that contain 5 to 25 features and 3.000 to 100.000 observations. We then removed duplicated, corrupted, and Sparse ARFF\footnote{Attribute-Relation File Format} formatted data sets.

The resulting 69 data sets are composed of 21 regression, 31 binary classification, and 17 multi-class classification data sets. The supplementary material contains a detailed list of all data sets and further information, such as OpenML ID, name, and the number of observations and features.

\subsection{Missingness Patterns}
\label{sec:missingess_pattern}
Most research on missing value imputation considers three different types of missingness patterns:
%
\begin{itemize}
\item Missing completely at random (MCAR, see Table \ref{tab:missingness_patterns_MCAR}): \\
Values are discarded independently of any other values
\item Missing at random (MAR, see Table \ref{tab:missingness_patterns_MAR}): \\
Values in column $c$ are discarded dependent on values in another column $k\neq c$
\item Missing not at random (MNAR, see Table \ref{tab:missingness_patterns_MNAR}): \\
Values in column $c$ are discarded dependent on their value in $c$
\end{itemize}
%
The missingness pattern most often used in the literature on missing value imputation is MCAR. Here the missing values are chosen independently at random. Usually, the implementations of this condition draw a random number from an uniform distribution and discard a value if that random number was below the desired missingness ratio. Few studies report results on the more challenging conditions MAR and MNAR. We here aim for realistic modeling of these missingness patterns inspired by observations in large-scale real-world data sets as investigated in \cite{Biessmann2018a}. We use an implementation proposed in \cite{Schelter2020a} and \cite{Jenga}, which selects two random percentiles of the values in a column, one for the lower and one for the upper bound of the value range considered. In the MAR condition, we discard values if values in a random other column fall in that percentile. In the MNAR condition, we discard values in a column if the values themselves fall in that random percentile range.
%
\begin{table}
	\centering
%	\caption{
%		Examples of missingness patterns for a missingness ratio of 50\%. 	}
%	\label{tab:missingness_patterns}
%	\vspace{1em}
%	\begin{subtable}{0.3\textwidth}
\begin{minipage}{0.28\textwidth}
\centering
	\begin{tabular}{cc}
\toprule
 height &  height$_{\text{MCAR}}$ \\
\midrule
  179.0 &                     ? \\
  192.0 &                     ? \\
  189.0 &                 189.0 \\
  156.0 &                 156.0 \\
  175.0 &                     ? \\
  170.0 &                 170.0 \\
  181.0 &                     ? \\
  197.0 &                     ? \\
  156.0 &                 156.0 \\
  160.0 &                 160.0 \\
\bottomrule
\end{tabular}
\caption{
		Applying the MCAR condition to column \textit{height} discards five out of ten values independent of the height values.
	}
	\label{tab:missingness_patterns_MCAR}
\vspace{2em}
\end{minipage}
\hfill
\begin{minipage}{0.3\textwidth}
\centering
	\begin{tabular}{ccc}
\toprule
 height & gender &  height$_{\text{MAR}}$ \\
\midrule
  200.0 &      m &                    ? \\
  191.0 &      m &                    ? \\
  198.0 &      f &                198.0 \\
  155.0 &      m &                    ? \\
  206.0 &      m &                    ? \\
  152.0 &      f &                152.0 \\
  175.0 &      f &                175.0 \\
  159.0 &      m &                    ? \\
  153.0 &      f &                153.0 \\
  209.0 &      m &                209.0 \\
\bottomrule
\end{tabular}
\caption{In the MAR condition, \textit{height} values are discarded dependent on values in another column,  here \textit{gender}. All discarded \textit{height} values correspond to rows in which \textit{gender} was \textit{male}.
}
	\label{tab:missingness_patterns_MAR}
\end{minipage}
\hfill
\begin{minipage}{0.28\textwidth}
\centering
	\begin{tabular}{cc}
\toprule
 height &  height$_{\text{MNAR}}$ \\
\midrule
  154.0 &                     ? \\
  181.0 &                 181.0 \\
  207.0 &                 207.0 \\
  194.0 &                 194.0 \\
  153.0 &                     ? \\
  156.0 &                     ? \\
  198.0 &                 198.0 \\
  185.0 &                 185.0 \\
  155.0 &                     ? \\
  164.0 &                     ? \\
\bottomrule
\end{tabular}
\caption{In the MNAR condition, \textit{height} values are discarded dependent on the actual \textit{height} values. All discarded values correspond to small \textit{height} values.
}
	\label{tab:missingness_patterns_MNAR}
\vspace{1em}
\end{minipage}

\end{table}

\subsection{Data Preprocessing}
\label{sec:preprocessing}
%
Data preprocessing is often an essential part of ML pipelines to achieve good results \citep{Sculley2015}. In our experiments, we apply the following three preprocessing steps for all imputation methods:
%
\begin{itemize}
	\item Encode categorical columns: \\
		Categories are transformed into a numerical representation, which is defined on the training set and equally applied to the test set

	\item Replace missing values: \\
		To avoid the imputation model from failing

	\item Normalize the data: \\
		Columns are rescaled to the same range, which is defined on the training set and equally applied to the test set
\end{itemize}
%
However, the concrete techniques for discriminative imputation, described in Sections \ref{sec:simple_imputation} to \ref{sec:dl_imputation}, and generative approaches, described in Section \ref{sec:generative_imputation}, are different.

For discriminative imputation approaches, we substitute missing values with their column-wise mean/mode value, one-hot encode categorical columns and normalize the data to zero mean and unit variance.
For generative imputation approaches, we need to preserve the number of columns. For this reason, we encode the categories of categorical columns as values from $0$ to $n-1$, where $n$ is the number of categories. Then, missing values are replaced with random uniform noise from $0$ to $0.01$, and, finally, the data is min-max scaled ranging from $0$ to $1$.

\subsection{Imputation Methods}
\label{sec:methods:impuation}
%
In this section, we describe our six different imputation methods. The overall goal of an imputation method is to train a model on a data set $\vec{X}\in\R^{n\times d} = [\vec{x}_1, \vec{x}_2, ..., \vec{x}_{i-1}, \vec{x}_{i+1}, ..., \vec{x}_d]$, where $d$ is the number of features, $n$ the number of observations, and $\vec{x}_i$ denotes the to-be-imputed column.
To abstract crucial steps such as preprocessing the data (see Section \ref{sec:preprocessing}) and cross-validating the imputation method's hyperparameters (see Section \ref{sec:HPO}), we define a framework implemented by all of the following imputation approaches.

\subsubsection{Mean/Mode Imputation}
\label{sec:simple_imputation}
%
As a simple imputation baseline, we use the column-wise \code{mean} for numerical or \code{mode}, i.e., the most frequent value,  for categorical columns to fill missing values.

\subsubsection{$k$-NN Imputation}
\label{sec:knKNN}
%
A popular ML imputation baseline is $k$-NN imputation, also known as Hot-Deck imputation~\citep{Batista2003}. For our implementation thereof, we use \code{scikit-learn}'s \code{KNeighborsClassifier} for categorical to-be-imputed columns and \code{KNeighborsRegressor} for numerical columns, respectively.

\subsubsection{Random Forest Imputation}
%
Similarly to the $k$-NN imputation approach, described in Section \ref{sec:knKNN}, we implement the random forest imputation method using \code{scikit-learn}'s \code{RandomForestClassifier}, and \code{RandomForestRegressor}.

\subsubsection{Discriminative Deep Learning Imputation}
\label{sec:dl_imputation}
%
Often simple deep learning models can achieve good imputation results~\citep{Biessmann2018a}. To easily optimize the model's architecture, we use the AutoML\footnote{"automated machine learning (AutoML) [...] automatically set [the model's] hyperparameters to optimize performance" \cite{AutoML}} library \code{autokeras} \citep{AutoKeras} to implement the discriminative deep learning imputation method.
For categorical columns, we use \code{autokeras}' \code{StructuredDataClassifier} and for numerical columns \code{StructuredDataRegressor}. Both classes take care of properly encoding the data themselves and optimizing the model's architecture and hyperparameters. We use $max\_trials = 50$, which means \code{autokeras} tries up to $50$ different model architecture and hyperparameter combinations, and $epochs = 50$, such that each model is trained for a maximum of $50$ epochs (\code{autokeras} uses early stopping by default).

\subsubsection{Generative Deep Learning Imputation}
\label{sec:generative_imputation}
%
All of the above approaches essentially follow the ideas known in the statistics literature as multiple imputation with chained equations (MICE) \citep{Little} or as {\em fully conditional specification} \citep{vanBuuren2018}: a discriminative model is trained on all but one column as features and the remaining column as the target variable. This approach has the advantage to be applicable to any supervised learning method, but it has the decisive disadvantage that for each to-be-imputed column, a new model has to be trained. Generative approaches are different in that they train just one model for an entire table. All matrix factorization-based approaches, such as \cite{Troyanskaya2001,Koren2009,Mazumder2010}, can be thought of as examples of generative models for imputation. We do not consider those linear generative models here as they have been shown to be outperformed by the mentioned methods and focus on deep learning variants of generative models only.

Generative deep learning methods can be broadly categorized into two classes: (variational) autoencoders (VAE)~\citep{VAE}\footnote{We focus on probabilistic autoencoders here as there are more imputation methods available for VAEs} and generative adversarial networks (GAN)~\citep{GAN}. In the following, we shortly highlight some representative imputation methods based on either of these two and describe the implementation used in our experiments.

\paragraph{Variational Autoencoder (VAE) Imputation}
%
VAEs learn to encode their input into a distribution over the latent space and decode by sampling from this distribution \citep{VAE}. Imputation methods based on this type of generative model include \cite{HIVAE, VAE_for_genomic_data, VAEM}. Rather than comparing all existing implementations, we focus on the original VAE imputation method for the sake of comparability with other approaches. To find the best model architecture, i.e., the number of hidden layers and their sizes, we follow the approach proposed by \cite{CaminoVAE}. We optimized using zero, one, or two hidden layer(s) for the encoder and decoder and fixed their sizes relative to the input dimension, i.e., the table's number of columns. If existing, the encoder's first hidden layer has $50\%$ of the input layer's neurons and the second layer $30\%$. The decoder's sizes are vice versa for upsampling the information to the same size as the input data. The latent space is also fixed to $20\%$ of the input dimension.
For training, we use Adam optimizer with default hyperparameters, batch size of $64$, and early stopping within $50$ epochs.

\paragraph{Generative Adversarial Network (GAN) Imputation}
%
GANs consist of two parts - a generator and a discriminator \citep{GAN}. In an adversarial process, the generator learns to generate samples that are as close as possible to the data distribution, and the discriminator learns to distinguish whether an example is true or generated. Imputation approaches based on GANs include \cite{GAIN, VIGAN, MisGAN}.
Here we employ one of the most popular approaches of GAN-based imputation, Generative Adversarial Imputation Nets (GAIN)~\citep{GAIN}.
GAIN adapts the original GAN architecture as follows.
The generator's input is the concatenation of the input data and a binary matrix that represents the missing values. The discriminator learns to reconstruct the mask matrix. Its input is the concatenation of the generator's output and a hint matrix, which reveals partial information about the missingness of the original data. The computation of the hint matrix incorporates the introduced hyperparameter $hint\_rate$. A second hyperparameter GAIN introduces $\alpha$ helps to balance the generator's performance for observed and missing values.
For training, we use Adam optimizer with default hyperparameters except for the learning rate for generator and discriminator, batch size of $64$, and early stopping within $50$ epochs.

\subsection{Hyperparameter Optimization}
\label{sec:HPO}
%
Optimizing and cross-validating hyperparameters are crucial to gain insights into a models' performance, robustness, and training time. Therefore, we choose for each imputation model the, as we find, most important hyperparameters and optimize them using cross-validated grid-search. For the $k$-NN and random forest imputation methods, we use 5-fold cross-validation, whereas we only 3-fold cross-validate VAE and GAIN to reduce the overall training time. Table \ref{tab:HPO} gives an overview of all imputation approaches and their hyperparameters we optimize, and the number of combinations. We do not define hyperparameter grids for mean/mode and DL imputation, as the former is parameterless and the latter optimized by \code{autokeras}.
%
\begin{table}[]
	\centering
	\begin{tabular}{@{}llll@{}}
		\toprule
		\multirow{2}{*}{Imputation Method} & \multicolumn{2}{c}{Hyperparameters}                          & \multirow{2}{*}{Grid Size} \\\cline{2-3}
		\\[-0.75em]
		& \multicolumn{1}{c}{Name}        & \multicolumn{1}{c}{Values} &                            \\ \midrule
		Mean/Mode                         &                                 &                            &                           \\
		\\[-0.5em]
		$k$-NN                             & $n\_neighbors$                  & \{1, 3, 5\}                & 3                          \\
		\\[-0.5em]
		Random Forest                      & $n\_estimators$                 & \{10, 50, 100\}            & 3                          \\
		\\[-0.5em]
		Discriminative DL*                   &                                 &                            &                            \\
		\\[-0.5em]
		VAE                                & $n\_hidden\_layers$             & \{0, 1, 2\}                & 3                          \\
		\\[-0.5em]
		\multirow{4}{*}{GAIN}              & $alpha$                         & \{1, 10\}                  & \multirow{4}{*}{16}        \\
		& $hint\_rate$                    & \{0.7, 0.9\}               &                            \\
		& $generator\_learning\_rate$     & \{0.0001, 0.0005\}         &                            \\
		& $discriminator\_learning\_rate$ & \{0.00001, 0.00005\}       &                            \\ \bottomrule
		\multicolumn{4}{l}{\footnotesize*Optimized using \code{autokeras}, see Section \ref{sec:dl_imputation}}
	\end{tabular}
	\caption{An overview of all imputation methods and their hyperparameters we optimized. \emph{Mean/Mode} imputation does not have any hyperparameters, and \emph{Discriminative DL} is optimized using \code{autokeras}, which is why we do not explicitly define a hyperparameter grid.}
	\label{tab:HPO}
\end{table}

\subsection{Evaluation Metrics}
%
To evaluate our experiments, we use two metrics: root mean square error ($RMSE$) and $macro\ F1$-score.
%
The $RMSE$ is defined as:
%
\begin{equation}
	RMSE = \sqrt{\frac{1}{N} \sum_{i = 0}^{N} (y_i - \hat{y_i})^2}
	\label{eq:RMSE}
\end{equation}
%
where $N$ is the number of observations, $y_i$ the observed values, and $\hat{y}_{i}$ the predicted values.
The $macro\ F1$-score is defined as the mean of class-wise $F1$-scores:
%
\begin{equation}
	macro\ F1 = \frac{1}{C}\sum_{i = 0}^{C} F1_i
	\label{eq:F1}
\end{equation}
%
where $i$ is the class index, $C$ the number of classes and the definition of $F1$ is:
%
\begin{equation}
	F1 = \frac{TP}{TP + \frac{1}{2}(FP + FN)}
\end{equation}
%
where $TP$ is the number of true positives, $FP$ the number of false positives, and $FN$ the number of false negatives.

Imputing categorical columns can be seen as a classification task. Accordingly, we measure performance in this case and for downstream classification tasks by the $macro\ F1$-score. In the following, we use the terms $F1$-score and $F1$ synonymously for $macro\ F1$-score. For regression tasks and imputing numerical columns, we use the $RMSE$. Since $F1$ is a score measure, larger values imply better performance. On the other hand, $RMSE$ is an error measure: a smaller value indicates better performance.


\chapter[SetCuts\mbox{ : } conversion from range to kinetic energy]
         {SetCuts\mbox{ : } conversion from
              range to kinetic energy }

\section{Charged particles}
 Starting from a particle cut given in stopping range, the method
 constructs a vector holding the cut values in kinetic energy for every
 material. The main steps of the algorithm are the same for all the
 charged particles, the only difference is that different energy loss
 formulae are used for electrons, positrons and heavy charged particles
 ( muon,pion,proton,...).

  In the case of charged hadrons this procedure is applied for the proton
 and antiproton only , the cut values in kinetic energy for other hadrons
 are computed
 using the proton and antiproton energy loss and range tables .
     \subsection{General scheme}
        \begin{enumerate}
           \item An energy loss table is created and filled for all the elements
                 in the element table.
           \item For every material in the material table the following steps are
                 performed:
              \begin{enumerate}
                 \item a range vector is constructed using the energy loss table and
                       formulae for the low energy part of the calculations,
                 \item the conversion from stopping range to kinetic energy is performed and
                       the corresponding element of the {\tt KineticEnergyCuts} vector is set
                       (It contains the particle cut value in kinetic energy for the
                        actual material.),
                 \item the range vector is deleted.
               \end{enumerate}
          \item The energy loss table is deleted at the end of the process.
       \end{enumerate}
    \subsection{Energy loss formula for heavy charged particles}
     The energy loss of the particle is calculated from a simplified Bethe-Bloch
     formula if the kinetic energy of the particle is above the value :
     \[
     T_{lim}=2 \,MeV \times \left( \frac { \mbox{particle mass}}{\mbox{proton mass}} \right)
     \]
     The simplified here means that the low energy shell correction term and
     the high energy Sternheimer density correction term have been omitted.
     Below the energy value $T_{lim}$ a simple parametrized energy loss formula
     is used to compute the loss, which reproduces the energy loss values
     of the stopping power tables fairly well. The main reason of using a
     parametrized formula for low energy is that the Bethe-Bloch breaks down
     at low energy. The formula has the following form :
     \[
    \frac{dE}{dx} = \left \{ \begin{array}{ll}
                   a*\sqrt{\frac{T}{M}}+b*\frac{T}{M} & \mbox{for $T \in [0, \, T_0]$}
                   \\ \\
                   c*\sqrt{\frac{T}{M}} & \mbox{for $T \in [T_0, \, T_{lim}]$}
                      \end{array}
            \right.
     \]
   \begin{tabbing}
      whereb:bbb\= \kill
      where :  \> M = particle mass, \\
               \> T = kinetic energy, \\
               \> $ T_0=0.1 \, MeV \times Z^{1/3} \times \mbox{ M/(proton mass)} $\\
               \> Z = atomic number.
    \end{tabbing}
     the paramaters $a,b,c$ have been chosen in such a way that $dE/dx$ is a
     continuous function of T at $T=T_{lim}$ and $T=T_0$ , and $dE/dx$ reaches its maximum
     at the correct T value.

    \subsection{Energy loss of electrons and positrons}
     The Berger-Seltzer energy loss formula has been used for T $>$ 10 keV to
     compute the energy loss comes from the ionization . This formula plays the
     role of the Bethe-Bloch for electrons ( see e.g. the GEANT3 manual).Below
     10 keV the simple c/(T/mass of electron) parametrization has been used,
     where c can be determined from the requirement of continuity at T = 10 keV.
     As in the case of electrons the radiation loss is important even at
     relative low (few MeV ) energy, a second term has been added to the
     energy loss formula which accounts for the radiation losses (losses due to
     bremsstrahlung). This second term is an empirical parametrized formula.
     For positrons a different formula is used to calculate the ionization
     loss, the term accounting for the radiation losses is the same than that
     for electrons.

    \subsection{Range calculation}
     The stopping range is defined as :
              \[ R(T)= \int_0^T \frac{1}{(dE/dx)} \, dE \]
     The integration has been done analytically for the low energy part and
     numerically above an energy limit.

\section{Photons}
 Starting from a particle cut given in absorption length, the method
 constructs a vector holding the cut values in kinetic energy for every
 material. The main steps of the algorithm are the following :
    \subsection{General scheme}
       \begin{enumerate}
          \item A cross section table is created and filled for all the elements
                in the element table.
          \item For every material in the material table the following steps are
                performed:
                \begin{enumerate}
                    \item an absorption length  vector is constructed using the
                          cross section table
                    \item the conversion from absorption length to kinetic energy is
                          performed and the corresponding element of the
                          {\tt KineticEnergyCuts} vector is set
                          (It contains the particle cut value in kinetic energy
                           for the actual material.),
                    \item the absorption length vector is deleted.
                \end{enumerate}
           \item The cross section table is deleted at the end of the process.
       \end{enumerate}
    \subsection{Cross section formula for elements}
        An approximate empirical formula is used to compute the {\em absorption
        cross section} of a photon in an element.
        The {\em absorption cross section} means here the sum of the cross sections
        of the gamma conversion, Compton scattering and photoelectric effect.
        These processes are the 'destructive' processes
        for photons , they destroy the photon or decrease its energy.
        (The coherent or Rayleigh scattering changes the direction of the gamma
        only , its cross section is not included in the {\em absorption cross section}.)
    \subsection{Absorption length vector}
        The {\tt AbsorptionLength} vector is calculated for every material as :
         \begin{center}
                 {\tt AbsorptionLength} = 5/(macroscopic absorption cross section)
         \end{center}
        The factor 5 comes from the requirement that the probability of having
        no 'destructive' interaction should be small, hence
        \begin{eqnarray*}
        \exp(-\mbox{{\tt AbsorptionLength * MacroscopicCrossSection}}) &=&\exp(-5) \\
         &=& 6.7 \times 10^{-3}
        \end{eqnarray*}
     \subsection{Meaningful cuts in absorption length}
         The photon cross section for a material has a minimum at a certain kinetic
         energy $T_{min}$. The {\tt AbsorptionLength} has a maximum at $T=T_{min}$, the value of
         the maximal {\tt AbsorptionLength} is the biggest "meaningful" cut in absorption
         length . If the cut given by the user is bigger than this maximum, a warning
         is printed and the cut in kinetic energy is set to the maximum gamma energy
         (i.e. all the photons will be killed in the material).

\section{Status of this document}
   9.10.98  created by L. Urb\'an.


The Synchronisation Phase allows those nodes that have produced the correct ledger update to then pass this update onto the rest of the network, thereby integrating the changes held within upon the overall state of the ledger. Catalysts DFS is the mechanism for distribution of the newly formed ledger update, thereby two distinct \\

At this stage a producer $p$ who during the consensus phase managed to produce the majority update can now pass along the correct ledger update. \\

Each $p$ that found themselves to be within the majority broadcast their ledger update to the network. This takes the form:

\begin{center}
$LSU = \#(\mathcal{L}_{final})~||~T~||~PId$
\end{center}

Meaning that contained within the final ledger state are three elements, the bloom filter containing all the users that a producer $p$ found to have passed on the correct ledger state updates the list of transactions $T$ that were incorporated into this ledger update, and their PId in order to verify authenticity of the update. From the LSU a CID is created that relates to the updates location on the DFS. \\

This combined with the information recorded in the transactions in the RANDAO provides users with the information required to determine which users from the pool of producers $P$ that were selected from this cycle were. \\

The producer then pins this update to the DFS, adding their name to the hash table. If they are the first to do so they also create the CID for this update. The producer can the broadcast this CID to the network, declaring that a new delta has been created. Other peers on the network can access the update and request the update from one of the producers that holds the update.

\begin{comment}

During the synchronisation phase $p$ executes the following steps:

\begin{enumerate}

\item Producer $p$ selects from the producer votes $V$ which received the most popular unique $V$. The number of most popular votes received is defined as $V_{max}$. This $V_{max}$ value must exceed a specified threshold $V_{thresh}$. So $V_{max} \geq V_{thresh}$.

\item $p$ creates a list $\mathcal{L}_{final}(vote)$. To $\mathcal{L}_{final}(vote)$ the producer $p$ appends the identifier of any producer that their given $V == V_{max}$ \textit{i.e.} they voted among the majority. Furthermore that producer must appear in at least half the $\mathcal{L}(vote)$ lists found in the $V$ values $p$ collected from other producers.

\item If the producer $p$ also created the correct ledger state update $LSU$ then they can write it to the DFS with the content address CID \cite{ADD LINK TO CID OBJ}.

\item Producer $p$ then creates the final producer output that can be declared to the network. This output is:
\begin{center}
\fbox{$\mathbf{o} = CID~||~\#(\mathcal{L}_{final}(vote))~||~Id$}
\label{eq:Hj}
\end{center}

The producer then broadcasts $\mathbf{o}$ to the network.
\end{enumerate}
\end{comment}
\begin{comment}

\subsubsection{Ledger state synchronisation across the network}

THIS PART NEEDS CHECKING AS THIS RELATES TO NETWORK SYNC

During the time period [$t_{s}, t_s + \Delta t_{cycle}$], user nodes collect $\{o_k\}_{\forall k \in P}$ producer outputs broadcast by the producers.
By extracting the identifier $Id_k$ embedded in any collected output $o_k$, a user node can easily compile a list of producer identifiers having broadcast the same second hash value $\mathcal{H}(\Delta L_n)$ (concatenated with the same list $\mathcal{L}_{n}(vote)$). Upon receiving $x > P/2$ identical addresses $\{\mathcal{A}_k = \mathcal{A}_n\}_{k \in x}$, the user nodes can read the common address content ($\Delta L_n$) from DFS. Using $\Delta L_n$ a user node can safely synchronise their local copy of the ledger and write it to their DFS if not already done. The balance of accounts stored on the ledger are updated and the producers effectively collect their rewards.\\

Worker nodes also store the list $\mathcal{L}_{n}(vote)$ embedded in each $o_k$ output. If selected to be a producer for the next cycle $\mathcal{C}_{n+1}$, a worker can use it to generate the reward allocated to the producers who correctly voted for the accurate ledger state update during the ledger cycle $\mathcal{C}_{n}$.\\

\begin{verbatim}
pragma solidity ^0.5.11;
contract RANDAO is Ownable
{
    int deltaHeight;
    int cycleVotes;
    int targetThreshold;

    struct Delta {
        bytes32 deltaHash;
    }
    struct Guest {
        address guestAddress;
        uint guestId;
    }
    struct validator {
        uint validatorId;
        bytes32 commitment;
        address validatorAddress;
    }
    address[] public stakers;
    bytes32[] public candidateDeltas;
    mapping(bytes32 => bool) commitments;
    mapping(address => Delta) public cycleVotes;
    mapping(address => validator) public stakersMapping;
    event NodeStake(address guest);

    constructor
    (
        int deltaHeight
    )
    public
    {
        deltaHeight = deltaHeight;
    }
    function stakeEntry(bytes32 commitment) public payable
    {
        address _senderAddress = _msgSender();
        require(msg.value == 21 Kat, "you need more Kats to stake");
        stakersMapping[_senderAddress].guestId = stakers.push(_senderAddress) - 1;
        // generate PRNG logic here
        emit NodeStake(_senderAddress);
    }
    function voteDelta(bytes32 favouriteDelta) public payable
    {
        address _senderAddress = _msgSender();
        if(stakers[stakersMapping[_senderAddress].guestId] == _senderAddress)
        {
            if (cycleThreshold < targetThreshold)
            {
                cycleVotes[_senderAddress] = candidateDeltas.push(favouriteDelta);
            }
        }
    }
}
\end{verbatim}

\end{comment}


\section{User Clustering}
\label{sec:uc}

%clear points
%road map
%detail of each step, with motivation
%proof if applicable
%self-explain

\par Providing the \textit{Feature Data}, the User Clustering module takes the charge of grouping each user concerned into a proper cluster,
as illustrated in  Algorithm \ref{alg:uc}.
%
The idea is to enumerate a number of clustering trials (line \ref{enu}) and select the optimal solution with the best Silhouette coefficient value ($v$ in line \ref{opti}).
In principle, each trial (referred by $t$ in line \ref{enu}) first performs a clustering task (line \ref{task}; to be detailed in section \ref{sec:cluster}), resulting a cluster (by $l(u)$) for each user $u$ (line \ref{l});
then, each user obtains a Silhouette coefficient value $v(u)$ stemmed from the in/out-cluster distances (lines \ref{v-b}--\ref{v-e}; shall be illustrated in section \ref{sec:compu});
finally, the averaged Silhouette coefficient value of all users serves as the Silhouette coefficient value of the current trial, written as $v(t)$ (line \ref{avg}), by which the said selection process is conducted (line \ref{opti}).

\begin{algorithm}[t]
\begin{small}
\caption{User Clustering in \sys{}}
\label{alg:uc}
\begin{algorithmic}[1]
\State Input: \textit{Feature Data} $F$  of a set of users, the minimum/maximum number of clusters $N_i$ and $N_a$
\State Output: Optimal user clustering result $R$
\vspace{1ex}
\ForAll {$t \in [N_i, N_a]$} \label{enu}
	%\State group users into $t$ clusters by $F$;
    \State perform K-Gru over F to get t clusters \label{task}
	\State clustering result $R'(t)\ =\ \{(u,\ l(u))\}$ with cluster info $l(u)$ for each user $u$; \label{l}
	\ForAll {$u \in \{u\}$}
		\State in-cluster distance $d_i(u)$ \label{v-b};
		\State out-cluster distance $d_o(u)$;
		\State Silhouette coefficient value $v(u)\ :=\ \frac{(d_o - d_i)}{max(d_o,\ d_i)}$; \label{v-e}
	\EndFor
	\State $v(t)\ :=\ Avg\{v(u)\}$; \label{avg}
\EndFor
\If {$v(a)\ =\ \ Max\{v(t)\}$} \label{opti}
	\State $R$ := $R'(a)$;
\EndIf
\State \bfseries{return} $R$.
\end{algorithmic}
\end{small}
\end{algorithm}

Next, we shall now first detail how \sys{} performs the clustering task and subsequently illustrate the computation for the metric of Silhouette coefficient value.

\subsection{K-Gru: Clustering in \sys{}}
\label{sec:cluster}

In \sys{}, the clustering rests on an optimized K-Prototype \cite{IEEEexample:huang1997clustering} algorithm, named K-Gru in this work.
Similar as K-Prototype, K-Gru randomly selects the cluster kernels among samples and employs the minimum distance between them to determine an initial result, upon which the clustering tasks are iterated until the results are stable.

Unlike K-Prototype that supports vector samples in which each dimension is of numerical/categorical, K-Gru could also handle the case where a dimension is one normalized vector.
%
Recall the sample data for User Clustering, i.e., \textit{Feature Data} in form of vectors (see formula \ref{eq:fu}), of which the data type regarding each dimension is shown as Table \ref{tbl:data-type}.

As aforementioned, the clustering of K-Gru rests on the distance between vector samples, where the dimensions are combined with numbers (normalized to 0-1 range), categories and normalized vectors. For simplicity, we shall first illustrate the distance calculation of the simple vectors with a single data type on each dimension, and then demonstrate that of complex vectors.

For numerical vectors $Y'\ = (y'_0, y'_1, \ldots)$ and $Z'\ = (z'_0, z'_1, \ldots)$, the \od{} \cite{IEEEexample:books/mk/HanKP2011} between $Y'$ and $Z'$ is given by :
%
\begin{equation}
\label{eq:od}
D_n(Y', Z') = \sum_{\substack{e}} (y_e - z_e)^2.
\end{equation}

For categorical vectors $Y''\ = (y''_0, y''_1, \ldots)$ and  $Z''\ = (z''_0, z''_1, \ldots)$, the \hd{} \cite{IEEEexample:huang1997clustering} of $Y''$ and $Z''$ is:
%
\begin{equation}
\label{eq:hd}
D_h(Y'', Z'') = \sum_{\substack{e}} H_e,
\end{equation}
where $H_e$ refers to the \hd{} over each dimension, with $H_e = 1$ if $y''_e$ and $z''_e$ share the identical value, and $H_e = 0$, otherwise.

Regarding two vectors where each dimension is a normalized vector per se, Cosine Similarity is leveraged to compute the distance.
Then, the distance between such two vectors $Y^{\ast}\ = (Y^{\ast}_0, Y^{\ast}_1, ...)$ and $Z^{\ast}\ = (Z^{\ast}_0, Z^{\ast}_1, ...)$ is:
%
\begin{equation}
\label{eq:vd}
D_v(Y^{\ast}, Z^{\ast}) = 1- \sum_{\substack{e}} Y^{\ast}_e \cdot Z^{\ast}_e,
\end{equation}
where $\cdot$ refers to the dot product operation between two normalized vectors $Y^{\ast}_e$ and $Z^{\ast}_e$.

Putting these together, the distance regarding the complex vectors $Y\ =\ (Y_0, Y_1, ...)$ and $Z\ =\ (Z_0, Z_1, ...)$ in K-Gru, referred to as \gd{}, is defined as:
%
\begin{equation}
\label{eq:gd}
D_g(Y, Z) = \sum_{\substack{e}} G_e,
\end{equation}
where the distance on each dimension $G_e$ is given by:
%
\begin{equation}
\label{eq:ge}
G_e =
  \begin{cases}
    (Y_e - Z_e)^2       &  \text{if } Y_e/Z_e \text{ is numerical}\\
    H_e\ (1\ or\ 0)       	&  \text{if } Y_e/Z_e \text{ is categorical}\\
    1 - Y_e \cdot Z_e  		&  \text{if } Y_e/Z_e \text{ is of normalized vector}
  \end{cases}
\end{equation}

\subsection{Silhouette Coefficient Metric Computation}
\label{sec:compu}

\begin{table}[tb!]
\centering
\begin{small}
%\caption{Types of Dimensional Data in \textit{Feature Data} Vector}
\caption{Dimension Types in \textit{Feature Data} Vector}
%\vspace{0.1cm}
\label{tbl:data-type}
\begin{tabular}{ll}
\toprule
\multicolumn{1}{l}{\textbf{Types}} & \multicolumn{1}{l}{\textbf{Data Dimensions}}	\\	\midrule \midrule
numerical data				& $\#R_u$, $\#E_u$, $R_{ee,u}$, $\#B_u$, $R_{oc,u}$, $\#W_{r,u}$,$\#W_{t,u}$               \\	\midrule
categorical data			& $G_u, P_u, U_{t,u}$				\\	\midrule
normalized vectors			& $P_{rt,u}$, $P_{rg,u}$, $P_{tt,u}$, $P_{tg,u}$, $P_u$			\\ \bottomrule
\end{tabular}
\end{small}
\end{table}

In system \sys{}, the Silhouette coefficient metric serves as the fundamental criteria for deriving an optimal clustering result.
Providing a clustering result, each user is associated with a cluster.

%For a user $u$ of cluster $l$, we employ the vector $Y$ to denote the \textit{Feature Data} as in formula \ref{eq:fu}.

\begin{definition}
\label{def:di}
The in-cluster distance $d_i(u)$ is the average distance to all the other users in the same cluster:
\begin{equation}
	d_i(u) = Avg\{D_g(F_u, F_u'')\ |\ u'' \in l \wedge  u \neq u''\}.
\end{equation}
\end{definition}

\begin{definition}
\label{def:do}
The out-cluster distance $d_o(u)$ is measured as the minimum of the distances $\{d^{\ast}\}$ between $u$ and other clusters:
\begin{equation}
	d_o(u) = Min\{d^{\ast}(u, l')\ |\  l' \neq l \},
\end{equation}
where $d^{\ast}$ is given by:
\begin{equation}
	d^{\ast}(u, l') = Avg\{D_g(Y_u, Y_u') \ | \ u' \in l'\}.
\end{equation}
\end{definition}

\begin{definition}
\label{def:coef}
The Silhouette coefficient value $v(u)$ is defined as:
\begin{equation}
\label{eq:coef}
v(u)\ =\ \frac{(d_o - d_i)}{max(d_o,\ d_i)}.
\end{equation}
\end{definition}

Intuitively, a good clustering solution should have a bigger $d_o$ and a smaller $d_i$, such that samples with obvious differences go to various clusters and vice versa.
When $d_o$ is far more than $d_i$, Silhouette coefficient value approaches to 1.
Hence, the larger Silhouette coefficient value is, the better clustering performs, by which the optimal solution is selected.


\section{Project Description}
In this project we create a Q-Learning algorithm that is able to play classic,
or ``retro", videogames. These games are widely considered to be NP-Hard or
many times PSPACE-Hard \cite{DBLP}. PSPACE-Hard problems are not only hard to
compute, but also hard to verify. This should match intuition of many videogames
as it is almost always unclear what an optimal strategy is. This is largely due
to the number of states in a single game. While actions may be few in number,
generally limited to the buttons one can press, each frame in the game can
generally be considered a new state. This makes even calculating the number
of states extremely difficult.

At the beginning of this project we set out with the goal to create a Q-learner
that would be able to play Super Mario Kart (SMK) \cite{SMK} through use of
OpenAI's Retro environment \cite{retro}. Retro creates an environment that
abstracts out emulation and helps developers focus on creating algorithms,
specifying actions, and rewards. Stretch goals were to get a deep Q network
(DQN) working and have several agents play against one another.

While we were not able to reach the goal of getting a reinforcement algorithm
playing SMK, we were able to demonstrate feasibility in retro's environment on
several other games, which had already be correctly integrated.

Documentation for the code is included at the end of this document in
section~\ref{sec:doc}.


\section{Solution Overview}
\label{sec:solution_overview}

Figure~\ref{figure:workflow} illustrates the workflow of our error detection system ED2.
The system takes a dirty dataset $D$ as input~\ding{182}.
Based on this dirty dataset, the \emph{Feature Extractor} generates content and metadata features $\rho$ for each data cell.
The \emph{Feature Extractor} combines information of all cells of the corresponding tuple and the corresponding column to one feature vector for each data cell~\ding{183}.
The feature representation is discussed in detail in Section~\ref{sec:features}.

With the help of the \emph{Initializer}~\ding{184}, the user provides an initial set of labeled cells for both classes, erroneous and correct, for all columns. We train one classifier for each column. This method is described in Section~\ref{sec:init}.
Based on the labeled data provided by the user~\ding{185}, ED2 uses cross-validation to find the optimal set of hyperparameters~\ding{186}.
ED2 uses these hyperparameters to train an error detection classifier on all available labeled data cells for each column.
Afterward, ED2 applies this model to all data cells of the corresponding column and estimates the probability of a cell to be erroneous~\ding{187}.
ED2 leverages these predictions $P$ to augment the feature matrix~\ding{188}.
This feature augmentation allows the models of different columns to share their knowledge with each other, as we explain in Section~\ref{sec:error_correlation_features}.

When all models are initialized~\ding{187}, the actual active learning process starts.
Our two-dimensional active learning policy is implemented via the \emph{Column Selector} component and the \emph{Batch Generator} component.
As we train one classifier per column, the \emph{Column Selector} has to choose the column that should be labeled next~\ding{189}. In Section~\ref{sec:order}, we describe how the \emph{Column Selector} leverages the results of the models to make this decision.
Then, the \emph{Batch Generator} selects the most promising cells for the given column~\ding{190} as described in Section~\ref{sec:uncertaintysampling}.
For each data cell in the batch, its corresponding tuple is presented one by one to the user~\ding{185}.
Based on the complete tuple, the user decides whether or not the marked cell value is erroneous.
After the batch of cells is labeled, the new labels are added to the training set of the corresponding column, hyperparameters are optimized~\ding{186}, and the classifier is retrained on the new data~\ding{187}.
From this point on, the process continues and repeats the steps from~\ding{185} to~\ding{190} in a loop.

During the entire active learning process, the \emph{Status Report} provides the user with a summary of the current state of the dataset. The \emph{Status Report} contains information that correlate with the convergence of the models, such as the certainty distribution for each column and current predictions of the least certain cells as described in Section~\ref{sec:stopAL}.
The active learning loop continues until the user is satisfied with the \emph{Status Report}. Then, the system applies the latest classification models for each column, marks the errors, and returns the result to the user.

In the following Section, we explain the classification algorithm in more detail, describing the features that we use to model the data and the active learning strategy that we employ to converge to a satisfactory state quickly.


\chapter{Introduction}\label{chap:introduction}
Indoor environments pose various challenges for localization and mapping algorithms, mainly because many unique settings exist.
Finding a solution which works for a lot of setups is therefore rather difficult. \newline
Let's start by giving an example for a typical indoor localization and mapping problem and then move on to describe the common problem on a higher level.\newline
Sometimes, finding your smartphone at home might be harder than you think, especially if you have no clue where you left it.
If nothing helps you will probably ask a family member, room mate or partner to help you out with a phone call.
Once you hear the sound of your exotic ring tone you will most likely start following it until you find your phone. \newline
This might sound like a silly example but in fact it covers the basic elements of a localization problem: A set of receivers (ears), an environment (house or apartment) and the unknown location of a source (smartphone).\newline
J. Bordoy et al. proposed a solution for almost the same problem \cite{bordoy2019exploiting}.
They used a combination of direct path and reflected ultrasound signals.
Former is usually referred to as line-of-sight (LOS) and latter as non-light-of-sight (NLOS) scenario.
LOS describes the case where a localization system is able to "see" the source to be located and NLOS is the case where an object/obstacle is blocking the direct path between the localization system and the source.\newline
Let's move on to an indoor mapping/imaging example from Flávio Ribeiro et al. where they try to estimate the geometry of a room with compact microphone arrays \cite{ribeiro2011geometrically}.
The source, in this case a loudspeaker, is co-located with the receiver array.
A known test signal is emitted through the source and the reflections of the test signal are used to estimate the room geometry.
Since they apply directional constraints on the received signal, they are able to extract the relevant reflections and therefore estimate the dimensions of the room.\newline
Even though both of these proposals are trying to solve two completely different problems, they share a common "interface" to the physical world.
This interface is illustrated in \figref{fig:Intro}.

\input{figures/introduction/figIntro}

The sources emit a signal through the room and interact with the environment.
Effects like path attenuation, reflections, scattering and diffraction will modify the signal as it propagates through the room \cite{vorlander2013computer}.
The result of these effects is perceived and recorded by the receivers.
Modelling and simulating the sources, receivers, the environment, the effects and the receivers will enable creating test data for the problems like \cite{bordoy2019exploiting} and \cite{ribeiro2011geometrically}.
Tests can be performed and evaluated in virtual environments and setups.
Creating a tool which allows us to do these things is therefore very useful.
The question is, how can this be achieved?

One very promising answer to this question is Acoustic/Ultrasonic Ray Tracing.
The hearing range of humans is $20\text{Hz} < f < 20 \text{kHz}$ and will be called "audible spectrum".
For frequencies higher than $20\text{kHz}$ we enter the ultrasound spectrum.
A lot of the general acoustic laws for the audible spectrum apply for the ultrasound spectrum as well.
There are however two main differences which are very important when designing an indoor localization or mapping system:\newline
1. Imagine having a system which depends on audible sound waves.
If the system is to be used in a human inhabited indoor environment, the system could be very annoying to people, especially for periodic sources.
This statement however is purely subjective and based on reasonable common sense.
Nonetheless it is a practical reason not to use frequencies below 20kHz.\newline
2. The second reason is that ultrasound waves can be approximated by rays, because of their reflection behavior.
This is mainly due to the fact that the relation between wavelength and the size of a reflecting surface is important.
For 20kHz the wavelength is approximately 17mm and for 100kHz it's approximately 3.4mm.
If the surface is much larger than the wavelength, which is the case for a lot of objects and obstacles, it will most likely get reflected.

This thesis explores this geometrical approach in order to provide simulated reflection data for indoor systems like \cite{bordoy2019exploiting} and \cite{ribeiro2011geometrically}.


\section{Evolution of Trust}
  Trust Is Risk is a game that runs indefinitely. In each turn, a player is chosen, decides what to play and, if valid, the
  chosen turn is executed.
  \subimport{fc17/definitions/}{turns.tex}
  \ifdefined\proceedings
  \else
    \subimport{common/}{turnexample.tex}
    We use $prev\left(j\right)$ and $next\left(j\right)$ to denote the previous and next turn respectively played by
    $Player(j)$.
  \fi
  \subimport{common/definitions/}{prevnextturn.tex}
  \subimport{common/definitions/}{damage.tex}
  \subimport{common/definitions/}{history.tex}
  \noindent Knowledge of the initial graph $\mathcal{G}_0$, all players' initial capital and the history amount to full
  comprehension of the evolution of the game. Building on the example of Fig.~\ref{fig:utxo}, we can see the resulting graph
  when $D$ plays
  \begin{equation}
  \label{turnexample}
     Turn_1 = \{Steal\left(1, A\right), Add\left(4, C\right), Add\left(-1, B\right)\} \enspace.
  \end{equation}
  \subimport{common/figures/}{turnexample.tikz}

  \noindent We now define the Trust Is Risk Game formally. We assume players are chosen so that, after her turn, a player will
  eventually play again later.
  \subimport{fc17/algorithms/}{trustisriskgame.tex}

  \noindent \texttt{strategy[}$A$\texttt{]()} provides player $A$ with full knowledge of the game, except for the capitals of
  other players. This assumption may not be always realistic. \texttt{executeTurn()} checks the validity of \texttt{Turn} and
  substitutes it with an empty turn if invalid. Subsequently, it creates the new graph $\mathcal{G}_j$ and updates the
  history accordingly. \ifdefined\proceedings\else For the routine code, see Appendix B.\fi


\documentclass{article}
\newsavebox{\oldepsilon}
\savebox{\oldepsilon}{\ensuremath{\epsilon}}
\usepackage[minionint,mathlf,textlf]{MinionPro} % To gussy up a bit
\renewcommand*{\epsilon}{\usebox{\oldepsilon}}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx} % For .eps inclusion
%\usepackage{indentfirst} % Controls indentation
\usepackage[compact]{titlesec} % For regulating spacing before section titles
\usepackage{adjustbox} % For vertically-aligned side-by-side minipages
\usepackage{array, amsmath,  mhchem}
\usepackage[hidelinks]{hyperref}
\usepackage{courier, subcaption}
\usepackage{multirow, enumerate}
\usepackage[autolinebreaks,framed,numbered]{mcode}
\usepackage{float}
\restylefloat{table}

\pagenumbering{gobble}
\setlength\parindent{0 cm}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\large

MCB 135 Problem Set 7 \hfill Due Friday, April 3, 2015 at 2:30 PM

\section*{Problem 1: Noise-induced oscillations (Ingalls 7.8.27, 45 points)}

Stochastic systems can exhibit a range of oscillatory behaviors, ranging from near-perfect periodicity to erratic cycles. To explore this behavior, consider a stochastic relaxation oscillator studied by Jos\'{e} Vilar and colleagues (Vilar et al., 2002). The system involves an activator and a repressor. The activator enhances expression of both proteins. The repressor acts by binding the activator, forming an inert complex. A simple model of the system is:

\begin{eqnarray*}
\textrm{ Name and description } \hspace{2 cm} & \textrm{Reaction} & \hspace{2 cm} \textrm{Reaction propensity}\\ \hline
R_1 \textrm{ (activator synthesis) } \hspace{2 cm} & \ce{\varnothing {\color{white}.} -> b_A A} & \hspace{2 cm} \frac{\gamma_A}{b_A} \cdot \frac{\alpha_0 + N_A/K_A}{1 + N_A/K_A}\\
R_2 \textrm{ (repressor synthesis) } \hspace{2 cm} & \ce{\varnothing {\color{white}.} -> b_R R} & \hspace{2 cm} \frac{\gamma_R}{b_R} \cdot \frac{N_A/K_R}{1 + N_A/K_R}\\
R_3 \textrm{ (activator decay) } \hspace{2 cm} & \ce{A -> \varnothing} & \hspace{2 cm} \delta_A N_A \\
R_4 \textrm{ (repressor decay) } \hspace{2 cm} & \ce{R -> \varnothing} & \hspace{2 cm} \delta_R N_R \\
R_5 \textrm{ (association) } \hspace{2 cm} & \ce{A + R -> C} & \hspace{2 cm} k_C N_A N_R \\
R_6 \textrm{ (dissociation w/ activator decay) } \hspace{2 cm} & \ce{C -> R} & \hspace{2 cm} \delta_A N_C \\
\end{eqnarray*}

Here, $N_A$, $N_R$, and $N_C$ are the molecular counts for the activator, repressor, and activator-repressor complex. The parameters $b_A$ and $b_R$ characterize the expression burst size. The Hill-type propensities of the synthesis reactions are not well-justified at the molecular level, but these expressions nevertheless provide a simple formulation of a stochastic relaxation oscillator.

\begin{enumerate}[a)]
\item Take parameter values $\gamma_A = 250$, $b_A = 5$, $K_A = 0.5$, $\alpha_0 = 0.1$, $\delta_A = 1$, $\gamma_R = 50$, $b_R = 10$, $K_R=1$, $k_C = 200$, and $\delta_R = 0.1$. Run a Gillespie SSA simulation of this model and verify its quasi-periodic behavior.
\item The deterministic version of this model is:
\begin{eqnarray*}
\frac{da}{dt} = \gamma_A \frac{\alpha_0 + a/K_A}{1 + a/K_A} - k_C a r - \delta_A a\\
\frac{dr}{dt} = \gamma_R \frac{a/K_R}{1 + a/K_R} - k_C a r + \delta_A c - \delta_R r\\
\frac{dc}{dt} =  k_C a r - \delta_A c
\end{eqnarray*}
where $a$, $r$, and $c$ are the concentrations of activator, repressor, and complex. Run a simulation with the same parameter values as in part (a). Does the system exhibit oscillations? How is the behavior different if you set $\delta_R=0.2$?
\item The contrast between the behavior of the models in parts (a) and (b), for $\delta_R=0.1$, can be explained by the excitability of this relaxation oscillato. Run two simulations of the deterministic model ($\delta_R=0.1$), one from initial conditions $(a,r,c)=(0,10,35)$ and another from initial conditions $(a,r,c)=(5,10,35)$. Verify that in the first case, the activator is quenched by the repressor, and the system remains at a low-activator steady state, whereas in the second case, this small quantity of activator is able to break free from the repressor and invoke a (single) spike in expression. Explain how noise in the activator abundance could cause repeated excitations by allowing the activator abundance to regularly cross the threshold. This is referred to as \textit{noise-induced oscillation}.
\end{enumerate}

\section*{Problem 2: Effect of autorepression (55 points)}

Consider the open system
\[ \ce{\varnothing {\color{white} .} ->[k_1] A ->[k_2] \varnothing} \]
\begin{enumerate}[a)]
\item Find the master equation for this system.
\item Show that, at steady state,
\[ P(N_A = n) = \frac{k_1}{k_2 n} P(N_A = n-1, t) \]
\item Use the Taylor series for $e^x$ to derive the steady-state probability distribution:
\[ P(N_A = n) = \frac{\left( \frac{k_1}{k_2} \right)^n e^{-k_1/k_2}}{n!} \]
\item Perform a Gillespie SSA simulation of the open system above with $k_1=10, k_2=1$. Estimate the probability distribution $P(n)$ from the timecourse $A(t)$. (Exercise your judgment in ignoring data early in the simulation and choosing an appropriate timescale for the simulation.) Plot the Poisson probability density function with $\lambda=k_1/k_2$ on the same axes for comparison.
\end{enumerate}
Now consider a related molecule that exhibits hyperbolic autorepression, i.e.
\[ \ce{\varnothing {\color{white} .} ->[k_1/(1+k_3B)] B ->[k_2] \varnothing} \]
\begin{enumerate}[a)]
\setcounter{enumi}{4}
\item Perform a Gillespie SSA simulation of this system with $k_1=100, k_2=k_3=1$ and estimate the probability distribution $P(n)$ from the timecourse $B(t)$. Fit a Poisson distribution to $P(n)$ and plot both on the same axes (e.g. using \mcode{poissfit()} and \mcode{poisspdf()} in MATLAB). Does the negative autoregulation system have more or less variance than expected for the simple regulation system?\end{enumerate}

\end{document}

problem sets/ps7/mcb 135 problem set 7.tex


\chapter{More Hypothesis Testing \label{chapter:hypothesisii}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Confidence Intervals}

\subsection{Greenwood Estimator for Kaplan-Meier Curves}


In order to complete the experiments, a few assumptions had to be made and are stated here.

\begin{itemize}
  \item The household being simulated was assumed to be "average", which means it uses 10,812 kWh of energy per year \cite{noauthor_how_nodate}. This works out to be just over 29 kWh per day.
  \item The household has a 5 kW solar panel array, which is reportedly the most common solar panel size in the US.
  \item The battery system is a Tesla Powerwall 2, with a 13.5 kWh capacity and a 5 kW max discharge/charge rate. It is also assumed that the battery is "perfect" and thus does not incur any parasitic loss while charging, discharging, or idling.
  \item The smart battery mainly looks 24 hours into the future before making a decision, though tests of 12 and 36 hours were also run.
  \item The home has an identical power curve every day, regardless of the time of year.
  \item The home is not able to take advantage of net metering, where excess energy can be "sold" back into the electrical grid in exchange for energy credits.
\end{itemize}

With this is mind, there were three experiments conducted using the simulator, with the potential for more at a future time.

\begin{itemize}
  \item \textbf{Experiment 1:} Examining yearly energy cost of the 8 possible combinations of technologies
  \item \textbf{Experiment 2:} Looking at the technologies in isolation
  \item \textbf{Experiment 3:} Exploring changes in yearly energy cost of looking ahead 12, 24, and 36 hours before making a decision
\end{itemize}

\subsection*{Experiment 1: Examining yearly energy cost of the 8 possible combinations of technologies}

For this experiment, 8 different simulations were run, each representing a unique combination of the 3 technologies being studied. Those simulations including a battery run 24 hours of predictions before making a decision. A cost is obtained for every hour of the day, and those costs are summed over all of 2016 to obtain the results found in Figure \ref{experiment_1}.

\begin{figure}
 \begin{center}
  \begin{tabular}{cc}
   \includegraphics[width=0.50\textwidth]{./figures/experiment_1.png} \\
   \end{tabular}
   \end{center}
\caption{The results of simulating all combinations of technologies for all of year 2016}
  \vspace{+1mm}
\label{experiment_1}
\end{figure}

There are a few things of interest from these results.

First, it would appear that nearly negligible energy savings are to be found without solar. Even the battery, able to take advantage of cheaper energy prices, offers very little financial benefit. Solar immediately contributes 20-25\% savings in cost.

Another point of interest is that once you have solar, the battery becomes significantly more useful, saving an additional 15-20\% in energy costs. Thus, it can be seen that solar and a battery are superadditive, meaning the two technologies together contribute greater savings than the sum of their individual potential savings.

Finally, it would appear that the smart home, as represented in this study as shifting loads to off-peak times, contributes very little, even when coupled with solar and/or a battery.

\subsection*{Experiment 2: Looking at the technologies in isolation}

The next experiment considers each technology in isolation, showing the overall cost of all simulations that include a technology, compared to all simulations that did not include a technology. These results are found in Figure \ref{experiment_2}.

\begin{figure}
 \begin{center}
  \begin{tabular}{cc}
   \includegraphics[width=0.50\textwidth]{./figures/experiment_2.png} \\
   \end{tabular}
   \end{center}
\caption{The results of isolating each technology}
  \vspace{+1mm}
\label{experiment_2}
\end{figure}

These results suggest that all technologies do contribute something in energy cost savings. As found in the previous experiment, solar contributes the most, with battery being the next greatest contributor. These results do suggest that smart home technology does contribute some to energy savings, though the contribution is so small as to hardly justify the expense of installing and maintaining such technologies.

\subsection*{Experiment 3: Exploring changes in yearly energy cost of looking ahead 12, 24, and 36 hours before making a decision}

This final experiment focuses more on the algorithm used to make a battery decision. As discussed previously, the Monte Carlo tree search algorithm used in this paper terminates a simulation after a specific number of hours in the future. The previous results used a fixed number of 24 hours in the future. This experiment runs the same simulation for all of year 2016, but terminates a battery simulation at times of 12, 24, and 36 hours in the future. These results are contained in Figure \ref{experiment_3}.

\begin{figure}
 \begin{center}
  \begin{tabular}{cc}
   \includegraphics[width=0.50\textwidth]{./figures/experiment_3.png} \\
   \end{tabular}
   \end{center}
\caption{The results of allowing the battery to look 12, 24, and 36 hours into the future before making a decision}
  \vspace{+1mm}
\label{experiment_3}
\end{figure}

Of course the results with no battery are identical. However, when the battery is introduced alongside solar, there can be seen minor reductions in energy costs as simulation depth is reduced. These results are significant because this is a "free" upgrade, meaning it did not require any additional investments in hardware, only a modification to the algorithm running on already present hardware.

There are a few things that might explain these results. If you run the exact same simulation repeatedly, you will find that the battery does not always choose the same action, but instead chooses amongst several similar actions. Thus, in 10 runs of the simulator for the same hour, you might find several "c10", several "c20", and several "idle", meaning the battery chooses to charge at 10\% of the max rate, 20\% of the max rate, or idle. While these differences might be nearly insignificant in the period of 1 hour, over the course of a year the difference between charging at 10\% and 20\% can add up to a meaningful amount. When you run the simulation looking ahead only 12 hours, the algorithm can be more confident in a final decision as there is less variability in the end result. As you increase the search depth, there will be more variability in the end result, which may make deciding what to do now more difficult and prone to error.

Allowing the Monte Carlo tree search algorithm to run more simulations or simulate for a longer time might allow the results of 24 or 36 hour predictions to normalize with those of 12 hour predictions. However, more work would need to be done to understand if looking ahead that far is every advantageous. If you can always obtain results simply as good as 12 hours but not necessarily better, then there is no need to simulate beyond 12 hours. Perhaps simulating less than 12 hours ahead might be even more useful. These are all areas for further study.


\section{Regler}

\subsection{Blockschaltbild}

\begin{figure}[h!]
	\centering
	\begin{tikzpicture}[node distance=2cm]
		% nodes
		\node [input] (in0) {};
		\node [sum, right of=in0] (in1) {$\Sigma$};
		\node [function, right of=in1] (c) {$C$};
		\node [function, right of=c] (p1) {$P_1$};
		\node [sum, right of=p1] (sum) {$\Sigma$};
		\node [function, above of=p1] (p2) {$P_2$};
		\node [input, left of=p2] (in2) {};
		\node [dot, right of=sum] (out1) {};
		\node [output, right of=out1] (out2) {};
		\node [output, below of=out1] (out3) {};
		% arrows
		\draw[->] (in0) node[anchor=east] {$\Omega_r$} -- (in1);
		\draw[->] (in1) -- (c);
		\draw[->] (in2) node[anchor=east] {$\Gamma$} -- (p2);
		\draw[->] (c) -- (p1);
		\draw[->] (p1) -- (sum);
		\draw[->] (p2) -| (sum);
		\draw[->] (sum) -- (out2) node[anchor=west] {$\Omega$};
		\draw[->] (out1) |- (out3) -| (in1);
		% legend
	\end{tikzpicture}
	\caption{Blockschaltbild der Drehzahlregelung (``\emph{closed loop}'')}
\end{figure}