\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc} %- Løser problem med å skrive andre enn engelske bokstaver f.eks æ,ø,å.
\usepackage[T1]{fontenc} %- Støtter koding av forskjellige fonter.
\usepackage{textcomp} % Støtter bruk av forskjellige fonter som dollartegn, copyright, en kvart, en halv mm, se http://gcp.fcaglp.unlp.edu.ar/_media/integrantes:psantamaria:latex:textcomp.pdf
\usepackage{csquotes}
\usepackage{url} % Gjør internett- og e-mail adresser klikkbare i tex-dokumentet.
\usepackage{hyperref} % Gjør referansene i tex-dokumentet klikkbare, slik at du kommer til referansen i referanselista.
\usepackage[english]{babel} % Ordbok. Hvis man setter norsk i options til usepackage babel kan man bruke norske ord.
\usepackage{amsmath} 				% Ekstra matematikkfunksjoner.
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{mathtools}
\usepackage{geometry}
\usepackage{tikz-cd}
\usepackage{graphicx}
\usepackage{changepage}
\usepackage{subcaption}
\usepackage{placeins}
\usepackage{bm}
\usepackage{physics}
\usepackage{siunitx}					% Må inkluderes for blant annet å få tilgang til kommandoen \SI (korrekte måltall med enheter)
	\sisetup{exponent-product = \cdot}      	% Prikk som multiplikasjonstegn (i steden for kryss).
 	\sisetup{output-decimal-marker  =  {,}} 	% Komma som desimalskilletegn (i steden for punktum).
 	\sisetup{separate-uncertainty = true}   	% Pluss-minus-form på usikkerhet (i steden for parentes).
\usepackage{booktabs} % For å få tilgang til finere linjer (til bruk i tabeller og slikt).
\usepackage[font=small,labelfont=bf]{caption}		% For justering av figurtekst og tabelltekst.
\usepackage[backend=biber]{biblatex}
\addbibresource{./ref.bib}

% math stuff
\newcommand{\restr}[2]{\ensuremath{\left.#1\right|_{#2}}}

% my personal commands
\newcommand{\R}{\mathbb{R}}

%\clearpage % Bruk denne kommandoen dersom du vil ha ny side etter det er satt plass til figuren.
% Disse kommandoene kan gjøre det enklere for LaTeX å plassere figurer og tabeller der du ønsker.
\setcounter{totalnumber}{5}
\renewcommand{\textfraction}{0.05}
\renewcommand{\topfraction}{0.95}
\renewcommand{\bottomfraction}{0.95}
\renewcommand{\floatpagefraction}{0.35}

% math stuff
\newtheorem{theorem}{Theorem}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem*{observation}{Observation}
\newtheorem*{example}{Example}
\newtheorem*{remark}{Remark}

\graphicspath{{../}}

\title{Project for Deep Learning in Scientific Computing}

\author{Alexander Johan Arntzen }

\date{\today}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

\section*{Task 1}
In this task a noisy dataset was provided. Attempts to denoise the data did not produce a better cross validation error, so no denoising was used. All the data was then normalized by min-max normalization.

A feed forward fully connected neural network was chosen to approximate the map. Training was then performed to select the optimal hyperparameters using cross validation error as a selection criterion. The final model was trained 10 times, and the lowest validation error was chosen. The resulting approximation is plotted in Figure \ref{fig:task1}

\begin{figure}[b]
	\begin{subfigure}[b]{0.5\textwidth}
	  \centering
	  \includegraphics[width=\linewidth]{figures/task1/final_tf0.pdf}
	  \caption{$T_f^0$}
	  \label{fig:task1a}
	\end{subfigure}
	\begin{subfigure}[b]{0.5\textwidth}
	  \centering
	  \includegraphics[width=\linewidth]{figures/task1/final_ts0.pdf}
	  \caption{$T_s^0$}
	  \label{fig:task1b}
	\end{subfigure}
	\caption{Training points and approximation made by the model}
	\label{fig:task1}
  \end{figure}

\section*{Task 2}
In this task both the Sobol points and the transformed points were given. By using linear regression, the parameters of the transformation was found. It was then observed that the points used in the finest mesh solutions also existed in the coarser solutions. Thus, it was possible to use the more accurate $CF$ values where they where available. The $CF$ values where then standardized, since they approximated a normal distribution.
Training a feed forward fully connected neural network on the aggregated data gave better results than a multilevel\cite{lye2020multilevel} approach. Ensemble training was then performed to select the optimal hyperparameters using cross validation error as a selection criterion. The final model was trained 10 times, and the lowest validation error was chosen. A plot of the predicted $CF$ values can be found in Figure \ref{fig:task2}
\begin{figure}[ht]
    \centering
    \includegraphics[width=0.8\textwidth]{figures/task2/final.pdf}
    \caption{Comparison between the predicted $CF$ values from the training set and the actual $CF$ values in the training set}
    \label{fig:task2}
\end{figure}

\section*{Task 3}
In this task the temperature data was fist normalized using min-max normalization. The temperature data was then structured so that consecutive temperature measurements are given for each starting time index. The training of the models was then done using the start of these sequences as input and the end as labels to approximate. A feed forward fully connected network was first used, but a network with an LSTM layer performed better on both series of temperatures. Ensemble training was then performed to select the optimal hyperparameters among input length, optimizer, learning rate, regularization and neurons. The final model was trained 5 times, and the lowest validation error was chosen. The predictions for each temperature series can be found in Figure \ref{fig:task3}
\begin{figure}[t]
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\linewidth]{figures/task3/final_tf0.pdf}
    \caption{$T_f^0$}
    \label{fig:task3a}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\textwidth}
    \centering
    \includegraphics[width=\linewidth]{figures/task3/final_ts0.pdf}
    \caption{$T_s^0$}
    \label{fig:task3b}
  \end{subfigure}
  \caption{Training points and predictions by the model}
  \label{fig:task3}
\end{figure}

\section*{Task 4}
In this task the training data $S$ where first normalized to the domain $[0,1]^3$, using min-max scaling. Using the normalized data a feed forward neural network $T^L_{\theta}(t, u)$ was then trained to approximate the map $T^L(t, u)$. The model depends on several hyperparameters including layers, neurons, activation function, optimization algorithm, learning rate, and regularization. The chosen parameters were chosen with ensemble training using cross validation error as a selection criterion.

With a model selected, the noisy data $(T_{f,j}^{L,*}, t_j)_{j=1}^{N}$ was used to define the loss function
\begin{equation}
	G(u) = \sum_{j=0}^{N}{(T_{f,j}^{L,*} - T_{\theta}(t_j,u))^2}.
\end{equation}
The optimization problem was then solved by a line seach algorithm. The resulting data are visualized in Figure \ref{fig:task4}
\begin{figure}[t]
    \centering
    \includegraphics[width=0.8\textwidth]{figures/task4/final.pdf}
    \caption{The figure shows training values colored by $u$ and the predictions made by the chosen model. The noisy measurements are also depicted with a blue line noting the approximated curve $(T,t)$ for the given $u$}
    \label{fig:task4}
\end{figure}

\section*{Task 5}
In this task the control parameters $(v,D)$ in training set $S$ where first normalized to the domain $[0,1]^2$,  with maximum and minimum parameters given as $[2,20]\times[50,400]$. Using the normalized data a feed forward neural network $CF_{\theta}(D, v)$ was then trained to approximate the map $CF(D, v)$. The model depends on several hyperparameters including layers, neurons, activation function, optimization algorithm, learning rate, and regularization. The chosen parameters were chosen with ensemble training using cross validation error as a selection criterion.  The final model was trained 5 times, and the lowest validation error was chosen.

Once a suitable model was selected the loss function
\begin{equation}
	G(D,v) = (CF_{ref}- CF_{\theta}(D,v))^2
\end{equation}
was minimized using SGD with projected gradient 1000 starting points as in the DNNopt\cite{Lye_2021} procedure. The starting points where chosen as the elements in a Sobol sequence in $\R^2$ . The optimization algorithm chosen was SGD with projected gradient. To speed up the optimization, loss was summed over all points, which enabled optimization of all the points simultaneously. The final model was trained 5 times, and the lowest validation error was chosen. The curve of optimal points can be viewed in Figure \ref{fig:task5}

\begin{figure}[t]
    \centering
    \includegraphics[width=0.8\textwidth]{figures/task5/final_optim_points.pdf}
    \caption{Optimal curve of $(D^*,v^*)$ values. The initial Sobol points are also shown with the corresponding $G$ value}
    \label{fig:task5}
\end{figure}

\section*{Appendix}
The code for this project can be found at \url{https://github.com/alexarntzen/deepthermal}

\FloatBarrier
\printbibliography
\end{document}


%\subsection{Search strategy for the resonance analysis: the BumpHunter algorithm}
%\label{sec:searchstrategy}

%The main statistical test employed in the dijet resonance search is based
%on the \BumpHunter\ algorithm~\cite{Aaltonen:2008vt,Choudalakis:2011bh} and
%is used to establish the presence or absence of a resonance in the dijet
%mass spectrum, as described in greater detail in previous
%publications~\cite{EXOT-2010-07,EXOT-2011-07}.
%The algorithm operates on the binned \mjj data, comparing the background estimate with the data in mass intervals of
%varying widths formed by combining neighboring bins. Starting with a two-bin signal window,
%the algorithm scans across the entire distribution,
%then steps through successively larger signal windows up to half of the whole fit range.
%For each point in the scan, it computes the significance of the difference between the data and the background.
%The most significant departure from the smooth spectrum
%(``bump'') is defined by the set of bins that have the smallest probability
%of arising from a Poisson background fluctuation.
%During this procedure, the background model is not changed or refit to the data
%outside of the excluded region.

%The \BumpHunter\ algorithm accounts for the so-called ``look-elsewhere effect''
%~\cite{lyons2008, Gross2010}, by performing a series of pseudo-experiments
%drawn from the background estimate to determine the probability that random
%fluctuations in the background-only hypothesis would create an excess
%anywhere in the spectrum at least as significant as the one observed.
%
%To make practical use of this algorithm, one must ensure the background
%estimate is not biased by the signal.
%Therefore, \BumpHunter\ is run in two steps.  In the first, the full
%distribution is fit and passed to \BumpHunter.
%If the most significant local excess from the background fit has a $p$-value
%smaller than 0.01, this region is excluded and a new background fit is
%performed. The exclusion is then progressively widened bin by bin until
%the $p$-value of the remaining fitted region is acceptable.
%During the 2015 analysis it was found that simply excluding one additional bin on the low mass
%side of the signal window removed most of the residual bias (if any
%did exist).  Then the result of this fit is used for the second
%stage where an unbiased estimate of the global significance of any
%excess is obtained.

Once the background is derived, the BumpHunter algorithm ~\cite{Aaltonen:2008vt,Choudalakis:2011bh} is employed to test the consistency or discrepancy between background and the observed data.
It can locate the local excess above the background and quantifies the degree of discrepancy between the observed data and background, based on the frequentist $p$-value from one of three test statistics: $\chi^{2}$, Log Likelihood and BumpHunter(described below).

%\subsection{Frequentist $p$-value}
%
%In the comparison between observed data and background, if the background comes only from the SM, this is called the background-only hypothesis or null hypothesis, denoted by $H_{0}$. If the null hypothesis is correct, the observed data, denoted $D$, will be the statistical fluctuation of the background. The validity of $H_{0}$ can be tested by determining the probability of obtaining the data spectrum as a fluctuation of the background-only hypothesis.
%
%The frequentist probability is commonly used in high energy physics, which is a statement on the frequency of a certain outcome given a large number $N$ of repeated experiments. The frequentist hypothesis test determines the consistency between $H_{0}$ and the observed experimental outcome $x$ by fixing in advance a value of probability $\alpha$ below which the hypothesis will be rejected as too discrepant. Specifically, if the observation falls in a space of possible outcomes $\omega$ such that
%\begin{equation}
%P(x \in \omega|H_{0}) \leq \alpha
%\end{equation}
%then the null hypothesis $H_{0}$ will be rejected, otherwise the data is consider to be consistent with background.

%Define a test statistic $t$ to be any numerical quantity which describes the compatibility
%between data and background, it usually increases monotonically with decreasing compatibility. The $p$-value of this test statistic is the probability of obtaining a value at least as extreme as the observed $t = t_{0}$ given $H_{0}$:
%\begin{equation}
%p = P(t>t_{0}|H_{0})
%\end{equation}
%where small $p$-value means small consistency between data and background.

\subsection{Test statistic}
Three test statistics are employed in the BumpHunter algorithm to quantify the discrepancy between observed data and background: $\chi^{2}$, Log Likelihood and the BumpHunter. They are represented by a single value which characterises the degree of agreement between the observed data and background and are used in defining $p$-values.

%The $\chi^{2}$ test statistic is defined as the sum in quadrature of the differences
%between observations and expectations, normalised to the variance. For a comparison
%where the observation and prediction are both binned histograms with contents $d_{i}$ and $b_{i}$ in bin $i$:
%\begin{equation}
%\chi^{2} = \sum_{i}\frac{(d_{i}-b_{i})^{2}}{b_{i}}\,.
%\end{equation}
%The "reduced $\chi^{2}$" value is defined as $\chi^{2}/\mathrm{NDF}$, which is often used to test goodness-of-fit, where NDF is the number of degrees of freedom in the fit.

%The Likelihood, $\mathcal{L}$, test statistic is an effective one in comparison of two binned histograms. In comparison of a mass spectrum, each bin content follows the Poisson distribution, so the Log Likelihood is defined as the product of the Poisson probability in each bin
%over all bins:
%\begin{eqnarray}
%\mathcal{L} = \prod_{i}\frac{b_{i}^{d_{i}}e^{-b_{i}}}{d_{i}!}.
%\end{eqnarray}
%The  Negative Log Likelihood (NLL), $-2\ln\mathcal{L}$ is defined as:
%\begin{equation}
%-2\ln\mathcal{L} = -2\ln\prod_{i}\frac{b_{i}^{d_{i}}e^{-b_{i}}}{d_{i}!}.
%\end{equation}

Both $\chi^{2}$ and log likelihood can quantify the discrepancy between the observed data and background in individual bin.
However, in the comparison of two binned spectra, the discrepancy in the window of neighbouring bins is more meaningful.
Several adjacent bins with large excess in each bin indicate new physics, however three bins with a large excess, a large deficit and a large excess may produce the large $\chi^{2}$ and NNL but would be of much less physical interest.

The third test statistic has therefore been defined to quantify the ``bump'' above the background, the ``BumpHunter statistic'', which is the default test statistic in the BumpHunter algorithm.
For a set of adjacent bins, a value $t$ is calculated as the Poisson probability of obtaining a result at least as significant as the one observed, define $d$ as the sum of the data and $b$ as the background in these neighbouring bins:
\begin{equation}
t =
\begin{cases}\displaystyle
\sum_{n=0}^{d}\frac{b^{n}}{n!}e^{-b} \quad \mathrm{for} \quad d<b\,, \\\displaystyle
\sum_{n=d}^{\infty}\frac{b^{n}}{n!}e^{-b} \quad \mathrm{for} \quad d \geq b\,.
\end{cases}
\end{equation}
The above expression can be represented in terms of gamma functions:
\begin{equation}
 t =
\begin{cases}\displaystyle
\Gamma(d+1, b) = 1 - \Gamma(d+1, b) \quad \mathrm{for} \quad d<b\,, \\
\Gamma(d, b) \quad \mathrm{for} \quad d \geq b\,.
\end{cases}
\end{equation}
This value accounts for the direction of neighbouring fluctuations by looking at the
overall excess or deficit in the region.

For every possible window along the mass spectrum, $t$ is calculated. The possible windows are found by looping over all widths between a minimum and a maximum number of bins. The BumpHunter statistic describing the overall spectrum is defined as the negative log of the smallest probability obtained for any window, defined as:
\begin{equation}
t_{0} = -\log t_\mathrm{min}\,.
\end{equation}

Once the test statistic is determined, the $p$-value can be calculated through generating many pseudo-data which can be derived by a randomly draw in each bin from a Poisson distribution with parameter equal to the expected bin content from the background spectrum.
The selected test statistic is then calculated for each pseudo-data.
The fraction of these cases for which the test statistic is more than that in observed data can be easily computed, $p$-value.
The full procedure to calculate the $p$-value obtained from a selected test statistic can be summarised as:
\begin{itemize}
        \item Calculate the value of the test statistic $t_{0}$ which compares background-only hypothesis to observed data, $t_{0}$,
        \item Generate a collection of pseudo-data from background to represent a range of possible experimental outcomes in the case the background-only hypothesis is correct,
        \item Compare each pseudo-data with background to calculate the test statistic value for each pseudo data, $t_{i}$,
        \item Calculate the fraction of $t_{i}$ for which $T > t_{0}$, this fraction is the $p$-value obtained from the test statistic $t$.
\end{itemize}

\subsection{The BumpHunter algorithm}
The BumpHunter algorithm compares the background with the observed data in intervals of varying widths formed by combining neighboring bins.
It scans across the entire distribution with the window width varying from 2 up to half of the number of the bins.
For each window in the scan, it computes the significance of the difference between the observed data and the background.
The most significant departure from the background spectrum is defined by the set of bins that has the smallest probability of arising from a Poisson background fluctuation.
If the measured $p$-value obtained from the BumpHunter statistic is less than 0.01, it may mean the existence of new physics.

As the pseudo-experiments are drawn from the background, the random fluctuations in the background-only hypothesis would create an excess anywhere in the spectrum at least as significant as the one observed, so the BumpHunter algorithm also accounts for the look-elsewhere effect~\cite{lyons2008, Gross2010}.

The $p$-value got in BumpHunter is used to quantify the discrepancy between observed data and background.
The residual in each bin can also been quantified by a $p$-value and described in detail in \cite{Choudalakis:2011bh}.
In each bin, a measured $p$-value is defined as the probability of measuring a discrepancy between data and background at least as large as the one observed.
The $p$-value is then translated into a $z$-value defined as the number of standard deviations to the right of the mean of the normal distribution:
\begin{equation}
p\mathrm{-value} = \int_{z\mathrm{-value}}^{\infty}\frac{}{\sqrt{2\pi}}e^{-\frac{x^{2}}{2}}dx\,.
\end{equation}
Bins with a $z$-value less than zero show no difference of any interest, while those with a $z$-value of more than two or three indicate a significant discrepancy.
For clarity of interpretation, one would like the sign of the $z$-value drawn in residual plots to depend on whether the data falls above or below the hypothesis.
Therefore, in the plots, any bins with a negative $z$-value are set to zero, while those with a positive $z$-value are drawn positive or negative depending on whether an excess or a deficit is observed.


\section{Curl}


\documentclass[14pt,letterpaper]{report}
\usepackage[utf8]{inputenc}
\usepackage[left=1.00in, right=1.00in, top=0.50in, bottom=1.00in]{geometry}

\usepackage{enumitem}

\title{BucketVision “Angry Eyes” NetworkTables \protect\\ Interface Control Document v1.0}
\makeatletter

\begin{document}
	\begin{center}
		{\LARGE \@title}

		{\textit \@date}
	\end{center}

	\section*{Overview}

	The “Angry Eyes” computer vision pipeline detects and determines the position of the dual-slanted retroreflective targets used in the 2019 FRC game. As this software runs on a separate system from the main robot controls, it publishes the position of detected targets through the NetworkTables interface so other systems may act on that data. This document described the format of that data.

	\section*{Configurable Items}

	The top-level table under which all items are published (1 level below root) is passed in as an argument to all of the new pipeline components. In the current test code, this is named BucketVision but a table with any name may be passed in here.

	\noindent Each component of the new pipeline which publishes data in the NetworkTable accepts a parameter for the name, with which it will get or create a table by that name under the top-level table above. In the current test code, this is FrontCamera. While there is no logic to detect differing names, care should be taken to use the same camera name for all relevant components, otherwise data will be published under different tables.

	\section*{Published Data}

	as noted above, these items are all published in a camera table which is in a top-level table

	\begin{itemize}[label={--}]
		\item \textbf{NumTargets} - Number

		An integer number representing the number of targets detected. All the following arrays will be this length, and each index will represent a single target.

		\item \textbf{distance} - Number Array

		The estimated distance (in meters) between the camera and the target. Do not rely on its accuracy, it is calculated crudely.

		$$ \textrm{Average Height}_{px} = \frac{\textrm{Height}_L + \textrm{Height}_R}{2} $$

		$$ \textrm{Height}_{deg} = \frac{\textrm{Average Height}_{px}}{\textrm{Camera px per degree}} $$

		$$ dist = \frac{\textrm{Rectangle Height}}{\textrm{tan}^{-1}(\textrm{Height}_{deg})} $$

		\item \textbf{pos\_x} - Number Array

		The horizontal location of the target in normalized image-space coordinates, from 0 (left) to 1 (right).

		\item \textbf{pos\_y} - Number Array

		The vertical location of the target in normalized image-space coordinates, from 0 (top) to 1 (bottom).

		\item \textbf{size} - Number Array

		The distance between the left and right portions of the target as a fraction of the width of the image.

		\item \textbf{parallax} - Number Array

		Scaled left right difference as a fraction of total height: (negative if camera is right of target)

		$$ \textbf{parallax} = (1000) \frac{Height\_left-Height\_right}{Height\_left+Height\_right} $$

		\item \textbf{angle} - Number Array

		The angle (in radians) between the left and right portions of the target.

	\end{itemize}

\end{document}


    \filetitle{dat2ttrend}{Construct linear time trend from date range}{dates/dat2ttrend}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
[TTrend,BaseDate] = dat2ttrend(Range)
[TTrend,BaseDate] = dat2ttrend(Range,BaseYear)
[TTrend,BaseDate] = dat2ttrend(Range,Obj)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{Range} {[} numeric {]} - Date range from which an integer
  linear time trend will be constructed.
\item
  \texttt{BaseYear} {[} model \textbar{} VAR {]} - Base year that will
  be used to construct the time trend.
\item
  \texttt{Obj} {[} model \textbar{} VAR {]} - Model or VAR object whose
  base year will be used to construct the time trend; if both
  \texttt{BaseYear} and \texttt{Obj} are omitted, the base year from
  \texttt{irisget('baseYear')} will be used.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\item
  \texttt{TTrend} {[} numeric {]} - Integer linear time trend, unique to
  the input date range \texttt{Range} and the base year.
\item
  \texttt{BaseDate} {[} numeric {]} - Base date used to normalize the
  input date range; see Description.
\end{itemize}

\paragraph{Description}\label{description}

For regular date frequencies, the time trend is constructed the
following way. First, a base date is created first period in the base
year of a given frequency. For instance, for a quarterly input range,
\texttt{BaseDate = qq(baseYear,1)}, for a monthly input range,
\texttt{BaseDate == mm(baseYear,1)}, etc. Then, the output trend is an
integer vector normalized to the base date,

\begin{verbatim}
TTrend = floor(Range - BaseDate);
\end{verbatim}

For indeterminate date frequencies, \texttt{BaseDate = 0}, and the
output time trend is simply the input date range.

\paragraph{Example}\label{example}