\section{Policy Gradient Methods}

\subsection{Exercise 13.1}
\subsubsection*{Q}
Use your knowledge of the gridworld and its dynamics to determine an \emph{exact} symbolic expression for the optimal probability of selecting the \texttt{right} action in Example 13.1.

\subsubsection*{A}
Define $p = \P{}(\texttt{right})$, so $\P{}(\texttt{left}) = 1-p$. Then, labelling the states 1-3 from right to left (value of terminal state is set to 0), the Bellman equations reduce to
\begin{align*}
    v_\pi(1) &= p v_\pi(2) - 1\\
    v_\pi(2) &= pv_\pi(1) - 1 + (1-p)v_\pi(3) \\
    v_\pi(3) &= (1-p)v_\pi(2) - 1.
\end{align*}
Setting $f(p)$ for the value of the initial state and solving this system gives
\[
    f(p) = \frac{p^2 - 2p + 2}{p(1-p)}
\]
which attains its maximum at $p = \sqrt{2}(\sqrt{2} - 1)$. (Note that $f$ is defined only on the open interval $(0, 1)$, the performance becomes infinitely bad as $p \to 0, 1$.)

\subsection{*Exercise 13.2}
\subsubsection*{Q}
Generalize the box on page 199, the policy gradient theorem (13.5), the proof of the policy gradient theorem (page 325), and the steps leading to the REINFORCE update equation (13.8), so that (13.8) ends up with a factor of $\gamma^t$ and thus aligns with the general algorithm given in the pseudocode.

\subsubsection*{A}
\begin{itemize}
    \item Generalisation the recursion equation that governs expected time in each state:
    \begin{align*}
        \eta(s) &= h(s) + \gamma \sum_{\bar{s}}\eta(\bar{s}) \sum_a \pi(a \vert{} \bar{s}) p(s \vert{} \bar{s}, a)\\
                &= h(s) + \gamma \sum_{\bar{s}, a}\pi(a \vert{} \bar{s}) p(s \vert{} \bar{s}, a) + \gamma ^2 \sum_{\bar{s}, a}\pi(a \vert{} \bar{s}) p(s \vert{} \bar{s}, a) \sum_{x, a'}\pi(a' \vert{} x) p(\bar{s} \vert{} x, a) + \cdots
    \end{align*}
    This just changes the solution for $\eta(s)$, we still have $\mu(s) = \frac{\eta(s)}{\sum_{s'} \eta(s')}$.
    \item The generalisation of the proof of the policy gradient theorem comes with the use of the Bellman  equation unfolding for the value function. We therefore arrive at the following gradient:
    \[
        \grad_{\vec{\theta}} v_\pi(s) = \sum_{x \in \S{}}\sum_{k = 0}^\infty \P{}(s \to x, k, \pi)\gamma^k\sum_a \grad_{\vec{\theta}} \pi(a \vert{} x) q_\pi(x, a),
    \]
    and the theorem follows as before.
    \item To full incorporate discounting, we need to view it as a form of termination. The policy gradient theorem becomes
    \[
        \grad_{\vec{\theta}} J(\vec{\theta}) = \Epi[\gamma_t \sum_a q_\pi(S_t, a) \grad_{\vec{\theta}} \pi(a \vert{} S_t, \vec{\theta})].
    \]
    The factor of $\gamma^t$ then follows through when we apply SGD. (It's possible to do some rearranging to prove this relation, but it is not done in the book --  a little unclear!)
\end{itemize}

\subsection{Exercise 13.3}
\subsubsection*{Q}
In Section 13.1 we considered policy parameterizations using the soft-max in action preferences (13.2) with linear action preferences (13.3). For this parameterization, prove that the eligibility vector is
\[
    \grad \log \pi(a \vert{} s, \vec{\theta}) = \vec{x}(s, a) - \sum_b \pi(b \vert{} s, \vec{\theta})\vec{x}(s, b)
\]
using the definitions and elementary calculus.

\subsubsection*{A}
Have softmax policy
\[
    \pi(a \vert{} s, \vec{\theta}) = \frac{\exp(h(s, a, \vec{\theta}))}{\sum_b \exp(h(s, a, \vec{\theta}))}
\]
with linear action preferences
\[
    h(s, a, \vec{\theta}) = \vec{\theta}^\top \vec{x}(s, a).
\]
The following is then clear:
\begin{align*}
    \grad_{\vec{\theta}} \log(\pi) &= \vec{x}(s, a) - \frac{\sum_b \vec{x}(s, b) \exp(\vec{\theta}^\top \vec{x}(s, b))}{\sum_b \exp(\vec{\theta}^\top \vec{x}(s, b))} \\
                                   &= \vec{x}(s, a) - \sum_b \vec{x}(s, b) \pi(b \vert{} s, \vec{\theta}).
\end{align*}

\subsection{Exercise 13.4}
\subsubsection*{Q}
Show that for the gaussian policy parameterization (13.19) the eligibility vector has the following two parts:

\begin{align*}
    \grad \log \pi(a \vert{} s, \vec{\theta}_\mu) &= \frac{\grad \pi(a \vert{} s, \vec{\theta}_\mu)}{\pi(a \vert{} s, \vec{\theta})} = \frac{1}{\sigma(s, \vec{\theta})^2} (a - \mu(s, \vec{\theta}))\vec{x}_\mu(s)\text{, and}\\
    \grad \log \pi(a \vert{} s, \vec{\theta}_\sigma) &= \frac{\grad \pi(a \vert{} s, \vec{\theta}_\sigma)}{\pi(a \vert{} s, \vec{\theta})} = \left( \frac{(a - \mu(s, \vec{\theta}))^2}{\sigma(s, \vec{\theta})^2} - 1 \right) \vec{x}_\sigma(s)
\end{align*}

\subsubsection*{A}
Gaussian policy
\[
    \pi(a \vert{} s, \vec{\theta}) = \frac{1}{\sigma(s, \vec{\theta}) \sqrt{2 \pi}} \exp\left( - \frac{(a - \mu(s, \vec{\theta}))^2}{2 \sigma(s, \vec{\theta})^2} \right)
\]
with the models $\mu(s, \vec{\theta}_\mu) = \vec{\theta}_\mu^\top\vec{x}_\mu(s)$ and $\sigma(s, \vec{\theta}_\sigma) = \exp(\vec{\theta}_\sigma^\top\vec{x}_\sigma(s))$. First,
\[
    \log \pi(a \vert{} s, \vec{\theta}) = - \log \sqrt{2 \pi} - \log \sigma - \frac{(a - \mu)^2}{2\sigma^2}
\]
so we have
\[
    \grad_{\vec{\theta}_\mu}\log\pi(a \vert{}s, \theta) = \frac{a - \mu}{\sigma^2}\grad_{\vec{\theta}_\mu}\mu(s, \vec{\theta}_\mu) = \frac{a - \mu}{\sigma^2} \vec{x}_\mu(s)
\]
and
\[
    \grad_{\vec{\theta}_\sigma}\log\pi(a \vert{} s, \vec{\theta}) = - \frac{\grad_{\vec{\theta}_\sigma} \sigma}{\sigma} + \frac{(a - \mu)^2}{\sigma^2}\grad_{\vec{\theta}_\sigma}\sigma = \left( \frac{(a - \mu)^2}{\sigma^2} - 1 \right)\vec{x}_\sigma(s)
\]
because $\grad_{\vec{\theta}_\sigma}\sigma = \vec{x}_\sigma(s) \sigma$.

\subsection{Exercise 13.5}
\subsubsection*{Q}
A \emph{Bernoulli-logistic unit} is a stochastic neuron-like unit used in some ANNs (Section 9.6). Its input at time $t$ is a feature vector $\vec{x}(S_t)$; its output, $A_t$, is a random variable having two values, 0 and 1, with $\text{Pr}\{A_t = 1\} = P_t$ and $\text{Pr}\{A_t = 0\} = 1- P_t$ (the Bernoulli distribution). Let $h(s, 0, \vec{\theta})$ and $h(s, 1, \vec{\theta})$ be the preferences in state $s$ for the unit’s two actions given policy parameter $\vec{\theta}$. Assume that the difference between the action preferences is given by a weighted sum of the unit’s input vector, that is, assume
that $h(s, 1, \vec{\theta}) - h(s, 0, \vec{\theta}) = \vec{\theta}^\top \vec{x}(s)$, where $\vec{\theta}$ is the unit’s weight vector.

\begin{enumerate}[(a)]
    \item Show that if the exponential soft-max distribution (13.2) is used to convert action preferences to policies, then $P_t = \pi(1 \vert{}S_t, \vec{\theta}_t) = 1/(1 + \exp(-\vec{\theta}_t^\top\vec{x}(S_t)))$(the logistic function).
    \item What is the Monte-Carlo REINFORCE update of $\vec{\theta}_t$ to $\vec{\theta}_t$ upon receipt of return $G_t$?
    \item Express the eligibility $\grad\log\pi(a\vert{}s,\vec{\theta})$ for a Bernoulli-logistic unit, in terms of $a$, $\vec{x}(s)$ and $\pi(a \vert{} s, \vec{\theta})$ by calculating the gradient.
\end{enumerate}

Hint: separately for each action compute the derivative of the logarithm first with respect to $P_t = \pi(1 \vert{}S_t, \vec{\theta}_t)$, combine the two results into one expression that depends on $a$ and $P_t$, and then use the chain rule, noting that the derivative of the logistic function $f(x)$ is $f(x)(1 - f(x))$.

\subsubsection*{A}

\begin{enumerate}[a)]
    \item $\pi(1 \vert{} S_t, \vec{\theta}_t) = e^{h(s, 1, \vec{\theta}_t)} / (e^{h(s, 1, \vec{\theta}_t)} + e^{h(s, 0, \vec{\theta}_t)}) = 1 /(1 + e^{-\vec{\theta}^\top\vec{x}(s)}) $
    \item $\vec{\theta}_{t+1} = \vec{\theta}_t + \alpha \gamma^t G_t \grad_{\vec{\theta}_t}\log\pi(a \vert{} S_t, \vec{\theta}_t)$
    \item Write $\pi(a \vert{} S_t, \vec{\theta}_t) = g((-1)^a \vec{\theta}_t^\top\vec{x}(s))$ where $a \in \{ 0, 1\}$ and $g$ is the sigmoid function $g(t) = 1 / (1 + e^{-t})$. It's then quite easy to see that
    \[
        \frac{\d{}}{\d{} t} \log g(t) = 1 - g(t)
    \]
    which leads to
    \[
        \grad_{\vec{\theta}} \pi(a \vert{} s, \vec{\theta}) = (-1)^a \vec{x}(s) (1 - \pi(a \vert{} s, \vec{\theta})).
    \]
\end{enumerate}


\section{Exercise solutions: control flow} % (fold)
\label{sec:exercise_solutions_control_flow}

\begin{frame}\frametitle{For loops}
    \framesubtitle{Problem}

    Print the numbers 1 to 100 that are divisible by 5 but not by 3

\end{frame}

\begin{frame}\frametitle{For loops}
    \framesubtitle{Solution}

    \codeblock{code/exsol_control_for.py}

\end{frame}

\begin{frame}\frametitle{While loops}
    \framesubtitle{Exercise}

    The smallest number that is divisible by 2, 3 and 4 is 12.
    Find the smallest number that is divisible by all integers between 1 and 10.

\end{frame}

\begin{frame}\frametitle{While loop}
    \framesubtitle{Solution}

    \codeblock{code/exsol_control_while.py}

\end{frame}

\begin{frame}\frametitle{Collatz sequence}
    \framesubtitle{Problem}

    A Collatz sequence is formed as follows:
    We start with some number $x_0$, and we find the next number in the sequence by
    \[
        x_{i+1} = \begin{cases}
            x_i / 2 & \text{ if $x_i$ is even}\\
            3x_i + 1 & \text{ if $x_i$ is odd}
        \end{cases}
    \]
    If $x_i = 1$, we stop iterating and have found the full sequence.

    It is conjectured, though not proven, that every chain eventually ends at $1$.

    Print the Collatz sequence starting at $x_0 = 103$.

\end{frame}

\begin{frame}\frametitle{Collatz sequence}
    \framesubtitle{Solution}

    \codeblock{code/exsol_control_collatz.py}

\end{frame}

% section exercise_solutions_control_flow (end)


% !TeX root = index.tex
\section{High School Arithmetic}
We will consider addition in the group $\bbz/100$. Denote the elements of $\bbz/100$ by $\tens{a}\units{b}$ where $a,b \in \set {0, 1, \dots, 9}$.

\subsection{The carry function}
\begin{mdframed}
  \adjustbox{scale=1,center}{%
    \begin{tikzcd}
      &\mbox{Adding 2-digit numbers}
        \ar[ddddl, leftrightarrow]
        % \ar[ddddr, leftrightarrow, end anchor={[xshift=0ex]}]
        &
      \\\\\\\\
      \mbox{2-cocycle condition}
      % \ar[rr, dashed, leftrightarrow]
      & & \text{\color{white} Group extensions}
    \end{tikzcd}
  }
\end{mdframed}

Addition in $\bbz/100$ is defined by the formula
\begin{equation}
  \label{equation:additionFormula}
  \tens{a_1}\units{b_1} + \tens{a_2}\units{b_2}
  =
  \tens{a_1 + a_2 + c(b_1, b_2)}\units{b_1 + b_2}
\end{equation}
where $c: \bbz/10 \times \bbz/10 \rightarrow \bbz/10$ is the ``carry'' function

\begin{qbox}
  Give an explicit definition of the carry function $c$.
\end{qbox}

\begin{qbox}
  Is $c$ a group homomorphism?
\end{qbox}

The binary operation on abelian groups satisfies the following three properties:
\begin{enumerate}
  \item identity: $\qquad x + 0 = x = 0 + x$,
  \item commutativity: $\qquad x+y = y+x$,
  \item associativity: $\qquad (x+y)+z = x + (y+z)$.
\end{enumerate}

\begin{qbox}
  Using Equation \eqref{equation:additionFormula} and the fact that $\bbz/100$ is an abelian group, determine the corresponding identities the function $c$ satisfies?
\end{qbox}
Such a function $c$ has a very fancy name, it is called a
\begin{align*}
  \underbrace{\mathrm{normalized}}_{\mathrm{identity}}
  \underbrace{\mathrm{symmetric}}_{\mathrm{commutativity}}
  \underbrace{\mathrm{2-cocycle}}_{\mathrm{associativity}}.
\end{align*}

\begin{qbox}
  \label{q:cocycleDefinesGroup}
  Conversely, show that if a function $c: \bbz/10 \times \bbz/10 \rightarrow \bbz/10$ is a normalized, symmetric, 2-cocycle then ``defining'' an addition on $\bbz/100$ using Equation \ref{equation:additionFormula} defines an abelian group structure on it.\hint{The only new thing you need to check is that inverses exist.}
\end{qbox}

% \begin{qbox}
%    Let $0 \le k < 10$ be an integer. Check that \begin{align*}
%     c_k: \bbz/10 \times \bbz/10 &\rightarrow \bbz/10\\
%     c_k(b_1,b_2) &=
%       \begin{cases}
%         0 & \mbox{if } b_1 + b_2 < 10, \\
%         k & \mbox{if } b_1 + b_2 \ge 10.
%       \end{cases}
%   \end{align*} is also a normalized symmetric 2-cocycle.
% \end{qbox}

% Let $N_k = \set{ \tens{a} \units{b}}$ be the set of two-digit numbers with addition defined as
% \begin{align*}
%   +_k: N_k \times N_k
%     &\longrightarrow N_k, \\
%   \tens{a_1}\units{b_1} +_k \tens{a_2}\units{b_2}
%     &=
%     \tens{a_1 + a_2 + c_k(b_1, b_2)}\units{b_1 + b_2}.
% \end{align*}
%
% By Q.\ref{q:cocycleDefinesGroup}, $(N_k, +_k)$ is an abelian group.

Using 2-cocycles, it is possible to create some very exotic ``carry functions''.
\begin{qbox}
  \label{q:symmetricCocycles}
  Come up with other examples of normalized, symmetric, 2-cocycles $c:\bbz/10 \times \bbz/10 \rightarrow \bbz/10$.
\end{qbox}

There are exactly 4 isomorphism classes of abelian groups of order 100:
  \begin{equation*}
    \bbz/100,\quad \bbz/50 \times \bbz/2, \quad \bbz/20 \times \bbz/5, \quad \bbz/10 \times \bbz/10.
  \end{equation*}

\begin{qbox}
  Each of the examples of carry functions $c$ you found in Q.\ref{q:symmetricCocycles} defines an abelian group structure on the set of 2-digit numbers. Find its isomorphism class.
\end{qbox}

\begin{qbox}[Bonus Question]
  Can you find all the normalized, symmetric, 2-cocycles $c:\bbz/10 \times \bbz/10 \rightarrow \bbz/10$? (I do not know any way to answer this question without using group cohomology computations. It would be amazing if you could solve this problem by some elementary methods.)
\end{qbox}


\section{Discrete Wavelet Transform}

\subsection{One dimensional DWT}

\begin{figure}
    \centering
    \includegraphics[scale=0.5]{dwt_1d_anal_synth.png}
    \caption{1-D DWT, two-band wavelet analysis and synthesis filter banks \cite{jpeg_suite}}
    \label{fig:dwt_1d_anal_synth}
\end{figure}

The linear convolution (filtering) of sequences $x(n)$ and $h(n)$ is defined as in equation \ref{eq:convolution}:
\begin{equation}
    y(n)=\sum_{m=-\infty}^{\infty}x(m)h(n-m)
\label{eq:convolution}
\end{equation}
The one dimensional discrete wavelet transform can be depicted as successive applications (convolutions) of
one selected pair of high and low-pass filters. The output of such application is then followed
by downsampling by the factor of two. For example, it can be achieved by discarding samples with
odd indices after each of filtering operation. It is better visualized in the Figure \ref{fig:dwt_1d_anal_synth} \cite{jpeg_suite}.
The pair of low and high-pass filters is known as analysis filter bank in the encoding process.
In the signal decoding process it is featured as a synthesis filter bank. The decoding step requires
using the inverse of discrete wavelet transform.

Take into consideration a one dimensional signal $x(n) = \{55, 234, 70, 21, 88, 37\}$. It can be better
understood as values of pixels in a part of the grayscale image row. It is followed with a pair of low
and high-pass filters designated by $h_{0}(n)$ and $h_{1}(n)$ respectively. An example of such pair is
a lowpass filter $h_{0}(n) = \{-1, 2, 6, 2, -1\}/8$ and a high-pass filter $h_{1}(n) = \{-1, 2, -1\}/2$. They are both
symmetric and consist of only integer operations. Such pair can be presented in the notation of (5, 3) filter bank.
This convention indicates that the length of lowpass filter is five and the length of high-pass filter is three.
In fact the analysis filter bank presented here was firstly proposed by LeGall and Tabatabai in 1988 and
is used in the JPEG 2000 standard for lossless compression of images. The filtering operation has to
be defined at the signal boundaries. Therefore, the one dimensional signal is extended in both directions.
The Part 1 of the JPEG 2000 standard requires symmetrical extension to be performed in such case \cite{jpeg_suite}.
After applying the required symmetrical padding the signal is extended to
$x(n) = \{21, 70, 234, 55, 55, 234, 70, 21, 88, 37, 37, 88, 21, 70\}$. Then, the low-pass filter is applied
resulting in $x'_{0}(n) = \{197.25, 75.5, 98.375, 67.125, 45.375\}$ and the high-pass one which results in
$x'_{1}(n) = \{44.75, -85.75, 29, 12.75, -29.5\}$.

\begin{figure}
    \centering
    \includegraphics[scale=0.45]{dwt_1d_2_level.png}
    \caption{Computation of a 2-level 4-point DWT using a two-stage two-channel Haar analysis filter bank \cite{dwt_impl}}
    \label{fig:dwt_1d_2_level}
\end{figure}

The next example shows how to compute the two levels of discrete wavelet transform. To speed up the process
no padding option is chosen this time which makes it non-compliant with the JPEG 2000 standard.
The filter used here is the most basic one, i.e. Haar analysis filter bank. It is the first wavelet
from the Daubechies wavelet family. The calculation process is visualized in the Figure \ref{fig:dwt_1d_2_level} \cite{dwt_impl}.

The input is chosen as 4-point signal $X_{\phi}(2, k) = \{2, 1, 3, 4\}$. This notation emphasizes the fact
that it is approximation of the input at scale 2. The so called scaling coefficients (or in other term
approximation at scale 1) $X_{\phi}(1, k)$ are computed by convolving the input $x(k)$ with the low-pass
Haar filter impulse response $l(k) = \{1/\sqrt{2}, 1/\sqrt{2}\}$. In the next step there is downsampling
by a factor of 2 applied. The output of convolution has five values. The middle three from these fives
correspond to cases where both the given input values overlap with the impulse response. As it was described
earlier, the odd values are preserved in the downsampling process. In a result first and third value of these
three middle ones are the approximation output $X_{\phi}(1, k)$. In the similar way, the detail coefficients
at scale 1 $X_{\psi}(1, k)$ are computed. The input $x(k)$ is convolved with the high-pass filter impulse
response $h(k) = \{-1/\sqrt{2}, 1/\sqrt{2}\}$. Then the downsampling by factor of 2 is performed.
Note that only only approximation output $X_{\phi}(1, k)$ of the first stage goes to the second one.
The $X_{\phi}(0, 0)$ and $X_{\psi}(0, 0)$ are calculated accordingly at the end of the second stage \cite{dwt_impl}.

\subsection{Two dimensional DWT}

The idea of using lowpass filter is the preservation of low frequencies of a signal while trying
to eliminate or at least attenuate the high frequencies. In a result the output signal is the blurred
version of the original one. Therefore, the operating principle of the high-pass filter is completely
opposite. As a result of applying such filter, the high frequencies of the signal are preserved and
the low ones are discarded or at least diminished. The output is a signal consisting of edges, textures
and other details \cite{jpeg_suite}.

\begin{figure}
    \centering
    \includegraphics[scale=0.7]{dwt_2d_example_wiki.png}
    \caption{2D DWT applied 2 times to an exemplary image \cite{dwt_example_wiki}}
    \label{fig:dwt_2d_example_wiki}
\end{figure}

There is presented an example of the effects of the two dimensional discrete wavelet transform on the Figure \ref{fig:dwt_2d_example_wiki}.
The DWT used here is compliant with the Part 1 of the JPEG2000 standard. The number of DWT stages presented in this
example is equal to two. Two dimensional discrete wavelet transform applied first time to the original image
yields four same sized sub-images. The LL layer (upper left sub-image) is an approximation of the image and contains the low frequencies.
This layer is once more transformed in the next stage. The LH layer (upper right sub-image) preserves high frequencies from the rows of the image.
As a result vertical lines and details (brightness) can be seen in the produced sub-image. On the other hand, the HL layer (bottom left)
contains high frequencies from the columns of the image. The horizontal details and lines can be noticed there.
Lastly, the HH layer (bottom right) preserves the diagonal lines \cite{dwt_example_wiki}.

\begin{figure}
    \centering
    \includegraphics[scale=0.45]{dwt_2d_1_level.png}
    \caption{Computation of a 1-level 4 $\times$ 4 2-D Haar DWT using a two-stage filter bank \cite{dwt_impl}}
    \label{fig:dwt_2d_1_level}
\end{figure}

The process of computing a 1 level two dimensional discrete wavelet transform with usage of
two-stage analysis Haar filter bank is shown in Figure \ref{fig:dwt_2d_1_level}. Coefficients $\mathbf{X}_{\phi}$
are calculated as a result of lowpass filtering and downsampling to each row of the two dimensional
data. Next, similar process process, i.e. lowpass convolution and downsampling is applied to each column of
resulting data. The rest of coefficients is obtained in very similar fashion to the previous ones.
Coefficients $\mathbf{X}^{H}_{\psi}$ are calculated by applying high-pass filtering and downsampling to each row of the
2-D data $\mathbf{x}$ and then followed by applying sequence of low-pass filtering and downsampling to each
column of the resulting data. Coefficients $\mathbf{X}^{V}_{\psi}$ are obtained by applying low-pass filtering
and then downsampling to each column of the resulting data. Lastly, coefficients $\mathbf{X}^{D}_{\psi}$ are
obtained by applying high-pass filtering and downsampling to each row of the 2-D data $\mathbf{x}$ followed by
applying high-pass filtering and downsampling to each column of the resulting data. In the next stage of more
complex DWT calculating process only the coefficients $\mathbf{X}_{\phi}$ are taken into consideration \cite{dwt_impl}.

\subsection{DWT features summary}

\begin{itemize}
    \item In a nutshell, the discrete wavelet transform is a set of bandpass filters. Usually it is implemented
    with the usage of low and high-pass filters recursively.
    \item The computational complexity of computing the DWT in the best case is linear, i.e. $O(N)$.
    \item The first approach to implement the DWT efficiently is evaluation of the required convolutions
    with the usage of the polyphase filter structure.
    \item The second approach is factorization of the polyphase matrix into a product of a set of sparse matrices.
    \item The two dimensional discrete wavelet transform (with separable filters) is usually computed by the row-column method.
    One dimensional DWT of all the columns is computed at first. Then the 1-D DWT of all the resulting
    rows is calculated. The order of the computation in the row-column method can be swapped. The result remains the same.
    \item Additional memory of approximate half the size of the given data is required in the some implementations of the DWT.
    However, there also exist methods of computing DWT in-place which do not require additional memory.
    \item Data reordering is required for an in-place computation of the DWT.
    \item Data expansion problem can occur due to the finite length of the data in the implementation of the asymmetric filters.
    \item Symmetric filters provide linear phase response and an effective solution to the border problem \cite{dwt_impl}.
\end{itemize}

\section{Part 2 of the JPEG 2000} \label{sec:part2_jpeg2000}

% Part2 in details
% write down different filters and basic ones

\subsection{Introduction}

Many ideas have been emerging as the JPEG 2000 was developed. These concept were full of
value-added capabilities. However, they were not that important to be gone through the time-consuming
ISO standardization process. The Part 1 (ISO/IEC, 2004a) of the standard, i.e. Core coding system,
was originally published in 2000. There was a need to create additional parts to include
missing features. The Part 2 of the standard, published as ISO/IEC 15444-2 or ITU Recommendation
T.801 (ISO/IEC, 2004b), contains multiple such extensions. There is present group of rather small
additions that could not merit entire documents of their own. In the Part 1 Core of JPEG 2000
standard decoders are supposed to handle all of the code-stream functionality. The Part 2
is different from first one in this aspect. It is a collection of options that can be
implemented on demand to meet very specific requirements of the given market. Moreover,
sections within an extension annex can be implemented separately. For example, subsets
of extended file format JPX can be used on their own. Therefore, some features of the Part 2
may be present in the wide spectrum of JPEG 2000 applications while the other ones can be
less common in the decoders \cite{jpeg_suite}.

As it was shown in the previous paragraph, the extensions present in the Part 2 consist of
very different set of topics that can modify or add some features to the Part 1 JPEG 2000 compliant
processing chain. Some tools can result in the compression efficiency improvement. Others can
ameliorate the visual appearance of compressed images. Another group of extensions can modify
or extend some functionalities in the other ways. The list of the major topics is presented below \cite{jpeg_suite}.
\newline \newline Compression efficiency:
\begin{itemize}
    \item Variable DC offset (VDCO) - Annex B
    \item Variable scalar quantization (VSQ) - Annex C
    \item Trellis coded quantization (TCQ) - Annex D
    \item Extended visual masking - Annex E
    \item Arbitrary wavelet decomposition - Annex F
    \item Arbitrary wavelet transform kernel - Annexes G and H
    \item Multiple component transform - Annex J
    \item Nonlinear point transform - Annex K \cite{jpeg_suite}
\end{itemize}
\hfill \break Functionalities:
\begin{itemize}
    \item Geometric manipulation - Annex I
    \item Single-sample overlap (SSO/TSSO) - Annex I
    \item Precinct-dependent quantization - Amendment 1
    \item Extended region of interest - Annex L
    \item Extended file format/metadata (JPX) - Annexes M and N
    \item Extended capabilities signaling - Amendment 2 \cite{jpeg_suite}
\end{itemize}

\subsection{Arbitrary Decomposition} \label{sec:arbitrary_decomposition}

In the Part 1 of the JPEG 2000 standard there is only one wavelet decomposition structure allowed.
This wavelet is called Mallat dyadic decomposition. Such decomposition is a good first choice
to be applied across a wide spectrum of images. However, other ones can improve the quality of the image
over specialized classes of the applications. The other effect of applying such decompositions are
unequal reductions in the horizontal and vertical dimensional of reduced resolution extracts \cite{jpeg_suite}.

\begin{figure}
    \centering
    \includegraphics[scale=0.45]{part_2_decomp_examples.png}
    \caption{Some examples of decomposition compliant with the Part 2 \cite{jpeg_suite}}
    \label{fig:part_2_decomp_examples}
\end{figure}

Other decomposition styles can be found in the wavelet literature. They include the full packet
tree processing and some of its derivatives. The applied packet decomposition derivatives
can outperform the solution from Part 1 of the JPEG 2000 standard in some applications.
For instance, they come crucial at maintaining regular fine-grain texture. Moreover,
the applications that require processing synthetic aperture radar images can benefit
from using this extension. The US Federal Bureau of Investigation actively uses a 500 ppi
fingerprint compression standard, i.e. WSQ (CJIS, 1997). The decomposition is specialized
for the characteristics of fingerprint imagery at 500 dpi \cite{jpeg_suite}.

Some of these decomposition can be seen of the Figure \ref{fig:part_2_decomp_examples}.
Resolution decomposition is depicted as solid lines. Dashed lines represent extra sublevel
decomposition. On the first example, i.e. image $(a)$, there is available full packet decomposition
with such parameters: NL = 3: Ddfs = 111, Doads = 321, Dsads = all 1s. The next picture
illustrates FBI decomposition wit specified parameters: NL = 5: Ddfs = 11111, Doads = 2321,
Dsads = 11101111111111111. The last image is juts an arbitrary example \cite{jpeg_suite}.

The prespecified decomposition structures are not the only feature of this extension.
Wavelet packet analysis can be also used to design custom decompositions for specific images
or some types of images. It was implemented in these papers \cite{entropy_algos},
\cite{wavelet_packet} and \cite{adaptive_wavelet}. Such applications often start with
a large decomposition tree. Then, they tend to locate a good decomposition based upon
specified optimization metric \cite{jpeg_suite}.

\subsection{Arbitrary Wavelet Transforms} \label{sec:arbitrary_wavelet_transform}

\begin{table}
    \centering
    \caption{Analysis and synthesis filter taps for the floating-point Daubechies (9, 7) filter bank}
    \label{tab:anal_synth_97i}
\begin{tabular}{ccc}
    \toprule
    n         & Low-pass, $h_{0}(n)$ & Low-pass, $g_{0}(n)$ \\
    \midrule
    $0$       & +0.602949018236360  & +1.115087052457000  \\
    $\pm 1$   & +0.266864118442875  & +0.591271763114250  \\
    $\pm 2$   & -0.078223266528990  & -0.057543526228500  \\
    $\pm 3$   & -0.016864118442875  & -0.091271763114250  \\
    $\pm 4$   & +0.026748757410810  &                     \\
    \bottomrule
\end{tabular}

\bigskip
\bigskip

\begin{tabular}{cc}
    \toprule
    n         & High-pass, $h_{1}(n)$ \\
    \midrule
    $-1$      & +1.115087052457000   \\
    $-2, 0$   & -0.591271763114250   \\
    $-3, 1$   & -0.057543526228500   \\
    $-4, 2$   & +0.091271763114250   \\
              &                      \\
    \bottomrule
\end{tabular}
\quad
\begin{tabular}{cc}
    \toprule
    n        & High-pass, $g_{1}(n)$ \\
    \midrule
    $1$      & +0.602949018236360   \\
    $0, 2$   & -0.266864118442875   \\
    $-1, 3$  & -0.078223266528990   \\
    $-2, 4$  & +0.016864118442875   \\
    $-3, 5$  & +0.026748757410810   \\
    \bottomrule
\end{tabular}
\end{table}

\begin{table}
    \centering
    \caption{Analysis and synthesis filter taps for the integer (5, 3) filter bank}
    \label{tab:anal_synth_53r}
\begin{tabular}{ccc}
    \toprule
    n         & Low-pass, $h_{0}(n)$ & Low-pass, $g_{0}(n)$ \\
    \midrule
    $0$       & +0.75  & +1    \\
    $\pm 1$   & +0.25  & +0.5  \\
    $\pm 2$   & -0.125 &       \\
    \bottomrule
\end{tabular}

\bigskip
\bigskip

\begin{tabular}{cc}
    \toprule
    n         & High-pass, $h_{1}(n)$ \\
    \midrule
    $-1$      & +1   \\
    $-2, 0$   & -0.5 \\
              &      \\
    \bottomrule
\end{tabular}
\quad
\begin{tabular}{cc}
    \toprule
    n        & High-pass, $g_{1}(n)$ \\
    \midrule
    $1$      & +0.75  \\
    $0, 2$   & -0.25  \\
    $-1, 3$  & -0.125 \\
    \bottomrule
\end{tabular}
\end{table}

The Part 1 of the JPEG 2000 standard specifies only two possible wavelet transforms.
The reversible one (5-3R, Table \ref{tab:anal_synth_53r}) and the irreversible one
(9-7I, Table \ref{tab:anal_synth_97i}). As it was stated before, both
are required to perform periodic symmetric signal extension at the boundaries.
It is similar case to the Mallat dyadic decomposition in terms of generic implementation.
These filters can compress quite well a wide set of image types. However, certain image
classes can be compressed more efficiently with other types of wavelets. Such a flexibility
is allowed in the Part 2 compliant applications. The range of wavelet transforms is broadened
to include not only the wider range of whole-sample symmetric ones but also half-sample and
generic nonsymmetric ones. Such ability to handle generic filters makes JPEG 2000 standard
a powerful research tool, together with supporting more than niche compression applications \cite{jpeg_suite}.

\section{Parallelism in computer architecture}

The parallelism as general term can be simply understood as two or more separate activities
that appear to happen at the same time. It is not only computer science specific abstraction
but also natural part of life. For instance a person can drive a car and simultaneously
talk on the phone or one person can have a walk, while the other one is riding bike.
However, the computer science aspect of parallelism is the interesting part in this paper.
It can be depicted as single system performing multiple independent tasks at the same time
rather than one after the other \cite{cpp_concurrency}. Multitasking operating systems have been
in usage for many years. However, running multiple applications was firstly done only by context switching.
The situation has been a little bit different in the server industry. High-end machines with multiple processors
have been available there for years making utilization of the real parallelism possible.
In recent years there is observed increase of personal computers capable of running multiple tasks
in similar manner \cite{cpp_concurrency}.

Nowadays, there is a trend in producing increasing amount of processors in multicore solutions by chip manufacturers.
There can be found 16 or even more processor cores on a single chip. Following this way is easier
for improving performance over strengthening single core solutions. Therefore, multicore desktop
computers and even embedded devices are growing share in the market. In the past, it was possible
for programmers to get their application run faster without doing anything. Such situation
was linked with the growing computation power within new generation for single core solutions.
The situation is quite different at the present time. If a software has to take advantage of
increasing computing power, one has to design and utilize concurrent run of multiple tasks \cite{cpp_concurrency}.

There are two approaches of utilizing concurrency in terms of performance. The most obvious one
is just to divide a single task into separate parts. Then, such subtasks can be run in parallel
reducing the total execution time of the program. This approach is called ``task parallelism''.
Despite sounding rather straightforward, such operation can become a complex process.
Especially whether there exist many dependencies between the separated parts. Such division
can be applied in two different ways. The first one is connected with processing, i.e.
one thread executes certain part of the given algorithm while the other ones perform operations
at the different part. The other way is connected strictly with the data. Each thread
performs the same operation on different parts of the given data. The latter approach is called
data level parallelism \cite{cpp_concurrency}.

There exists quite notable subgroup of algorithms which are basically ready to be parallelized.
They are often referred as ``embarrassingly parallel'', ``naturally parallel'' or
``conveniently concurrent'' \cite{cpp_concurrency}. Such algorithms are especially good in terms
of scalability properties. As the number of available hardware resources, i.e. threads
increases, the parallelism level in the algorithm is trivial to match. However, if there exist
parts of the algorithm which are not easy to parallelize, one has to divide the algorithm
into a fixed number of tasks. Therefore such application becomes not scalable one \cite{cpp_concurrency}.

The another way to use parallelism for improving performance is to employ existing concurrent
solutions to solve bigger issues. This approach can be depicted as processing 2, 5 or 10 files at
given time instead of just one. Although it seems like another application of data level parallelism,
there is different focus in performing such operation on sets of data concurrently.
The amount of time needed to process one chunk of data is still the same. However, more data
can be processed in the same amount of time. Unfortunately, there are limits on this specific
approach as well. Moreover, there are cases where such attitude can be nonbeneficial at all.
In the end, the increase in throughput which comes from this specific approach makes
new things possible, e.g. increased resolution in video processing where different areas
of the picture can be processed at the same time \cite{cpp_concurrency}.

\section{Known solutions}

\subsection{Part 1 compliant applications} \label{sec:part_1}

There are multiple solutions that implement features from the Part 1 of the JPEG 2000 standard.
The OpenJPEG library is an example of such application. It is open-source solution developed to
promote wider usage of this standard. The main part of this project is the codec compliant with
the Part 1 of the JPEG 2000 standard. Moreover, the OpenJPEG library integrates other parts
of the standard \cite{jpeg_suite}. Few of them can be seen on the list below:

\begin{itemize}
    \item from the Part 2: handling the JP2 boxes and extended multiple component
    transforms for multi and hyperspectral imagery.
    \item from the Part 3: MJ2 (Motion JPEG 2000).
    \item from the Part 11: JPWL (JPEG 2000 Wireless).
    \item OPJViewer, a GUI based tool for visualization of the J2K (extension used for storing
    code-stream JPEG 2000 data), JP2 (standard JPEG 2000 file extension), JPWL and MJ2 files.
    \item OPJIndexer, a code-stream indexer to view information about the headers and packets localization.
    This tool is also capable of reading the rate-distortion contribution of each packet to the image \cite{jpeg_suite}.
\end{itemize}

The OpenJPEG library is written in the C programming language and released under the BSD license.
The main targets of this software are desktop platforms, i.e. Win32, Unix and Mac OS platforms.
The Communications and Remote Sensing Lab (TELE) of the Catholic University of Louvain (UCL)
is the main developer group of this library. CS company and CNES is the supporting side.
Some of the modules are maintained by the Digital Signal Processing Lab (DSPLab) of the University
of Perugia, mainly the JPWL and OPJViewer. \cite{jpeg_suite}.

Another example of Part 1 compliant application is the JasPer. This computer software project is aimed
to create reference implementation of the standard codec. The project was started by the Image Power Inc.
and the University of British Columbia back in the 1997. As OpenJPEG JasPer is written in the C programming language.
There are some sample applications available in the codebase. They can come in handy while testing the codec.
JasPer is currently released publicly under the MIT license. The library is a component of several notable
software projects. It includes but is not limited to netpbm, ImageMagick and KDE. In series of the JPEG 2000
compression tests conducted in 2004 JasPer turned out to be the top performing solution, closely followed by
IrfanView and Kakadu. The disadvantage of this implementation is its time performance. In the same tests
JasPer was the slowest software. However, it is a feature as this codec was designed to be used as reference
in non performance-critical systems.

There is one more notable implementation of the Part 1, i.e. Grok. It is open-sourced software released under
the GNU Affero General Public License (AGPL) version 3 license. Its design aims to provide stable, high
performant and low memory using solution. The function responsible for decoding process (grk\_decompress)
is currently over 0.5 the speed of the Kakadu software. Moreover, Grok supports fast sub-tile decoding
to standard output for png, jpeg, bmp, pnm and raw formats. This library supports both TLM and PLT code stream markers
for fast single-tile and sub-tile decoding of large tiled images. The support of meta-data formats such as
XML, IPTC, XMP and ICC profiles is also included. There is also initial version of Part 15 implementation
(High Throughput JPEG 2000) available. The final version of this solution should be ten times faster over
the original Part 1 of the JPEG 2000 standard.

\subsection{Kakadu} \label{sec:kakadu}

Kakadu is not only a complete implementation of the JPEG 2000 standard Part 1 but also an application
that supports Part 2 and Part 3 in a significant amount of features. The software was originally developed
by David Taubman of the University of New South Wales (UNSW) in Australia. The author is also noticeably
known for being the designer of EBCOT, i.e. the core coding component of JPEG 2000. The name of this library
comes from ``Kakadu National Park'' which is located in the Northern Territory of Australia \cite{jpeg_suite}. Licensing
is more advanced in comparison to solutions mentioned in \fullref{sec:part_1}. There are separate licensing
schemes for research, commercial and demonstration-only applications.

The Kakadu software framework is widely adopted in the substantial range of JPEG 2000 products. The few examples
are Apple's Quicktime v6 for MAC, Yahoo's Messenger, Google Earth and Internet Archive \cite{jpeg_suite}.
Features that can be realized thanks to Kakadu's implementation by the named beforehand solutions include live video
and products for geospatial imagery such as MicroImages TNT. Moreover, this framework is used in medical imaging applications,
interactive image rendering applications, remote browsing of large collection and images, digital cinema applications
and the other fields that require compression and decompression of JPEG 2000 images and videos \cite{jpeg_suite}.

Kakadu is considered as a comprehensive, heavily optimized and fully compliant software toolkit for JPEG 2000
developers. There are multiple features available that make runtime execution so flawless. Multithreaded
processing is supported in such way that makes the most of parallel processing resources, i.e. multiple CPUS,
multicore CPUs and hyperthreading \cite{jpeg_suite}. Compiler intrinsic functions are utilized to manually
vectorize processing of data in processor's pipeline. Moreover, Kakadu comes with built-in thread scheduler.
Such implementation enables possibility of utilizing all computational resources close to 100\%.
In a 2007 the JasPer library was outperformed by Kakadu in terms of speed.

Supported features of Part 2 include arbitrary wavelet transform kernels and general multicomponent transforms.
The Kakadu library offers extensive support for interactive mode of client–server applications. It is done
thanks to the implementation of the most notable features from the JPIP (JPEG 2000 Internet Protocols) standard \cite{jpeg_suite}.

\subsection{Reversible denoising and lifting steps with step skipping}

Methods such as reversible denoising and lifting based color component transformation aim to improve
overall quality of image compression. Color space transformation in reversible manner is required
by the lossless image compression framework used in the JPEG 2000 standard. The undesirable side effect
of such transformation is contamination of transformed components with noise from other ones.
Therefore, the compression ratio of given image is substantially diminished \cite{denoising}.

The work in this specific paper is aimed to remove correlation without increasing the noise.
Therefore, a reversible denoising and lifting step (RDLS) was proposed. The RDLS integrates
usage of denoising filters into lifting step. New image component transformation is a result
of applying RDLS to color space transformation. The main feature of this operation is
being ``reversible despite involving the inherently irreversible denoising'' \cite{denoising}.

The main targets using application of RDLS to the RDgDb color space transformation with
simple denoising filters are the JPEG-LS, JPEG 2000 and JPEG XR lossless modes of the
standard algorithms.
The images which have native optical resolution of acquisition devices benefit the most
from this application. Improvement in terms of compression ratios is the most visible
in subset of images which unmodified color space transformation either improved or worsened
ratios in comparison to the untransformed image. On the average improvement is between
5\% and 6\% for such specific images. However, things differ for images from ``standard
test-sets'' resulting in the improvement only up to 2.2\% \cite{denoising}.

Another application of the RDLS (reversible denoising and lifting step) is described
in the paper \cite{entropy}. New method of using ``hybrid transform'' was introduced there.
The main input to that paper was discrete wavelet transform using custom prediction
mechanism. Although simple prediction is considered to be ineffective when combined with DWT,
the application of modified discrete wavelet transform using RLDS with step skipping is able to
take advantages of its strengths. The usage of heuristics and estimation of entropy resulted
in making described transform ``image-adaptive'' \cite{entropy}.

The data set used for experiments in the presented paper contained 247 non-photographic and
499 photographic images. As a result it was found that described approach using combination
of RDLS with step skipping, DWT and prediction turned out to be effective. The prediction
mechanism allowed to double the JPEG 2000 compression ratio improvements made by using only RDLS.
Compression schemes with various tradeoffs were proposed due to fact that for some images
applying prediction instead of DWT could be more beneficial. The compression ratios of non-photographic
and photographic images improved by 30.9\% and 1.2\%, respectively, in comparison to solution
compliant with Part 1 of the JPEG 2000 standard. The cost was in the increase of compression
time by 2\% and breaking mentioned before compliance. Greater ratio improvements were claimed to
be possible with greater cost in runtime performance \cite{entropy}.

\subsection{Skipping Selected Steps of DWT Computation}

The other method of improving image compression, i.e. bitrates of lossless JPEG 2000 is skipping
selected steps of discrete wavelet computation (SS-DWT). At the first phase of implementing
this particular method fixed SS-DWT variants were employed. Then, heuristic was employed to select
from the mentioned before variants best one for certain image \cite{skipping_dwt}.

The experiments on diverse set of images resulted in the improvement of bitrates vastly of
non-photographic images. ``The entropy estimation of encoding effects'' was used to select the most
feasible variant of applied fixed SS-DWT. It is especially important from the practical standpoint
as time execution of such application is reduced. ``Such compression scheme is compliant with the Part 2
of the JPEG 2000 standard as opposed to the general SS-DWT case'' \cite{skipping_dwt}.

The average improvement in terms of bitrate was around 5\% for the entire test-set. Moreover,
the time needed to perform compression of the image was only 3\% great than the part 1 of the JPEG 2000
compliant variant. However, the results are quite different across the set of photographic and non-photographic
images. The first ones are improved on average by 0.5\% while the latter by 14\%. The heuristic can
be further exploited to perform more modifications and result with improvement of bitrate up to 17.5\%.
These extra modifications include ``skipping the steps based on the actual bitrate rather than the
estimated one and applying reversible denoising and lifting steps to SS-DWT''. However it is achieved with
great time penalty \cite{skipping_dwt}.
Furthermore, it has been evaluated that applying the fixed skipped steps discrete wavelet
transform (fixed SS-DWT) variants with the lossless compression compliant with the Part 2
of JPEG 2000 standard can provide another improvements \cite{practical_dwt}.


\subsection{Extreme value theorem}

We can expand the boundedness theorem such that \(m\) and \(M\) are functions of \(f(x)\) in the bound \([a,b]\). That is:

\(\exists m \in \mathbb{R} \exists M\in \mathbb{R}\forall x\in [a,b](m<f(x)<M)\)


\documentclass[10pt,a4paper]{article}
\usepackage{amsmath,amssymb,bm,graphicx,pictex,makeidx,subfigure}
\usepackage[italian,english]{babel}
\usepackage[center,small]{caption}[2007/01/07]
\usepackage{fancyhdr}
\usepackage{color}

\definecolor{blu}{rgb}{0,0,1}
\definecolor{verde}{rgb}{0,1,0}
\definecolor{rosso}{rgb}{1,0,0}

\begin{document}

\section{The $\chi^2$ in the presence of correlations}

Suppose to have an ensamble of $n$ measurements having the following
structure:
\begin{equation}
  m_i\pm \sigma_{i,\rm stat} \pm \sigma_{i,\rm unc} \pm \sigma_{i,\rm
    corr}^{(1)}\pm\dots \pm \sigma_{i,\rm
    corr}^{(k)}\,,
\end{equation}
where $m_i$, with $i=1,\dots, n$, is the central value of the $i$-th
measurement, $\sigma_{i,\rm stat}$ its (uncorrelated) statistical
uncertainty, $\sigma_{i,\rm unc}$ its uncorrelated systematic
uncertainty\footnote{There could be more than one uncorrelated
  systematic uncertainty. In this case, $\sigma_{i,\rm unc}$ is just
  the square root of the sum in quadrature of all the uncorrelated
  systematic uncertainties.}, and $\sigma_{i,\rm corr}^{(l)}$, with
$l=1,\dots,k$, its correlated systematic uncertainties. With this
information at hand, one can construct the full covariance matrix
$V_{ij}$ as follows (see for example Ref.~\cite{Ball:2012wy}):
\begin{equation}\label{eq:covmat}
  V_{ij}=\left(\sigma_{i,\rm stat}^2 +\sigma_{i,\rm unc}^2\right)\delta_{ij} + \sum_{l=1}^{k}\sigma_{i,\rm
    corr}^{(l)}\sigma_{j,\rm
    corr}^{(l)}\,.
\end{equation}
This is a clearly symmetric matrix. Given a set of predictions $t_i$
corresponding to the $n$ measurements of the ensamble, the $\chi^2$
takes the form:
\begin{equation}\label{eq:chi2cov}
  \chi^2=
  \sum_{i,j=1}^{n}\left(m_i-t_i\right)V_{ij}^{-1}\left(m_j-t_j\right) =
  \mathbf{y}^{T} \cdot \mathbf{V}^{-1} \cdot \mathbf{y}\,,
\end{equation}
where in the second equality we have used the matricial notation and
defined $y_i = m_i-t_i$. A convenient way to compute the $\chi^2$
relies on the Cholesky decomposition of the covariance matrix
$\mathbf{V}$. In particular, it can be proven that any symmetric and
positive definite matrix $\mathbf{V}$ can be decomposed as:
\begin{equation}\label{eq:choleskydec}
\mathbf{V} = \mathbf{L}\cdot\mathbf{L}^{T}\,,
\end{equation}
where $\mathbf{L}$ is a lower triangular matrix whose entries are
related recursively to those of $\mathbf{V}$ as follows:
\begin{equation}\label{eq:cholalg}
\begin{array}{rcl}
  L_{kk} &=&\displaystyle \sqrt{V_{kk}-\sum_{j=1}^{k-1}L_{kj}^2}\,,\\
  \\
  L_{ik} &=&\displaystyle
             \frac{1}{L_{kk}}\left(V_{ik}-\sum_{j=1}^{k-1}L_{ij}L_{kj}\right)\,,\quad
             k < i\,,\\
\\
  L_{ik} &=&\displaystyle 0\,,\quad
             k > i\,.\\
\end{array}
\end{equation}
It is then easy to see that the $\chi^2$ can be written as:
\begin{equation}
\chi^2 = \left|\mathbf{L}^{-1}\cdot \mathbf{y}\right|^2\,.
\end{equation}
But the vector $\mathbf{x} \equiv \mathbf{L}^{-1}\cdot \mathbf{y}$ is
the solution of the linear system:
\begin{equation}
  \mathbf{L} \cdot \mathbf{x} = \mathbf{y}\,,
\end{equation}
that can be efficiently solved by forward substitution, so that:
\begin{equation}
  \chi^2 = \left|\mathbf{x}\right|^2\,.
\end{equation}
Following this procedure, one does not need to compute explicitly the
inverse of the covariance matrix $\mathbf{V}$, simplifying
significantly the computation of the $\chi^2$.

\section{Additive and multiplicative uncertainties}

The correlated systematic uncertainties $\sigma_{i,\rm corr}^{(l)}$
may be either \textit{additive} or \textit{multiplicative}. The nature
of the single uncertainties is typically provided by the experiments
that release the measurements. A typical example of multiplicative
uncertainty is the luminosity uncertainty but there can be others.

Now let us express all the correlated systematic uncertainties
$\sigma_{i,\rm corr}^{(l)}$ as relative to the associate central value
$m_i$, so that we define\footnote{Note that this redefinition does not
  change the nature of the uncertainties, additive uncertainties
  remain additive as well as multiplicative uncertainties remain
  multiplicative.}:
\begin{equation}
\sigma_{i,\rm corr}^{(l)}\equiv  \delta_{i,\rm corr}^{(l)} m_i
\end{equation}
and let us also define
$s_i^2\equiv \sigma_{i,\rm stat}^2 +\sigma_{i,\rm unc}^2$ so that
Eq.~(\ref{eq:covmat}) can be rewritten as:
\begin{equation}\label{eq:covmat2}
  V_{ij}=s_i^2\delta_{ij} + \left(\sum_{l=1}^{k}\delta_{i,\rm
    corr}^{(l)}\delta_{j,\rm
    corr}^{(l)}\right)m_im_j\,.
\end{equation}
Now we split the correlated systematic uncertainties into $k_a$
additive uncertainties and $k_m$ multiplicative uncertainties, such
that $k_a+k_m=k$. This way Eq.~(\ref{eq:covmat2}) takes the form:
\begin{equation}\label{eq:covmat3}
  V_{ij}=s_i^2\delta_{ij} + \left(\sum_{l=1}^{k_a}\delta_{i,\rm
    add}^{(l)}\delta_{j,\rm
    add}^{(l)}+\sum_{l=1}^{k_m}\delta_{i,\rm
    mult}^{(l)}\delta_{j,\rm
    mult}^{(l)}\right)m_im_j\,.
\end{equation}
It is well known that this definition of the covariance matrix is
problematic in that it results in the so-called D'Agostini bias of the
multiplicative uncertainties~\cite{DAgostini:1993arp}. A possible
solution to this problem is the so-called
$t_0$-prescription~\cite{Ball:2009qv}, where the experimental central
value $m_i$ in the multiplicative term is replaced by a fixed
theoretical predictions $t_i^{(0)}$, typically computed in a previous
fit in which the ``standard'' definition of the covariance matrix in
Eq.~(\ref{eq:covmat}) (often referred to as \textit{experimental}
definition) is used. Applying the $t_0$ prescription, the covariance
matrix takes the form:
\begin{equation}\label{eq:covmat4}
  V_{ij}=s_i^2\delta_{ij} + \sum_{l=1}^{k_a}\delta_{i,\rm
    add}^{(l)}\delta_{j,\rm
    add}^{(l)}m_im_j+\sum_{l=1}^{k_m}\delta_{i,\rm
    mult}^{(l)}\delta_{j,\rm
    mult}^{(l)}t_i^{(0)}t_j^{(0)}\,.
\end{equation}

\section{Artificial generation of correlated systematics}

In order to implement the definition of the $\chi^2$ discussed above,
it is necessary to have the experimental information in terms of the
correlated systematic uncertainties $\sigma_{i,\rm corr}^{(l)}$. This
is what the experimental collaborations usually release. However, in
some cases this information is given in terms of a covariance
matrix. Therefore, one needs to find a workaround to generate
correlated systematic uncertainties out of a covariance matrix.

Given a $n \times n$ symmetric matrix $\mathbf{C}$, it will have $n$
orthonormal eigenvectors $\mathbf{x}^{(i)}$, such that
$\mathbf{x}^{(i)}\cdot \mathbf{x}^{(j)}=\delta_{ij}$, each of which
will have a non-negative eigenvalue $\lambda_i$ associated:
\begin{equation}
  \mathbf{C}\cdot \mathbf{x}^{(i)} = \lambda_i \mathbf{x}^{(i)}\,, \quad
  i =1,\dots,n\,.
\end{equation}
If we define:
\begin{equation}\label{eq:artsys}
  \sigma_{i,\rm corr}^{(l)} = \sqrt{\lambda_l} x_i^{(l)}\,,\quad i,l=1,\dots,n\,,
\end{equation}
one can show that:
\begin{equation}\label{eq:artsydef}
  \sum_{l=1}^{n}\sigma_{i,\rm corr}^{(l)}\sigma_{j,\rm corr}^{(l)} =C_{ij}\,.
\end{equation}
To prove this equality we start from the following matricial relation:
\begin{equation}
\mathbf{C} =\mathbf{Q}\cdot \mathbf{\Lambda}\cdot \mathbf{Q}^{-1}\,,
\end{equation}
where $\mathbf{\Lambda}$ is a diagonal matrix with the eigenvalues
$\lambda_i$ on the diagonal ($\Lambda_{ij} = \lambda_i\delta_{ij}$),
while $\mathbf{Q}$ is a matrix whose columns are the eigenvectors
$\mathbf{x}^{(i)}$ ($Q_{ij} = x_{i}^{(j)}$). In addition, since in
this particular case
$\mathbf{x}^{(i)}\cdot \mathbf{x}^{(j)}=\delta_{ij}$, this implies
that:
\begin{equation}
\mathbf{Q}^T \cdot \mathbf{Q}  = \mathbf{I}\quad\Rightarrow\quad
\mathbf{Q}^{-1} =  \mathbf{Q}^{T}\,,
\end{equation}
so that:
\begin{equation}\label{eq:diagC}
  \mathbf{C} =\mathbf{Q}\cdot \mathbf{\Lambda}\cdot \mathbf{Q}^{T}\,.
\end{equation}
It follows that:
\begin{equation}
  C_{ij} =\sum_{k,l=1}^{n}Q_{ik}\Lambda_{kl} Q_{jl} = \sum_{k,l=1}^{n} x_{i}^{(k)}
  \lambda_{k}\delta_{kl}x_{j}^{(l)} = \sum_{l=1}^{n} \lambda_{l}x_{i}^{(l)}
  x_{j}^{(l)}=\sum_{l=1}^{n}\sigma_{i,\rm corr}^{(l)}\sigma_{j,\rm corr}^{(l)} \,,
\end{equation}
as required.

The matrix \textbf{C} can be regarded as the correlated contribution to
the full covariance matrix \textbf{V}. In particular, considering
Eqs.~(\ref{eq:covmat}) and~(\ref{eq:covmat2}), one can write:
\begin{equation}
\mathbf{V} = \mathbf{U} + \mathbf{C}\,,
\end{equation}
where $\mathbf{U}$ is a diagonal matrix of uncorrelated uncertainties:
\begin{equation}
U_{ij} = s_i^2\delta_{ij}\,.
\end{equation}
This defines the matrix $\mathbf{C}$ as:
\begin{equation}\label{eq:corrdef}
\mathbf{C} = \mathbf{V} - \mathbf{U}\,,
\end{equation}
such that, given a $n\times n$ covariance matrix $\mathbf{V}$ along
with its uncorrelated contribution $\mathbf{U}$, one can generate a
set of $n$ \textit{artificial} correlated systematics according to
Eq.~(\ref{eq:artsys}), where $\mathbf{C}$ is given in
Eq.~(\ref{eq:corrdef}), for each of the $n$ measurements. This allows
us to implement Eq.~(\ref{eq:covmat4}) for the construction of the
covariance matrix.

\section{Determining the systematic shifts}

In order to visualise the effect of systematic uncertainties, it is
instructive to compute the \textit{systematic shift} generated by the
systematic uncertainties. To do so, we need to write the $\chi^2$ in
terms of the so-called ``nuisance parameters'' $\lambda_\alpha$. One
can show that the definition of the $\chi^2$ in Eq.~(\ref{eq:chi2cov})
is equivalent to~\cite{Ball:2012wy}:
\begin{equation}\label{eq:chi2nuis}
\chi^2 = \sum_{i=1}^n\frac{1}{s_i^2}\left(m_i -t_i
  -\sum_{\alpha=1}^k\lambda_\alpha \sigma_{i,\rm corr}^{(\alpha)} \right)^2 + \sum_{\alpha=1}^k\lambda_\alpha^2\,.
\end{equation}
The optimal value of the nuisance parameters can be computed by
minimising the $\chi^2$ with respect to them, that is imposing:
\begin{equation}
\frac{\partial \chi^2}{\partial \lambda_\beta} = 0\,.
\end{equation}
This yields the system:
\begin{equation}\label{eq:nuissys}
  \sum_{\beta=1}^kA_{\alpha\beta}\lambda_\beta =\rho_\alpha\,,
\end{equation}
with:
\begin{equation}\label{eq:sysing}
A_{\alpha\beta}= \delta_{\alpha\beta}+\sum_{i=1}^n\frac{\sigma_{i,\rm corr}^{(\alpha)}\sigma_{i,\rm corr}^{(\beta)}}{s_i^2}\quad\mbox{and}\quad \rho_\alpha=\sum_{i=1}^n\frac{m_i-t_i}{s_i^2}\sigma_{i,\rm corr}^{(\alpha)}\,,
\end{equation}
that determines the values of $\lambda_\beta$. The quantity:
\begin{equation}
d_i =\sum_{\alpha=1}^k\lambda_\alpha \sigma_{i,\rm corr}^{(\alpha)}
\end{equation}
in Eq.~(\ref{eq:chi2nuis}) can be interpreted as a shift caused by the
correlated systematic uncertainties. Defining the shifted predictions
as:
\begin{equation}
\overline{t}_i =t_i+d_i\,,
\end{equation}
the $\chi^2$ reads:
\begin{equation}\label{eq:chi2nuisshift}
  \chi^2 = \sum_{i=1}^n\left(\frac{m_i -\overline{t}_i}{s_i}\right)^2 + \sum_{\alpha=1}^k\lambda_\alpha^2\,.
\end{equation}
Therefore, up to a penalty term given by the sum of the square of the
nuisance parameters, the $\chi^2$ takes the form of the uncorrelated
definition. In order to achieve a visual assessment of the agreement
between data and theory, it appears natural to compare the central
experimental values $m_i$ to the shifted theoretical predictions
$\overline{t}_i$ in units of the uncorrelated uncertainty $s_i$.

% \section{The effect of cuts}

% Due to the possible mutual correlation of the measurements of a given
% ensamble, the exclusion of any of the measurements in the computation
% of the $\chi^2$ necessarily introduces an inconsistency. However, in
% many cases, due to limitations in the computation of the theoretical
% predictions, it is unavoidable introducing cuts. Unfortunately, there
% is no way to avoid this inconsistency and the best one can do is to
% compute the $\chi^2$ in Eq.~(\ref{eq:chi2cov}) skipping the values of
% $i$ and $j$ corresponding to the measurements excluded from the
% computation.

% Since cuts are typically of kinematic origin, one can argue that in
% the case of \textit{unnormalised} measurements the correlation between
% measurements taken in sufficiently different kinematic regions are not
% very correlated. This ensures that the exclusion of measurements based
% on kinematic cuts does not bias the computation of the $\chi^2$
% significantly\footnote{This heuristic argument is far from being
%   rigorous.}. However, in the presence of \textit{normalised}
% measurements this problem is made more severe by the fact that the
% (common) normalisation introduces a further correlation that is
% transversal to the whole ensamble~\cite{Boughezal:2017nla}. Moreover,
% normalised measurements are typically such that the integral over the
% full ensamble gives one. Therefore, excluding data breaks the
% normalisation.  However, this problem can be overcome by simply
% normalising the theoretical predictions to the integral of the
% measurements that survive the cut.

\begin{thebibliography}{alp}

%\cite{Ball:2009qv}
\bibitem{Ball:2009qv}
  R.~D.~Ball {\it et al.} [NNPDF Collaboration],
  %``Fitting Parton Distribution Data with Multiplicative Normalization Uncertainties,''
  JHEP {\bf 1005} (2010) 075
  doi:10.1007/JHEP05(2010)075
  [arXiv:0912.2276 [hep-ph]].
  %%CITATION = doi:10.1007/JHEP05(2010)075;%%
  %84 citations counted in INSPIRE as of 13 May 2018

%\cite{DAgostini:1993arp}
\bibitem{DAgostini:1993arp}
  G.~D'Agostini,
  %``On the use of the covariance matrix to fit correlated data,''
  Nucl.\ Instrum.\ Meth.\ A {\bf 346} (1994) 306.
  doi:10.1016/0168-9002(94)90719-6
  %%CITATION = doi:10.1016/0168-9002(94)90719-6;%%
  %146 citations counted in INSPIRE as of 13 May 2018

%\cite{Ball:2012wy}
\bibitem{Ball:2012wy}
  R.~D.~Ball {\it et al.},
  %``Parton Distribution Benchmarking with LHC Data,''
  JHEP {\bf 1304} (2013) 125
  doi:10.1007/JHEP04(2013)125
  [arXiv:1211.5142 [hep-ph]].
  %%CITATION = doi:10.1007/JHEP04(2013)125;%%
  %102 citations counted in INSPIRE as of 13 May 2018

%\cite{Boughezal:2017nla}
\bibitem{Boughezal:2017nla}
  R.~Boughezal, A.~Guffanti, F.~Petriello and M.~Ubiali,
  %``The impact of the LHC Z-boson transverse momentum data on PDF determinations,''
  JHEP {\bf 1707} (2017) 130
  doi:10.1007/JHEP07(2017)130
  [arXiv:1705.00343 [hep-ph]].
  %%CITATION = doi:10.1007/JHEP07(2017)130;%%
  %19 citations counted in INSPIRE as of 13 May 2018

\end{thebibliography}

\end{document}


\documentclass[12pt]{article}

\usepackage[ruled, vlined]{algorithm2e}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{parskip}

\geometry{a4paper}

\title{Set-based Minesweeper}
\author{Andrew Kritzler}

\begin{document}
\maketitle
\tableofcontents
\newpage

\section{Definition of \(G\)}

Minesweeper is usually played on a finite rectangular grid containing a predetermined number of mines.
Consider the following \(3 \times 4\) grid with 3 mines.
\[
    \begin{matrix}
        \texttt{0} & \texttt{1} & \texttt{\#} & \texttt{*} \\
        \texttt{1} & \texttt{2} & \texttt{3}  & \texttt{-} \\
        \texttt{X} & \texttt{@} & \texttt{-}  & \texttt{-} \\
    \end{matrix}
\]

\texttt{*} is a mine, \texttt{@} is a detonated mine, \texttt{\#} is a correct flag, \texttt{X} is an incorrect flag, and \texttt{-} is a plain tile.
The following table provides a description of every cell.
\begin{center}
    \begin{tabular}{*{6}{c}}
        \toprule
        \(x\) & \(y\) & Tile        & Mine?     & Revealed? & Flagged?  \\
        \midrule
        0     & 0     & \texttt{X}  &           &           & \(\top \) \\
        0     & 1     & \texttt{1}  &           & \(\top \) &           \\
        0     & 2     & \texttt{0}  &           & \(\top \) &           \\
        1     & 0     & \texttt{@}  & \(\top \) & \(\top \) &           \\
        1     & 1     & \texttt{2}  &           & \(\top \) &           \\
        1     & 2     & \texttt{1}  &           & \(\top \) &           \\
        2     & 0     & \texttt{-}  &           &           &           \\
        2     & 1     & \texttt{3}  &           & \(\top \) &           \\
        2     & 2     & \texttt{\#} & \(\top \) &           & \(\top \) \\
        3     & 0     & \texttt{-}  &           &           &           \\
        3     & 1     & \texttt{-}  &           &           &           \\
        3     & 2     & \texttt{*}  & \(\top \) &           &           \\
        \bottomrule                                                     \\
    \end{tabular}
\end{center}

Hopefully, the following transformation is self-explanatory.
For each entry in the matrix, \((x, y) \in M\) if and only if it is a mine.
Similarly, sets \(R\) and \(F\) are used for the remaining columns.
\[
    \begin{aligned}
        M & = \{(1, 0), (2, 2), (3, 2)\}                         \\
        R & = \{(0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 1)\} \\
        F & = \{(0, 0), (2, 2)\}
    \end{aligned}
\]

\(G = (M, R, F)\) is a minesweeper game, where \(M, R, F \subseteq \mathbb{Z}^2\) and \(R \cap F = \varnothing \).
Notice how \(G\) does not encode the dimensions of the grid; the grid is considered to be infinite.
An infinite game is impractical because computers have finite resources and the player could never win.
However, the simplicity of this model is useful for mathematical study.

\section{Dynamic Generation of \(M\)}

Let \(A : \mathbb{Z}^2 \to \mathcal{P}(\mathbb{Z}^2)\) be a function that outputs the set of adjacent coordinates.
\(A\) is a useful building block for more complex logic.
For example, \(|A(x, y) \cap M|\) counts the number of mines adjacent to \((x,y)\).
\[A(x, y) = (\{x - 1, x, x + 1\} \times \{y - 1, y, y + 1\}) \setminus \{(x, y)\} \]

Generating \(M\) statically is impossible.
An infinite board cannot be described in terms of its number of mines.
Instead, the board must be described in terms of its density of mines.
Let \(\gamma \) be a predetermined value representing the proportion of cells which are mines, where \(0 \leq \gamma \leq 1\).
For example, in a \(16 \times 30\) board with 99 mines, \(\gamma = 99 \div (16 \times 30) = 0.20625\).

A cell \((x, y)\) is \textit{inactive} if it and its adjacent cells have not been revealed, i.e., \((x, y) \notin R\) and \(A(x, y) \cap R = \varnothing \).
When the player reveals a cell, mines are randomly placed in the inactive cells within \(A(x, y) \cup \{(x, y)\} \).
Afterwards, all nine of these cells become active.
On the player's first turn when \(R = \varnothing \), no mines are generated.
Thus, the first tile revealed will always be \texttt{0}.

For notation purposes, let \(X\) be a standard uniform random variable, i.e., \(X \sim U(0, 1)\).
As a result, \(\Pr(X < \gamma ) = \gamma \).

\begin{algorithm}[H]
    \SetAlgoLined{}
    \DontPrintSemicolon{}
    \caption{Reveal}
    \eIf{\((x, y) \notin R \cup F\)}{
        \If{\(R \neq \varnothing \)}{
            \ForAll{\((u, v) \in A(x, y) \cup \{(x, y)\} \)}{
                \If{\((u, v) \notin R \wedge A(u, v) \cap R = \varnothing \)}{
                    \If{\(X < \gamma \)}{
                        \(M \gets M \cup \{(u, v)\} \)
                    }
                }
            }
        }
        \(R \gets R \cup \{(x, y)\} \) \\
        \Return{\(\top \)}
    }{
        \Return{\(\bot \)}
    }
\end{algorithm}

\end{document}


\subsubsection{Time Series Normalization}

\begin{frame}{Time Series Normalization}
    \begin{itemize}
        \item z-normalization or Z-scoring time series is common prior DTW calculation \cite{ding2008querying}

        \item Two different time series normalizations $\eta$ and $\eta '$ from \cite{das1998rule}
    \end{itemize}
\end{frame}

\begin{frame}{Time Series Normalization}{Calculation}
    \begin{block}{Given}
        \begin{itemize}
            \item A domain set $\mathbb{U}$

            \item A distance measure function $d$ with $d: \mathbb{U} \times \mathbb{U} \to \mathbb{R}$

        \end{itemize}
    \end{block}
    \begin{block}{Input}
        \begin{itemize}
            \item A time series $Q = (q_1, q_2, \dots, q_i, \dots, q_l)$ with length $l$ over the domain set
                $\mathbb{U}$
        \end{itemize}
    \end{block}
\end{frame}

\begin{frame}{Time Series Normalization $\eta$}{Calculation}
    \begin{block}{Calculation}
        \begin{itemize}
            \item Every data point $q$ of $Q$ will be transformed by $\eta$

            \item $\eta (q) = q -\bar{q}$

        \end{itemize}
    \end{block}
    \begin{block}{Mean of $Q$}
        \begin{itemize}
            \item $\bar{q} = \frac{1}{l} \sum \limits_{i=1}^{l} q_i$
        \end{itemize}
    \end{block}
\end{frame}

\begin{frame}<handout:0>{Time Series Normalization $\eta$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-100,
                                    ymax=0,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};
                            \end{axis}
                        \end{tikzpicture} \\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-100,
                                ymax=0,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}

\begin{frame}<handout:0>{Time Series Normalization $\eta$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-40,
                                    ymax=40,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-40,
                                ymax=40,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}

\begin{frame}{Time Series Normalization $\eta$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[gray, quiver={u=\thisrow{u}, v=\thisrow{v}}] table {../data/fig/norm1/path.dat};
                            \addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-40,
                                    ymax=40,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};
                                \addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm1/matrix_path.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-40,
                                ymax=40,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}

\begin{frame}{Time Series Normalization $\eta '$}{Calculation}
    \begin{block}{Calculation}
        \begin{itemize}
            \item Every data point $q$ of $Q$ will be transformed by $\eta '$

            \item $\eta '(q) = \frac{\eta (q)}{\sigma}$

        \end{itemize}
    \end{block}
    \begin{block}{Standard deviation of $Q$}
        \begin{itemize}
            \item $\sigma = \frac{1}{l-1} \sum \limits_{i=1}^{l} d(q_i, \bar{q})^2$
        \end{itemize}
    \end{block}
\end{frame}

\begin{frame}<handout:0>{Time Series Normalization $\eta '$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[red, thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-100,
                                    ymax=0,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/dynamictimewarping/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/dynamictimewarping/matrix.dat};
                            \end{axis}
                        \end{tikzpicture} \\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-100,
                                ymax=0,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/dynamictimewarping/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}

\begin{frame}<handout:0>{Time Series Normalization $\eta '$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[red, thick, mark=none] table {../data/fig/norm1/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm1/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-40,
                                    ymax=40,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm1/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm1/matrix.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-40,
                                ymax=40,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm1/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}

\begin{frame}<handout:0>{Time Series Normalization $\eta '$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-2,
                                    ymax=2,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-2,
                                ymax=2,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}

\begin{frame}{Time Series Normalization $\eta '$}{Example}
    \begin{center}
        \resizebox {\textwidth} {!} {
            \begin{tabular}{cc}
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tikzpicture}
                        \begin{axis}[
                            xmin=0,
                            xmax=47,
                            xlabel=time,
                            ylabel=acceleration,
                            width=\axisdefaultwidth,
                            height=0.7*\axisdefaultheight,
                            reverse legend,
                            legend pos=south east]
                            \addplot[gray, quiver={u=\thisrow{u}, v=\thisrow{v}}] table {../data/fig/norm2/path.dat};
                            \addplot[red, thick, mark=none] table {../data/fig/norm2/q.dat};
                            \addlegendentry{Q}
                            \addplot[blue, thick, mark=none] table {../data/fig/norm2/c.dat};
                            \addlegendentry{C}
                        \end{axis}
                    \end{tikzpicture}
                } & \quad
                \resizebox* {!} {0.3\textwidth} {
                    \begin{tabular}[b]{ll}
                        \begin{turn}{90}
                            \begin{tikzpicture}
                                \begin{axis}[
                                    xmin=0,
                                    xmax=47,
                                    ymin=-2,
                                    ymax=2,
                                    hide x axis,
                                    hide y axis,
                                    width=\axisdefaultwidth,
                                    height=0.7*\axisdefaultheight]
                                    \addplot[red, ultra thick, mark=none] table {../data/fig/norm2/q.dat};
                                \end{axis}
                            \end{tikzpicture}
                        \end{turn} \hspace*{3em} &
                        \begin{tikzpicture}
                            \begin{axis}[
                                enlargelimits=false,
                                ymin=0,
                                ymax=47,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=\axisdefaultwidth,
                                colorbar,
                                colormap/viridis high res]
                                \addplot[matrix plot*,
                                    mesh/cols=48,
                                    point meta=explicit] table[meta=C] {../data/fig/norm2/matrix.dat};
                                \addplot[white, ultra thick, mark=*, mark size=1] table {../data/fig/norm2/matrix_path.dat};
                            \end{axis}
                        \end{tikzpicture}\\
                        &
                        \\[1em]
                        &
                        \begin{tikzpicture}
                            \begin{axis}[
                                xmin=0,
                                xmax=47,
                                ymin=-2,
                                ymax=2,
                                hide x axis,
                                hide y axis,
                                width=\axisdefaultwidth,
                                height=0.7*\axisdefaultheight]
                                \addplot[blue, ultra thick, mark=none] table {../data/fig/norm2/c.dat};
                            \end{axis}
                        \end{tikzpicture}
                    \end{tabular}
                }
            \end{tabular}
        }
    \end{center}
\end{frame}