%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Template for a conference paper, prepared for the
%% Food and Resource Economics Department - IFAS
%% UNIVERSITY OF FLORIDA
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Version 1.0 // November 2019
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ariel Soto-Caro
%%  - asotocaro@ufl.edu
%%  - arielsotocaro@gmail.com
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[10pt]{article}
\usepackage{format}

\usepackage{amsthm}
\theoremstyle{plain}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}

\newtheorem*{remark}{Remark}

\usepackage {tikz}
\usetikzlibrary {positioning}
\definecolor {processblue}{cmyk}{0.96,0,0,0}

\usepackage{mathtools}
\usepackage{mathrsfs}
\usepackage{dsfont}
\usepackage[ruled,vlined]{algorithm2e}

\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiterX{\inp}[2]{\langle}{\rangle}{#1, #2}

\usepackage{enumitem}
\setlist[itemize,1]{label=\textbullet}
\setlist[itemize,2]{label=$\circ$}
\setlist[itemize,3]{label=$\ast$}

%% ===============================================
%% Setting the line spacing (3 options: only pick one)
% \doublespacing
% \singlespacing
\onehalfspacing
%% ===============================================

\setlength{\droptitle}{-5em} %% Don't touch

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SET THE TITLE
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% TITLE:
\title{Undirected Graph Connectivity}

% AUTHORS:
\author{Kishlaya Jaiswal\\% Name author
    % \href{mailto:kishlaya.j@gmail.com}{\texttt{kishlaya.j@gmail.com}} %% Email author 1
% \and Second Author\\% Name author
%     \href{mailto:secondauthor@ufl.edu}{\texttt{secondauthor@ufl.edu}} %% Email author 2
% \and Third Author\\% Name author
%     \href{mailto:thirdauthor@ufl.edu}{\texttt{thirdauthor@ufl.edu}}%% Email author 3
%\and Forth Author\\% Name author
%    \href{mailto:forthuthor@ufl.edu}{\texttt{forthuthor@ufl.edu}}%% Email author 4
    }

% DATE:
\date{\today}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ABSTRACT
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\setstretch{.8}
\maketitle
% %%%%%%%%%%%%%%%%%%
\begin{abstract}
% CONTENT OF ABS HERE--------------------------------------

We will discuss the problem of st-connectivity in undirected graphs, giving a short proof for solving it in logspace using random walks and then finally we will give a detailed overview of Omer Reingold's result - solving this problem in logspace without using randomness.

% END CONTENT ABS------------------------------------------
\noindent
\textit{\textbf{Advisor: }%
Samir Datta} \\ %% <-- Keywords HERE!

\end{abstract}
}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BODY OF THE DOCUMENT
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% % --------------------
\section{Introduction}
% % --------------------

Consider the following problem: given a undirected graph $G$ and two vertices $s,t \in G$, determine if $t$ is reachable from $s$.

$$USTCON = \{(G,s,t) \mid t \text{ is reachable from } s \text{ in } G\}$$

Widely known algorithms for solving this problem are Breadth-First Search and Depth-First Search. The running time of these algorithms is $O(|V|+|E|)$ and requires $O(|V|)$ space, that is $USTCON \in P$.

But can we do better? It is clear that we can't improve on running time. So we turn to look at this problem from the point of view of complexity theory.

We know that $USTCON \in NL$, because we can non-deterministically guess the vertices on the path from $s$ to $t$ one-by-one, and description of each vertex requires only $\log |V|$ many bits. Furthermore, using Savitch's theorem we get that $USTCON \in L^2$

Our next hope would be to prove $USTCON \in L$. But in making an attempt to this problem, what might seem more obvious at first is that $USTCON \in RL$, for we can do a random walk on the graph starting at $s$ with the hope that, after not-too-many steps we have a good chance to hit $t$ if $t$ was in the same connected component as $s$, otherwise it is clear that we will never hit $t$. Let's try and make this argument more precise.

% % --------------------
\section{$USTCON \in RL$}
% % --------------------

The idea is straight-forward - start a random walk at $s$ and continue until $poly(n)$ steps, where a random step is: if at vertex $u$, then choose a neighbour $v$ of $u$ uniformly at random and go to $v$. If we do not hit $t$ then we output that there is no path connecting them. We now analyze the probability of failure - not hitting $t$ even though $s$ and $t$ are in the same connected components.

So let's say $s$ and $t$ are in the same component. Denote by $E_{uv}$ the expected time to hit $v$ starting at $u$ for any two vertices $u$ and $v$. Using Markov's inequality, we get:
$$\mathbb{P}(\text{Time taken to hit } t > K) \leq \frac{E_{st}}{K}$$

The stationary distribution for this walk is $\pi$ given by $\pi(u) \sim d_u$. Using the fundamental theorem for Markov Chains, $E_{uu} = \frac{1}{\pi_{u}} = \frac{2m}{d_u}$ $\forall u \in V$.

For any edge $(u,v) \in E$, we calculate $E_{uv}$ as follows:
$$E_{uu} = \sum_{v: (u,v) \in E} \frac{1 + E_{uv}}{d_u}$$
$$\implies E_{uv} \leq d_uE_{uu} = 2m$$

Finally, let $\sigma$ be a path from $s$ to $t$ then $E_{st} \leq \sum_{(u,v) \in \sigma} E_{uv} \leq 2|\sigma|m  \leq 2m(n-1)$.

Hence it suffices to take $4n^3$ many steps in our random walks so that $\mathbb{P}(\text{failure}) \leq \frac12$.

% % --------------------
\section{$USTCON \in L$}
% % --------------------

Improving from Savitch's theorem ~\cite{DBLP:conf/focs/NisanSW92} showed that $USTCON \in L^{3/2}$. Later, ~\cite{DBLP:journals/jacm/ArmoniTWZ00} improved this to $USTCON \in L^{4/3}$. Finally in 2004, ~\cite{DBLP:journals/eccc/ECCC-TR04-094} showed that $USTCON \in L$, whose proof we discuss now.

We will assume that the given graph $G$ is $d$-regular and each connected component is non-bipartite. This assumption is justified because given a graph, replace each vertex $v$ with a cycle of length $d_v$ connecting each neighbour of $v$ to a unique vertex in the cycle, thus making the graph $3$-regular. Now add $d-3$ self-loops on each vertex to make it $d$-regular.

We begin with a simple observation that given a $d$-regular graph with diameter atmost $\rho$ of each component, if we just did a brute-force search by checking for $t$ on all possible paths from $s$, it would require us to enumerate all $O(d^\rho)$ paths emanating from $s$ and hence take $O(\rho \log d)$ space. In general, $\rho$ can be as large as $n$. But if our graph was well-connected and we had $\rho = O(\log n)$, then we have accomplished our goal.

An intuitive way to make our graph \textsl{well-connected} is by connecting each vertex to a vertex which was originally at distance $2$. This operation makes it $d^2$-regular, making our graph even more dense. But if we keep repeating this process only, then after $\log n$ steps, space complexity of enumerating all paths would turn $O(\rho \log d^{2^{\log n}}) = O(\rho n \log d)$, defeating our purpose.

So we need another operation to make our graph \textsl{sparse}, keeping the degree constant. Intuitively, we will take a small graph and replace each vertex in our original graph with this small graph and edges are taken to be the "zigzag" lines. This operation is called zigzag product of graphs, makes the degree constant at the cost of deteriorating the connectedness slightly.

Both these operations preserve the connected components of $G$ (Squaring preserves the connected components of $G$ because each component contains an odd-cycle). Alternating this process of squaring and zigzaging $O(\log n)$ times, we will find that $G$ becomes a well-connected sparse graph with a diameter $O(\log n)$ and constant degree. Thus, we are done.

Now to make our above intuition precise, we start with the following definitions.

\subsection{Expanders}

As already hinted above, expanders are well-connected but sparse graphs. Well-connectedness is specified by cuts of atleast some constant size and sparseness using constant small degree.

Given a graph $G$ and $S \subseteq V$, let
$$\Gamma(u) \coloneqq \{v \mid (u,v) \in E\}$$
$$\Gamma(S) \coloneqq \bigcup_{u \in S} \Gamma(u)$$

\begin{definition}
$G$ is said to be a $(1+\epsilon)$ \textbf{vertex-expander} if for any subset $S$ of vertices with $|S| \leq N/2$, $|\Gamma(S)| \geq (1+\epsilon)|S|$.
\end{definition}

\begin{remark}
Let $G$ be $(1+\epsilon)$ vertex-expander for some $\epsilon > 0$ then, $G$ has logarithmic diameter
\end{remark}

Vertex expansion is a combinatorial property but it's easy to deal with algebraic properties, like spectrum of a graph and in particular, connectedness can be described using the largest (in absolute value) eigenvalue of the normalized adjacency matrix $\mathrm{A} = D^{-1/2}AD^{-1/2}$, denoted by $\lambda(G)$, that is

$$\lambda(G) \coloneqq \max_{\mathbf{x} \perp \mathbf{u}, \norm{\mathbf{x}}=1} \norm{\mathrm{A}\mathbf{x}}$$

where $\mathbf{u} = \frac1n \mathbf{1}$ is the uniform probability distribution on $V$.

% and since $\mathbf{u} = \frac1n \mathbf{1}$ is an eigenvector of $\mathrm{A}$ with largest eigenvalue $1$, we can equivalently say
% $$\lambda(G) = \sup_{\mathbf{x} \perp \mathbf{u}, \norm{\mathbf{x}}=1} \norm{\mathrm{A} \mathbf{x}}$$

\begin{definition}
$G$ is said to be a $(n,d,\lambda)$ \textbf{spectral-expander} if $G$ is $d$-regular graph on $n$ vertices with $\lambda(G) \leq \lambda$.
\end{definition}

Finally we have the result establishing the connection between two notions from algebra and combinatorics: every spectral expander is also a vertex expander.

\begin{theorem}
Let $G$ be a $(n,d,\lambda)$ spectral-expander then $G$ is also a $(1 + \epsilon)$ vertex-expander, where $\epsilon = \frac{1-\lambda^2}{1+\lambda^2}$
\end{theorem}

\begin{proof}
Let $S \subseteq V$ such that $|S| \leq n/2$ and $\mathbf{x} = \chi_S/|S|$ be the uniform probability distribution on $S$.

For any probability distribution $\pi$, using Cauchy-Schwarz we get $$1 = \left(\sum_{u \in \text{support}(\pi)} \pi_u\right)^2 \leq |\text{support}(\pi)| \left(\sum_{u \in \text{support}(\pi)} \pi_u^2\right) = |\text{support}(\pi)| \norm{\pi}^2$$

where $\text{support}(\pi) = \{u \mid \pi_u > 0\}$.

Since $\mathrm{A}$ is also the transition matrix for random walk on $G$, so $(\mathrm{A}\mathbf{x})$ is a probability distribution on $V$, and we have
$$\frac{1}{|\text{support}(\mathrm{A}\mathbf{x})|} \leq  \norm{\mathrm{A}\mathbf{x}}^2 = \norm{\mathrm{A}\mathbf{x} - \mathbf{u}}^2 + \frac1n \leq \lambda(G)^2\norm{\mathbf{x} - \mathbf{u}}^2 + \frac1n$$

But $\text{support}(\mathrm{A}\mathbf{x}) = \Gamma(S)$ and
$\norm{\mathbf{x} - \mathbf{u}}^2 = \frac{1}{|S|} - \frac1n$, giving us the desired result:

\begin{align*}
    \frac{1}{\Gamma(S)} &\leq \lambda^2\left(\frac{1}{|S|}-\frac1n\right) + \frac1n \\
    &= \frac{\lambda^2}{|S|} + \frac{1 - \lambda^2}{n} \\
    &\leq \frac{\lambda^2}{|S|} + \frac{1 - \lambda^2}{2|S|} \\
    \implies \Gamma(S) &\geq \left(\frac{2}{1 + \lambda^2}\right)|S|
\end{align*}
\end{proof}

In fact, both these notions of expansion are equivalent but we don't require the converse relation for our main result.

\begin{remark}
Let $G$ be $(n,d,\lambda)$ spectral-expander where $\lambda < 1$ then $G$ has diameter $O(\log n)$ where the leading constant in our big-$O$ notation depends upon $\lambda$ (as it depends upon $\epsilon$).
\end{remark}

\subsection{Graph Squaring}

Let $A$ be the adjacency matrix of $G$ then $G^2$ is the graph defined using the adjacency matrix $A^2$.

Since $G$ is $d$-regular and $G^2$ is $d^2$-regular, we get that the normalized adjacency matrix of $G^2$ is the square of normalized adjacency matrix of $G$. Thus $\lambda(G^2) = \lambda(G)^2$.

So squaring improves the spectral expansion at the cost of exploding the degree of a graph. In particular, if $G$ is $(n,d,\lambda)$ expander then $G^2$ is a $(n,d^2,\lambda^2)$ expander.

\subsection{Zigzag product}

Let $G$ be $(n,d_1,\lambda_1)$ expander and $H$ be $(d_1, d_2, \lambda_2)$ expander.

Define $G \textcircled{z} H$ as a graph on the vertex set $V(G) \times V(H)$.

In $G$, label each neighbour of a vertex $u$ from $\{1 \ldots d_1\}$ so that $u[i]$ represents the $i^{th}$ neighbour of $u$. For example: here $u[2] = v$ and $v[3] = u$

\begin{center}
\begin{tikzpicture}[shorten >=1pt,->]
  \tikzstyle{vertex}=[circle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , minimum width =1 cm]
  \node[vertex] (G_1) at (-2.5,0)  {u};
  \node[vertex] (G_2) at (2.5,0)  {v};

  \draw (G_1) -- (-3,2) -- cycle node[midway,above] {1};
  \draw (-2,0) -- node[below] {2} ++(2,0) -- node[above] {3} ++(2,0) -- cycle;
  \draw (G_1) -- (-3,-2) -- cycle node[midway,above] {3};
  \draw (G_1) -- (-5,-1) -- cycle node[midway,above] {4};
  \draw (G_1) -- (-5,1) -- cycle node[midway,above] {5};
  \draw (G_2) -- (4,1.5) -- cycle node[midway,above] {1};
  \draw (G_2) -- (4,-1.5) -- cycle node[midway,above] {2};
\end{tikzpicture}
\end{center}

Now take any $d_2$-regular graph $H$ on $d_1$ vertices (we label the vertices from $\{1 \ldots d_1\}$), and replace each vertex in $G$ with a \textsl{cloud} $H$, that is consider a graph on vertex set $V(G) \times V(H)$ with the following edges: Suppose you're at a vertex $(u,i)$. Choose any neighbour $i'$ of $i$ and go to $(u,i')$. Use this index $i'$ to go to a different cloud which is $(v, j')$ where $v = u[i']$ and $u = v[j']$. Finally choose any neighbour $j$ of $j'$ and go to $(v,j)$. Add an edge between $(u,i)$ and $(v,j)$.

\begin{center}
\begin{tikzpicture}[shorten >=1pt,->]
  \tikzstyle{vertexg}=[circle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , minimum width =3.5 cm]
  \tikzstyle{vertexh}=[circle ,top color =white , bottom color = white ,
draw,black , text=black , minimum width =.5 cm]
  \node[vertexg] (G_1) at (0,2.5)  {u};
  \node[vertexg] (G_2) at (0,-2.5)  {v};

  \node[vertexh] (H_1) at (-1, 2) {i};
  \node[vertexh] (H_2) at (1, 2) {i'};

  \node[vertexh] (H_3) at (-1, -2) {j'};
  \node[vertexh] (H_4) at (1, -2) {j};

  \draw[dashed, processblue] (H_1) -- (H_2) -- cycle;
  \draw[dashed, processblue] (H_2) -- (H_3) -- cycle;
  \draw[dashed, processblue] (H_3) -- (H_4) -- cycle;

  \draw (H_1) -- (H_4) -- cycle;
\end{tikzpicture}
\end{center}

Notice that from $(u,i)$ there are $d_2$ many choices for $(u,i')$. $(v,j')$ is already determined from $(u,i')$. And from $(v,j')$ there are $d_2$ many choices for $(v,j)$. Hence degree of any vertex is $d_2^2$.

\begin{theorem}[~\cite{DBLP:journals/eccc/ECCC-TR01-018}]
$G \textcircled{z} H$ is a $(nd_1, d_2^2, f(\lambda_1, \lambda_2))$ expander where $$f(\lambda_1, \lambda_2) = \frac12 (1 - \lambda_2^2)\lambda_1 + \frac12 \sqrt{(1 - \lambda_2^2)^2\lambda_1^2 + 4\lambda_2^2}$$
\end{theorem}

\begin{corollary}
If $\lambda_2 \leq \frac12$ then $1-f(\lambda_1, \lambda_2) \geq \frac13(1-\lambda_1)$
\end{corollary}

\begin{proof}
Since $\lambda_1 \leq 1$
$$\sqrt{(1 - \lambda_2^2)^2\lambda_1^2 + 4\lambda_2^2} \leq \sqrt{(1 - \lambda_2^2)^2 + 4\lambda_2^2} = \frac12 (1 + \lambda_2^2) = 1 - \frac12 (1 - \lambda_2^2)$$
$$1 - f(\lambda_1, \lambda_2) \geq \frac12 (1 - \lambda_2^2) - \frac12 (1 - \lambda_2^2)\lambda_1 = \frac12 (1 - \lambda_2^2)(1-\lambda_1)$$
Thus, $\lambda_2 \leq \frac12 \implies 1 - f(\lambda_1, \lambda_2)\geq  \frac38( 1- \lambda_1) \geq \frac13( 1- \lambda_1)$
\end{proof}

\subsection{Existence of a small expander}

To begin our algorithm, we need to start with a good expander for zigzaging our graph with. ~\cite{DBLP:journals/eccc/ECCC-TR01-018} give an explicit construction of graph $U$ which is $(D^{8}, D, 1/5)$ expander, for some constant $D$.

Then we define
\begin{align*}
    G_1 &= U^8 \text{ \textcircled{z} } U \\
    G_2 &= G_1^4 \text{ \textcircled{z} } U \\
    H &= G_2^4 \text{ \textcircled{z} } U \\
\end{align*}

\begin{lemma}
$H$ is a $(d_0^{16}, d_0, 1/2)$ expander (where $d_0 = D^2$)
\end{lemma}

\begin{proof}
Using the above-mentioned theorem , we get

$G_1$ is a $(D^{16}, D^2, 1/4)$ expander as $\frac12 (1 - \frac{1}{5^2})\frac{1}{5^8} + \frac12 \sqrt{(1 - \frac{1}{5^2})^2\frac{1}{25^8} + 4\frac{1}{5^2}} < \frac14$

$G_2$ is a $(D^{24}, D^2, 1/4)$ expander as $\frac12 (1 - \frac{1}{5^2})\frac{1}{4^4} + \frac12 \sqrt{(1 - \frac{1}{5^2})^2\frac{1}{16^4} + 4\frac{1}{5^2}} < \frac14$

$H$ is a $(D^{32}, D^2, 1/2)$ expander as $\frac12 (1 - \frac{1}{5^2})\frac{1}{4^4} + \frac12 \sqrt{(1 - \frac{1}{5^2})^2\frac{1}{16^4} + 4\frac{1}{5^2}} < \frac14 < \frac12$

Hence, $H$ is a $(d_0^{16}, d_0, 1/2)$ expander, as required.
\end{proof}

% ~\cite{DBLP:journals/eccc/ECCC-TR01-018} showed that there exists a constant $d_0$ and a graph $H$ which is $(d_0^{16}, d_0, 1/2)$ expander.

\subsection{Reingold's algorithm}

It is now clear that if we fix any two \textsl{constants} $d$ and $\lambda < 1$, then for any input graph $G$ such that each component of $G$ is a $(n,d,\lambda)$ expander, we can solve the connectivity problem (restricted to these class of graphs) in logspace.

Thus, we take these constants to be $d = d_0^{16}$ and $\lambda = \frac12$ and then it suffices to show how to convert any graph $G$ into a $(O(n),d_0^{16},1/2)$ expander.

\medskip

\begin{algorithm}[H]
\SetAlgoLined
 Input: $G$

 Convert $G$ into a $d_0^{16}$ regular graph by replacing each vertex with a cycle and adding self-loops

 Set $l = 2\ceil{\log (d_0^{16}n^2)}$

 Let $G_0 = G$

 \For{$i\gets1$ \KwTo $l$}{
    compute $G_i = (G_{i-1} \textcircled{z} H)^8$
 }

 Output $G_l$
 \caption{Transform $G$ such that each component is a $(O(n),d_0^{16}, 1/2)$ expander}
\end{algorithm}

\medskip

We mention once again that both the operations: squaring and zigzag product preserve the connected components, that is $s$ and $t$ are connected in $G$ iff they are connected in $G_l$.

\subsection{Analysis}

We assume that $G$ is connected because if $G$ has multiple connected components, then we can apply the same analysis for each component separately.

\begin{lemma}
Each $G_i$ $(0 \leq i \leq l)$ is a graph on $n(d_0)^{16i}$ vertices and is $d_0^{16}$-regular
\end{lemma}

\begin{proof}
We proceed by induction on $i$. For $i=0$ it follows immediately. Now suppose it is true for for some $i$, that is $G_i$ is $(n(d_0)^{16i}, d_0^{16}, \lambda)$ expander for some $\lambda$. Since $H$ is $(d_0^{16}, d_0, 1/2)$ expander, we get $G_i \textcircled{z} H$ is a $(n(d_0)^{16(i+1)}, d_0^{2}, \lambda')$ expander for some $\lambda'$.

Therefore, $G_{i+1} = (G_i \textcircled{z} H)^8$ is a graph on $n(d_0)^{16(i+1)}$ vertices and is $d_0^{16}$-regular.
\end{proof}

\begin{remark}
Thus, each of the zigzag products in our algorithm is valid and $G_l$ is a $d_0^{16}$-regular graph on $O(n)$ vertices.
\end{remark}

\begin{lemma}
If $l = 2\ceil{\log d_0^{16}n^2}$ then $\left(1 - \frac{1}{d_0^{16}n^2}\right)^{2^l} \leq \frac12$
\end{lemma}

\begin{proof}
$$2\ceil{\log x} \leq 2\log x + 2 \implies 2^l \leq 4x^2$$
$$\implies \left(1 - \frac{1}{x}\right)^{2^l} \leq \left(1 - \frac{1}{x}\right)^{4x^2} \leq \frac12, \forall x \geq 1$$
\end{proof}

Now let $1 > \lambda_2 \geq \cdots \geq \lambda_n$ be the eigenvalues of $\mathrm{A}$, then by our definition $\lambda(G) = \max \{\lambda_2, |\lambda_n|\}$

\begin{lemma}[\cite{DBLP:journals/cpc/AlonS00}]
Let $G$ be $d$-regular non-bipartite graph with diameter $D$ on $n$ vertices, then
$$1 + \lambda_n \geq \frac{1}{d(D+1)n}$$
\end{lemma}

\begin{lemma}
For any $d$-regular, connected graph $G$ on $n$ vertices, $$1 - \lambda_2 \geq\frac{1}{dn^2}$$
\end{lemma}

\begin{proof}
Using Rayleigh's theorem, we know that
$$\lambda_2 = \sup_{\mathbf{x} \perp \mathbf{u}, \norm{\mathbf{x}} = 1} \mathbf{x}^T\mathrm{A}\mathbf{x}$$

Note that,
\begin{align*}
    \mathbf{x}^T\mathrm{A}\mathbf{x} &= \sum_u \sum_v \mathrm{A}(u,v)x(u)x(v) \\
    &= \frac1d \sum_u \sum_{v \sim u} x(u)x(v) \\
    &= \frac1d \sum_{(u,v) \in E} 2x(u)x(v) \\
    &= \frac1d \sum_{(u,v) \in E} x(u)^2 + x(v)^2 - (x(u) - x(v))^2 \\
    &= \frac1d \sum_{(u,v) \in E} (x(u)^2 + x(v)^2) - \frac1d \sum_{(u,v) \in E} (x(u) - x(v))^2 \\
    &= 1 - \frac1d \sum_{(u,v) \in E} (x(u) - x(v))^2 \\
    \implies 1 - \mathbf{x}^T\mathrm{A}\mathbf{x} &= \frac1d \sum_{(u,v) \in E} (x(u) - x(v))^2 \\
\end{align*}

Since $\{\mathbf{x} \perp \mathbf{u}, \norm{\mathbf{x}} = 1\}$ is a compact space, we can find a vector $\mathbf{x}$ such that $\lambda_2 = \mathbf{x}^T\mathrm{A}\mathbf{x}$.

Since $\sum_{u} x(u)^2 = 1$, there is a vertex $u_0$ such that $x(u_0) \geq 1/\sqrt{n}$. Further, since $\sum_u x(u) = 0$, choose a vertex $v_0$ such that $x(v_0) < 0$. Thus, $|x(u_0) - x(v_0)| \geq 1/\sqrt{n}$. Since $G$ is connected, fix a path $P$ from $u_0$ to $v_0$.

\begin{align*}
    1 - \lambda_2 &= 1 - \mathbf{x}^T\mathrm{A}\mathbf{x} \\
    &= \frac1d \sum_{(u,v) \in E} (x(u) - x(v))^2 \\
    &\geq \frac1d \sum_{(u,v) \in P} (x(u) - x(v))^2 \\
    &\geq \frac{1}{d} \frac{1}{|P|} \left(\sum_{(u,v) \in P} |x(u) - x(v)| \right)^2 \\
    &\geq \frac{1}{dn} \bigg(|x(u_0) - x(v_0)| \bigg)^2 \\
    &\geq \frac{1}{dn^2}
\end{align*}
\end{proof}

\begin{corollary}
For any $d$-regular, connected, non-bipartite graph $G$ on $n$ vertices, $$\lambda(G) \leq 1 - \frac{1}{dn^2}$$
\end{corollary}

\begin{proof}
If $\lambda_n > 0$, then $\lambda(G) = \lambda_2 \leq 1 - \frac{1}{dn^2}$

Otherwise, $\lambda_n < 0 \implies |\lambda_n| = -\lambda_n \leq 1 - \frac{1}{dn^2}$ and hence $\lambda(G) = \max \{\lambda_2, |\lambda_n|\} \leq 1 - \frac{1}{dn^2}$
\end{proof}

\begin{lemma}
$\lambda(G_i) \leq \max \{\lambda(G_{i-1})^2, \frac12\}$ $\forall 1 \leq i \leq l$
\end{lemma}

\begin{proof}
Let $\lambda(G_{i-1}) = \lambda$.

If $\lambda \leq 1/2$ then $\lambda(G_{i-1} \textcircled{z} H) \leq 1 - 1/6 = 5/6$. So $\lambda(G_i) \leq (5/6)^8 \leq 1/2$

Otherwise $\lambda > 1/2$ then $\lambda(G_{i-1} \textcircled{z} H) \leq 1 - \frac13(1-\lambda)$ and
$$\left(1 - \frac13(1-\lambda)\right)^4 = \left(\frac{\lambda+2}{3}\right)^4 \leq \lambda, \forall \lambda \in [1/2,1]$$

So $\lambda(G_i) \leq \lambda(G_{i-1})^2$
\end{proof}

\begin{lemma}
$\lambda(G_l) \leq 1/2$
\end{lemma}

\begin{proof}
Suppose for some $1 \leq i \leq l-1$, $\lambda(G_i) \leq \frac12$, then $$\lambda(G_{i+1}) \leq \max \left(\lambda(G_{i})^2, \frac12\right) \leq \max \left(\frac14, \frac12\right) = \frac12$$ and hence $\lambda(G_l) \leq \frac12$ by induction. Otherwise if $\lambda(G_i) > \frac12$ $\forall 1 \leq i \leq l-1$, then $$\lambda(G_l) \leq \lambda(G_{l-1})^2 \leq \lambda(G_{l-2})^{2^2} \leq \cdots \leq \lambda(G_0)^{2^l} \leq \left(1 - \frac{1}{d_0^{16}n^2}\right)^{2^l} \leq \frac12$$
\end{proof}

\subsection{Implementation}

\begin{definition}
Given a $d$-regular graph $G = (V,E)$ along with each neighbour of each vertex labelled from $[d] = \{1 \ldots d\}$, define $\text{Rot}_G: V \times [d] \rightarrow V \times [d]$ such that
$$\text{Rot}_G(u,i) = (v,j)$$
where $v=u[i]$ and $u=v[j]$
\end{definition}

\begin{remark}
An adjacency list/matrix of a graph can be converted to rotation map using $O(\log n)$ space.
\end{remark}

On a final note, we mention that using the \textsl{Rotation Map Representation} of graphs, we can implement the above algorithm in logspace.

That is, all the three steps:
\begin{itemize}
    \item Converting $G$ into $d_0^{16}$-regular non-bipartite graph
    \item Squaring a graph
    \item Taking zigzag product with $H$ ($H$ is a constant graph and can be directly encoded on a TM)
\end{itemize}
can be effected in $O(\log n)$ space.

\printbibliography

\end{document}


\documentclass{article}

\usepackage{natbib}
\bibliographystyle{apj}

\usepackage[margin=0.8in]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{float}
\usepackage{amsmath}
\usepackage{fixmath}
\usepackage{minted}

\author{Leandro Rizk \\ leo.rizk@mail.utoronto.ca \\ CTA200 -- University of Toronto}
\title{Computing Project: Background Study on SETI Figures of Merit}
\date{14 May 2021}

\begin{document}

\maketitle

\section{Introduction}

\paragraph{}
The search for extraterrestrial intelligence (SETI) relies on our ability to detect and recognize technosignatures---signs of activity from a technologically advanced civilization. Since we have yet to find any evidence of these, we cannot truly know what we are looking for. We expect that, similar to humans, extraterrestrial civilization may utilize electromagnetic radiation in the radio bands to send and receive information. These technosignatures are expected to be of very narrow bandwidth ($\sim$ 1 Hz), display a Doppler drift due to relative accelerations (from orbits and rotations) between the signal source and our receivers, and not be explained by Earth-based radio-frequency interference (RFI). With so many potentially habitable exoplanets in our galaxy and an entire spectrum of frequencies where there might be a narrow signal, our SETI efforts must strategically span large portions of the sky and observe in a wide range of radio frequencies.

\paragraph{}
The Breakthrough Listen initiative is the largest program to date aimed at detecting technosignatures. One of the goals of this 10-year program that started in 2016 is to survey one million nearby stars, but it has so far observed only a few thousand. Ongoing and upcoming surveys using MeerKAT and the Very Large Array are expected to achieve this goal in the coming years.

\paragraph{}
It is worthwhile to compare the merits of previous SETI efforts. Search parameters are either proper to the instruments (e.g. frequency resolution, effective collecting area) or chosen by the researchers (e.g. signal-to-noise ratio threshold, observation time). In this report, I will compare several of these parameters using a variety of metrics with the objective of appreciating what has so far been done in the search for technosignatures and the progress that is yet to come.

\section{EIRP and Transmitter Rate}

\paragraph{}
One method to evaluate a SETI project is to combine the values of \textbf{equivalent isotropic radiated power} (EIRP) and \textbf{transmitter rate} into a single figure of merit, dubbed the \textbf{continuous waveform transmitter rate figure of merit} (CWTFM) by \citet{Enriquez_2017}:

\begin{equation}
\textrm{CWTFM} \; = \; \zeta_{\textrm{AO}} \, \frac{\textrm{EIRP}}{n_{\textrm{stars}} \, \cdot \, (\upDelta \nu_{\textrm{tot}} / \nu_{\textrm{mid}})} \; ,
\label{eq1}
\end{equation}

where the factor $\frac{1}{n_{\textrm{stars}} \, \cdot \, (\upDelta \nu_{\textrm{tot}} / \nu_{\textrm{mid}})}$ represents the transmitter rate. The transmitter rate depends on the number of stars surveyed ($n_{\textrm{stars}}$), the total bandwidth ($\upDelta \nu_{\textrm{tot}}$), and the central frequency ($\nu_{\textrm{mid}}$) of the observation. The coefficient $\zeta_{\textrm{AO}}$ is simply a normalization factor to obtain a CWTFM of 1 when EIRP = $10^{13}$ W (the EIRP of the Arecibo Planetary Radar),  $n_{\textrm{stars}}$ = 1000, and $\upDelta \nu_{\textrm{tot}} / \nu_{\textrm{mid}}$ = 1/2. Rearranging the variables in \textbf{Equation \ref{eq1}} reveals that $\zeta_{\textrm{AO}} = 5 \times 10^{-11}$ W$^{-1}$.

\paragraph{}
The minimum EIRP that would need to be generated by an extraterrestrial transmitter at a distance $d$ to be detected by a search is described by \textbf{Equation \ref{eq4}} \citep{10.1093/mnras/staa2672}:

\begin{equation}
\textrm{EIRP} \; = \; 4 \, \pi \, d^2 \, F_{\textrm{min}} \; ,
\label{eq4}
\end{equation}

where $F_{\textrm{min}}$ is the \textbf{minimum detectable flux} for that search.

\paragraph{}
\textbf{Figure \ref{fig1}} is a means of visualizing the CWTFM of SETI projects. In this figure, adapted from \citet{Enriquez_2017} and expanded to include more surveys, EIRP is plotted against transmitter rate on logarithmic scales. Searches that are positioned closer to the bottom left corner in this plot have a smaller CWTFM. Points below the line of CWTFM = 1 can be qualified as more effective. This plot attempts to illustrate the strengths of a particular survey---those with higher star counts and/or higher relative observation bandwidths are towards the bottom while those with smaller EIRP are towards the left.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.46]{Figure1.pdf}
\caption{Comparison of past and future SETI projects (adapted from \citet{Enriquez_2017}, Figure 7) \textbf{\label{fig1}}}
\end{center}
\end{figure}

\textbf{Figure \ref{fig2}}, on the other hand, compares the CWTFM of SETI projects head-on. If we consider that a CWTFM of $<$ 1 corresponds to a more effective survey, then only a few recent or future surveys make the cut. Those are the surveys using the Green Bank Telescope, the Square Kilometre Array, the Karl G. Jansky Very Large Array, MeerKAT, and the next-generation Very Large Array.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.54]{Figure 1a.png}
\caption{Continuous waveform transmitter rate figure of merit (CWTFM) of past and future SETI projects \textbf{\label{fig2}}}
\end{center}
\end{figure}

\section{Frequency Range}

\paragraph{}
Another interesting parameter to compare between SETI projects is the \textbf{total bandwidth} covered by a search. Over the years, this frequency range has been able to significantly increase. \textbf{Figure \ref{fig3}} compares the range of observing frequencies of a number of surveys as well as their sky coverage and relative sensitivity to picking up an event. (Sensitivity is further contrasted in \textbf{Figures \ref{fig4}} and \textbf{\ref{fig5}}.)

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.46]{Figure2.pdf}
\caption{Frequency range, sky coverage, and sensitivity of SETI projects \textbf{\label{fig3}}}
\end{center}
\end{figure}

\paragraph{}
The classification of sensitivity in \textbf{Figure \ref{fig3}} was chosen to best compare the eight surveys on the plot. A highly sensitive survey is one that would be able to detect a 1-Hz wide signal from an Arecibo-like transmitter at 75 pc away (minimum detectable flux density $<$ 15 Jy). A low-sensitivity survey is one that could not detect a 1-Hz wide signal from an Arecibo-like transmitter at 25 pc away (minimum detectable flux density $>$ 135 Jy). A survey with intermediate sensitivity is one that could detect a 1-Hz wide signal from an Arecibo-like transmitter at 25 pc away but not at 75 pc away. Minimum detectable flux is further discussed in the next section.

\paragraph{}
\textbf{Figure \ref{fig3}} is a bit misleading, as sky coverage is in reality dependent on the frequency being observed. This is because sky coverage is a function of the telescope's \textbf{beamwidth}, which is itself inversely proportional to the operating frequency. A more accurate representation would show ranges following a descending slope. I think, however, the plot still achieves its objective of visually comparing SETI coverage in sky area and in frequency space.

\section{Sensitivity}

\paragraph{}
A survey's sensitivity is best described by the \textbf{minimum detectable flux} ($F_{\textrm{min}}$), as determined by \textbf{Equation \ref{eq2}} \citep{Price_2020}:

\begin{equation}
F_{\textrm{min}} \; = \; \textrm{SNR}_{\textrm{min}} \, \cdot \, \textrm{SEFD} \, \sqrt{\frac{\delta \nu}{n_{\textrm{pol}} \, \cdot \, \tau_{\textrm{obs}}}} \; ,
\label{eq2}
\end{equation}

where SNR$_{\textrm{min}}$ is the \textbf{signal-to-noise ratio threshold}, SEFD is the \textbf{system equivalent flux density}, $\delta \nu$ is the spectral resolution, $n_{\textrm{pol}}$ in the number of polarizations, and $\tau_{\textrm{obs}}$ is the observation time. The SEFD can be found by SEFD $= 2 k_{\textrm{B}} T_{\textrm{sys}} / A_{\textrm{eff}}$ (where $T_{\textrm{sys}}$ and $A_{\textrm{eff}}$ respectively represent the system temperature and effective collecting area of the telescope). Flux density is often measured in Janskys (Jy = $10^{-26}$ W/m$^2$/Hz).

\paragraph{}
Where the information was available, I plotted the minimum detectable flux of a project in relation to the sky coverage in \textbf{Figure \ref{fig4}}. The plot also shows the flux from a hypothetical Arecibo-like transmitter (10$^{13}$ W) at various distances from the receiver, assuming a transmission bandwidth of 1 Hz. The same information is displayed in \textbf{Figure \ref{fig5}}, but presented differently: this figure plots the distance a hypothetical Arecibo-like transmitter (10$^{13}$ W) must be to produce the minimum detectable flux of a survey, assuming 1-Hz transmission bandwidth. It is important to note that, in both \textbf{Figures \ref{fig4}} and \textbf{\ref{fig5}}, when a project consists of multiple instruments (e.g. Price 2020 or Project Phoenix), the sky coverage plotted corresponds to the total value for the entire project. These figures really showcase the strength of the (ongoing) survey using the MeerKAT array.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.46]{Figure3.pdf}
\caption{Minimum detectable flux of SETI projects \textbf{\label{fig4}}}
\end{center}
\end{figure}

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.46]{Figure4.pdf}
\caption{SETI projects' ability to detect an Arecibo-like transmitter \textbf{\label{fig5}}}
\end{center}
\end{figure}

\section{Drake Figure of Merit}

\paragraph{}
Yet another figure of merit used in comparing SETI projects is called the \textbf{Drake figure of merit} (DFM). This is described by \textbf{Equation \ref{eq3}} \citep{Price_2020}:

\begin{equation}
\textrm{DFM} \; = \; \frac{\upDelta \nu_{\textrm{tot}} \, \cdot \, \upOmega}{S_{\textrm{min}}^{3/2}} \; ,
\label{eq3}
\end{equation}

where $\upDelta \nu_{\textrm{tot}}$ is the total bandwidth in Hz, $\upOmega$ is sky coverage in square degrees, and $S_{\textrm{min}}$ is the minimum detectable flux density in Jy ($S_{\textrm{min}} = F_{\textrm{min}} / \delta \nu_{\textrm{t}}$), where we can assume the bandwidth of the transmitted signal to be $\delta \nu_{\textrm{t}}$ = 1 Hz.

\paragraph{}
\textbf{Figure \ref{fig6}} compares the Drake figure of merit of a number of SETI projects, where information was available. In this metric, the MeerKAT survey stands out again.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.54]{Figure5.png}
\caption{Drake figure of merit for SETI projects \textbf{\label{fig6}}}
\end{center}
\end{figure}

\section{Conclusions}

\paragraph{}
Over the years, SETI surveys have improved in their sensitivity and in the observation frequency range. Large variations in the parameters between projects have required me to use logarithmic scales in all my figures to be able to adequately make visual comparisons.

\paragraph{}
The ongoing search using the MeerKAT array in South Africa seems to be very promising thanks to its large sky coverage as well as high sensitivity. MeerKAT is expected to propel the Breakthrough Listen initiative in its target to survey one million stars for technosignatures.

\bibliography{references}

\end{document}


% ----------------------------------------------------------------
% Article Class (This is a LaTeX2e document)  ********************
% ----------------------------------------------------------------
\documentclass[11pt]{article}
\usepackage[english]{babel}
\usepackage{amsmath,amsthm, amssymb}
\usepackage{amsfonts}
\usepackage{multirow}
\usepackage{threeparttable}
\usepackage{enumerate}
\usepackage[utf8]{inputenc}
\usepackage{multicol}

%Candelaria's favorite packages
\usepackage{setspace}	% Set the spacing for the document
\usepackage{xtab}		% Use for tables
\usepackage{comment}	% Use for block comments
\usepackage{rotating}	% Helpful for rotating figures
\usepackage{lscape}	% Change a page into landscape
\usepackage{hyperref}
\hypersetup{colorlinks=false,pdfborder={0 0 0},breaklinks=true}
\usepackage{graphicx}	% Load a graphic image
%\usepackage{url}		% Use for formatting URLS (nice for NatBib also)
\usepackage{booktabs}  	% Use for nice tables/ Works well with ESTOUT
\usepackage{longtable} 	% Used to break long tables over multiple pages
\usepackage{caption}
\usepackage{subcaption} 	% Used to create SubFloats
\usepackage{listings} 	% Use to enter code blocks, like a fancy verbatim

% ADD COLOR:
\usepackage{color}
\usepackage[usenames, dvipsnames, svgnames, table]{xcolor}

% Packages for the bibliography
\usepackage[longnamesfirst]{natbib}
%\usepackage{natbib}

% Set Page Margins
%\usepackage{fullpage}
\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}
\addtolength{\topmargin}{-.875in}
\addtolength{\textheight}{1.75in}

% Set line and table spacing
\renewcommand{\baselinestretch}{1.0}
\renewcommand{\arraystretch}{1.1}
\setlength\abovedisplayskip{0pt}
\setlength\belowdisplayskip{0pt}

% Redefine the cite command
\renewcommand\cite{\citet}

%\setlength{\parindent}{0in}

%\setlength{\leftmargin}{0pt} \setlength{\parskip}{1.1ex} \setlength{\parindent}{1em} \setlength{\itemsep}{0pt} \setlength{\footnotesep}{10pt}
%\renewcommand{\footnoterule}{\rule{3in}{.3pt}\vspace{-.3pt}}

% THEOREMS -------------------------------------------------------
\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
%\numberwithin{equation}{section} %Number equations within section
% ----------------------------------------------------------------

% AUTHOR INFO

\title{Problem Set 7\\ Due: TBD}%

% ----------------------------------------------------------------

%%%%%%
% SHORT CITES
%%%%%%
\shortcites{ColEtAl1966}

\begin{document}

\begin{center}
{\huge Problem Set 4: Probability}\\[5pt]
\end{center}

\section*{Problem 1}
\begin{enumerate}
\item If you roll one die, what is the probability of rolling a 4?
{\color{red} One out of the six possible outcomes:
$$ P(4) = \frac{1}{6} $$}
\item If you roll one die, what is the probability of rolling \em at least \em a 4?
{\color{red} Out of the six possible outcomes, either a 4, 5, or 6 will work.
$$ P(\geq 4) = \frac{3}{6} = \frac{1}{2} $$}
\item If you roll two dice, what is the probability they sum to 4?
{\color{red} Rolling two dice has $6 \times 6 = 36$ possible outcomes. Of these, $(1, 3), (3,1),$ and $(2,2)$ will work.
$$ P(4) = \frac{3}{36} = \frac{1}{12} $$}
\item If you roll two dice, what is the probability they sum to \em at least \em a 4?
{\color{red} Of the 36 possible outcomes, we can count the ones that sum to 4 or greater, or recognize that the probabilities of all events must sum to one. So - first we find the probability that you roll a total of 3 or less:
$$ P(\leq 3) = \frac{3}{36} = \frac{1}{12} $$
Next, we recognize that:
$$ P(\geq 4) = 1 - P(\leq 3) $$
$$ P(\geq 4) = 1 - \frac{1}{12} = \frac{11}{12} $$
}
\end{enumerate}

\section*{Problem 2}
\begin{enumerate}
\item If you flip 10 coins, what is the probability that \em exactly \em four of them land on heads?
{\color{red}
These are often called ``Bernoulli trials,'' or an experiment repeated with a probability $p$ of success each time. If we consider heads to be our ``success'', $p=\frac{1}{2}$. The probability of observing exactly $k$ successes from $n$ trials is:
$$P(k) = \frac{n!}{k!(n-k)!}p^k(1-p)^{n-k}$$
So:
$$P(k=4) = \frac{10!}{4!(10-4)!}\bigg(\frac{1}{2}\bigg)^4\bigg(1-\frac{1}{2}\bigg)^{10-4}$$
$$P(k=4) = \frac{1\cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6 \cdot 7 \cdot 8 \cdot 9 \cdot 10}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6}\bigg(\frac{1}{2}\bigg)^{10}$$
$$P(k=4) = \frac{210}{2^{10}} = 0.205 $$}

\item If you were to flip 10 coins, what is the probability that \em at least \em four of them land on heads?
{\color{red} Similar to Problem 1.4 above, we write:
$$ P(\geq 4H) = 1 - (P(3H) + P(2H) + P(1H) + P(0H)) $$
Computing each of the probabilities separately:
$$ P(3H) = \frac{120}{2^{10}} = 0.117 $$
$$ P(2H) = \frac{45}{2^{10}} = 0.044 $$
$$ P(1H) = \frac{10}{2^{10}} = 0.010 $$
$$ P(\geq 4H) = 1 - (0.117 + 0.044 + 0.001) = 1 - 0.171 = 0.829 $$}

\item A box of 12 donuts has three cinnamon sugar, three glazed, three chocolate frosted and three maple (yuck).  If you were to reach into the box and select a donut at random, what would be the probability you select a non-maple donut?
{\color{red} $$P(\text{non-maple}) = \frac{9}{12} = \frac{3}{4} $$}

\item Pretend you are a monster who selects donuts at random, takes a bite and replaces them in the box.  How many donuts can you expect to bite before you taste your first maple donut?
{\color{red} From above, we know the probability of selecting a maple donut each time is $P(\text{maple}) = \frac{1}{4}$. If we consider this a ``success'' (what a terrible thing to consider success), theexpected number of trials until you reach a success is:
$$ E(\text{maple}) = \frac{1}{P(\text{maple})} = 4 $$}

\end{enumerate}

\section*{Bonus}
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, ``Do you want to pick door No. 2?" Is it to your advantage to switch your choice?  Explain your reasoning.

{\color{red} This is a fairly famous question known as the ``Monty Hall Problem.'' The short version is that you should always switch. Consider this, if you don't switch - you have a $\frac{1}{3}$ probability of guessing right on your first try. You might be tempted to think that after he shows you the goat, you now have a $\frac{1}{2}$ chance of winning the car, but this is untrue!

Think about what happens when you choose to switch. If you pick the correct door to start, you will lose when you switch (which occurs with probability $\frac{1}{3}$. If you pick a goat door to start (which occurs with probability $\frac{2}{3}$), if you switch, you'll end up with the car - making your probability of winning $\frac{2}{3}$!

If you don't buy this argument, write out the possibilities and what happens when you do/don't switch.
}
\section*{Bonus 2}
Assume you know nothing about your cohort other than that there are 30 people in it.  What is the probability that you share a birthday with someone in the cohort?  What is the probability that any two people in the cohort share a birthday?

{\color{red} Here's another famous problem, called the ``Birthday Problem.'' for someone else to have your birthday, let's first make two simplifying assumptions. First, birthdays are uniformly distributed across the calendar year (which is actually untrue). Next, assume that no one is born on a leap year (which is also wrong, but doesn't make much of a difference in the final answer).

Under these assumptions, the probability that someone else in your cohort shares your birthday is $\frac{29}{365} = 0.0795$. When you consider two people in a group sharing a birthday, however, things get a ittle weird.

First, recognize that the probability of two specific people having different birthdays is $\frac{364}{365}$.

Now, in a group of 30 people, we can make $_{30}C_2 = 435$ distinct pairs. So the probability that no two people share a birthday is:
$$P(\text{no pairs}) = \bigg(\frac{364}{365}\bigg)^{435} = 0.303$$
Now we see:
$$P(\text{at least one pair}) = 1 - 0.303 = 0.697 $$
Which is much higher than you may have expected!}

\section*{Super Bonus}
One hundred people line up to board an airplane. Each has a boarding pass with an assigned seat. However, the first person to board has lost his boarding pass and takes a random seat. After that, each person takes the assigned seat if it is unoccupied, and one of unoccupied seats at random otherwise. What is the probability that the last person to board gets to sit in his assigned seat?

{\color{red} Another classic puzzle! There are a number of ways to think about this problem, but here's one:

Every time a pasenger's seat is taken, there is an equal chance that they end up in any open seat - this include's the first passenger's seat and the last passenger's seat. As soon as someone ends up in the first passenger's seat, the last passenger will be able to get their own. If someone ends up in the last passenger's seat first, however, that last passenger has no hope of getting to their real seat.

Because at each step, those events are equally likely, the probability the last passenger gets their assigned seat is precisely $\frac{1}{2}$.}

\end{document}


\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[USenglish]{babel}
\usepackage[nodayofweek,level]{datetime}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{intersections,arrows.meta}
\usepackage{pgfplots}
\usepackage[scr]{rsfso}
\usepackage{array}
\usepackage{stackengine}
\stackMath

\usepackage{tikz,pgfplots}

\pgfplotsset{compat=1.10}
% Uncomment to use "fillbetween" function
% otherwise leave commented because
% the red highlighting is annoying
%\usepgfplotslibrary{fillbetween}

% Change for each new hw week
\newcommand{\dueDate}{\formatdate{27}{10}{2017}} % day/month/year
\newcommand{\hwNum}{4}

\begin{document}

\selectlanguage{USenglish}
%------------------------ Title Code ------------------------
\title{Homework: Week \hwNum}
\author{Joseph Ismailyan}
\date{}
\maketitle
\begin{flushleft}
Math 100 \\
Due: \dueDate \\
Professor Boltje \\
MWF 9:20a-10:25a
\end{flushleft}

%------------------------ Begin Page 1 ------------------------
\begin{minipage}[t]{0.40\textwidth}

\section*{Section 3.5}
\subsection*{6.}
The statement is \textbf{false} because it does not take into account the subsets $ A_1\cap A_2, A_2\cap A_3, $ and $ A_1\cap A_3 $ so these will be double counted and give the wrong cardinality.

\subsection*{8.}
This problem can be split into four simpler problems of choosing one card from each suit, then \\
multiplying them to find the overlap. After that, we add the number of ways to get only red cards.
\[
\stackon{13\choose1}{heart}*\stackon{13\choose1}{diamond}*\stackon{13\choose1}{spade}*\stackon{13\choose1}{clover}={13\choose1}^4
\]
\[
{13\choose1}^4 + {26\choose4} = 43,511
\]

\end{minipage}
% Creates verticle line
\hfill\vline\hfill
\begin{minipage}[t]{0.45\textwidth}

\section*{Chapter 4}
\subsection*{6.}
\textbf{Proposition} Let $ a,b,c \in \mathbb{Z} $\\
$ \text{ If } a|b \text{, and } a|c\text{ then } a|(b+c)$\\\\
\textit{Proof.} Suppose $ a|b $ and $ a|c.$
By definition, $ a|b $ means there is an integer $ n $ with $ b=an $ and  $ a|c $ means there is an integer $ m $ with $ c=am $. Thus, $ a|(b+c) $ means $ (b+c) = an+am \rightarrow (b+c)= (n+m)a$ for the integer $ x=(n+m) $.
Therefore $ a|(b+c). $
$ \hfill\blacksquare $

\subsection*{8.}
\textbf{Proposition} Let $ a\in \mathbb{Z} $\\
$ \text{ If } 5|2a \text{ then } 5|a$.\\\\
\textit{Proof.} Suppose
$ 5|2a $. Then $ 2a=5b$ where $ b\in \mathbb{Z}$. Since $ 2a $ is even, we can say that $ 5n $ is also even. Then $ n $ must be even, because an odd $ n $ would produce an odd $ 5n $ which cannot be equal to $ 2a $. So then $ b=2m $ where $  m\in \mathbb{Z}$. Then $ 2a=5(2m) \rightarrow 2a=10m $ simplifies to $ a=5m. $ The equation $ a=5m $ means $ 5|a $ by definition of divisibility.
$ \hfill\blacksquare $

\end{minipage}
\pagebreak

%------------------------ End Page 1 ------------------------

%------------------------ Begin Page 2 ----------------------

\begin{minipage}[t]{0.40\textwidth}

\subsection*{10.}

\textbf{Proposition} Let $ a,b\in \mathbb{Z} .$\\
$ \text{ If } a|b \text{ then } a|(3b^3-b^2+5b)$.\\\\
\textit{Proof.} Suppose $ a|b $ where $ a,b\in \mathbb{Z} $. Since $ a|b $, there exists an integer $ n $ where $ b=an $, which we can substitute that into the equation $ (3b^3-b^2+5b) = (3(an)^3-(an)^2+5(an)) \newline =(3a^3b^3-a^2b^2+5an) \newline =(3a^2b^3-ab^2+5n)a \newline =ma$ where $ m=(3a^2b^3-ab^2+5n) $ Therefore $ (3b^3-b^2+5b) =ma $ for some integer $ m. \newline$ Thus, $  a|(3b^3-b^2+5b) $.
$ \hfill\blacksquare $

\subsection*{20.}
\textbf{Proposition} Let $ a\in \mathbb{Z} .$\\
$ \text{ If } a^2|a \text{ then }a\in\{-1,0,1\} $.\\\\
\textit{Proof.} Suppose $ a^2|a$ where $  a\in \mathbb{Z}.\newline $
Since $ a^2|a $, there exists an integer $ n $ where $ a=na^2 $. Subtracting $ a $ from both sides gives us $ 0=na^2-a \newline \implies 0=a(na-1) $. So $ a=0 $ or $ 0=na-1 \implies na=1$. Therefore $ a $ can be $ -1,0,$ or $1 . \newline$ Thus $ a=\{-1,0,1\}.$
$\hfill\blacksquare$

\end{minipage}
% Creates verticle line
\hfill\vline\hfill
\begin{minipage}[t]{0.45\textwidth}

\subsection*{24.}
\textbf{Proposition} If $ n \in\mathbb{N} $ and $ n\geq 2 $ then the numbers $ n!+2, n!+3, n!+4, n!+5,....n!+n $ are all composite.\\
\textit{Proof.}
Suppose $ n \in\mathbb{N} $ and $ n\geq 2 $, and $ k\in\{2, 3,..., n\} $. Consider the definition of a prime number \textit{A whole number that cannot be divided evenly by numbers other than 1 or itself.} In order to prove the proposition, we must prove that all numbers through $ n!+n $ have more divisors than just $ 1 $ and itself. First lets consider $ n!+2 =2(\frac{n!+2}{2})=2(\frac{n!}{2}+1) $ which makes it clear that $ 2 $ is a divisor. Since $ n\geq 2 $, it cannot be equal to $ 2 $ and so it is a composite number. We can apply this same logic to $ n!+n =n(\frac{n!+n}{n})=n(\frac{n!}{n}+1) $ which shows that $ n $ is a divisor. Since $ n\geq 2 $, it cannot be equal to $ n $ and so it is a composite number. And finally, we can use these examples to prove the general case with the arbitrary value $ k $. If $ n!+k $ then $ k(\frac{n!+k}{k})=k(\frac{n!}{k}+1) $ which shows $ k $ to be a divisor. Since $ n\geq 2 $, it cannot be equal to $ k $ and so it is a composite number. Therefore the numbers $ n!+2, n!+3, n!+4, n!+5,....n!+k $ are all composite.
$\hfill\blacksquare$

\subsection*{26.}
\textbf{Proposition} Every odd integer is a difference of two squares.\\
\textit{Proof.} Suppose $ n,m\in\mathbb{Z} $ and $ k $ is an odd integer, which by definition of being odd, in the form $ 2m-1 $. The difference of two squares can be defined as such: $ k=2m-1\rightarrow 2m-1=(n)^2-(n-1)^2 $ which can be simplified to $ n^2-(n^2-2n+1)=n^2-n^2+2n-1=2n-1. $. The number $ 2n-1 $ is not divisible by $ 2 $ so it odd. Therefore, every odd integer is a difference of two squares.
$\hfill\blacksquare$

\end{minipage}
\pagebreak

%------------------------ End Page 2 ------------------------

%------------------------ Begin Page 3 ----------------------

\begin{minipage}[t]{0.40\textwidth}

\section*{Additional Hwk}
\textbf{Proposition}  Let $a,b\in\mathbb{Z}$, $n\in\mathbb{N}$, $a=qn+r$, $b=q'n+s$ with $q,q'\in\mathbb{Z}$, $r,s\in\{0,1,\ldots,n-1\}$.  $a\equiv b$ $(\mathrm{mod}\ n)$ if and only if $r=s$\\
Note: To complete this proof if the "if and only if" format, I'll first prove that if $a\equiv b$ $(\mathrm{mod}\ n)$ then $ r=s $. Followed by if $ r=s $ then $ a\equiv b$ $(\mathrm{mod}\ n). $
\subsection*{Part A}
\textbf{Proposition} Let $a,b\in\mathbb{Z}$, $n\in\mathbb{N}$, $a=qn+r$, $b=q'n+s$ with $q,q'\in\mathbb{Z}$, $r,s\in\{0,1,\ldots,n-1\}$. If $ a\equiv b(\mathrm{mod}\ n) $ then $ r=s. $\\
\textit{Proof.} Suppose $a\equiv b$ $(\mathrm{mod}\ n)$. Then $ b-a $ is divisible by $ n $, which is notated by $ n|b-a $. Then, by the definition of divisibility, $ b-a=dn, d\in\mathbb{Z}$. Then we can simplify to $ dn=b-a \newline\rightarrow q'n +s-(qn+r)=q'n +s-qn-r=q'n-qn+(s-r)=(q'-q)n+(s-r)$. Since $ r-s $ is divisible by $ n $, it follows that $ s-r $ must be $ 0 $ since $ 1-n\leq r-s \leq n-1 $. $ s-r=0 $ only if $ r=s $, therefore if $ a\equiv b(\mathrm{mod} n) $ then $ r=s. $

\end{minipage}
% Creates verticle line
\hfill\vline\hfill
\begin{minipage}[t]{0.45\textwidth}
\subsection*{Part B}
\textbf{Proposition} Let $a,b\in\mathbb{Z}$, $n\in\mathbb{N}$, $a=qn+r$, $b=q'n+s$ with $q,q'\in\mathbb{Z}$, $r,s\in\{0,1,\ldots,n-1\}$. If $ r=s. $ then $a\equiv b(\mathrm{mod}\ n).$\\
\textit{Proof.} Suppose $ r=s $. This means that $ a $ and $ b $ have the same remainder after being divided by $ n $. So then $ b-a $ must also be divisible by $ n $, which can be shown by $ b-a=q'n+r-(qn+r)=q'n+r-qn-r=(q'-q)n. $ Therefore $ b-a $ is divisible by $ n $ which can be written as $ a\equiv b(\mathrm{mod} n) $

\subsection*{Part C}
In part A I showed that if $ a\equiv b(\mathrm{mod} n) $ then $ r=s $, or $a\equiv b(\mathrm{mod} n) \implies r=s $, and in part B I showed that if $ r=s $ then  $ a\equiv b(\mathrm{mod} n) $, or $ r=s \implies a\equiv b(\mathrm{mod} n) .$ Therefore we can combine these statements and get  $ a\equiv b(\mathrm{mod} n)   \Leftrightarrow  r=s$
$\hfill\blacksquare$

\end{minipage}
\pagebreak

%------------------------ End Page 3 ------------------------

\end{document}


\documentclass[12pt, oneside]{scrbook}
\usepackage[a4paper,%
            left=3.81cm,right=2.54cm,top=2.54cm,bottom=2.54cm,%
           ]{geometry}
\usepackage[utf8]{inputenc}

\usepackage{amsmath, mathtools}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage{enumitem}

\usepackage{hyperref}

\usepackage{subfiles}

\usepackage{tikz}
\usetikzlibrary{cd}
\usepackage{subcaption}
\usepackage{relsize}
\usepackage{mathpartir}

\usepackage[T1]{fontenc}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{exmp}
\newtheorem{exmp}{Example}[section]

\usepackage[
backend=biber,
style=alphabetic,
sorting=nyt
]{biblatex}
\addbibresource{bibliography.bib}

\begin{document}

\author{Saran Sankar}
\title{Algebraic geometry notes}
\date{}
\maketitle

\chapter*{Preface}

\addcontentsline{toc}{chapter}{Preface}

Mostly notes taken during self-study of \cite{shafarevich2013basic} with some gaps filled in from other sources.  Things are reformulated and simplified using the categorical language whenever possible.

\tableofcontents

\subfile{prelim.tex}

\subfile{schemes.tex}

\printbibliography

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%																		 			%%
%																		 			%%
%																		 			%%
%																		 			%%
%						Document: Written by Marly Tatiana Celis Galvez 			%%
%						Assignment Part I Time Series Applied Macroeconometrics		%%
%																		 			%%
%																		 			%%
%																		 			%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[margin=70pt]{geometry}

%References
\usepackage[style=authoryear,sorting=nyt,backend=biber]{biblatex}
		%\addbibresource{D:/Thesis/to_overleaf.bib}
%
%\usepackage{shellesc}
\usepackage{minted}
%[cache=false]
%
\usepackage{standalone}
\usepackage[hidelinks]{hyperref}
\usepackage{csquotes}
%When using babel or polyglossia with biblatex, loading csquotes is recommended
%to ensure that quoted texts are typeset according to the rules of your main language.

%Math packages
\usepackage{amsfonts,latexsym,amsthm,amssymb,amsmath,amscd,euscript}
\usepackage{mathtools}
%Images packages
\usepackage{float}
\restylefloat{table}
\usepackage{tikz}
\usetikzlibrary{positioning}

\usepackage{array}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{tabularx,ragged2e,booktabs,caption}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
%\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
%\pagestyle{fancy}

	\usepackage{fancyhdr}
	\pagestyle{fancy}
	\fancyhf{}
	\rhead{Marly Tatiana Celis}
	\lhead{Groningen University - Utretch University}
	\lfoot{\href{mailto:m.t.celis.galvez.1@student.rug.nl}{{\tt m.t.celis.galvez.1@student.rug.nl}}}

%$ latex -shell-escape input
%																		 			%%
%																		 			%%
%																		 			%%
%																		 			%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%																		 			%%
%																		 			%%
%																		 			%%
\begin{document}
%																		 			%%
%																		 			%%
%																		 			%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
	\Large Applied Macroeconometrics 2021 \\
	Assignment Part I Time series econometrics
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

This document contains my solutions for the assignment 1 for the course Applied Macro Econometrics 2021, an elective taken at Groningen University. \\
\indent Marly Tatiana Celis Galvez \\
\indent Research Master - Multidisciplinary Economics \\
\indent Utrecht University

\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\section{Exercise 1}

Multivariate time series modelling\\

Aruba is a island and a constituent country of the Netherlands in the southern Caribean sea. Before COVID-19, about three-quarters of the Aruban gross national product was earned through tourism and related activities. Most tourists cam from North America, with a market-share of 73.3\%, followed by Latin America with 15.2\% and Europe with 8.3\%. The spreadsheet tourism series.xlsx has monthly series of stay-over visitors, visitor's nights, cruise visitors and ship calls.

\subsection{Descriptive part}
\subsubsection{Informative graphs}
Design informative graphs of and describe patterns in the series of cruise visitors and stay-over visitors to Aruba
For the first question I will plot the series. Perhaps, I'll try to observe the components of the series, for example, the trend, the  cycle, the seasonality, and the irregular part. At the least, I will discuss it. \\
In addition,  I can graph some correlograms \\

Before I can tell something about modelling the relationship between the two variables, I graphed the series to look for visible problems with the series. Such problems can include seasonal patterns, abrupt changes, discontinuities, and outliers.
%Changes in the seasonal pattern that occur sufficiently far back in the past can be avoided sumpy by advancing the starting date of the used for adjustment or for modeling.
\begin{figure}[h!]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/lStayovervisitorsin1000.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/lShipcalls.png}
    \end{subfigure}
    \begin{subfigure}[b]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/lCruisevisitorsin1000.png}
    \end{subfigure}
        \begin{subfigure}[b]{0.45\textwidth}
        \includegraphics[width=\textwidth]{plots_1/lVisitorsnightsin1000.png}
    \end{subfigure}
    % \begin{subfigure}[b]{0.3\textwidth}
    %       \includegraphics[width=\textwidth]{Project_2/imgs/2/graph0.4.png}
    % \end{subfigure}
    % \begin{subfigure}[b]{0.3\textwidth}
    %       \includegraphics[width=\textwidth]{Project_2/imgs/2/graph1.png}
    % \end{subfigure}
    \caption{Series Tourism Aruba 2005-2018}
    \label{fig:originalseries}
\end{figure}

The corrgram command lists a table of autocorrelations, partial autocorrelations,
and Q statistics. It will also list a character-based plot of the autocorrelations and
partial autocorrelations

\begin{figure}[h!]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/pergram_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/pergram_2.png}
    \end{subfigure}
    \caption{Series Tourism Aruba 2005-2018}
    \label{fig:pergrams}
\end{figure}

Autocorrelation function

\begin{figure}[H]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/cruise_ac_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/cruise_pac_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/stay_ac_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/stay_pac_1.png}
    \end{subfigure}
    \caption{AC and PACF 2005-2018}
    \label{fig:autorro}
\end{figure}

\begin{figure}[H]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/cruise_spect_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/stay_spect_1.png}
    \end{subfigure}
    \caption{Series Tourism Aruba 2005-2018}
    \label{fig:sepctral}
\end{figure}

\subsubsection{Modelling}
How would you proceed modelling the relationship between the two variables?. \\

For this second question, I would suggest to estimate a VAR model. A VAR model fits multivariate time-series regression of each of two series of our interest.\\
I would also take several steps:
\begin{itemize}
    \item Discount the seasonal component first. The main reason I would do so is because the series are related to tourism, which is in itself a phenomena that is related with seasonal changes. Particularly, monthly changes. For instance, it is well know that in tourism there are the so-called hot seasons, which are a time of the year when the number of people that prefer to spend their vacation on warmer places increases. Consequently, I expect that the behaviour of these series is affected by those kind of seasonal components.
    \item I should establish whether the series are non stationary. A stationary process is such that the mean, variances and covariances of the disturbances term $\epsilon_t$ do not change over time. Once I define the stationary process I will be sure that I am not finding spurious relations between the two series.
%a process is said to be stationary if its probability distribution remains unchanged as time progresses
    \item I would also check whether the stationary process are cointegrated. As we know, when two $I(1)$ variables are cointegrated, or it exists a particular linear combination of these nonstationanry variables which is stationary. Indeed, cointegrated models stand that "In such cases a long-run relationship between these variables exists". The existence of a long-run relationship also has its implications for the short-run behaviour of the $I(1)$ variables, because there has to be some mechanism that drive the variables to their long-run equilibrium relationship.
\end{itemize}

I graph the two series without any adjustment, as shown in \ref{fig:behavriora} and \ref{fig:behavriorb}. However the seasonal component is strong and do not allow to perceive a clear relationship.
\begin{figure}[h!]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/orginal_nologs.png}
         \caption{Series Tourism Aruba 2005-2018 in Levels}
         \label{fig:behavriora}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/series_originales.png}
          \caption{Series Tourism Aruba 2005-2018 in Logs}
    \label{fig:behavriorb}
    \end{subfigure}
\end{figure}
The scatter plot of the two series reveals a potential statistical relationship.
\begin{figure}[h!]
    \centering
     \includegraphics[width=0.6\textwidth]{plots_1/correlation_1.png}
     \caption{Scatter Plot - Series Tourism Aruba 2005-2018}
    \label{fig:scatter}
\end{figure}

\newpage
\subsection{Seasonality study}
For this part of the exercise I calculate natural logarithms and apply the seasonal adjustment filters X-13 ARIMA SEATS and CAMPLET to the two visitors series.
%To solve this exercise then I calculate the logarithm in excel for camplet
%And I use the file series.xlsx which contains only the two series of interest: cruise vistors and stayover visitors
% \begin{itemize}
% \item Compare outcomes for the seasonally adjusted series data
% \item Do the seasonal adjustment filters produce similar seasonal patterns?
% \item What happens if the last year of quarterly observations is discarded in the seasonal adjustment?
% \item Do the seasonally adjusted data lead to changes in your modelling approach described above?
% \end{itemize}

\subsubsection{Seasonal Adjustment with Camplet}
The objective is to get as high an accuracy percentage as possible. As a rule of thumb an accuracy over 60% gives reliable short extrapolations

\begin{table}[H]
\centering
\captionof{table}{CAMPLET Adjustment Results} \label{tab:title}
\begin{tabular}{ l| c|c|c|c|c|c }
\toprule[1.25pt]
Series & Accuracy & Common adjustment & Multiplier & Pattern & LE & T \\
\midrule
Cruise visitors & 58 & 1.5 & 50 & 1 & 8 & 1 \\
Stay over visitors & 81 & 	1.5 & 50 & 1 & 8 & 1 \\
LN Cruise visitors & 76 & 	1.5 & 50 & 1 & 8 & 1 \\
LN Stay over visitors & 95 & 	1.5 & 50 & 1 & 8 & 1\\
\bottomrule[1.25pt]
\end{tabular}
\par
\end{table}

%Charts
% cam_crui_1.png cam_crui_2.png
% cam_stay_1.png cam_stay_2.png
\begin{figure}[H]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/cam_crui_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/cam_crui_2.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/cam_stay_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/cam_stay_2.png}
    \end{subfigure}
    \caption{Seasonal components for Cruise series using X-13 Arima Seats}
    \label{fig:campletadj1}
\end{figure}

Interpretation:
\begin{itemize}
\item Accuracy. The efficacy of extrapolations is high. Both of the series have an accuracy over 60\%; hence, it is possible to say that the adjustment has reliable short extrapolations.
\item Common adjustment. The applied length of the series is 1.5 years.
\item Multiplier. The applied length is 50 times the percentage deviation of the extrapolation from the measured value.
\item Pattern. The pattern is one year.
\item Limit to error. The tolerance of deviation beyond the series' path is 8\%.
\item Time. How often an outlier must return in corresponding periods to be dubbed a shift of pattern is 1.
\end{itemize}

\subsubsection{Seasonal Adjustment with X13 Arima Seats}
I downloaded the exectuable \textbf{X13Data.exe} from \href{https://www.census.gov/srd/www/x13as/}{www.census.gov}
%
% Contains a subdirectory named x13as with the following contents:
% the program x13as.exe (the X-13ARIMA-SEATS executable),
% a sample input file named testairline.spc,
% the Reference Manual and PC Quick Reference in a subdirectory named docs,
% and two Icon programs to assist users of X-13ARIMA-SEATS in a subdirectory named tools: genhol.exe (which generates user-defined regressors for moving holidays) and cnvx13as.exe (which converts spec files used with X-12-ARIMA to files that can be used with X-13ARIMA-SEATS), along with their documentation.
\begin{figure}[h!]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/x13_crui_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/x13_crui_2.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/x13_crui_3.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/x13_crui_4.png}
    \end{subfigure}
    \caption{Seasonal components for Cruise series using X-13 Arima Seats}
    \label{fig:x13arimacruise1}
\end{figure}

\begin{figure}[h!]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/x13_stay_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/x13_stay_2.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/x13_stay_3.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/x13_stay_4.png}
    \end{subfigure}
    \caption{Seasonal components for Stay-over series using X-13 Arima Seats}
    \label{fig:x13arimastay1}
\end{figure}

\newpage
\subsection{Compare outcomes for the seasonally adjusted series data}
The comparison is shown in the graphs in figures \ref{fig:campletx13d}

\subsection{Do the seasonal adjustment filters produce similar seasonal patterns?}
Yes, both seasonal filters produce very similar patterns. As shown in the graphs \ref{fig:campletx13d} where series in blue represent Cruise Visitors, and series in red Stay-Over Visitors. The dashed lines are the series generated by Camplet and the solid lines are the series generated by X13 Arima Seats.\\

Some gaps can be seen in the seasonal adjustment of the Cruise Visitors series. This could be due to missing values from october, november and decemeber of 2005. I believe that it means that the Camplet algorithm is much more sensitive to gaps than X13 Arima Seats.
%	camp_vs_x13_1.png camp_vs_x13_2.png
%	camp_vs_x13_3.png camp_vs_x13_4.png

\begin{figure}[H]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/camp_vs_x13_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/camp_vs_x13_2.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/camp_vs_x13_3.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/camp_vs_x13_4.png}
    \end{subfigure}
    \caption{Comparison of the two seasonal adjustments.\label{fig:campletx13d}}
\end{figure}

\subsection{What happens if the last year of quarterly observations is discarded in the seasonal adjustment?}
% camp_vs_x13_1_b.png camp_vs_x13_2_b.png
% 	cruise_stay_camplet_1_b.png cruise_stay_x13_1_b.png
In general the adjustment does not change. Although for the cruise visitors series the gap between the two seasonal adjustment closes.

\begin{figure}[H]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/camp_vs_x13_1_b.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/camp_vs_x13_2_b.png}
    \end{subfigure}
    \caption{Cruise visitors vs Stay Over- without last year of quarterly observations}
    \label{fig:minus4months}
\end{figure}

\subsection{Do the seasonally adjusted data lead to changes in your modelling}
Do the seasonally adjusted data lead to changes in your modelling approach described above? Not really, the seasonally adjusted data confirms that the two series behave in correspondence to each other. The graphs \ref{fig:behaviourafteradjs} confirm that there is a common behaviour between the two series. For instance, When one of the series has particularly high values, the other exhibits the opposite- low values. This happens during 2005 and 2015. The X13 Arima Seats shows this constants more clearly. Consequently, I will consider a VAR model where both of the series are Cointegrated.

%cruise_stay_camplet_1
%cruise_stay_x13_1

\begin{figure}[h!]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/cruise_stay_camplet_1.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/cruise_stay_x13_1.png}
    \end{subfigure}
    \caption{Comparison two series after adjustment}
    \label{fig:behaviourafteradjs}
\end{figure}

%cruise_stay_camplet_1_c.png
	%cruise_stay_x13_1_c.png

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\section{Exercise 2 Stationarity and Granger-causality}

\subsection{Unit-roots}
Test both visitors series for unitroots using ADF and KPSS test. What are your findings?\\

I use the command \textbf{dfuller} in Stata which performs the augmented Dickey-Fuller test that a variable follows a unit-root process. This command allows me to test four cases: (1) Default Unit Root as random walk without drift, (2) Random walk with trend, (3) Random walk with drift, and (4) Random walk with a constant. I represent these four cases in the following two tables. \\
In every case, the null hypothesis is that the series contains a unit root, and the alternative is that the variable was generated by a stationary process. \\
In table \ref{tab:dfuller1}, I report the Test Statistic of each regression and the MacKinnon approximate p-value for Z(t). In addition, I perform the test for the two adjusted versions of the two series.

% For 152 observations, Dickey-Fuller test for unit root presents the following critical values
% \begin{center}
% \captionof{table}{Unit Root Tests Dickey Fuller} \label{tab:dfuller1}
%     \begin{tabular}{c|c|c|c|c}
%     \toprule
%         &   Test        & 1\% Critical	& 5 \%	Critical	& 10\%	Critical \\
%         &	Statistic   &		Value	& Value             &		Value \\
% Z(t)    &	-3.923	    &	-3.493	    &	-2.887          &		-2.577 \\
%     \bottomrule
%     \end{tabular}
% \end{center}

%
\begin{table} \centering
\captionof{table}{Unit Root Tests Dickey Fuller} \label{tab:dfuller1}
        \begin{tabular}{l c|c|c|c|c}
\toprule
            &   \multicolumn{2}{c}{ LN Cruise Seasonally Adj} &    \multicolumn{2}{c}{LN Stay-Over Seasonally Adj}\\
%\midrule
            &    Camplet &  X13-Seats &     Camplet &  X13-Seats \\
            \midrule
\multirow{ 2}{*}{Unit Root} & Zt          &      -3.923&      -1.818&      -1.837&      -1.529 \\
& p           &       0.002&       0.372&       0.362&       0.519\\
\hline
\multirow{ 2}{*}{Trend} & Zt          &      -4.883&      -3.406&      -3.707&      -2.257\\
& p           &       0.000&       0.051&       0.022&       0.458\\
\hline
\multirow{ 2}{*}{Drift} & Zt          &      -3.923&      -1.818&      -1.837&      -1.529\\
& p           &       0.000&       0.036&       0.034&       0.064\\
\hline
\multirow{ 2}{*}{Constant} & Zt          &      -3.923&      -1.818&      -1.837&      -1.529\\
& p           &       0.002&       0.372&       0.362&       0.519\\
\bottomrule
\end{tabular}
\end{table}

With the seasonal adjusted series by Camplet I can reject the null hypothesis that log Cruise Visitors exhibits a unit root. However, with the seasonal adjusted series by X13 Arima Seats I cannot reject the null hypothesis that the Cruise and Stay Over series exhibit a unit root.

I then test the Integrated series of order $I(1)$ using again Dickey-Fuller test. The null hypothesis is similar. $H_0$ is that the integrated series contain a unit root, and the alternative is that the series is a stationary process. Now all the p-values indicate that it is possible to reject the null hypothesis for unit roots.
\begin{center}
        \begin{tabular}{l c|P{2.5cm}|P{2.5cm}|P{2.5cm}|P{2.5cm}}
\toprule
            &   \multicolumn{2}{c}{$I(1)$ LN Cruise Seasonally Adj} &    \multicolumn{2}{c}{$I(1)$ LN Stay-Over Seasonally Adj}\\
 &    Camplet &  X13-Seats &     Camplet &  X13-Seats \\
\midrule
\multirow{ 2}{*}{Unit Root} & Zt          &     -14.686&     -23.322&     -18.769&     -13.336\\
& p           &       0.000&       0.000&       0.000&       0.000\\
\hline
\multirow{ 2}{*}{Trend} & Zt          &     -14.647&     -23.443&     -18.743&     -13.355\\
& p           &       0.000&       0.000&       0.000&       0.000\\
\hline
\multirow{ 2}{*}{Drift} & Zt          &     -14.686&     -23.322&     -18.769&     -13.336\\
& p           &       0.000&       0.000&       0.000&       0.000\\
\hline
\multirow{ 2}{*}{Constant} & Zt          &     -14.686&     -23.322&     -18.769&     -13.336\\
& p           &       0.000&       0.000&       0.000&       0.000\\
\bottomrule
\end{tabular}
\end{center}

Similarly, Stata has the routine \textbf{kpss} that performs the Kwiatkowski-Phillips-Schmidt-Shin test for trend stationarity. In this test, the null hypothesis claims stationary versus an alternative hyphotesis of non-trend stationarity. According to the Stata output, the KPSS test the number of lags used for this series is a maximum of 13 chosen by Schwert criterion. It contrasts the test statistic for each lag against the critical values. Moreover, it computes autocovariances weighted by Bartlett kernel. In the table \ref{tab:kpss} I report the test statistic for the lag order 0 and lag order 13, for the log version of the adjusted series and the integrated $I(1)$ version of the series.

\begin{table} \centering
\captionof{table}{Unit Root Tests KPSS} \label{tab:kpss}
        \begin{tabular}{l|P{2.5cm}|P{2.5cm}|P{2.5cm}|P{2.5cm}}
\toprule
            &   \multicolumn{2}{c}{Cruise Seasonally Adj} &    \multicolumn{2}{c}{Stay-Over Seasonally Adj}\\
\midrule
LN          &            &            &            &            \\
Lag(0)      &       0.860&       2.208&       0.810&       0.903\\
Lag(13)     &       0.178&       0.219&       0.093&       0.097\\
\midrule
D1          &            &            &            &            \\
Lag(0)      &       0.011&       0.011&       0.024&       0.048\\
Lag(13)     &       0.060&       0.049&       0.071&       0.077\\
\bottomrule
\multicolumn{5}{l}{Critical values for $H_0$: Series are trend stationary}\\
\multicolumn{5}{l}{10\%: 0.119  5\% : 0.146  2.5\%: 0.176  1\% : 0.216}
\end{tabular}
\end{table}

Once the series are differentiated I cannot reject the null $H_0$ that the two series are trend stationary. In other words, the first difference is necessary to analyze the underlying stationary process of the seasonally adjusted series of Cruise visitors and Stay-Over visitors.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Granger Causality}
Test the two seasonally adjusted visitors for Granger-causality. What do you find? Do you think this outcome is plausible? Motivate your answer. \\

To test Granger Causality I use two Stata commands. First I run a VAR regression between the seasonally adjusted series, not yet integrated. Second I use the command \textbf{vargranger}. The output of the VAR regressions below. Here I report the $chi2$ statistic and the pvalue of the Granger test. \\
The first row of table \ref{tab:granger} is a Wald test that the coefficients on the two lags of Stay-Over visitors that appear in the regression for Cruise visitors. The null hypothesis being that the coefficients are jointly zero.
The second row, is the Wald test for the coefficients on the two lags of Cruise visitors in the regression for Stay-Over.

\begin{table} \centering
\captionof{table}{Granger Causality Test} \label{tab:granger}
        \begin{tabular}{l|P{2.5cm}|P{2.5cm}|P{2.5cm}}
\toprule
	& chi2	& df & 	p \\
\midrule
Cruise : Stay-Over &	4.699 &	2 &	0.095 \\
%Cruise : All & 	4.699 & 	2	& 0.095 \\
\hline
Stay-Over : Cruise &	1.792 &	2	& 0.408  \\
%Stay-Over : ALL &	1.792	& 2	& 0.408 \\
\bottomrule
\end{tabular}
\end{table}

The results show that the null hypothesis that Stay-Over visitors does not Granger-cause cruise cannot be rejected. Hence, I cannot reject the hypothesis that stay-over visitors does not \textit{Granger-cause} cruise visitors. This is clear evidence that a long run steady state equilibrium exist between the two series.

For me this result makes sense because Cointegration is a property of nonstationary series, which is the case of the two series of the analysis. In addition, the time-behaviour of the series showed some trade-off between the series. Particularly, during 2005 and 2015. Moreover, from an economic perspective one can expected that the dynamics between Cruise Visitors complements the dynamics of Stay-Over visitors in the long run.

\input{tables/var_cam}
\input{tables/var_x13}
\input{tables/granger}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\section{Exercise 3 VAR and VECM}

Columns 2-5 and 6-9 of Table 1 show two types of impulse responses with standard deviation between brackets of the VAR model of the logs of seasonally adjusted series, with a constant and a trend and three lags.

\subsection{Ortogonalized and generalized Impulse Responses}
Which columns give orthogonalized IRs (OIRs) and which generalized IRs? What is the ordering used in the OIRs? Can you comment on the plausibility of this assumption?. \\

Since it is known that Generalized Impulse Responses coincides with Orthogonalized Impulse Responses for the most endogenous variable in the VAR, and the table provided I hardly see a difference between the two columns, I conclude that the two variables and their shocks are likely correlated. Hence in this VAR model there is no ordering of the variables. It cannot be said that there is a more exogenous or endogeneous variable than the other.\\
I believe that this makes sense in the case of the tourism series because both may depend on similar economic factors and are affected by similar shocks. Perhaps further variables should be included in the model.

\subsection{VAR}
Rewrite a vector autoregressive (VAR) system with three lags in zt, which consists of two variables, as a Vector Error Correction Model.

Let's say that the VAR(3) is

\begin{align*}
 z_{t} & = \Phi_1 z_{t-1} + \Phi_2 z_{t-2} +\Phi_3 z_{t-3} + u_t \\
  & \text{where} \; z_t \; \text{is a 2 dimensional vector: Cruise and Stay Over} \\
 &  \Phi_i \; i=1,2,3 \; 2\times 2 \; \text{matrices of fixed coefficients}\\
  &  u_t \; \text{is a mean zero serially uncorrelated vector of disturbances} \\
\text{In matrix notation} & \\
  & \mathbf{z}_t=\mathbf{A(L)} \mathbf{z}_t + \mathbf{e}_t \; , \qquad
 \mathbf{e}_t ~ \; (0, \mathbf{\Omega})  \\
 & \text{where} \; \mathbf{A(L)} \text{is degree} \; 3 \\
 \text{VECM representation} & \\
 & \mathbf{A}*(L)\Delta \mathbf{z}_t = - \Pi \mathbf{z}_{t-1} + \mathbf{e}_t\\
 & \Pi = \mathbf{A}(3) \; \text{degree of} \; \mathbf{A}*(L)=(3-1)=2
 \end{align*}

\subsection{VEC}
What are the possible outcomes and implications for the rank of the parameter matrix of $z_{t-1}$ in the Vector Error Correction Model?\\

The $rank(\Pi)$ can be between $0$ and $m=2$. Therefore, in this case the possible outcomes for the rank
\begin{align*}
    \text{Rank}\Pi = r < 2 \; \therefore \; 1
\end{align*}
The implication of the rank defines the dimension of the cointegration space
\begin{align*}
    & r= 0 \; : \; \text{nonstationary variables, no cointegration, VAR in first differences} \\
    & r=2 \; : \; \text{stationary variables; VAR in levels}
\end{align*}

\subsection{Graphs and Impulse response: long-run cointegratng}
Do the graphs of the series and the impulse responses in Table 1 suggest
the existence of a long-run cointegrating relation between cruise visitors
and stay-over visitors (both seasonally adjusted and in logs)? \\

Yes, both the graphs and the Impulse Responses Coefficients suggest that the series are cointegrated. However, it is necessary to seasonally adjust the series. As I discussed in the previous two exercises.

\subsection{Cointegration test}

Carry out a co-integration test. What do you find? \\

In Stata I run the command \textbf{vecrank} which performs the Johansen test for cointegration. According to the test, the trace statistic at $r=0$ of 4.84 is less than its critical value of 15.41, I cannot reject the null hyphotesis that the two series in the system are part of a cointegrated equation.

%\begin{center}
\begin{table}[H] \centering
\caption{Johnasen Cointegration Test\label{johnasen}}
\begin{tabular}{llllll}
\toprule
rank & parms & LL        & eigenvalue & statistic & value \\
\midrule
0    & 6     & 482.9493  & .          & 4.8402*   & 15.41 \\
1    & 9     & 485.2964  & 0.03002    & 0.1460    & 3.76  \\
2    & 10    & 485.36942 & 0.00095    &           &      \\
\bottomrule
\end{tabular}
\end{table}
This result confirms the finding of the Granger test and the previous discussion.
%\end{center}

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

\newpage
\section{Exercise 4. State Space forms}

\begin{itemize}
    \item Write $VAR(2)$ and $MA(2)$ and $ARMA(2,2)$ processes in state-space form SSF
\end{itemize}

%I have to download the seasonally adjusted US real GDP series
%https://research.stlouisfed.org/useraccount/apikey
%https://www.stata.com/manuals/dimportfred.pdf
% First, I start by describing the a ARMA(2,2)
% \begin{align*}
%     y_t =& \mathbf{x}_t\beta + \rho_1(y_{t-1} - \mathbf{x}_{t-1}) +\rho(y_{t-2} - \mathbf{x}_{t-2} \beta) + \theta_1\epsilon_{t-1} + \theta_2\epsilon_{t-2}  +\epsilon \\
%     \rho &\; \text{first order autocorrelation parameter} \\
%     \theta & \; \text{first order moving average parameter} \\
%     \epsilon_t & \; ~ i.i.d. \; N(0,\sigma^2)
% \end{align*}

% I can now write the $VAR(2)$ in state space form as follows:

% \begin{align*}
%     \mathbf{y}_t & = \mathbf{A_1} \mathbf{Y}_{t-1} + \mathbf{A_2} \mathbf{Y}_{t-2} +\mathbf{B}_0 \mathbf{x}_t +\mathbf{u}_t \\
%   & \mathbf{y}_t  : \; K \times 1 \; \text{vector of endogenous variables} \\
%     & \mathbf{A}  : \; K \times K2 \; \text{matrix of coefficients} \\
%     & \mathbf{B}_0  : \; K \times M \; \text{matrix of coefficients} \\
%     & \mathbf{x}_t  : \; M \times 1 \; \text{vector of exogenous variables} \\
%     & \mathbf{u}_t  : \; K \times 1 \; \text{vector of white noise innovations}
% \end{align*}
\subsection{VAR(2)}
 \begin{align*}
    y_t =& \mathbf{x}_t\beta + \rho_1(y_{t-1} - \mathbf{x}_{t-1} \beta) +\rho(y_{t-2} - \mathbf{x}_{t-2} \beta) +\epsilon \\
    \rho &\; \text{first order autocorrelation parameter} \\
    \epsilon_t & \; ~ i.i.d. \; N(0,\sigma^2)
\end{align*}
I define the system equation as
\begin{align*}
    \text{System equation}: \qquad \mathbf{z}_t & = \mathbf{A} \mathbf{z}_{t-1}+ \mathbf{B} \epsilon_t \\
    \text{Observed equation}: \qquad \mathbf{y}_t & = \mathbf{C} \mathbf{z}_t \\
& \mathbf{z}_t = \begin{bmatrix}
    Y_t & Y_{t-1}  & Y_{t-2} \\
    \mathbf{x}_t & \mathbf{x}_{t-1}  & \mathbf{x}_{t-2}
\end{bmatrix}
\end{align*}

\begin{align*}
    \begin{bmatrix}
   y_t\\
     y_{t-1}
\end{bmatrix}	 =
\begin{bmatrix}
    \rho_1 & \rho_2 & \beta & \rho_1 \beta & \rho_2 \beta \\
    1 & 0 & 0 & 1 & 0
\end{bmatrix}
\begin{bmatrix}
    y_{t-1} \\
    y_{t-2} \\
    \mathbf{x}_t \\
    \mathbf{x}_{t-1} \\
    \mathbf{x}_{t-2} \\
\end{bmatrix} +
\begin{bmatrix}
    1 \\
    0 \\
    0 \\
    0 \\
    0
\end{bmatrix}
\epsilon
\end{align*}

\subsection{MA(2)}

 \begin{align*}
    y_t =& \mu_t  \\
    \mu_t =& \epsilon_t  +\theta_1\epsilon_{t-1} + \theta_2\epsilon_{t-2} \\
     \theta & \; \text{moving average parameter} \\
    \epsilon_t & \; ~ i.i.d. \; N(0,\sigma^2)
\end{align*}
The space state form can be represented as follows

\begin{align*}
    \text{System equation}: \qquad \mathbf{z}_t & = \mathbf{A} \mathbf{z}_{t-1}+ \theta \epsilon_t \\
    \text{Observed equation}: \qquad \mathbf{y}_t & = \mathbf{C} \mathbf{z}_t \\
        y_t & =
    \begin{bmatrix}
     1 & 0 & 0
\end{bmatrix}
\mathbf{z}_t +
\mu \\
\mathbf{z}_t & = \begin{bmatrix}
 0 & 1 & 1\\
 0 & 0 & 0
\end{bmatrix}
\mathbf{z}_{t-1} + \begin{bmatrix}
 1 \\
 \theta_1 \\
 \theta_2
\end{bmatrix} \epsilon_t
\end{align*}

\subsection{ARMA(2,2)}

 \begin{align*}
    y_t = & \rho_1(y_{t-1}  +\rho_2(y_{t-2} +\epsilon_t + \theta_1 \epsilon_{t-1} + \theta_1 \epsilon_{t-2} \\
    \rho &\; \text{autocorrelation parameter} \\
    \theta & \; \text{moving average parameter} \\
    \epsilon_t & \; ~ i.i.d. \; N(0,\sigma^2) \\
    \text{Let} \; m=\max(p,q+1)=3 \\
y_t = & \rho y_{t-1} + \rho_2 y_{t-2} + \rho_2 y_{t-3}+\epsilon_t + \theta_1 \epsilon_{t-1} + \theta_2 \epsilon_{t-4} \\
    \text{System equation}: \qquad \mathbf{z}_t & = \mathbf{A} \mathbf{z}_{t-1}+ \mathbf{\theta} \epsilon_t \\
    \text{Observed equation}: \qquad \mathbf{y}_t & = \mathbf{C} \mathbf{z}_t \\
& \mathbf{z}_t = \begin{bmatrix}
    Y_t  \\
    \rho_2 y_{t-1} + \theta_1 \epsilon_{t} + \theta_2 \epsilon_{t-4} \\
    \rho_3 y_{t-1} + \theta_3 \epsilon_{t}
\end{bmatrix} \\
y_t = & \begin{bmatrix}
 1 & \mathbf{0}_{m-1}
\end{bmatrix} \mathbf{z}_t \\
 & \mathbf{z}_t = \begin{bmatrix}
 \rho_1 & 1 & 0 & 0 \\
 \rho_2 & 0 & 1 & 0 \\
 \rho_3 & 0 & 0 & 0 \\
\end{bmatrix} \mathbf{z}_{t-1} +
\begin{bmatrix}
 1 \\
 \theta_1 \\
 \theta_2
\end{bmatrix} \epsilon_t
\end{align*}

\newpage
\subsection{Beveridge-Nelson}

\begin{itemize}
\item Download the seasonally adjusted US real GDP series

I use Stata 16 and its module to import data from the Federal Reserve Economic Data\footnote{Link to \href{https://www.stata.com/features/overview/import-fred/}{\textit{ St. Louis Federal Reserve}}}. To estimate the Beveridge-Nelson decomposition model I computed the components step by step in Stata and following the post in the website of Eviews (since I do not have access to this software)\footnote{\href{http://blog.eviews.com/2020/02/beveridge-nelson-filter.html}{blog.eviews.com}}. I present the code I used in the appendix.

\begin{verbatim}
fredsearch real gross national product, tags(usa)

import fred GDPC1 GDPPOT, daterange(1990-01-01 2019-12-31) clear
\end{verbatim}
    \item Estimate a Beveridge-Nelson trend-cycle decomposition model, assuming a unit root plus drift for the trend $\tau_t$, an $AR(2)$ process for the cycle $c_t$, and uncorrelated innovations $\eta_t, v_t$.
\end{itemize}

The Beveridge-Nelson decomposition determines a trend process that I called $\hat{\tau}$ and a cycle process $c_t$, such that $y_t= \tau_t+c_t$. As required, I also add a drift and assume that there is unit root (e.g I use the first difference of the log)

\begin{align*}
    y_{t} = \mu + \phi_1 y_{t-1} +\rho_2 y_{t-2} + \epsilon
\end{align*}

The first step is to fit an $AR(2)$ model, for which I assume unit root\footnote{I do not test for this}. After this I estimate and store the deterministic drift as $\hat{\mu} = \frac{\hat{\alpha}}{1-\hat{\phi}} $. Then I compute the Beveridge-Nelson cycle component \\
\begin{align*}
    \hat{\tau}_t =\Big(  y_{t} + \frac{\hat{\phi}}{1-\hat{\phi}} \Delta y_t \Big) - \Big( \frac{\hat{\phi}}{1- \hat{\phi}}\Big) \hat{\mu}
\end{align*}

Finally, I compute the Beveridge-Nelson $\hat{c}_t = y_t -  \hat{\tau}_t$

\begin{figure}[H]
    \centering
     \includegraphics[width=0.6\textwidth]{plots_1/bn_cycletrend.png}
     \caption{Beveridge-Nelson: Cycle and trend}
    \label{fig:bntrend}
\end{figure}

In addition, I contrast the result of the decomposition with the GDP gap in the graph \ref{fig:bndecomp}.

\begin{figure}[H]
    \centering
     \includegraphics[width=0.6\textwidth]{plots_1/bn_decompostion.png}
     \caption{Beveridge-Nelson Cycle and  GDP gap}
    \label{fig:bndecomp}
\end{figure}

To the sake of completeness, I compare my calculation with the estimation of the in-built routine of Stata for the Hodrick-Prescott.

\begin{figure}[H]
    \centering
     \includegraphics[width=0.6\textwidth]{plots_1/bn_hp_decom.png}
     \caption{Hodrick Prescott}
    \label{fig:bndecomps}
\end{figure}

\newpage

\section{Appendix}
\subsection{X13-ARIMA Seats}
I used the software directly downloaded from the United States Census Bureau \textit{X-13ARIMA-SEATS program (Version 1.1 Build 39) }. For each of the series I converted it first to .dat file. Then I created a spec file. These files have three purposes: (1) to establish the span of time analyzed, (2) to establish the time of adjustment e.g. Seats, and (3) to provide additional requirements e.g. compute or not the logs. The following is an example of the one of the spec files.
\begin{minted}{spec}
series{
    file = "ln_cruisevisitors.dat"
    period = 12
    format = Datevalue
}
transform{
    function = none
}
regression{
    variables = ( const td1coef )
    #aictest = ( td easter )
    #savelog = aictest
}
outlier{
    types = ( AO LS )
}
arima{
    model =  (1 0 0)(1 1 1)
}
forecast{
    maxlead = 12
    print = none
}
estimate{
    print = (roots regcmatrix acm)
    savelog = (aicc aic bic hq afc)
}
check{
    print = all
    savelog = (lbq nrm)
}
seats{ }
slidingspans{
    savelog = percent
    additivesa = percent}
history{
    estimates = (fcst aic sadj sadjchng trend trendchng)
    savelog = (asa ach atr atc)}
\end{minted}

\newpage
\subsection{Other graphs}

\begin{figure}[H]
    \centering
        \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/cruise_stay_camplet_1_b.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/cruise_stay_x13_1_b.png}
    \end{subfigure}
    \caption{Comparison two series after adjustment without the last year quarterly observations}
\end{figure}

\begin{figure}[H]
    \centering
    \begin{subfigure}[t]{0.45\textwidth}
         \includegraphics[width=\textwidth]{plots_1/x13_crui_5.png}
    \end{subfigure}
    \begin{subfigure}[t]{0.45\textwidth}
          \includegraphics[width=\textwidth]{plots_1/x13_stay_5.png}
    \end{subfigure}
    \caption{Series Tourism Aruba 2005-2018}
    \label{fig:comparison}
\end{figure}

\newpage
\subsection{Code Beveridge-Nelson Cycle}
%\begin{verbatim}
\begin{minted}{stata}
//
*Drift: errors that accumulate over time
*assuming a unit root plus drift
//
arima d_loggdp , ar(2)
	ereturn list
// Paramaters used to calculate cycle and trend
scalar alpha_hat = e(b)[1,1]
scalar phi_hat = e(b)[1,2]
scalar mu_hat = alpha_hat/(1-phi_hat)

// Trend = tau
gen tau_hat = (gdp+(phi_hat/(1- phi_hat)*d_loggdp))-(phi_hat/(1-phi_hat))*mu_hat

// Cycle
gen cycle = gdp-tau_hat

// Plots
// The cylce and the gap
tw (tsline cycle , yaxis(1) lcolor(navy)  lpattern(dash) ///
legend(label(1 "Beveridge-Nelson cycle ")) )  ///
(tsline cbogap , yaxis(2)   ytitle("Cycle", axis(2)) ///
lcolor(gray) graphregion(color(white)) ///
plotregion( color(white)) xtitle("")  xlabel(, noticks ///
format(\%tm) labsize(small) grid) legend(label(2 "GDP gap"))

// The cylce and the trend
tw (tsline cycle , yaxis(1) lcolor(navy)  lpattern(dash) ///
legend(label(1 "Beveridge-Nelson cycle ")) )  ///
(tsline tau_hat , yaxis(2)   ytitle("Trend", axis(2)) ///
lcolor(dkgreen) graphregion(color(white)) ///
plotregion( color(white)) xtitle("")  xlabel(, noticks format(\%tm) ///
labsize(small) grid) legend(label(2 "Trend"))

// Comparing wiht Hodrick-Prescott

tsfilter hp hp_vars=d_loggdp, smooth(1)

tw (tsline cycle , yaxis(1) lcolor(navy)  lpattern(dash) ///
legend(label(1 "Beveridge-Nelson cycle ")) )  ///
(tsline hp_vars , yaxis(2)   ytitle("Hodrick-Prescott ", ///
axis(2))  lcolor(stone ) graphregion(color(white)) ///
plotregion( color(white)) xtitle("")  xlabel(, noticks format(\%tm) ///
labsize(small) grid) legend(label(2 "Hodrick-Prescott"))
\end{minted}
%\end{verbatim}

\end{document}


\documentclass[a4paper,11pt]{report}
\usepackage{tikz}

\begin{document}

\section*{Question 3}
\begin{block}{}
Schedule 1 is not conflict serializable due to conflicting operations.
In order to determine conflict serializability, we can draw a graph
with edges from $\emph{T_x}$ to $\emph{T_y}$ for operations $\emph{O_i}$, $\emph{O_j}$
where at least one of $\emph{O_i}$, $\emph{O_j}$ is a $\emph{write}$
operation.
\end{block}

% \begin{tikzpicture}
%   [scale=.8,auto=left,every node/.style={circle,fill=white!20, thick}]
%   \node (n6) at (1,10) {6};
%   \node (n4) at (4,8)  {4};
%   \node (n5) at (8,9)  {5};
%   \node (n1) at (11,8) {1};
%   \node (n2) at (9,6)  {2};
%   \node (n3) at (5,5)  {3};

%   \foreach \from/\to in {n6/n4,n4/n5,n5/n1,n1/n2,n2/n5,n2/n3,n3/n4}
%     \draw (\from) -- (\to);

% \end{tikzpicture}

% $
% \begin{tabular}{ c | c | c | c }
%   T_1 & T_2 & T_3 & T_4 \\
%   \hline
%   4 & 5 & 6 & 9 \\
%   % 7 & 8 & 9 \\
% \end{tabular}
% \quad
% \begin{tabular}{ c | c | c | c }
%   T_1 & T_2 & T_3 & T_4 \\
%   \hline
%   4 & 5 & 6 & 9 \\
%   % 7 & 8 & 9 \\
% \end{tabular}
% $

% The foundations of the rigorous study of \emph{analysis}
% were laid in the nineteenth century, notably by the
% mathematicians Cauchy and Weierstrass. Central to the
% study of this subject are the formal definitions of
% \emph{limits} and \emph{continuity}.

% Let $D$ be a subset of $\bf R$ and let
% $f \colon D \to \mathbf{R}$ be a real-valued function on
% $D$. The function $f$ is said to be \emph{continuous} on
% $D$ if, for all $\epsilon > 0$ and for all $x \in D$,
% there exists some $\delta > 0$ (which may depend on $x$)
% such that if $y \in D$ satisfies
% \[ |y - x| < \delta \]
% then
% \[ |f(y) - f(x)| < \epsilon. \]

% One may readily verify that if $f$ and $g$ are continuous
% functions on $D$ then the functions $f+g$, $f-g$ and
% $f.g$ are continuous. If in addition $g$ is everywhere
% non-zero then $f/g$ is continuous.

\end{document}