\documentclass{beamer}
\DeclareFontShape{OT1}{cmss}{b}{n}{<->ssub * cmss/bx/n}{}
\usetheme{default}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathbbol}
\usepackage{xcolor} % before tikz or tkz-euclide if necessary
\usepackage{tkz-euclide} % no need to load TikZ
\usepackage{multirow}

\usepackage[
backend=biber,
style=authoryear-icomp,
sortlocale=de_DE,
natbib=true,
url=false,
doi=true,
eprint=false
]{biblatex}
\addbibresource{../../Bibliography/main_ML.bib}

\titlegraphic{\includegraphics[width=2cm]{../../Figures/UAMS_RGB.png}
}

\title{Statistical Machine Learning\\ Multilinear Regression and Variants }
\author{Horacio G\'omez-Acevedo\\ Department of Biomedical Informatics}

\begin{document}
\begin{frame}[plain]
		\maketitle
\end{frame}
\begin{frame}{(Multi)Linear Regression }
		It is very insightful to check the ordinary linear regression as a
		linear algebra problem.
		%
		If we have training data \(\{ (x_1,y_1),\ldots,(x_n,y_n)\}\), let's
		write \(X\) as a \(n\times 2\) matrix
		\begin{equation*}
		X= \begin{pmatrix}
			\mathbb{1} & \mathbb{X }
		\end{pmatrix}=
		\begin{pmatrix}
			1 & x_1\\
			1 & x_2 \\
		   	\vdots & \vdots \\
			1 & x_n
		\end{pmatrix}
		\end{equation*} The response variable vector \(Y\), the parameters
		\(\theta_0, \theta_1\) and the vector of random errors are expressed as
		%
		\begin{equation*}
		\mathbb{Y}=
		\begin{pmatrix}
			y_1\\
			y_2\\
			\vdots\\
			y_n
		\end{pmatrix},
		\theta=
		\begin{pmatrix}
			\theta_0 \\
			\theta_1
		\end{pmatrix},
		\varepsilon=
		\begin{pmatrix}
			\varepsilon_1\\
			\varepsilon_2\\
			\vdots\\
			\varepsilon_n
		\end{pmatrix}
		\end{equation*}
	\end{frame}

\begin{frame}{(Multi)Linear Regression (cont)}
	Then we can write the population regression formula in a matrix form
\begin{equation}
	\mathbb{Y}=X \cdot \theta + \varepsilon=\theta_0 \mathbb{1}+ \theta_1 \mathbb{X}+ \varepsilon
\end{equation}
The method of least squares reduces to find $(\hat{\theta}_0,\hat{\theta_1})$ that minimizes the function
	\begin{equation*}
		(\theta_0,\theta_1)\mapsto \frac{1}{n}\sum_{i=1}^n (y_i- \theta_0-\theta_1 x_i)^2
	\end{equation*}
\end{frame}

\begin{frame}{Least Squares Function}
	As we can see in the following graph, the projection of the minimum value will be the estimates of $\hat{\theta}_0$ and $\hat{\theta}_1$.
	\begin{figure}[h]
		\centering
		\includegraphics[scale=0.5]{../../Figures/fig_minfunc.png}
	\end{figure}
\end{frame}

\begin{frame}{Multidimensional Interpretation}
If we plot the vectors $\mathbb{1}$ and $\mathbb{X}$, the hyperplane (generated) by those vectors, contains a vector $\mathbb{V}$ which is closest to the vector $\mathbb{Y}$.  It can be proven that the vector $\mathbb{V}$ can be written as
\begin{equation*}
	\mathbb{V} = X (X^t X)^{-1} X^t \mathbb{Y}
\end{equation*}
On the other hand
\begin{equation*}
	\mathbb{V}= X \cdot \begin{pmatrix} \hat{\theta}_0\\ \hat{\theta}_1 \end{pmatrix}
\end{equation*}
Thus
\begin{equation}
	\begin{pmatrix}
		\hat{\theta}_0\\ \hat{\theta}_1
\end{pmatrix} = (X^t X)^{-1} X^t \mathbb{Y}
\label{eq:normeq}
\end{equation}
This last equation is called the {\bf normal form}
\end{frame}

\begin{frame}{Multidimensional Interpretation}

	\begin{figure}[h]
		\centering
		\includegraphics[scale=0.5]{../../Figures/fig_projection.png}
	\end{figure}
\end{frame}

\begin{frame}{Computational Complexity}
	The solution of the linear regression problem using the normal equation (\ref{eq:normeq}), requires significant amount of computation resources as $n$ tend to increase.

	Let $f,g \colon \mathbb{N} \to \mathbb{R}^+$ two non-negative functions. We say that $f(n)= O(g(n))$ (big O) if there are two non-negative integers $n_0$ and $c$ such that for every $n\ge n_0$
	\begin{equation*}
		f(n) \le c \cdot  g(n)
	\end{equation*}
  {\bf Example.} Let $f(n)=5n^3+3n^2+1000n +10000$. In this case $f(n)=O(n^3)$ since when $n$ is very large, $f(n)$ behaves like the polynomial $5n^3$.

  The complexity of matrix inversion is between $O(n^{2.4})$ and $O(n^3)$, depending on the algorithm.
\end{frame}

\begin{frame}{Gradient Descent Revisited}

	In a previous lecture, we have defined the general gradient descent rational as reaching the (hopefully global) minimum iteratively using a formula like
	\begin{equation*}
		\theta^{k+1}= \theta^k - \eta(k) \nabla J(\theta^k)
	\end{equation*}
	In the context of linear regression, $J(\mathbf{x})= MSE(\mathbf{x})$. Since the $MSE$ is a convex function, a global minimum can be reached! Thus after a certain number of steps $m$ we say that $\theta^m$ is (close enough) to the linear regression problem
	\begin{equation*}
	 {X}  \cdot \theta ^m \approx \mathbb{Y}
	\end{equation*}

{\bf Note.} In G\'eron's book the notation is just a bit different (by using the transpose), but the concepts are totally equivalent.
\begin{equation*}
	MSE(\theta)=  \frac{1}{m} \sum_{i=1}^m (\theta^T \cdot \mathbf{x}^{(i)} - y^{(i)})^2
\end{equation*}
\end{frame}
\begin{frame}{Stochastic Gradient Descent}
	For the {\bf cost function} MSE, the gradient is calculated as
	\begin{equation*}
		\nabla_\theta MSE (\theta)= \frac{2}{m} X^t (X \cdot \theta)-\mathbb{Y}
	\end{equation*}
Thus, at each step of the gradient descent, we need to recalculate the gradient using the whole dataset. This operation is expensive as matrix multiplication continue to pile up. One solution is to use the calculations of the gradient taking instances in the training set at every step and computing  gradients based only on that instance.

\end{frame}

\begin{frame}{Regularized Linear Models (Shrinkage)}
Traditionally these methods involves using least squares to fit a linear model that contains a subset of the predictors (ergo the name shrinkage).  These techniques {\it constrains} or {\it regularizes} the coefficient estimates towards zero.

\begin{equation*}
	RSS= \sum_{i=1}^n \left( y_i - \theta_0 - \sum_{j=1}^p \theta_j x_{ij} \right)^2
\end{equation*}

In {\bf ridge regression}, the coefficients are estimated by minimizing a slightly different quantity. The ridge regression coefficient estimates $\hat{\theta}^R$ that minimize
\begin{equation*}
\sum_{i=1}^n \left( y_i - \theta_0 - \sum_{j=1}^p \theta_j x_{ij} \right)^2 + \lambda \sum_{j=1}^p \theta_j^2,
\end{equation*}
where $\lambda \ge 0$ is a tuning parameter (hyperparameter) to be determined separately.

\end{frame}

\begin{frame}{Ridge Regression (cont)}

	The shrinkage penalty is applies to $\theta_1,\ldots, \theta_p$ but not to intercept $\theta_0$.  Since this is the measure of the mean value of the response when $x_{i1}=x_{i2}=\cdots=x_{ip}=0$.

	One of the main reasons to use ridge regression is in the bias-variance trade-off. As $\lambda $ increases, the flexibility of the ridge regression fit decreases leading to decreased variance but increased bias.

	One disadvantage of ridge regression is that it will include all $p$ predictors in the final model. The penalty term $\lambda \sum_{i=1}^p \theta_j$ will shrink all the coefficients towards zero, but it will not set any of them exactly to zero.
\end{frame}

\begin{frame}{Lasso}
	The {\bf Lasso} alternative calculates the coefficients $\hat{\theta}_\lambda^L$ by minimizing a slightly different formula
\begin{equation*}
	\sum_{i=1}^n \left( y_i - \theta_0 - \sum_{j=1}^p \theta_j x_{ij} \right)^2 + \lambda \sum_{j=1}^p |\theta_j|,
\end{equation*}
	The advantage of lasso is that it forces some of the coefficient estimates to be exactly equal to zero when the tuning parameter $\lambda$ is sufficiently large. Thus, we say that lasso yields {\it sparse} models.
\end{frame}

\begin{frame}{Optimization perspective}
	Ridge regression can be seen as the minimization of the following problem
	\begin{equation*}
		\min_{\theta} \left\{ \sum_{i=1}^n \left( y_i - \theta_0 - \sum_{j=1}^p \theta_j x_{ij} \right)^2 \right\} \quad\textrm{subject to }   \sum_{j=1}^p \theta_j^2 \le s
	\end{equation*}
whereas the lasso becomes
\begin{equation*}
	\min_{\theta} \left\{ \sum_{i=1}^n \left( y_i - \theta_0 - \sum_{j=1}^p \theta_j x_{ij} \right)^2 \right\} \quad\textrm{subject to }   \sum_{j=1}^p |\theta_j | \le s
\end{equation*}

\end{frame}

\begin{frame}{Optimization picture}
	The ellipses that are centered around $\hat{\theta}$ represent regions of constant RSS. The intersections between the lasso and ridge regression coefficient estimates with the ellipses. Notice that for the lasso the point of contact has $\theta_1=0$, whereas for the ridge regression the value of $\theta_1$ is "small" but does not vanish.
		\begin{figure}[h]
		\centering
		\includegraphics[scale=0.5]{../../Figures/fig_lasso_ridge.png}
	\end{figure}

\end{frame}

\begin{frame}{Problem with Lasso}
For Lasso Regression the cost function is defined as
\begin{equation*}
	J(\theta)=MSE(\theta)+\alpha\sum_{i=1}^n |\theta_i|
\end{equation*}
However, the absolute function is not differentiable at zero! So, we use the right or left hand derivatives. More precisely,

\begin{equation*}
	g(\theta,J)= \nabla_\theta MSE (\theta)+ \lambda
	\begin{pmatrix}
		\textrm{sign}(\theta_1)\\
		\vdots\\
		\textrm{sign}(\theta_n)
	\end{pmatrix}
\end{equation*}
where
\begin{equation*}
	\textrm{sign}(x)= \begin{cases}
		1 & \textrm{if } x>0\\
		0 & \textrm{if } x=0\\
		-1 & \textrm{if  }x<0
	\end{cases}
\end{equation*}
\end{frame}

\begin{frame}{Elastic Network}
This model is a (convex) combination between Ridge Regression and Lasso Regression. For $r \in [0,1]$ and $s \ge 0$ the optimization goal is

\begin{equation*}
	\begin{split}
\min_{\theta} \left\{ \sum_{i=1}^n \left( y_i - \theta_0 - \sum_{j=1}^p \theta_j x_{ij} \right)^2 \right\}  \\
\quad\textrm{subject to }   (1-r)\sum_{j=1}^p |\theta_j | + r \sum_{j=1}^p \theta_j^2 \le s
	\end{split}
\end{equation*}

\end{frame}

\begin{frame}{What have we learned?}
	\begin{itemize}
		\item Multi-linear regression as an optimization problem.
		\item The gradient descent is a good strategy for finding a solution for multi-linear regression.
		\item Expansion of the multi-linear regression models using hyperparameters.
		\item LASSO and Ridge regression use shrinking methods to reduce some coefficients to zero.
	\end{itemize}
\end{frame}

\begin{frame}{References}
Materials and some of the pictures are from \citep{James2015}, \citep{duda}, \citep{geron2}, and \citep{pestman}.
\printbibliography

I have used some of the graphs by hacking TiKz code from StakExchange, Inkscape for more aesthetic plots and other old tricks of \TeX
\end{frame}
\end{document}

%\subsection{Matrix Form of OLR}\label{matrix-form-of-olr}}
%
%{\it Algebra is generous; she often gives more than is asked of her.}\\
%{\bf Jean le Rond d'Alembert}
%
%
%It is very insightful to check the ordinary linear regression as a
%linear algebra problem.
%
%If we have training data \(\{ (x_1,y_1),\ldots,(x_n,y_n)\}\), let's
%write \(X\) as a \(n\times 2\) matrix \begin{equation}
%X=
%\begin{pmatrix}
%	1 & x_1\\
%	1 & x_2 \\
%	\vdots & \vdots \\
%	1 & x_n
%\end{pmatrix}
%\end{equation} The response variable vector \(Y\), the parameters
%\(\theta_0, \theta_1\) and the vector of random errors are expressed as
%
%\begin{equation}
%Y=
%\begin{pmatrix}
%	y_1\\
%	y_2\\
%	\vdots\\
%	y_n
%\end{pmatrix},
%\theta=
%\begin{pmatrix}
%	\theta_0 \\
%	\theta_1
%\end{pmatrix},
%\varepsilon=
%\begin{pmatrix}
%	\varepsilon_1\\
%	\varepsilon_2\\
%	\vdots\\
%	\varepsilon_n
%\end{pmatrix}
%\end{equation} Then we can write the population regression formula in a matrix form
%\begin{equation}
%Y=X \cdot \theta + \varepsilon
%\end{equation}
%
%During least squared method it is shown that the so-called
%\textbf{normal equations} are satisfied by the estimates of
%\(\hat{\theta}\)
%
%\begin{equation}
%\begin{split}
%	n \hat{\theta}_0 + \hat{\theta}_1 \sum x_i &= \sum y_i\\
%	\hat{\theta}_0 \sum x_i + \hat{\theta}_1 \sum x_i^2  &= \sum x_iy_i
%\end{split}
%\Rightarrow X^t \cdot X \cdot \hat{\theta}= X^t \cdot Y
%\label{eq:hat1}
%\end{equation} where \begin{equation}
%X^t\cdot X =
%\begin{pmatrix}
%	n & \sum x_i\\
%	\sum x_i & \sum x_i^2
%\end{pmatrix}
%\end{equation}
%
%It can be shown that \begin{equation*}
%\det (X^t\cdot X) = n \sum (x_i - \overline{x})^2 >0
%\end{equation*} (except in the trivial case where all the \(x_i\)'s
%are the same). Thus, the matrix is invertible. Then, from equation
%(\ref{eq:hat1}) we have
%
%\begin{equation}
%\hat{\theta}=
%\begin{pmatrix}
%	\hat{\theta}_0 \\
%	\hat{\theta}_1 \\
%\end{pmatrix} = (X^t \cdot X)^{-1} X^t \cdot Y
%\end{equation}
%
%From here, we use the following simple observation \begin{equation}
%\hat{Y}= X \cdot \hat{\theta}\Rightarrow \hat{Y}= X\cdot(X^t \cdot X)^{-1} \cdot X^t \cdot Y
%= H \cdot Y
%\end{equation} where the matrix \(H\) is called the \textbf{hat matrix}.
%
%The hat matrix is idempotent i.e. \(H^2=H\).
%
%As for the vector of residuals, \begin{equation}
%\mathbf{e}= Y-\hat{Y} = Y- X \cdot \hat{\theta}= Y-HY= (I_n-H)Y
%\end{equation}
%
%In the setup for linear regression, the variance-covariance matrix of
%the residuals
%
%\begin{equation}
%\sigma^2(\mathbf{e}) = \sigma^2 (I_n -H)
%\end{equation}
%
%Note that \(X \cdot \hat{\theta}\) is the vector of the expected values
%of the \(y_i\) observations. Thus we can write \begin{equation}
%E(Y)=X \cdot \hat{\theta}
%\end{equation} From the computational point of view, instead of solving
%constantly an optimization problem, we can quickly calculate parts of
%the hat matrix.\\
%\begin{equation*}
%(X^t \cdot X)^{-1} =
%\begin{pmatrix}
%	\frac{1}{n} + \frac{ \overline{x}^2}{\sum (x_i-\overline{x})^2} &
%	\frac{-\overline{x}}{\sum (x_i-\overline{x})^2} \\
%	\frac{-\overline{x}}{\sum (x_i-\overline{x})^2} &
%	\frac{1}{\sum (x_i-\overline{x})^2}
%\end{pmatrix}
%\end{equation*}
%
%A good reference for statistics is the extensive book of Kutner et. al.
%\emph{Applied Linear Statistical Models} with its close to 1400 pages
%but unfortunately no R code (as far as I know).


\chapter{Calculation of Incident Fields and GSM Entries}
\label{chap:incgsm}

\section{Introduction}

In Chapter~\ref{chap:gfstratified} a method was presented to efficiently evaluate the
potential Green's functions for a multiply stratified medium under
quasi-periodic boundary conditions.  In order to make use of the
Green's functions in a periodic moment method procedure, it is also
necessary to compute the incident fields and pick off the scattering
matrix entries for the multiply stratified medium.  This chapter provides
the framework for these tasks.

We will assume that the single FSS sheet is located at interface
number $s$, located between layers $s$ and $s+1$, where $1 \leq s < N.$

\section{Electric Current Unknowns}
\subsection{Calculation of Incident Fields}
In this case the incident field is the field that would exist in the
 structure in the absence of the unknown electric currents (and the
 metalization which they represent). That is, the incident field is
 the field present in the pure radome case, with primary excitation
 from an incoming normalized Floquet mode with unit excitation
 coefficient.

 There are two cases to consider.  In the first case, the primary excitation
 is a Region~$1$ Floquet mode propagating in the $+z$ direction.
 In the second case, the exciting wave is a Region~$N$ Floquet mode
 propagating in the  $-z$ direction.

\subsubsection{Region~1 Incidence}
The primary excitation is a plane wave incident from Region~1 with
transverse electric field given by
\begin{equation}
  \e_q \one(x,y) e^{-\gamma\one (z-z_1)}
\end{equation}
where $q$ is the
modal triple index $q = (p_q,m_q,n_q).$
The transmission line equivalent circuit for determining the incident
field present at any desired junction plane is shown in Figure~\ref{fig:equiv1}.
\begin{figure}[tbp]
  \begin{center}
    \footnotesize
    \psset{unit=0.95cm}
    \pspicture(-1.5,-1.9)(12,1.6)
    \psset{nodesep=0pt}
    \vsource{-1.5} \rput[l](-2,0.35){$V_g$}
    \seriesload{-1.5}{-0.75}{0}{$Z_{q}^{(1)}$}
    \zlabel{0}{$z_1$}
    \tlsection{0}{1.8}{2}
    \zlabel{1.8}{$z_2$}
    \tlsection{1.8}{3.5}{3}
    \tlsection{4.3}{6.4}{\ensuremath{s}}
    \zlabel{6.4}{$z_s$}
    \tlsection{6.4}{8.7}{\ensuremath{s+1}}
    \tlsection{9.5}{11.6}{\ensuremath{N-1}}
    \shuntload{11.6}{$Z_{q}^{(N)}$}
    \zlabel{11.6}{$z_{N-1}$}
    \rput*(3.9,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(3.9,-0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,-0.8){\huge$\boldsymbol{\cdots}$}
    \endpspicture
    \caption{Equivalent transmission line circuit used to find
    incident electric field for a plane wave incident from Region~1.}
    \label{fig:equiv1}
  \end{center}
\end{figure}
We choose the generator voltage $V_g = 2$ to supply a unit incoming voltage
wave. The total incident (both incoming and reflected) electric field at
$z=z_1$ is then
\begin{equation}
  \Idemfactor_z \bdot \E\inc(x,y,z_1) = V(z_1) \e_q\one(x,y)
  = \frac{V_g}{2}(1 + S^{11}_{qq}) \e_q\one(x,y)
\end{equation}
where $S^{11}_{qq}$ is the
partial GSM entry due to the incident fields.
We can find $V(z_1)$ using the transmission line equivalent circuit.
The voltage and current at the junction plane $z=z_1$ are
\begin{equation}
  V(z_1) = \frac{V_g\Zright(z_1)}{\Zright(z_1) + Z_q\one}, \quad
  I(z_1) = \frac{V_g}{\Zright(z_1) + Z_q\one}
\end{equation}
where $\Zright(z_i)$ is the impedance seen looking to the right at
$z=z_i$.  The right-looking impedances seen at the junction planes
are easily determined using the following recursive
formulas derived from elementary transmission line theory:
\begin{subequations}
  \begin{align}
    &\Zright(z_{N-1}) = Z_{q}^{(N)} \\
    &\Zright(z_i) = Z_{q}^{(i+1)}
    \frac%
    {\Zright(z_{i+1}) + Z_{q}^{(i+1)}\tanh(\gamma_{q}^{(i+1)} h^{(i+1)})}%
    {Z_{q}^{(i+1)} + \Zright(z_{i+1})\tanh(\gamma_{q}^{(i+1)} h^{(i+1)})}, \notag \\
    & \mkern300mu i = N-2,N-3,\ldots,1.
  \end{align}
\end{subequations}
A similar recursive procedure can be used to calculate the
equivalent circuit voltages and currents
at each of the remaining junction planes:
\begin{multline}
  V(z_i) = V(z_{i-1}) \cosh(\gamma_{q}\eye h\eye)
  - Z_q\eye
  I(z_{i-1}) \sinh (\gamma_{q}\eye h\eye), \quad
  I(z_i) = \frac{V(z_i)}{\Zright(z_i)} \\
  i = 2,3,\ldots,N-1.
  \label{eq:recurseright}
\end{multline}

The total incident (both incoming and reflected) electric field at
$z=z_s$ is then
\begin{equation}
  \Idemfactor_z \bdot \E\inc(x,y,z_s) = V(z_s) \e_q\one(x,y)
  = V(z_s) \frac{c_q\one}{c_q\ess} \e_q\ess(x,y),
\end{equation}
where we used the fact that $\e_q\one / c_q\one = \e_q\ess / c_q\ess.$

The partial transmission scattering parameter (due to the incident
field) $S^{21}_{qq}$ is obtained from the equivalent circuit voltage
at $z=z_{N-1}$:
\begin{equation}
  \Idemfactor \bdot \E\inc(x,y,z_{N-1}) = V(z_{N-1}) \e_q\one(x,y)
  = S^{21}_{qq} \e_q\enn(x,y).
\end{equation}
Since $\e_q\one / c_q\one = \e_q\enn / c_q\enn$ we find that
\begin{equation}
  S^{21}_{qq} = V(z_{N-1}) \frac{c_q\one}{c_q\enn}.
\end{equation}

\subsubsection[Region N Incidence]{Region~$N$ Incidence}
The primary excitation is a plane wave incident from Region~$N$ with
transverse electric field given by
\begin{equation}
  \e_q \enn(x,y) e^{\gamma\one (z-z_{N-1})}
\end{equation}
where $q$ is the
modal triple index $q = (p_q,m_q,n_q).$
The transmission line equivalent circuit for determining the incident
field present at any desired junction plane is shown in Figure~\ref{fig:equiv2}.
\begin{figure}[tbp]
  \begin{center}
    \footnotesize
    \psset{unit=0.95cm}
    \pspicture(0.3,-1.9)(13,1.6)
    \psset{nodesep=0pt}
    \shuntload{0}{$Z_{q}\one$}
    \zlabel{0}{$z_1$}
    \tlsection{0}{1.8}{2}
    \zlabel{1.8}{$z_2$}
    \tlsection{1.8}{3.5}{3}
    \tlsection{4.3}{6.4}{\ensuremath{s}}
    \zlabel{6.4}{$z_s$}
    \tlsection{6.4}{8.7}{\ensuremath{s+1}}
    \tlsection{9.5}{11.6}{\ensuremath{N-1}}
    \vsource{13} \rput[l](13.03,0.35){$V_g$}
    \seriesload{11.6}{12.35}{13}{$Z_{q}\enn$}
    \zlabel{11.6}{$z_{N-1}$}
    \rput*(3.9,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(3.9,-0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,-0.8){\huge$\boldsymbol{\cdots}$}
    \endpspicture
    \caption{Equivalent transmission line circuit used to find
    incident electric field for a plane wave incident from Region~$N$.}
    \label{fig:equiv2}
  \end{center}
\end{figure}
We choose the generator voltage $V_g = 2$
to supply a unit incoming voltage wave.
The total incident (both incoming and reflected) electric field at
$z=z_{N-1}$ is
\begin{equation}
  \Idemfactor_z \bdot \E\inc(x,y,z_{N-1}) = V(z_{N-1}) \e_q\enn(x,y)
  = (1 + S^{22}_{qq}) \e_q\enn(x,y)
\end{equation}
where $S^{22}_{qq}$ is the
partial GSM entry due to the incident fields.
We can find $V(z_{N-1})$ using the transmission line equivalent circuit.
The voltage and current at the junction plane $z=z_{N-1}$ are
\begin{equation}
  V(z_{N-1}) =  \frac{V_g\Zleft(z_{N-1})}{\Zleft(z_{N-1}) + Z_q\enn}, \quad
  I(z_{N-1}) = \frac{-V_g}{\Zleft(z_{N-1}) + Z_q\enn}
\end{equation}
where $\Zleft(z_i)$ is the impedance seen looking to the left at
$z=z_i$.  The left-looking impedances seen at the junction planes
are easily determined using the following recursive
formulas derived from elementary transmission line theory:
\begin{subequations}
  \begin{align}
    &\Zleft(z_1) = Z_{q}\one \\
    &\Zleft(z_i) = Z_{q}\eye
    \frac%
    {\Zleft(z_{i-1}) + Z_{q}\eye \tanh(\gamma_{q}\eye h\eye)}%
    {Z_{q}\eye + \Zleft(z_{i-1})\tanh(\gamma_{q}\eye h\eye)}, \notag \\
    & \mkern300mu i = 2,3,\ldots,N-1.
  \end{align}
\end{subequations}
A similar recursive procedure can be used to calculate the
equivalent circuit voltages and currents at each of the remaining
junction planes:
\begin{multline}
  \left\{
    \begin{array}{@{}l@{}}
      \displaystyle
      V(z_i) = V(z_{i+1}) \cosh (\gamma_{q}\epw h\epw)
      + Z_q\epw
      I(z_{i+1}) \sinh ( \gamma_{q}\epw h\epw ), \\
      \displaystyle
      I(z_i) = -V(z_i)/\Zleft(z_i)
    \end{array}
  \right.
  \\
  i = N-2,N-3\ldots,1.
  \label{eq:recurseleft}
\end{multline}

The total incident (both incoming and reflected) electric field at
$z=z_s$ is then
\begin{equation}
  \Idemfactor_z \bdot \E\inc(x,y,z_s) = V(z_s) \e_q\enn(x,y)
  = V(z_s) \frac{c_q\enn}{c_q\spw} \e_q\spw(x,y),
\end{equation}
where we used the fact that $\e_q\enn / c_q\enn = \e_q\spw / c_q\spw.$

The partial transmission scattering parameter (due to the incident
field) $S^{12}_{qq}$ is obtained from the equivalent circuit voltage
at $z=z_1$:
\begin{equation}
  \Idemfactor \bdot \E\inc(x,y,z_{1}) = V(z_{1}) \e_q\enn(x,y)
  = S^{12}_{qq} \e_q\one(x,y).
\end{equation}
Since $\e_q\enn / c_q\enn = \e_q\one / c_q\one$ we find that
\begin{equation}
  S^{12}_{qq} = V(z_{1}) \frac{c_q\enn}{c_q\one}.
\end{equation}

\subsection{Calculation of (scattered) GSM entries}
We now assume that the electric surface currents $\Js$
on the FSS sheet located at $z=z_s$ have been obtained using the
method of moments.  We seek expressions for the outgoing  wave
coefficients $\{b_q\one\}$
and $\{b_q\enn\}$ in the scattered field expansions
\begin{equation}
  \E\scat(x,y,z) =
  \begin{cases}
    \displaystyle
    \sum_{q} b_q\one \e_q\one(x,y) e^{j\gamma_q\one (z-z_1)} & (z<z_1) \\[0.5ex]
    \displaystyle
    \sum_{q} b_q\enn \e_q\enn(x,y) e^{-j\gamma_q\enn (z-z_{N-1})} & (z>z_{N-1}).
  \end{cases}
\end{equation}
These coefficients are the partial GSM entries due to the scattered
(radiated by the induced surface currents) fields.
Using the results of \cite{mimo:97} we find that they are given by
\begin{subequations}
  \label{eq:belectric}
\begin{align}
  b_q\one &=
  -\t_q \bdot \ftJs(\vecbeta_{m_q,n_q})
  \frac%
  {V_i^{p_q}(\vecbeta_{m_q,n_q},z_1,z_s)}%
  {A c_q\one}
%   =  -\t_q \bdot \ftJs(\vecbeta_{m_q,n_q})
%   \frac%
%   {c_q\one Y_q\one V_i^{p_q}(\vecbeta_{m_q,n_q},z_1,z_s) }%
%   {P_0}
  \\
  b_q\enn &=
  -\t_q \bdot \ftJs(\vecbeta_{m_q,n_q})
  \frac%
  {V_i^{p_q}(\vecbeta_{m_q,n_q},z_{N-1},z_s)}%
  {A c_q\enn}
\end{align}
\end{subequations}
where $\t_q$ is the modal polarization vector defined in \eqref{eq:tdef}, and $V_i^p$ is the
transmission line Green's function for the
voltage due to a unit current source for either the TE ($p=1$) or TM
($p=2$) equivalent circuit, shown in Figure~\ref{fig:equiv3}.
\begin{figure}[tbp]
  \begin{center}
    \footnotesize
    \pspicture(-0.3,-1.9)(12,1.6)
    \psset{nodesep=0pt}
    \shuntload{0}{$Z_{q}^{(1)}$}
    \zlabel{0}{$z_1$}
    \tlsection{0}{1.8}{2}
    \zlabel{1.8}{$z_2$}
    \tlsection{1.8}{3.5}{3}
    \tlsection{4.3}{6.4}{\ensuremath{s}}
    \zlabel{6.4}{$z_s$}
    \isource{6.4} \rput[l](6.45,0.35){$1\,\text{A}$}
    \tlsection{6.4}{8.7}{\ensuremath{s+1}}
    \tlsection{9.5}{11.6}{\ensuremath{N-1}}
    \shuntload{11.6}{$Z_{q}^{(N)}$}
    \zlabel{11.6}{$z_{N-1}$}
    \rput*(3.9,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(3.9,-0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,-0.8){\huge$\boldsymbol{\cdots}$}
    \endpspicture
    \caption{Equivalent transmission line circuit used to find
    scattered fields.
    We set $p=1$ when evaluating $\Vi\TE$ and $p=2$ for
    $\Vi\TM$. Superscripted quantities in parentheses are region
    designators. }
    \label{fig:equiv3}
  \end{center}
\end{figure}
Since we have a unit current source at $z=z_s$ the
voltage there is equal to the total impedance at that point:
\begin{subequations}
\begin{align}
  \Vi^p(\vecbeta_{m_q,n_q},z_s,z_s) &=
  Z^{\text{tot}}(z_s) =
  \frac{1}{\frac{1}{\Zleft(z_s)} + \frac{1}{\Zright(z_s)}}
  =
  \frac{\Zleft(z_s) \, \Zright(z_s)}{\Zleft(z_s) + \Zright(z_s)}, \\
  \Ii^p(\vecbeta_{m_q,n_q},z_s^+,z_s) &=
  \frac{\Vi^p(\vecbeta_{m_q,n_q},z_s,z_s)}{\Zright(z_s)}, \\
  \Ii^p(\vecbeta_{m_q,n_q},z_s^-,z_s) &=
  \frac{-\Vi^p(\vecbeta_{m_q,n_q},z_s,z_s)}{\Zleft(z_s)}.
\end{align}
\end{subequations}
With the voltage and current known at $z_s$, one can apply
\eqref{eq:recurseleft} for $i=s-1, s-2, \ldots, 1$ and
\eqref{eq:recurseright} for $i=s+1, s+2, \ldots, N-1$ to determine
Green's function voltages needed to evaluate Equations~\eqref{eq:belectric}.

\section{Magnetic Current Unknowns}
\subsection{Calculation of Incident Fields}
In this case the incident field is the field that would exist in the
 structure in the absence of the unknown magnetic currents, but in the
 presence of the unperforated ground plane at $z=z_s.$
 That is, the incident field is the sum of the incoming and reflected
 (due to the ground plane) waves, with primary excitation
 from an incoming normalized Floquet mode with unit excitation
 coefficient.

 There are two cases to consider.  In the first case, the primary excitation
 is a Region~$1$ Floquet mode propagating in the $+z$ direction.
 In the second case, the exciting wave is a Region~$N$ Floquet mode
 propagating in the  $-z$ direction.

\subsubsection{Region~1 Incidence}
The primary excitation is a plane wave incident from Region~1 with
transverse magnetic field given by
\begin{equation}
  \h_q \one(x,y) e^{-\gamma\one (z-z_1)}
\end{equation}
where $q$ is the
modal triple index $q = (p_q,m_q,n_q).$
The transmission line equivalent circuit for determining the incident
magnetic field present at any desired junction plane is shown in
Figure~\ref{fig:mequiv1}.
\begin{figure}[tbp]
  \begin{center}
    \footnotesize
    \psset{unit=0.95cm}
    \pspicture(-1.5,-1.9)(9,1.6)
    \psset{nodesep=0pt}
    \isource{-1.5} \rput[l](-2,0.35){$I_g$}
    \shuntload{-0.75}{$Y_{q}^{(1)}$}
    \psline(-1.5,0.8)(0,0.8) \psline(-1.5,-0.8)(0,-0.8)
    \zlabel{0}{$z_1$}
    \tlsection{0}{1.8}{2}
    \zlabel{1.8}{$z_2$}
    \tlsection{1.8}{3.5}{3}
    \tlsection{4.3}{6.4}{\ensuremath{s-1}}
    \zlabel{6.4}{$z_{s-1}$}
    \tlsection{6.4}{8.7}{\ensuremath{s}}
    \zlabel{8.7}{$z_{s}$}
    \psline(8.7,-0.8)(8.7,0.8) % Short Circuit
    \rput*(3.9,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(3.9,-0.8){\huge$\boldsymbol{\cdots}$}
    \endpspicture
    \caption{Equivalent transmission line circuit used to find
    incident magnetic field at $z=z_s$ for a plane wave incident from
    Region~1.}
    \label{fig:mequiv1}
  \end{center}
\end{figure}
We choose the generator current $I_g = 2$ to supply a unit incoming current
wave. The total incident (both incoming and reflected) magnetic field at
$z=z_1$ is then
\begin{equation}
  \Idemfactor_z \bdot \H\inc(x,y,z_1) = I(z_1) \h_q\one(x,y)
  = \frac{I_g}{2}(1 - S^{11}_{qq}) \h_q\one(x,y)
\end{equation}
where $S^{11}_{qq}$ is the
partial GSM entry due to the incident fields.
We can find $I(z_1)$ using the transmission line equivalent circuit.
The current and voltage at the junction plane $z=z_1$ are
\begin{equation}
  I(z_1) = \frac{I_g}{1 + \Zright(z_1)  Y_q\one}, \quad
  V(z_1) = \frac{I_g \Zright(z_1)}{1 + \Zright(z_1)  Y_q\one}, \quad
\end{equation}
where $\Zright(z_i)$ is the impedance seen looking to the right at
$z=z_i$.  The right-looking impedances seen at the junction planes
are easily determined using the following recursive
formulas derived from elementary transmission line theory:
\begin{subequations}
  \begin{align}
    &\Zright(z_{s-1}) = Z_{q}^{(s)} \tanh(\gamma_{q}^{(s)} h^{(s)}) \\
    &\Zright(z_i) = Z_{q}^{(i+1)}
    \frac%
    {\Zright(z_{i+1}) + Z_{q}^{(i+1)}\tanh(\gamma_{q}^{(i+1)} h^{(i+1)})}%
    {Z_{q}^{(i+1)} + \Zright(z_{i+1})\tanh(\gamma_{q}^{(i+1)}
      h^{(i+1)})},
    \notag \\
    & \mkern300mu i = s-2,s-3,\ldots,1.
  \end{align}
\end{subequations}
A similar recursive procedure can be used to calculate the
equivalent circuit currents and voltages
at each of the remaining junction planes:
\begin{multline}
  I(z_i) = I(z_{i-1}) \cosh(\gamma_{q}\eye h\eye)
  - Y_q\eye
  V(z_{i-1}) \sinh (\gamma_{q}\eye h\eye), \quad
  V(z_i) = I(z_i)  \Zright(z_i) \\
  i = 2,3,\ldots,s.
  \label{eq:Mrecurseright}
\end{multline}

The total incident (both incoming and reflected) magnetic field at
$z=z_s$ is then
\begin{equation}
  \Idemfactor_z \bdot \H\inc(x,y,z_s) = I(z_s) \h_q\one(x,y)
  = I(z_s) \frac{c_q\ess}{c_q\one} \h_q\ess(x,y),
\end{equation}
where we used the fact that $ c_q\one \h_q\one  = c_q\ess \h_q\ess.$

The partial reflection scattering parameter (due to the incident
field) $S^{11}_{qq}$ is obtained from the equivalent circuit current
at $z=z_{1}$:
\begin{equation}
  \Idemfactor \bdot \H\inc(x,y,z_{1}) = I(z_{1}) \h_q\one(x,y)
  = (1-S^{11}_{qq}) \h_q\one(x,y),
\end{equation}
so that
\begin{equation}
  S^{11}_{qq} = 1-I(z_{1}).
\end{equation}

\subsubsection[Region N Incidence]{Region~$N$ Incidence}
The primary excitation is a plane wave incident from Region~$N$ with
transverse magnetic field given by
\begin{equation}
  -\h_q \enn(x,y) e^{\gamma\one (z-z_{N-1})}
\end{equation}
where $q$ is the
modal triple index $q = (p_q,m_q,n_q).$
The transmission line equivalent circuit for determining the incident
field present at any desired junction plane is shown in
Figure~\ref{fig:mequiv2}.
\begin{figure}[tbp]
  \begin{center}
    \footnotesize
    \psset{unit=0.95cm}
    \pspicture(1.8,-1.9)(13,1.6)
    \psset{nodesep=0pt}
    \psline(1.8,-0.8)(1.8,0.8)
    \zlabel{1.8}{$z_s$}
    \tlsection{1.8}{3.8}{\ensuremath{s+1}}
    \tlsection{3.8}{6.0}{\ensuremath{s+2}}
    \zlabel{3.8}{$z_{s+1}$}
    \tlsection{6.8}{9.4}{\ensuremath{N-2}}
    \zlabel{9.4}{$z_{N-2}$}
    \tlsection{9.4}{11.6}{\ensuremath{N-1}}
    \shuntload{12.1}{$Y_{q}\enn$}
    \isource{13} \rput[l](13.0,0.35){$\,I_g$}
    \psline(11.6,-0.8)(13.0,-0.8) \psline(11.6,0.8)(13.0,0.8)
    \zlabel{11.6}{$z_{N-1}$}
    \rput*(6.4,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(6.4,-0.8){\huge$\boldsymbol{\cdots}$}
    \endpspicture
    \caption{Equivalent transmission line circuit used to find
    incident electric field for a plane wave incident from Region~$N$.}
    \label{fig:mequiv2}
  \end{center}
\end{figure}
We choose the generator current $I_g = 2$
to supply a unit incoming current wave.
The total incident (both incoming and reflected) magnetic field at
$z=z_{N-1}$ is
\begin{equation}
  \Idemfactor_z \bdot \H\inc(x,y,z_{N-1}) = I(z_{N-1}) \h_q\enn(x,y)
  = ( S^{22}_{qq}-1) \h_q\enn(x,y)
\end{equation}
where $S^{22}_{qq}$ is the
partial GSM entry due to the incident fields.
We can find $V(z_{N-1})$ using the transmission line equivalent circuit.
The current and voltage at the junction plane $z=z_{N-1}$ are
\begin{equation}
  I(z_{N-1}) =  \frac{-I_g}{1+\Zleft(z_{N-1})  Y_q\enn}, \quad
  V(z_{N-1}) =  \frac{-I_g \Zleft(z_{N-1})}{1+\Zleft(z_{N-1})  Y_q\enn}
\end{equation}
where $\Zleft(z_i)$ is the impedance seen looking to the left at
$z=z_i$.  The left-looking impedances seen at the junction planes
are easily determined using the following recursive
formulas derived from elementary transmission line theory:
\begin{subequations}
  \begin{align}
    &\Zleft(z_{s+1}) = Z_{q}^{(s+1)} \tanh(\gamma_{q}^{(s+1)} h^{(s+1)}) \\
    &\Zleft(z_i) = Z_{q}\eye
    \frac%
    {\Zleft(z_{i-1}) + Z_{q}\eye \tanh(\gamma_{q}\eye h\eye)}%
    {Z_{q}\eye + \Zleft(z_{i-1})\tanh(\gamma_{q}\eye h\eye)}, \quad
     i = s+2,s+3,\ldots,N-1.
  \end{align}
\end{subequations}
A similar recursive procedure can be used to calculate the
equivalent circuit currents and voltages at each of the remaining
junction planes:
\begin{multline}
  \left\{
    \begin{array}{@{}l@{}}
      \displaystyle
      I(z_i) = I(z_{i+1}) \cosh (\gamma_{q}\epw h\epw)
      + Y_q\epw
      V(z_{i+1}) \sinh ( \gamma_{q}\epw h\epw ), \\
      \displaystyle
      V(z_i) = -I(z_i) \Zleft(z_i)
    \end{array}
  \right.
  \\
  i = N-2,N-3\ldots,s.
  \label{eq:Mrecurseleft}
\end{multline}

The total incident (both incoming and reflected) magnetic field at
$z=z_s$ is then
\begin{equation}
  \Idemfactor_z \bdot \H\inc(x,y,z_s) = I(z_s) \h_q\enn(x,y)
  = I(z_s) \frac{c_q\spw}{c_q\enn} \h_q\spw(x,y),
\end{equation}
where we used the fact that $ c_q\enn \h_q\enn = c_q\spw \h_q\spw.$

The partial reflection scattering parameter (due to the incident
field) $S^{22}_{qq}$ is obtained from the equivalent circuit current
at $z=z_{N-1}$:
\begin{equation}
  \Idemfactor \bdot \H\inc(x,y,z_{N-1}) = I(z_{N-1}) \h_q\enn(x,y)
  = (S^{22}_{qq} - 1) \h_q\enn(x,y),
\end{equation}
so that
\begin{equation}
  S^{22}_{qq} = I(z_{N-1}) + 1.
\end{equation}

\subsection{Calculation of (scattered) GSM entries}
We now assume that the magnetic surface currents $\sigma\Ms$ at
$z = z_s-0$ and $-\sigma\Ms$ at $z = z_s+0$ have been numerically
determined, where $\sigma = 1$ for a primary wave incident from
Region~$1$ and $\sigma = -1$ for a primary wave incident from Region~$N$.
We seek expressions
for the outgoing  wave coefficients $\{b_q\one\}$
and $\{b_q\enn\}$ in the scattered field expansions
\begin{equation}
  \H\scat(x,y,z) =
  \begin{cases}
    \displaystyle
    \sum_{q} -b_q\one \h_q\one(x,y)
    e^{j\gamma_q\one (z-z_1)} & (z<z_1) \\[0.5ex]
    \displaystyle
    \sum_{q} b_q\enn \h_q\enn(x,y)
    e^{-j\gamma_q\enn (z-z_{N-1})} & (z>z_{N-1}).
  \end{cases}
\end{equation}
These coefficients are the partial GSM entries due to the scattered
(radiated by the induced surface currents) fields.
Using the results of \cite{mimo:97} we find that they are
\begin{subequations}
  \label{eq:bmagnetic}
\begin{align}
  b_{q}\one &=
  \z\cross\t_{q} \bdot \ftMs(\vecbeta_{m_q,n_q})
  \frac%
  {\sigma c_{q}\one  I_v^{p_q}(\vecbeta_{m_q,n_q},z_1,z_s)}%
  {P_0} \\
  %
  b_{q}\enn &=
  \z\cross\t_{q} \bdot \ftMs(\vecbeta_{m_q,n_q})
  \frac%
  {\sigma c_{q}\enn I_v^{p_q}(\vecbeta_{m_q,n_q},z_{N-1},z_s)}%
  {P_0}
  %
\end{align}
\end{subequations}
where $I_v^{p_q}$ is the transmission line Green's function for the
current due to a unit voltage source for either the TE ($p_q=1$) or TM
($p_q=2$) equivalent circuit, as shown in Figure~\ref{fig:mequiv3},
and $P_0 \equiv \SI{1}{\watt}$.
\begin{figure}[tbp]
  \begin{center}
    \footnotesize
    \pspicture(-0.3,-1.7)(12,1.6)
    \psset{nodesep=0pt}
    \shuntload{0}{$Y_{q}^{(1)}$}
    \zlabel{0}{$z_1$}
    \tlsection{0}{1.8}{2}
    \tlsection{2.6}{4.7}{\ensuremath{s}}
    \invertedvsource{4.7} \rput[l](4.75,0.35){$1\,\text{V}$}
    \zlabel{4.7}{$z_s$}
    \zlabel{6.4}{$z_s$}
    \vsource{6.4} \rput[l](6.45,0.35){$1\,\text{V}$}
    \tlsection{6.4}{8.7}{\ensuremath{s+1}}
    \tlsection{9.5}{11.6}{\ensuremath{N-1}}
    \shuntload{11.6}{$Y_{q}^{(N)}$}
    \zlabel{11.6}{$z_{N-1}$}
    \rput*(2.2,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(2.2,-0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,0.8){\huge$\boldsymbol{\cdots}$}
    \rput*(9.1,-0.8){\huge$\boldsymbol{\cdots}$}
    \endpspicture
    \caption{Equivalent transmission line circuits used to find
    scattered fields.
    We set $p=1$ when evaluating $\Iv\TE$ and $p=2$ for
    $\Iv\TM$. Superscripted quantities in parentheses are region
    designators. }
    \label{fig:mequiv3}
  \end{center}
\end{figure}
For either the left-looking or right-looking equivalent circuit,
we have a unit voltage source at $z=z_s$ so that the
current there is equal to the admittance seen at that point:
\begin{subequations}
\begin{align}
  \Vv^{p}(\vecbeta_{m_q,n_q},z_s^-,z_s) &= -1, \quad
  \Iv^{p}(\vecbeta_{m_q,n_q},z_s^-,z_s) = \Yleft(z_s^-) = 1/\Zleft(z_s^-), \\
  \Vv^{p}(\vecbeta_{m_q,n_q},z_s^+,z_s) &= 1, \quad \hphantom{-}
  \Iv^{p}(\vecbeta_{m_q,n_q},z_s^+,z_s) = \Yright(z_s^+) = 1/\Zright(z_s^+).
\end{align}
\end{subequations}
With the voltage and current known at $z_s$, one can apply
\eqref{eq:Mrecurseleft} for $i=s-1, s-2, \ldots, 1$ and
\eqref{eq:Mrecurseright} for $i=s+1, s+2, \ldots, N-1$ to determine
Green's function currents needed to evaluate Equations~\eqref{eq:bmagnetic}.


\section{Problem statement}
I aim to execute aggressive maneuvers similar to the display dives of male Anna’s Hummingbirds (\Calypteanna) with an autonomous quadrotor platform.

My project assumes the following are provided: a quadrotor and  flight controller (e.g. Crazyflie 2.1, Bitcraze, Malm\"{o}, Sweden), and a method of obtaining three-dimensional (3D) position data of the quadrotor in test flights (e.g. OptiTrack, NaturalPoint Inc., Corvalis, OR). Example trajectories obtained from live hummingbirds will be obtained from \cite{clark2009courtship}.  Given a desired hummingbird flight trajectory, depicted in \fref{fig:problem-statement-1}a, the system will autonomously generate and execute the control inputs required to successfully complete the maneuver.

A successful maneuver is defined as a root mean square error (RMSE) calculation of less than \SI{10}{cm} between the time-scaled hummingbird trajectory and the quadrotor trajectory, with a standard deviation $\sigma$ of \SI{5}{cm} over the entire dataset. The RMSE will be calculated between the $x$, $y$, $z$ position data for each pair of data points that share the same time value, $t$. The hummingbird trajectory will be scaled by a constant factor in time to allow for the physical limitations of the quadrotor--e.g. the quadrotor may only have to travel the desired trajectory at half the speed of the hummingbird to still achieve a successful maneuver. The hummingbird trajectory will also be geometrically dilated to a smaller overall trajectory path in order to physically fit the trajectory inside the available lab space. These are necessary adaptations due to the impressive speed and acceleration capabilities of the Anna’s hummingbirds relative to their size \cite{clark2009courtship}, and of course the physical size constraints of the Maury 201 labroom.
\begin{figure}[h]
\begin{center}
\includegraphics[height=1.88in]{\myroot/figures/problem-statement-1a.png}%
\includegraphics[height=1.88in]{\myroot/figures/problem-statement-1b.png}
\end{center}
\caption{(a) The five stages of an Anna’s Hummingbird dive maneuver, from \cite{clark2009courtship}. (b) A quadrotor using path planning to fly through a thrown hoop, from \cite{mellinger2011minimum}.}
\label{fig:problem-statement-1}
\end{figure}

As a stretch goal, I will also analyze and replicate a variety of different types of hummingbird dives and maneuvers, to include evasive aerial maneuvers \cite{sholtis2015field, cheng2016flight}. Success will be determined in the same fashion as described above.


\documentclass[a4paper, 12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xspace}
\usepackage{cleveref}
\usepackage{booktabs}
\usepackage[parfill]{parskip}
\usepackage{booktabs}

\newcommand{\pt}{\ensuremath{p_{\mathrm{T}}}\xspace}

\begin{document}

\section{Tracks}
The myTrack class is used to take a vector of hit objects and calculate the track parameters.
At current, two track parameter extraction methods are used: beamline constraint and no-beamline constraint.
First, some definitions.
\begin{description}
  \item[A fake track]
    A track is labelled as fake if any one of the hits belonging to the track do not come from the same particle.

  \item[Track reconstruction efficiency]
    The ATLAS convention defines this as the fraction of truth particles matched to a reconstructed track (after the track passes the relevant quality criteria).
    Here, we used the following definition
    \begin{equation}
      \epsilon = \frac{\mathrm{Number~of~tracks~matched}}{\mathrm{Number~of~particles~in~outermost~layer}}
    \end{equation}
    The number of particles in the outermost layer is used as a proxy for the number of true particles.
    The number of matched tracks is equivalent to the number of truth particles matched to a track.
    This efficiency can be calculated as a function of the reconstructed tracks $\eta$ or \pt, or of the truth particles $\eta$ or \pt.

  \item[Fake rate]
    The fake rate is defined as
    \begin{equation}
      R_f = \frac{\mathrm{Numer~of~fake~tracks}}{\mathrm{Numer~of~reconstructed~tracks}}.
    \end{equation}
    This can be defined as a per event quantity, or as a function of $\eta$ or $\pt$.

\end{description}

\subsection{Beamline constraint}
All tracks are assumed to have only three hits, one for each layer of the triplet.
To extract the track parameters, it is assumed that the particle originated form the beamline, i.e. $(0, 0, z_0)$ in $(x, y, z)$.
Only the hits in the outermost and innermost layer are used, with coordinates $(x_1, y_1, z_1)$ and $(x_3, y_3, z_3)$ respectively, giving a total of three coordinates.
By definition $d_0=0$.

To extract the radius of curvature the centre of the circle connecting the three coordinates is calculated in the $x$--$y$ plane as follows:
\begin{align}
  a = \frac{y_3 r_{01}^2 - y_1 r_{03}^2}{2(y_3x_1 - y_1x_3)} \\
  b = \frac{x_3 r_{01}^2 - x_1 r_{03}^2}{2(y_3x_1 - y_1x_3)}
\end{align}
where $r_{0i} = \sqrt{x^2_i + y^2_i}$ and $(a, b)$ are the coordinates of the centre of the circle.
Since the circle touches the origin, the radius of curvature is then $R=\sqrt{a^2 + b^2}$ from which the \pt can be extracted using $\pt[\mathrm{GeV}] = 1.199 \times R[\mathrm{m}]$, which holds for a
magnetic field of 4\,T.

As an aside, one can further simplify the expression for $R$, consider $R^2 = a^2+b^2$ and let $C_{13} = x_1 y_3 - y_1 x_3$,
\begin{align}
  a^2 + b^2 & = \frac{(y_3 r_{01}^2 - y_1 r_{03}^2)^2 + (x_3 r_{01}^2 - x_1 r_3^2)^2}{4C_{13}^2} \\
  & = \frac{r^4_{01} y_3^2 + r_{03}^4 y_1^2 - 2 r^2_{01}r^2_{03}y_1 y_3    + r^4_{01} x_3^2 + r_{03}^4 x_1^2 - 2 r^2_{01}r^2_{03}x_1 x_3      }{4C_{13}^2} \\
  & = \frac{r_{01}^4 (x_3^2 + y_3^2) + r_{03}^4 (x_1^2 + y_1^2) -2r^2_{01}r^2_{03}(x_1 x_3 + y_1 y_3)}{4 C_{13}^2} \\
  & = \frac{r^2_{01}r^2_{03}(r^2_{01} + r^2_{03} -2(x_1 x_3 - y_1 y_3))}{4C_{13}^2} \\
\end{align}
Noticing that $r^2_{13} = (x_3 - x_1)^2 + (y_3 - y_1)^2 = r_{01}^2 + r_{03}^2 - 2(x_1 x_3 + y_1y_3)$, we have
\begin{equation}
  R = \sqrt{a^2 + b^2} = \frac{r_{01} r_{03} r_{13}}{2C_{13}}
\end{equation}

The $\phi$ parameter is calculated as the angle made by the tangent to the circle at the origin.
The angle is given by $\phi = \tan^{-1}( -b/a)$.

In the longitudinal plane $z_0$ and $\eta$ can also be extracted.
We follow the methodology of A. Sch\"oening.
First the bending angles at the first and third layer positions are calculated
\begin{align}
  \Phi_1 & = 2 \sin^{-1} \left( \frac{C_{13}}{r_{13} r_{03} }\right) \\
  \Phi_3 & = 2 \sin^{-1} \left( \frac{C_{13}}{r_{13} r_{01} }\right)
\end{align}
where $C_{13} = x_1 y_3 - y_1 x_3$.
Then the corresponding arc lengths are calculated
\begin{align}
  s_1 & = R \Phi_1 \\
  s_3 & = R \Phi_3
\end{align}
From which the track parameters are extracted as follows:
\begin{align}
  z_0 & = z_1 - s_1 \frac{z_3 - z_1}{ s_3 - s_1} \\
  \theta & = \tan^{-1} \left( \frac{s_3 - s_1}{ z_3 - z_1} \right)
\end{align}

\subsection{No beamline constraints}
Here, the above assumption that the track originated from $(0, 0, z_0)$ is removed, and all three hit points are used to extract the track parameters.

\section{Results}
Track parameters are calculated with the beamline constraint by default.

\end{document}


\chapter{Dynamic Causal Modelling for resting state fMRI \label{Chap:DCM_rsfmri}}

This chapter provides an extension to the framework of Dynamic Causal Modelling (DCM) for modelling intrinsic dynamics of a resting state network \cite{rsDCM2014,rsDCM2015}. This DCM estimates the effective connectivity among coupled populations of neurons, which subtends the observed functional connectivity in the frequency domain. We refer to this as spectral DCM (spDCM).

\section{Theoretical background}
Spectral DCM uses a neuronally plausible power-law model of the coupled dynamics of neuronal populations to generate complex cross spectra among measured responses. Spectral DCM is distinct from stochastic DCM (sDCM) \cite{stocDCM2011} as it eschews the estimation of random fluctuations in (hidden) neural states; rendering spectral DCM essentially deterministic in nature. These models are similar to conventional deterministic DCM for fMRI \cite{dcm} but model endogenous activity that would reproduce the functional connectivity (correlations) observed in resting state fMRI. DCMs for resting state data are also slightly simpler; given that most resting state designs compare groups of subjects (e.g. patient cohorts vs. controls), spDCMs do not usually require the bilinear term (accounting for condition-specific effects on effective connection strengths). In other words, spectral DCM is intended to simply compare endogenous coupling between groups of subjects (e.g. patients vs. healthy controls).

In modelling resting state activity, it is necessary to augment the ordinary differential equations used in standard DCM, with a stochastic term to model endogenous neuronal fluctuations. This renders the equations of the motion stochastic. The stochastic generative model for the resting state fMRI time series, like any other DCM, comprises of two equations: the Langevin form of evolution equation (motion) is written as:

\begin{equation}\label{spdcm_eq1}
\dot{z}= f(z,u,\theta)+ v
\end{equation}
and the observation equation, which is a static nonlinear mapping from the hidden physiological states in Eq.~\ref{spdcm_eq1} to the observed BOLD activity and is written as:
\begin{equation}\label{spdcm_eq2}
y= h(z,u,\phi)+ e
\end{equation}
where $\dot{z}$ is the rate in change of the neuronal states $z$, $\theta$ are unknown parameters (i.e. the effective connectivity) and $v$ (resp. $e$) is the stochastic process -- called the state noise (resp. the measurement or observation noise) -- modelling the random neuronal fluctuations that drive the resting state activity.  In the observation equations, $\phi$ are the unknown parameters of the (haemodynamic) observation function and $u$ represents any exogenous (or experimental) inputs -- that are usually absent in resting state designs. For resting state activity, Eq.~\ref{spdcm_eq1} takes on a very simple linear form:
\begin{equation}\label{spdcm_eq3}
\dot{z}= Az + Cu + v
\end{equation}
where $A$ is the Jacobian describing the behaviour -- i.e. the effective connectivity -- of the system near its stationary point ($f(z_{o})=0$) in the absence of the fluctuations $v$. It is to be noted that we can still include exogenous (or experimental) inputs, $u$  in our model. These inputs drive the hidden states -- and are usually set to zero in resting state models. It is perfectly possible to have external, (non-modulatory) stimuli, as in the case of conventional functional neuroimaging studies. For example, in \cite{dcm} we used an attention to visual motion paradigm to illustrate this point.

Inverting the stochastic DCM of the form given by Eq.~\ref{spdcm_eq3} in the time domain, which includes state noise, is rather complicated because such models require estimation of not only the model parameters (and any hyperparameters that parameterise the random fluctuations), but also the hidden states, which become random (probabilistic) variables. Hence the unknown quantities to be estimated under a stochastic DCM are  $\psi=\{z,\phi,\theta,\sigma\}$, where $\sigma$ refers to any hyperparameters (precisions or inverse covariances) defining the neuronal fluctuations. In terms of temporal characteristics, the hidden states are time-variant, whereas the model parameters (and hyperparameters) are time-invariant. There are various variational schemes in literature that can invert such models. For example, dynamic expectation maximization (DEM) \cite{karl_DEM} and generalized filtering (GF) \cite{karl_generalised_filtering}.

Although the stochastic models in  Eq.~\ref{spdcm_eq1} and their inversion in time domain provide a useful means to estimate effective connectivity they also require us to estimate hidden states. This poses a difficult inverse problem that is computationally demanding; especially when the number of hidden states becomes large. To finesse this problem, we furnish a constrained inversion of the stochastic model by parameterising the neuronal fluctuations. This parameterisation also provides an opportunity to compare parameters encoding the neuronal fluctuations among groups. The parameterisation of endogenous fluctuations means that the states are no longer probabilistic; hence the inversion scheme is significantly simpler, requiring estimation of only the parameters (and hyperparameters) of the model.

Spectral DCM simply estimates the time-invariant parameters of their cross spectra. In other words, while stochastic DCMs model the observed BOLD timeseries of each node, spectral DCMs model the observed functional connectivity between nodes. Effectively, this is achieved by replacing the original timeseries with their second-order statistics (i.e., cross spectra), under stationarity assumptions. This means, instead of estimating time varying hidden states, we are estimating their covariance, which does not change with time. This means we need to estimate the covariance of the random fluctuations; where a scale free (power law) form for the state noise (resp. observation noise) that can be motivated from previous work on neuronal activity:
\begin{eqnarray}\label{spdcm_eq4}
& g_{v}(\omega,\theta) & = \alpha_{v}\omega^{-\beta_{v}}\\ \nonumber
& g_{e}(\omega,\theta) & = \alpha_{e}\omega^{-\beta_{e}}
\end{eqnarray}
Here, $\{\alpha,\beta\}\subset \theta$ are the parameters controlling the amplitudes and exponents of the spectral density of the neural fluctuations. This models neuronal noise with a generic $1/f^{\gamma}$ spectra, which characterizes fluctuations in systems that are at nonequilibrium steady-state. Using the model parameters, $\theta \supseteq \{A,C,\alpha, \beta\}$, we can simply generate the expected cross spectra:
\begin{eqnarray}\label{spdcm_eq5}
& y & = \kappa \ast v + e\\ \nonumber
& \kappa & = \partial_z h \mathrm{exp} (t \partial_z f ) \\ \nonumber
& g_{y}(\omega,\theta) & = |K(\omega)|^2 g_{v}(\omega,\theta) + g_{e}(\omega,\theta)
\end{eqnarray}
where $K(\omega)$ is the Fourier transform of the system's (first order) Volterra kernels  $\kappa$, which are a function of the Jacobian or effective connectivity. The unknown quantities $\psi=\{\phi,\theta,\sigma\}$ of this deterministic model can now be estimated using standard Variational Laplace procedures \cite{karl_vb_laplace}. Here $g_{y} (\omega,\theta)$ represents the predicted cross spectra that can be estimated, for example, using autoregressive (AR) model. Specifically, we use a fourth-order autoregressive model to ensure smooth sample cross spectra of the sort predicted by the generative model. The frequencies usually considered for fMRI range from 1/128 Hz to 0.1 Hz in 32 evenly spaced frequency bins.

\section{Practical example}

Data used for this example can be downloaded from the SPM website. This dataset\footnote{Resting state DCM dataset: \url{http://www.fil.ion.ucl.ac.uk/spm/data/spDCM/}} consists of an exemplar subject from the full dataset available from the FC1000 project website\footnote{``1000 Functional Connectomes'' Project,: \url{http://fcon_1000.projects.nitrc.org/fcpClassic/FcpTable.html}} and was used in \cite{rsDCM2015} to interrogate the information integration in default mode network (DMN) -- a distinct brain system that is activated when an individual engages in introspection like mindwandering or daydreaming. The DMN comprises part of the medial prefrontal cortex (mPFC), posterior cingulate cortex (PCC) and parts of inferior parietal lobe and superior frontal regions.

The archive contains the smoothed, spatially normalised, realigned, slice-time corrected images in the directory \texttt{func}. The directory \texttt{anat} contains a spatially normalised T1 structural image and the directory \texttt{GLM} contains the file \texttt{rp\_rest0000.txt} containing six head motion parameters. All preprocessing took place using SPM12.

\subsection{Defining the GLM}
First, we need to set up the GLM analysis and extract our time series from the results. For resting state fMRI because there is no task so first we need to generate \texttt{SPM.mat} so that we can extract the time series. This can be done by following the steps below.

Let's set up a batch that will specify the model and estimate it.

\begin{enumerate}
 \item The analysis directory you have downloaded should include:
 \begin{enumerate}
  \item A directory named \texttt{func}, which includes the preprocessed fMRI volumes.
  \item A directory named \texttt{anat}, which includes a normalised T1 structural volume.
  \item A directory named \texttt{GLM}, which include file \texttt{rp\_rest0000.txt} containing the movement regressors from the realignment step.
 \end{enumerate}
 \item In \matlab\ type
\begin{verbatim}
>> cd GLM
>> spm fmri
\end{verbatim}
 \item From the main SPM window, click on the \textsc{Batch} button.
 \item From the SPM menu at the top of the Batch Editor, select ``Stats $>$ fMRI model specification''.
 \item Click \textsc{Directory} and choose the \texttt{GLM} directory that you made above.
 \item \textsc{Units for design} [\textsc{scans}]
 \item \textsc{Interscan interval} [2]
 \item Click \textsc{Data \& Design}, Choose \textsc{New "Subject/Session"}
 \item Click \textsc{Scans} and choose all the functional scans \texttt{swrestxxxx.img}. There should be 175 \texttt{*.img} files.
 \item From the SPM menu at the top of the Batch Editor, select ``Stats $>$ model estimation''.
 \item For \textsc{Select SPM.mat}, click on the \textsc{Dependency} button and choose the proposed item (the output from the previous module).
 \item You should now be able to press the \textsc{Run} green arrow at the top of the Batch Editor window. This will specify and estimate the GLM.
\end{enumerate}

We will also need to extract signal from CSF and white matter (WM) to be used as confound. Here is a step-by-step example for extracting the WM (Pons) time series which we will use as one of the nuisance variable:

\begin{enumerate}
 \item From the main SPM window, click on the \textsc{Batch} button.
 \item From the SPM menu at the top of the Batch Editor, select ``Util $>$ Volume of interest''
 \item Select the \texttt{SPM.mat} file (generated during the previous section).
 \item Adjust data: \texttt{NaN}
 \item Which session: \texttt{1}
 \item Name of VOI: \texttt{WM}
 \item Select 'Region(s) of Interest' $>$ Sphere
 \item Centre: \texttt{[0 -24 -33]}
 \item VOI radius (mm): e.g.\texttt{6} mm
 \item Select 'Movement of Centre' $>$ Fixed
 \item Select 'Region of Interest' $>$ Mask Image
 \item Image file: select \texttt{mask.nii} (in \texttt{GLM} folder)
 \item Expression: \texttt{i1\&i2}
 \item Now you should be able to press the green arrow button. This would extract the WM time series and save this as  \texttt{VOI\_WM\_1.mat} in the working directory.
\end{enumerate}

Do the same thing with to extract CSF (from one of the ventricles) signal with a sphere centred on \texttt{[0 -40 -5]}. This will create files \texttt{VOI\_CSF\_1.mat}. Next we need to adjust the SPM with the covariates. Do the following procedure:
\begin{enumerate}
 \item From the main SPM window, click on the \textsc{Batch} button.
 \item From the SPM menu at the top of the \textsc{Batch Editor}, select ``Stats $>$ fMRI model specification''.
 \item Click Directory and choose the \texttt{GLM} directory that you made above.
 \item \textsc{Units for design} [\textsc{scans}]
 \item \textsc{Interscan interval} [2]
 \item Click \textsc{Data \& Design}, Choose \textsc{New "Subject/Session"}
  \item Click \textsc{Scans} and choose all the functional scans \texttt{swrestxxxx.img}. There should be 175 \texttt{*.img} files.
 \item Click on Multiple Regressors. And then select the  \texttt{VOI\_CSF\_1.mat}t, \texttt{VOI\_WM\_1.mat} and \texttt{rp\_rest000.txt}. Leave the rest of the fields as default.
 \item From the SPM menu at the top of the Batch Editor, select ``Stats $>$ model estimation''.
 \item For \textsc{Select SPM.mat}, click on the \textsc{Dependency} button and choose the proposed item (the output from the previous module).
 \item You should now be able to press the \textsc{Run} green arrow at the top of the Batch Editor window (press 'continue' when asked for overwriting existing \textsc{SPM.mat} file). This will specify and estimate the GLM.
\end{enumerate}

\subsection{Extracting time series}

Once you have specified and estimated the GLM, here is now a step-by-step example for extracting the PCC time series:
\begin{enumerate}
 \item From the main SPM window, click on the \textsc{Batch} button.
 \item From the SPM menu at the top of the Batch Editor, select ``Util $>$ Volume of interest''
 \item Select the \texttt{SPM.mat} file (generated during the previous section).
 \item Adjust data: \texttt{NaN}
 \item Which session: \texttt{1}
 \item Name of VOI: \texttt{PCC}
 \item Select 'Region(s) of Interet' $>$ Sphere
 \item Centre: \texttt{[0 -52 26]}
 \item VOI radius(mm): e.g.\texttt{ 8} mm
 \item Select 'Movement of Centre' $>$ Fixed
 \item Select 'Region of Interest' $>$ Mask Image
 \item Image file: select \texttt{mask.nii} (in \texttt{GLM} folder)
 \item Expression: \texttt{i1\&i2}
 \item Now you should be able to press the green arrow button. This would extract the WM time series and save this as  \texttt{VOI\_CSF\_1.mat} in the working directory.
\end{enumerate}
SPM now computes the first principal component of the time series from all voxels included in the sphere. The result is stored (together with the original time series) in a file named \texttt{VOI\_PCC\_1.mat} in the working directory (the ``1'' refers to session 1). Do the same for the rest of the VOIs: mPFC (\texttt{[3 54 -2]}), LIPC ({[-50 -63 32]}) and RIPC (\texttt{[48 -69 35]}).

\subsection{Specifying and estimating the DCM}

Now we have extracted the time series, we are ready to build the DCM. We will look at a simplified version of the model described in \cite{rsDCM2015}.  In our example here, we will model a fully connected system comprising PCC, mPFC and bilateral IPC. This DCM is shown schematically in Figure~\ref{spdcm_full}, and can be made as follows:
\begin{enumerate}
 \item Press the large \texttt{Dynamic Causal Modelling} button.
 \item Choose \textsc{specify}.
 \item Select the \texttt{SPM.mat} file you just created when specifying the GLM.
 \item \texttt{DCM\_???.mat}: e.g. \texttt{DMN}.
 \item Select all VOIs in order \texttt{VOI\_PCC\_1}, \texttt{VOI\_mPFC\_1}, \texttt{VOI\_LIPC\_1} and  \texttt{VOI\_RIPC\_1}.
 \item Specify slice timings for each area. The default values are set to the last slice of the data, which was the default in the original DCM version. For sequential (as opposed to interleaved) data, this modelling option allows to use DCM in combination with any TR (slice timing differences). Here, we proceed with the default values.
\item Enter \texttt{0.04} for ``Echo Time, TE[s]''.
\item Define the fully connected model. Your connectivity matrix should look like the one in See Figure~\ref{spdcm_Fig1}.
\end{enumerate}
A polite ``Thank you'' completes the model specification process. A file called \texttt{DCM\_DMN.mat} will have been generated.

You can now estimate the model parameters, either by pressing the DCM button again and choosing \textsc{estimate (cross-spectra)}, or by typing
\begin{verbatim}
>> spm_dcm_estimate('DCM_DMN');
\end{verbatim}
from the \matlab\ command line.

Once this is completed, you can review the results as follows:
\begin{enumerate}
\item Press the DCM button.
\item Choose \textsc{review}.
\item Select \texttt{DCM\_DMN.mat}
\end{enumerate}

By clicking ``review...'' you can now select from multiple options, e.g. you can revisit the fit of the model (``Cross-spectra (BOLD)''), shown in Figure~\ref{spdcm_Fig2} or look at the parameter estimates for the endogenous coupling (``Coupling (A)'') as shown in Figure~\ref{spdcm_Fig3}. Of course, you can also explore the model results at the level of the \matlab\ command line by loading the model and inspecting the parameter estimates directly. These can be found in \texttt{DCM.Ep.A} (endogenous coupling) and  \texttt{DCM.Ep.a }(neuronal parameters).

\begin{figure}[ht]
\begin{center}
\includegraphics[width=100mm]{dcm_rs/dcm_mod_full}
\caption{\em DCM with fully connected model.\label{spdcm_full}}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\includegraphics[width=100mm]{dcm_rs/Fig1}
\caption{\em Specification of model depicted in Fig~\ref{spdcm_Fig1}. Filled circles define the structure of the extrinsic connections A such that all circles are filled since we are using a fully connected model here.
\label{spdcm_Fig1}}
\end{center}
\end{figure}

\begin{figure}[ht]
\begin{center}
\includegraphics[width=140mm]{dcm_rs/Fig2}
\caption{\em Plot of predicted and observed cross spectral densities after convergence in Fig~\ref{spdcm_Fig2}. The dotted lines are measured cross spectra and solid lines are its predictions. The lower left panel shows the self cross spectra for the four regions. The rest of the graphics show both self and cross spectra for the four regions.
\label{spdcm_Fig2}}
\end{center}
\end{figure}

\begin{figure}[ht]
\begin{center}
\includegraphics[width=140mm]{dcm_rs/Fig3}
\caption{\em This Fig~\ref{spdcm_Fig3} shows the estimated fixed A matrix (top and lower left panels). The posterior probabilities of these effective connectivity parameters are shown on the lower right panel. The red dashed line depicts the 95\% threshold.
\label{spdcm_Fig3}}
\end{center}
\end{figure}


\subsection{Specific Implementation Details}
\label{ssec:pk_curve_specifics}

At this point in time, the Ethereum Virtual Machine (EVM)
only allows for certain elliptic curve operations to
be performed inexpensively from precompiled contracts.
In order to keep gas costs low, we will rely heavily
on these contracts.
The precompiled contracts are
\textsc{ECAdd}, \textsc{ECMul}, and \textsc{PairingCheck};
see Alg.~\ref{alg:ec_algs} for specifics.
While they have the names addition and scalar multiplication,
we will primarily be using multiplicative notation in this whitepaper;
the exception will be when we talk about hash-to-curve algorithms
in Sec.~\ref{ssec:hash-to-curve}.
Furthermore, we may not explicitly reference \textsc{ECAdd}
and \textsc{ECMul} when using them in our algorithms
for space considerations, although we will use comments to make
this clear.

\input{algs/ec_algs.tex}

We require elliptic curves with pairing-based cryptography.
The source code for curve \texttt{bn256} is implemented
for Ethereum here\footnote{
\url{https://github.com/ethereum/go-ethereum/tree/master/crypto/bn256/cloudflare}
}.
This code implements the Optimal Ate pairing from~\cite{naehrig2010new} and
is based on Barreto-Naehrig curves~\cite{bnCurves},
a family of pairing-friendly curves.
A more recent version of Cloudflare's library can be found here\footnote{
\url{https://github.com/cloudflare/bn256}}.
Cloudflare's version includes a hash-to-curve function
based on~\cite{ft2012bnhashtocurve}, which is the same paper we base our
hash function on.
Unfortunately, the newer version uses a different prime;
the Ethereum library uses a 254-bit prime while the current Cloudflare
library uses a 256-bit prime.
We modified the Ethereum code
and included functions for computing modular square roots as
well as a hash-to-curve algorithm.
We plan to make these updates available to others, as they will
be useful whenever cryptographic signatures are used.
Our code includes an implementation for the hash-to-curve algorithms
described in~\cite{ft2012bnhashtocurve}; see Sec.~\ref{ssec:hash-to-curve}.

The underlying field operations perform arithmetic modulo a prime number.
This can be difficult to perform quickly~\cite[Chapter 14]{hac1996}.
The \texttt{bn256} library uses Montgomery
encoding~\cite{montgomery1985modular} for efficiency;
we will give an overview here although one reference
is~\cite[Chapter 14.3.2]{hac1996}.
The primary advantage of using the Montgomery encoding is that
modular multiplication requires only multiplication with a potential
subtraction; in particular, it does not require division.

If we want to perform multiplication modulo $p$, let $R>p$ such
that $\gcd(R,p) = 1$ and it is convenient to perform modular arithmetic
with respect to $R$.
Given $x\in\Z_{p}$, the Montgomery encoding of $x$ is

\begin{equation}
    \tilde{x} \equiv xR \mod p.
\end{equation}

\noindent
Given two encoded values $\tilde{a}$ and $\tilde{b}$,
Montgomery multiplication allows us to compute $\widetilde{ab}$:

\begin{equation}
    \widetilde{ab} = \tilde{a}\tilde{b}R^{-1} \mod p.
\end{equation}

\noindent
Here, $R^{-1}R = 1 \mod p$, so $R^{-1}$ is the multiplicative
inverse of $R$ with respect to $p$.
An efficient implementation of Montgomery multiplication
allows us to use it both for encoding and decoding,
and this is what the \texttt{bn256} library does.

We now look at the elliptic curves in the pairing-based cryptography.
Specifically, we have the elliptic curve $E/\F_{p}$ where

\begin{equation}
    E : y^{2} = x^{3} + ax + b
\end{equation}

\noindent
and constants

\begin{align}
    p &= \texttt{30644E72 E131A029 B85045B6 8181585D 97816A91 6871CA8D 3C208C16
                D87CFD47} \nonumber\\
        &= 36u^{4} + 36u^{3} + 24u^{2} + 6u + 1 \nonumber\\
    q &= \texttt{30644E72 E131A029 B85045B6 8181585D 2833E848 79B97091 43E1F593
                F0000001} \nonumber\\
        &= 36u^{4} + 36u^{3} + 18u^{2} + 6u + 1 \nonumber\\
    u &= 4965661367192848881 \nonumber\\
    a &= 0 \nonumber\\
    b &= 3 \nonumber\\
    g_{1} &= \parens{1,2} \nonumber\\
    h_{1} &= \parens{h_{1,x}, h_{1,y}} \nonumber\\
    h_{1,x} &= \texttt{081D36DE F693881E DFC5614E AE25BB5C 228A7142 A36EE533 47B09434 1D541F2C} \nonumber\\
    h_{1,y} &= \texttt{2CD20C36 14D407F3 39B9BB25 EF23979C D2EE1E45 310EB0C5 023A3F5F D52D8B11}
\end{align}

\noindent
From here, we see $p = 3 \mod 4$ and $p = 1 \mod 6$.
If $E(\F_{p})$ is the group of points on $E/\F_{p}$
acting under addition, then $E(\F_{p}) = \angles{g_{1}}$
and $\abs{E(\F_{p})} = q$; here, $g_{1}$ the standard generator.
From the construction of BN curves, $q$ is prime,
which implies that any nontrivial element of $\G_{1}$ is a generator.
During the distributed key generation protocol, we will
need another generator $h_{1}$ for $E(\F_{p})$ such that
$\dlog_{g_{1}}h_{1}$ is unknown, which ensures no one
is able to bias the underlying probability distribution
of the master public key.
Here, we set

\begin{equation}
    h_{1} = \textsc{HashToG1}(\texttt{[]byte("MadHive Rocks!")}),
\end{equation}

\noindent
where $\textsc{HashToG1}$ is the hash-to-curve function
from Alg.~\ref{alg:hash-to-G1} developed in
Sec.~\ref{ssec:hash-to-curve}.
In the future $h_{1}$ may change on each iteration of the DKG
protocol, but it is constant at this point.

We let $e:\G_{1}\times\G_{2}\to\G_{T}$ be our nondegenerate
bilinear map over groups $\G_{1}$, $\G_{2}$, and $\G_{T}$.
We let $\G_{1} = E(\F_{p})$, $\G_{2}\subseteq E(\F_{p^{12}})$,
and $\G_{T}\subseteq \F_{p^{12}}^{*}$;
$e$ is the Optimal Ate pairing~\cite{bnCurves}.
By design, we have $\abs{\G_{1}} = \abs{\G_{2}} = \abs{\G_{T}} = q$.
For efficient implementation, we will need to look at the twist
curve $E'/\F_{p^{2}}$ where

\begin{equation}
    E' : y^{2} = x^{3} + b'.
\end{equation}

\noindent
In this case, $b' = b/\xi$ and the specific choice of
$\xi\in\F_{p^{2}}^{*}$ will be discussed below.
We then define

\begin{align}
    &\psi:E'(\F_{p}^{2})\to E(\F_{p}^{12}) \nonumber\\
    &\parens{x',y'} \mapsto \parens{z^{2}x',z^{3}y'},
\end{align}

\noindent
and we see that $\psi$ is an injective group homomorphism.
Here, we use the definition
$\F_{p^{12}} \equiv \F_{p^{2}}\brackets{X}/\parens{X^{6}-\xi}$,
where $\xi\in\F_{p^{2}}$ is a nonsquare noncube
and $z\in\F_{p^{12}}$ is one of the roots of $X^{6}-\xi$.
That $\xi\in\F_{p^{2}}^{*}$ exists follows from
the fact $p = 1\mod 6$; for more information
see~\cite[Lemma 1]{bnCurves}.
It is this homomorphism $\psi$  which allows for efficient
computation, because this allows most of our arithmetic operations
to occur in $\F_{p}$ and $\F_{p^{2}}$;
in particular, signatures are elements of $E(\F_{p})$
and we represent public keys as elements of $E'(\F_{p^{2}})$.
The only time arithmetic in $\F_{p^{12}}$ is required is when
we compute the Optimal Ate pairing.

We now discuss the specific parameters for the twist curve $E'$:

\begin{align}
    \xi &= i + 9 \nonumber\\
    h_{2,x,i} &= \texttt{198E9393 920D483A 7260BFB7 31FB5D25 F1AA4933 35A9E712 97E485B7 AEF312C2} \nonumber\\
    h_{2,x} &= \texttt{1800DEEF 121F1E76 426A0066 5E5C4479 674322D4 F75EDADD 46DEBD5C D992F6ED} \nonumber\\
    h_{2,y,i} &= \texttt{090689D0 585FF075 EC9E99AD 690C3395 BC4B3133 70B38EF3 55ACDADC D122975B} \nonumber\\
    h_{2,y} &= \texttt{12C85EA5 DB8C6DEB 4AAB7180 8DCB408F E3D1E769 0C43D37B 4CE6CC01 66FA7DAA} \nonumber\\
    h_{2} &= \parens{h_{2,x,i}i + h_{2,x}, h_{2,y,i}i + h_{2,h}}.
\end{align}

\noindent
The values of $\xi$ and $h_{2}$ are from the \texttt{bn256}
implementation used in Ethereum.
We specify the $i$ component before the non-$i$ component
following the library convention.

For BN curves like the one we are using, there is no known
efficiently computable isomorphism
$\vphi:\G_{2}\to\G_{1}$~\cite[Chap 2.2.7]{rass2013cryptography},
which makes our setting Type 3~\cite{EfficienySecurity2010}.

As noted in the Cloudflare \texttt{bn256} source code repository,
the original implementation had approximately 128 bits of security,
but this has been reduced due to recent work~\cite{exTNFS}.
The exact security level has been discussed
here~\cite{MSSsecurity,BDkeysizes}, with~\cite{BDkeysizes} listing the
security level at 100 bits.
While this is below the desired 128-bit level, it is believed
to be currently out of reach.
Even so, with this in mind we take precautions by enforcing
regular key rotation in order to ensure the security of the system.
The decrease in security is partially mitigated by the fact that
validators use the Ethereum private key to sign messages
throughout the consensus algorithm.


\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}

\author{Salvador Castagnino \\ scastagnino@itba.edu.ar}
\date{}
\title{Chapter 3 - $L^p$ Spaces}

\begin{document}

\maketitle

\section*{Exercise Solutions}

\begin{exercise}\textbf{Exercise 3.3.}
    Let's suppose that $\phi$ is not convex in $ \left( a,b \right)   $ then there exist $x,y \in \left( a,b \right) $ and $t_0 \in [0,1]$ such that
    \[
       \phi \left( \left( 1-t_0 \right) x + t_0 y \right) > \left( 1-t_0 \right) \phi \left( x \right) + t_0 \phi \left( y \right)
    \]
    Define $g,h:[0,1] \rightarrow \mathbb{R}$ such that,
    \[
       g \left( t \right) = \phi \left( \left( 1-t \right) x + t y \right)
    \]
    \[
       h \left( t \right) = \left( 1-t \right) \phi \left( x \right) + t \phi \left( y \right)
    \]
    and let $f = h - g$. We define the nonempty sets $A = \{t \in [0,t_0\left)\ |\ f(t)=0\}$ and $B = \{t \in \left(t_0, 1]\ |\ f(t)=0\}$ given that $f \left( 0 \right) = f \left( 1 \right) = 0$, and let $t_a = \sup A$ and $t_b = \inf B$, we want to see that $t_a \in A$  and $t_b \in B$. Let $\{a_n\}$ and $\{b_n\}$ be sequences in $A$ and $B$ which converge to $t_a$ and $t_b$ respectively, by continuity of $f$ we can see that
    \[
        0 = \lim_{n \to \infty} f \left( a_n \right) = f \left( \lim_{n \to \infty} a_n \right) = f \left( t_a \right)
    \]
    With this and the fact that $t_a < t_0 < t_b$ as $f \left( t_0 \right) < 0$ we have that $t_a \in A$ and the proof for $t_b \in B$ is analogous. Now by the definition of $t_a$ and $t_b$ and continuity of $f$ we have that $f \left( t \right) < 0$ for all $t \in \left( t_a,t_b \right)$. Finally we take $x'= \left( 1-t_a \right) x+t_ay$ and $y' = \left( 1-t_b \right) x+t_by$ and by working algebraically over $f \left( \frac{t_a+t_b}{2} \right) < 0$ we arrive at the following inquality
    \[
        \phi \left( \frac{x'+y'}{2} \right) > \frac{\phi \left( x' \right) + \phi \left( y' \right) }{2}
    \]
    which is a clear contradiction, as we wanted. This concludes the proof.

\end{exercise}

\bigbreak

\begin{observation}\textbf{Observation}
    This proof shows that to see that convexity holds it sufices to show that given each pair of points $x,y \in \left( a,b \right) $ there exists a $t \in [0,1]$ (not necessarily $\frac{1}{2}$ ) such that $\phi \left( \left( 1-t \right) x + t y \right) \le  \left( 1-t \right) \phi \left( x \right) + t \phi \left( y \right)$.
\end{observation}

\bigbreak

\begin{exercise}\textbf{Exercise 3.4.}
    Let $f$ be a complex measurable function on $X$ and $\mu$ a positive measure on $X$, define
    \[
        \phi \left( p \right) = \int_X |f|^p\: d\mu = \|f\|_p^p \quad \left( 0 < p < \infty \right)
    \]
    and now let $E = \{p: \phi \left( p \right) < \infty\}$ and assume $0 < \|f\|_\infty$. Let's begin by characterizing $E$. Let $0<p<s<\infty$ and $x \in [0, \infty \left)$ then $x^p < x^s$ iff $1 < x$ and $x^s < x^p$ iff $x < 1$. With this in mind if $0<r<p<s<\infty$ then $|f|^p \le max\{|f|^r,|f|^s\} \le |f|^r+|f|^s$ and we get,
    \[
        \int_X |f|^p\: d\mu \le \int_X |f|^r\: d\mu + \int_X |f|^s\: d\mu
    \]
    Suppose that $s,r \in E$ then $p \in E$, which proves statement (a).

\bigbreak

    As a consequence of (a) we see that $E$ is a connected set and with this in mind, supposing $E$ is nonempty, we can see that $E$ is an interval with endpoints $a= \inf E$ and $b = \sup E$, this interval will be closed or not if $E$ contains them or not, but for sure $E^o= \left( a,b \right) $.

\bigbreak

    To prove that $\log \phi$ is convex in $E^o$ we start by proving that the composition is well defined, in other words, $\phi$ is never zero. If $\phi \left( p \right) = 0$ for some $p \in E^o $ then $|f|=0$ a.e. on $X$ and this implies $\|f\|_\infty = 0$ contradicting our assumption, thus the composition is well defined and we proceed to prove convexity. Take $x,y \in \left( a,b \right) $ and $t \in \left( 0,1 \right) $. By properties of the logarithm we get,
    \[
        \left( 1-t \right) \log \phi \left( x \right) + t \log \phi \left( y \right) = \log \left( \phi \left( x\right)^{1-t} \phi \left( y \right)^t \right)
    \]
    given that the logarithm is a nondecreasing function, convexity holds if and only if
    \[
        \phi \left( (1-t)x + ty \right) \le \phi \left( x \right)^{1-t} \phi \left( y \right)^t
    \]
    rewriting $\phi$ on both sides in terms of Lp norms we get the following,
    \[
        \|f^{ \left( 1-t \right) x} f^{ty}\|_1 \le \|f^{ \left( 1-t \right) x}\|_ {\left( 1-t \right)^{-1} } \|f^{ty}\|_{t^{-1}}
    \]
    Given that $1 \le \left( 1-t \right)^{-1}$ and $1 \le  t^{-1} $ are conjugate exponents, the last inequallity holds by Holder's inequality and this concludes the proof.

\bigbreak

    To prove that $\phi$ is continous in $E$ we start by noticing that $\log \phi$ is convex in $ \left( a,b \right) $ which implies convexity of $\phi$ in $ \left( a,b \right) $ which in turn implies continuity of $\phi$ in $ \left( a,b \right) $, so we only need to prove continuity on a and b, in case they are elements of $E$.

    Let $\{p_n\}$ be a sequence in $ \left( a,b \right) $ which converges to $a$ and let's suppose $a \in E$, we will show that $\phi \left( p_n \right) $ converges to $\phi \left( a \right) $, the proof for $b$ is analogous. By linearity of the integral and properties of the absolute value we get
    \[
        |\phi \left( p_n \right) - \phi \left( a \right) | = | \int_X |f^{p_n}| - |f^a|\: d\mu | \le \int_X ||f^{p_n}|-|f^a||\: d\mu \le \int_X |f^{p_n} - f^a|\: d\mu
    \]
    Also, by continuity of the exponential we know that $f^{p_n}$ converges pointwise to $f^a$ as $n$ goes to infinity so it sufices to find a real function $g \in L^1 \left( \mu \right) $ such that $|f^{p_n}| \le g$. Let $g=|f^a|+|f^{p_M}|$ with $p_M$ the greatest element of the sequence $\{p_n\}$ which exists given the convergence of the sequence. Then we can see that $a \le p_n \le p_M$ for all $1 \le n$ and as mentioned above we have
    \[
        |f|^{p_n} \le \max \{ |f|^a , |f|^{p_M}\} \le |f|^a + |f|^{p_M} = g
    \]
    Finally by Lebesgue's Dominated Convergence Theorem we get that
    \[
        \int_X |f^{p_n} - f^a|\: d\mu \rightarrow 0
    \]
    which concludes the proof of (b).

\bigbreak

\end{exercise}

\bigbreak

\begin{exercise}\textbf{Exercise 3.5.}
    In order to prove that $ \|f\|_p \le \|f\|_r$ if $0 < p < r \le \infty$ we start by looking at case in which both $p$ and $r$ are finite. For every $x \in \left( 0,\infty \right) $ the function $x^{c}$ is twice differentiable and we have that
    \[
        \left( x^c \right)'' = \left( x^{c-1}c \right) ' = c \left( c-1 \right) x^{c-2}
    \]
    Observe that if $1 \le c$, the expression above is nonnegative for all $x \in \left( 0,\infty \right)$ and thus $x^c$ convex over that interval. With this in mind and the fact that $\mu \left( \Omega \right) = 1$ and $1 \le \frac{r}{p}$ we will use Jensen's Inequality to prove the result. Let $A = \{x \in \Omega | f \left( x \right) \neq 0 \}$ (the integral over it's complement is exactly $0$ and in this way $|f| \left( A \right) \subset \left( 0,\infty \right)$), then
    \[
        \|f\|_p = \left( \int_A |f|^p\: d\mu  \right)^{\frac{r}{rp}} \le \left( \int_A |f|^{\frac{rp}{p}}\: d\mu  \right)^\frac{1}{r} = \|f\|_r
    \]
    and this concludes the proof for the finite case.

    Now let $r = \infty$, this case is much simpler. By definition of the essential supremum we have that $|f| \le \|f\|_\infty $ almost everywhere and using the fact that $\mu \left( \Omega \right) = 1$ we get,
    \[
        \|f\|_p = \left( \int_\Omega |f|^p\: d\mu  \right)^\frac{1}{p} \le \left( \int_\Omega \|f\|_\infty^p \: d\mu  \right) ^\frac{1}{p} = \|f\|_\infty
    \]

\end{exercise}

\bigbreak

\begin{exercise}\textbf{Exercise 3.7.}
    Let $0 < p < s < \infty$, an example for the inclusion $L^s \left(  \mu\right)  \subset L^p \left( \mu \right) $ can easily be constructed using \textbf{Ex.3.5}.

    Let $X = \left( 1, \infty \right) $ and $m$ the Lebesgue Measure, we see that neither of the inclusions hold. On the one hand, $\frac{1}{x} \notin L^1 \left( 1, \infty \right)$ and $\frac{1}{x} \in L^2 \left( 1, \infty \right) $. On the other hand, $\frac{I_{ \left( 1,2 \right) }}{ x-1} \notin L^1 \left( 1,\infty \right) $ and $\frac{I_{ \left( 1,2 \right) }}{x-1} \in L^{\frac{1}{2}} \left( 1,\infty \right) $ being $I_A$ the indicator function of $A$. We will only prove the first of these last two statements (the second one can be proved in a simlar manner chosing a convenient partition of $ \left( 1,2 \right) $),
    \[
        \int_{1}^{\infty}\frac{I_{ \left( 1,2 \right) }}{x-1} \: dx  = \int_{1}^{2} \frac{1}{x-1}\: dx = \sum_{n=0}^{\infty} \int_{1+\frac{1}{e^{n+1}}}^{1+\frac{1}{e^n}} \frac{1}{x-1}\: dx
    \]
    given that the antiderivative of $\frac{1}{x-1}$ is $\ln \left( x-1 \right) + C$ the expression above equals
    \[
        \sum_{n=0}^{\infty} \left [\ln \left( \frac{1}{e^n} \right)  - \ln \left( \frac{1}{e^{n+1}} \right) \right] = \sum_{n=0}^{\infty} \ln \left( e \right) = \infty
    \]

    For the remaining inclusion we take $X = \mathbb{N}$ with the Counting Measure over the power set of $\mathbb{N}$. Observe that all measurable functions in this case will be just sequences of complex numbers so if $f=\{a_n\}$ we have,
    \[
        \|f\|_p^p = \int_X |f|^p\: d\mu = \sum_{n=1}^{\infty} |a_n|^p
    \]
    Suppose $\{a_n\} \in \ell^p \left( \mathbb{N} \right)$ then the sequence $\{|a_n|^p\}$ converges to 0 and thus there exists a natural number $M$ such that $|a_n|^p < 1$ for all $M < n$. Given that $1 < \frac{s}{p}$ we have that $|a_n|^s = \left( |a_n|^p \right)^\frac{s}{p} < |a_n|^p$ for all $n$ greater than $M$ and with that in mind we get,
    \[
       \sum_{n=1}^{\infty} |a_n|^s = \sum_{n=1}^{M} |a_n|^s + \sum_{n=M+1}^{\infty} |a_n|^s < \sum_{n=1}^{M} |a_n|^s + \sum_{n=M+1}^{\infty} |a_n|^p < \infty
    \]
    As we wanted, $\{a_n\} \in \ell ^s \left( \mathbb{N} \right) $, which concludes the proof.
    Some conditions which imply inclusion can be found in the section of useful properties.
\end{exercise}

\bigbreak

\begin{exercise}$\textbf{Exercise 3.10.}$
Given that $fg\ge1$ and both $f$ and $g$ are positive we have $f \ge \frac{1}{g}$ and using Holder's inequality and the fact that $\mu\left(\Omega\right)=1$,

\[
    1 = \|1\|_1 = \|g^{\frac{1}{2}}g^{-\frac{1}{2}}\|_1 \le \|g^{\frac{1}{2}}\|_2 \|g^{-\frac{1}{2}}\|_2 =  \left( \|g\|_1 \|g^{-1}\|_1 \right) ^{\frac{1}{2}} \le \left(\|g\|_1 \|f\|_1 \right)^{\frac{1}{2}}
\]
thus,

\[
    1 \le \int_\Omega f\: d\mu \int_\Omega g\: d\mu
\]

\end{exercise}

\pagebreak

\begin{exercise}\textbf{Exercise 3.17.}
   We start by looking at the case in which $1 \le  p < \infty$, we want to see that
   \begin{equation}
       | \alpha - \beta |^p \le 2^{p-1} \left( |\alpha|^p + |\beta|^p \right)
   \end{equation}
   for every $\alpha$ and $\beta$ complex numbers not both zero (in that case the proof is tirivial). Let $X = [0,1]$ and $\mu$ be the Lebesgue Measure, we define the complex function $f$ over $[0,1]$ such that
   \[
       f \left( x \right) =
       \begin{cases}
           2\alpha & \text{if}\  0 \le x < \frac{1}{2} \\
           2\beta & \text{if}\  \frac{1}{2} \le x \le 1
       \end{cases}
   \]
   Rearrangin $ \left( 1 \right) $ we get,
   \begin{equation}
       |\alpha - \beta| \le \left( \frac{1}{2} | 2\alpha |^p + \frac{1}{2} | 2\beta | ^p \right) ^{\frac{1}{p}} = \|f\|_p
   \end{equation}
   Observing that $\mu \left( X \right) = 1$ and $0 < \|f\|_\infty $ by \textbf{Ex.3.5} we know that $\|f\|_1 $ \le $\|f\|_p $ and we have
   \begin{equation}
       |\alpha - \beta| \le |\alpha| + |\beta| = \|f\|_1 \le \|f\|_p
   \end{equation}
   which concludes the proof.

\end{exercise}

\bigbreak

\begin{exercise}\textbf{Exercise 3.18.}
    Let's start with statement \textbf{(a)}, for it we will assume that $\mu \left( X \right) < \infty $. Let $A$ be a set in which $\{f_n\}_{n \in \mathbb{N}}$ converges pointwise to $f$ and $\mu \left( X-A \right) = 0$ take $\epsilon > 0$. By Egorov's theorem there exists a set $B \subset A$ in which the sequence converges uniformly and $\mu \left( A-B \right)  < \epsilon$. By the uniform convergence of the sequence there exists $N \in \mathbb{N}$ such that
    \[
        |f_n \left( x \right) - f \left( x \right) | < \epsilon \qquad \forall\ x \in B\ \forall\ n > N
    \]
    Given that the set of all points which don't satify this condition for $n$ large enough is a subset of $X-B$ it's measure must be less than $\epsilon$ which proves that $\{f_n\}_{n \in \mathbb{N}}$ converges in measure to $f$ and concludes the proof.

    Now let's prove statement \textbf{(b)}, we won't need the assumption that $\mu \left( X \right) < \infty$ for this one. Assume that $\{f_n\}_{n \in \mathbb{N}}$ doesn't converge in measure to $f$, we start by looking at the case in which $0 \le p < \infty$. By our assumption, there exists $\epsilon > 0$ such that for every $N \in \mathbb{N}$ there exists an $n > N$ such that
    \begin{equation}
        \mu \left( \{ x \in X : |f_n \left( x \right) - f \left( x \right) | > \epsilon \} \right) \ge \epsilon
    \end{equation}
    Now let $E_{\epsilon, n}$ denote the set in (4), keeping notation as above we have
    \[
        \epsilon^{p+1} \le \int_{E_{\epsilon,n}} \epsilon^p \: d\mu \le \int_{E_{\epsilon,n}} |f_n-f|^p\: d\mu \le \int_X |f_n-f|^p\: d\mu
    \]
    and clearly $\|f_n-f\|_p $ doesn't converge to zero which is a contradiction and concludes the proof for $1 \le p < \infty$ (the case in which $p=\infty$ uses the same idea and won't we proven here). It calls my atention that we didn't need the fact that $f_n \in L^p \left( \mu \right) $ and makes me believe that there must be a mistake in the proof...

    It only remains to prove \textbf{(c)}, we won't need the assumption that $\mu \left( X \right) < \infty$. We start by taking a subsequence $\{f_{n_j}\}_{j \in \mathbb{N}}$ such that
    \begin{equation}
        \mu \left( E_{2^{-j}, n_j} \right) < 2^{-j}
    \end{equation}
\end{exercise}
    with $E_{\epsilon,n}$ defined as in (4). Observe that for every $\epsilon > 0$ and every $\delta > 0$ we can ask for a $m$ large enough such that,
    \begin{equation}
        \mu \left( A_m \right) := \mu \left( \bigcup_{j = m}^{\infty} E_{2^{-j},n_j }\right) \le \sum_{j=m}^{\infty} \mu \left( E_{2^{-j},n_j} \right) < \epsilon
    \end{equation}
    and
    \begin{equation}
        2^{-j} < \delta \qquad \forall j \ge m
    \end{equation}
    As defined in (6) we clearly have $A_{m+1} \subset A_m$. Now suposse that the sequence $\{f_{n_j}\}_{j \in \mathbb{N}}$ doesn't converge poitwise to any point in a set $B \subset X$ with $\mu \left( B \right) > 0$ we can ask for an m large enough such that (6) holds for $\epsilon = min\{1, \mu \left( B \right)\}$ (we can't just pick $\mu \left( B \right) $ as it could equal $\infty$). In that case $B$ won't be a subset of $A_m$ and we can ask for a point $x \in B - A_m$.

    Now take $\gamma > 0$ and $m' \ge m$ such that (7) holds for $\delta = \gamma$ then $x \in B-A_{m'}$  as $A_{m'} \subset A_m$. Given that if $|f_{n_j} \left( y \right) - f \left( y \right) | > 2^{-m'}$ for some $j \ge m'$ we have $ y \in A_{m'}$, as $x \notin A_{m'}$ it must be the case that for all $j \ge m'$
    \[
        |f_{n_j} \left( x \right) - f \left( x \right) | \le 2^{-m'} < \delta = \gamma
    \]
    and then we have that $f_{n_j} \left( x \right) \rightarrow f \left( x \right) $ which contradicts our assumption and concludes the proof.
\bigbreak

\begin{exercise}\textbf{Exercise 3.20.}
    Let $\alpha, \beta \in \mathbb{R}$ and $t \in [0,1]$ we define
    \[
        f \left( x \right) =
        \begin{cases}
            \alpha & \text{if}\ 0 \le x < t \\
            \beta & \text{if}\ t \le x \le 1
        \end{cases}
    \]
    which is clearly measurable and bounded. It only remains to replace $f$ in the given inequality to prove the convexity of $\phi$.
\end{exercise}

\bigbreak

\begin{exercise}\textbf{Exercise 3.23.}
    Let $\mu$ be a positive measure with $\mu \left( X \right) < \infty$ and $f$ a complex measurable function with $0 < \|f\|_\infty < \infty $ define the sequence
    \[
        a_n = \int_X |f|^n\: d\mu  = \|f\|_n^n
    \]
    By the given hypothesis we have that first, the hypothesis of \textbf{Ex.3.4.e} hold and second, $0 < a_n < \infty$ for every $ 1 \le n$ and thus the quotients $\frac{a_{n+1}}{a_n}$ are well defined and we have the inequality,
    \[
        \liminf_{n \to \infty} \frac{a_{n+1}}{a_n} \le \liminf_{n \to \infty}a_n^{\frac{1}{n}} \le \limsup_{n \to \infty} a_n^{\frac{1}{n}} \le \limsup_{n \to \infty} \frac{a_{n+1}}{a_n}
    \]
    Looking at \textbf{Ex.3.4.e} we see that is sufices to show that $\frac{a_{n+1}}{a_n}$ converges in $[0,\infty]$ because in that case both limits will exist and equal $\|f\|_\infty $ as $a_n^{\frac{1}{n}} = \|f\|_n$. In order to prove this, we will show that $\frac{a_{n+1}}{a_n}$ is a nondecreasing sequence.

    Observing that $0 < n < n+1 < n+2 < \infty$ and that $2 \left( n+1 \right) = n + \left( n+2 \right) $ we can use \textbf{Obs.3.1} and we get,
    \[
        \|f\|_{n+1}^{n+1} \le \sqrt{\|f\|_n^n \|f\|_{n+2}^{n+2}}
    \]
    rearranging the terms we get,
    \[
        \frac{a_{n+1}}{a_n} \le \frac{a_{n+2}}{a_{n+1}}
    \]
    which proves that the sequence $\frac{a_{n+1}}{a_n}$ is nondecreasing, as we wanted. This concludes the proof.
\end{exercise}

\section*{Useful Properties}

\begin{theorem}\textbf{Theorem 3.1 (Young's Inequality)}

    Let $a,b \in \mathbb{R}_{ \ge 0}$ and let $1 < q,p < \infty$ with $\frac{1}{p}+\frac{1}{q}=1$ we have
    \[
        ab \le \frac{a^q}{q} + \frac{b^p}{p}
    \]
    \textit{Proof.} If $a$ or $b$ equal $0$ the proof is trivial, so assume they don't. Taking $\ln$ on both sides we get
    \[
        \frac{\ln \left( a^q \right) }{q} + \frac{\ln \left( b^p \right) }{p} \le \ln \left( \frac{a^q}{q} + \frac{b^p}{p} \right)
    \]
    which given that $\frac{1}{p} + \frac{1}{q} = 1$ holds by the concavity of the logarith and concludes the proof.
\end{theorem}

\bigbreak

\begin{observation}\textbf{Observation 3.1}

Let $0 < r < p < s < +\infty$ with $p-r=s-p$ which is the same as $2p=r+s$ and let $f$ be a masurable function, using Holder's inequality we get,
\[
    \|f\|_p^p = \|f^p\|_1 = \|f^{\frac{r}{2}}f^{\frac{s}{2}}\|_1 \le \|f^{\frac{r}{2}}\|_2 \|f^{\frac{s}{2}}\|_2 = \left( \|f\|_r^r \|f\|_s^s   \right)^{\frac{1}{2}}
\]
thus,
\[
    \|f\|_p^p \le \sqrt{\|f\|_r^r \|f\|_s^s  }
\]
\end{observation}

\begin{observation}\textbf{Observation 3.2}
    Let $1 \le r < p < \infty$ and let $f$ be a measurable function, using Holder's inequality we get,
    \[
        \|f\|_r = \left( \|f^r\|_1  \right)^{\frac{1}{r}} \le \left( \|1\|_q \|f^r\|_ \frac{p}{r} \right)^\frac{1}{r} = \mu \left( X \right) ^\frac{1}{rq} \|f\|_p
    \]
    with $q = \left( 1 - \frac{r}{p} \right)^{-1}$

    Observe that if $\mu \left( X \right) < \infty$ we get that $L^p \left( \mu \right) \subset L^r \left( \mu \right) $.
\end{observation}

\bigbreak

\begin{theorem}\textbf{Teorem 3.2}
    Let $\phi : \left( a,b \right) \rightarrow \mathbb{R}$ be a convex function with $a,b \in [-\infty,\infty]$ then $\phi$ has lateral derivatives on every point in $ \left( a,b \right) $.

    \textit{Proof.} By convexity of $\phi$ for every $a < x < y < b$ and $a< z <b$  we have,
    \begin{equation}
        \frac{\phi \left( z \right) - \phi \left( x \right) }{z - x} \le \frac{\phi \left( z \right) - \phi \left( y \right) }{z - y}
    \end{equation}

    Let $c \in \left( a,b \right) $ define $f_c: \left( a,b \right) \rightarrow \mathbb{R}$ such that
    \[
    f_c \left( x \right) =
       \begin{cases}
           \frac{\phi(c)-\phi(x)}{c-x} & \text{if}\  c \neq x \\
           0 & \text{if}\ c = x
       \end{cases}
    \]
    by \textbf{(8)} we have that $f_c$ is nondecreasing in $ \left( a,c \right) $ and in $ \left( c,b \right) $. With this in mind we can see that the lateral limits of $f_c$ exists in c and equal
    \[
        \lim_{x \to c^-}f_c \left( x \right) = \phi_{-}' \left( c \right) = \sup_{a < x < c}\frac{\phi(c)-\phi(x)}{c-x}
    \]
    \[
        \lim_{x \to c^+}f_c \left( x \right) = \phi_{+}' \left( c \right)  = \inf_{c < x < b}\frac{\phi(c)-\phi(x)}{c-x}
    \]
    This concludes the proof.
\end{theorem}

\bigbreak

\begin{corollary}\textbf{Corollary}

    Let $\phi: \left( a,b \right) \rightarrow \mathbb{R}$ with $a,b \in [-\infty, \infty]$ a convex function then $\phi$ is continous over \left( a,b \right) .

\end{corollary}

\end{document}