\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{url}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{color}
\usepackage{listings}
\usepackage{verbatim}
\usepackage{enumitem}
\usepackage[parfill]{parskip}

\newcommand{\xb}{\mathbf{x}}
\newcommand{\yb}{\mathbf{y}}
\newcommand{\wb}{\mathbf{w}}
\newcommand{\Xb}{\mathbf{X}}
\newcommand{\Yb}{\mathbf{Y}}
\newcommand{\tr}{^T}
\newcommand{\hb}{\mathbf{h}}
\newcommand{\Hb}{\mathbf{H}}

\newcommand{\cmt}[1]{{\footnotesize\textcolor{red}{#1}}}
\newcommand{\todo}[1]{\cmt{TO-DO: #1}}

\title{CS294-112 Deep Reinforcement Learning HW2}

\author{ Heri Zhao
}

\date{Fall 2018}

\usepackage{courier}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\footnotesize\ttfamily,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    %numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\lstset{style=mystyle}

\begin{document}

\maketitle

\section*{Problem 1}
\begin{enumerate}[label=(\alph*)]
  \item For any $t$, we have
  \begin{align*}
    & \mathbb{E}_{\tau \sim p_\theta(\tau)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_t, a_t)} \mathbb{E}_{p_\theta(\tau / s_t, a_t | s_t, a_t)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_t, a_t)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_t)} \mathbb{E}_{p_\theta(a_t | s_t)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_t)} \left[b(s_t) \int_{a_t} p_\theta(a_t | s_t) \nabla_\theta \log \pi_\theta(a_t|s_t) d_{a_t} \right] \\
    &= \mathbb{E}_{p_\theta(s_t)} \left[b(s_t)\nabla_\theta \int_{a_t} \pi_\theta(a_t|s_t) d_{a_t} \right] \\
    &= \mathbb{E}_{p_\theta(s_t)} \left[b(s_t)\nabla_\theta 1 \right] \\
    &= 0
  \end{align*}
  Hence,
  $$
  \sum_{t=1}^T \mathbb{E}_{\tau \sim p_\theta(\tau)}\left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] = 0
  $$

  \newpage
  \item Becasue it is MDP problem, so future states and actions of the process conditional on both past and present values, depends only upon the present state. Therefore,
  $$
  p_\theta(s_{t+1:T}, a_{t:T} | s_{1:t}, a_{1:t-1}) = p_\theta(s_{t+1:T}, a_{t:T} | s_t)
  $$
  Now we sow the equation 12:
  \begin{align*}
   & \mathbb{E}_{\tau \sim p_\theta(\tau)}\left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_{1:t}, a_{1:t-1})} \mathbb{E}_{p_\theta(s_{t+1:T}, a_{t:T} | s_t)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_{1:t}, a_{1:t-1})} \mathbb{E}_{p_\theta(a_t | s_t)} \mathbb{E}_{p_\theta(s_{t+1:T}, a_{t:T} | s_t, a_t)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_{1:t}, a_{1:t-1})} \mathbb{E}_{p_\theta(a_t | s_t)} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_{1:t}, a_{1:t-1})} \left[\int_{s_t} \int_{a_t} p_\theta(a_t | s_t) \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] \\
    &= \mathbb{E}_{p_\theta(s_{1:t}, a_{1:t-1})} \left[\int_{s_t} b(s_t) \nabla_\theta \int_{a_t} \pi_\theta(a_t|s_t) d_{a_t} d_{s_t} \right] \\
    &= \mathbb{E}_{p_\theta(s_{1:t}, a_{1:t-1})} \left[\int_{s_t} b(s_t) \nabla_\theta 1 \right] \\
    &= 0
  \end{align*}
  Hence,
  $$
  \sum_{t=1}^T \mathbb{E}_{\tau \sim p_\theta(\tau)}\left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \left(b(s_t)\right)\right] = 0
  $$

\end{enumerate}

\newpage
\section*{Problem 4}
\begin{figure}[H]
  \centering
  \includegraphics[height=3.4in]{p4_1.png}
  \caption{Learning curves for small batch experiments}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py CartPole-v0 -n 100 -b 1000 -e 3 -dna --exp_name sb_no_rtg_dna
python train_pg_f18.py CartPole-v0 -n 100 -b 1000 -e 3 -rtg -dna --exp_name sb_rtg_dna
python train_pg_f18.py CartPole-v0 -n 100 -b 1000 -e 3 -rtg --exp_name sb_rtg_na
python plot.py data/sb_* --value AverageReturn
\end{lstlisting}

\begin{figure}[H]
  \centering
  \includegraphics[height=3.3in]{p4_2.png}
  \caption{Learning curves for large batch experiments}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py CartPole-v0 -n 100 -b 1000 -e 3 -dna --exp_name sb_no_rtg_dna
python train_pg_f18.py CartPole-v0 -n 100 -b 1000 -e 3 -rtg -dna --exp_name sb_rtg_dna
python train_pg_f18.py CartPole-v0 -n 100 -b 1000 -e 3 -rtg --exp_name sb_rtg_na
python plot.py data/lb_* --value AverageReturn
\end{lstlisting}

Answer the following questions briefly:
  \begin{itemize}
  \item Which gradient estimator has better performance without advantage-centering---the trajectory-centric one, or the one using reward-to-go? \\
  \textbf{In small batch size case, we can see the one using reward-to-go gives higher average rewards and lower variance than the trajectory-centric one. In the large batch case, we can see there is not much difference on average rewards, but the variance is little better for reward-to-go one.}

  \item Did advantage centering help? \\
  \textbf{Advantage centering did help in terms of stabling the learning curve. In both small and large batch cases, though the green and orange curves have similar average rewards, the green curve is much more stable.}

  \item Did the batch size make an impact? \\
  \textbf{Yes, batch size did make an impact. It especially helped a lot for trajectory-centric and non-advantage-centering case (blue curve). It also helped the other two curve to converge to reward 200 faster.}
  \end{itemize}

\newpage
\section*{Problem 5}
$b* = 60, r* = 0.01$. The policy gets to stable at iteration about \#55.
\begin{figure}[H]
  \centering
  \includegraphics[height=3.5in]{p5.png}
  \caption{Learning Curve of InvertedPendulum with $b = 60$ and $lr = 0.01$ on specific $seed = 1$.}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py InvertedPendulum-v2 -ep 1000 --discount 0.9 -n 100 -e 1 -l 2 -s 64 -b 60 -lr 0.01 -rtg --exp_name ip_b60_r0.01
python plot.py data/ip_b60_r0.01_InvertedPendulum-v2*
\end{lstlisting}

\newpage
\section*{Problem 7}
\begin{figure}[H]
  \centering
  \includegraphics[height=3.5in]{p7.png}
  \caption{Learning Curve of LunarLander. The policy achieve an average return of around 180.}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py LunarLanderContinuous-v2 -ep 1000 --discount 0.99 -n 100 -e 3 -l 2 -s 64 -b 40000 -lr 0.005 -rtg --nn_baseline --exp_name ll_b40000_r0.005
python plot.py data/ll_b40000_r0.005_LunarLanderContinuous-v2_* --value AverageReturn
\end{lstlisting}

\newpage
\section*{Problem 8}
\begin{figure}[H]
  \centering
  \includegraphics[height=4in]{p8_1.png}
  \caption{$3 \times 3$ hyper-parameter search. Best parameter is $b* = 50000$ and $r* = 0.02$}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 10000 -lr 0.005 -rtg --nn_baseline --exp_name hc_b10000_r0.005
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 10000 -lr 0.01 -rtg --nn_baseline --exp_name hc_b10000_r0.01
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 10000 -lr 0.02 -rtg --nn_baseline --exp_name hc_b10000_r0.02
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 30000 -lr 0.005 -rtg --nn_baseline --exp_name hc_b30000_r0.005
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 30000 -lr 0.01 -rtg --nn_baseline --exp_name hc_b30000_r0.01
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 30000 -lr 0.02 -rtg --nn_baseline --exp_name hc_b30000_r0.02
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.005 -rtg --nn_baseline --exp_name hc_b50000_r0.005
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.01 -rtg --nn_baseline --exp_name hc_b50000_r0.01
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.02 -rtg --nn_baseline --exp_name hc_b50000_r0.02
\end{lstlisting}
\begin{figure}[H]
  \centering
  \includegraphics[height=4in]{p8_2.png}
  \caption{Learning Curve of HalfCheetah. The run with rtg and baseline achieves to reward around 200}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.02 --exp_name hc_b50000_r0.02
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.02 -rtg --exp_name hc_b50000_r0.02_rtg
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.02 --nn_baseline --exp_name hc_b50000_r0.02_bl
python train_pg_f18.py HalfCheetah-v2 -ep 150 --discount 0.95 -n 100 -e 3 -l 2 -s 32 -b 50000 -lr 0.02 -rtg --nn_baseline --exp_name hc_b50000_r0.02_rtg_bl
python plot.py data/hc_b50000_r0.02_*
\end{lstlisting}
How did the batch size and learning rate affect the performance? \\
\textbf{In this problem, larger batch size with same learning-rate will make learning/converging faster. For learning-rate, generally we need to pick a proper value so that it won't be too small or too large. Small learning-rate will help to stabilize the curve, but if it is too small, we have take more iterations to reach to the optimal, and there will be more chances being trapped by local minimum. Large learning-rate will help to increase convergence speed, but if it is too large, the curve will fluctuate a lot ending up with jumping from one local minimal to another instead of converging (e.g. green curve in Figure 5).}

\newpage
\section*{Bonus}
I implemented the GAE-$\lambda$, according to the following equations:
\begin{align*}
& A_t = \delta_t + \gamma \lambda A_{t+1} \\
& A_T = \delta_T = -V(s_T) + r_T + 0 \\
& \delta_t = -V(s_t) + r_t + \gamma V(s_{t+1})
\end{align*}
\begin{lstlisting}[language=python]
# Bonus part for GAE-lambda
adv_n = []
# A_t = delta_t + gamma * lambda * A_{t+1}
# A_T = delta_T = -V(s_T) + r_T + 0
# delta_t = -V(s_t) + r_t + gamma * V(s_{t+1})
index_b = 0
for re in re_n:
    adv_along_path = []
    last_v = 0  # V(s_{t+1})
    a_t = 0
    # we need to iterate the part of b_n corresponding to re in reversed order
    for r, v in zip(reversed(re), reversed(b_n[index_b: index_b + len(re)])):
        delta_t = -v + r + self.gamma * last_v
        a_t = delta_t + self.gamma * self.gae_lambda * a_t
        last_v = v
        adv_along_path.append(a_t)
    index_b += len(re)
    adv_along_path.reverse()
    adv_n.extend(adv_along_path)
# update q_n for fitting baseline later
q_n = b_n + adv_n
\end{lstlisting}
In Figure 7, we can see that the best $\lambda$ for GAE is 0.94 (red line). Compared with the case with default reward-to-go and baseline function (orange line, $\lambda=1$), GAE-$0.94$ is much more faster and achieves higher rewards at the end. \\
We can also notice that when $\lambda$ is too small or reach to $0$, the performance drops to even below non-value-function one (blue line).

\begin{figure}[H]
  \centering
  \includegraphics[height=4in]{bonus.png}
  \caption{Learning Curve for Walker2d-v2. Comparison of GAE-$\lambda$.}
\end{figure}
\begin{lstlisting}[language=bash]
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --exp_name wa_b5000_r0.01_gamma0.95_nvf
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --nn_baseline --exp_name wa_b5000_r0.01_gamma0.95_lambda1
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --nn_baseline --gae --gae_lambda 0.98 --exp_name  wa_b5000_r0.01_gamma0.95_lambda0.98
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --nn_baseline --gae --gae_lambda 0.94 --exp_name  wa_b5000_r0.01_gamma0.95_lambda0.94
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --nn_baseline --gae --gae_lambda 0.92 --exp_name  wa_b5000_r0.01_gamma0.95_lambda0.92
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --nn_baseline --gae --gae_lambda 0.8 --exp_name  wa_b5000_r0.01_gamma0.95_lambda0.8
python train_pg_f18.py Walker2d-v2 -ep 150 --discount 0.95 -n 35 -e 1 --seed 1 -l 2 -s 32 -b 5000 -lr 0.01 -rtg --nn_baseline --gae --gae_lambda 0 --exp_name  wa_b5000_r0.01_gamma0.95_lambda0
python plot.py data/wa_b5000_r0.01_gamma0.95*
\end{lstlisting}

\end{document}


%%%%%%%%%%%%%
% TODO
%%%%%%%

\section{Problems and Motivation}
\subsection{Unsafety from Probability}
We are trying to tackle two problems in this work. The first issue is the interaction between nondeterminism and noninterference. More specifically, standard noninterference definitions fail to address leakages that result from different frequencies of possible execution traces of the same program. A simple example of this weakness can be seen below:

\begin{lstlisting}
if (random_bit() = 1)
  return secret_bit
else
  return random_bit()
\end{lstlisting}

This code leaks the secret bit 50\% of the time and outputs a random bit 50\% of the time. It is also important to note that it can output 0 or 1 independently of the secret value. This way, any (state, return) pair represents a successful execution.

Let’s say that two states are equivalent if they are the same for their non secret parts. Since any pair of state and return value is a valid execution, it is possible to find another execution from a related state. This makes it satisfy the noninterference definition.

Although the above program satisfies the noninterference definition, the secret bit can be determined via the observed frequency of repeated calls. When we look at the frequencies of output values, we can see that they correlate with the value of the secret bit. \\

\begin{tabular}{| c | c | c |}
	\hline
	Secret bit & Output 0 \% & Output 1 \% \\
	\hline
	0 &	75\% & 25\% \\
	\hline
	1 &	25\% & 75\% \\
	\hline
\end{tabular}\\

Any adversary who can observe the output of the function sufficiently many times can infer the value of the secret bit with high confidence. These types of vulnerabilities are not limited to usage of randomization. They also manifest themselves when there are random events such as crashes that can affect the behavior of the system.

The main example we will consider is crash and recovery of a storage system. If the recovery behavior of the system is dependent on the secret data stored in it, then the system may contain a vulnerability of this kind.

\subsection{Unsafe Data Handling}
The second problem observed involves handling the data in a potentially unsafe way. Many storage systems process the data provided to them before storing it. A potentially malicious developer can take advantage of this capability to leak information.

A classic example of this phenomenon is branching on confidential data. If not done carefully, it can result in leakage of confidential data. This does not mean that branching on confidential data should be avoided at all costs.

Data deduplication in a storage system in a good example to demonstrate this effect. For this example, we will treat data contents as secret but metadata as public. Therefore a user noticing extra space savings is fine as long as he cannot infer contents of the data from this knowledge.

Deduplication requires branching on confidential data, which can be abused if not handled carefully. Consider the following obviously unsafe implementation:

\begin{lstlisting}
write_to_txn(a, v)
  if ((a, v) is in txn)
    return false
  else
    add_to_txn(a, v)
    return true
\end{lstlisting}

Above code snippet takes an address and a data value and checks if the pair is already in the transaction. If it is in the transaction, then it returns false and does nothing. If it is not, it adds it to the transaction.

This implementation avoids writing the same pairs multiple times. However, it also allows an adversary to query the contents of the transaction for any address. A simple solution that can be considered to solve this problem is prohibiting branching control flow based on confidential data. This can be achieved by using a deeply embedded language that doesn’t have an operation to compare secret data or treat secret data as an abstract object that cannot be compared. Such approaches have the advantage that any program written in such a language is noninterfering by construction.

It is quite a strong property but also a restrictive one which eliminates many possible efficient implementations.

However, it is possible to implement a safe deduplicator. One way would be performing the process after the transaction is finalized but before committing it. Such a deferred deduplication will still branch on confidential data but without revealing it.

An ideal solution would prohibit unsafe implementations while allowing the safe ones with as little constraint as possible.


%!TEX root = ../../dissertation.tex

\section{Tables and Figures}

\begin{table}
\caption{Benchmark parameter values.}
\tabcolsep=0.2in
\centering
\begin{tabular}{lrl}
\toprule
Parameter  &  Value  &  Comment \\
\midrule

%& \\
\multicolumn{3}{l}{\textit Preferences} \\
$\rho$   &  $-1$  & IES $= 1/(1-\rho) = 1/2$ \\
$\alpha$ &  $-9$ & RA $= 1-\alpha = 10$ \\ %, Bansal \& Yaron (2004, Table II) \\
$\beta$  &   0.98 &  \\

\multicolumn{3}{l}{\textit Armington aggregator}  \\
$\sigma$    &   0   &  Cobb-Douglas   \\
$\omega$    &  0.1  &  chosen to hit import share of 0.1  \\

\multicolumn{3}{l}{\textit Productivity growth  } \\
$\log g$  &  0.004   &  Tallarini (2000, Table 4) \\
$v^{1/2}$ & 0.015   &  Tallarini (2000, Table 4), rounded off \\
$ \varphi_v$ & 0.95 & Backus, Ferriere, and Zin (2015, Table 1) \\
$ \tau$   &  $0.74 \times 10^{-5}$  & makes $v$ three standard deviations from zero \\
$ \gamma$ & 0.1 & persistence of productivity difference \\
\bottomrule
\end{tabular}
\label{tab:benchmark}
\end{table}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Consumption frontiers.
Lines represent the frontier quantities of consumption given unit quantities of the intermediate goods.
The dashed black line has $\omega = 1/2$, making the two final goods the same.
For the others, we choose an import share of 0.1
and use (\ref{eq:share-calculation}) to adjust $\omega$ as we vary $\sigma$.
The elasticities of substitution noted in the figure are $1/(1-\sigma)$.}

\includegraphics[width=\textwidth]{images/BCFL/final-goods-frontier.pdf}
\label{fig:consumption-frontier}
\end{figure}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Pareto and consumption frontiers.
The outer line is the consumption frontier with benchmark parameter values.
The inner line is the Pareto frontier:  the utility $J$ of agent 1 given
promised utility $U$ to agent 2.
In each case, the other state variables are $z_{1t} = z_{2t} = \wh{z}_t = 1$
and $v_t = v$.}

\includegraphics[width=\textwidth]{images/BCFL/frontiers_alpha9.pdf}
\label{fig:pareto-frontier}
\end{figure}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Dynamics of the additive and recursive Pareto weight.
The two lines represent simulations of models with additive ($\alpha = \rho = -1$)
and recursive ($\alpha = -9$, $\rho = -1 $) preferences.
The simulations use the same paths for exogenous state variables.
In each case, we plot $\log \lambda_t^*$ against time. }

\includegraphics[width=\textwidth]{images/BCFL/paretoweightstability_alpha9.pdf}
\label{fig:exchange-pareto-weight-two}
\end{figure}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Risk aversion and expected changes in the Pareto weight.
The lines represent the expected change in $\log \lambda_t^*$, or $E_t[\log \lambda^*_{t+1}] - \log \lambda_t$,
with three values of risk aversion $1-\alpha$:
$2$ (additive), 10, and 50. }

\includegraphics[width=\textwidth]{images/BCFL/policy_at_ss_one_axis.pdf}
\label{fig:change-pareto-weight-ra}
\end{figure}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Armington substitutability and expected changes in the Pareto weight.
The lines represent the expected change in $\log \lambda_t^*$, or $E_t[\log \lambda^*_{t+1}] - \log \lambda_t$,
with three values of the substitutability parameter $\sigma$ in the Armington aggregator.
The elasticities $1/(1-\sigma)$ are 2/3, 1, and 2. }

\bigskip
\includegraphics[width=\textwidth]{images/BCFL/Policies_Diff_Elast.png}
\label{fig:change-pareto-weight-arm}
\end{figure}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Intertemporal substitution and expected changes in the Pareto weight.
The lines represent the expected change in $\log \lambda_t^*$, or $E_t[\log \lambda^*_{t+1}] - \log \lambda_t$,
with three values of the substitutability parameter $\rho$ in the time aggregator:
$-1$, $-0.01$, and 1/3.
They correspond to intertemporal elasticities of substitution of 1/2, 0.99, and 3/2. }

\bigskip
\includegraphics[width=\textwidth]{images/BCFL/Policies_Diff_rho.png}
\label{fig:change-pareto-weight-ies}
\end{figure}

% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Consumption and the real exchange rate.
The dots represent simulations of models with additive ($\alpha = \rho = -1$)
and recursive ($\alpha = -9$) preferences.
In each case, we plot  $\log e_t = \log (p_{2t}/p_{1t}) $ against $\log (c_{2t}/c_{1t}) $
for a simulation of the model. }

\includegraphics[width=\textwidth]{images/BCFL/con_v_fxr_alpha9.pdf}
\label{fig:exchange-cons-rer-two}
\end{figure}

%\end{document}
% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Dynamics of the real exchange rate.
The lines represent autocorrelation functions for the real exchange rate
($\log e_t$) in models with additive ($\alpha = \rho = -1$)
and recursive ($\alpha = -9$) preferences.}

\includegraphics[width=\textwidth]{images/BCFL/acorr_fx_alpha1_9_one_axis.pdf}
\label{fig:rer-acfs}
\end{figure}

%\end{document}
% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Responses of variables
to an impulse in relative productivity\newline
$\log \wh{z}_t = (1/2) (\log z_{1t} - \log z_{2t}) $ in country 2.
The impulse takes place at date $t=1$.
Responses are reported as percent deviations from mean values.
}

\bigskip
\includegraphics[width=\textwidth]{images/BCFL/irf_wrt_zhat_alpha9.pdf}
\label{fig:irf-zhat}
\end{figure}

%\end{document}
% ****************************************************************************
\clearpage
\begin{figure}[htb]
\caption{Responses of variables
to an impulse in volatility $v_t$.
The impulse takes place at date $t=1$.
Responses are reported as percent deviations from mean values.
}

\bigskip
\includegraphics[width=\textwidth]{images/BCFL/irf_wrt_v_alpha9.pdf}
\label{fig:irf-v}
\end{figure}


The first step in running any environmental model is defining your
domain.  This section will bring us through the steps and rational
behind those steps and how to use ArcGIS to define your grid.

Before we can run our \ac{ctm}, \acs{cmaq}, we first have to run other
models to prepare inputs for \acs{cmaq}.  These models process
meteorology, emissions and terrain topology; and these other models
sometime require their own domains.

We want to set up a domain encompassing the north eastern United
States with a resolution of of 36 km$^2$.  To do this, we must:
\begin{itemize}
	\item configure the projection we wish to use
	\item set up a domain to run our meteorology
	\item set up a domain for \acs{cmaq}
\end{itemize}

%\hl{make a nested domain an ``extra''}

\section{Domain Specifications}

We will use a \emph{Lambert Conic Conformal} grid projection in this exercise.
This is the projection most commonly used for \acs{cmaq}, though other
projections are supported.

The specific projection we would like to use is not provided by ArcGIS by
default, so we will have to create it.  See appendix \ref{defining_projection}
for instructions on how to implement the following projection.  (A projection
file is also available in the included materials, named
\file{proj\_lcc\_cmaq.prj})

%Actual [http://svn.pontus.cee.carleton.ca/svn/models/doc/domain/Toronto12/rpo_lambert_proj.prj projection file] is available [http://svn.pontus.cee.carleton.ca/svn/models/doc/domain/Toronto12/rpo_lambert_proj.prj here].

The grid specifics are:
\begin{itemize}
	%\item False Easting: \textbf{2736.0}
	%\item False Northing: \textbf{2088}
	\item False Easting: \textbf{0.0}
	\item False Northing: \textbf{0.0}
	\item Central Meridian: \textbf{-97.0}
	\item Standard\_Parallel\_1: \textbf{33}
	\item Standard\_Parallel\_2: \textbf{45}
	\item Latitude\_Of\_Origin: \textbf{40}
	\item Linear Unit: \textbf{Kilometre}
\end{itemize}

Or, if you prefer the information in the standard \textbf{proj} format.
%+proj=lcc +datum=WGS84 +no_defs +lon_0=-97 +lat_1=33 +lat_2=40 +lat_0=40 +units=km +x_0=2736 +y_0=2088 +title="\acs{cmaq} RPO-NA LCC Shifted"
\begin{minted}{text}
+proj=lcc +datum=WGS84 +no_defs +lon_0=-97 +lat_1=33 +lat_2=40 +lat_0=40
   +units=km +x_0=0 +y_0=0 +title="\acs{cmaq} RPO-NA LCC"
\end{minted}
Though ArcGIS does display projection information in this form, it
is rather hidden.  Other GIS packages however (such as QGIS) use this
format more prominently.

%Note that we have named this domain ``shifted'', this is because we are
%including false easting and northings that we do not actually need for the
%projection (and will remove later.)  We are including these because they will
%make it easier to define our grids.  The false easting and northing in this
%setup actually defines the origin of our the \acs{cmaq} domain we are setting
%up.  We could just as easily remove the false easting and northing

Our \ac{cmaq} grid specification is:
\begin{itemize}
	\item A 36 km$^2$ spanning the North Eastern US.
	\item Grid origin (lower left corner) at: $(936, -576) \text{ km}$
	\item 44 rows, 40 columns.
\end{itemize}

This grid was chosen because it is a standard grid used in the
\acs{cmaq} test case.  If you're choosing a new domain, you want to
take the following into consideration:
\begin{itemize}
	\item Is my domain large enough to properly model transport processes for the time period I intend to model?
	\item Do my boundaries exclude any major emission sources close to my boundaries? \ie, would expanding my domain by another cell include a major emission source that impacts my main area of interest?
	\item Is my domain an appropriate size and resolution to model the chemistry in my area of interest?
\end{itemize}

To accommodate this grid, our meteorology should be larger by 3
cells.  Having a larger meteorological domain is is standard practice in air
quality modelling, though whether it be 3 cells or some other number is the
modellers choice.  The reason for a larger meteorological domain is to reduce
the effect of the meteorological boundaries on the \ac{ctm} domain.  These
extra cells are later removed such that the meteorological domain matches the
grid domain.

Therefore, our meteorological domain should be:
\begin{itemize}
	\item A 36 km$^2$ encompassing our \ac{cmaq} domain with a padding of 3 cells
	\item Grid origin (lower left corner) at: $(828, -684) \text{ km}$
	\item 50 rows, 46 columns.
\end{itemize}

\section{Drawing your domains in ArcGIS}
\label{drawing_domains}

Though not necessary, designing your grid in a GIS application -
though slow - can be incredibly helpful to visualize your domain(s)
and ensure they are exactly what you think they are.  Without any
visualization, the user may define their domain simply mathematically.
\eg~Toronto is X km away from our grid centre in our projection, our
cell size is Y, we want Z cells to be processed before Toronto, so we
need K cells.

The mathematical methods work of course, but become complicated when entering
domains into the different models.  For example, \acs{wrf}, a common
meteorological model, uses grid points rather than grid cells, and calculates
the offsets from the grid origin.  Meanwhile, \acs{cmaq}, our \acs{ctm}, uses
grid cells and requires inputs from the projection centre.

First, for context, add a shapefile for the continental US.  Such a
shape file can be downloaded at the Global Administrative Regions
website ( \url{http://www.gadm.org/} ) I recommend adding the
\file{USA\_adm1} file as it contains all the state boundaries.

We will use the \emph{Fishnet} tool to draw the grids onto your
projection to reduce the amount of confusion.  Though ArcGIS has a
native Fishnet tool, it is - in my opinion - less than intuitive to
use.  Therefore, this lesson recommends downloading a third-party
fishnet tool from
\url{http://arcscripts.esri.com/details.asp?dbid=12807}.  Once you
download this tool, add it to your menu bar, it should appear as in
figure \ref{fig:fishnet}.

\begin{figure}
	\centering
	\includegraphics[width=0.10\textwidth]{fishnettool.jpg}
	\caption{Third-party Fishnet tool}
	\label{fig:fishnet}
\end{figure}

Use the fishnet tool to create the \acs{cmaq} domain specified above, \ie
\begin{itemize}
	\item X (km): \textbf{936}, Y (km): \textbf{-576}
	\item Rows: \textbf{44}, Cols: \textbf{40}
	\item Size of each Cell: \textbf{36}, \textbf{36}
	\item Specify Output Shapefile: \acs{cmaq}\_36
	\item Coordinate System (optional): Select the projection you created earlier
\end{itemize}

You should now see a new grid layer added.  At this point, I normally change it's colour to ``hallow" with a blue line colour.

Next, we want to create the meteorological domain.

\begin{itemize}
	\item X (km): \textbf{828}, Y (km): \textbf{-684}
	\item Rows: \textbf{50}, Cols: \textbf{46}
	\item Size of each Cell: \textbf{36}, \textbf{36}
	\item Specify Output Shapefile: \acs{wrf}\_36
	\item Coordinate System (optional): Import the projection off the previous grid
\end{itemize}

\begin{figure}
	\centering
	\includegraphics[width=0.60\textwidth]{grid_setup.jpg}
	\caption{Meteorological (red) and \acs{ctm} (blue) domain}
	\label{grid_setup}
\end{figure}

The specifics of setting up the models to run this domain, and running the models is outside the scope of this tutorial.


\section{Rewards and the Epoch Boundary}
\label{sec:epoch}

\newcommand{\UTxOEpState}{\type{UTxOEpState}}
\newcommand{\Acnt}{\type{Acnt}}
\newcommand{\PlReapState}{\type{PlReapState}}
\newcommand{\NewPParamEnv}{\type{NewPParamEnv}}
\newcommand{\Snapshots}{\type{Snapshots}}
\newcommand{\SnapshotEnv}{\type{SnapshotEnv}}
\newcommand{\SnapshotState}{\type{SnapshotState}}
\newcommand{\NewPParamState}{\type{NewPParamState}}
\newcommand{\EpochState}{\type{EpochState}}
\newcommand{\BlocksMade}{\type{BlocksMade}}
\newcommand{\Snapshot}{\type{Snapshot}}
\newcommand{\RewardUpdate}{\type{RewardUpdate}}

\newcommand{\obligation}[4]{\fun{obligation}~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}}
\newcommand{\reward}[7]{\fun{reward}
  ~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}~ \var{#5}~ \var{#6}~ \var{#7}}
\newcommand{\rewardOnePool}[9]{\fun{rewardOnePool}
  ~\var{#1}~\var{#2}~\var{#3}~\var{#4}~\var{#5}~\var{#6}~\var{#7}~\var{#8}~\var{#9}}
\newcommand{\isActive}[4]{\fun{isActive}~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}}
\newcommand{\activeStake}[5]{\fun{activeStake}~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}~ \var{#5}}
\newcommand{\poolRefunds}[3]{\fun{poolRefunds}~ \var{#1}~ \var{#2}~ \var{#3}}
\newcommand{\poolStake}[3]{\fun{poolStake}~ \var{#1}~ \var{#2}~ \var{#3}}
\newcommand{\stakeDistr}[3]{\fun{stakeDistr}~ \var{#1}~ \var{#2}~ \var{#3}}
\newcommand{\lReward}[4]{\fun{r_{operator}}~ \var{#1}~ \var{#2}~ \var{#3}~ {#4}}
\newcommand{\mReward}[4]{\fun{r_{member}}~ \var{#1}~ \var{#2}~ \var{#3}~ {#4}}
\newcommand{\poolReward}[5]{\fun{poolReward}~\var{#1}~{#2}~\var{#3}~\var{#4}~\var{#5}}
\newcommand{\createRUpd}[2]{\fun{createRUpd}~\var{#1}~\var{#2}}

In order to handle rewards and staking, we must change the stake distribution
calculation function to add up only the Ada in the UTxO
 before performing any calculations. In Figure~\ref{fig:functions:stake-distribution}
 below, we do so using the function $\fun{utxoAda}$, which returns the amount of Ada
 tokens in an address.

%%
%% Figure Functions for Stake Distribution
%%
\begin{figure}[htb]
  \emph{Helper function}
  %
  \begin{align*}
    & \fun{utxoAda} \in \UTxO \to \Addr \to \Coin \\
    & \fun{utxoAda}~{\var{utxo}}~\var{addr} ~=~\sum_{\var{out} \in \range \var{utxo}, \fun{getAddr}~\var{out} = \var{addr}} \fun{getCoin}~\var{out}
  \end{align*}
  %
  \emph{Stake Distribution (using functions and maps as relations)}
  %
  \begin{align*}
      & \fun{stakeDistr} \in \UTxO \to \DState \to \PState \to \Snapshot \\
      & \fun{stakeDistr}~{utxo}~{dstate}~{pstate} = \\
      & ~~~~ \big((\dom{\var{activeDelegs}})
      \restrictdom\left(\fun{aggregate_{+}}~\var{stakeRelation}\right),
    ~\var{delegations},~\var{poolParams}\big)\\
      & \where \\
      & ~~~~ (~\var{rewards},~\var{delegations},~\var{ptrs},~\wcard,~\wcard,~\wcard)
        = \var{dstate} \\
      & ~~~~ (~\var{poolParams},~\wcard,~\wcard) = \var{pstate} \\
      & ~~~~ \var{stakeRelation} = \left(
        \left(\fun{stakeCred_b}^{-1}\cup\left(\fun{addrPtr}\circ\var{ptr}\right)^{-1}\right)
        \circ\left(\hldiff{\fun{utxoAda}}~{\var{utxo}}\right)
        \right)
        \cup \left(\fun{stakeCred_r}^{-1}\circ\var{rewards}\right) \\
      & ~~~~ \var{activeDelegs} =
               (\dom{rewards}) \restrictdom \var{delegations} \restrictrange (\dom{poolParams})
  \end{align*}

  \caption{Stake Distribution Function}
  \label{fig:functions:stake-distribution}
\end{figure}


\subsection{Volatility and implied volatility}


\documentclass{article}
\usepackage{fullpage}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{url}
\usepackage{cite}
\usepackage{xcolor,colortbl}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{chains,3d}

\newcommand{\Exp}{\text{exp}}

\begin{document}
	\hfill \textbf{Vector embeddings of time series data with linear properties}

	\hfill Ben Black

	\section{Vector embeddings}

	Dense data, such as images, video, and audio, is extremely high dimensional in its raw form. For many important tasks, especially information retrieval, it is extremely useful to be able to embed the important parts of the image in a vector of manageable dimension (typically on the order of 100 dimensions). Once the vectors are computed, similar images can be grouped by the similarity of their embeddings.

	This paper describes a new fast embedding algorithm for audio, but it can be easily generalized to other time series data.

	\section{Generative vector embeddings}

	The idea of an embedding is taken from generative models. Take some data $A_1,A_2,A_3,...$, you want an embedding function $f$ and a decoding function $g$ such that $g(f(A_i)) \sim A_i$, where $\sim$ is some approximation relation, and the output of $f$ is smaller than the size of $A$. Then $f(A)$ is the embedding of $A$.

	In less mathematical terms, $f$ can be seen as a lossy compression function which compresses the data (say, a 600x800 photograph), to an embedding, say a 50 dimensional floating point vector. $g$ is the decompression function which attempts to generate an image based only on the vector.

	In the deep learning paradigm, it is easy to see how to construct such an $f$ and $g$, given a $\sim$ and a dataset. It is simply to turn the approximation relation to a cost function, make $f$ and $g$ some neural network architecture, and minimize the cost of $g(f(A_i)) \sim A_i$.

	The biggest problem with this model is coming up with an appropriate approximation relation $\sim$. Humans can easily tell which images are similar and different, yet when pressed, it is clear that this similarity cannot be easily described in terms of color channel magnitudes. For example, two cars, one red and one blue will have very different color channels, but humans would say that the images are quite similar compared to an image of a dog.

	The deep learning community's solution is adversarial networks. %In an adversarial network, after $g$ has output an image,
	Intuitively, a generative network can be seen as a counterfitter artist, which cheaply produces images based on incomplete information about the art. The adversarial network is the authority which tries to tell counterfitted art from the real deal. In the end, we hope that the counterfitter gets better and better at producing realistic images in order to fool the authority, while the authority gets better and better and forces the counterfitter to improve even further.

	More precisely, an adversarial network is a function $c$ which tries to guess whether the image $\bar{A}$ was generated by $g(f(A))$, or if it is in fact the original $A$. This adversarial network is trained separately from the generative network.

	Thus, the adversarial network $c$ is attempts to optimize these two probabilities
	$$P[c(g(f(A_i))) = 0]$$
	$$P[c(A_i) = 1]$$
	It is very important that $f$ and $g$ are fixed when $c$ is training, or this would be trivially solvable.

	While the generative network ($f$ and $g$) is trained to optimize the value of
	$$P[c(g(f(A_i))) = 1]$$
	While holding $c$ fixed.

	The adversarial and generative networks are then trained in an alternating sequence, so both the networks can learn from the success of the other.

	When training is finished, remember the embedding is simply calculated by running $f(A)$, and so it can apply to data outside the original training dataset, although it is not guaranteed to generate a good embedding.

	%\subsection{Problems}

	%Using generative vector embeddings which are constructed as described above leads to two major issues which prevent them from being used for many important purposes, including information retrieval. One is that the vectors are not guaranteed to have any substantive algebraic qualities. The other is that these models are not equipped to handle large inputs and outputs.

	\subsubsection{Similarity of generative embeddings}

	In the classical generative embeddings described above, the embedding vector is only consumed by a single function, the decoding function $g$. Ideally, though, we want to use this vector for purposes other than applying $g$. In this paper, we will focus on using the vector for information retrieval. One important function for information retrieval is the similarity relation, which takes in two inputs and outputs a number which represents how similar the inputs are to each other.

	Unfortunately, with the generative networks, there is no guarantee that classical vector similarity calculations, like squared distance or cosine distance accurately represent distance of vectors. This is because even 3 layer neural networks are universal approximators, meaning that if the network is large enough, the network can approximate any function to any degree, even highly discontinuous ones. In reality, of course, neural networks are finite and the weights are trained in a very particular way, so they do have some good properties, but we cannot a-priori say what they are. Of course, many studies have tried to fill in this gap in theory with actual results, and many of them look somewhat promising. The most promising one is the "traveling along a dimension property" (CITE case of this). However, similarity relations is not one of those promising results. This is one reason why we need a new general embedding algorithm for dense data.

	\subsubsection{Large Data}

	Generative networks as described above have had significant success with low resolution images and audio, and more limited success with high resolution images. However, we sometimes want to get vectors of much larger data sources, for example, video. Generating more than a handful of frames of even a video would be an astronomically difficult task for a neural network, and would require enormous embeddings, and slow training. This raises the question of why we are trying to generate things in the first place if all we want is a vector. One sort of hacky solution is to average many vectors, for example make a video vector by averaging many image vectors, but averages and other cumulative methods are not likely to be good representations because of the problem with algebraic qualities mentioned above.

	%Deep neural networks are functions with fixed input and output. Currently, the only well understood way of handling inputs with variable input is with recurrent networks, networks which the output of one iteration feeds into the next. The typical way of handling embeddings with these networks is to feed in the entire dataset one section at a time, and then have the network try to generate the whole dataset back, one step at a time. Unfortunately, with current state of the art (deep LSTMs), this method does not give good results for large numbers of steps (over 50 time steps). At hand here is an even

	\section{Sparse embeddings for word2vec}

	One of the major advances in vector embeddings was Thomas Miktov's word2vec algorithm. This algorithm is based on the same ideas as the generative networks described above, but specialized for sequences of sparse data such as words. There are two ideas in word2vec that are critical to this work. First is to compare local context to global content, instead of generating data. Second is to rephrase the prediction problem into terms of individual vectors, instead of dense matrices.

	First, lets review the basic ideas behind word2vec. The key idea behind word2vec is that the semantic meaning of a word can be described by the frequency of the words in its context. The skip-gram model leverages that by using one word in a context to try to predict other words in its context. In probabilistic terms, this means trying to estimate
	$$P[w_1 | w_2]$$ Within some specific window.

	This model is very slow in its original form because of the softmax classification at the end. Recall that the softmax is computed by the following formula

	$$ \frac{\Exp(W_i x)}{\sum_j \Exp(W_j x)}$$
	In terms of the skip-gram model, $x$ would be the word vector embedding, and $W$ would be the output layer. Unfortunately, the output layer of the skip gram model scales in terms of the vocabulary size, so in order to calculate the denominator of the fraction, the algorithm needs $$(\text{vocab size}) * (\text{embedding size})$$
	Word2vec eventually solved this problem with negative sampling. The idea is to approximate the denominator by sampling a subset of the output weight vectors, instead of the entire thing.
	$$ \frac{\Exp(W_i x)}{\sum_{j \in S} \Exp(W_j x)}$$
	$S$ is then chosen randomly from the set of words, but not uniformly: more frequent words are chosen more often than less frequent words.

	These manipulations of the generative equation give rise to a completely new interpretation of what is going on:

	Positive sample: words $i$ and $j$ are found in the same context. Then compute $W_i O_j$.

	Negative sample: word $k$ is sampled randomly from the input. Compute $W_i O_k$.

	Then the negative sample should have a low value as to compared to the positive sample.

	\section{Dense discriminative embeddings}

	There has been some past work on discriminative embeddings, rather than predictive embeddings. My work will follow in their footsteps. The most successful version of this is "Look, Learn, Listen" or L$^3$. These models are very powerful in the way that they say what things go where. Unfortunately, attempts to use intra-model learning through spacial reconstructions, etc have fallen far short of supervised learning techniques. \cite{DBLP:journals/corr/NorooziF16} Our goal is to have a better embedding system than them.

	It is useful to see how these intra-model embeddings work. All of them try to extract high level information by using high level patterns in images. Some try to extract feature position information such as different parts of an animal by artificially creating and solving a jigsaw puzzle. Others look at frames in a video and try to extract position using match mismatch tuples. Others use gray scale to try to predict color. All of them can be termed as missing information problems. Unfortunately, the information these networks extract to solve the missing information problem never seem to be as useful a the information that supervised networks learn to find labels.

	Meanwhile, other techniques, such as unsupervised learning which assumes no specific structure in the input, such as (CITE: ADVERSARIAL FEATURE LEARNING), do even worse.

	Instead of hand-engineering a missing information problem, we will train the network to learn the best best possible missing information problem to solve using reinforcement learning, while solving that problem.

	Another way of describing this problem is scene exploration, with the goal of finding "surprising elements" in the scene.

	%But all them them try to extract high level featuring using high level patterns.
	%Our technique is fundamentally different in all of these is that it extracts much lower level features first, and then builds upon them to form high level features. This way, nwe hope that it captures many different aspects of the image relatively well, instead of just capturing enough to solve the contrived high level problem.

	\section{Algorithm}

	The algorithm is a neural network trying to approximate a match/mismatch problem. The match case is two local sound vector, the mismatch case is two vectors sampled uniformly from the entire dataset.

	\begin{tikzpicture}[scale=0.6,mainnode/.style={font=\sffamily\footnotesize\bfseries}]
	\draw [->] (0,0) -- node[pos=-0.2] {time} (5,0);
	\foreach \tick in {0,1,2,3,4,5,6,7,8,9}
	\draw [-] (0.5*\tick,0) -- node[pos=-1.5] {\tick} (0.5*\tick,0.3);
	\draw [-] (1.5,-1) --  (1.5,-1.5);
	\draw [-] (3.5,-1) --  (3.5,-1.5);
	\draw [-] (1.5,-1.5) -- node[anchor=north] {Window} (3.5,-1.5);
	\end{tikzpicture}

	The mismatch case has the pair of data drawn uniformly from the entire dataset.

	Song ID vector

	\section{Results}

	To test the qualities of these vectors, they were \cite{DBLP:journals/corr/abs-1712-06651}

	\bibliography{project_proposal}{}
	\bibliographystyle{plain}

\end{document}


    \filetitle{subsasgn}{Subscripted assignment for model and systemfit objects}{model/subsasgn}

	\paragraph{Syntax for assigning parameterisations from other
object}\label{syntax-for-assigning-parameterisations-from-other-object}

\begin{verbatim}
M(Inx) = N
\end{verbatim}

\paragraph{Syntax for deleting specified
parameterisations}\label{syntax-for-deleting-specified-parameterisations}

\begin{verbatim}
M(Inx) = []
\end{verbatim}

\paragraph{Syntax for assigning parameter values or steady-state
values}\label{syntax-for-assigning-parameter-values-or-steady-state-values}

\begin{verbatim}
M.Name = X
M(Inx).Name = X
M.Name(Inx) = X
\end{verbatim}

\paragraph{Syntax for assigning std deviations or cross-correlations of
shocks}\label{syntax-for-assigning-std-deviations-or-cross-correlations-of-shocks}

\begin{verbatim}
M.std_Name = X
M.corr_Name1__Name2 = X
\end{verbatim}

Note that a double underscore is used to separate the Names of shocks in
correlation coefficients.

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

\begin{itemize}
\item
  \texttt{M} {[} model \textbar{} systemfit {]} - Model or systemfit
  object that will be assigned new parameterisations or new parameter
  values or new steady-state values.
\item
  \texttt{N} {[} model \textbar{} systemfit {]} - Model or systemfit
  object compatible with \texttt{M} whose parameterisations will be
  assigned (copied) into \texttt{M}.
\item
  \texttt{Inx} {[} numeric {]} - Inx of parameterisations that will be
  assigned or deleted.
\item
  \texttt{Name}, \texttt{Name1}, \texttt{Name2} {[} char {]} - Name of a
  variable, shock, or parameter.
\item
  \texttt{X} {[} numeric {]} - A value (or a vector of values) that will
  be assigned to a parameter or variable Named \texttt{Name}.
\end{itemize}

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

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{M} {[} model \textbar{} systemfit {]} - Model or systemfit
  object with newly assigned or deleted parameterisations, or with newly
  assigned parameters, or steady-state values.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}

Expand the number of parameterisations in a model or systemfit object
that has initially just one parameterisation:

\begin{verbatim}
m(1:10) = m;
\end{verbatim}

The parameterisation is simply copied ten times within the model or
systemfit object.


\documentclass[namedreferences]{solarphysics}

\usepackage[hyperref,optionalrh]{spr-sola-addons} % For Solar Physics
%\usepackage[optionalrh]{spr-sola-addons} % For Solar Physics
%\usepackage{epsfig}          % For eps figures, old commands
\usepackage{graphicx}        % For eps figures, newer & more powerfull
%\usepackage{courier}         % Change the \texttt command to courier style
%\usepackage{amssymb}        % useful mathematical symbols
\usepackage{color}           % For color text: \color command
\usepackage{breakurl}        % For breaking URLs easily trough lines
\def\UrlFont{\rm}                        % define the fonts for the URLs

% General definitions
% please place your own definitions here and don't use \def but
% \newcommand{}{} or
% \renewcommand{}{} if it is already defined in LaTeX

\newcommand{\BibTeX}{\textsc{Bib}\TeX}
\newcommand{\etal}{et al.}

% Definitions for equations
\renewcommand{\vec}[1]{{\mathbfit #1}}
\newcommand{\deriv}[2]{\frac{{\mathrm d} #1}{{\mathrm d} #2}}
\newcommand{\rmd}{ {\ \mathrm d} }
\newcommand{\uvec}[1]{ \hat{\mathbf #1} }
\newcommand{\pder}[2]{ \f{\partial #1}{\partial #2} }
\newcommand{\grad}{ {\bf \nabla } }
\newcommand{\curl}{ {\bf \nabla} \times}
\newcommand{\vol}{ {\mathcal V} }
\newcommand{\bndry}{ {\mathcal S} }
\newcommand{\dv}{~{\mathrm d}^3 x}
\newcommand{\da}{~{\mathrm d}^2 x}
\newcommand{\dl}{~{\mathrm d} l}
\newcommand{\dt}{~{\mathrm d}t}
\newcommand{\intv}{\int_{\vol}^{}}
\newcommand{\inta}{\int_{\bndry}^{}}
\newcommand{\avec}{ \vec A}
\newcommand{\ap}{ \vec A_p}

\newcommand{\bb}{\vec B}
\newcommand{\jj}{ \vec j}
\newcommand{\rr}{ \vec r}
\newcommand{\xx}{ \vec x}

% Definitions for the journal names
\newcommand{\adv}{    {\it Adv. Space Res.}}
\newcommand{\annG}{   {\it Ann. Geophys.}}
\newcommand{\aap}{    {\it Astron. Astrophys.}}
\newcommand{\aaps}{   {\it Astron. Astrophys. Suppl.}}
\newcommand{\aapr}{   {\it Astron. Astrophys. Rev.}}
\newcommand{\ag}{     {\it Ann. Geophys.}}
\newcommand{\aj}{     {\it Astron. J.}}
\newcommand{\apj}{    {\it Astrophys. J.}}
\newcommand{\apjl}{   {\it Astrophys. J. Lett.}}
\newcommand{\apss}{   {\it Astrophys. Space Sci.}}
\newcommand{\cjaa}{   {\it Chin. J. Astron. Astrophys.}}
\newcommand{\gafd}{   {\it Geophys. Astrophys. Fluid Dyn.}}
\newcommand{\grl}{    {\it Geophys. Res. Lett.}}
\newcommand{\ijga}{   {\it Int. J. Geomagn. Aeron.}}
\newcommand{\jastp}{  {\it J. Atmos. Solar-Terr. Phys.}}
\newcommand{\jgr}{    {\it J. Geophys. Res.}}
\newcommand{\mnras}{  {\it Mon. Not. Roy. Astron. Soc.}}
\newcommand{\nat}{    {\it Nature}}
\newcommand{\pasp}{   {\it Pub. Astron. Soc. Pac.}}
\newcommand{\pasj}{   {\it Pub. Astron. Soc. Japan}}
\newcommand{\pre}{    {\it Phys. Rev. E}}
\newcommand{\solphys}{{\it Solar Phys.}}
\newcommand{\sovast}{ {\it Soviet  Astron.}}
\newcommand{\ssr}{    {\it Space Sci. Rev.}}
\chardef\us=`\_

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

\begin{article}
\begin{opening}

\title{Article Preparation Guidelines for {\it Solar Physics}}

\author[addressref={aff1,aff2,aff3},email={e-mail.a@mail.com}]{\inits{F.N.}\fnm{First~Names}~\lnm{Last~Name~Author-a}\orcid{123-456-7890}}
\author[addressref=aff1,email={e-mail.b@mail.com}]{\inits{F.}\fnm{First~Names}~\lnm{Last~Name~Author-b}}
\author[addressref=aff2,corref,email={e-mail.c@mail.com}]{\inits{F.}\fnm{First~Names}~\lnm{Last~Name~Author-c}\orcid{987-654-3210}}
\author[addressref=aff3]{\inits{T.}\fnm{First~Names}~\lnm{Last~Name~Author-d}}
%\author{\inits{}\fnm{}~\lnm{}\orcid{}}
%   NOTE:  Just one corresponding author [corref]
%   \institute{$^{1}$ First affiliation
%                     email: \url{e.mail-a} email: \url{e.mail-b}\\
%              $^{2}$ Second affiliation
%                     email: \url{e.mail-c} \\
%             \textit{}
\address[id=aff1]{First very very very very very very very very very
 very very very very very very very very very very very very very very very very very very long affiliation and address}
\address[id=aff2]{Institution, City, State, Country}
\address[id=aff3]{Third affiliation and address}

\runningauthor{Author-a et al.}
\runningtitle{\textit{Solar Physics} Example Article}

\begin{abstract}
This is an example article for manuscripts for the journal {\it Solar
Physics}. It contains the basic commands to write an article as well
as some explanations for defining equations, figures, tables,
and references.
The abstract should be one paragraph long.  It should summarize
the results of the article, with just enough background to clearly state the
problem being addressed.
Please do not just repeat text from the introduction and conclusion.
Any references should be fully expanded, as the abstract can appear
without the full article, and its reference list;
{\it e.g.} \citeauthor{Dupont07} (\solphys{} \textbf{323}, 965,
\citeyear{Dupont07}).
Please make sure that the language of the article has been reviewed by a
scientist fluent in English, or an editorial professional.
Check that all of the citations in the text are in the reference list at the
end, and that there are not extraneous references, preferably by using
\BibTeX . If you do not run a spell check on your article, do not expect
your reader to believe that you were any more careful in your science.
Choose your keywords from the list provided in the file
\texttt{sola\us keyword\us list.txt}.
\end{abstract}
\keywords{Flares, Dynamics; Helicity, Magnetic; Magnetic fields, Corona}
\end{opening}
%-------------------------------------------------

\section{Introduction}
     \label{S-Introduction}

This file describes the use of special \LaTeX\ features,
useful to format an article for {\it Solar Physics}.  It is only a complement
to the \LaTeX\ and \BibTeX\ documentation.
It is designed to be used as an example
article giving the general commands. When compiled with \LaTeX\
(see Section~\ref{S-BibTeX} for \BibTeX\ compilation), it provides
some practical guidance on the main useful features. More information
is included within this file, but commented out (with a \%).
Un-commenting the \LaTeX\ commands permits one to show their
results in the compiled file.

  %{\S}{\bf --- Road map of the article} \\
    % When writing a article, it is worth to define a title for each paragraph:
    %   gives a roadmap for the article logic.
    % Replacing automatically all the ``%{\S}{\bf'' by ``{\S}{\bf''
    % brings these titles in the typeset of the article.
 Section~\ref{S-general} gives examples and some general information
to aid writing text with citations (Section~\ref{S-text})
and defining labels (Section~\ref{S-labels}).
Section~\ref{S-features} gives examples of equations
(Section~\ref{S-equations}), figures (Section~\ref{S-figures}), and
tables (Section~\ref{S-tables}).
It continues by describing the inclusion of labeled references
(Section~\ref{S-references}) and suggestions for an easy construction
of a list of references (Section~\ref{S-BibTeX}).
An appendix is shown as a particular section (Appendix~\ref{S-appendix}),
which can contain figures and tables (Figure~\ref{F-appendix},
Table~\ref{T-appendix}).
There is a list of abbreviations used for the main journals (see the
beginning of this \texttt{.tex} file, or the companion
 \verb+sola_example_labels.tex+
file, for the definition of the \LaTeX\ commands.
Our conclusions are given in Section~\ref{S-Conclusion}.

\section{Authors, emails and affiliations}
\label{S-aug}
Authors, their emails and their affiliations should be typsed with commands:
\verb+\author[key=val,key,..]{}+ and \verb+\address[key=val]{}+.

Command \verb+\author+  has an optional parameter with available keys:
\begin{itemize}
\item \verb+addressref=<address_id1,address_id2,..>+ -- makes numbered marks of affiliations with the same \texttt{id}.
\item \verb+email=<authors_email>+ -- outputs author and email in the footnotes area.
\item \verb+corref+ -- marks this author as a corresponding one and outputs him (and his email) in the footnotes area with envelope icon in front.
\end{itemize}
Mandatory parameter -- authors name, which should be tagged in three commands:
\begin{itemize}
\item \verb+\inits+ -- is used for author's initials (will be outputed before author's name in the footnotes area).
\item \verb+\fnm+ -- is used for author's first name.
\item \verb+\lnm+ -- is used for author's last name.
\item \verb+\orcid+ -- is used for author's ORCID identifier (will be outputed \textit{orcid.eps} image with a link to \verb+https://orcid.org/+\textit{identifier}.
\end{itemize}

Command \verb+\address+ has optional parameter  with one key -- \texttt{id}, which is used to combine author and affiliation with the same mark.
All affiliations are outputed in footnotes area right after the emails.

\section{General Text} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \label{S-general}

\subsection{Text with Citations} %%%%%%%%%%%%%%
  \label{S-text}
This section gives an example of text with references
included with the \verb+\citep{}+ and \verb+\citealp{}+ commands
(see Section~\ref{S-references} about citation commands).

   %{\S}{\bf --- Introduction of H.  What is it ?} \\
Magnetic helicity quantifies how the magnetic field is sheared
and/or twisted compared to its lowest energy state (potential
field). Observations of sheared, and even helical, magnetic
structures in the photosphere, corona and solar wind have
attracted considerable attention, with the consequent interest in
magnetic helicity studies (see reviews by \citealp{Brown99}, and,
\citealp{Berger03}). Stressed magnetic fields are often observed
in association with flares, eruptive filaments, and coronal mass
ejections (CMEs), but the precise role of magnetic helicity in
such activity events still needs to be clarified.

   %{\S}{\bf --- Theoretical use of H} \\
Magnetic helicity plays a key role in magnetohydrodynamics (MHD)
because it is almost preserved on a timescale less than the global
diffusion timescale (\citealp{Berger84}, \citeyear{Berger03}).
Its conservation defines a
constraint on the magnetic field evolution; in particular a
stressed magnetic field with finite total helicity cannot relax to
a potential field.  Thus magnetic helicity is at the heart of
several MHD relaxation theories, for example of coronal heating
\citep{Heyvaerts84} but also of flares \citep{Kusano04,Melrose04}.
The permanent accumulation of helicity in the corona could be
vital to the origin of CMEs \citep{Rust94,Low97}.  In the
convection zone, the accumulation of helicity in large scales
limits the efficiency of the dynamo, thus the conservation of
magnetic helicity is responsible for dynamo saturation, the
so-called $\alpha$-effect quenching \citep{Brandenburg01}.

\subsection{Importance of Using Labels} %%%%%%%%%%%%%%
  \label{S-labels}

  %{\S}{\bf --- Why using labels ?} \\
    \LaTeX\ defines labels for many features like sections,
equations, figures, tables, and citations.  The systematic use
of these labels greatly facilitates the writing of a scientific
article (even if it may appear as more extra work at the beginning).
Indeed, it permits one to re-number or re-order automatically the
features during the compilation ({\it e.g.} when adding or moving a
section).  It also permits one to
cross check automatically whether the citations have been included
in the bibliography list.

  %{\S}{\bf --- How to use labels} \\
    Labels are powerful but their use can be cumbersome if some
clear logic is not used in defining them since one can easily
forget the exact defined label ({\it e.g.} case sensitive).
A label should be simple
while reflecting precisely what it refers to. It is very helpful
to create a small auxiliary file where all these labels are
kept (see the \verb+sola_example_labels.tex+
accompanying the present file).
It also provides a roadmap of the article with the list
of the sections and subsections with the equations introduced in each.
Including the full command ({\it e.g.} \verb+Section~\ref{S-labels}+)
permits one to do a simple copy/paste when needed (rather than moving
through the \texttt{.tex} file looking for the definition of the label).
It is also useful that
\verb+sola_example_labels.tex+   file contains the copy of the
new commands, as well as the citation commands. For references,
the simple convention of concatenating the first author's name and the year
(and eventually a letter), is simple enough to be easily remembered.

\section{Including Special Features} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \label{S-features}

\subsection{Examples of Equations} %%%%%%%%%%%%%%
  \label{S-equations}
Here are a few examples of equations. It is useful to define
a new command when a combination of symbols is present at several
locations, for example:\\
  \verb+ \renewcommand{\vec}[1]{{\mathbfit #1}} +
(see the beginning of present \texttt{.tex} file for more examples).
The mathematics style is to set operators such as ``d'', ``ln'', ``log'',
``curl'', \textit{etc.} in roman, not italic.
The following math fonts should be used:
\begin{itemize}
\item Scalar: slant \verb+\mathit+
\item Vector: bold slant \verb+\mathbfit+
\item Matrix: bold \verb+\mathbf+
\item Tensor: calligraphic \verb+\mathcal+
\end{itemize}

\subsubsection{Simple Equations} %%%%%%%%%%%%%%
  \label{S-simple-equations}
 The magnetic helicity of the magnetic field ($\vec{B}$) fully contained
within a volume $\vol $ is \citep{Elsasser56}:
   \begin{equation}  \label{Eq-H-def}
     H^{\rm closed} = \intv \avec \cdot \bb \dv \,.
   \end{equation}

\subsubsection{Array of Equations} %%%%%%%%%%%%%%
  \label{S-array-equations}
The vector potential ($\avec$) can be written as a function of $\bb$
within the Coulomb gauge:
   \begin{eqnarray}
     \avec (\xx) &=& \mu_{0}\intv \frac{\jj (\xx  ^\prime)}
                     { | \xx - \xx  ^\prime |} \dv ^\prime
                       \nonumber \\      % \\ indicates the equation end
                 &=& \frac{1}{4\pi} \int \bb (\xx ^\prime ) \times
                     \frac{(\xx  - \xx ^\prime)}{\,\, |\xx - \xx ^\prime |^3}
                                           \dv ^\prime   \,.
                       \label{Eq-A-B}    % No ``\\'' for the last equation
   \end{eqnarray}

Then the magnetic helicity can be written as a function of $\bb$
alone \citep{Moffatt69}. An approximation of this double integral
can be realized by splitting
the magnetic field in $N$ flux tubes \citep{BergerF84}:
   \begin{eqnarray}
    H^{\rm closed} &=& \frac{1}{4\pi} \intv \intv
                      \bb (\xx ) \times \bb (\xx ^\prime )
                      \cdot \frac{(\xx  - \xx ^\prime)}{\,\, |\xx - \xx ^\prime |^3}
                      \dv \dv ^\prime \,,                     \label{Eq-H-B} \\
                  &\approx & \sum_{i=1}^N T_i^{\rm closed} \Phi_i^2
                           + \sum_{i=1}^N \sum_{j=1,j \neq i}^N
                             {\mathcal L}^{\rm closed}_{i,j} \Phi_i \Phi_j  \,.
                       \label{Eq-H-N}     % No ``\\'' for the last equation
   \end{eqnarray}
where $\Phi_i$ and $T_i^{\rm closed}$ are the magnetic flux and the
self helicity of flux tube $i$ respectively ($T_i^{\rm closed}$
includes both twist and writhe), and ${\mathcal L}^{\rm
closed}_{i,j}$ is the mutual helicity between flux tubes $i$ and
$j$.

\subsubsection{Long Equations} %%%%%%%%%%%%%%
  \label{S-long-equations}
 A long equation is broken into several lines:
      \begin{eqnarray}
      \deriv{H}{t} &=&
                    \frac{1}{2 \pi} \int_{\Phi } \int_{\Phi }
                    \left(   \deriv{ \theta (\xx _{c_-} -\xx _{a_+}) }{t}
                           + \deriv{ \theta (\xx _{c_+} -\xx _{a_-}) }{t}
                    \right.                            \nonumber  \\
       && \qquad \qquad \;
                    \left. - \deriv{ \theta (\xx _{c_+} -\xx _{a_+}) }{t}
                         -\, \deriv{ \theta (\xx _{c_-} -\xx _{a_-}) }{t}
                    \right)
                    \rmd \Phi_{a} \rmd \Phi_{c}  \,. \label{Eq-dH-Phi}
      \end{eqnarray}
A fine tuning of the positions can be obtained with the following spacing commands
(\verb+\!+ is a negative thin space):
     \begin{eqnarray}
     \verb+\! + |\!| \,\  \qquad &    \! \verb+  \, + |\,|
                          & \qquad    \verb+    \: + |\:|       \nonumber \\
     \verb+\ + |\ |       \qquad &    \verb+\quad + |\quad|
                          & \qquad    \verb+\qquad + |\qquad|   \nonumber
     \end{eqnarray}

  \begin{figure}    %%%%%%%%%%%%%%%%%% FIGURE 1
   \centerline{\includegraphics[width=0.5\textwidth,clip=]{fig1a.eps}
              }
              \caption{Example of a simple figure with only one panel.
Relative units (here \texttt{$\backslash$textwidth}) are preferred
so that the figure adapts automatically to the text width (this command is very useful
in more complex figures such as Figures~\ref{F-4panels} and~\ref{F-rotate-cut}).
The use of the command \texttt{$\backslash$includegraphics} requires the
inclusion of \texttt{$\backslash$usepackage\{graphicx\}} at the beginning of the
\LaTeX\ file.
                      }
   \label{F-simple}
   \end{figure}

  \begin{figure}    %%%%%%%%%%%%%%%%%% FIGURE 2
                                % includes the two top panels
   \centerline{\hspace*{0.015\textwidth}
               \includegraphics[width=0.515\textwidth,clip=]{fig1a.eps}
               \hspace*{-0.03\textwidth}
               \includegraphics[width=0.515\textwidth,clip=]{fig1b.eps}
              }
     \vspace{-0.35\textwidth}   % Shift close to the panel top
     \centerline{\Large \bf     % Includes the labels (here needs the color
                                %   package, see beginning of this file)
      \hspace{0.0 \textwidth}  \color{white}{(a)}
      \hspace{0.415\textwidth}  \color{white}{(b)}
         \hfill}
     \vspace{0.31\textwidth}    % Shift back to the panel bottom
%
   \centerline{\hspace*{0.015\textwidth}
               \includegraphics[width=0.515\textwidth,clip=]{fig1c.eps}
               \hspace*{-0.03\textwidth}
               \includegraphics[width=0.515\textwidth,clip=]{fig1d.eps}
              }
     \vspace{-0.35\textwidth}   % Shift close to the panel top
     \centerline{\Large \bf     % Includes the labels (here needs the color package)
      \hspace{0.0 \textwidth} \color{white}{(c)}
      \hspace{0.415\textwidth}  \color{white}{(d)}
         \hfill}
     \vspace{0.31\textwidth}    % Shift back to the panel bottom

\caption{Example of a figure with four panels (constructed with
four \texttt{.eps} files).
The labels of the panels are included with \LaTeX\ commands
so that each panel can be referred to unambiguously in the text.
The position of the panels
is fine-tuned with the \texttt{$\backslash$hspace} and
\texttt{$\backslash$vspace} commands.
        }
   \label{F-4panels}
   \end{figure}

%% The following show the use of the epsfig package.
%%    Un-comment the relevant parts if needed
%%    Un-comment the \usepackage{epsfig} line at the top of this file
%  \begin{figure}    %%%%%%%%%%%%%%%%%% FIGURE 2 bis
%   \centerline{\epsfig{file=fig1a.eps,width=0.51\textwidth,clip=}
%               \hspace*{-0.03\textwidth}
%               \epsfig{file=fig1b.eps,width=0.51\textwidth,clip=}
%              }
%    \vspace*{0.003\textwidth}
%   \centerline{\epsfig{file=fig1c.eps,width=0.51\textwidth,clip=}
%               \hspace*{-0.03\textwidth}
%               \epsfig{file=fig1d.eps,width=0.51\textwidth,clip=}
%              }
%  \centerline{\includegraphics[width=\textwidth,clip=]{fig1.eps} }
%\caption{Example of figure with four panels.}
%   \label{F-4panels-bis}
%   \end{figure}

  \begin{figure}    %%%%%%%%%%%%%%%%%% FIGURE 3   rotation + cut
% Original BoundingBox (in the .eps files) : 54 360 558 720
%   corresponds to the coordinates of: left, bottom, right, top   (unrotated)
   \centerline{\includegraphics[width=0.4\textwidth,clip=,
                 bb=54 440 488 660,angle=-90]{fig1a.eps}
               \includegraphics[width=0.4\textwidth,clip=,
                 bb=54 440 488 660,angle=-90]{fig1b.eps}
               \includegraphics[width=0.4\textwidth,clip=,
                 bb=54 440 488 660,angle=-90]{fig1c.eps}
               \includegraphics[width=0.4\textwidth,clip=,
                 bb=54 440 488 660,angle=-90]{fig1d.eps}
              }
     \vspace{-0.39\textwidth}   % Shift close to the panel top
     \centerline{\Large \bf     % Includes the labels (here needs the color package)
      \hspace{0.07\textwidth}   \color{white}{(a)}
      \hspace{0.122\textwidth}  \color{black}{(b)}
      \hspace{0.122\textwidth}  \color{white}{(c)}
      \hspace{0.122\textwidth}  \color{white}{(d)}
         \hfill}
     \vspace{0.36\textwidth}    % Shift back to the panel bottom
\caption{Example of a figure with panels smaller
than the original and rotated clockwise by 90$^{\circ}$
(compare with Figure~\ref{F-4panels}). The \texttt{clip=}
command is important to include only the selected part of the figure
by changing the \texttt{BoundingBox}.
The labels of the panels are included using \LaTeX\ commands.
        }
   \label{F-rotate-cut}
   \end{figure}

\subsection{Examples of Figures} %%%%%%%%%%%%%%
  \label{S-figures}
  %{\S}{\bf --- Main features} \\
 A simple figure is presented as Figure~\ref{F-simple}. When more
than one panel is present, one should add labels for those individual panels.
One can add labels to a figure by using \LaTeX\ as done
in Figures~\ref{F-4panels} and~\ref{F-rotate-cut}.
The package \verb+\usepackage{color}+
can be used to write text ({\it e.g.} labels) in white or in color.
Figures can be rotated and their position fine tuned
(Figures~\ref{F-4panels} and~\ref{F-rotate-cut}).

  %{\S}{\bf --- Cutting a figure in the .eps file} \\
  Cutting a figure can be made by editing the \texttt{.eps}
file with a text editor, and changing the \texttt{BoundingBox},
then saving the file (do not use a text editor designed for \LaTeX\ since
it could open the file as a figure, and not as a text file).
An \texttt{.eps} file has typically the command
\verb+ %%BoundingBox: 54 360 558 720 +
at the beginning, where the numbers are the left, bottom, right, and top
coordinates of the graphic (in units of ``pt'').
Changing these numbers is a way to reduce the part of the image shown.
The \texttt{GhostView} application gives the coordinates
of the cursor (in units of ``pt''), so it permits one to locate the
coordinates of the cropping.
The result of the changes can be checked using \texttt{GhostView}.
 Note that, depending on the software used to create the \texttt{.eps} file,
the \texttt{BoundingBox} can be repeated at several places in the
\texttt{.eps} file ({\it e.g.} with \texttt{PageBoundingBox}).
Also, with some software,
the \texttt{BoundingBox} is defined only close to the end of the file
(the file has at the beginning: \texttt{BoundingBox: (atend)}).
The \texttt{BoundingBox} can still be changed
in place, or defined at the beginning of the \texttt{.eps} file.
   Finally, this method provides a figure with a reduced size, when
included in \LaTeX\ (do not forget the \texttt{clip=}
in the command including the \texttt{.eps} file!).
The advantage of this method is that the correct \texttt{BoundingBox}
is easily determined.

  %{\S}{\bf --- Cutting a figure with \LaTeX } \\
   An alternative way to crop figures is to include the \texttt{BoundingBox}
in the\linebreak \verb+\includegraphics+ command, for example:\\
\verb+ \includegraphics[width=\textwidth,bb=54 440 488 660, clip=]+ \\
  The advantage
is that it can be made within \LaTeX . The initial value is given
by the \texttt{BoundingBox} found in the \texttt{.eps} file.
It may be better to process the
figure in a separate \texttt{.tex} file, since it will require several
iterations to get the right \texttt{BoundingBox}.

\begin{table}
\caption{ A simple table. Each column is aligned by one of the letters:
l: left, c: center, r: right.
Using two \$s permits one to insert equation-like features (see last column).
The inclusion of $\sim$ adds a blank to approximately align the numbers
of the last two columns (see the \LaTeX\ file).
}
\label{T-simple}
\begin{tabular}{ccclc}     % define the column alignment
                           % l: left, c: center, r: right
  \hline                   % horizontal line
Rot. & Date & CMEs & CMEs~ & $\alpha$ \\
     &      & obs. & ~cor. & $10^{-2}$Mm$^{-1}$\\
  \hline
1\tabnote{First table line.} & 02--Nov--97 & 16  & 24.1~ & -1.26 \\
2 & 29--Nov--97 & --  & ~2.53 & ~0.94 \\
3 & 27--Dec--97 & 06  & 11.7~ & ~0.82 \\
4 & 23--Jan--98 & 09  & 16.82 & ~0.94 \\
5 & 20--Feb--98 & 04  & ~9.6~ & ~1.00 \\
total&          & 35  & 64.75 &       \\
  \hline
\end{tabular}
\end{table}

  \begin{table}
\caption{ A more complex table with multi-columns labels. The command
\texttt{$\backslash$multicolumn\{4\}\{c\}\{Flares (GOES)\}} permits
writing the title ``Flares (GOES)'' over four columns. The alignment
of the decimal points is made by defining two columns separated with an
inter-column replaced by a ``.'' with the command \texttt{r@\{.\}l}
(see the \LaTeX\ file).
}
\label{T-complex}
\begin{tabular}{lcccccc r@{.}l c} % define the column alignment
                                  % l: left, c: center, r: right
                                  % @{.} replace the inter-column by a .
  \hline
Rot. & Date & \multicolumn{4}{c}{Flares (GOES)}& CMEs
     & \multicolumn{2}{c}{CMEs} & $\alpha$ \\
     &      &   X & M & C & B                  & obs.
     & \multicolumn{2}{c}{cor.} & $10^{-2}$Mm$^{-1}$\\
  \hline
1 & 02--Nov--97 & 02 & 04 & 24 & 05 & 16  & ~24&1 & -1.26 \\
2 & 29--Nov--97 & -- & -- & 03 & 04 & --  &   2&53& ~0.94 \\
3 & 27--Dec--97 & -- & 01 & 07 & 08 & 06  &  11&7 & ~0.82 \\
4 & 23--Jan--98 & -- & -- & 03 & 03 & 09  &  16&82& ~0.94 \\
5 & 20--Feb--98 & -- & -- & -- & -- & 04  &   9&6 & ~1.00 \\
total&          & 02 & 05 & 37 & 20 & 35  &  64&75&       \\
  \hline
\end{tabular}
\end{table}

\subsection{Examples of Tables} %%%%%%%%%%%%%%
  \label{S-tables}
   Tables are easy to write provided one keeps the alignment
with the column separator \texttt{\&} when entering the table
in the \LaTeX\ file
(even if it is not required by \LaTeX). Examples of a simple table,
Table~\ref{T-simple}, and a more complex table, Table~\ref{T-complex},
are given.

\subsection{Including References in the Text} %%%%%%%%%%%%%%
  \label{S-references}
  The classical way to input references in the text is with the
\verb+\cite{label-ref}+ command where \verb+label-ref+ is a label
unique for each reference.  It is defined in the environment
\verb+\begin{thebibliography}{} ... +, or in the \BibTeX\ file
(see Section~\ref{S-BibTeX}).
Style uses \texttt{natbib} package to handle all the issues with citations.
The natbib package is a reimplementation of the \LaTeX\ \verb+\cite+ command,
to work with both author-year and numerical citations.

\texttt{natbib} provides a lot of different citation commands. So you can manage the output of citation by yourself.
For example:\\
\verb+\defcitealias{Dupont07}{DSK}+: \defcitealias{Dupont07}{DSK}alias text for citation \texttt{Dupont07}\\
\verb+(\citealp{Dupont07}: hereafter \citetalias{Dupont07})+ will output:\linebreak
                                  (\citealp{Dupont07}: hereafter \citetalias{Dupont07})

For more valid citation commands see the \texttt{natbib} package documentation.

%The main citation commands, and their
%compilation results, are:\\
%\verb+\cite{Kusano04}          +: (Kusano \etal, 2004)\\
%\verb+\cite{Kusano04,Berger03} +: (Kusano \etal, 2004; Berger, 2003)\\
%\verb+\inlinecite{Brown99}     +: Brown, Canfield, and Pevtsov (1999)\\
%\verb+\opencite{Brown99}       +: Brown, Canfield, and Pevtsov, 1999\\
%\verb+\citeauthor{Brown99}     +: Brown, Canfield, and Pevtsov\\
%\verb+\shortcite{Brown99}      +: (1999)\\
%\verb+\citeyear{Brown99}       +: 1999\\
%\verb+(\opencite{Berger84}, \citeyear{Berger03}) +:
%                                  (\opencite{Berger84}, \citeyear{Berger03})

\subsection{Using \BibTeX} %%%%%%%%%%%%%%
  \label{S-BibTeX}
  %{\S}{\bf --- Why using \BibTeX ? } \\
  The use of \BibTeX\ simplifies the inclusion of references. Only the
references cited and labeled in the text are included at compilation,
and an error message appears if some references
are missing.  Any new reference will automatically be written at the correct
location in the reference list after compilation.
Moreover the references are stored, in any order, in a separate file
(with the \texttt{.bib} extension) in the \BibTeX\ format, so independently of
the journal format. Such a personal reference file can be re-used with any journal.
The formatting of the references and their listing order are made automatically
at compilation (using the information given in the \texttt{.bst} file).

  %{\S}{\bf --- Downloading references} \\
  The references in \BibTeX\ format can be downloaded from the
Astrophysics Data System (ADS), then stored
in \verb+sola_bibliography_example.bib+ (file\linebreak name of the present example).
The main extra work is to define a proper and easy label for each citation
(a convenient one is simply first-author-name-year).  Furthermore, it is better
to have the journal names defined by commands (for example
\texttt{$\backslash$solphys)}, as defined at the beginning of
this \texttt{.tex} file.
This provides an homogeneity in the reference list and permits flexibility
when changing for journals.   Some caution should be taken for some journals
since ADS does not necessarily provide a uniform format for the
journal names. This is the case for \jgr\  Moreover since
\jgr\ has a new way to refer to an article
(since 2002 it has no page number), then the ADS references need to be corrected.
More generally, it is worth verifying
each reference from the original publication (independently of \BibTeX\ use).

  %{\S}{\bf --- Compilation: general} \\
   The full \LaTeX\ and \BibTeX\ compilation is made in four steps:
\begin{tabbing}
1) {\tt latex filename}\qquad\qquad\=(stores the labels in the {\tt .aux} file)\\
2) {\tt bibtex filename}\>(loads the bibliography in the {\tt .bbl} file)\\
3) {\tt latex filename}\>(reads the .bbl, stores in the {\tt .aux})\\
4) {\tt latex filename}\>(replaces all labels)
\end{tabbing}
   where \texttt{filename} is the name of your \LaTeX\ file (for example,
the present file) {\bf without} typing its \texttt{.tex} extension.
If a \texttt{(?)} is still present in the output (at the place of a label),
it means that this label has not been properly defined.
 (for example, \LaTeX\ labels are case sensitive).
Any undefined label has a warning written in the \texttt{console window}
(it is better to have this window open by default, since \LaTeX\ warning and
error messages are very useful to localize the problem).

  %{\S}{\bf --- Compilation: simple} \\
  When the references are not changed, it is unnecessary to re-run \BibTeX .
When no new labels are added, running latex once is sufficient to refresh
the \LaTeX\ output. So, except for
the first, and the final time (safest), running \LaTeX\ once is sufficient
in most cases to update the \LaTeX\ output, if the compilation files
created are not erased! For example \BibTeX\ keeps the bibliography in the usual
environment,\\
  \verb+ \begin{thebibliography}{} ... \end{thebibliography}+\\
in the file with the \verb+.bbl+ extension.

\subsection{Miscellaneous Other Features} %%%%%%%%%%%%%%
      \label{S-Miscellaneous}
Long URL's can be quite messy when broken across lines
\textrm{http://gong.nso.edu/data/magmap/} as normal text,
however the \texttt{breakurl} package does a nice job of this,
\textit{e.g.}~\url{http://gong.nso.edu/data/magmap/}.

\section{Conclusion} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \label{S-Conclusion}
      We hope authors of {\it Solar Physics} will find this guide useful.
Please send us feedback on how to improve it.

  \LaTeX\ is very convenient to write a scientific text, in particular
with the use of labels for figures, tables, and references. Moreover, the labels and list of references are checked by the software against
one another, and, the formatting should be effortless with \BibTeX.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{acks}
 The authors thank ... ({\it note the reduced point size})
\end{acks}

\noindent To change a title use an optional parameter:\par
\verb+\begin{acks}[Acknowledgements]...\end{acks}+

%\acknowledgment US spelling: \verb+\acknowledgment+
%\acknowledgement British  spelling: \verb+\acknowledgement+

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix

 After the \verb+\appendix+ command, the sections are referenced with
capital letters.
The numbering of equations, figures and labels is
is just the same as with classical sections.

  \begin{figure}    %%%%%%%%%%%%%%%%%% FIGURE 1
   \centerline{\includegraphics[width=0.3\textwidth,clip=]{fig1a.eps}
              }
   \caption{Example of a simple figure in an appendix.}
    \label{F-appendix}
  \end{figure}

  \begin{table}
   \caption{ A simple table in an appendix. }
   \label{T-appendix}
    \begin{tabular}{ccclc}     % define the column alignment
                               % l: left, c: center, r: right
      \hline                   % horizontal line
    Rot. & Date & CMEs & CMEs~ & $\alpha$ \\
         &      & obs. & ~cor. & $10^{-2}$Mm$^{-1}$\\
      \hline
    1 & 02--Nov--97 & 16  & 24.1  & -1.26 \\
    2 & 29--Nov--97 & --  & ~2.53 & ~0.94 \\
      \hline
    \end{tabular}
   \end{table}

\section{Abbreviations of some Journal Names} %%%%%%%%%
    \label{S-appendix}
Journal names are abbreviated in {\it Solar Physics} with the IAU
convention (IAU Style Book
published in Transactions of the IAU XXB, 1988, pp. Si-S3.
\url{www.iau.org/Abbreviations.235.0.html}).  Here are a few journals with their \LaTeX\
commands (see the beginning of this \texttt{.tex} file).\\
  \verb+\aap     + \aap \\
  \verb+\apj     + \apj \\
  \verb+\jgr     + \jgr \\
  \verb+\mnras   + \mnras \\
  \verb+\pasj    + \pasj \\
  \verb+\pasp    + \pasp \\
  \verb+\solphys +~ \solphys

\section{Additional statments}

There are several environments for additional statments:
\begin{itemize}
\item \texttt{authorcontribution}
\item \texttt{fundinginformation}
\item \texttt{dataavailability}
\item \texttt{materialsavailability}
\item \texttt{codeavailability}
\item \texttt{ethics} where can be written declarations like \texttt{conflict}.
\end{itemize}

\begin{authorcontribution}
Information about author contribution ...
\end{authorcontribution}

\begin{fundinginformation}
Information about fundings ...
\end{fundinginformation}

\begin{dataavailability}
Information about available data ...
\end{dataavailability}

\begin{materialsavailability}
Information about available material ...
\end{materialsavailability}

\begin{codeavailability}
Information about available code ...
\end{codeavailability}

\begin{ethics}
\begin{conflict}
The authors declare that they have no conflicts of interest ....
\end{conflict}
\end{ethics}

%%% BIBLIOGRAPHY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Bibliography Included with \BibTeX }
      % more powerful
  With \BibTeX\ the formatting will be done automatically for all
the references cited with one
of the \verb+\cite+ commands (Section~\ref{S-references}).
Besides the usual items, it includes the title of the article
and the concluding page number.

There is an option \texttt{showbiblabels} that adds a \verb+\bibitem+
label at the end of every bibliography item. Label output is made on \verb+\endbibitem+ command.
This option should be used
just for compatibility while citing a document (see the references below).
Don't forget to remove the option when document will be finished.

\BibTeX\ style sorts references alphabetically by the authors, years, title but some times references
need to be moved up or down in the list. This can be achieved adding \verb+sortkey+ field in the bib file entry.

     % format of references provided by the journal (.bst)
\bibliographystyle{spr-mp-sola}
     % name your Bibtex file containing your references (.bib)
\bibliography{sola_bibliography_example}

     % Checking: look if the file containing the ``\bibitem'' exits
     %           so check if the .bbl file exist (bibTeX compilation)
\IfFileExists{\jobname.bbl}{} {\typeout{}
\typeout{****************************************************}
\typeout{****************************************************}
\typeout{** Please run "bibtex \jobname" to obtain} \typeout{**
the bibliography and then re-run LaTeX} \typeout{** twice to fix
the references !}
\typeout{****************************************************}
\typeout{****************************************************}
\typeout{}}

\section*{Bibliography included manually }
     % Require more work
  The articles can be entered, formatted, and ordered
by the author with the command \verb+\bibitem+.  ADS provides
references in the {\it Solar Physics} format by selecting
the format \verb+SoPh format+ under the menu
\verb+Select short list format+.    Including the article title
and the concluding page number are optional;
however, we require consistency in the author's choice.
That is, all of the references should have the article title, or none,
and similarly for ending page numbers.

\begin{thebibliography}{}
  \bibitem[\protect\citeauthoryear{{Berger}}{2003}]{Berger03b}
Berger,~M.A.:
2003, in Ferriz-Mas, A., N{\'u}{\~n}ez, M. (eds.),
    \textit{Advances in Nonlinear Dynamics}, Taylor and Francis Group,
    London, 345.
  \bibitem[\protect\citeauthoryear{{Berger} and {Field}}{1984}]{BergerF84b}
Berger,~M.A., Field,~G.B.:
1984, \textit{J. Fluid. Mech.} \textbf{147}, 133.
  \bibitem[\protect\citeauthoryear{{Brown}, {Canfield}, and
                                   {Pevtsov}}{1999}]{Brown99b}
Brown,~M., Canfield,~R., Pevtsov,~A.:
1999, Magnetic Helicity in Space and Laboratory Plasmas, Geophys. Mon.
      Ser. 111, AGU.
 \bibitem[\protect\citeauthoryear{{Dupont}, {Schmidt}, and {Koutny}}{2007}]{Dupont07}
Dupont, J.-C., Schmidt, F., Koutny, P.: 2007, \solphys{} \textbf{323}, 965.
\end{thebibliography}

\end{article}

\end{document}


\subsubsection{Sliding Window Simulation} \label{sliding_window_simulation}
A sliding window simulation walks with a given window size and step size over the simulated acceleration time series
stream of an experimentee and tries to identify as many gestures as possible. The simulated acceleration time series
stream of an experimentee starts after the slide (j) of figure \ref{fig:slides} and ends in slide (r) of figure
\ref{fig:slides}. The sliding window simulation is not able to read the labels of an gesture in the simulated
acceleration time series. Furthermore a sliding window simulation gets the gestures of an experimentee from slide (b)
to (i) in figure \ref{fig:slides} as training data.

Such a simulation is not free of parameters. Two parameters are already mentioned, the window size and the steps
size. In addition to parameters being the choice of the distance measure for time series, the threshold that marks
unclassifiable windows and the measure used for the sliding window filter with a blur factor. All those parameters and
their options are explained and mentioned in the following section. Furthermore a performance measure to compare the
different configured simulations is explained.

\input{experiment/experimental_protocol/sliding_window_simulation/window_size_determination.tex}
\input{experiment/experimental_protocol/sliding_window_simulation/step_size_determination.tex}
\input{experiment/experimental_protocol/sliding_window_simulation/time_series_distance_measures.tex}
\input{experiment/experimental_protocol/sliding_window_simulation/threshold_determination.tex}
\input{experiment/experimental_protocol/sliding_window_simulation/sliding_window_filter_measures.tex}
\input{experiment/experimental_protocol/sliding_window_simulation/performance_measure.tex}


\subsubsection{Total number of messages sent}\label{subsubsec:rect2krmessages}

This is an indication of the energy efficiency of the entire network.

The maximum number of copies is the dominant factor (\(84.89\%\)), as in the
other cases. As in the low density configuration the second most important
factor is the broadcast radius (\(5.58\%\)), with other factors and combinations
that had a negligible influence. The unexplained variation is extremely low
(\(0.31\%\)).

From \figref{fig:rectperfmessagesR} we notice that also increasing the broadcast
radius is useful to reduce the total number of messages sent when the maximum
number of copies is low, for the same reasons of the other scenarios.

\begin{figure}[hbt]
	\centering
	\includegraphics[width=0.8\textwidth]{img/rect/messages_R_perfplot.png}
	\caption{Performance plot for the total number of messages sent. The
	broadcast radius can be used to reduce the total number of messages sent
	when the maximum number of copies is not
	high}\label{fig:rectperfmessagesR}
\end{figure}