% Vector variables (in Bold Font style)
\newcommand{\va}{\mathbf{a}} \newcommand{\vb}{\mathbf{b}} \newcommand{\vc}{\mathbf{c}} \newcommand{\vd}{\mathbf{d}} \newcommand{\ve}{\mathbf{e}} \newcommand{\vf}{\mathbf{f}} \newcommand{\vg}{\mathbf{g}} \newcommand{\vh}{\mathbf{h}} \newcommand{\vi}{\mathbf{i}} \newcommand{\vj}{\mathbf{j}} \newcommand{\vk}{\mathbf{k}} \newcommand{\vl}{\mathbf{l}} \newcommand{\vm}{\mathbf{m}} \newcommand{\vn}{\mathbf{n}} \newcommand{\vo}{\mathbf{o}} \newcommand{\vp}{\mathbf{p}} \newcommand{\vq}{\mathbf{q}} \newcommand{\vr}{\mathbf{r}} \newcommand{\vs}{\mathbf{s}} \newcommand{\vt}{\mathbf{t}} \newcommand{\vu}{\mathbf{u}} \newcommand{\vv}{\mathbf{v}} \newcommand{\vw}{\mathbf{w}} \newcommand{\vx}{\mathbf{x}} \newcommand{\vy}{\mathbf{y}} \newcommand{\vz}{\mathbf{z}}
\newcommand{\vA}{\mathbf{A}} \newcommand{\vB}{\mathbf{B}} \newcommand{\vC}{\mathbf{C}} \newcommand{\vD}{\mathbf{D}} \newcommand{\vE}{\mathbf{E}} \newcommand{\vF}{\mathbf{F}} \newcommand{\vG}{\mathbf{G}} \newcommand{\vH}{\mathbf{H}} \newcommand{\vI}{\mathbf{I}} \newcommand{\vJ}{\mathbf{J}} \newcommand{\vK}{\mathbf{K}} \newcommand{\vL}{\mathbf{L}} \newcommand{\vM}{\mathbf{M}} \newcommand{\vN}{\mathbf{N}} \newcommand{\vO}{\mathbf{O}} \newcommand{\vP}{\mathbf{P}} \newcommand{\vQ}{\mathbf{Q}} \newcommand{\vR}{\mathbf{R}} \newcommand{\vS}{\mathbf{S}} \newcommand{\vT}{\mathbf{T}} \newcommand{\vU}{\mathbf{U}} \newcommand{\vV}{\mathbf{V}} \newcommand{\vW}{\mathbf{W}} \newcommand{\vX}{\mathbf{X}} \newcommand{\vY}{\mathbf{Y}} \newcommand{\vZ}{\mathbf{Z}}
% Greek Vector variables (in Bold Font style)
\newcommand{\vbeta}{\bm{\beta}}
\newcommand{\vbhat}{\bm{\hat \beta}}
\newcommand{\vbstar}{\bm{\beta^*}}
\newcommand{\veps}{\bm{\epsilon}}
\newcommand{\vmu}{\bm{\mu}}
\newcommand{\vtheta}{\bm{\theta}}
\newcommand{\valpha}{\bm{\alpha}}
\newcommand{\vdelta}{\bm{\delta}}

% Constant vectors
\newcommand{\vzero}{\mathbf{0}}
\newcommand{\vone}{\mathbf{1}}
\newcommand{\thetac}{\mathrm{\theta^{(0)}}}

% Scalars

% Matrix variables (in DS style where possible)
\newcommand{\mA}{\mathds{A}} \newcommand{\mB}{\mathds{B}} \newcommand{\mC}{\mathds{C}} \newcommand{\mD}{\mathds{D}} \newcommand{\mE}{\mathds{E}} \newcommand{\mF}{\mathds{F}} \newcommand{\mG}{\mathds{G}} \newcommand{\mH}{\mathds{H}} \newcommand{\mI}{\mathds{I}} \newcommand{\mJ}{\mathds{J}} \newcommand{\mK}{\mathds{K}} \newcommand{\mL}{\mathds{L}} \newcommand{\mM}{\mathds{M}} \newcommand{\mN}{\mathds{N}} \newcommand{\mO}{\mathds{O}} \newcommand{\mP}{\mathds{P}} \newcommand{\mQ}{\mathds{Q}} \newcommand{\mR}{\mathds{R}} \newcommand{\mS}{\mathds{S}} \newcommand{\mT}{\mathds{T}} \newcommand{\mU}{\mathds{U}} \newcommand{\mV}{\mathds{V}} \newcommand{\mW}{\mathds{W}} \newcommand{\mX}{\mathds{X}} \newcommand{\mY}{\mathds{Y}} \newcommand{\mZ}{\mathds{Z}}

\newcommand{\cA}{\mathcal{A}} \newcommand{\cB}{\mathcal{B}} \newcommand{\cC}{\mathcal{C}} \newcommand{\cD}{\mathcal{D}} \newcommand{\cE}{\mathcal{E}} \newcommand{\cF}{\mathcal{F}} \newcommand{\cG}{\mathcal{G}} \newcommand{\cH}{\mathcal{H}} \newcommand{\cI}{\mathcal{I}} \newcommand{\cJ}{\mathcal{J}} \newcommand{\cK}{\mathcal{K}} \newcommand{\cL}{\mathcal{L}} \newcommand{\cM}{\mathcal{M}} \newcommand{\cN}{\mathcal{N}} \newcommand{\cO}{\mathcal{O}} \newcommand{\cP}{\mathcal{P}} \newcommand{\cQ}{\mathcal{Q}} \newcommand{\cR}{\mathcal{R}} \newcommand{\cS}{\mathcal{S}} \newcommand{\cT}{\mathcal{T}} \newcommand{\cU}{\mathcal{U}} \newcommand{\cV}{\mathcal{V}} \newcommand{\cW}{\mathcal{W}} \newcommand{\cX}{\mathcal{X}} \newcommand{\cY}{\mathcal{Y}} \newcommand{\cZ}{\mathcal{Z}}

\newcommand{\ewise}[2]{{#1 * #2}} % element-wise product

\newcommand{\EE}{\mathrm{E}} % Expectation

\newcommand{\g}{\,\vert\,} % for conditional probability, division

\subsection {A fully connected FFNN} \label {sec: fcffnn}
Forward propagation
\begin {equation} \begin {split}
& \text {Initialize the input layer } \vZ^1 = \vX, \vA^1 = \vZ^1 \\
& \text {Propagate all activity forward } \vZ^l = \mW^l \vA^{l-1} + \vB^l, \vA^l = f^l(\vZ^l) \\
\end {split} \end {equation}

$\vZ^l = \mW^l \vA^{l-1} + \vB^l$ is equivalent to
\begin{equation} \label {eq: nnwts}
\begin{bmatrix}
Z_1 \\
\ldots \\
Z_J \\
\end{bmatrix}
=
\begin{bmatrix}
W_{1,1} & \ldots & W_{1,K} \\
\ldots & \ldots & \ldots \\
W_{J,1} & \ldots & W_{J,K} \\
\end{bmatrix}
\begin{bmatrix}
A_1 \\
\ldots \\
A_K \\
\end{bmatrix}
+
\begin{bmatrix}
B_1 \\
\ldots \\
B_J \\
\end{bmatrix}
\end{equation}
Where layer $l$ has $J$ nodes and layer $l-1$ has $K$ nodes.

Backward propagation
\begin {equation} \begin {split}
& \text {Assuming that the loss function is } \cL = 0.5 (\vY - \vA^l)^2 \\
& \qquad \text {Where $\vY$ is the known output corresponding to the input $\vX$} \\
& \qquad \text {Calculate the final error } \nabla_a \cL =  \vA^l - \vY \\
& \text {Initialize  the back propagation } \vdelta^L =  \ewise {\nabla_a \cL} {{f^L}^{'} (\vZ^L)} \\
& \text {Backpropagate the error } \vdelta^l =  \ewise {\left[ {\mW^{l+1}}^T \vdelta^{l+1} \right]} {{f^{l}}^{'} (\vZ^l)}, l \in [2, L-1] \\
& \text {Calculate the gradient of weights } \frac {\partial \cL} {\partial \mW^l} = \vdelta^l {\vA^{l-1}}^T, l \in [2, L] \\
& \qquad \text {Equivalently } \frac {\partial \cL} {\partial W_{j,k}^l} = a_k^{l-1} \delta_j^l, l \in [2, L] \\
& \text {Calculate the gradient of bias weights } \frac {\partial \cL} {\partial \vB^l} = \vdelta^l, l \in [2, L] \\
& \qquad \text {Equivalently } \frac {\partial \cL} {\partial B_j^l} = \delta_j^l, l \in [2, L] \\
\end {split} \end {equation}

Update ($\eta$ is a hyperparameter that is not learned by the FFNN)
\begin {equation} \begin {split}
& \text {Update weights } \mW^l = \mW^l - \eta \frac {\partial \cL} {\partial \mW^l}, l \in [2, L] \\
& \text {Update bias weights } \vB^l = \vB^l - \eta \frac {\partial \cL} {\partial \vB^l}, l \in [2, L] \\
\end {split} \end {equation}

\subsection{Recurrent neural networks}
Recurrent neural networks (RNN) can be used as classification models for time series data.
\begin{align*}
&s_{t} = f_1(W^{s,s}s_{t-1}+W^{s,x}x_ t),\quad t=1,2,...,T\\
&y=f_2(W^{s,y} s_ T + W_0)
\end{align*}


\documentclass{article}
\usepackage{mymacro}
\usepackage{longtable,booktabs}
\usepackage[a4paper, margin=.7in]{geometry}
\usepackage{blindtext}

\def\tbs{\textbackslash}

\begin{document}

\section{Symbols}

Mainly based on physics package

\begin{center}
\begin{table}[htp]
    \begin{tabular}{|p{3cm}||l|l|p{6cm}|}
    \toprule
    Macro                     & Usage                            & Effect                   & Comments \\
    \midrule \midrule
    \tbs quantity             & \tbs qty(\tbs frac\{b\}\{a\})    & $\qty(\frac{b}{a})$      & Automatic bracing: (), [], \{\}, $\vert\vert$
    \\ \hline
                              & \tbs pqty\{a\}                   & $\pqty{a}$               & \tbs pqty: (); \tbs bqty: []; \tbs vqty: $\abs{}$; \tbs Bqty: \{\}
    \\ \hline \hline
    \textbf{Bracing}          &                                  &                          & * for no resize, manual bracing: \tbs big, \tbs Big, \tbs bigg, \tbs Bigg
    \\ \hline
    \tbs absolutevalue        & \tbs abs\{a\}                    & $\abs{a}$                & Absoluevalue
    \\ \hline
    \tbs norm                 & \tbs norm\{a\}                   & $\norm{a}$               & Norm
    \\ \hline
    \tbs opnorm               & \tbs opnorm\{a\}                 & $\opnorm{a}$             & Operator norm
    \\ \hline
    \tbs evaluated            & \tbs eval\{a\}\_0\^{}1           & $\eval{a}_0^1$           & Evaluation, also \tbs eval(a$\vert$ \_0\^{}1; \tbs eval[a$\vert$ \_0\^{}1
    \\ \hline
    \tbs order                & \tbs order\{a\}                  & $\order{a}$              & Order
    \\ \hline
    \tbs commutator           & \tbs comm\{a\}\{b\}              & $\comm{a}{b}$            & Commutator
    \\ \hline
    \tbs anticommutator       & \tbs acomm\{a\}\{b\}             & $\acomm{a}{b}$           & Anti-commutator
    \\ \hline
    \tbs poissonbracket       & \tbs pb\{a\}\{b\}                & $\pb{a}{b}$              & Poison bracket
    \\ \hline \hline
    \end{tabular}
    \begin{tabular}{|p{3cm}||l|l|p{6cm}|}
    \toprule
    \textbf{Vector}           &                                  &                          &
    \\ \hline
    \tbs vectorbold           & \tbs vb\{a\}                     & $\vb{a}$                 & Vector as bold (no Greek), * for italic and Greek
    \\ \hline
    \tbs vectorarrow          & \tbs va\{a\}                     & $\va{a}$                 & Vector with arrow (no Greek), * for italic and Greek
    \\ \hline
    \tbs vectorunit           & \tbs vu\{a\}                     & $\vu{a}$                 & With hat (no Greek), * for italic and Greek
    \\ \hline
    \tbs dotproduct           & \tbs vdot                        & $\vdot$                  & Dot product (bold cdot)
    \\ \hline
    \tbs crossproduct         & \tbs cross                       & $\cross$                 & or \tbs cp
    \\ \hline
    \tbs gradient             & \tbs grad\{a\}                   & $\grad{a}$               & Also valid for (), []. with \textit{arrowdel} command, it's changed to vector mode
    \\ \hline
    \tbs divergence           & \tbs div\{a\}                    & $\div{a}$                & Also valid for (), [].
    \\ \hline
    \tbs laplacian            & \tbs laplacian\{a\}              & $\laplacian{a}$          & Also valid for (), [].
    \\ \hline \hline
    \end{tabular}
\end{table}
\end{center}
\begin{longtable}{l||l|l|p{6cm}}
\textbf{Derivatives}      &                                  &                          &
\\ \hline
\tbs differential         & \tbs dd\{a\}                     & $\dd{a}$                 & Differential symbol; also valid for ()
\\ \hline
                          & \tbs dd[3]\{a\}                  & $\dd[3]{a}$              & Power
\\ \hline
\tbs variation            & \tbs var[3]\{a\}                 & $\var[3]{a}$             & Variation of functional; works as \tbs dd.
\\ \hline
\tbs derivative           & \tbs dv[2]\{a\}                  & $\dv[2]{a}$              & Derivative, powers available with []
\\ \hline
                          & \tbs dv\{f\}\{a\}                & $\dv{f}{a}$              & Two arguments
\\ \hline
                          & \tbs dv\{a\}(f)                  & $\dv{a}(f)$              & Low form
\\ \hline
                          & \tbs dv*\{f\}\{a\}               & $\dv*{f}{a}$             & Inline form
\\ \hline
\tbs partialderivative    & \tbs pdv\{f\}\{a\}               & $\pdv{f}{a}$             & Partial derivative. same to \tbs dv.
\\ \hline
                          & \tbs pdv\{f\}\{x\}\{y\}          & $\pdv{f}{x}{y}$          & Can take two variables
\\ \hline
\tbs functionalderivative & \tbs fdv\{F\}\{g\}               & $\fdv{F}{g}$             & Functional derivative; works as \tbs dv
\\ \hline \hline
\textbf{Dirac notation}   &                                  &                          & * for no resize
\\ \hline
\tbs ket                  & \tbs ket\{a\}                    & $\ket{a}$                & Ket
\\ \hline
\tbs bra                  & \tbs bra\{a\}                    & $\bra{a}$                & Bra
\\ \hline
                          & \tbs bra\{a\}\tbs ket\{b\}       & $\bra{a}\ket{b}$         & Auto contraction
\\ \hline
\tbs innerproduct         & \tbs braket\{a\}\{b\}            & $\braket{a}{b}$          & Braket. Also \tbs ip
\\ \hline
                          & \tbs braket\{a\}                 & $\braket{a}$             & Norm
\\ \hline
\tbs outerproduct         & \tbs ketbra\{a\}\{b\}            & $\ketbra{a}{b}$          & Outer, also \tbs op or \tbs dyad
\\ \hline
\tbs expectationvalue     & \tbs expval\{A\}                 & $\expval{A}$             & Expectation value (implicit), also \tbs ev. (Resize doesn't include A, ** to include)
\\ \hline
                          & \tbs expval\{A\}\{n\}            & $\expval{A}{n}$          & Expectation value (explicit)
\\ \hline
\tbs matrixelement        & \tbs mel\{n\}\{A\}\{m\}          & $\mel{n}{A}{m}$          & Matrix element, also \tbs matrixel. (Resize doesn't include A, ** to include)
\\ \hline \hline
\textbf{Matrix}           &                                  &                          &
\\ \hline
\tbs matrixquantity       & \tbs mqty\{a\& b\tbs \tbs c\& d\}& $\begin{matrix}\mqty{a&b\\c&d}\end{matrix}$        & Matrix, can be grouped as elements in larger matrix. Also works with (), *(), [], $\norm{}$. \tbs pmqty: (); \tbs Pmqty:* (); \tbs bmqty: []; \tbs vmqty: $\norm{}$
\\ \hline
\tbs smallmatrixquantity  & \tbs smqty\{a\& b\tbs \tbs c\& d\}& $\begin{matrix}\smqty{a&b\\c&d}\end{matrix}$       & Small matrix, same as above
\\ \hline
\tbs matrixdeterminant    & \tbs mdet\{a\}                   & $\begin{matrix}\mdet{a}\end{matrix}$               & Determinant;
\\ \hline
                          & \tbs smdet\{a\}                  & $\begin{matrix}\smdet{a}\end{matrix}$              & Determinant, small version
\\ \hline
\tbs identitymatrix       & \tbs imat\{3\}                   & $\begin{matrix}\smqty(\imat{3})\end{matrix}$       & Identity Matrix
\\ \hline
\tbs xmatrix              & \tbs xmat\{x\}\{2\}\{3\}         & $\begin{matrix}\smqty{\xmat{x}{2}{3}}\end{matrix}$  & Matrix filled with $x$
\\ \hline
                          & \tbs xmat*\{a\}\{2\}\{3\}        & $\begin{matrix}\smqty{\xmat*{x}{2}{3}}\end{matrix}$ & * assign indices to elements
\\ \hline
\tbs zeromatrix           & \tbs zmat\{2\}\{3\}              & $\begin{matrix}\smqty{\zmat{2}{3}}\end{matrix}$    & Zero matrix
\\ \hline
\tbs paulimatrix          & \tbs pmat\{1\}                   & $\begin{matrix}\smqty{\pmat{1}}\end{matrix}$       & Pauli [0, 1, 2, 3] matrix
\\ \hline
\tbs diagonalmatrix       & \tbs dmat\{a, b\}                & $\begin{matrix}\smqty{\dmat{a,b}}\end{matrix}$     & Diagonal matrix, up to 8 elements, add [0] option to fill with 0. matrix can be inputted as entries as well.
\\ \hline
\tbs antidiagonalmatrix   & \tbs admat\{a,b\}                & $\begin{matrix}\smqty{\admat{a,b}}\end{matrix}$    & Anti-diagonal matrix, as above.
\\ \hline \hline
\textbf{Text in math mode}&                                  &                           & Insert text in math mode, including spacing. Special macros see table~\ref{tab:text}.
\\ \hline
\tbs qqtext               & 1 \tbs qq\{word\} 2              & $1\qq{word}2$             & with *, only include spacing at the end.
\end{longtable}

\begin{table}[hpb]
    \caption{Text in math mode}\label{tab:text}
    \centering
    \begin{tabular}{llll}
    \tbs qcc & \tbs qif & \tbs qthen & \tbs qotherwise \\
    \tbs qunless & \tbs qgiven & \tbs qusing & \tbs qassume \\
    \tbs qsince & \tbs qlet & \tbs qfor & \tbs qall \\
    \tbs qeven & \tbs qinteger & \tbs qand & \tbs qor \\
    \tbs qas & \tbs qin
    \end{tabular}
    \begin{tabular}{|llll}
    $1\qcc1$ & $1\qif1$ & $1\qthen1$ & $1\qotherwise1$ \\
    $1\qunless1$ & $1\qgiven1$ & $1\qusing1$ & $1\qassume1$ \\
    $1\qsince1$ & $1\qlet1$ & $1\qfor1$ & $1\qall1$ \\
    $1\qeven1$ & $1\qinteger1$ & $1\qand1$ & $1\qor1$ \\
    $1\qas1$ & $1\qin1$
    \end{tabular}
\end{table}

Other special functions:

The functions in Tab.~\ref{tab:func} can be used as \tbs sin[2](x):
$\sin[2](x)$, which handles the sizing and powers.
\begin{table}[hpb]
    \caption{Functions}\label{tab:func}
\centering
\begin{tabular}{llll}
\tbs sin & \tbs sinh & \tbs arcsin & \tbs asin \\
\tbs cos & \tbs cosh & \tbs arccos & \tbs acos \\
\tbs tan & \tbs tanh & \tbs arctan & \tbs atan \\
\tbs csc & \tbs csch & \tbs arccsc & \tbs acsc \\
\tbs sec & \tbs sech & \tbs arcsec & \tbs asec \\
\tbs cot & \tbs coth & \tbs arccot & \tbs acot \\
\tbs log & \tbs ln
\end{tabular}
\begin{tabular}{|llll}
$\sin$ & $\sinh$ & $\arcsin$ & $\asin$ \\
$\cos$ & $\cosh$ & $\arccos$ & $\acos$ \\
$\tan$ & $\tanh$ & $\arctan$ & $\atan$ \\
$\csc$ & $\csch$ & $\arccsc$ & $\acsc$ \\
$\sec$ & $\sech$ & $\arcsec$ & $\asec$ \\
$\cot$ & $\coth$ & $\arccot$ & $\acot$ \\
$\log$ &$ \ln$
\end{tabular}
\end{table}

The functions in Tab.~\ref{tab:limit} can be used as \tbs max[2]\{x\}:
$\max[2]{x}$, which handles the sizing and subscript (traditional typeset \tbs
max\_2 is still available).
In display mode, it is
$$\max[2]{x}$$
\begin{table}[htp]
    \caption{Limits}\label{tab:limit}
\centering
\begin{tabular}{lll}
\tbs max & \tbs min & \tbs lim \\
\tbs sup & \tbs inf & \tbs argmin \\
\tbs argmax
\end{tabular}
\begin{tabular}{|lll}
$\max$ & $\min$ & $\lim$ \\
$\sup$ & $\inf$ & $\argmin$ \\
$\argmax$
\end{tabular}
\end{table}

\pagebreak
The functions in Tab.~\ref{tab:ftext} can be used with automatic sizing of [],
(), and \{\}:
\begin{table}[htp]
    \caption{Function as text}\label{tab:ftext}
\centering
\begin{tabular}{lll}
\tbs exp    & \tbs det  & \tbs Pr \\
\tbs tr     & \tbs Tr   & \tbs Res\\
\end{tabular}
\begin{tabular}{|lll}
$\exp$      & $\det $   & $\Pr$     \\
$\tr$       & $\Tr$     & $\Res$    \\
\end{tabular}
\end{table}

Following functions can be used with conditions:
\begin{table}[htp]
    \caption{Conditional}\label{tab:cond}
\centering
\begin{tabular}{lll}
\tbs ave[a]\{b\}\{c\} & \tbs prob\{a\}\{b\} \\
\tbs entro\{a\}\{b\}  & \tbs KLdiv\{a\}\{b\}\\
\end{tabular}
\begin{tabular}{|lll}
$\displaystyle\ave[a]{b}{c}$  & $\prob{a}{b} $ \\
$\entro{a}{b} $               & $\KLdiv{a}{b} $\\
\end{tabular}
\end{table}

Following functions are provided as plain text:
\begin{table}[hpb]
\centering
\begin{tabular}{lll}
\tbs rank & \tbs erf & \tbs ker \\
\tbs deg  & \tbs gcd & \tbs hom
\end{tabular}
\begin{tabular}{|lll}
$\rank$ & $\erf$ & $\ker$ \\
$\deg$ & $\gcd$ & $\hom$
\end{tabular}
\end{table}

The following symbols are defined\linebreak[0]
\begin{table}[!hpb]
    \caption{Symbols}\label{tab:sym}
\centering
\begin{tabular}{llll}
\tbs ell & \tbs binary & \tbs complex & \tbs integer \\
\tbs real & \tbs natural & \tbs hilb  &
\end{tabular}
\begin{tabular}{|llll}
$\ell$ & $\binary$ & $\complex$ & $\integer$\\
$\real$ & $\natural$ & $\hilb$ &
\end{tabular}
\end{table}

Also, some special operators are provided:

\tbs principalvalue or \tbs pv\{f\}: $\pv{f}$, \tbs PV\{f\}: $\PV{f}$, \tbs Re:
$\Re{z}$, \tbs Im: $\Im{z}$.

\section{Marks and Colors}

Several shortcut for colors are provided with the \emph{xcolor} package:

\red{\tbs red}, \blue{\tbs blue}, \green{\tbs green}

Also the hyperrefs are colored:

\begin{enumerate}
    \item In document ref: \hyperref[dummylabel]{dummy target}\label{dummylabel}
    \item cite: \cite{dummy}
    \item url: \url{www.dummyurl}
\end{enumerate}

The marks are provided by the \emph{soul} package
\begin{enumerate}
    \item \tbs so: \so{space out}
    \item \tbs ul: \ul{underline}
    \item \tbs st: \st{striking out}
    \item \tbs hl: \hl{highlight}
\end{enumerate}

\blindtext

\begin{thebibliography}{1}
    \bibitem{dummy} dummy citation
\end{thebibliography}

\end{document}


%
% revise the whole content at Aug 10th, 2009
%
%
%

\chapter{More discussion on operator}
%
% this chapter used to describe more on the
% momentum operator and coordinate Operator; they are the foundations
% to build more complicated operators, so we also give some
% mathematical discussion to them. so that in the future, we can
% use them to derive more properties for the given operator
%
\section{Momentum operator and position operator}
%
%
%
In the above content, we have rigorously introduced the momentum
operator and position operator. Now we are going to give further
discussions for them.

As a kind of vector operator, the momentum operator and position
operator can be defined as:
\begin{eqnarray}
% \nonumber to remove numbering (before each equation)
  \mathbf{\hat{r}} &=& \hat{x}\overrightarrow{i} + \hat{y}\overrightarrow{j} + \hat{z}\overrightarrow{k} \nonumber \\
  \mathbf{\hat{p}} &=& \hat{p}_{x}\overrightarrow{i} + \hat{p}_{y}\overrightarrow{j} + \hat{p}_{z}\overrightarrow{k}
\end{eqnarray}

For the $\hat{x}, \hat{y}, \hat{z}$; in the position representation
according to the analysis in
(\ref{sec:PRAMR_in_position_representation}) we can simply express
them as:
\begin{align}\label{OPERATORMOREeq:14}
\hat{x} &= x \nonumber \\
\hat{y} &= y \nonumber \\
\hat{z} &= z
\end{align}

Accordingly, the x, y, z directions of the component for the
momentum operator $\hei{p}$ is defined as:
\begin{align}\label{OPERATORMOREeq:13}
\hat{P}_{x} &= -i\hbar\frac{\partial}{\partial x}   \nonumber \\
\hat{P}_{y} &= -i\hbar\frac{\partial}{\partial y}   \nonumber \\
\hat{P}_{z} &= -i\hbar\frac{\partial}{\partial z}
\end{align}

As for the commutation relationship, it's defined in the axiom
\ref{axiom5} and read as:
\begin{equation}\label{OPERATORMOREeq:12}
[\hat{x}_{i}, \hat{x}_{j}] = 0 \quad [\hat{P}_{i}, \hat{P}_{j}] = 0
\quad [\hat{x}_{i}, \hat{P}_{j}] = i\hbar\delta_{ij}
\end{equation}

However, we can also get this expression from
(\ref{OPERATORMOREeq:13}) and (\ref{OPERATORMOREeq:14}). For an
arbitrary $\Psi(x)$ we can see that:
\begin{eqnarray}
% \nonumber to remove numbering (before each equation)
  x\hat{P}_{x}\Psi(x) &=& -i\hbar x\frac{\partial\Psi(x)}{\partial x} \nonumber \\
  \hat{P}_{x}x\Psi(x) &=& -i\hbar\frac{\partial}{\partial x}(\Psi(x) x) \nonumber \\
                   &=& -i\hbar x\frac{\partial\Psi(x)}{\partial x}
                   -i\hbar\Psi(x)
\end{eqnarray}
Therefore we have:
\begin{equation}\label{}
[\hat{x}, \hat{P}_{x}]\Psi(x) = i\hbar\Psi(x) \rightarrow [\hat{x},
\hat{P}_{x}] = i\hbar
\end{equation}

Now let's introduce an operator $\hat{R}$, which is defined as:
\begin{equation}\label{}
\hat{R}^{2} = \hei{r}^{2} = x^{2} + y^{2} + z^{2} \Rightarrow
\hat{R} = \sqrt{x^{2} + y^{2} + z^{2}}
\end{equation}
The real Hamiltonian always refers to this scalar operator of
$\hat{R}$ rather than the $\hei{r}$.

On the other hand, we also use the inverse operator of $\hat{R}$
(represented by $\hat{R}^{-1}$):
\begin{equation}\label{}
\hat{R}^{-1} = \frac{1}{\sqrt{x^{2} + y^{2} + z^{2}}}
\end{equation}

In quantum chemistry, for an ordinary molecule system its
Hamiltonian only contains the kinetic operator of $\hat{T}$ and
$\hat{R}^{-1}$ (for the electrons and nuclear-electron terms); this
is clearly shown in (\ref{BASICeq:4}).

By the way, both of $\hei{p}$ and $\hei{r}$ are hermitian operators.
Specifically, in the position representation we have:
\begin{align}\label{OPERATORMOREeq:1}
\bra{\psi}\hei{r}\ket{\phi} &= \int\psi^{*}\bm{r}\phi d\tau   \nonumber \\
&= \int\bm{r}\psi^{*}\phi d\tau   \nonumber \\
&= \left\{\int\bm{r}\phi^{*}\psi d\tau \right \}^{*}   \nonumber \\
&= \bra{\phi}\hei{r}\ket{\psi}^{*}
\end{align}

What's more, it's natural to see that any function that only related
to the $\hei{r}$ or ($\hat{x}, \hat{y}, \hat{z}$) is the hermite
operator. Consequently, the potential operator of $\hat{V}(r)$ (for
example, the $\hat{R}$ and $\hat{R}^{-1}$)in the Hamiltonian
operator is hermite, since the momentum operator is hermitian, then
according to (\ref{hermitian_in_operator}) the kinetic operator
$\hat{T} = \frac{\hei{p}^{2}}{2m}$ is also hermitian; so the
Hamiltonian operator ($\hat{H} = \hat{T} + \hat{V}(r)$) itself is
hermitian.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{More discussion on the algorithm of operator}
%
% only directly give more relations to the algorithm of operator
% see below
%
%
%
The introduction to the momentum operator and position operator here
can be wound up for a while, now let's go to present more algorithms
on operators.

The dot product and the cross product for the vector operators are
defined as:
\begin{equation}\label{OPERATORMOREeq:2}
\hei{A}\cdot\hei{B} = \hat{A}_{x}\hat{B}_{x} +
\hat{A}_{y}\hat{B}_{y} + \hat{A}_{z}\hat{B}_{z}
\end{equation}
\begin{equation} \label{OPERATORMOREeq:3}
\hei{A}\times\hei{B} = \left\{ \begin{aligned}
         (\hei{A}\times\hei{B})_{x} &= \hat{A}_{y}\hat{B}_{z} -  \hat{A}_{z}\hat{B}_{y} \nonumber \\
         (\hei{A}\times\hei{B})_{y} &= \hat{A}_{z}\hat{B}_{x} -  \hat{A}_{x}\hat{B}_{z} \nonumber \\
         (\hei{A}\times\hei{B})_{z} &= \hat{A}_{x}\hat{B}_{y} -  \hat{A}_{y}\hat{B}_{x}
                          \end{aligned} \right.
\end{equation}

Here we can see that the cross product between operators are similar
to the case in classical mechanics.

The power for the operators is defined as:
\begin{equation}\label{}
\hat{A}^{n} = \underbrace{\hat{A}\cdot\hat{A}\cdots\hat{A}}_{n}
\end{equation}
Here we note that the definition of $\hat{R}^{2} = \hei{r}^{2}$ is
the dot product between $\hei{r}$, also the kinetic operator is
related to $\hat{P}^{2}$:
\begin{equation}\label{}
\frac{1}{2}\frac{\hat{P}^{2}}{2m} = \frac{\hbar^{2}}{2m}\left(
\frac{\partial^{2}}{\partial x^{2}} + \frac{\partial^{2}}{\partial
y^{2}} + \frac{\partial^{2}}{\partial z^{2}}  \right)
\end{equation}

Then we are going to focus on the commutative relationship, it's
easy to prove that for any of the arbitrary operators, the
expression below are correct(only use the definition of the
commutation):
\begin{align}\label{OPERATORMOREeq:4}
[\hat{A}, \hat{B}] &= -[\hat{B}, \hat{A}] \nonumber \\
[\hat{A}, \hat{A}] &= 0  \nonumber \\
[\hat{A}, \hat{B} \pm \hat{C}] &= [\hat{A}, \hat{B}] \pm  [\hat{A},
  \hat{C}] \nonumber \\
[\hat{A}, \hat{B}\hat{C}] &= \hat{B}[\hat{A}, \hat{C}] + [\hat{A},
  \hat{B}]\hat{C} \nonumber \\
[\hat{A}\hat{B}, \hat{C}] &= \hat{A}[\hat{B}, \hat{C}] + [\hat{A},
  \hat{C}]\hat{B} \nonumber \\
[\hat{A}, \hei{B}\cdot\hei{C}] &= [\hat{A}, \hei{B}]\cdot\hei{C} +
\hei{B}\cdot
  [\hat{A}, \hei{C}] \nonumber \\
[\hat{A}, \hei{B}\times\hei{C}] &= [\hat{A}, \hei{B}]\times\hei{C} +
\hei{B}\times
  [\hat{A}, \hei{C}]
\end{align}
These rules may be very useful when evaluating the characters of
some particular operator.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Commutation relationship between $\hei{r}$ and $\hei{p}$}
%
% derive some important commutation relationship for the
% p and r so that in the future we can use them to prove
% more properties for the composite operators
%
%
Commutation is a kind of important subject in quantum mechanics.
Here in this section we focus on some commutation relationship
between $\hei{r}$ and $\hei{p}$, which is very useful in proving the
commutation relationship for composite operators. Here below for
convenience, the vector operator is expressed as:
\begin{equation}\label{}
\hei{A} = \sum_{i=1}^{3}\overrightarrow{e}_{i}\hat{A}_{i} =
\overrightarrow{e}_{1}\hat{A}_{1} +
\overrightarrow{e}_{2}\hat{A}_{2} +
\overrightarrow{e}_{3}\hat{A}_{3}
\end{equation}
For convenience, the $\overrightarrow{e}$ refers to $e$.

First let's consider the $[\hei{p}, \hat{R}^{2}]$.
\begin{align}\label{OPERATORMOREeq:6}
[\hei{p}, \hei{r}^{2}] &= [\sum e_{i}\hat{p}_{i}, \sum
e_{j}\hat{r}_{j} \cdot \sum e_{j}\hat{r}_{j}] \nonumber \\
&=\sum_{ij} e_{i}e_{j}[\hat{p}_{i}, \hat{r}_{j}^{2}] \nonumber \\
&=\sum_{ij} e_{i}e_{j}\left\{\hat{r}_{j}[\hat{p}_{i}, \hat{r}_{j}] +
[\hat{p}_{i}, \hat{r}_{j}]\hat{r}_{j} \right\} \nonumber \\
&=-\sum_{ij} e_{i}e_{j}2i\hbar\delta_{ij}r_{j} \nonumber \\
&=-\sum_{j} e_{j}2i\hbar r_{j} \nonumber \\
&=-2i\hbar\hei{r}
\end{align}

So far we can deduce the $[\hei{p}, \hat{R}^{2n}]$:
\begin{equation}\label{}
[\hei{p}, \hat{R}^{2n}] = \hat{R}^{2}[\hei{p}, \hat{R}^{2n-2}] +
[\hei{p}, \hat{R}^{2n-2}]\hat{R}^{2}
\end{equation}
This is a clear recursion, so we can get that $[\hei{p},
\hat{R}^{2n}] = -ni\hbar\hat{R}^{2n-2}\hei{r}$.

Next we are going to derive the $[\hei{p}, \hat{R}]$ from $[\hei{p},
\hat{R}^{2}]$.
\begin{align}\label{OPERATORMOREeq:7}
[\hei{p}, \hat{R}^{2}] &= \hat{R}[\hei{p}, \hat{R}]+ [\hei{p},
\hat{R}]\hat{R} \nonumber \\
-2i\hbar\hei{r} &= 2\hat{R}[\hei{p}, \hat{R}]
\end{align}
Thus the $[\hei{p}, \hat{R}] =i\hbar\frac{\hei{r}}{\hat{R}}$.

Here in (\ref{OPERATORMOREeq:7}), why $\hat{R}$ and $[\hei{p},
\hat{R}]$ commute with each other? Here we prove it. Since that we
have $[\hei{p},\hat{R}^{2}] = \hat{R}[\hei{p}, \hat{R}]+ [\hei{p},
\hat{R}]\hat{R}$, so the $[\hei{p},\hat{R}^{2}]$ directly related to
the $[\hei{p}, \hat{R}]$; thus we start from
$[\hei{p},\hat{R}^{2}]$:
\begin{align}\label{}
\left[\hat{R}, [\hei{p},\hat{R}^{2}]\right] &= \left[\hat{R},
\hat{R}[\hei{p},
\hat{R}]+ [\hei{p}, \hat{R}]\hat{R}\right] \nonumber \\
&=\left[\hat{R}, \hat{R}[\hei{p}, \hat{R}]\right]+ \left[\hat{R},
[\hei{p}, \hat{R}]\hat{R}\right]
\end{align}
By using the formula in (\ref{OPERATORMOREeq:4}) related to
$[\hat{A}, \hat{B}\hat{C}]$, we have the expression above
transforming into:
\begin{align}\label{}
\left[\hat{R}, [\hei{p},\hat{R}^{2}]\right] &=
\hat{R}\left[\hat{R},[\hei{p}, \hat{R}] \right] + [\hat{R},
\hat{R}][\hei{p}, \hat{R}] + [\hei{p}, \hat{R}][\hat{R}, \hat{R}] +
\left[\hat{R},[\hei{p}, \hat{R}] \right]\hat{R} \nonumber \\
&=\hat{R}\left[\hat{R},[\hei{p}, \hat{R}] \right]+
\left[\hat{R},[\hei{p}, \hat{R}] \right]\hat{R}
\end{align}
Here we can see the relationship that the $\hat{R}$ commutes with
$[\hei{p}, \hat{R}]$ is wholly determined by the $\left[\hat{R},
[\hei{p},\hat{R}^{2}]\right]$. However, since we have proved that
$[\hei{p},\hat{R}^{2}]$ equals to $-2i\hbar\hei{r}$, it commutes
with $\hat{R}$; thus $\hat{R}$ commutes with $[\hei{p}, \hat{R}]$.
The demonstration finished.

By induction, we can prove the general expression between
$\hat{R}^{n}$ and $\hei{p}$:
\begin{equation}\label{OPERATORMOREeq:8}
[\hei{p}, \hat{R}^{n}] = -ni\hbar\hat{R}^{n-2}\hei{r} \quad
(n=1,2,3, \cdots)
\end{equation}

For the $[\hei{p}, \hat{R}^{-n}]$, we can derive it from the
(\ref{OPERATORMOREeq:8}):
\begin{align}\label{}
[\hei{p}, 1] &= \left[\hei{p},
\hat{R}^{n}\frac{1}{\hat{R}^{n}}\right] \Rightarrow \nonumber \\
           0 &=\hat{R}^{n}\left[\hei{p}, \frac{1}{\hat{R}^{n}}\right] +
\left[\hei{p}, \hat{R}^{n}\right]\frac{1}{\hat{R}^{n}}
\end{align}
Therefore $[\hei{p}, \hat{R}^{-n}] = -ni\hbar\hat{R}^{n-2}\hei{r}$;
the $n$ ranges over all the negative number.

Here, we note that by the same procedure in the
(\ref{OPERATORMOREeq:6}), we can prove that:
\begin{equation}\label{OPERATORMOREeq:9}
[\hei{r}, \hei{p}\cdot\hei{p}] =-2i\hbar\hei{p}
\end{equation}
This is useful while considering the commutative relationship
between angular momentum operator and the Hamiltonian operator.

By the way, we will derive two useful relations which is needed in
the later content. Suggest that $f(\hei{r})$ is the function for the
$\hei{r}$, in the position representation we can see that:
\begin{align}\label{OPERATORMOREeq:10}
(\hei{p}f(\hei{r}) - f(\hei{r})\hei{p})\ket{\Psi} &=
-i\hbar\nabla(f(\hei{r})\ket{\Psi}) + i\hbar
f(\hei{r})(\nabla\ket{\Psi}) \quad \hei{p} = -i\hbar\nabla
\nonumber \\
&=-i\hbar\ket{\Psi}\nabla(f(\hei{r})) =
-i\hbar\ket{\Psi}\frac{\partial f(\hei{r})}{\partial \hei{r}}
\end{align}

thus we have:
\begin{equation}\label{}
[\hei{p}, f(\hei{r})] = -i\hbar \nabla(f(\hei{r})) =
-i\hbar\frac{\partial f(\hei{r})}{\partial \hei{r}}
\end{equation}

Similarly, if we express the $\hei{r} =
i\hbar\frac{\partial}{\partial \hei{p}}$ in momentum representation,
then by exchanging the position between \heit{p} and \heit{r} in the
expression of (\ref{OPERATORMOREeq:10}), we can get similar
expression:
\begin{equation}\label{OPERATORMOREeq:11}
[\hei{r}, f(\hei{p})] = i\hbar \frac{\partial f(\hei{p})}{\partial
\hei{p}}
\end{equation}

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

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../../main"
%%% End:


\chapter{Image Feature Extraction}

A subset of characteristics
with a high discriminative capacity
to be extracted
from the set of cutouts
was defined.
All selected features
refer to information related to the texture of the images
and do not undergo segmentation preprocessing.

\input{R/average-intensity.tex}

Maximum Intensity Value;

Minimum Intensity Value;

\section{Local Binary Pattern}

The Local Binary Pattern (LBP)
is a derivation of the Texture Unit
defined by \cite{wang_texture_1990}.
From the spatial domain,
we can define the LBP feature vector $l$
for each pixel $a$
by comparing the pixel to each of its 8 neighbors.
If the center pixel's value is greater than the neighbor's value,
we assign $0$ to that position in the vector.
Otherwise,
we write $1$.
For example,
consider that we have

\begin{center}
\begin{tabular}{|c|c|c|}
  \hline
  $a_{i - 1, j + 1} = 194$ & $a_{i, j + 1} = 144$ & $a_{i + 1, j + 1} = 132$ \\
  \hline
  $a_{i - 1, j} = 180$ & $a_{i, j} = 136$ & $a_{i + 1, j} = 136$ \\
  \hline
  $a_{i - 1, j - 1} = 167$ & $a_{i, j - 1} = 125$ & $a_{i + 1, j - 1} = 129$ \\
  \hline
\end{tabular}
\end{center}

The feature vector will be

\begin{center}
\begin{tabular}{|c|c|c|}
  \hline
  $l_{i - 1, j + 1} = 1$ & $l_{i, j + 1} = 1$ & $l_{i + 1, j + 1} = 0$ \\
  \hline
  $l_{i - 1, j} = 1$ & & $l_{i + 1, j} = 0$ \\
  \hline
  $l_{i - 1, j - 1} = 1$ & $l_{i, j - 1} = 0$ & $l_{i + 1, j - 1} = 0$ \\
  \hline
\end{tabular}
\end{center}

We represented as a matrix
that has $l_{i, j}$ empty.
We can store the matrix as a linear vector
by following the 8 neighbours in one direction.
For example,
if we start with $l_{i, j + 1}$
and go clockwise,
we will have

\begin{center}
\begin{tabular}{|c|}
  \hline $l_{i, j + 1} = 1$ \\
  \hline $l_{i + 1, j + 1} = 0$ \\
  \hline $l_{i + 1, j} = 0$ \\
  \hline $l_{i + 1, j - 1} = 0$ \\
  \hline $l_{i, j - 1} = 0$ \\
  \hline $l_{i - 1, j - 1} = 1$ \\
  \hline $l_{i - 1, j} = 1$ \\
  \hline $l_{i - 1, j + 1} = 1$ \\
  \hline
\end{tabular}
\end{center}

In total,
we have $2^8 = 256$ possible values for the LBP vector $l$.
The histogram of LBP in an image
should revel its texture information.

\input{R/local-binary-pattern.tex}

\section{Histogram of Oriented Gradients (HOG)}

\section{Gray-Level Co-Occurrence Matrix (GLCM);}

7 Hu Moments;

Haralick’s Texture Features (Haralick, 1979):

– Angular Second Moment (Energy);

– Contrast;

– Correlation;

– Variance;

– Entropy;

– Maximal Correlation Coefficient;

– Inverse Difference Moment (Homogeneity);

– Sum Average, Sum Variance and Sum Entropy;

– Difference Variance and Difference Entropy;

– Information Measure of Correlation I and II.

\input{R/range.tex}

\input{R/variance.tex}


%% Solutions to part 2
\pagebreak

\subsubsection*{2.A}

\subsubsection*{2.B}
The Matlab code to calculate the learning curve is included below. Figure~\ref{fig:part2-learning-curve} shows the learning curve averaged over 100 independent input realizations, and  Figure~\ref{fig:part2-weights} shows the converged weight vector.

Note that the learning curve converged to a much smaller MMSE. Note further that the bias weight is practically negligible now, and some of the weights corresponding to the squared inputs and to the cross-products are significant.

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part2_learning_curve.eps}
	\caption{Experimental learning curve for nonlinear plant identification using a nonlinear filter based on Volterra series. The learning curve was averaged 100 times. The training signal had variance $\sigma_r^2 = 4$.}
	\label{fig:part2-learning-curve}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part2_weights.eps}
	\caption{Weight vector after convergence.}
	\label{fig:part2-weights}
\end{figure}
\FloatBarrier

\subsubsection*{2.C}

As shown in Figure~\ref{fig:part2-learning-curve}, the MMSE estimated using the last 200 samples was equal to $\approx 0.0046$.

\subsubsection*{2.D}
The Matlab code is included in the appendix. The output of the plant is compared to the output of the adaptive filter in Figure~\ref{fig:part2-test}.

The adaptive filter was trained with random signal, but it can almost perfectly track the plant output to a sinusoidal input. The same cannot be accomplished when the adaptive filter is linear as in part 1.E.

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part2_test.eps}
	\caption{Test of the adaptive filter after convergence with a sinusoidal signal. During the first $L+1$ samples, the filter was being initialized.}
	\label{fig:part2-test}
\end{figure}
\FloatBarrier

\subsubsection*{2.E}

When the training signal variance was $\sigma_r^2 = 0.4$, the adaptive filter achieved MMSE equal to $1.8\times 10^{-5}$ during training, but it didn't performed as well as before during test with a sinusoidal signal. The reason for this is that for a smaller training signals, the plant is approximately linear, and the adaptive equalizer cannot learn well the weights that weigh the nonlinear terms of the input.

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part2e_learning_curve.eps}
	\caption{Experimental learning curve for nonlinear plant identification using a nonlinear filter based on Volterra series. The learning curve was averaged 100 times. The training signal had variance $\sigma_r^2 = 0.4$.}
	\label{fig:part2e-learning-curve}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[h!]
	\centering
	\includegraphics[scale=0.8]{part2e_weights.eps}
	\caption{Weight vector after convergence.}
	\label{fig:part2e-weights}
\end{figure}
\FloatBarrier

\FloatBarrier
\begin{figure}[t!]
	\centering
	\includegraphics[scale=0.8]{part2e_test.eps}
	\caption{Test of the adaptive filter after convergence with a sinusoidal signal. During the first $L+1$ samples, the filter was being initialized.}
	\label{fig:part2e-test}
\end{figure}
\FloatBarrier


\section{Tricks}
\begin{enumerate}

\item
In the result display, do click-drag-release to copy a selection of the display to the clipboard.

\item
In a script, line breaking is allowed provided the line breaks occur immediately after operators.
The scanner will automatically go to the next line after an operator.

\item
Setting \verb$trace=1$ in a script causes each line to be printed just before it is evaluated.
This is useful for debugging.

\item
The last result is stored in the symbol $last$.

\item
Use \verb$contract(A)$ to get the mathematical trace of matrix $A$.

\item
Use \verb$binding(s)$ to get the unevaluated binding of symbol $s$.

\item
Use \verb$s=quote(s)$ to clear symbol $s$.

\item
Use \verb$float(pi)$ to get the floating point value of $\pi$.
Set \verb$pi=float(pi)$ to evaluate expressions with a numerical value for $\pi$.
Set \verb$pi=quote(pi)$ to make $\pi$ symbolic again.

\item
Assign strings to unit names so they are printed normally.
For example, setting \verb$meter="meter"$ causes the symbol {\it meter}
to be printed as meter instead of $m_{eter}$.

\item
Use \verb$expsin$ and \verb$expcos$ instead of \verb$sin$ and \verb$cos$.
Trigonometric simplifications occur automatically when exponentials are used.

\item
Use \verb$A==B$ or \verb$A-B==0$ to test for equality of $A$ and $B$.
The equality operator \verb$==$ uses a cross multiply algorithm to eliminate denominators.
Hence \verb$==$ can typically determine equality even when the unsimplified result of $A-B$ is nonzero.

\end{enumerate}


\documentclass[t,usenames,dvipsnames]{beamer}
\usetheme{Copenhagen}
\setbeamertemplate{headline}{} % remove toc from headers
\beamertemplatenavigationsymbolsempty

\usepackage{amsmath, tikz, xcolor, bm, pgfplots, array}
\pgfplotsset{compat = newest}
\usetikzlibrary{arrows.meta, calc, decorations.pathreplacing, patterns, decorations.markings}
\tikzset{>=stealth}

\title{Parametric Equations}
\author{}
\date{}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Objectives}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
    \titlepage
\end{frame}

\section{Sketch a parametric curve.}

\begin{frame}{Intro}
Up until now, we have looked at functions that define $x$ in terms of $y$ (or $y$ in terms of $x$ for inverse functions). \newline\\ \pause

In this section, we will look at parametric functions: ones in which $x$ and $y$ are defined by a \alert{parameter}, such as $t$.
\end{frame}

\begin{frame}{Intro}
For instance, the plot below could show the path a bug might take (starting at $O$) while walking on a table: \newline\\

\begin{center}
    \begin{tikzpicture}
    \begin{axis}[
    axis lines = middle,
    xmin = -1, xmax = 7.5,
    ymin = -1, ymax = 6,
    xtick = {1,2,3,4,5},
    ytick = {1,2,3,4,5},
    xlabel = $x$, ylabel = $y$,
    ]
    \addplot [mark = *, mark size=2pt] coordinates {(5,1)} node [right] {$O$};
    \addplot [domain = -2:2, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.25 with {\arrow{>};},
    mark = at position 0.5 with {\arrow{>};},
    mark = at position 0.75 with {\arrow{>};},
    mark = at position 1 with {\arrow{>};}
    }}
    ] ({t^2+1}, {t^3-3*t+3}) node [left, above] {$P(x,y) = (f(t),g(t))$};
    \end{axis}
    \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}{Intro}
The independent variable ($t$ in this case) is called a \alert{parameter}.    \newline\\  \pause

The system of equations
\[
\begin{cases}
    x &= f(t)   \\
    y &= g(t)
\end{cases}
\]

is called a \alert{parametrization} of the curve.   \newline\\  \pause

\emph{Note}: The curve itself is a set of points and is devoid of any orientation.
\end{frame}

\begin{frame}{Example 1}
Sketch the curve described by
\[
\begin{cases}
    x &= t^2 - 3    \\
    y &= 2t - 1
\end{cases}
\quad \text{ for } t \geq -2
\]
\pause
\begin{minipage}{0.5\textwidth}
\setlength{\extrarowheight}{3pt}
\begin{tabular}{cccc}
                    $t$ & $x(t)$ & $y(t)$ & $(x(t), y(t))$ \\ \hline
    \onslide<2->{$-2$  & 1 & $-5$ & $(1,-5)$ \\[3pt]}
    \onslide<3->{$-1$ & $-2$ & $-3$ & $(-2,-3)$ \\[3pt]}
    \onslide<4->{0 & $-3$ & $-1$ & $(-3,-1)$ \\[3pt]}
    \onslide<5->{1 & $-2$ & 1 & $(-2,1)$ \\[3pt]}
    \onslide<6->{2 & 1 & 3 & $(1,3)$ \\[3pt]}
    \onslide<7->{3 & 6 & 5 & $(6, 5)$ \\}
\end{tabular}
\end{minipage}
\hspace{-0.25cm}
\begin{minipage}{0.5\textwidth}
\onslide<8->{
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
    axis lines = middle,
    grid,
    xmin = -3, xmax = 6,
    ymin = -5, ymax = 5,
    xtick = {-3,-2,...,6},
    ytick = {-5,-4,...,5},
    xlabel = $x$, ylabel = $y$,
    ]
    \addplot [mark = *, mark size=2pt, only marks] coordinates {(1,-5) (-2,-3) (-3,-1) (-2,1) (1,3) (6,5)};
    \addplot [domain = -2:3, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.15 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.4 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.65 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.85 with {\arrow[ultra thick, red]{>};}
    }}] ({t*t-3},{2*t-1});
    \end{axis}
\end{tikzpicture}}
\end{minipage}
\end{frame}

\section{Rewrite an equation by eliminating the parameter.}

\begin{frame}{Eliminating the Parameter}
We can eliminate the parameter $t$ by solving one of the equations for $t$ and substituting it into the other.
\end{frame}

\begin{frame}{Example 2}
Eliminate the parameter in Example 1 and write the equation using only $x$ and $y$.
\[
\begin{cases}
    x &= t^2 - 3    \\
    y &= 2t - 1
\end{cases}
\quad \text{ for } t \geq -2
\]
\begin{align*}
    \onslide<2->{y &= 2t - 1} \\[8pt]
    \onslide<3->{y+1 &= 2t} \\[8pt]
    \onslide<4->{t &= \frac{y+1}{2}} \\[8pt]
    \onslide<5->{x &= t^2 - 3} \\
\end{align*}
\end{frame}

\begin{frame}{Example 2}
    \begin{align*}
        x &= t^2 - 3    \\[6pt]
        \onslide<2->{x &= \left(\frac{y+1}{2}\right)^2 - 3} \\[6pt]
        \onslide<3->{x+3 &= \frac{(y+1)^2}{4}} \\[6pt]
        \onslide<4->{4(x+3) &= (y+1)^2} \\[6pt]
        \onslide<5->{t &= \frac{y+1}{2}}    \\[6pt]
        \onslide<6->{\frac{y+1}{2} &\geq -2} \\[6pt]
        \onslide<7->{y &\geq -5} \\
    \end{align*}
\end{frame}

\begin{frame}{Example 2}
    \[  4(x+3) = (y+1)^2, \quad y \geq -5
    \]
\end{frame}

\begin{frame}{Example 3a}
    Sketch each of the following curves.    \newline\\
(a) \quad $\begin{cases}
        x &= t^3    \\
        y &= 2t^2   \\
    \end{cases}$    \quad for $-1 \leq t \leq 1$    \newline\\    \pause
\begin{minipage}{0.6\textwidth}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
    axis lines = middle,
    grid,
    xmin = -2, xmax = 2,
    ymin = -1, ymax = 3,
    xtick = {-2,-1,...,2},
    ytick = {-1,0,...,3},
    xlabel = $x$, ylabel = $y$
]
\addplot [mark = *, mark size = 2pt, only marks] coordinates {(-1,2) (1,2)};
\addplot [domain = -1:1, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.15 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.4 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.65 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.85 with {\arrow[ultra thick, red]{>};}
    }}] ({t*t*t},{2*t*t});
\end{axis}
\end{tikzpicture}
\end{minipage}
\hspace{-0.5cm}
\begin{minipage}{0.4\textwidth}
\begin{align*}
    \onslide<3->{x &= t^3} \\[8pt]
    \onslide<4->{t &= \sqrt[3]{x}} \\[8pt]
    \onslide<5->{y &= 2\left(\sqrt[3]{x}\right)^2}    \\[8pt]
    \onslide<6->{y &= 2\cdot \sqrt[3]{x^2}}   \\[8pt]
    \onslide<7->{y &= 2x^{2/3}} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3b}
    (b) \quad $\begin{cases}
        x &= 2e^{-t} \\
        y &= e^{-2t}    \\
    \end{cases}$    \quad for $t \geq 0$    \newline\\  \pause
\begin{minipage}{0.6\textwidth}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
    axis lines = middle,
    grid,
    xmin = -1, xmax = 3,
    ymin = -1, ymax = 2,
    xtick = {-1,0,...,3},
    ytick = {-1,0,...,2},
    xlabel = $x$, ylabel = $y$
]
\addplot [mark = *, mark size = 2pt, only marks] coordinates {(2,1)};
\addplot [domain = 0:5, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.15 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.4 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.65 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.85 with {\arrow[ultra thick, red]{>};}
    }}] ({2*e^(-1*t)},{e^(-2*t});
\draw [fill=white] (axis cs: 0,0) circle (2pt);
\end{axis}
\end{tikzpicture}
\end{minipage}
\hspace{-0.5cm}
\begin{minipage}{0.4\textwidth}
\begin{align*}
    \onslide<3->{x &= 2e^{-t}} \\[6pt]
    \onslide<4->{e^{-t} &= \frac{x}{2}} \\[6pt]
    \onslide<5->{y &= \left(e^{-t}\right)^2} \\[6pt]
    \onslide<6->{y &= \left(\frac{x}{2}\right)^2} \\[6pt]
    \onslide<7->{y &= \frac{x^2}{4}} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3c}
(c) \quad $\begin{cases}
        x &= \sin t \\
        y &= \csc t \\
    \end{cases}$    \quad for $0 < t < \pi$ \newline\\  \pause
\begin{minipage}{0.6\textwidth}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
    axis lines = middle,
    grid,
    xmin = -1, xmax = 2,
    ymin = -1, ymax = 4,
    xtick = {-1,0,1,2},
    ytick = {-1,0,...,4},
    xlabel = $x$, ylabel = $y$
]
\addplot [mark = *, mark size = 2pt, only marks] coordinates {(1,1)};
\addplot [domain = 0.25:3.0, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.15 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.4 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.65 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.85 with {\arrow[ultra thick, red]{>};}
    }}] ({sin(deg(t))},{1/(sin(deg(t)))});
\end{axis}
\end{tikzpicture}
\end{minipage}
\hspace{-0.25cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<3->{x &= \sin t} \\[6pt]
    \onslide<4->{y &= \csc t} \\[10pt]
    \onslide<5->{y &= \frac{1}{\sin t}} \\[10pt]
    \onslide<6->{y &= \frac{1}{x}} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3d}
(d) \quad $\begin{cases}
        x &= 1 + 3\cos t    \\
        y &= 2\sin t    \\
    \end{cases}$    \quad for $0 \leq t \leq \frac{3\pi}{2}$
    \newline\\  \pause
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
    axis lines = middle,
    grid,
    xmin = -3, xmax = 5,
    ymin = -3, ymax = 3,
    xtick = {-3,-2,...,5},
    ytick = {-3,-2,...,3},
    xlabel = $x$, ylabel = $y$
]
\addplot [mark = *, mark size = 2pt, only marks] coordinates {(4,0) (1,2) (-2,0) (1,-2)};
\addplot [domain = 0:4.71, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.15 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.4 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.65 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.85 with {\arrow[ultra thick, red]{>};}
    }}] ({1+3*cos(deg(t))},{2*sin(deg(t))});
\end{axis}
\end{tikzpicture}
\end{minipage}
\hspace{-0.5cm}
\begin{minipage}{0.5\textwidth}
\begin{align*}
    \onslide<3->{x &= 1 + 3\cos t} \\[10pt]
    \onslide<4->{\frac{x-1}{3} &= \cos t} \\[10pt]
    \onslide<5->{y &= 2 \sin t} \\[10pt]
    \onslide<6->{\frac{y}{2} &= \sin t} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3d}
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
    axis lines = middle,
    grid,
    xmin = -3, xmax = 5,
    ymin = -3, ymax = 3,
    xtick = {-3,-2,...,5},
    ytick = {-3,-2,...,3},
    xlabel = $x$, ylabel = $y$
]
\addplot [mark = *, mark size = 2pt, only marks] coordinates {(4,0) (1,2) (-2,0) (1,-2)};
\addplot [domain = 0:4.71, samples = 100, variable = \t,
    postaction={decorate, decoration={markings,
    mark = at position 0.15 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.4 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.65 with {\arrow[ultra thick, red]{>};},
    mark = at position 0.85 with {\arrow[ultra thick, red]{>};}
    }}] ({1+3*cos(deg(t))},{2*sin(deg(t))});
\end{axis}
\end{tikzpicture}
\end{minipage}
\hspace{-0.5cm}
\begin{minipage}{0.5\textwidth}
\begin{align*}
    \cos^2 t + \sin^2 t &= 1 \\[10pt]
    \onslide<2->{\left(\frac{x-1}{3}\right)^2 + \left(\frac{y}{2}\right)^2 &= 1} \\[10pt]
    \onslide<3->{\frac{(x-1)^2}{9} + \frac{y^2}{4} &= 1} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Parametrizations of Common Curves}
\begin{itemize}
    \item For $y = f(x)$, as $x$ runs through some interval $I$, let $x=t$ and $y = f(t)$ and let $t$ run through $I$.    \newline\\  \pause
    \item For $x = g(y)$, as $y$ runs through some interval $I$, let $x=g(t)$ and $y = t$ and let $t$ run through $I$.    \newline\\  \pause
    \item For a directed line segment with initial point $(x_0,y_0)$ and terminal point $(x_1,y_1)$ let $x = x_0 + (x_1-x_0)t$ and let $y = y_0 + (y_1-y_0)t$ for $0 \leq t \leq 1$.  \newline\\  \pause
    \item For an ellipse in the form $\frac{(x-h)^2}{a^2} + \frac{(y-k)^2}{b^2}=1$, let $x = h + a\cos t$ and $y = k + a\sin t$ for $0 \leq t < 2\pi$.
\end{itemize}
\end{frame}

\begin{frame}{Example 4}
Find a parametrization for each of the following.   \newline\\
(a) \quad $y = x^2$ from $x = -3$ to $x = 2$
    \onslide<2->{\[ x = t \quad  \text{and} \quad y = t^2 \quad \text{for } -3 \leq t \leq 2 \]}

\onslide<3->{(b) \quad $y = f^{-1}(x)$ where $f(x) = x^5 + 2x + 1$}
\begin{align*}
    \onslide<4->{y &= x^5 + 2x + 1} \\[8pt]
    \onslide<5->{x &= y^5 + 2y + 1}   \\[8pt]
    \onslide<6->{y = t \quad & \quad x = t^5 + 2t + 1 \quad \text{for } -\infty < t < \infty}
\end{align*}
\end{frame}

\begin{frame}{Example 4c}
(c) \quad The line segment which starts at $(2,-3)$ and ends at $(1,5)$
\begin{align*}
    \onslide<2->{x_1 - x_0 &= 1 - 2} \\
    \onslide<3->{&= -1} \\
    \onslide<4->{x &= x_0 + (x_1 - x_0)t} \\
    \onslide<5->{x &= 2 + (-1)t} \\
    \onslide<6->{{\color{red}x} &{\color{red}= 2 - t} \\
        y_1 - y_0 &= 5 - (-3)} \\
    \onslide<7->{&= 8} \\
    \onslide<8->{y &= y_0 + (y_1 - y_0)t} \\
    \onslide<9->{{\color{red}y} &{\color{red}= -3 + 8t}} \\
    \onslide<10->{& \text{for } 0 \leq t \leq 1}
\end{align*}
\end{frame}

\begin{frame}{Example 4}
(d) \quad The circle $x^2+2x+y^2-4y=4$
\begin{align*}
    \onslide<2->{\frac{(x+1)^2}{9} + \dfrac{(y-2)^2}{9} &= 1} \\[10pt]
    \onslide<3->{x = -1 + 3\cos t \quad & \quad y = 2 + 3\sin t \quad \text{for } 0 \leq t < 2\pi} \\
\end{align*}
\end{frame}

\begin{frame}{Example 4}
(e) \quad The left half of the ellipse $\dfrac{x^2}{4} + \frac{y^2}{9} = 1$
\begin{align*}
    \onslide<2->{x &= 2\cos t} \\[8pt]
    \onslide<3->{y &= 3\sin t} \\[8pt]
    \onslide<4->{& \text{for } \frac{\pi}{2} \leq t \leq \frac{3\pi}{2}}
\end{align*}
\end{frame}

\end{document}


\subsubsection{Circular Cylinders}
\noindent
A circular cylinder is what we usually think of as a cylinder. It is a circle extruded into 3D space. One of its forms is
\begin{equation*}
	x^2 + y^2 = R^2
\end{equation*}
where $R$ is the cylinder's radius.

[INSERT IMAGE]


\section{Model}

\begin{definition}\label{def:mp}
  A Markov process is a stochastic process $Q_0, Q_1, \dots$ for which
  \begin{align*}
    p(Q_t=q_t \gv Q_0=q_0, Q_1=q_1, \dots, Q_{t-1}=q_{t-1}) = p(Q_t=q_t \gv Q_{t-1}=q_{t-1}).
  \end{align*}
  There is one, and only one, initial state $q_0$ such that $p(Q_0=q_0)=1$.
  The possible values of $Q_t$ form a finite set $\set{Q}$ called the state space.
\end{definition}

\begin{definition}\label{def:hmm}
  Let $\set{A}$ be a finite set of symbols.
  Let $Q_0, Q_1, \dots$ be a Markov process and let $S_0, S_1, \dots$
  be a stochastic process for which
  \begin{align*}
    p(S_t\in\set{A} \gv Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t) = p(S_t\in\set{A} \gv Q_t=q_t),
  \end{align*}
  for $t>0$, and $p(S_0=\emptyset \gv Q_0=q_0)=1$.
  The pair $(Q_t, S_t)$ is a hidden Markov model (HMM) with alphabet $\set{A}$ and $\emptyset$
  represents an empty sequence.
\end{definition}

The standard HMM definition is often extended to account for non-initial states that
do not emit symbols. Those states are referred to as silent states and are useful to
describe a missing alignment position, for example. This section goes a step further by
defining a more general hidden Markov model that accounts for states that instead emit
sequence of symbols of variable length, including zero-length sequences.

% \begin{definition}
%   Let $\set{A}$ be a finite set of symbols, $k\in\field{N}_0$, and define
%   $\set{B}=\bigcup_{i=0}^k\set{A}^i$.
%   Let $Q_0, Q_1, \dots$ be a Markov process.
%   Let $S_0, S_1$ be a stochastic process for which
%   \begin{equation*}
%     p(S_t\in\set{B} \gv Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t)
%     = p(S_t\in\set{B} \gv Q_t=q_t)
%   \end{equation*}
%   for $t>0$, and $p(S_0=\emptyset \gv Q_0=q_0)=1$.
%   The pair $(Q_t, S_t)$ is an invisible Markov model (IMM) with alphabet $\set{A}$ and
%   limit $k$.
% \end{definition}

\begin{definition}
  Let $\set{A}$ be a finite set of symbols.
  Let $Q_0, Q_1, \dots$ be a Markov process.
  Let $F_0, F_1, \dots$ and $V_0, V_1$ be two stochastic processes for which
  \begin{equation*}
    p(F_t\in\field{N}, V_t\in\set{A}^{f_t} \gv Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t)
    = p(F_t\in\field{N}, V_t\in\set{A}^{f_t} \gv Q_t=q_t)
  \end{equation*}
  and $p(F_0=0, V_t=\emptyset \gv Q_0=q_0) = 1$.
  The triplet $(Q_t, F_t, V_t)$ is an invisible Markov model (IMM) with alphabet $\set{A}$.
\end{definition}

Let $\arr{s}=s_1 .. s_L$ be a sequence emitted from an IMM.
The marginal likelihood of $\arr{s}$ is given by
\begin{align}\label{eq:ml}
  \mathrm{ML}(\arr{s}) = p(V_0=\arr{s}) + p(V_0\neq\arr{s}, V_0||V_1=\arr{s}) +
  p(V_0\neq\arr{s}, V_0||V_1\neq\arr{s}, V_0||V_1||V_2=\arr{s}) + \dots,
\end{align}
where $||$ denotes sequence concatenation.
Note that
\begin{align*}
  p(V_0 \neq \arr{s}, V_0||V_1=\arr{s}) &= p(V_0\neq\arr{s}, V_0||V_1=\arr{s}, F_0=L) +
  p(V_0\neq\arr{s}, V_0||V_1=\arr{s}, F_0 \neq L)\\
  &= p(V_0\neq\arr{s}, V_0||V_1=\arr{s}, F_0=L) + p(V_0||V_1=\arr{s}, F_0 \neq L)\\
  &= p(V_0||V_1=\arr{s}, F_0 \neq L) = p(V_0||V_1=\arr{s}, F_0 < L).
\end{align*}
Similarly,
\begin{align*}
  p(V_0\neq\arr{s}, V_0||V_1\neq\arr{s}, V_0||V_1||V_2=\arr{s}) =
  p(V_0||V_1||V_2=\arr{s}, F_0+F_1 < L).
\end{align*}
Let $V_{0..t} = V_0||V_1||\dots||V_t$ and $L_t = F_0 + F_1 + \dots + F_{t-1}$.
The marginal likelihood of $\arr{s}$ is also given by
\begin{align*}
  \mathrm{ML}(\arr{s}) = p(V_0=\arr{s}) + \sum_{t=1}^{\infty} p(V_{0..t}=\arr{s}, L_t<L).
\end{align*}

For computational reasons, it would be useful to have an upper bound on the summation of the
marginal likelihood.
We will define a type of IMM that has such a feature.

\begin{definition}
  A cycle is any probable sequence of states that starts and ends with the same state.
\end{definition}

\begin{definition}
  A quiet state is a state that has a non-zero probability of emitting an empty sequence.
\end{definition}

\begin{definition}
  A quiet cycle is any cycle having only quiet states.
\end{definition}

\begin{corollary}
  Let $M$ be the number of states of the IMM. If it has no quiet cycles, any sequence of $M$ states
  will have emitted at least one symbol.
\end{corollary}

If IMM has no quiet cycles, there is always a $N \leq L\cdot M$ such that
\begin{align*}
  \mathrm{ML}(\arr{s}) = p(V_0=\arr{s}) + \sum_{t=1}^N p(V_{0..t}=\arr{s}, L_t<L).
\end{align*}


\documentclass[11pt, oneside]{article}

\usepackage{../../shared/preamble}
\addbibresource{../../shared/references.bib}

\usepackage{../real-numbers/real-numbers}
%\usepackage{manifolds}

\title{Manifolds}
\author{Arthur Ryman, {\tt arthur.ryman@gmail.com}}
\date{\today}

% Document
\begin{document}

\maketitle

\begin{abstract}
This article contains Z Notation type declarations for manifolds and some related objects.
It has been type checked by \fuzz.
\end{abstract}

    \section{Introduction}

    Manifolds can be defined in several ways.
    The way I prefer to think about them is that, first of all, they are  based on topological spaces.
    A manifold is therefore a topological space with some additional structure.
    This additional structure allows one to regard a manifold as, locally, being like an open subset of $\R^n$
    for some natural number $n$ referred to as the dimension of the manifold.
    In the following, let $M$ be a topological space of dimension $n$.

    \section{Charts}
    A chart $\phi$ on $M$ is a continuous injection of some open subset $U \subseteq M$ into $\R^n$.
    A chart gives every point $p \in U$ in its domain of definition a tuple of $n$ real number coordinates.
    \begin{equation}
        \phi: U \inj \R^n
    \end{equation}

    \subsection{Transition Functions}
    Let $U, V, W$ be open subsets of $M$ with $W = U \cap V$.
    Let $\phi: U \inj \R^n$ and $\psi: V \inj \R^n$ be charts.
    Every point $p \in W$ is therefore given two, typically distinct, tuples of coordinates.
    The mapping from one coordinate tuple to the other is called the transition function defined by the pair of charts.
    Let $t_{\phi,\psi}$ denote that transition function that maps the $\phi$ coordinates to the $\psi$ coordinates.
    \begin{equation}
        \forall x \in \phi(W) @ t_{\phi,\psi}(x) = \psi(\phi^{-1}(x))
    \end{equation}

    \subsection{Compatible Charts}
    Let $\mathcal{F}$ be some family of partial injections from $\R^n$ to $\R^n$, e.g. continuous, differentiable, smooth, defined on the open subsets.
    \begin{equation}
        \mathcal{F} \subseteq \R^n \pinj \R^n
    \end{equation}

    A pair of charts are said to be compatible with respect to $\mathcal{F}$ when their transition functions belong to $\mathcal{F}$.

    \section{Atlases}
    A set of pairwise compatible charts that cover $M$ is called an atlas for $M$.
    An atlas gives $M$ a manifold structure.
    If the charts are only required to be continuous then $M$ is called a topological manifold.
    If the charts are required to be differentiable then the atlas is called a differential or differentiable structure and $M$ is called
    a differentiable manifold.
    Infinitely differentiable charts are called smooth charts.
    We are only concerned with smooth charts and manifolds.

    In general, we normally consider an atlas to be a maximal set of charts.
    A given set of mutually compatible charts belongs to a unique maximal atlas.
    The given set is said to generate the maximal atlas.

    \section{Smooth Mappings}
    Mappings from one smooth manifold to another are called smooth when they are smooth when expressed in their coordinate charts.
    A smooth mapping that has a smooth inverse is called a diffeomorphism.

    \section{Tangent Vectors}
    A tangent vector $X$ at the point $p \in M$ is a mapping from the set of smooth functions at $p$ to $\R$ that satisfies the following
    for all $c \in \R$ and $f,g \in C^{\infty}(M,p)$
    \begin{align}
        X(cf) &= cX(f) \\
        X(f + g) &= X(f) + X(g) \\
        X(fg) &= g(p)X(f) + f(p)X(g)
    \end{align}

    A smooth curve $\gamma: \R \fun M$ defines a tangent vector $X$ at $p=\gamma(0)$ by
    \begin{equation}
        X(f) = \left.\frac{df(\gamma(t))}{dt}\right|_{t=0}
    \end{equation}

    \section{Tangent Bundles}

    The set of all tangent vectors at $p$ is denoted $M_p$ or $T_p(M)$.
    It is an $n$-dimensional vector space and is called the tangent space at $p$.
    The set of all tangent spaces is called the tangent bundle and is denoted $T(M)$
    \begin{equation}
        T(M) = \{~ (p,X) | p \in M, X \in M_p ~\}
    \end{equation}

    The tangent bundle $T(M)$ is a smooth vector bundle over $M$ under the natural projection
    $\pi: T(M) \fun M, \pi(p,X) = p$.

    \printbibliography

\end{document}


\section{Compactly generated spaces}
A lot of homotopy theory is about loop spaces and mapping spaces.
Standard topology doesn't do very well with mapping spaces, so we will narrate the story of \emph{compactly generated spaces}.
One nice consequence of working with compactly generated spaces is that the category is
Cartesian-closed (a concept to be defined below).

\subsection{CGHW spaces}\label{CGWHspaces}
Some constructions commute for ``categorical reasons''.
For instance, limits commute with limits.
Here is an exercise to convince you of a special case of this.
\begin{exercise}%Exercise 4 from 18.906
    Let $X$ be an object of a category $\cc$.
    The \emph{overcategory} (or the \emph{slice category}) $\cc_{/X}$ has objects
    given by morphisms $p:Y\to X$ in $\cc$, and morphisms given by the obvious
    commutativity condition.
    \begin{enumerate}
	\item Assume that $\cc$ has finite products.
	    What is the left adjoint to the functor $X\times -:\cc\to\cc_{/X}$ that sends
	    $Y$ to the object $X\times Y \xar{\pr_1}X$?
	\item As a consequence of Theorem \ref{adjointslimits}, we find that $X\times -:\cc\to\cc_{/X}$ preserves limits.
	    The composite $\cc\to\cc_{/X}\to\cc$, however, probably does not.
	    \begin{itemize}
		\item What is the limit of a diagram in $\cc_{/X}$?
		\item Let $Y:\cI\to\cc$ be any diagram. Show that
		    $${\lim_{i\in\cI}}^{\cc_{/X}}(X\times Y_i)
		    \simeq X\times {\lim_{i\in\cI}}^\cc Y_i.$$
		    What happens if $\cI$ only has two objects and only identity morphisms?
	    \end{itemize}
    \end{enumerate}
\end{exercise}
However, colimits and limits need not commute!
An example comes from algebra.
The coproduct in the category of commutative rings is the tensor product (exercise!).
But $\left(\lim \Z/p^k\Z\right) \otimes \QQ \simeq \Z_p \otimes \QQ \simeq \QQ_p$ is
clearly not $\lim\left(\Z/p^k\Z\otimes \QQ\right) \simeq \lim 0 \simeq 0$!

We also need not have an isomorphism between
$X\times\colim_{j\in \cJ}Y_j$ and $\colim_{j\in \cJ}(X\times Y_j)$.
One example comes a quotient map $Y\to Z$:
in general, the induced map $X\times Y\to X\times Z$ is not necessarily another quotient map.
A theorem of Whitehead's says that this problem is rectified if we assume that $X$ is
a compact Hausdorff space.
Unfortunately, a lot of interesting maps are built up from more ``elementary'' maps by such a procedure,
so we would like to repair this problem.
%Why were we talking about colimits? Here's an observation. Suppose $X\to Y$ is a quotient map; then a map $Y\to Z$ is continuous iff the composite $X\to Y\to Z$ is continuous. A quotient map \emph{is} a coequalizer. What I'm saying is, I can find two maps to $X$ such that $Y$ is a coequalizer of $X$. What space are we mapping into $X$? Well, suppose $Z=X/\sim$. If we considered:
%\begin{equation*}
%    \begin{tikzcd}
%	X\times_Z X\ar[r,shift left=.75ex,"\pi_1"]\ar[r,shift right=.75ex,swap,"\pi_2"] & X\ar[r] & Z
%    \end{tikzcd}
%\end{equation*}
%The term here is ``regular epimorphism''.

We cannot simply do this by restricting ourselves to compact Hausdorff spaces:
that's a pretty restrictive condition to place.
Instead (motivated partially by the Yoneda lemma),
we will look at topologies detected by maps from compact Hausdorff spaces.
\begin{definition}
    Let $X$ be a space.
    A subspace $F\subseteq X$ is said to be \emph{compactly closed} if,
    for any map $k:K\to X$ from a compact Hausdorff space $K$,
    the preimage $k^{-1}(F)\subseteq K$ is closed.
\end{definition}
It is clear that any closed subset is compactly closed, but
there might be compactly closed sets which are not closed in the topology on $X$.
This motivates the definition of a $k$-space:
\begin{definition}
    A topological space $X$ is said to be a \emph{$k$-space}
    if every compactly closed set is closed.
\end{definition}
The $k$ comes either from ``kompact'' and/or Kelly, who was an early topologist
who worked on such foundational topics.

It's clear that $X$ is a $k$-space if and only if the following statement is true:
a map $X\to Y$ is continuous if and only if, for every compact Hausdorff space $K$ and map $k:K\to X$,
the composite $K\to X\to Y$ is continuous.
For instance, compact Hausdorff spaces are $k$-spaces. First countable (so metric spaces) and CW-complexes are also $k$-spaces.

In general, a topological space $X$ need not be a $k$-space.
However, it can be ``$k$-ified'' to obtain another $k$-space denoted $kX$.
The procedure is simple: endow $X$ with the topology consisting of all compactly closed sets.
The reader should check that this is indeed a topology on $X$;
the resulting topological space is denoted $kX$.
This construction immediately implies, for instance, that the identity $kX\to X$ is continuous.

Let $k\Top$ be the category of $k$-spaces.
This is a subcategory of the category of topological spaces, via a functor $i:k\Top\hookrightarrow \Top$.
The process of $k$-ification gives a functor $\Top\to k\Top$, which has the property that:
$$k\Top(X,kY)=\Top(iX,Y).$$
Notice that this is another example of an adjunction!
We can conclude from this that $k(iX\times iY)=X\times^{k\Top}Y$, where $X$ and $Y$ are $k$-spaces.
One can also check that $kiX\simeq X$.

The takeaway is that $k\Top$ has good categorical properties inherited from $\Top$:
it is a complete and cocomplete category.
As we will now explain, this category has more categorical niceness, that does not exist in $\Top$.

\subsection{Mapping spaces}\label{mappingspaces}
Let $X$ and $Y$ be topological spaces.
The set $\Top(X,Y)$ of continuous maps from $X$ to $Y$ admits a topology, namely the compact-open topology.
If $X$ and $Y$ are $k$-spaces, we can make a slight modification:
define a topology on $k\Top(X,Y)$ generated by the sets
$$W(k:K\to X, \text{ open }U\subseteq Y) := \{f:X\to Y: f(k(K))\subseteq U\}.$$
We write $Y^X$ for the $k$-ification of $k\Top(X,Y)$.
\begin{prop}
    \begin{enumerate}
	\item The functor $(k\Top)^{op}\times k\Top\to k\Top$ given by $(X,Y)\to Y^X$ is a functor of both variables.
	\item $e:X\times Z^X\to Z$ given by $(x,f)\mapsto f(x)$ and $i:Y\to (X\times Y)^X$ given by $y\mapsto(x\mapsto(x,y))$ are continuous.
    \end{enumerate}
\end{prop}
\begin{proof}
    The first statement is left as an exercise to the reader.
    For the second statement, see \cite[Proposition 2.11]{StricklandCGWH}.
\end{proof}
As a consequence of this result, we can obtain a very nice adjunction.
Define two maps:
\begin{itemize}
    \item $k\Top(X\times Y,Z)\to k\Top(Y,Z^X)$ via
	$$(f:X\times Y\to Z)\mapsto (Y\xrightarrow{i}(X\times Y)^X\to Z^X).$$
    \item $k\Top(Y,Z^X) \to k\Top(X\times Y,Z)$ via
	$$(f:Y\to Z^X)\mapsto(X\times Y\to X\times Z^X\xrightarrow{e} X).$$
\end{itemize}
By \cite[Proposition 2.12]{StricklandCGWH}, these two maps are continuous inverses, so there is a natural homeomorphism
$$k\Top(X\times Y,Z)\simeq k\Top(Y,Z^X).$$
This motivates the definition of a {Cartesian closed} category.
\begin{definition}\label{cartesian-closed}
    A category $\cc$ with finite products is said to be
    \emph{Cartesian closed} if, for any object $X$ of $\cc$, the functor $X\times -:\cc\to \cc$ has a right adjoint.
\end{definition}
Our discussion above proves that $k\Top$ is Cartesian closed, while this is not satisfied by $\Top$.
As we will see below, this has very important ramifications for algebraic topology.
\begin{exercise}
    \todo{Insert Exercise 2 from 18.906.}
\end{exercise}


\chapter{The Cut-Matching Game: Expanders via Max Flow}

In this chapter, we learn about a new algorithm to compute expanders that employs max flow as a subroutine.

\section{Introduction}

We start with a review of expanders where make a subtle change the notion of an expander in comparison to chapter \ref{chap:cheegersInequality} to ease the exposition.

\paragraph{Definitions.} We let $G=(V,E)$ be an unweighted, connected graph in this chapter, and let $\dd$ be the degree vector, $E(S,V \setminus S)$ denote the set of edges crossing the cut $A,B$

Given set $\emptyset \subset S \subset V$, then we define the \textbf{sparsity} $\psi(S)$ of $S$ by
\[
\psi(S) = \frac{|E(S, V \setminus S)|}{ \min\{|S|, |V \setminus S| \} }
\]
Note that \textbf{sparsity} $\psi(S)$ differs from \textbf{conductance} $\phi(S) = \frac{|E(S, V \setminus S)|}{ \min\{\vol(S), \vol(V \setminus S) \} }$, as defined in \ref{chap:cheegersInequality}, in the denominator. It is straight-forward to see that in a connected graph $\psi(S) \geq \phi(S)$ for all $S$.

Clearly, we again have $\psi(S) = \psi(V \setminus S)$. We define the \emph{sparsity} of a graph $G$ by $\psi(G) = \min_{\emptyset \subset S \subset V} \psi(S)$. For any $\psi \in (0, n]$, we say a graph $G$ is a $\psi$-expander with regard to sparsity, if $\psi(G) \geq \psi$. When the context is clear, we simply say that $G$ is a $\psi$-expander.

\paragraph{The Main Result.} The main result of this chapter is the following theorem.

\begin{theorem}
There is an algorithm $\textsc{SparsityCertifyOrCut}(G, \psi)$ that given a graph $G$ and a parameter $0 <\psi \leq 1$ either:
\begin{itemize}
    \item \emph{Certifies} that $G$ is a $\Omega(\psi/\log^2 n)$-expander with regard to sparsity, or
    \item Presents a \emph{cut} $S$ such that $\psi(S) \leq O(\psi)$.
\end{itemize}
The algorithm runs in time $O(\log^2 n) \cdot T_{max\_flow}(G) + \tilde{O}(m)$ where $T_{max\_flow}(G)$ is the time it takes to solve a Max Flow problem on $G$\footnote{Technically, we will solve problems with two additional vertices and $n$ additional edges but this will not change the run-time of any known max-flow algorithm asymptotically.}.
\end{theorem}

The bounds above can further be extended to compute $\phi$-expanders (with regard to conductance). Using current state-of-the art Max Flow results, the above problem can be solved in $\tilde{O}(m + n^{3/2+o(1)})$ time \cite{BLLSSSW21}.

\section{Embedding Graphs into Expanders}

Let us start by exploring the first key idea behind the algorithm. We therefore need a definition of what it means to embed one graph into another.

\paragraph{Definition of Embedding.} Given graphs $H$ and $G$ that are defined over the same vertex set, then we say that a function $\textsc{Embed}_{H \xrightarrow{} G}$ is an \emph{embedding} if it maps each edge $(u,v) \in H$ to a $u$-to-$v$ path $P_{u,v} = \textsc{Embed}_{H \xrightarrow{} G}(u,v)$ in $G$.
\begin{figure}[!ht]
    \centering
    \includegraphics[scale=0.2]{./fig/embedGraph_lectureCutMatching.jpeg}
    \caption{In this example the red edge $(u,v)$ in $H$ is mapped to the red $u$-to-$v$ path in $G$.}
    \label{fig:my_label}
\end{figure}

We say that the \emph{congestion} of $\textsc{Embed}_{H \xrightarrow{} G}$ is the maximum number of times that any edge $e \in E(G)$ appears on any embedding path: \[
\congestion(\textsc{Embed}_{H \xrightarrow{} G}) = \max_{e \in E(G)} |\{ e' \in E(H) \;|\; e \in \textsc{Embed}_{H \xrightarrow{} G}(e') \}|.
\]

\paragraph{Certifying Expander Graphs via Embeddings.} Let us next prove the following lemma that is often consider Folklore.

\begin{lemma}\label{lma:folklore_embedding}
Given a $\frac{1}{2}$-expander graph $H$ and an embedding of $H$ into $G$ with congestion $C$, then $G$ must be an $\Omega\left(\frac{1}{C}\right)$-expander.
\end{lemma}
\begin{proof}
Consider any cut $(S, V \setminus S)$ with $|S| \leq |V \setminus S|$. Since $H$ is a $\psi$-expander, we have that $|E_H(S, V \setminus S)| \geq |S|/2$. We also know by the embedding of $H$ into $G$, that for each edge $(u,v) \in E_H(S, V \setminus S)$, we can find path a $P_{u,v}$ in $G$ that also has to cross the cut $(S, V \setminus S)$ at least once. But since each edge in $G$ is on at most $C$ such paths, we can conclude that at least $|E_H(S, V \setminus S)|/ C \geq |S|/2C$ edges in $G$ cross the cut $(S, V \setminus S)$.
\end{proof}

Unfortunately, the reverse of the above lemma is not true, i.e. even if there exists no embedding from $1/2$-expander $H$ into $G$ of congestion $C$, then $G$ might still be an $\Omega\left(\frac{1}{C}\right)$-expander.

\section{The Cut-Matching Algorithm}

Although there are still some missing pieces, let us next discuss the algorithm   \ref{algo:cutMatchingGame}. The algorithm runs for $T$ iterations where we will later find that the right value to set $T$ to is in $\Theta(\log^2 n)$.

\begin{algorithm}[H]
    \For{$i = 0,1,2, \dots, T$}{
        $(S_i, \overline{S}_i) \gets \textsc{FindBiPartition}(G, \{M_1, M_2, \dots, M_{i}\})$ \tcp*{Assume  $|S| = |\overline{S}| = n/2$}
        Solve the flow problem on $G$ where each vertex $e \in E$ receives capacity $\cc(e) = 1/\psi$ and the demand at each edge $v \in S$ is $+1$ and for each $v \in \overline{S}$ is $-1$, by introducing a super-source $s$ and super-sink $t$\;
        \If{flow procedure returns a flow $\ff$ with $\val(f) = n/2$}{
            Remove $s,t$ to derive $S$-$\overline{S}$ flow; then decompose flow $\ff$ into flow paths $P_1, P_2, \dots, P_{n/2}$\;
            Create a matching $M_{i}$ where for each $s$-to-$\overline{s}$ flow path $P_i$, we add $(s, \overline{s})$ to $M_i$.
        }\Else{
            \Return the minimum cut $(X_S, X_{\overline{S}})$ in the flow problem after removing the super-source $s$ and the super-sink $t$ from the two sets.
        }
    }
    \Return $H = \bigcup_{i} M_i$
  \caption{\textsc{SparsityCertifyOrCut}$(G, \psi)$}
  \label{algo:cutMatchingGame}
\end{algorithm}

\begin{figure}[!ht]
    \centering
    \includegraphics[scale=0.2]{./fig/AlgorithmProcessing_lectureCutMatching.jpeg}
    \caption{Illustration of the steps of the Algorithm. In a), a bi-partition of $V$ is found. In b), the bi-partition is used to obtain a flow problem where we inject one unit of flow to each vertex in $S$ via super-source $s$ and extract one unit via super-sink $t$. c) A path flow decomposition. For each path, the first vertex is in $S$ and the last vertex in $\overline{S}$. d) We find $M_i$ to be the one-to-one matching between endpoints in $S$ and $\overline{S}$ defined by the path flows.}
    \label{fig:my_label}
\end{figure}

\paragraph{Beginning of an Iteration.} In each iteration of the algorithm, we first invoke a sub-procedure $\textsc{FindBiPartition}(\cdot)$ that returns a cut $(S,\overline{S})$ (where $\overline{S} = V \setminus S$) that partitions the vertex set into two equal-sized sides. Here, we implicitly assume that the number of vertices $n$ is even which is w.l.o.g.

Next, the algorithm creates a flow problem where each vertex $s \in S$ has to send exactly one unit of flow and each vertex $\overline{s} \in S$ has to receive exactly one unit of flow. We therefore introduce dummy nodes $s$ and $t$, add for each vertex $v \in S$ an edge of capacity $1$ between $s$ and $v$; and for each vertex $v \in \overline{S}$ and edge between $t$ and $v$ of capacity $1$. We set the capacity of edges in the original graph $G$ to $1/\psi$ (which we assume wlog to be integer).

\paragraph{The If Statement.} If the flow problem can be solved exactly, then we can find a path decomposition of the flow $\ff$ in $\tilde{O}(m)$ time (for example using a DFS) where each path starts in $S$ ends in $\overline{S}$ and carries one unit of flow\footnote{For simplicity, assume that the returned flow is integral.}. This defines a one-to-one correspondence between the vertices in $S$ and the vertices in $\overline{S}$. We capture this correspondences in the matching $M_i$. We will later prove the following lemma.

\begin{lemma}
If the algorithm returns after constructing $T$ matchings, for an appropriately chosen $T = \Theta(\log^2 n)$, then the graph $H$ returned by the algorithm is a $\frac{1}{2}$-expander and $G$ can be embedded into $H$ with congestion $O(\log^2 n/ \psi)$.
\end{lemma}

\paragraph{The Else Statement.} On the other hand, if the flow problem on $G$ could not be solved, then we return the min-cut of the flow problem. Such a cut can be found in $O(m)$ time by using the above reduction to an $s$-$t$ flow problem on which one can compute maximum flow $\ff$ from which the $s$-$t$ min-cut can be constructed by following the construction in the proof of \Cref{thm:maxFlowEqualsMinCut}.

It turns out that this min-cut already is a sparse cut by the way our flow problem is defined.

\begin{lemma}
If the algorithm finds a cut $(X_S, X_{\overline{S}})$, then the returned cut satisfies $|E_G(X_S \setminus \{s\}, X_{\overline{S}} \setminus \{t\})| = O(\psi)$.
\end{lemma}
\begin{proof}
First observe that since a min-cut was returned, we have that $|E_G(X_S, X_{\overline{S}})| < n/2$ (otherwise we could have routed the demands).

Let $n_s$ be the number of edges incident to the super-source $s$ that cross the cut $(X_S, X_{\overline{S}})$. Let $n_t$ be the number of edges incident to $t$ that cross the cut $(X_S, X_{\overline{S}})$.

\begin{figure}[!ht]
    \centering
    \includegraphics[scale=0.2]{./fig/FewEdgesCrossCut_lectureCutMatching.jpeg}
    \caption{Set $X_S$ is enclosed by the orange circle. The thick orange edges are in the cut and incident to super-source $s$. Thus they count towards $n_s$. Here $n_s = 2, n_t = 0$. Note that all remaining edges in the cut are black, i.e. were originally in $G$ and therefore have capacity $1/\psi$.}
    \label{fig:my_label}
\end{figure}

Observe that after taking away the vertices $s$ and $t$, the cut $(X_S \setminus \{s\}, X_{\overline{S}} \setminus \{t\})$ has less than $n/2 - n_s - n_t$ capacity. But each remaining edge has capacity $1/\psi$, so the total number of edges in the cut can be at most $\psi \cdot (n/2 - n_s - n_t)$. Since $X_S \setminus \{s\}$ is of size at least $n/2-n_s$, and $X_{\overline{S}} \setminus \{t\}$ is of size at least $n/2-n_t$, we have that the induced cut in $G$ has
\[
    \psi(X_S \setminus \{s\}) < \frac{\psi \cdot (n/2 - n_s - n_t)}{\min\{ n/2 - n_s, n/2 - n_t\}} \leq \psi.
\]
\end{proof}

\section{Constructing an Expander via Random Walks}

Next, we give the implementation and analysis for the procedure $\textsc{FindBiPartition}(\cdot)$. We start however by giving some more preliminaries.

\paragraph{Random Walk on Matchings.} Let $\{M_1, M_2, \dots, M_{T+1}\}$ be the set of matchings we compute (if we never find a cut). In the $i^{th}$-step of the lazy random walk,  we let the mass at each vertex $j$ stay put with probability $1/2$,  and otherwise traverses the edge in matching $M_i$ incident to $j$ with probability $1/2$.

We let $\pp_{j \mapsto i}^t$ denote the probability that a particle that started at vertex $j$ is at vertex $i$ after a $t$-step lazy random walk. We let $\pp_i^t = [\pp_{1 \mapsto i}^t\; \pp_{2 \mapsto i}^t\; \dots \;\pp_{n \mapsto i}^t]$. Note that for each edge $(i,j) \in M_{t+1}$, we have that
\[
\pp_i^{(t+1)} = \frac{1}{2} \pp_i^t + \frac{1}{2} \pp_j^t = \pp_j^{(t+1)}.
\]
We define the projection matrix $\proj^t = [\pp_1^{t}, \pp_2^{t}, \dots, \pp_n^{t}]^\trp$ that maps an initial probability distribution $\dd$ to the probability distribution over the vertices that the random walk visits them at step $t$. You will prove in the exercises that $\proj^t$ is \emph{doubly-stochastic}.

We say that a lazy random walk is \emph{mixing} at step $t$, if for each $i,j$, $\pp_{j \mapsto i}^t \geq 1/(2n)$.

\begin{lemma}
If $t$-step lazy random walk is \emph{mixing}, then $H = \bigcup_{i \leq t} M_i$ is a $\frac{1}{2}$-expander.
\end{lemma}
\begin{proof}
Consider any cut $(S, \overline{S})$ with $|S| \leq |\overline{S}|$. It is convenient to think about the random walks in terms of probability mass that is moved around. Observe that each vertex $j \in \overline{S}$ has to push at least $1/(2n)$ units of probability from $j$ to $i$ (by definition of mixing).

\begin{figure}[!ht]
    \centering
    \includegraphics[scale=0.15]{./fig/MixingWalkIsExpander_lectureCutMatching.jpeg}
    \caption{Each vertex $j \in \overline{S}$ sends at least $1/(2n)$ probability mass to $i$ (red arrow). But in order to transport it, it does have to push the mass through edges in the matchings $M_1, M_2, \dots, M_t$ that cross the cut.}
    \label{fig:my_label}
\end{figure}

Clearly, to move the mass from $\overline{S}$ to $S$ it has to use the matching edges that also cross the cut.

Now observe that since there are $\geq n/2$ vertices in $\overline{S}$, and each of them has to push $\geq 1/(2n)$ mass to $i$, the total amount of probability mass pushed through the cut for $i$ is $\geq 1/4$. Since there are $|S|$ such vertices $i$, the total amount of mass that has to cross the cut is $\geq |S|/4$.
But note, that after each step of the random walk, the total probability mass at each vertex is exactly $1$. Thus, at each step $t'$, each edge in $M_{t'}$ crossing the cut can push at most $1/2$ units of probability mass over the cut (and thereafter the edge is gone).

It follows that there must be at least $|S|/2$ edges in the matchings $M_1, M_2, \dots M_{t}$. But this implies that $H = \cup_i M_i$ is a $\frac{1}{2}$-expander.

\end{proof}

\paragraph{Implementing $\textsc{FindBiPartition}(\cdot)$.} We can now give away the implementation of $\textsc{FindBiPartition}(\cdot)$ which you can find below.

\begin{algorithm}[H]
    Choose random $n$-dimensional vector $\rr$ orthogonal to $\vecone$.\;
    Compute vector $\uu = \proj^t \rr$, i.e. each $\uu_i = \pp_i^t \cdot \rr$\;
    Let $S$ be the $n/2$ smallest vertices w.r.t. $\uu$; and $\overline{S}$ be the $n/2$ largest w.r.t $\uu$ (ties broken arbitrarily but consistently).\;
    \Return $(S, \overline{S})$
  \caption{\textsc{FindBiPartition}$(G, \{M_1, M_2, \dots, M_t\})$}
  \label{algo:findBiPartition}
\end{algorithm}

The central claim, we want to prove is the following: given a potential function for the random walk at step $t$
\[
    \Phi^t = \sum_{i,j} (\pp_{j \mapsto i}^t - 1/n)^2 = \sum_{i} \|\pp_{i}^t - \vecone/n\|_2^2.
\]
\begin{claim}\label{clm:mainClaimCutMatching}
In the algorithm $\textsc{SparsityCertifyOrCut}(\cdot)$, we have $\mathbb{E}[\Phi^{t} - \Phi^{(t+1)}] \geq \Omega(1/\log n) \Phi^{t}$.
\end{claim}
\begin{corollary}
For appropriate $T = \Theta(\log^2 n)$, the algorithm $\textsc{SparsityCertifyOrCut}(\cdot)$ has $\Phi^{(T+1)} \leq 4/n^2$.
\end{corollary}

The corollary follows straight-forwardly since $O(\log n)$ iterations suffice with high probability to reduce the potential by factor $\frac{1}{2}$ (you can use Chernoff here). Then, after $O(\log n)$ such phases consisting of $O(\log n)$ iterations, the potential drops to $1/n^d$ for any $d$ which then goes into the constant factors.

We further observe that this implies that $\{M_1, M_2, \dots, M_{T+1}\}$ is mixing (you can straight-forwardly prove it by a proof of contradiction), and thereby we conclude the proof of our main theorem.

Let us now give the prove of Claim \ref{clm:mainClaimCutMatching}:

\paragraph{Interpreting the Potential Drop.} Let us start by observing
\begin{align*}
     \Phi^{t} - \Phi^{(t+1)} = \sum_{i} \|\pp_{i}^t -\vecone/n\|_2^2 + \sum_{i} \|\pp_{i}^{(t+1)} -\vecone/n\|_2^2
\end{align*}
Considering now matching $M_{t+1}$,  and an edge $(i,j) \in M_{t+1}$. We can re-write the former sum as $\sum_{i} \|\pp_{i}^t -\vecone/n\|_2^2 = \sum_{(i,j) \in M_{t+1}} \|\pp_{i}^t -\vecone/n\|_2^2 + \|\pp_{j}^t -\vecone/n\|_2^2$ and we can do the same for the $t+1$-step walk probabilities. Further, note that for $(i,j) \in M_{t+1}$, we have $\pp_i^{(t+1)} = \pp_j^{(t+1)} = \frac{\pp_i^t+ \pp_j^t}{2}$. Thus,
\begin{align*}
     \Phi^{t} - \Phi^{(t+1)} = \sum_{(i,j)}  \|\pp_{i}^t -\vecone/n\|_2^2 + \|\pp_{j}^t -\vecone/n\|_2^2 - 2 \left\|\frac{\pp_i^t+ \pp_j^t}{2}\right\|_2^2.
\end{align*}
Finally, we can use the formula $\|\xx\|^2 + \|\yy\|^2 - 2 \|(\xx + \yy)/2\|^2 = \frac{1}{2} \| \xx - \yy\|^2$ term-wise to derive
\begin{align*}
     \Phi^{t} - \Phi^{(t+1)} = \frac{1}{2}\sum_{(i,j) \in M_{t+1}} \|(\pp_{i}^t -\vecone/n) - (\pp_{j}^t -\vecone/n)\|_2^2 = \frac{1}{2}\sum_{(i,j) \in M_{t+1}} \|\pp_{i}^t - \pp_{j}^t \|_2^2.
\end{align*}

\paragraph{Understanding the Random Projection.} Next, we want to further lower bound the potential drop using the random vector $\uu$. We will show that (w.p. $\geq 1-n^2$)
\begin{align}\label{eq:cutMatchingAnalysis}
     \Phi^{t} - \Phi^{(t+1)} = \frac{1}{2} \sum_{(i,j) \in M_{t+1}} \|\pp_{i}^t - \pp_{j}^t \|_2^2 \geq \frac{n-1}{32 \cdot \log n} \sum_{(i,j) \in M_{t+1}} \|\uu_i - \uu_j\|^2_2.
\end{align}

To prove this claim, we will prove this again term-wise, showing that for each pair of vertices $i,j \in V$, we have $\|\pp_{i}^t - \pp_{j}^t \|_2^2 \geq \frac{n-1}{16 \cdot \log n} \|\uu_i - \uu_j\|^2_2$ w.h.p. It will then suffice to talk a union bound over all pairs $i,j$.

To this end, let us make the following observations: since $\uu_i = \pp_i^t \cdot \rr$, we have that $\uu_i - \uu_j = (\pp_i^t - \pp_j^t) \cdot \rr$ by linearity. Also note that since $\sum_j \pp_{j \mapsto i}^t = 1$ for all $i$ (since $\proj^t$ is doubly-stochastic), we further have that the projection $(\pp_i^t - \pp_j^t)$ is orthogonal to $\vecone$.

We can now use the following statement about random vector $\rr$ to argue about the effect of projecting $(\pp_i^t - \pp_j^t)$ onto $\rr$.

\begin{theorem}\label{thm:factsGaussianAnnulus}
If $\yy$ is a vector of length $\ell$ in $\mathbb{R}^d$, and $\rr$ a unit random vector in $\mathbb{R}^d$, then
\begin{itemize}
    \item $\mathbb{E}[(\yy^\trp \rr)^2] = \frac{\ell^2}{d}$, and
    \item for $x \leq d/16$, then $\mathbb{P}[(\yy^\trp \rr)^2 \geq x\ell^2/d] \leq e^{-x/4}$
\end{itemize}
\end{theorem}

This allows us to pick $x = 16 \cdot \log n$, and we then we obtain that
\[
    \mathbb{P}\left[ ((\pp_i^t - \pp_j^t) \cdot \rr)^2 \geq  \frac{16 \log n}{n-1} \|\pp_i^t - \pp_j^t\|_2^2\right] \leq e^{-4 \log n} = n^{-4}.
\]
Multiplying both sides of the event whose probability we bound by $(n-1)/(16 \log n)$, we derive the claimed inequality  \ref{eq:cutMatchingAnalysis}.

\paragraph{Relating to the Lengths of the Projections.} Let $\mu = \max_{i \in S} \uu_i$, then we have by definition that $\mu \leq \uu_j$ for all $j \in \overline{S}$.

Now we can write
\begin{align*}
     \Phi^{t} - \Phi^{(t+1)} &\geq \frac{n-1}{32 \cdot \log n} \sum_{(i,j) \in M_{t+1}} \|\uu_i - \uu_j\|^2_2 \\
     &\geq  \frac{n-1}{32 \cdot \log n} \sum_{(i,j) \in M_{t+1}}  (\uu_i - \mu)^2 + (\uu_j - \mu)^2\\
     &=  \frac{n-1}{32 \cdot \log n}\left( \sum_{i \in V} \uu_i^2 - \mu \cdot \sum_i \uu_i + n \mu \right)
\end{align*}
by standard calculations. We then observe that $\sum_i \uu_i = \sum_i \pp_i^t \cdot \rr = \vecone \cdot \rr = 0$ by the fact that $\proj^t$ is doubly-stochastic and since $\rr$ is orthogonal to the all-ones vector. We can therefore conclude
\[
\frac{n-1}{32 \cdot \log n}\left( \sum_{i \in V} \uu_i^2 - \mu \cdot \sum_i \uu_i + n \mu \right) \geq \frac{n-1}{32 \cdot \log n} \sum_{i \in V} \uu_i^2.
\]
It remains to use the second fact of Theorem \ref{thm:factsGaussianAnnulus} to obtain that
\[
\mathbb{E}[\uu_i^2] = \mathbb{E}[(\pp_i^t \cdot \rr)^2] = \mathbb{E}[(\pp_i^t - \vecone/n) \cdot \rr)^2] = \frac{\|\pp_i^t - \vecone/n\|_2^2}{n-1}
\]
where we used again that $\rr$ is orthogonal to $\vecone$ in the second equality.

It remains to conclude
\[
\mathbb{E}[\Phi^{t} - \Phi^{(t+1)}] \geq \frac{n-1}{32 \cdot \log n} \sum_{i} \frac{\|\pp_i^t - \vecone/n\|_2^2}{n-1} = \Omega(1/\log n) \Phi^t.
\]


\documentclass{memoir}
\usepackage{linalg}
% This covers all the notes from 10-23-19 to ~11-01-19

% \begin{figure}[ht]
%     \centering
%     \incfig{riemmans-theorem}
%     \caption{Riemmans theorem}
%     \label{fig:riemmans-theorem}
% \end{figure}

\begin{document}
\chapter{Eigenvalues, Eigenvectors, and Eigenspaces}
\begin{defn}[Invariant subspace]
	Suppose $T \in \mathcal{L}(V)$. A subspace $U$ of $V$ is called \textbf{invariant} under $T$ if $u \in U$ implies $Tu \in U$.
\end{defn}
\section{Eigenvalues and Eigenvectors}
\label{sec:eigenvalues_and_eigenvectors}

\begin{defn}[Eigenvalue]

	Suppose $T  \in \mathcal{L}(V)$. A number $\lambda \in F$  is called an \textbf{eigenvalue} of $T$ if there exists $v \in V$ such that $v\neq 0$ and $Tv = \lambda v$.

\end{defn}
\begin{lemma}[Equivalent conditions]
	Suppose $V$ is finite-dimensional, $T \in \mathcal{L}(V)$, and $\lambda \in F$. Then the following are equivalent:
	\begin{itemize}
		\item $\lambda$ is an eigenvalue of $T$
		\item $T-\lambda I$ is not injective
		\item $T-\lambda I$ is not surjective
		\item $T-\lambda I$ is not invertible
	\end{itemize}
\end{lemma}
\begin{defn}[Eigenvector]
	Suppose $T \in \mathcal{L}(V)$ and $\lambda \in F$ is an eigenvalue of $T$. A vector $v\in V$ is called an \textbf{eigenvector} of $T$ corresponding to $\lambda$ if $v\neq 0$ and $Tv = \lambda v$.
\end{defn}
\begin{lemma}[Linearly independent eigenvectors]
	Let $T \in \mathcal{L}(V)$. Suppose $\lambda_1,\ldots,\lambda_m$ are distinct eigenvalues of $T$ and $v_1,\ldots,v_m$ are corresponding eigenvectors. Then $v_1,\ldots,v_m$ is linearly independent.
\end{lemma}

\section{Existence of Eigenvalues}
\label{sec:existence_of_eigenvalues}
\begin{thm}
	Every operator on a finite-dimensional, nonzero, complex vector space has an eigenvalue.
\end{thm}
\begin{defn}[Upper-triangular Matrix]
A matrix ix called \textbf{upper-triangular} if all the entries below the diagonal equal zero.

\end{defn}
\begin{thm}
	Suppose $V$ is a finite-dimensional complex vector space and $T\in \mathcal{L}(V)$. Then $T$ has an upper-triangular matrix with respect to some basis of $V$.
\end{thm}
\begin{thm}
	Suppose $T \in \mathcal{L}(V)$ has an upper-triangular matrix with respect to some basis of $V$. Then $T$ is invertible if and only if all the entries on the diagonal of that upper-triangular matrix are nonzero.
\end{thm}
\begin{thm}
	Suppose $T \in \mathcal{L}(V)$ has an upper-triangular matrix with respect to some basis of $V$. Then the eigenvalues of $T$ are precisely the entries on the diagonal of that upper-triangular matrix.
\end{thm}
\section{Eigenspaces and Diagonal Matrices}
\label{cha:eigenspaces_and_diagonal_matrices}
\begin{defn}[Eigenspace]

Suppose $T \in \mathcal{L}(V)$ and $\lambda\in F$. The \textbf{eigenspace} of $T$ corresponding to $\lambda$, denoted $E(\lambda,T)$, is defined by
\begin{align*}
	E(\lambda,T) = \textrm{null}(T-\lambda I).
\end{align*}
In other words, $E(\lambda,T)$ is the set of all eigenvectors of $T$ corresponding to $\lambda$, along with the zero vector.
\end{defn}
\begin{cor}[Sum of eigenspaces is a direct sum]
	Suppose $V$ is finite-dimensional and $T \in \mathcal{L}(V)$. Suppose also that $\lambda_1,\ldots,\lambda_m$ are distinct eigenvalues of $T$. Then
	\begin{align*}
		E(\lambda_1,T) + \ldots + E(\lambda_m,T)
	\end{align*}
	is a direct sum. Furthermore,
	\begin{align*}
		\textrm{dim} E(\lambda_1,T) + \ldots + \textrm{dim} E(\lambda_m,T) \leq \textrm{dim} V.
	\end{align*}
\end{cor}
\begin{defn}[Diagonalizable]
	An operator $T\in \mathcal{L}(V)$ is called \textbf{diagonalizable} if the operator has a diagonal matrix with respect to some basis of $V$.
\end{defn}
\begin{thm}[Conditions equivalent to diagonalizability]
	Suppose $V$ is finite-dimensional and $T \in \mathcal{L}(V)$. Let $\lambda_1,\ldots,\lambda_m$ denote the distinct eigenvalues of $T$. Then the following are equivalent:
	\begin{itemize}
		\item $T$ is diagonalizable
		\item $V$ has a basis consisting of eigenvectors of $T$
		\item There exist one-dimensional subspaces $U_1,\ldots,U_n$ of $V$, each invaraint under $T$, such that
			\begin{align*}
				V = U_1 \bigoplus \ldots \bigoplus U_n
			\end{align*}
		\item $V = E(\lambda_1,T) \bigoplus \ldots \bigoplus E(\lambda_m,T)$
		\item \textrm{dim}$V$ = \textrm{dim}$E(\lambda_1,T) + \ldots + \textrm{dim}E(\lambda_m,T)$.
	\end{itemize}
\end{thm}
\begin{cor}
	If $T \in \mathcal{L}(V)$  has \textrm{dim}$V$ distinct eigenvalues, then $T$ is diagonalizable.
\end{cor}

\section{Trace and Determinant}
\label{sec:trace_and_determinant}

The trace and determinant of linear maps are a vital tool to characterizing linear maps, and now that we have defined eigenvalues, we can work with the concepts well enough to get a deep understanding.

\begin{defn}[Trace]
	Suppose \(T \in \mathcal{L}(V)\). The \textbf{trace} of \(T\) is the sum of the eigenvalues of \(T\), with each eigenvalue repeated according to its multiplicity.
\end{defn}
Note that if our underlying field is \(R\), we have to include complex eigenvalues as well.\\

This might seem different than the traditional definition used in other linear algebra notes, but we will soon see that it corresponds exactly to the other definitions. In particular, the trace has a connection to characteristic polynomials.

\begin{prop}
	Suppose \(T \in \mathcal{L}(V)\) and let \(n = \textrm{dim}(V)\). Then \(\textrm{Tr}(T)\) is equal to the negative of the coefficient of \(x^{n-1}\) in the characteristic polynomial of \(T\).
\end{prop}

Now we will make the connection to entries of a matrix.
\begin{thm}
	Let \(T \in \mathcal{L}(V)\). Then the trace of \(\mathcal{M}(T)\) is the sum of the entries of the diagonal, and exactly equals \(\textrm{Tr}(T)\).
\end{thm}

Note that this also tells us that the trace is invariant under change of basis, of course.

\begin{cor}
	If \(A\) and \(B\) are linear maps of the same size, then
	\begin{align*}
		\textrm{Tr}(AB) = \textrm{Tr}(BA)
	\end{align*}
\end{cor}

The trace also has a useful additivity property.

\begin{prop}
	Suppose \(S,T \in \mathcal{L}(V)\). Then \(\textrm{Tr}(S+T) = \textrm{Tr}(S) + \textrm{Tr}(T)\).
\end{prop}

The trace can be useful in proving some rather strong properties. For example
\begin{prop}
	There do not exist operators \(S,T \in \mathcal{L}(V)\) such that
	\begin{align*}
		ST-TS = I.
	\end{align*}
\end{prop}
\begin{proof}
	To see this, observe that
	\begin{align*}
		\textrm{Tr}(ST-TS) &= \textrm{Tr}(ST) - \textrm{Tr}(TS)\\
				   &= \textrm{Tr}(ST) - \textrm{Tr}(ST)\\
				   &= 0
	\end{align*}
	but \(\textrm{Tr}(I) = \textrm{dim}(V)\), and so equality can never hold.
\end{proof}

\subsection{Determinant}
\label{subsec:determinant}

Once again, we will define the determinant in an abstract manner, and show it corresponds to our traditional notion of a determinant.

\begin{defn}[Determinant]
	Let \(T \in \mathcal{L}(V)\). The \textbf{determinant} of \(T\) is the product of the eigenvalues of \(T\), with each eigenvalue repeated according to its multiplicity.
\end{defn}
If our underlying field is \(\R\), then we need to include the complex eigenvalues as well.\\

Once again, the determinant has many deep connections, including to the characteristic polynomial.
\begin{prop}
	Suppose \(T \in \mathcal{L}(V)\) and let \(n = \textrm{dim}(V)\). Then \(\textrm{det}(T)\) equals \((-1)^{n}\) times the constant term of the characteristic polynomial of \(T\).
\end{prop}

This alone actually gives us some powerful consequences already.
\begin{prop}
	An operator on \(V\) is invertible if and only if its determinant is nonzero.
\end{prop}
\begin{proof}
	Recall that the operator \(T\) is invertible if and only if 0 is not an eigenvalue of \(T\). Of course, this only occurs if and only if the product of the eigenvalues of \(T\) is nonzero, and hence we have the proposition.
\end{proof}

Some take the proposition below to be the definition, but we will have it follow as a consequence.
\begin{prop}
	Let \(T \in \mathcal{L}(V)\). Then the characteristic polynomial of \(T\) equals \(\textrm{det}(xI-T)\).
\end{prop}

All of this corresponds to the traditional definition of determinants of matrices. We will omit the details to show this, however.

\begin{defn}[Determinant of a matrix]
	Let \(A\) be an \(n\)-by-\(n\) matrix given by
	\begin{align*}
		A = \begin{pmatrix} A_{1,1} & \cdots & A_{1,n}\\
		\vdots & \ddots & \vdots \\
	A_{n,1} & \cdots & A_{n,n}\end{pmatrix} .
	\end{align*}
	The \textbf{determinant} of \(A\) is defined by
	\begin{align*}
		\textrm{det}(A) = \sum_{(\sigma_1,\ldots,\sigma_n) \in \textrm{perm}(n)} \left( \textrm{sign}(\sigma_1,\ldots,\sigma_n) \right) A_{m_1,1}\ldots A_{\sigma_n, n}.
	\end{align*}
\end{defn}

\begin{prop}
	Suppose \(A\) is a square matrix and \(B\) is obtained from \(A\) by interchanging two columns. Then
	\begin{align*}
		\textrm{det}(A) = -\textrm{det}(B).
	\end{align*}
\end{prop}
We can also see that if a square matrix has two equal columns, then \(\textrm{det}(A) = 0\).

\begin{prop}
	Suppose \(S,T \in \mathcal{L}(V)\). Then
	\begin{align*}
		\textrm{det}(ST) = \textrm{det}(TS) = \textrm{det}(S) \textrm{det}(T)
	\end{align*}
\end{prop}

Many of our special operators have unique traces and determinants.

\begin{prop}
	Suppose \(V\) is an inner product space and \(S \in \mathcal{L}(V)\) is an isometry. Then \(\left| \textrm{det}(S) \right|=1\).
\end{prop}

\subsection{Volume}
\label{subsec:volume}

\begin{prop}
	Suppose \(V\) is an inner product space and \(T \in \mathcal{L}(V)\). Then
	\begin{align*}
		\left| \textrm{det}(T) \right| = \textrm{det}\left( \sqrt{T^{*}T}  \right) .
	\end{align*}
\end{prop}

We define a linear map on a set by
\begin{align*}
	T(\Omega ) := \left\{Tx \mid x \in \Omega  \right\} .
\end{align*}

\begin{prop}
	Let \(T \in \mathcal{L}(\R^{n})\) and \(\Omega \subset \R^{n}\). Then
	\begin{align*}
		\textrm{Vol}(T(\Omega )) = \left| \textrm{det}(T) \right|  \textrm{Vol}(\Omega )
	\end{align*}
\end{prop}
This also implies that isometries don't change volume.
\end{document}