% $Header: /cvsroot/latex-beamer/latex-beamer/solutions/conference-talks/conference-ornate-20min.en.tex,v 1.7 2007/01/28 20:48:23 tantau Exp $

\documentclass[10pt]{beamer}

\mode<beamer>
{
  \usetheme{default}
  \usecolortheme[rgb={0,0,0.8}]{structure}
  %\setbeamercolor{normal text}{bg=blue!50}
  %\setbeamercolor{normal text}{fg=blue!50}
  % or ...

  %\setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}

\usepackage[english]{babel}
% or whatever

%\usepackage[latin1]{inputenc}
% or whatever

\usepackage{times}
\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.

%\usepackage{newcent}
%\usefonttheme{structuresmallcapsserif}

\usepackage{amssymb,latexsym,amsmath}
\usepackage{amsthm}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}

\usepackage{mathtools}
\input xy
\xyoption{all}
\usepackage[latin1]{inputenc}
\usepackage{color}
\usepackage{tikz}
\usepackage{fontawesome}

\title[Gaussian Processes for Time Series Forecasting] % (optional, use only with long paper titles)
{Gaussian Processes for Time Series Forecasting}

%\subtitle

\author[Dr. Juan Orduz] % (optional, use only with lots of authors)
{Dr. Juan Orduz}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
%   affiliation.

\institute[PyCon DE \& PyData Berlin 2019] % (optional, but mostly needed)
{

}
% - Use the \inst command only if there are several affiliations.
% - Keep it simple, no one is interested in your street address.

\date[ PyCon DE \& PyData Berlin 2019] % (optional, should be abbreviation of conference name)
{PyCon DE \& PyData Berlin 2019}
% - Either use conference name or its abbreviation.
% - Not really informative to the audience, more for people (including
%   yourself) who are reading the slides online

\subject{data science}
% This is only inserted into the PDF information catalog. Can be left
% out.

% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:

\pgfdeclareimage[height=0.7cm]{university-logo}{images/logo.png}
\logo{\pgfuseimage{university-logo}}

% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:

%\beamerdefaultoverlayspecification{<+->}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

%\begin{frame}{Contenido}
%\tableofcontents
%\end{frame}

\begin{frame}{Overview}
{{\bf Aim:} Give a better intuition on the notion of Gaussian Process Regression}
\tableofcontents
\end{frame}

\section{Introduction}

\begin{frame}{Multivariate Normal Distribution}{\cite{multivariate_normal_orduz_2019}}
$X = (X_1, \cdots, X_d)$ has a{ \bf multinormal distribution} if every linear combination is normally distributed. The joint density has the form

$$
p(x|m,K_0) =\frac{1}{\sqrt{(2\pi)^{d}|K_0|}}\exp\left(-\frac{1}{2}(x - m)^T K_0^{-1}(x - m)\right)
$$
%(2\pi)^{−d/2}|K_0|^{−1/2}\exp\left(-\frac{1}{2}(x−m)^T {K_0}^{-1}(x−m)\right)

where $m \in \mathbb{R}^d$ is the {\bf mean vector} and  $K_0 \in M_d(\mathbb{R})$ is the (symmetric, positive definite) {\bf covariance matrix}.

\begin{center}
\begin{figure}
\includegraphics[scale=0.15]{images/multinormal_density.png}
\includegraphics[scale=0.15]{images/no_multinormal_density.png}
\caption{Left: Multivariate Normal Distribution, Right: Non-Multivariate Normal Distribution}
\end{figure}
\end{center}
\end{frame}

\section{Bayesian Linear Regression}

\begin{frame}{Bayesian Linear Regression}{\cite{reg_bayesian_regression_2019}, \cite[Chapter 2.1]{RW05}}
Let $x_1, \cdots, x_n \in \mathbb{R}^d$ and $y_1, \cdots, y_n$ be a set of observations (data). We want to fit the linear model
$$
f(x) = x^T b \quad \text{and} \quad y = f(x) + \varepsilon, \quad \text{with} \quad \varepsilon \sim N(0, \sigma_n^2)
$$
where $b \in \mathbb{R}^d$ denotes the parameter vector. Let $X \in M_{d \times n}$ denote the observation matrix.
\begin{center}
\begin{figure}
\includegraphics[scale=0.14]{images/lin_raw_data.png}
\caption{The true parameters in this example are $b=(1, 3)$ and $\sigma_n=0.5$}
\end{figure}
\end{center}
We want to compute $p(b|X, y)$ using the Bayes theorem
$$
p(b|X, y) = \frac{p(y|X, b) p(b)}{p(y|X) } \propto \text{likelihood} \times \text{prior}
$$
\end{frame}

\begin{frame}{Prior Distribution}
\begin{itemize}
\item Prior
$$
b \sim N(0, \Sigma_p), \quad  \Sigma_p \in M_{d}(\mathbb{R})
$$

\begin{center}
\begin{figure}
\includegraphics[scale=0.17]{images/lin_join_prior.png}
\includegraphics[scale=0.17]{images/prior_lin_mod_param_distr.png}
\caption{Prior Distribution, for this example
$
\Sigma_p=
\left(
\begin{array}{cc}
2 & 1 \\
1 & 2
\end{array}
\right).
$
}
\end{figure}
\end{center}
\item Likelihood
\begin{align*}
p(y|X, b)
= \prod_{i=1}^{n}p(y_i|x_i, b)
%=& \frac{1}{(2\pi \sigma_n^2)^{n/2}} \exp\left(-\frac{1}{2\sigma_n^2}||y - X^T b||^2\right) \\
= N(X^T b, \sigma_n^2 I)
\end{align*}
\end{itemize}
\end{frame}

\begin{frame}{Posterior Distribution Sampling }{\cite{pymc3}}
\begin{center}
\begin{figure}
\includegraphics[scale=0.25]{images/lin_posterior_pymc3.png}
\caption{Posterior distribution of the $b$ weight estimation using MCMC sampling (\href{https://docs.pymc.io/}{PyMC3}). Here we use 3 chains. }
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Posterior Distribution - Analytical Solution}{\cite[Chapter 2.1.1]{RW05}}
\begin{itemize}
\item Posterior
$$
p(b|y, X) = N\left(\bar{b}=\frac{1}{\sigma_n^2}A^{-1}Xy, A^{-1}\right), \quad A=\sigma_{n}^{-2}XX^T + \Sigma_p^{-1}
$$
\end{itemize}
\begin{center}
\begin{figure}
\includegraphics[scale=0.17]{images/lin_join_posterior.png}
\includegraphics[scale=0.17]{images/posterior_lin_mod_param_distr.png}
\caption{Posterior Distribution.}
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Predictive Distribution - Analytical Solution}{\cite[Chapter 2.1.1]{RW05}}
\begin{align*}
p(f_*|x_*, X, y)
= \int p(f_*|x_*, b)p(b|X, y)db
= N\left(
\frac{1}{\sigma_n^2}x_*^T A^{-1}Xy, x_*^T A^{-1}x_*
\right)
\end{align*}

\begin{center}
\begin{figure}
\includegraphics[scale=0.25]{images/lin_prediction.png}
\caption{Prediction Interval.}
\end{figure}
\end{center}
\end{frame}

\section{The Kernel Trick}

\begin{frame}{The Kernel Trick}{\cite[Chapter 2.1.2]{RW05}}
Let us consider a map $\phi: \mathbb{R}^d \longrightarrow \mathbb{R}^N$ and the model
$$
f(x) = \phi(x)^T b \quad \text{and} \quad y = f(x) + \varepsilon, \quad \text{with} \quad \varepsilon \sim N(0, \sigma_n^2).
$$
It is easy to verify that the analysis for this model as analogous to the standard linear model replacing $X$ with $\Phi\coloneqq \phi(X)$. Set $\phi_*= \phi(x_*)$,
\begin{align*}
p(f_*|x_*, X, y) =& N\left(
\overbrace{\frac{1}{\sigma_n^2}\phi_*^T A^{-1}\Phi y}^{(1)},
\underbrace{ \phi_*^T A^{-1}\phi_*}_{(2)}
\right)
\end{align*}
\begin{align*}
(1) =& \phi_{*}^T \Sigma_{p}\Phi(\Phi^T \Sigma_p \Phi + \sigma_n^2I)^{-1}y \\
(2)= &\phi_{*}^T\Sigma_p\phi_{*} - \phi_{*}^T \Sigma_{p}\Phi(\Phi^T \Sigma_p \Phi + \sigma_n^2I)^{-1}\Phi^T\Sigma_p\phi_*
\end{align*}
This motivates the definition of the {\bf covariance function} or {\bf kernel}
$$
k(x, x')\coloneqq \phi(x)^T\Sigma_p\phi(x')
$$
\end{frame}

\section{Gaussian Process Regression}

\begin{frame}{Gaussian Process}{\cite[Chapter 21]{BDA13}, \cite[Chapter 2.2]{RW05}}
\begin{block}{Main Idea}
The specification of a covariance function implies a distribution over functions.
\end{block}
\begin{block}{Gaussian Process}
\begin{itemize}
\item A {\bf Gaussian Process} is a collection of random variables, any finite number of which have a joint multinormal distribution. \\
\item A Gaussian process $f \sim \mathcal{GP}(m, k)$ is completely specified by its mean function $m(x)$ and covariance function $k(x, x')$. Here $x \in \mathcal{X}$ denotes a point on the index set $\mathcal{X}$.
$$
m(x) = E[f(x)]
\quad
\text{and}
\quad
k(x, x') = E[(f(x) - m(x))(f(x') - m(x'))]
$$
\end{itemize}
\end{block}
\pause
\begin{block}{Example}
The map $f(x) = \phi(x)^T b $ (with prior $b\sim N(0, \Sigma_p)$) defines a Gaussian process with $m(x)=0$ and $k(x, x') = \phi(x)^T\Sigma_p\phi(x')$.
\end{block}
\begin{block}{Notation}
Let $K(X, X)$ denote the matrix of the point-wise kernel images.
\end{block}
\end{frame}

\begin{frame}{Linear Regression - Function Space View}{\cite[Chapter 2.2]{RW05}}
\begin{itemize}
\item Let us consider input points $X_*$ (test set).
\item Prior
\begin{align*}
f_* \sim N(0, K(X_*,X_* ))
\end{align*}
\begin{center}
\begin{figure}
\includegraphics[scale=0.2]{images/gp_lin_prior.png}
\caption{We sample from the prior space of functions by plotting their realization on $n_*=80$ points. }
\end{figure}
\end{center}
\end{itemize}
\end{frame}

\begin{frame}{Linear Regression - Function Space View}{\cite[Chapter 2.2]{RW05}}
\begin{itemize}
\item Joint Distribution
\begin{align*}
\left(
\begin{array}{c}
y \\
f_*
\end{array}
\right)
\sim
N\left(0,
\left(
\begin{array}{cc}
K(X,X)+\sigma_n^2 & K(X,X_*) \\
K(X_*,X) & K(X_*,X_*)
\end{array}
\right)
\right)
\end{align*}
\item Conditional Distribution $f_* | X, y, X_*\sim N(\bar{f}_*, \text{cov}(f_*))$
\begin{center}
\begin{figure}
\includegraphics[scale=0.15]{images/gp_lin_posterior.png}
\end{figure}
\end{center}
\begin{align*}
\bar{f}_* =& K(X_*,X)(K(X,X) + \sigma_n^2 I)y \\
 \text{cov}(f_*) =& K(X_*,X_*) - K(X_*,X)(K(X,X) + \sigma_n^2I)^{-1}K(X,X_*)
\end{align*}
\end{itemize}
\end{frame}

\section{Kernel Examples}

\begin{frame}{Kernel Examples}{\cite{ROERGA}, \cite[Chapter 4.2]{RW05}}
Symmetric and positive semi-definite functions $k:\mathcal{X}\times\mathcal{X}\longrightarrow \mathbb{R}$.
\begin{itemize}
\item Dot Product
\begin{align*}
k_{DOT}(x, x') = (\sigma_0^2 + x^T\Sigma_p x')^m
\end{align*}
\item Squared Exponential
\begin{align*}
k_{SE}(x, x') = \exp\left(- \frac{(x - x')^2}{2\ell ^2}\right)
\end{align*}
\item Rational Quadratic
\begin{align*}
k_{RQ}(x, x') = \left(1 + \frac{(x - x')^2}{2\alpha\ell^2}\right)^{-\alpha}
\end{align*}
\item Exp-Sine-Squared
\begin{align*}
k_{ESS} (x, x')= \exp\left(-2 \left(\frac{\sin(\pi (x - x')/T )}{\ell}\right)^2\right)
\end{align*}
\end{itemize}
\end{frame}

\section{Non-Linear Example (RBF)}

\begin{frame}{Example: Non-Linear Function}{\cite{gaussian_process_reg_2019}}
\begin{center}
\begin{figure}
\includegraphics[scale=0.23]{images/f_example2.png}
\end{figure}
\end{center}
\begin{center}
\begin{figure}
\includegraphics[scale=0.23]{images/raw_data_example2.png}
\caption{Non-Linear Example with $n=500$ training points.}
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Prior Distribution}
$$
f \sim N(0, K(X_*,X_*))
$$
\begin{center}
\begin{figure}
\includegraphics[scale=0.27]{images/code_sample_prior_example2.png}
\caption{We sample from the prior space of functions by plotting their realization on $n_*=100$ points. }
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Joint Distribution}
\begin{align*}
\left(
\begin{array}{c}
y \\
f_*
\end{array}
\right)
\sim
N\left(0,
\left(
\begin{array}{cc}
K(X,X)+\sigma_n^2 & K(X,X_*) \\
K(X_*,X) & K(X_*,X_*)
\end{array}
\right)
\right)
\end{align*}
\begin{center}
\begin{figure}
\includegraphics[scale=0.25]{images/cov_prior_example2.png}
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Conditional Distribution}
 $$f_* | X, y, X_*\sim N(\bar{f}_*, \text{cov}(f_*))$$
\begin{center}
\begin{figure}
\includegraphics[scale=0.24]{images/cov_posterior_example2.png}
\caption{Covariance matrix of the posterior (conditional) distribution.}
\end{figure}
\end{center}
 \begin{align*}
\bar{f}_* =& K(X_*,X)(K(X,X) + \sigma_n^2 I)y \\
\text{cov}(f_*) =& K(X_*,X_*) - K(X_*,X)(K(X,X) + \sigma_n^2I)^{-1}K(X,X_*)
\end{align*}
\end{frame}

\begin{frame}{Posterior Distribution}
\begin{center}
\begin{figure}
\includegraphics[scale=0.32]{images/code_sample_posterior_example2.png}
\caption{We sample from the posterior space of functions by plotting their realization on $n_*=100$ points. }
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Hyperparameter Estimation}{\cite[Chapter 2.3, 5]{RW05}}
\begin{center}
\begin{figure}
\includegraphics[scale=0.21]{images/hyp_posterior_1_example2}
\includegraphics[scale=0.21]{images/hyp_posterior_2_example2}
\caption{Samples from two gaussian processes with different scale parameters (left: $\ell=1$ and right: $\ell = 0.001$).}
\end{figure}
\end{center}
\begin{block}{Methods}
\begin{itemize}
\item Marginal Likelihood ($\theta$ = parameter vector)
\begin{align*}
\log(p(y|X, \theta)) = -\frac{1}{2}y^T (K+\sigma_n^2I)^{-1}y - \frac{1}{2}\log|K+\sigma_n^2I| - \frac{n}{2}\log (2\pi)
\end{align*}
\item Cross Validation
\end{itemize}
\end{block}
\end{frame}

\section{The Kernel Space}

\begin{frame}{The Kernel Space}{\cite{ROERGA}, \cite[Chapter 4]{RW05}}
Let $k_1, k_2: \mathcal{X}\times\mathcal{X}\longrightarrow \mathbb{R}$ be two kernels, then the following are also kernels
\begin{itemize}
\item $k_1 + k_2$
\item $k_1 \times k_2$
\item $k_1*k_2$ (convolution)
\end{itemize}
If $k: \mathcal{X}_1\times\mathcal{X}_1\longrightarrow \mathbb{R}$ and $h: \mathcal{X}_2\times\mathcal{X}_2\longrightarrow \mathbb{R}$ are two kernels, then the following are also kernels (on $\mathcal{X}_1 \times \mathcal{X}_2$)
\begin{itemize}
\item $k_1 \oplus k_2$
\item $k_1 \otimes k_2$
\end{itemize}
\begin{block}{Remark (\cite[Chapter 4.3]{RW05})}
There is a rich theory of spectral theory for kernels by considering the integral operator $T_k : L^2(\mathcal{X}, \mu) \longrightarrow L^2(\mathcal{X}, \mu)$ (where $(\mathcal{X}, \mu)$ is a finite measure space and $k\in L^{\infty}(\mathcal{X}\times \mathcal{X} , \mu\times\mu)$).
\begin{align*}
(T_k\phi)(x) = \int_{\mathcal{X}} k(x, x')\phi(x') d\mu(x')
\end{align*}
\end{block}
\end{frame}

\section{Example: Time Series}

\begin{frame}{Example: Periodic Component I (\cite{gaussian_process_time_series_2019})}{\cite[Section 1.7. Gaussian Processes]{scikitlearn}}
\begin{center}
\begin{figure}
\includegraphics[scale=0.3]{images/code_kernel_1_example3.png}
\includegraphics[scale=0.3]{images/gp1_example3.png}
\end{figure}
\end{center}
\begin{center}
\begin{figure}
\includegraphics[scale=0.20]{images/sample_1_example3.png}
\includegraphics[scale=0.20]{images/pred_1_example3.png}
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Example: Add Linear Trend }
\begin{center}
\begin{figure}
\includegraphics[scale=0.3]{images/code_kernel_2_example3.png}
\end{figure}
\end{center}
\begin{center}
\begin{figure}
\includegraphics[scale=0.20]{images/sample_2_example3.png}
\includegraphics[scale=0.20]{images/pred_2_example3.png}
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Example: Add Periodic Component II }
\begin{center}
\begin{figure}
\includegraphics[scale=0.3]{images/code_kernel_3_example3.png}
\end{figure}
\end{center}
\begin{center}
\begin{figure}
\includegraphics[scale=0.20]{images/sample_3_example3.png}
\includegraphics[scale=0.20]{images/pred_3_example3.png}
\end{figure}
\end{center}
\end{frame}

\begin{frame}{Computational Challenges}
\begin{itemize}
\item Calculating the posterior mean and covariance matrix requires $\mathcal{O}(n^3)$ computations.
\item A practical implementation of Gaussian process regression is described in \cite[Algorithm 2.1]{RW05}, where the Cholesky decomposition is used instead of inverting the matrices directly.
\item There are remarkable approximation methods for Gaussian processes to speed up the computation (\cite[Chapter 20.1]{BDA13})
\end{itemize}
\end{frame}

\begin{frame}[t, allowframebreaks]
\frametitle{References}
\footnotesize{
\setbeamertemplate{bibliography item}[text]
\bibliographystyle{plain}
\bibliography{references}
}
\end{frame}

\begin{frame}
\begin{center}
\huge{Thank You!}%\footnote{Especially to all the organizers and speakers!}
\end{center}

\begin{block}{Contact}
\begin{itemize}
\item \faRocket $\:$ \href{https://juanitorduz.github.io}{https://juanitorduz.github.io}
\item \faGithub $\:$ \href{https://github.com/juanitorduz}{github.com/juanitorduz}
\item \faTwitter $\:$ \href{https://twitter.com/juanitorduz}{juanitorduz}
\item \faEnvelope $\:$ \href{mailto:juanitorduz@gmail.com}{juanitorduz@gmail.com}
\end{itemize}
\end{block}

\begin{center}
\includegraphics[scale=0.08]{images/qr-code-juanitorduz.png}
\end{center}

\end{frame}

\end{document}


\section{List Mode Data Analysis}
	For data collected using a digitizer, or similiar equipment, this menu features numerous options to analyze and save various data. This has the expectation of time dependent data being collected, i.e. a source is being pulsed using a logic pulse. With detector and sync pulse data both being captured and recoreded as raw data.
		\subsection{View Time Decay}
			This is used to generate a plot of multiple region of interest pulse arrival times relative to the sync pulse. This must be run after having used the list mode data set of tools. The first pop up will request the number of data sets to be plotted. After selection of this, the windows file explorer will be generated. It will expect a file that is two columns, the first being time stamps, the second being a number of counts accumulated during the time step. This will be repeated for the total number of files selected. Several additional windows will appear that request additional information regarding the frequency, duty cylce, and location of region dividers. All of which are optional. The data will be processed and plotted in the window upon clicking the ``Process'' button. A high quality image, 600dpi, can be saved with the selection of the ``Save Image'' button.

	\subsection{Analyze List Mode Data}
		This is the primary interface for loading and manipulating time dependent data. As such an entire section is dedicated to this later in this document.

	\subsection{Detection Probability}
		\subsubsection{Theory}
		This is used to determine the time required to reach 99\% detection probability. Poisson and Gaussian Statistics are implemented in their respsective regimes, less than 30 counts for Poisson and any number of counts greater than 30 for Gaussian. For Poisson statistics, the distribution is only dependent on the mean, $\mu$, in this case the mean is taken as the number of counts, this is seen in equation \ref{eq:poisson}. Gaussian statistic distribution is dependent on a mean, $\mu$, and variance, the mean is again taken to be the number of counts and the standard deviation to be $\sigma=\sqrt{N}$, the distribution function is seen in equation \ref{eq:gaussian}.

	\begin{equation}
		P=\frac{\mu^kexp\left(-\mu\right)}{k!}
		\label{eq:poisson}
	\end{equation}
	\begin{equation}
		P=\frac{1}{2\pi\sigma^2}exp\left(\frac{\left(\mu-k\right)^2}{2\sigma^2}\right)
		\label{eq:gaussian}
		\end{equation}
	An example of a foreground and background distribution plotted together are seen in Figure \ref{fig:pdf}. The background distribution is used in conjunction with a maximum false alarm rate, one alarm per eight hours is the default, to find a threshold to be used to determine the detection probability. \\

	\begin{figure}[h!]
		\centering
		\includegraphics[width=0.6\linewidth]{pdf.png}
		\caption{Probability distribution functions for a foreground and background plotted together.}
		\label{fig:pdf}
	\end{figure}
	The probability distribution functions are then numerically integrated using trapeziodal rule. The integration of this must sum to exactly one. The foreground and background cumulative density functions, along with the threshold is seen in Figure \ref{fig:cdf}.\\
	\begin{figure}[h!]
		\centering
		\includegraphics[width=0.6\linewidth]{cdf.png}
		\caption{Cummulative density function with detection threshold indicated.}
		\label{fig:cdf}
	\end{figure}
Using the cummulative density function and the threshold, the detection probability is found as $1-f_{cdf}$ where $f_{cdf}$ is the foreground cummulative density function evaluated at the threshold index. For the given examples the detection probability is 93\%.
\subsubsection{Implementation}
	Two files are required for this to work, a background and a foreground, these are selected in this order. The files are generated using the ``Save ROI'' method in the ``List Mode Reader'' interface. The files take a two column form with a time of arrival and energy as the two columns. A window will appear to set the first time step to begin integrating. This is due to statistical fluctuations at extremely low count fields. A total of 181 time steps are taken over the entire length of the accumulated time.\\

It should be noted that this portion may take a significant portion of time to run due to have to generate, and integrate 362 discrete functions. \\

Upon completeion of the analysis, the software will automatically bring up a windows file explorer to save the data points out, to be used for generation of a video. This will then generate a plot of the probability of detection versus time, the software will indicate the point at which the detection probability rises above 99\% for the first time. Care should be taken by the user to ensure the start point has not removed prudent data, but is high enough to remove any erroneous data points.

\subsection{Save Probability Video}
	This generates a video from the probability data saved using the detection probability function. It expects as input a two column file with time in the first column and a detection probability in the second. It saves as an mp4 file type.

\subsection{View Detection Probability}
	When the detection probability algorithm is used, it generated a data file containing the number of pulses, along with time stamp and detection probability. This interface allows for the user to analyze this data and plot multiple files on top of each other. This interface features a slider that can be used to change the detection probability, this will update the legend to show the new time needed to determine a detection.


\SubSecDef{model}{Security Model}

Consider a subproblem from the whitebox design problem. Recall that during the algebraic attack, the adversary tries to find a function $f$ of low degree $d$ such that when applied to values computed in the nodes of the obfuscated circuit it would produce some predictable value. Typically, predictable value is a value computed using the \emph{reference circuit} and it depends on a small fraction of the key. Our aim is to ``hide'' predictable values among unpredictable values. The unpredictability of computed functions may only come from the secret~key/randomness used during the obfuscation process. In order to develop a formal attack model we allow the obfuscated circuit to use \emph{random} bits. We underline that randomness here is merely an abstraction required for provable security arguments.

In the real whitebox implementation the random bits may be implemented as \emph{pseudorandom} values computed from the input. Of course the pseudorandom generation part has to be protected as well. However, the white-box designer is free to choose arbitrary pseudorandom generator and its protection is an easier task then obfuscating a general circuit. For example, the designer can choose a random circuit satisfying some basic properties like computing a balanced function. The resulting circuit protected against the algebraic attack using pseudorandomly generated bits must further be obfuscated and protected from \emph{removal} of the pseudorandomness. This is type of protection that we called \emph{structure hiding} in \SecRef{method} and it is out of the scope of this work. It is indeed a challenging problem.

There is a strong similarity between the algebraic attack and the side channel probing attack. In the $t$-th order probing attack the adversary may observe $t$ intermediate values computed in the circuit. In the $d$-th order algebraic attack the adversary has access to all intermediate values but she can combine them only with a function of degree at most $d$.

\paragraph{Semantic Security.}
The main idea of masking schemes is to \emph{hide the values} computed in the reference circuit using (pseudo)random masks. We assume that the adversary knows the reference circuit. Given the inputs (e.g. a plaintext and a key) she can compute all intermediate values. The final goal of the adversary is to recover the key of an obfuscated implementation or, at least, learn some partial information about it. To formalize this, we adapt classic semantic security and indistinguishability ideas. The adversary may ask to encrypt two different vectors of inputs. The challenger chooses randomly one of the vectors and provides an oracle modelling the algebraic attack to the adversary. The goal of the adversary is to decide which of the vectors was encrypted. If she can not do this, then she can not learn any information about the hidden inputs (e.g. the plaintext and the key). Note that the adversary is allowed to choose many different keys which is not possible in the white-box scenario. However, it leads to simpler definitions since we do not have to distinguish plaintext and key and we just treat them as one input. It is possible to add a constraint allowing to choose only a single key per input vector, but this would not lead to any improvement.

\paragraph{Algebraic Attack Oracle.}
The oracle modelling the algebraic attack should not reveal too much information about computed values. Otherwise, it may be possible for the adversary to reconstruct the obfuscated circuit and then we would arrive in the general white-box scenario. We model the attack as follows: the adversary chooses the target function among linear (or higher-order) combinations of the intermediate functions in the circuit and she tries to guess its values during encryptions of the inputs from one of the two vectors. Note that some functions may have strong correlation with some function of the input. For a small vector of inputs the adversary may simply guess the value, ask the oracle a few times until the guess is correct and then compute the correlations. However, in the real algebraic attack this is not possible due to presence of "noise" in the circuit. For a small number of plaintexts there will be a lot of false matches for any "predicted" value, because there are many different functions computed in the circuit and it is highly probable that there is a linear combination of them matching an arbitrary value. We take this into account and require that only the function chosen by the adversary has to match the predicted value. As a result, the adversary can not accurately predict values of any \emph{single} function in the $d$-th order closure of the circuit functions in order to run the linear algebra attack.

\paragraph{Encoding and Decoding.}
The circuit in the model can not take the input as it is, because these values allow for a simple distinguisher. Since we are developing a masking scheme, we assume that he inputs are already masked using random shares. The adversary targets masked operations, which we call \emph{critical computations}. This goes in parallel with the classic Boolean masking scenarios. We would like to stress that this is necessary in order to formally analyze the security of masked computations. Therefore, we do not consider the initial encoding and the final decoding processes. Indeed, these procedures are not relevant for the algebraic attack since they are not related to the reference circuit. Therefore, their protection is a part of the structure hiding component.

The security model is illustrated in \FigRef{masked-circuit}.

\begin{figure}
    \centering
    \includegraphics[height=8cm]{\PathFig{MaskedCircuitWB.png}}
    \FigDef{masked-circuit}{(Pseudo)randomness in a masked circuit.}
\end{figure}


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

      \subsection{loss\_cp.m}

\begin{par}
\textbf{Summary:} Cart-Pole loss function; the loss is $1-\exp(-0.5*d^2*a)$,  where $a>0$ and  $d^2$ is the squared difference between the actual and desired position of tip of the pendulum. The mean and the variance of the loss are computed by averaging over the Gaussian state distribution $p(x) = \mathcal N(m,s)$ with mean $m$ and covariance matrix $s$. Derivatives of these quantities are computed when desired.
\end{par} \vspace{1em}
\begin{verbatim}function [L, dLdm, dLds, S2] = loss\_cp(cost, m, s)\end{verbatim}
\begin{par}
\textbf{Input arguments:}
\end{par} \vspace{1em}
\begin{verbatim}cost            cost structure
  .p            length of pendulum                              [1 x  1 ]
  .width        array of widths of the cost (summed together)
  .expl         (optional) exploration parameter
  .angle        (optional) array of angle indices
  .target       target state                                    [D x  1 ]
m               mean of state distribution                      [D x  1 ]
s               covariance matrix for the state distribution    [D x  D ]\end{verbatim}
\begin{par}
\textbf{Output arguments:}
\end{par} \vspace{1em}
\begin{verbatim}L     expected cost                                             [1 x  1 ]
dLdm  derivative of expected cost wrt. state mean vector        [1 x  D ]
dLds  derivative of expected cost wrt. state covariance matrix  [1 x D^2]
S2    variance of cost                                          [1 x  1 ]\end{verbatim}
\begin{par}
Copyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.
\end{par} \vspace{1em}
\begin{par}
Last modified: 2013-05-16
\end{par} \vspace{1em}

\subsection*{High-Level Steps}

\begin{enumerate}
\setlength{\itemsep}{-1ex}
   \item Precomputations
   \item Define static penalty as distance from target setpoint
   \item Trigonometric augmentation
   \item Calculate loss
\end{enumerate}

\begin{lstlisting}
function [L, dLdm, dLds, S2] = loss_cp(cost, m, s)
\end{lstlisting}

\subsection*{Code}

\begin{lstlisting}
if isfield(cost,'width'); cw = cost.width; else cw = 1; end
if ~isfield(cost,'expl') || isempty(cost.expl); b = 0; else b =  cost.expl; end

% 1. Some precomputations
D0 = size(s,2);                           % state dimension
D1 = D0 + 2*length(cost.angle);           % state dimension (with sin/cos)

M = zeros(D1,1); M(1:D0) = m; S = zeros(D1); S(1:D0,1:D0) = s;
Mdm = [eye(D0); zeros(D1-D0,D0)]; Sdm = zeros(D1*D1,D0);
Mds = zeros(D1,D0*D0); Sds = kron(Mdm,Mdm);

% 2. Define static penalty as distance from target setpoint
ell = cost.p; % pendulum length
Q = zeros(D1); Q([1 D0+1],[1 D0+1]) = [1 ell]'*[1 ell]; Q(D0+2,D0+2) = ell^2;

% 3. Trigonometric augmentation
if D1-D0 > 0
  % augment target
  target = [cost.target(:); gTrig(cost.target(:), 0*s, cost.angle)];

  % augment state
  i = 1:D0; k = D0+1:D1;
  [M(k) S(k,k) C mdm sdm Cdm mds sds Cds] = gTrig(M(i),S(i,i),cost.angle);

  % compute derivatives (for augmentation)
  X = reshape(1:D1*D1,[D1 D1]); XT = X';              % vectorized indices
  I=0*X; I(i,i)=1; ii=X(I==1)'; I=0*X; I(k,k)=1; kk=X(I==1)';
  I=0*X; I(i,k)=1; ik=X(I==1)'; ki=XT(I==1)';

  Mdm(k,:)  = mdm*Mdm(i,:) + mds*Sdm(ii,:);                    % chainrule
  Mds(k,:)  = mdm*Mds(i,:) + mds*Sds(ii,:);
  Sdm(kk,:) = sdm*Mdm(i,:) + sds*Sdm(ii,:);
  Sds(kk,:) = sdm*Mds(i,:) + sds*Sds(ii,:);
  dCdm      = Cdm*Mdm(i,:) + Cds*Sdm(ii,:);
  dCds      = Cdm*Mds(i,:) + Cds*Sds(ii,:);

  S(i,k) = S(i,i)*C; S(k,i) = S(i,k)';                      % off-diagonal
  SS = kron(eye(length(k)),S(i,i)); CC = kron(C',eye(length(i)));
  Sdm(ik,:) = SS*dCdm + CC*Sdm(ii,:); Sdm(ki,:) = Sdm(ik,:);
  Sds(ik,:) = SS*dCds + CC*Sds(ii,:); Sds(ki,:) = Sds(ik,:);
end

% 4. Calculate loss!
L = 0; dLdm = zeros(1,D0); dLds = zeros(1,D0*D0); S2 = 0;
for i = 1:length(cw)                    % scale mixture of immediate costs
    cost.z = target; cost.W = Q/cw(i)^2;
  [r rdM rdS s2 s2dM s2dS] = lossSat(cost, M, S);

  L = L + r; S2 = S2 + s2;
  dLdm = dLdm + rdM(:)'*Mdm + rdS(:)'*Sdm;
  dLds = dLds + rdM(:)'*Mds + rdS(:)'*Sds;

  if (b~=0 || ~isempty(b)) && abs(s2)>1e-12
    L = L + b*sqrt(s2);
    dLdm = dLdm + b/sqrt(s2) * ( s2dM(:)'*Mdm + s2dS(:)'*Sdm )/2;
    dLds = dLds + b/sqrt(s2) * ( s2dM(:)'*Mds + s2dS(:)'*Sds )/2;
  end
end

% normalize
n = length(cw); L = L/n; dLdm = dLdm/n; dLds = dLds/n; S2 = S2/n;
\end{lstlisting}


\section{Tuples} % (fold)
\label{sec:tuples}
\begin{questions}
\titledquestion{Swapping two values} % (fold)
\label{sub:swapping_two_values}

Suppose you have two variables: \texttt{a} and \texttt{b}.
Now you want to set \texttt{a} equal to the value of \texttt{b} and at
 the same time set \texttt{b} equal to the value of \texttt{a}.

The following obviously does not work
\begin{verbatim}
    a = b
    b = a
\end{verbatim}
so in some languages, you need to define a third variable like this
\begin{verbatim}
    t = a
    a = b
    b = t
\end{verbatim}
However, in Python you don't need to do this. How can you swap \texttt{a} and
\texttt{b} in one line?

% titledquestion swapping_two_values (end)

\titledquestion{Zip} % (fold)
\label{sub:zip}

Suppose we have two lists, \texttt{x} and \texttt{y} that give the $x$ and $y$
coordinates of a set of points. Create a list with the coordinates (x,y) as a tuple.
Hint: Find out about the \texttt{zip} function.

You have decided that actually, you need the two seperate lists, but unfortunately,
you have thrown them away.
How can we use zip to \emph{unzip} the list of tuples to get two lists again?

% titledquestion zip (end)

\titledquestion{Distances} % (fold)
\label{sub:zip}

Suppose we have two vectors, \texttt{x} and \texttt{y}, stored as tuples with $n$ elements.
Implement functions that compute the $l_1$ and $l_2$ distances between \texttt{x} and \texttt{y}.
Note that $n$ is not explicitly given.

% titledquestion distances (end)
\end{questions}
% section tuples (end)


%!TEX root=report.tex
\section{Conclusion}

The main purpose of this report was to describe mass losses or gains at the West Coast of Greenland and Western Antarctica.
Both locations were found to be losing mass.
Both location had periodic trends, but while West Greenland had soft oscillating curves Western Antarctica's mass loss was more jagged; this might suggests that ice is melting and breaking of in a more unstable pattern.
However, overall it was found that ice at the two locations was melting with approximately the same speed and with a slight difference in acceleration.

\begin{table}[H]
\centering
\begin{tabular}[H]{l | cc}
Parameter/location & Western Antarctica  & South Coast of Greenland \\ \hline
Velocity $\left[\frac{m}{day}\right]$ &  $-2.26 \cdot 10^{-4}$ & $-2.24 \cdot 10^{-4}$ \\
Acceleration $\left[\frac{m}{day^2}\right]$ &  $-1.24 \cdot 10^{-7}$ & $-8.27 \cdot 10^{-8}$ \\
\end{tabular}
\caption{Velocity and acceleration for the two analysed locations}
\end{table}

Of course these estimates depend on the selected locations and by choosing a different pair of locations, the estimates may not be exactly the same.
To get a better understanding of the patterns plots of the velocity (Figure \ref{fig:ols-world-parameter-vel}) and acceleration (Figure \ref{fig:ols-world-parameter-acc}) in a world view, was also made.
From these it is seen that Greenland and Antarctica are generally very similar in maximum magnitude of both acceleration and velocity. The most surprising observation is probably found in Greenland. Here the highest velocity is found on the east coast, but the highest acceleration is actually located on the west cost. This is not similar to Antarctica, where the highest acceleration and velocity is located at approximately the place.

Similar results were gained when using clustering algorithms to find similar locations. Here GMM with a Kernel PCA \ref{section:result-gmm} seems to give a much less noisy result than K-means \ref{section:result-kmeans}.

These results are of course influenced by the glacial isostatic adjustment. Later the ICE-5G dataset was used to correct for this (glacial isostatic adjustment), though NASA suggest  \cite{NASA-GIA-incomplete} that this is not enough to get useful estimates.

Attempts to improving the variance of these estimates were also made. First by using a GLS model instead of a OLS model \ref{section:result-ols-ar} and later by introducing basis expansion \ref{section:result-splines} to allow for more flexibility in the seasons. Both of these gave good results and it is even possible to combine the methods. However, in the case of the splines (technically it is not a spline, as it is not a polynomial), even though the obtained fit was theoretically good, several cusp and movements that to the human eye looked discontinuous existed. Thus it should not be recommended to use splines with cosine and sine functions, without doing something to improve the continuity.

Another way to improve the variance is to reduce the amount of OLS parameters. Here the p-values and the LAR \ref{section:result-lar} model suggests that only OLS parameters down to a period of $3 \cdot \omega$ is worth keeping. At least for those selected locations.

Finally a time series model was used in form of a seasonal ARIMA \ref{section:result-ts}. The results here were disappointing in that the residuals were far from being white noise distributed. This suggests that there are exogenous inputs which affects the system in a significant way. Finding and observing those variables would possibly also allow for a better OLS estimate.


% Karlin-Altschul Equation
%
% Basic introduction to the Karlin-Altschul equation.

\subsection{The Karlin-Altschul Equation}
\begin{frame}
  \frametitle{Definition}
  \begin{itemize}
    \item The Karlin-Altschul equation
    \begin{equation*}
      E = k m n e^{-\lambda S}
    \end{equation*}
    \item Symbols:
    \begin{itemize}
      \item $k$: minor constant, adjusts for correlation between alignments
      \item $m$: number of letters in query sequence
      \item $n$: number of letters in the database
      \item $\lambda$: scoring matrix scaling factor
      \item $S$: raw alignment score
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Interpretation}
  \begin{itemize}
    \item The Karlin-Altschul equation
    \begin{equation*}
      E = k m n e^{-\lambda S}
    \end{equation*}
    \item $E$ is the number of alignments of a similar score expected by chance when querying a database of the same size and letter frequency, where the letters in that database are randomly-ordered
    \item Small changes in score $S$ can produce large changes in $E$
    \item BUT biological sequence databases are not random!
  \end{itemize}
\end{frame}


%\newcommand{\lstst}{\begin{lstlisting}[frame=single]
%set<SET,EQUAL >
%\end{lstlisting}}
%\newcommand{\lstst}{\lstss{set\<SET,EQUAL \>}}
\section{Introduction}
This paper is intended to compile some requirements as to how to implement a computer algebra library written in \textsf{C++} and define a what should and should not be included.
\subsection{Background}
A previous version of a computer algebra library was written by us a couple of years ago. It was pretty straight forward. There was a set of base class templates which inherited their properties to ther child classes (or class templates) in the following way:
\newcommand{\lstss}[1]{\textsf{#1}}
\newcommand{\lstst}{\lstss{set$\left<\mathtt{SET,EQUAL}\right>$}}
\bn
\item The root class template was \lstst, where \textsf{SET} type parameter was the implementing child class (template) with (in-) equality operators and \textsf{EQUAL} type parameter was the a class template implementing a function operator\\
\begin{lstlisting}[frame=single]
/**
 * Set class templ.
 * General base class templ
 */
template<typename SET, typename EQUAL >
class set {
	const SET* ptr;
protected:
	set():ptr(0){}

	//only inheritance, no direct usage
	set(SET& ref):ptr(const_cast<const SET*>(&ref)){}

public:

	//static member of type 'EQUAL' should inherit
   	//from equal_map<set>, used in equality
	static const EQUAL& EQUAL;

	~set(){if(ptr!=0) ptr=0;}
	bool operator==(const SET& s1, const SET& s2) const {
		return EQUAL(s1,s2);
	}
	bool operator!=(const SET& s1, const SET& s2) const {
		return !(s1==s2);
	}
};
/**
 * Equality map class templ.
 * All equality maps should inherit from this
 * class templ and implement map operator
 */
template<typename SET >
class equal_map {
protected:
	equal_map():ptr(0){}
public:
	bool operator()(const SET& s1, const SET& s2) const ;
};
\end{lstlisting}
\newcommand{\lstsg}{\lstss{semi\_{}group$\left<SEMI,EQUAL,OPER \right>$}}
\item The immediate child template of \lstst was
\begin{lstlisting}[frame=single]
template<typename SEMI, typename EQUAL, typename OPER >
class semi_group<SEMI, EQUAL,OPER > : public set<SEMI, EQUAL >
{
//code
};
\end{lstlisting}
 where the \textsf{SEMI} is an implementing partial specialization/child of\\ \indent \textsf{semi\_{}group$\left<SEMI,EQUAL,... \right>$},\\
 \textsf{EQUAL} as in its parent class and \textsf{OPER} is a binary associative operation
$$m : \mathsf{SEMI} \times \mathsf{SEMI} \longrightarrow \mathsf{SEMI},\ (s,s') \longmapsto s s'$$
on \textsf{SEMI}. For convenience a specialized structure was provided:
\begin{lstlisting}[frame=single]
template< typename SEMI >
struct oper_morph {
SEMI operator()(const SEMI& s1, const SEMI& s2) const ;
}
\end{lstlisting}
such that each child class would simply provide the definition of the map operator for each specialization. In addition, those types of classes were usually kept as singleton classes, i.e. there would only be one instantiation for type implemented.
\item The immediate child of \lstst was the monoid class template with one additional type parameter: \textsf{NEUT}, the trivial map:
$$e : \ast \longrightarrow M,\ \longmapsto e_M,$$
where $e_M$ is the neutral element of the monoid $M$ and $\ast$ is the trivial submonoid.
\begin{lstlisting}[frame=single]
/**
 * The monoid class template
 */
template<typename MONO, typename EQUAL, typename OPER , typename NEUT>
class monoid<MONO, EQUAL, OPER, NEUT > : public semi_group<SEMI, EQUAL, OPER >
{
//code
};
\end{lstlisting}
Again, a structure template was provided for both the operation map and neutral map
\begin{lstlisting}[frame=single]
/**
 * The operation map structure template
 */
template< typename MONO >
struct oper_morph {
MONO operator()(const MONO& s1, const MONO& s2) const ;
};
/*
 * The neutral map structure template
 */
template <typename MONO >
struct trivial {
	//should be a constant ref.
	const MONO& operator()() const ;
};
\end{lstlisting}
\item The immediate child of \texttt{monoid} was \texttt{group} with one additional template parameter, the inversion map, with on structure template already provided:
\begin{lstlisting}[frame=single]
template< typename GROUP, typename EQUAL, typename OPER, typename NEUT, typename INVERSE >
class group : public monoid<GROUP,EQUAL,OPER,NEUT,INVERSE > {
//code
};
template< typename SEMI >
struct inverse_morph {
	GROUP operator()(const GROUP& g) const ;
};
\end{lstlisting}
To distinguish between non-abelian and abelian groups, we implemented two base class templates that came with a structure template for the neutral element.
\en
\subsection{The problem}
Two major problems arose from this form of implementation.
\subsubsection{Steepness}
With additional class templates in place to provide a basic interface for computer algebra library, one particular problem crept up: a rather steep level of inheritance. Although, each constructor usually consists of one line of code leaving a distinct chance of proper optimisation, a different optimisation scheme and a general dependence on another compiler might serverly alter timing.\\
\subsubsection{Code bloat}
The problem came clear when we started testing the implementation for bugs. Checking the size on even the simplest type, for instance the cyclic ring class template parameterised via its charactersistic, had a size of 72 bytes although only an unsigned integer coded each instance. In addition, copy construction became prohibitively expensive as all base class constructors had to be called (for the latter example, six base class constructor calls were required only to copy some integers).\\Secondly, all constructs requiring a multitude of instances of different types within this type framework caused substantial costs in memory. Consider the type \texttt{fraction} inheriting from a field type - this type would require two group structures as $(\mathbb{Q}, +, 0, -)$ and $(\mathbb{Q}^\times, \cdot, 1, ^{-1})$ which in turn, depend on the integer type within the same frame work. Thus, the minimal requirement for memory would by 144 bytes per instance. Any type consisting of instance of fractions would be a multiple of this size.
\subsubsection{Diamond problem}
Certain algebraic structures were diamond prone, that is a class diagram converged at one level with matching parameter types. Consider a two-sided module
\begin{lstlisting}[frame=single]
/**
 * Left module class template
 * Comes with unital ring parameters (not given) and module
 * specific parameter list
 * -> URNG type of underlying unital ring
 * -> ...  ring specific parameter list
 * -> MOD  type of implementing class
 * -> ...	module specific parameter types
 */
template<typename URNG, ..., //ring specific parameter list
typename MOD, typename ADD, typename MOD_ZERO,
typename MOD_INV, typename LEFT_SCALAR >

//is a direct child of ablian groups class templ.
class left_mod : public ablian_group<MOD, ADD, MOD_ZERO, MOD_INV > {
public:

	//left scalar multiplication map
	static const LEFT_SCALAR& LEFT;

	//operator definition
	friend MOD operator*(const URNG& scl, const MOD& m){
		return LEFT(scl,m);
	}
};
/**
 * Right module class template
 * Comes with unital ring parameters (not given) and module
 * specific parameter list
 * -> URNG type of underlying unital ring
 * -> ...  ring specific parameter list
 * -> MOD  type of implementing class
 * -> ...	module specific parameter types
 */
template<typename URNG, ..., //ring specific parameter list
typename MOD, typename ADD, typename MOD_ZERO,
typename MOD_INV, typename RIGHT_SCALAR >

//is a direct child of ablian groups class templ.
class right_mod : public ablian_group<MOD, ADD, MOD_ZERO, MOD_INV > {
public:

	//right scalar multiplication map
	static const RIGHT_SCALAR& RIGHT;

	//operator definition, note the inversion of arguments
	//compared to left_mod<URNG,...,MOD,...>
	friend MOD operator*(const MOD& m, const URNG& scl){
		return RIGHT(m,scl);
	}
};
\end{lstlisting}
Now, let us consider a class inheriting from both classes, called \texttt{two\_{}mod}. We would get
{\scriptsize
$$\xymatrix{
&\mathtt{two\_mod}\ar[rd]\ar[ld]&\\
\ar[rd]\mathtt{left\_mod<URNG,...,two\_mod,...>}&&\mathtt{right\_mod<URNG,...,two\_mod,...>}\ar[ld]\\
&\mathtt{abel_group<two\_mod,...>}&\\}$$}
This class has two distinct inheritance paths to the same parameterisation of the base class template \texttt{abel\_{}group}. Therefore, any ambiguious function/member call will result in a compile error. It can only be resolved via virtualisation of the base class in the diagram. On the other hand, virtualisation prohibits the use of constant expressions in newer standard versions and adds to the users responsiblity to correctly instantiate objects by including a direct constructor call to the virtual base class in every constructor in every base class.
\subsection{Workaround}
An immediate workaround came apparent: instead of preserving the mathematical structure in a steep inheritance tree, simple construct category class templates with members (data or functions) that contain a given mathematical structure and provide functors where needed or wanted. The idea is that each instantiation of a mathematical object should only rely on a simple base class and have the containing category objects deal with upward and downward casting (in type theoretic fashion).\\
\indent We will discuss this and other approaches in the next section.\\


\section{Introduction}

A $\beta$-variational autoencoder ($\beta$-VAE) is a family of unsupervised models whose goal is to infer a ``disentangled," low-dimensional representation of some high-dimensional data, often images \cite{weng2018VAE}. In general, auto-encoders seek to reconstruct some input $\vx\in\R^d$ while simultaneously learning a latent representation, $\vz\in\R^k$, which is typically chosen to be lower-dimensional than $\vx$. This is accomplished by training two models: an encoder parameterized by $\phi$, denoted $g_\phi(\vx)$, and a decoder parameterized by $\theta$, denoted $f_\theta(\vz)$. The algorithm is, roughly:
\begin{enumerate}
    \item Given example $\vx$, compute $\vz = g_\phi(\vx)$
    \item Compute reconstruction $\hat{x} = f_\theta(\vz)$
\end{enumerate}
A limitation of this deterministic autoencoder is that the latent space in which $\vz$ resides is typically quite sparse and/or irregular. This can make it difficult to use the latent representations for inference or other purposes. Variational auto-encoders (VAEs) improve upon this by replacing the decoder $f_\theta$ with a stochastic sampling function. Consequently, $g_\phi$ now outputs a mean $\vmu$ and a covariance $\Sigma$, which parameterize a Gaussian distribution \cite{kingma2013auto}. The algorithm then becomes:
\begin{enumerate}
    \item Given example $\vx$, compute ($\vmu, \Sigma) = g_\phi(\vx)$
    \item Sample latent variable $\vz \sim \N(\vmu, \Sigma)$
    \item Compute reconstruction $\hat{x} = f_\theta(\vz)$
\end{enumerate}

To make this model tractable, we typically use isotropic Gaussians, meaning the covariance matrix $\Sigma$ is diagonal. By replacing the deterministic algorithm with a stochastic one, the model is forced to learn latent representations that are more robust to Gaussian noise, since if small perturbations led to dramatically different outputs, the model would perform poorly at reconstructing the output. The loss function for the VAE can be expressed as a sum of two terms: (1) reconstruction error and (2) regularization (defined more rigorously later on in the methods section). The reconstruction term pushes the model to faithfully reconstruct the original data, while the regularization term encourages the model to learn a generalizable and efficient latent representation.

While the VAE model solves the problem of irregular latent spaces, there are no guarantees that the latent representations are {\it meaningful}. This gives rise to the idea of {\it disentanglement}, which is roughly the notion that the different components of the latent variable $\vz$ should correspond to distinct {\it generative factors} (i.e. the parameters of the generative process) \cite{bengio2012representation}. For instance, if we are modelling an image dataset consisting of human faces, we might want one dimension to correspond to skin tone, another to correspond to eye shape, a further one to correspond to amount of hair, and so on. Introduced by Burgess et al. in 2018, the $\beta$-VAE is a model designed with this goal in mind \cite{higgins2016beta}. An additional hyperparameter, $\beta \in \R$ is added as a coefficient for the regularization term from the VAE loss. When $\beta=1$, the loss function is identical to the original VAE loss function. When $\beta > 1$, the model is forced to learn a less expressive, and therefore more information-dense, latent encoding for the data. Furthermore, the representations learned by $\beta$-VAE tend to be more disentangled, meaning that it is more possible to recover the original factors that may have generated the data.

In the landscape of dimensionality reduction techniques, $\beta$-VAE (and all types of VAE) are non-linear. The data domain (images) is such that the data are extremely high dimensional but the dimensions have highly complex relationships with one another, both geometrically and semantically. It is for this reason that simpler, more linear dimensionality reduction techniques, like PCA, or manifold-based techniques, like ISOMAP, are less likely to be able to perform well on image data, while VAE's can. However, this additional flexibility comes at the cost of reduced interpretability, since we no longer have any guarantees about the geometric relationship between the data space and latent space. This is where $\beta$-VAEs come in: by reducing the flexibility of the latent space, we can hopefully gain more interpretability in the low-dimensional representations.


\documentclass{iitkthesis}

\usepackage{mathtools,amssymb}

\usepackage{lipsum}

\usepackage{libertine}

\title{When my thesis has its own latex class, and the title is so
  long that it does not fit into one line}

\author{Raghav Brahmadesam Venkataramaiyer}
\rollno{14119266}
\degree{Doctor of Philosophy}
\department{Design Programme}
\submissiondate{February 2021}

\advisors{%
\advisor{Dr. Vinay P. Namboodiri}{\textsc{cse iitk}}{}
}

\advisornames{{Dr. Vinay P. Namboodiri}}

\advisenum{%
  \item {Dr. Vinay P. Namboodiri}
}

\begin{document}
\frontmatter
\maketitle
\certificate
\declaration

\abstract{\lipsum}

\mainmatter
\chapter{Introduction}

\lipsum[1-4]

\section{The first blood}

There is a variable $\mathbf{x} \equiv \{x_0,x_1,\ldots,x_n\}$.

\begin{align}
  \theta^* = \arg\min_\theta
             \mathbb{E}_{\mathbf{x},y\sim\mathrm{data}}
             \left(\Delta(F_\theta(\mathbf{x}),y)\right)
\end{align}

\lipsum[5-12]

\subsection{Blaze of glory}
\lipsum[14-28]

\paragraph{Bon Jovi}
\lipsum[29-31]

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


\subsection{Unstable gradient problem}

\subsubsection{Vanishing gradient problem}

Gradients can be become small, and so propagation can be very slow.

\subsubsection{Exploding gradient problem}

Gradients can become too large and not converge.

\subsubsection{ReLU}

This addresses the unstable gradient problem.


\section{L* and NL* execution with example}

This section aims to provide an example of the execution of the two algorithms taking the unknown language $\U$ defined by $\E+(b+aa+abb)(a+b)^*$ % $+(b+aa+abb)(a+b)*
\input{sections/annexe/example/L_example.tex}
\input{sections/annexe/example/NL_example.tex}

\subsection{Example to find residual from a regular language}
In this section we would like to explain why the \textit{mDFA} of \cref{sec:l-exec} has one state more of the \textit{cRFSA} of \cref{sec:nl-exec}.

Let's start with the regular expression of $\U = \E+(b+aa+abb)(a+b)^*$. The residuals of this language can be found iteratively thanks \cref{algo:find_residuals}.

\begin{algorithm}[H]
  \caption{Algo to find residuals of a language $\U$}
  \label{algo:find_residuals}
  \KwIn{$\U$, $\Sigma$}
  \KwOut{$\RE$ = The set of residuals of $\U$}
  $\RE \gets \{\}$ \tcp*{Initialisation of $\RE$}
  $E \gets \{\E\}$\tcp*{The list of words to treat}
  \While{$E.length > 0$}{
    $current \gets E.pop()$\;
    $residual = (current)^{-1}L\footnote{This operation can be performed, for example, with the \textit{Brzozowski derivative} algorithm}$\;
    \If{$residual \notin \RE$}{
      $\RE \gets \RE \cup \{residual\}$\;
      \For{$sym \in \Sigma$}{
        $word \gets current \cdot sym$\;
        $E \gets E \cup \{word\}$\;
      }
    }
  }
  \Return $\RE$
\end{algorithm}

Let's apply this algorithm over $\U$.

\newcommand{\EM}{\varnothing}

\begin{tabular}{c|c|r|l|c|l}
  $Iteration$   & current & Operation      & Result                  & $\RE$                  & $E$                        \\
  \hline\hline
  \textit{Init} & $-$     & $-$            & $-$                     & $\RE = \{\}$           & $E = \{\E\}$               \\
  1             & $\E$    & $\E^{-1}\U$    & $\RE_1 = \U$            & $\RE = \RE \cup \RE_1$ & $E = \{a, b\}$             \\
  2             & $a$     & $a^{-1}\U$     & $\RE_2 = (a+bb)(a+b)^*$ & $\RE = \RE \cup \RE_2$ & $E = \{b, aa, ab\}$        \\
  3             & $b$     & $b^{-1}\U$     & $\RE_3 = (a+b)^*$       & $\RE = \RE \cup \RE_3$ & $E = \{aa, ab, ba, bb\}$   \\
  4             & $aa$    & $(aa)^{-1}\U$  & $(a+b)^* = \RE_3$       & $-$                    & $E = \{ab, ba, bb\}$       \\
  5             & $ab$    & $(ab)^{-1}\U$  & $\RE_4 = b(a+b)^*$      & $\RE = \RE \cup \RE_4$ & $E = \{ba, bb, aba, abb\}$ \\
  6             & $ba$    & $(ba)^{-1}\U$  & $(a+b)^* = \RE_3$       & $-$                    & $E = \{bb, aba, abb\}$     \\
  7             & $bb$    & $(bb)^{-1}\U$  & $(a+b)^* = \RE_3$       & $-$                    & $E = \{aba, abb\}$         \\
  8             & $aba$   & $(aba)^{-1}\U$ & $(a+b)^* = \RE_3$       & $-$                    & $E = \{abb\}$              \\
  9             & $abb$   & $(abb)^{-1}\U$ & $\RE_5 = \EM$           & $\RE = \RE \cup \RE_5$ & $E = \EM$                  \\
\end{tabular}

We see that the residuals of $\U$ are exactly five, the same number of state of the \textit{mDFA} returned by \textit{L*}, but only four of them are \textit{prime} because $\RE_3 = \RE_1 \cup \RE_2 \cup \RE_4$. That's why the \textit{cRFSA} has only four states.


\lab{Extensions}{Python Idioms}{Idiomatic Python}
\label{lab:Extensions_Idioms}

\objective{Learn various ways to do things efficiently in Python}

\begin{definition}[Idiom]
the style of expression in writing, speech, or music that is typical of a particular period, person, or group.
\end{definition}

Python has many powerful idioms that are very common.  The experienced Python programmer will at some point in time encounter these idioms.  The idioms discussed in this chapter take special advantage of the Python language to do things in a cleaner, more elegant, and often more efficient manner.  We will use the Zen of Python as a guide to the concepts discussed in this lab.

Lets begin:
\begin{lstlisting}
: import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
\end{lstlisting}

\section*{1. Beautiful is better than ugly}
\begin{lstlisting}
squares = []
for n in range(10):
    squares.append(n**2)

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
\end{lstlisting}
In this example, we are constructing a list of the squares of the numbers 1 to 10.
Now lets add only the odd squares.
\begin{lstlisting}
oddsquares = []
for n in range(10):
    n = n**2
    if n%2 == 0:
        oddsquares.append(n)

[1, 9, 25, 49, 81]
\end{lstlisting}
In Python, both of these solutions are pretty clear and succinct.
However, each problems can solved respectively as follows
\begin{lstlisting}
squares = [x**2 for x in range(10)]
oddsquares = [x for x in squares if x%2 == 1]
\end{lstlisting}
These two solutions are known in Python as list comprehensions.
List comprehension syntax closely mirrors the mathematical form of set definition.

\section*{2. Explicit is better than implicit}
\begin{lstlisting}
from scipy import *
a = rand(10,10)
\end{lstlisting}

Importing things into the global namespace (more on that later) is not a good idea.

Things should be imported explicitly
\begin{lstlisting}
from scipy import rand as sprand
a = sprand(10,10)
\end{lstlisting}

\section*{3. Flat is better than nested}

\section*{4. Sparse is better than dense. Readability counts.}
\begin{lstlisting}
primes = [x for x in range(2, 50) if x not in [j for i in range(2,8) for j in range(i*2, 50, i)]]
\end{lstlisting}

\section*{5. Namespaces are one honking great idea -- let's do more of those!}
Two python objects cannot share the same name.  If two python objects happen to share a name,
one of the objects will override the other.  There is no notion of method overloading in Python.
In other languages two functions may share the same name if they accept different input arguments.
In Python, the most recently defined will override any method that shares the same name,
regardless of the input arguments.
\begin{lstlisting}
def random(x):
    return x**2+.5**.215%x
def random(y):
    return y**9**(1./3)-.52%y
\end{lstlisting}
In the code above, the second \li{random} function will override the first \li{random}.
After the second function is defined, the first function is completely inaccessible.
Now let's import Python's \li{random} module (\li{import random}).  Now \li{random} refers
to the module and not to our defined function.  This is where the concept of namespaces becomes important.
A namespace is a space or collections of names.  It is Python's method of keeping names from colliding.
Namespaces are defined in Python using modules.  We mention namespaces because, it not understood could be
a source of grief.  We illustrate with another example
\begin{lstlisting}
def add(x, y):
    return x*y/(x+y)
\end{lstlisting}
As you can see, our function clearly does add two numbers in the standard way.  There are three ways
to import Python modules.  We will use the SciPy library as an example.
\begin{enumerate}
\item \li{import scipy} imports all the functions in the SciPy namespace and places them in
the \li{scipy} namespace.  SciPy also has an add function which adds elements of two arrays.
This add function can be accessed by \li{scipy.add} while our version of add is still accessible by \li{add}.
If we don't want to always type \li{scipy.}, we can define an alias for the namespace by importing our module
with \li{import scipy as sp}.  Then we access SciPy's add function by \li{sp.add}.
\item \li{from scipy import add} will import SciPy's add function into the current namespace.  Our add function
will no longer be accessible after this import.  We can again define an alias by \li{from scipy import add as sadd}.
\item \li{from scipy import *} is highly discouraged as it provides no control over namespaces.  It will import all
functions in the SciPy namespace, clobbering any function in current namespace that shares the same name.
\end{enumerate}

\section*{Constructions}

\subsection*{Strings}
Strings are immutable object in Python.  As such, it is quite costly to concatenate strings using the \li{+} operator.
\begin{lstlisting}
: import string
: def concatStr(strs):
:     m = `'
:     for s in strs:
:         m += s
:     return m
: def accumStr(strs):
:     return `'.join(strs)
: timeit concatStr(list(string.letters))
100000 loops, best of 3: 3.03 us per loop
: timeit accumStr(list(string.letters))
1000000 loops, best of 3: 810 ns per loop
\end{lstlisting}
Notice that \li{accumStr} runs considerably faster.  What is actually happening in \li{concatStr} is that each time we add an element from \li{list(string.letters)}, Python has to reallocate the entire string in memory.  Not only is \li{accumStr} more efficient, but it is also significantly shorter.

Python has some really powerful string formatting options available.  More information is located at \url{http://www.python.org/dev/peps/pep-3101/}

\subsection*{Tuples}
Python creates tuples whenever the interpreter encounters a list of comma separated values.  This is called tuple packing.
\begin{lstlisting}
: a = 1, 2, 3, 4, 5
: print a, type(a)
(1, 2, 3, 4, 5) <type `tuple'>
\end{lstlisting}
We can also unpack a tuple into several variables
\begin{lstlisting}
: a, b, c = 1, 2, 3
: print a; print b; print c
1
2
3
\end{lstlisting}
We can take advantage of this to quickly swap the values of two variables.
\begin{lstlisting}
: a, b = 3, 5
: print a; print b
3
5
: b, a = a, b
: print a; print b
5
3
\end{lstlisting}
Note the following
\begin{lstlisting}
: (0,)
(0,)
: 0,
(0,)
: (0) #this is not a tuple!
0
: () #this is a special empty tuple
()
: tuple() #tuple constructor
()
\end{lstlisting}

\section*{Lists}
Lists are Python's workhorse datatype.  It is therefore highly useful to be able to quickly and efficiently construct and iterate through lists in Python.
\begin{lstlisting}
: [] #an empty list
[]
: list() #list constructor
[]
: [1] #list with one element
[1]
: [1, 2] #list more than one element
[1, 2]
\end{lstlisting}

\subsection*{List Constructions}
List comprehensions are a very powerful in Python.  They permit us to write short, possible nested, loops that result in the creation of a list of objects.  Detailed information about list comprehensions can be found at \url{http://www.python.org/dev/peps/pep-0202/}
\begin{lstlisting}
: [i for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
: [i**2 for i in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
: [i**2 for i in range(10) if i%2==0]
[0, 4, 16, 36, 64]
: [i**2 if i%2==0 else i for i in range(10)]
[0, 1, 4, 3, 16, 5, 36, 7, 64, 9]
: [(i,j) for i in range(3) for j in range(5, 7)]
[(0, 5), (0, 6), (1, 5), (1, 6), (2, 5), (2, 6)]
\end{lstlisting}
List comprehensions should not be used when clarity will be sacrificed.  It would be counterproductive to maintain a complex list comprehension that could have been written as a regular \li{for} loop.

One might be tempted to do the following to create a list of ten $1$s.
\begin{lstlisting}
: l = []
: for x in range(10):
:     l.append(1)
: for x in range(5):
:     l.append(8)
\end{lstlisting}
The same can be done with the following.  The plus operator on lists means concatenate and the
multiplication operator on lists means repeat or tile.
\begin{lstlisting}
: l = [1]*10+[8]*5
\end{lstlisting}

\subsection*{List Iteration}
Python contains a handful of really nice ways to iterate though lists.

When iterating though lists, it is recommended to iterate by object rather than by index.
However, if indexes are needed, using \li{enumerate} is highly suggested.
\begin{lstlisting}
: a = list(`abcdefghijklmnopqrstuvwxy')

#iterate by index
: for i in range(len(a)):
:     print a[i],
a b c d e f g h i j k l m n o p q r s t u v w x y z

#iterate by object
: for l in a:
:     print l,
a b c d e f g h i j k l m n o p q r s t u v w x y z

#using enumerate
: for i in enumerate(a):
:     print i,
(0, `a') (1, `b') (2, `c') (3, `d') (4, `e') (5, `f')
(6, `g') (7, `h') (8, `i') (9, `j') (10, `k') (11, `l')
(12, `m') (13, `n') (14, `o') (15, `p') (16, `q') (17, `r')
(18, `s') (19, `t') (20, `u') (21, `v') (22, `w')
(23, `x') (24, `y') (25, `z')
\end{lstlisting}

When iterating a list in reverse it is advisable to use the \li{reversed()} function.
\begin{lstlisting}
: a = range(100)
: timeit for x in reversed(a): pass
#Do not do this.  It creates a copy of the list to iterate through.
: timeit for x in a[::-1]: pass
\end{lstlisting}

To quickly eliminate duplicates from a list, the best way is to convert to a \li{set}
and then back to list.
\begin{lstlisting}
: a = [1,1,5,2,3,6,43,32,2,43,65,6,3,2,1,1,1]
: a = list(set(a))
\end{lstlisting}

\begin{problem}
Compare the time needed to complete each operation below on sets, tuples, lists, and dictionaries.
\begin{enumerate}
\item Membership: Testing to see if an element is in the sequence
\item Insertion/Remove: Insert an element at beginning middle a
\item Sorting: Note that the underlying data structures for sets and dictionaries keep the keys in sorted order.
\end{enumerate}

\end{problem}

\begin{problem}
Do all of the following in one line of code.
You may not use semicolons to combine multiple lines of code.
You may only import functions from the Python standard library.
Import statements do not count as your one line of code.

Note that some of these things should actually be done in multiple lines, but you should do this now to ensure that you actually understand the basic python datatypes.
Often when you are writing a program, readability, simplicity, and elegance take precedence over the number of lines used or the speed at which the program runs.
\begin{enumerate}
\item Create a list, $X$, of tuples that represent the equivalence relation which generate
the congruence classes $\mod 5$ on the numbers 0 to 49.  When done, execute
\end{enumerate}

\item Use a single list comprehension to make the list $X$ of tuples that represent the equivalence relation which generates the congruence classes $\pmod 5$ on the numbers 0 through 49.
Multiply the list by 20 to add lots of duplicate entries (still in the same line)
Hint: You probably want something of the form \li{[... for a in ... for b in ... if...]}

\item Shuffle your new list. This should be very easy, just go to the documentation and find the function that does it.

\item Eliminate adjacent duplicate entries.
Hint: to modify the list in place do something like \li{X[:]=...}

\item Sort your list by the second value of each tuple.

\item Make two new lists $x$ and $y$, where $x$ is the ordered list of the first item of each tuple and $y$ is the ordered list of the second item of each tuple.
Hint: You will want to map the list function onto an unzipped version of $X$.
Also notice that something like \li{a,b=1,2} assigns both $a$ and $b$ simultaneously.

\item Print the number of duplicate $x$ values, then the number of duplicate $y$ values (in the same line).
Hint: \li{set(X)} will be a set of all unique entries in $X$.

\item Sort all three lists by $x$ value (yes, in one line).
Hint: Unzip a list comprehension of tuples.

\item Make a set $Xset$ representing the unique entries of $X$.
Also make a new set $X15set$ that represents the congruence classes $\pmod 15$. (all in the same line)

\item Make functions corresponding to $X$ and $X15$ that take two numbers as arguments and use $X$ and $X15$ to determine if they relate.
Have each function return True or False.
Hint: Use lambda functions (you may have to look them up).

\item Make a list of the equivalence classes formed by $X$ assuming no prior knowledge of the equivalence classes, i.e. you must generate the equivalence classes of $X$ using $X$, not just list them off based on how we defined $X$.
Hint: It should include a nested list comprehension.
This one is pretty ugly.

\item Remove duplicates from $X$
Hint: Convert it to a set, then back to a list.

\item Shuffle $X$ again.

\item Reinitialize $x$ and $y$ from the shuffled version of $X$.

\item Make a dictionary based on $x$ and $y$ which, for each member of $x$, gives some meber of $y$ which relates to it.
Hint: Use a dictionary comprehension.
Note that item assignment on a dictionary adds an item if it isn't already there and overwrites it if it is.
Also note, that if we had not already removed duplicates from $X$, you would want to iterate over set representations of $x$, $y$, and $X$ because the duplicates would slow down computation considerably.

\item Test your dictionary to see if it represents a surjective function.
Hint: Use \li{all()}.
Also, consider the \li{values()} method of dictionaries.

\item Test your dictionary to see if it represents an injective function.
Hint: Consider the \li{keys()} method of dictionaries.

\item Initialize an empty dictionary for the the next part of the problem.
Note that you can also initialize empty sets and lists.

\item Make a dictionary that represents a random function from $x$ to $y$ that is injective and surjective.
You should be able to base this entirely on the current order of $X$, since we shuffled it earlier.
You may use three lines for this one.
The first two should be used to begin for loops.

\item Show the dictionary you defined represents a surjective function.

\item Show the dictionary you defined represents an injective function.

\end{itemize}

\end{problem}

\begin{problem}

Make two randomly shuffled lists containing each of the numbers from $0$ to $100$ exactly once as a floating point value.
Use two for loops and a try-catch block (not an if statement) to divide each element of one list by each element of the other list.
Store the results in a new list.
When you hit zero-division, you should set the result equal to $0$.

\end{problem}

\begin{itemize}
\item Comprehensions (lists, sets, dicts, tuples)
\item Strings+formatting
\item Generators
\item == vs is
\end{itemize}


%---------------------------Volume-----------------------------
\section{Volume}

The tetrahedron volume metric is simply
\[
q = V.
\]

\tetmetrictable{volume}%
{$L^3$}%                                      Dimension
{$[0,DBL\_MAX]$}%                             Acceptable range
{$[-DBL\_MAX,DBL\_MAX]$}%                     Normal range
{$[-DBL\_MAX,DBL\_MAX]$}%                     Full range
{$\frac { \sqrt{2}} {12}$}%                   Equilateral tet
{\cite{par:93}}%                              Citation
{v\_tet\_volume}%                            Verdict function name


\chapter*{List of Symbols}\label{app:listOfSymbols}
The list of symbols found below contains often-used symbols in the thesis in the context that they are normally used. Depending on the context they might carry a different meaning ($y$ being displacement of the lip-reed in Chapter \ref{ch:trombone} but the vertical spatial coordinate for 2D systems in fx. Chapter \ref{ch:2Dsyst}). Some might also be accompanied by a subscript in the main document

{\centering\renewcommand{\arraystretch}{1.1}
\begin{longtable}{ p{2cm} p{6.5cm} p{2.5cm}  }
 Symbol & Description & Unit\\
 \hline\\
 \endhead
 $\alpha$ & Fractional part of & \\
 $A$ & Cross-sectional area of string & m$^2$\\
 $c$ & Wave speed & m/s\\
 $\frac{d^n}{dt^n}$ & $n$\textsuperscript{th} order derivative with respect to $t$ & - \\
 $\pt^n$ & $n$\textsuperscript{th} order partial derivative with respect to $t$ & - \\
 $\dtp$, $\dtm$, $\dtd$ & Forward, backward and centred difference in time operator & - \\
 $\dxp$, $\dxm$, $\dxd$ & Forward, backward and centred difference in space operator& - \\
 $\dtt$& Second order difference in time operator& - \\
 $\dxx$& Second order difference in space operator& - \\
 $\dxxxx$& Fourth order difference in space operator& - \\
 $\mtp$, $\mtm$, $\mtd$ & Forward, backward and centred average in time operator& - \\
 $\mxp$, $\mxm$, $\mxd$ & Forward, backward and centred average in space operator& - \\
 $\mtt$ & Second order average in time operator& -\\
 $\mxx$ & Second order average in space operator& -\\
 $E$ & Young's Modulus & Pa (kg$\cdot$m$^{-1}\cdot$s$^{-2}$)\\
 $f$ & Force & N\\
 $f$ & Frequency & Hz\\
 $f_\text{s}$ & Sample rate & Hz\\
 $h$ & Grid spacing & m \\
 $H$ & Membrane / Plate thickness & m \\
 $I$ & Area moment of inertia & m$^4$\\
 $l$ & Spatial index of a grid function & - \\
 $l,m$ & Spatial index of a 2D grid function & - \\
 $L$ & Length & m\\
 $L_x$ & Length in $x$-direction (2D) & m\\
 $L_y$ & Length in $y$-direction (2D) & m\\
 $k$ & Time step ($=1/f_\text{s}$) & s\\
 $K$ & Spring coefficient & N/m\\
 $\kappa$ & Stiffness coefficient & m$^2$/s \\
 $n$ & Sample index to grid function & - \\
 $N$ & Number of points string & -\\
 $N_x$ & Number of points $x$-direction (2D) & -\\
 $N_y$ & Number of points $y$-direction (2D) & -\\
 $\mathbb{N}^0$ & Set of non-negative integers %($\mathbb{N}^0 = 0, 1, 2, \hdots$)
 & -\\
 $p$ & Pressure & Pa\\
 $r$ & Radius & m\\
 $S$ & Cross-sectional area (brass) & m$^2$\\
 $t$ & Time & s\\
 $T$ & Tension & N (1D)\\
 & & N/m (2D)\\
 $u$ & State variable & m\\
 $v$ & Particle velocity & m/s\\
 $x$ & Spatial dimension & m\\
 $y$ & Spatial dimension (2D) & m\\
 $\gamma$ & Scaled wave speed & s$^{-1}$\\
 $\lambda$ & Courant number for 1D wave eq. ($=ck/h$) & -\\
 $\mu$ & Stiffness \SWcomment[free parameter] & -\\
 $\nu$ & Poisson's ratio & -\\
 $\eta$ & Relative displacement & m\\
 $\rho$ & Material density & kg$\cdot$m$^{-3}$\\
 \\
    \hline {\bf Operations}\\\hline
 \\
 $\mathfrak{I}(\cdot)$ & Imaginary part of &\\
 $\mathfrak{R}(\cdot)$ & Real part of & \\
 $\floor[\cdot]$ & Flooring operation &\\
 $\ceil[\cdot]$ & Ceiling operation &\\
 \\\hline
 {\bf Subscripts}\\\hline
 \\
 $\ctxt$ & Connection &\\
 $\ptxt$ & Plate &\\
 $\stxt$ & String &
\end{longtable}}


\section{Approach}
The task of speaker recognition can be considered as a task of classification. Thus a number of machine learning techniques
can be applied to this task. In general, this task should cover the following three topics:

\begin{enumerate}
  \item Feature Extraction: process the voice signal and extract acoustic features that
	  could describe the acoustic characteristics of speakers, which can be correlated
	  in some extend to model latter used.

  \item Acoustic Model: provide the functionality of registration as well as identification or verification.

  \item Evaluation: Evaluate our approach using datasets with appropriate metrics.
\end{enumerate}

\subsection{Feature Extraction}
The task of speaker recognition is highly correlated to the task of speech recognition.
In the field of speech recognition, Complex Cepstrum \cite{cepstrum} is
considered to be a concise description to the original acoustic signal.
In particular, Mel-frequency Cepstral Coefficients (MFCC), is a state-of-the-art standard feature
widely used in Automatic Speech Recognition (ASR) system.
The general procedure for calculating MFCC is as follows:
\begin{figure}[H]
  \centering
  \includegraphics[width=\textwidth]{res/MFCC.png}
\end{figure}

As for speaker recognition, several different features are suggested and compared
by researchers \cite{evaluation}. Cepstrum still proves to be a robust and effective
feature in this task. Therefore, a bunch of cepstral features, including MFCC,
LPCC (Linear Prediction Cepstrum Coefficients), are commonly used
in speaker recognition system.\cite{feature}

We plan to implement common cepstral features used by researchers, and use a
combination of some of them, according to the further observation and test on how
much they contribute to the task.

\subsection{Model}
According to works in years, Gaussian Mixture Model (GMM)
has been a common approach to acoustic modeling.\cite{GMM}
GMM can be used to acquire an acoustic model $P(\mathbf{O} | \mathbf{W}) $,
which gives the probability of a given observation
$\mathbf{O}$ under certain word $\mathbf{W}$. By using GMM, this
conditional probability can be well estimated by modeling the distribution as
a sum of several normal distribution.

In addition to that, Hidden Markov Model (HMM) is a main-stream approach in ASR system,
since it can describe sequential relation of observations.\cite{SLP}
We have noticed a few research-oriented open-source speech recognition
tool building on HMM, such as HTK\cite{htk}.
Such tools might be quite useful in buiding a speaker recognition system.

Recently, some common machine learning model are also applied to the task of speaker
recognition. \cite{svm} suggested a method of using SVM in speaker recognition.
Deep neural networks are also used in speech processing recently.\cite{deep}

HMM and GMM will probably be our first attempt, as they are already widely used and proven to be
efficient and effective.  We might also try to migrate our extracted feature to
some other available models.

\subsection{Evaluation}
\subsubsection{Dataset}
There are a number of well-known databses for speaker recognition system evaluation,
such as KING speaker verification\cite{king}. \cite{database} gives description on
several common databases. But most of these databases are not free of charge.
We intend to search for an freely available database,
otherwise we have to build some simple test cases by our own.
\subsubsection{Metrics}
As we intend to distinguish different speakers, the primary goal is overall
accuracy of the system we built. Furthermore, the performance may differ from
speaker to speaker, which may provide with additional feedback to our approach.
Thus we shall examine precision, recall and $F_1$ score for each speaker.


\section{Introduction}

In modern mathematical and computer science world, providing a proof is hard, but confirming its correctness
is sometimes not a easy work as well. In November 2015, Babai announced a quasipolynomial
time algorithm for graph isomorphism problem, where Harald Helfgott discovered a flaw.
Though Babai re-announced a correction in 2017, the new proof has not been fully peer-reviewed yet.\par
On the other hand, some famous problems have been solved with the help of computer programs,
for example \href{http://www.ams.org/journals/notices/200811/tx081101382p.pdf}{proving {\it Four Color Theorem} using Coq}.\par
The key idea is that although searching for proofs is an undeciable and unpractical task with respect to the
limited computation power and ability of computer,
checking the validity of a certain proof can be done in computer with the help of type system.\par
In our implementation, using {\it Curry-Howard isomorphism}, programs, properties, and proofs are formalized in the same
language -- {\it Calculus of Inductive Constructions}, which is a $\lambda$-calculus with an enriched type system.


\import{useful.tex}
\chapter{Matma}
\myimport{extended-gcd}
\myimport{crt}
\myimport{floor-sum}
%\myimport{mod-int}
%\myimport{newton}
\myimport{berlekamp-massey}
\myimport{miller-rabin}
\myimport{rho-pollard}
\myimport{fft}
\myimport{fft-mod}
\myimport{fwht}
\myimport{integral}
\myimport{primitive-root}
\myimport{discrete-log}