\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath,amssymb,amsfonts,soul}
\usepackage{graphicx}
\usepackage{multicol}
\setlength{\oddsidemargin}{0in} \setlength{\evensidemargin}{0in}
\setlength{\topmargin}{0in} \setlength{\textheight}{8.5in}
\setlength{\textwidth}{6.5in}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
	\hskip -\arraycolsep
	\let\@ifnextchar\new@ifnextchar
	\array{#1}}
\makeatother

\begin{document}
\begin{flushleft}
	\bfseries{MATH 260, Linear Systems and Matrices, Fall `14}\\
	\bfseries{Activity 3:  Elementary Row Operations}\\
%	\bfseries{Honor Code:} \hspace{3.5in}\bfseries{Names:}\\
\end{flushleft}
\begin{flushleft}

\section*{Algebra Warmup}
Solve the following system of equations by elimination. Everytime you add two equations, or multiply by numbers, right out explicitly what you are adding together or multiplying by on the left.

\vspace{0.25in}

\begin{center}
$\begin{array}{rrrrrcr}
x&+&y&+&z&=&3\\
2x&-&2y&-&z&=&-9\\
-x&+&y&-&z&=&3
\end{array}
$
\end{center}

\newpage

\section{Turning Systems into Matrices}

Linear Algebra is a mathematical field which allows fast and easy solving of systems of linear equations by denoting operations on the entire system succinctly.  Notice that it was rather messy to work with all of those equations in the warmup excercise; imagine doing that for 5 or 10 variables and equations. There are two notations we use in Linear Algebra to condense systems: \textit{Matrix-Vector Form} and \textit{Augmented Matrices}. Let's turn the system from the warmup into Matrix-Vector Form:

\vspace{0.2in}

a) First, we'll identify all the variables of the system and put them together into one column vector of size $3 \times 1$: $\vec{\textbf{x}}=\begin{bmatrix} x\\y\\z\end{bmatrix}$

\vspace{0.2in}

b) Make a matrix of the variables' coefficients; we'll call it \textbf{A}.  It should have size $3 \times 3$.  Write it out. What would $\textbf{A}\cdot\vec{\textbf{x}}$ be?

\vspace{1.5in}

c) Write the values on the right-hand sides of the $=$ as a $3 \times 1$ column vector.  Call it $\vec{\textbf{b}}$.

\vspace{1in}

d) Using the vectors $\vec{\textbf{x}}$, $\vec{\textbf{b}}$ and the matrix \textbf{A}, express the system of equations from the warmup as a single matrix-vector equation.

\vspace{1.5in}

e) Augmented Matrix form is where we just the coefficients (\textbf{A}) and the right-hand-side ($\vec{\textbf{b}}$). We write is as: $[\textbf{A}|\vec{\textbf{b}}]$. Generally, we actually write out the numbers, as we want to manipulate the augemented matrix.  Write out the full augmented matrix for this system (it should be a $3 \times 4$ matrix with a vertical line before the last column).

\newpage

\section{Row Operations}

The main reason we want an augemented matrix is to use it for solving systems. One way to solve the system is by doing row operations to get it into \textit{row echelon form} (REF) or \textit{reduced row echelon form} (RREF). We'll define these in a bit, once we are comfortable with operations...\\

\vspace{0.1in}

\hrulefill \\
\noindent
There are three basic row operations we can perform (see page 134 of the text):\\
$R_i$ means row \textit{i} before an operation while $R_i^*$ denotes row \textit{i} after an operation.\\
1) Row swap between row \textit{i} and row \textit{j}, denoted: $R_i \leftrightarrow R_j$\\
2) Multiply a row \textit{i} by a constant \textit{c} ( with $c\neq 0$) , denoted: $R_i^*=c R_i$\\
3) Add a (multiple) of a row to another row, denoted: $R_i^*= R_i+c R_j$\\
\hrulefill \\

\vspace{0.1in}

\noindent

Lets try these out with our augmented matrix version of the warmup problem:

\vspace{0.2in}

a) Perform the following row operations in sequence:\\

\vspace{0.1in}

$\begin{array}{c}
\\
\\
R_2 \leftrightarrow R_3\\
\\
\\
\\
\end{array}
$
\hspace{0.55in}
$\begin{bmatrix}[ccc|c]
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\end{bmatrix}$
\hspace{0.2in}
$\begin{array}{c}
\\
\\
\\
\\
R_3^*=R_3+2 R_2\\
\end{array}
$
\hspace{0.25in}
$\begin{bmatrix}[ccc|c]
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\end{bmatrix}$\\
\vspace{0.1in}
$\begin{array}{c}
\\
\\
R_2^* = R_1 + R_2\\
\\
\end{array}
$
\hspace{0.25in}
$\begin{bmatrix}[ccc|c]
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\end{bmatrix}$
\hspace{0.2in}
$\begin{array}{c}
\\
\\
R_2^*= \frac{1}{2}R_2\\
\\
R_3^*= -\frac{1}{3}R_3\\
\end{array}
$
\hspace{0.5in}
$\begin{bmatrix}[ccc|c]
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}& \hspace{0.2in}\\
& & & \\
\end{bmatrix}$\\
\vspace{0.1in}
You should now have an augmented matrix with 8 non-zero entries.  The first non-zero entry in each row should also be a positive 1.  Now, let's convert this augmented matrix back into equations...\\
\vspace{0.1in}
b) Rewrite your final augmented matrix below, without the brackets or line (but leave space between each number). Now, beside each number in column 1 put an `$x$', column 2 a `$y$' and column 3 a `$z$'. Where the vertical line was, put an `=' sign.

\vspace{1.25in}

c) How does this compare to what you got for the warmup?  How do the row operations compare to what you did to solve by elimination?

\vspace{1.5in}

\newpage
\section{REF and RREF}

The matrix we got at the end of 2a was in \textit{row echelon form}. A matrix in REF has the following traits (see page 136 of the text):

\begin{enumerate}
	\item Any zero rows are at the bottom
	\item The leftmost non-zero entry of each non-zero row equals 1.\\
 (This entry is called its \textbf{pivot} or \textbf{leading 1}.)
	\item Each pivot is further to the right than the pivot in the row above it.
\end{enumerate}

a) Determine if each of the following matrices is in REF or not. If not, perform row operations to turn it into REF.\\

\vspace{0.1in}
\begin{center}
$\textbf{M}=\begin{bmatrix}
0 & 0 & 2\\
1 & 3 & 1
\end{bmatrix}
$
\hspace{0.2in}
$\textbf{T}=\begin{bmatrix}
1 & 3 & 0 & -1 \\
0 & 0 & 1 & -2
\end{bmatrix}$\\
\end{center}

\vspace{2.5in}

\textit{Reduced row echelon form} (RREF) is a even more strict form for matrices to take, which adds an additional property to the three above:\\
\vspace{0.1in}
\hrulefill \\
\indent 4. Each pivot is the only non-zero entry in its column.\\
\vspace{-3pt}
\hrulefill \\
\vspace{0.1in}
Matrix \textbf{T} from (a) is actually in RREF.\\

b) What additional row operation(s) are required to turn matrix \textbf{M} into RREF?

\newpage

\section{Bringing it Together}

Take the following system of equations, write it first in matrix-vector from, then as an augmented matrix. Finally, use row operations to turn it into RREF:

\begin{center}
$\begin{array}{rrrrrrr}
x_1 & + & x_2 & + & 2 x_3 & = & 1\\
2 x_1 & - & x_2 & + & x_3 & = & 2\\
4 x_1 & + & x_2 & + & 5 x_3 & = & 4
\end{array}$
\end{center}

\end{flushleft}
\end{document}

Fall 2014 - Capaldi A/Activities/Activity03_ElemRowOps.tex


\chapter{\projcur Programs}
% \section{Program}
\section{Ridgelet Transform}
\subsection{im\_radon}
\index{im\_radon}
Program {\em im\_radon} makes an (inverse-) Radon transform of a square
$n \times n$ image.
The output file which contains the transformation has a
suffix, .rad. If the output file name
given by the user does not contain this suffix, it is automatically
added. The ``.rad'' file is a FITS format file, and can be manipulated by
any package implementing the FITS format, or can be converted to another
format using the {\em im\_convert} program.
For the two first Radon transform methods, the user can change the
number of directions and the resolution. For other methods, the
number of directions and the resolution are fixed, and the
x and y options are not valid. Options f, w and s allow the user to perform
a filtering-backprojection. They are valid only when the selected Radon
method is the second one. ``w'' fixes the width of the filter and the
``s'' is the sigma parameter of the Gaussian filter.
{\bf
\begin{center}
 USAGE:  im\_radon  options image\_in trans\_out
\end{center}}
where options are:
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-m type\_of\_radon\_method]}
{\small
\begin{enumerate}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item  Radon transform (resp.\ backprojection) in spatial domain. \\
       By default, the output image is a $2n \times n$ image.
\item  Radon projection in spatial domain and reconstruction in Fourier domain.
       By default, the output image is a $2n \times n$ image.
       The reconstruction is available only for image with
       a size $n$ being a power of 2.
\item  Radon transformation and reconstruction in Fourier space
       (i.e.\ Linogram). \\
       The output is a
       $2n \times n$ image. The number of rows is multiplied by two.
\item  Finite Radon Transform. \\
       The output image is a $(n+1) \times n$ image. The input image size $n$
       must be a prime number.
\item  Slant Stack Radon transform. \\
       The output image has twice the number of rows and twice the number
       of columns of the input image.
       The output is a $2n \times 2n$ image.
       The reconstruction is not available with this transform.
\end{enumerate}}
Default is Radon transformation and reconstruction in Fourier space.

\item {\bf [-y OutputLineNumber]} \\
For the RADON transform, OutputLineNumber = number of projection,
 and default is twice the number of input image rows. Only valid for Radon
methods 1 and 2.\\
% For the inverse RADON transform, OutputLineNumber = number of lines,
% and default is the input image column number.

\item {\bf [-x OutputColumnNumber]} \\
For the RADON transform, OutputLineNumber = number of pixels per projection,
and default is the input image column number. Only valid for Radon
methods 1 and 2.\\
% For the inv. RADON transform, OutputLineNumber = number of column,
% and default is the input image column number.

\item {\bf [-r]} \\
Inverse Radon transform.
\item {\bf [-f]} \\
Filter each scan of the Radon transform. Only valid for Radon
method 2.
\item {\bf [-w FilterWidth]} \\
Filter width. Only valid for Radon
method 2. Default is 100.
\item {\bf [-s SigmaParameter} \\
 Sigma parameter for the filtering. Only valid for Radon
method 2. Default is 10.
\item {\bf [-v]} \\
Verbose. Default is no
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item im\_radon image.fits trans\\
Apply the Radon transform to an image.
\item im\_info -r trans.rad rec\\
 Reconstruct an image from its Radon transform.
\end{itemize}

\subsection{rid\_trans}
\index{rid\_trans}
Program {\em rid\_trans} makes the  ridgelet transform
(and the inverse when -r option is set).
The output file which contains the transformation has a
suffix, .rid. If the output file name
given by the user does not contain this suffix, it is automatically
added. The ``.rid'' file is a FITS format file, and can be manipulated by
any package implementing the FITS format, or can be converted to another
format using the {\em im\_convert} program.
The default transform is the second one
(RectoPolar Ridgelets using a  FFT based WT).
The two first transform are based on the RectoPolar
(i.e. linogram) radon transform, but the first applies a standard
bi-orthogonal wavelet transform (WT) on the Radon image rows, while the
second uses the Fourier-based WT which introduces a redundancy of 2.
For an $n \times n$ image, the output has $2n$ lines and $n$ column
with the first transform, and is a $2n \times 2n$ image for the second.
When the overlapping is set, the size is doubled in each direction.

{\bf
\begin{center}
 USAGE: rid\_trans options image\_in trans\_out
\end{center}}
where options are:

\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-t type\_of\_ridgelet]}
\begin{enumerate}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item RectoPolar Ridgelet Transform using a standard bi-orthogonal WT.
\item RectoPolar Ridgelet Transform using a FFT based Pyramidal WT.
\item Finite ridgelet transform.
\end{enumerate}
Default is 2.
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the wavelet transform.
 Default is automatically calculated.
\item {\bf [-b BlockSize]} \\
Block Size. Default is image size.
\item {\bf [-i]} \\
Print statistical information about each band. Default is no.
\item {\bf [-O]} \\
 No block overlapping. Default is no. When this option is set, the
 number of rows and columns is multiplied by two.
\item {\bf [-r]} \\
Inverse Ridgelet transform.
\item {\bf [-x]} \\
 Write all bands separately as images in the FITS format with prefix 'band\_j'
(j being the band number).
\item {\bf [-v]} \\
Verbose. Default is no
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item rid\_transform image.fits trans\\
Apply the Ridgelet transform to an image.
\item rid\_transform -r trans.rid rec\\
 Reconstruct an image from its Ridgelet transform.
\end{itemize}

\subsection{rid\_stat}
\index{rid\_stat}
Program {\em rid\_stat} makes the  ridgelet transform, and
gives statistical information on the ridgelet coefficients.
At each scale, it caculates the standard deviation, the skewness,
the kurtosis, the minimum, and the maximum. The output file is a
fits file containing a two-dimensional array $T[J-1,5]$ ($J$ being the
number of scales), with the following syntax:
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item $T[j,0] = $ standard deviation of the jth ridgelet band.
\item $T[j,1] = $ skewness of the jth ridgelet band.
\item $T[j,2] = $ kurtosis of the jth ridgelet band.
\item $T[j,3] = $ minimum of the jth ridgelet band.
\item $T[j,4] = $ maximum of the jth ridgelet band.
\end{itemize}
The last ridgelet scale is not used.
If the ``-A'' option is set, these statistics are calculated only for
the ridgelet coefficients relative the specified angle.
{\bf
\begin{center}
 USAGE: rid\_stat options image\_in trans\_out
\end{center}}
where options are:

\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-t type\_of\_ridgelet]}
\begin{enumerate}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item RectoPolar Ridgelet Transform using a standard bi-orthogonal WT.
\item RectoPolar Ridgelet Transform using a FFT based Pyramidal WT.
\item Finite ridgelet transform.
\end{enumerate}
Default is 2.
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the wavelet transform.
 Default is automatically calculated.
\item {\bf [-b BlockSize]} \\
Block Size. Default is 16.
\item {\bf [-O]} \\
   Use overlapping block. Default is no.
\item {\bf [-A Angle]} \\
 Statistics for a given angle. The value must be given  in degrees.
 Default is no, statistics are calculated from all coefficients.
\item {\bf [-v]} \\
Verbose. Default is no
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item rid\_stat -v  image.fits tabstat\\
\end{itemize}

\subsection{rid\_filter}

Program {\em rid\_filter} filters an image using the ridgelet transform.
\begin{center}
 USAGE:  rid\_filter options image\_in imag\_out
\end{center}
where options are
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-t type\_of\_ridgelet]}
\begin{enumerate}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item RectoPolar Ridgelet Transform using a standard bi-orthogonal WT.
\item RectoPolar Ridgelet Transform using a FFT based pyramidal WT.
\item Finite ridgelet transform.
\end{enumerate}
Default is 2.
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the wavelet transform.
 Default is automatically calculated.
\item {\bf [-h]} \\
Apply the ridgelet transform only on the high frequencies.
Default is no.

\item {\bf [-b BlockSize]} \\
Block Size. Default is image size.

\item {\bf [-F FirstDetectionScale]} \\
 First detection scale. Default is 1.

% \item {\bf [-i NbrIter]}  \\
%  Number of iteration for the constraint reconstruction.
%   Default is no.
% \item {\bf [-G RegulParam]}  \\
%   Regularization parameter for the constraint reconstruction.
%  Default is 0.2.
% \item {\bf [-C ConvergParam]}  \\
%  Convergence parameter. Default is 1.

\item {\bf [-s Nsigma]} \\
False detection rate. The false detection rate for a detection is given
\begin{eqnarray}
\epsilon =  \mbox{erfc}( NSigma / \sqrt{2})
\end{eqnarray}
{\em Nsigma} parameter allows us to express the false detection rate
even if it is not Gaussian noise. \\
Default is 3.

\item {\bf [-g sigma]} \\
Gaussian noise: sigma = noise standard deviation.  \\
 Default is automatically estimated.

\item {\bf [-p]} \\
Poisson noise.

\item {\bf [-O]}  \\
Do not apply block overlapping. By default, block overlapping is used.

\item {\bf [-v]} \\
Verbose.
\end{itemize}
\subsubsection*{Examples:}
\begin{itemize}
\item rid\_filter  image.fits fima\\
Filter an image using all default options.
\item rid\_filter -h -s5 image.fits fima\\
Five sigma filtering, filtering only the high frequencies.
\end{itemize}

\section{Curvelet Transform}
\subsection{cur\_trans}
\index{cur\_trans}
Program {\em cur\_trans} determines the  curvelet transform
(and the inverse when -r option is set).
The output file which contains the transformation has a
suffix, .cur. If the output file name
given by the user does not contain this suffix, it is automatically
added. The ``.cur'' file is a 3D FITS format file, and can be manipulated by
any package implementing the FITS format.
The curvelet transform uses the ridgelet transform, and the default
ridgelet transform is the RectoPolar one with a FFT based pyramidal WT.

{\bf
\begin{center}
 USAGE: cur\_trans options image\_in trans\_out
\end{center}}
where options are:
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-t type\_of\_ridgelet]}
\begin{enumerate}
\baselineskip=0.4truecm
\item RectoPolar Ridgelet Transform using a standard bi-orthogonal WT.
\item RectoPolar Ridgelet Transform using a FFT based pyramidal WT.
\item Finite ridgelet transform.
\end{enumerate}
Default is 2.
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the 2D wavelet transform.
 Default is 4.
\item {\bf [-N number\_of\_scale]} \\
 Number of scales used in the ridgelet transform.
 Default is automatically calculated.
\item {\bf [-b BlockSize]}  \\
Block Size. Default is 16.
\item {\bf [-r]}  \\
Inverse Curvelet transform.
\item {\bf [-i]}  \\
Print statistical information about each band. Default is no.
\item {\bf [-O]}  \\
 Block overlapping. Default is no.
\item {\bf [-x]} \\
 Write all bands separately as images in the FITS format with prefix 'band\_j'
(j being the band number).
\item {\bf [-v]} \\
Verbose. Default is no.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item cur\_trans -i image.fits trans\\
Curvelet transform of an image.
\item cur\_trans -r  trans.cur rec\\
Image reconstruction from its curvelet transform.
\end{itemize}

\subsection{cur\_stat}
\index{cur\_stat}
Program {\em cur\_stat} determines the  curvelet transform, and
gives statistical information on the curvelet coefficients.
At each scale, it caculates the standard deviation, the skewness,
the kurtosis, the minimum, and the maximum. The output file is a
FITS file containing a two-dimensional array $T[J-1,5]$ ($J$ being the
number of bands), with the following syntax:
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item $T[j,0] = $ standard deviation of the jth ridgelet band.
\item $T[j,1] = $ skewness of the jth ridgelet band.
\item $T[j,2] = $ kurtosis of the jth ridgelet band.
\item $T[j,3] = $ minimum of the jth ridgelet band.
\item $T[j,4] = $ maximum of the jth ridgelet band.
\end{itemize}
{\bf
\begin{center}
 USAGE: cur\_stat options image\_in trans\_out
\end{center}}
where options are:
\begin{itemize}
\baselineskip=0.4truecm
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the wavelet transform.
 Default is automatically calculated.
\item {\bf [-b BlockSize]} \\
Block Size. Default is 16.
\item {\bf [-O]} \\
   Use overlapping block. Default is no.
\item {\bf [-v]} \\
Verbose. Default is no
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item cur\_stat -v  image.fits tabstat\\
\end{itemize}

\subsection{cur\_filter}
\index{cur\_filter}

Program {\em cur\_filter} filters an image using the curvelet transform.
\begin{center}
 USAGE:  cur\_filter options image\_in imag\_out
\end{center}
where options are
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-t type\_of\_ridgelet]}
\begin{enumerate}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item RectoPolar Ridgelet Transform using a standard bi-orthogonal WT.
\item RectoPolar Ridgelet Transform using a FFT based Pyramidal WT.
\item Finite ridgelet transform.
\end{enumerate}
Default is 2.
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the 2D wavelet transform.
 Default is 4.

\item {\bf [-N number\_of\_scale]} \\
 Number of scales used in the ridgelet transform.
 Default is automatically calculated.

\item {\bf [-b BlockSize]}  \\
Block Size. Default is 16.

\item {\bf [-g sigma]} \\
Gaussian noise: sigma = noise standard deviation.  \\
 Default is automatically estimated.

\item {\bf [-s Nsigma]} \\
False detection rate. \\
Default is 3.

\item {\bf [-O]}  \\
Do not apply block overlapping. By default, block overlapping is used.

\item {\bf [-P]}  \\
 Supress the positivity constraint. Default is no.

\item {\bf [-I NoiseFileName]}  \\
If the noise is stationary, the program can estimate the correct
thresholds from a realization of the noise.

\item {\bf [-v]} \\
Verbose
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item cur\_filter image.fits sol\\
Curvelet filtering of an image.
\item cur\_filter -n 5 -s4  image.fits sol\\
Curvelet filtering of an image, using five resolution levels, and
a 4-sigma detection.
\end{itemize}

\subsection{cur\_colfilter}
\index{cur\_colfilter}

Program {\em cur\_colfilter} filters a
color image using the curvelet transform.
\begin{center}
 USAGE:  cur\_colfilter options image\_in imag\_out
\end{center}
where options are
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-n number\_of\_scale]} \\
 Number of scales used in the 2D wavelet transform.
 Default is 4.

\item {\bf [-N number\_of\_scale]} \\
 Number of scales used in the ridgelet transform.
 Default is automatically calculated.

\item {\bf [-b BlockSize]}  \\
Block Size. Default is 16.

\item {\bf [-g sigma]} \\
Gaussian noise: sigma = noise standard deviation.  \\
 Default is automatically estimated.

\item {\bf [-s Nsigma]} \\
False detection rate. \\
Default is 3.

\item {\bf [-O]}  \\
Do not apply block overlapping. By default, block overlapping is used.

\item {\bf [-v]} \\
Verbose
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item cur\_colfilter image.fits sol\\
Curvelet transform of a color image.
\end{itemize}

\subsection{cur\_contrast}
\index{cur\_contrast}

Program {\em cur\_contrast} filters a color image using the curvelet transform.
\begin{center}
 USAGE:  cur\_contrast options image\_in imag\_out
\end{center}
where options are
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-n number\_of\_scales]} \\
Number of scales used in the wavelet transform.
Default is 4.
\item {\bf [-N number\_of\_scales]} \\
Number of scales used in the ridgelet transform.
Default is automatically calculated.
\item {\bf [-b BlockSize]} \\
Block size used by the curvelet transform. Default is 16.
\item {\bf [-O]} \\
Use overlapping block. Default is no.
\item {\bf [-g sigma]} \\
Noise standard deviation. Only used when filtering is performed.
Default is automatically estimated.
\item {\bf [-s NSigmalLow]} \\
 Coefficient $<$ NSigmalLow*SigmaNoise is not modified.
 Default is   5.
\item {\bf [-S NSigmalUp]} \\
 Coefficient $>$ NSigmalUp*SigmaNoise is not modified.
 Default is  20.
\item {\bf [-M MaxCoeff]} \\
If MaxBandCoef is the maximum coefficient in a given curvelet band,
 Coefficient $>$ MaxBandCoef*MaxCoeff is not modified.
 Default is 0.5.
\item {\bf  [-P P\_parameter]} \\
Determine the degree on non-linearity. P must be in ]0,1[.
Default is 0.5.
\item {\bf [-T P\_parameter]} \\
 Curvelet coefficent saturation parameter. T must be in [0,1].
Default is 0.
\item {\bf [-c]} \\
By default a sigma clipping is performed. When this option is set, no
sigma clipping is performed.
\item {\bf [-K ClippingValue]} \\
Clipping value. Default is 3.
\item {\bf [-L Saturation]} \\
Saturate the reconstructed image.
A coefficient larger than Saturation*MaxData is set to Saturation*MaxData.
Default is  1. If L is set to 0, then no saturation is applyied.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item cur\_contrast image.fits image\_out.fits\\
Enhance the contrast using the curvelet transform.
\item cur\_contrast -O image.fits image\_out.fits\\
Enhance the contrast using the curvelet transform and block overlapping.
\item cur\_contrast -M 0.8 image.fits image\_out.fits\\
Enhance more the contrast.
\end{itemize}

\subsection{cur\_colcontrast}
\index{col\_colcontrast}
The program {\em col\_colcontrast} enhances the contrast of a color image
using the curvelet transform.
The command line is:
{\bf
\begin{center}
 USAGE: cur\_colcontrast option in\_image out\_image
\end{center}}
where options are:
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item {\bf [-n number\_of\_scales]} \\
Number of scales used in the wavelet transform.
Default is 4.
\item {\bf [-N number\_of\_scales]} \\
Number of scales used in the ridgelet transform.
Default is automatically calculated.
\item {\bf [-b BlockSize]} \\
Block size used by the curvelet transform. Default is 16.
\item {\bf [-O]} \\
Use overlapping block. Default is no.
\item {\bf [-g sigma]} \\
Noise standard deviation.
Default is automatically estimated.
\item {\bf [-s NSigmalLow]} \\
 Coefficient $<$ NSigmalLow*SigmaNoise is not modified.
 Default is   5.
\item {\bf [-S NSigmalUp]} \\
 Coefficient $>$ NSigmalUp*SigmaNoise is not modified.
 Default is  20.
\item {\bf [-M MaxCoeff]} \\
If MaxBandCoef is the maximum coefficient in a given curvelet band,
 Coefficient $>$ MaxBandCoef*MaxCoeff is not modified.
 Default is 0.5.
 \item {\bf  [-P P\_parameter]} \\
Determine the degree of non-linearity. P must be in ]0,1[.
Default is 0.5.
\item {\bf [-T P\_parameter]} \\
 Curvelet coefficent saturation parameter. T must be in [0,1].
Default is 0.
\item {\bf [-c]} \\
By default a sigma clipping is performed. When this option is set, no
sigma clipping is performed.
\item {\bf [-K ClippingValue]} \\
Clipping value. Default is 3.
\item {\bf [-L Luminance\_Saturation]} \\
Values in the luminance map which are
larger than Saturation*MaxData are set to Saturation*MaxData.
Default is  1.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item cur\_colcontrast image.tiff image\_out.tiff\\
Enhance the contrast using the curvelet transform.
\item cur\_colcontrast -n 5 image.tiff image\_out.tiff\\
Ditto, but use five scales instead of four.
\item cur\_colcontrast -M 0.9 image.tiff image\_out.tiff\\
Enhance more the contrast.
\end{itemize}

\section{Combined Filtering}
\subsection{cb\_filter}
\index{cb\_filter}
Program {\em cb\_filter} filters an image corrupted by Gaussian noise by
 the combined filtering method. By default, the undecimated  bi-orthogonal WT
 and the curvelet transform are used. The number of iterations is defaulted
 10. In general, the algorithm converges with less than six iterations.
If the ``-T'' option is set, the Total Variation is minimized instead of
the $l_1$ norm of the multiscale coefficients.
A deconvolution can also be performed using the ``-P'' option. In this
case, a division is first done in Fourier space between the
input image and the point spread function. All Fourier components with
a norm lower than $\epsilon$ (default value is $10^{-3}$) are set to zero.
Then the deconvolved image is filtered by the combined filtering method
using the new noise properties (still Gaussian, but not white).

{\bf
\begin{center}
 USAGE: cb\_filter options image\_in trans\_out
\end{center}}
where options are:
\begin{itemize}
\baselineskip=0.4truecm
\itemsep=0.1truecm
 \item {\bf [-t TransformSelection]}
\begin{enumerate}
\baselineskip=0.4truecm
\itemsep=0.1truecm
\item A trous algorithm
\item Bi-orthogonal WT with 7/9 filters
\item Ridgelet transform
\item Curvelet transform
\item Mirror Basis WT
% \item Multiscale Ridgelet
%\item Cosinus transform
%\item Pyramidal Median transform
\end{enumerate}

\item {\bf [-n number\_of\_scales]} \\
Number of scales used in the \`a trous wavelet transform
%, the PMT and
 and the curvelet transform.
% Number of ridgelet in the multi-ridgelet transform.
Default is 4.

\item {\bf [-b BlockSize]}  \\
 Block Size in the ridgelet transform.
Default is image size.
% Starting Block Size in the multi-ridgelet transform. Default is 8.

\item {\bf [-i NbrIter]}  \\
Number of iterations. Default is 10.

\item {\bf [-F FirstDetectionScale]} \\
First detection scale in the ridgelet transform.
Default is 1.

\item {\bf [-k]} \\
Kill the last scale in ridgelet. % , and multiscale ridgelet transform.
Default no.

\item {\bf  [-K]} \\
Kill last scale in the \`a trous algorithm and the curvelet. % and the PMT
Default no.

\item {\bf  [-L FirstSoftThreshold]} \\
First soft thresholding value. Default is 0.5.

\item {\bf  [-l LastSoftThreshold]} \\
Last soft thresholding value. Default is 0.5.

\item {\bf  [-u]} \\
 Number of undecimated scales in the WT.
 Default is 1.

\item {\bf [-s Nsigma]} \\
False detection rate. Default is 4.

\item {\bf [-g sigma]} \\
Gaussian noise: sigma = noise standard deviation.  \\
 Default is automatically estimated.

% \item {\bf [-p]} \\
% Poisson Noise. Default is no (Gaussian).

\item {\bf [-O]}  \\
No block overlapping. Default is no.

\item {\bf [-T]}  \\
 Minimize the Total Variation instead of the L1 norm.

\item {\bf [-P PsfFile]}  \\
Apply a deconvolution using the PSF in the file PsfFile.

\item {\bf [-e Eps]}  \\
 Remove frequencies with $|P P^*| < \epsilon $.
 Default is $10^{-3}$.

\item {\bf [-C TolCoef]}  \\
 Default is 0.5.

\item {\bf [-v]} \\
Verbose. Default is no.
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item cb\_filter image.fits sol\\
Image filtering by the combined filtering method, using both
the curvelet and wavelet transform.
\end{itemize}


\chapter{Introduction}

In machine learning problem
settings, we
are often presented with data
but additionally have
information about how the
data was collected or generated.
Furthermore, we may have
knowledge or access
to domain expertise that
could inform a learning algorithm.
Traditionally,
one way of incorporating
prior knowledge or domain
expertise into machine
learning algorithms
is by formulating them as probabilistic
graphical models, which
offer flexible avenues for
incorporating assumptions about data.
Take, for example, if we are
tasked with discovering
clusters in a dataset, but have
prior knowledge that
the features of the data are
disentangled or independent,
we can incorporate that
information into the
prior distribution
over cluster components.

This strategy, however,
has major downsides,
namely that the types
of assumptions that
can be incorporated
into probabilistic graphical
models have been historically
limited to generative models in which
Bayesian inference is tractable.
Thus, in scenarios where
the data is high-dimensional
and exhibits complex structure,
we are forced to make
restrictive assumptions
that enable tractable inference,
but limit the capacity
of our model.

On the other hand,
neural networks have emerged
as a dominant force
in machine learning,
thanks to their
ability to scale to large datasets
and their empirical success on complex
data like images and text.
Incorporating prior knowledge
or domain expertise into
deep learning approaches
has often taken the form of
custom neural network layers or
architectures that are tailored
to the task at hand,
and although these strategies
have seen empirical success,
they are often ad-hoc
solutions and do not
leverage the explicit assumptions
and modeling of uncertainty that
probabilistic graphical models offer.
Combining deep learning
methods with probabilistic graphical
models has thus been
recent topic of interest
with many open problems
and challenges.

Much work has gone into investigating
which models are tractable
and how to approximate
intractable ones.
One of the most prominent
methods to emerge in unsupervised learning
is the variational autoencoder \citep[VAE; ][]{Kingma2014, Rezende2014},
which frames autoencoding
as a probabilistic latent variable model.
The VAE models
through a generative process
where latent codes are sampled
from a prior distribution,
and are then passed through a
neural network decoder.
The encoder is used for inference,
approximating the posterior
distribution of codes given data.

The VAE is a stepping stone
for incorporating
neural networks into
statistical learning,
but in its original form,
has very simple assumptions.
The statistical learning literature,
on the other hand, has
explored a wide variety of
models and structures for data.
In this thesis, we
motivate and discuss
the use of Bayesian structured priors
and the algorithmic challenges
in incorporating them
with deep generative models.
The combination
of a Bayesian structured
prior with a VAE
results
in a class of models called
Bayesian structured representation learning
models.

In Part I, we introduce the
core ideas and foundations for Bayesian structure
learning and present a contribution
in the space of interactive structure learning.
In Part II, we motivate and discuss
algorithms and models used in Bayesian structured
representation learning.


\section{Kinematic ages}
\subsection{Calculating velocity dispersions}
\label{sec:velocity_dispersion}

A kinematic age can be calculated from the velocity dispersion, \ie\ standard
deviation, of a group of stars.
These velocity dispersions can then be converted into an age using an AVR
\citep[\eg][]{holmberg2009, yu2018}.
Kinematic ages represent the {\it average age} of a group of stars and are
most informative when stars are grouped by age.
If a group of stars have similar ages, their kinematic age will be close
the age of each individual.
On the other hand, the kinematic age of a group with large age variance will
not provide much information about the ages of individual stars.
Velocity distributions themselves do not reveal whether a group of stars have
similar or different ages, since either case the velocities are
Gaussian-distributed.
Fortunately however, we can group \kepler\ stars by age using the implicit
assumption that underpins gyrochronology: that stars with the same rotation
period and color are the same age.
% We discuss the implications of this assumption and cases where it doesn't
% apply in the Discussion of this paper (section \ref{sec:discussion}).

In this paper, we use the kinematic ages published in \citet{lu2021}.
In that work, the kinematic age of each star in our sample was calculated by
placing it in a bin with other stars with similar rotation periods, effective
temperatures, absolute Gaia magnitudes and Rossby numbers.
The kinematic age of each star was estimated by calculating the velocity
dispersions of stars with these similar parameters, then using an AVR to
calculate a corresponding age \citep{yu2019}.
The bin size was optimized using a number of Kepler stars with asteroseismic
ages.

We used the \citet{yu2018} AVR to convert velocity dispersion to age.
This relation was calibrated using the ages and velocities of red clump stars.
They divided their sample into metal rich and poor subsets, and calibrated
separate AVRs for each, plus a global AVR.
Their AVR is a power law:
\begin{equation}
    \sigma_{vz} = \alpha t ^\beta,
\end{equation}
where $\alpha$ and $\beta$ take values (6.38, 0.578) for metal rich stars
(3.89, 1.01) for metal poor stars, and (5.47, 0.765) for all stars.

We used 1.5$\times$ the Median Absolute Deviation (MAD) of velocities, which
is a robust approximation to the standard deviation and is less sensitive to
outliers.
Velocity outliers could be binary stars or could be generated by
underestimated parallax or proper motion uncertainties.

Figure \ref{fig:kin_and_clusters} displays the data we used to calibrate our
gyrochronology model in \prot-\teff\ space.
Kepler field stars are shown as small points, and cluster stars are larger
points with black outlines.
Points are colored by either their kinematic ages or cluster ages.
The left- and right-hand panels have a linear and logarithmic y-axis,
respectively.

\begin{figure}
\caption{
    The calibration data.
Kepler field stars are shown as small points, and cluster stars are larger
points with black outlines.
Points are colored by either their kinematic ages or cluster ages.
The left- and right-hand panels have a linear and logarithmic y-axis,
respectively.
}
  \centering \includegraphics[width=1\textwidth]{kin_and_clusters_log_lin}
\end{figure}


\chapter{Nomenclature}
\markboth{NOMENCLATURE}{}

\textbf{{\large Upper-case Roman}}

\begin{longtable}[l]{ll}
$\mathcal{B}$ & Solid body governing equation\tabularnewline
$C_D$ & Drag coefficient\tabularnewline
$C_L$ & Lift coefficient\tabularnewline
$C_s$ & Smagorinsky model constant\tabularnewline
$\mathcal{CC}$ & Correlation coefficient\tabularnewline
$D$ & Cylinder diameter\tabularnewline
$E$ & Kinetic energy \tabularnewline
$\mathcal{F}$ & Fluid governing equation\tabularnewline
$F_x$ & Drag force\tabularnewline
$F_y$ & Lift force\tabularnewline
$H$ & Helicity \tabularnewline
$II, III$ & Non-zero invariants of the anisotropic Reynolds-stress tensor \tabularnewline
$K_\epsilon$ & BDIM convolution kernel \tabularnewline
$L$ & Characteristic length\tabularnewline
$L_{11}$ & Integral lengthscale\tabularnewline
$L_a$ & Spanwise-averaging length\tabularnewline
$L_z$ & Cylinder span\tabularnewline
$M$ & Number of time steps\tabularnewline
$\mathcal{M}$ & Meta-equation combining fluid and solid governing equations\tabularnewline
$N$ & Number of grid points\tabularnewline
$P$ & Spanwise-averaged pressure\tabularnewline
$R$ & Ratio of mean vortex-stretching term to mean vortex-advection term\tabularnewline
$Re$ & Reynolds number \tabularnewline
$\mathcal{S}$ & 3-D Navier--Stokes spatial operator \tabularnewline
$\tilde{\mathcal{S}}$ & 2-D Navier--Stokes spatial operator \tabularnewline
$\mathcal{S}^R$ & Perfect closure \tabularnewline
$S_{ij}$ & Rate-of-strain tensor \tabularnewline
$St$ & Strouhal number \tabularnewline
$\vect{U}$ & Spanwise-averaged velocity vector field \tabularnewline
$U$ & Characteristic velocity\tabularnewline
$U$ & Spanwise-averaged velocity component along the $x$ spatial direction\tabularnewline
$U_\infty$ & Free-stream velocity\tabularnewline
$V$ & Spanwise-averaged velocity component along the $y$ spatial direction\tabularnewline
$W$ & Spanwise-averaged velocity component along the $z$ spatial direction\tabularnewline
$\mathrm{X}_n$ & Model input set\tabularnewline
$\mathrm{Y}_n$ & Model output set\tabularnewline
$Z$ & Enstrophy \tabularnewline
\end{longtable}

\textbf{{\large Lower-case Roman}}

\begin{longtable}[l]{ll}
$b_{ij}$ & Anisotropic Reynolds-stress tensor \tabularnewline
$d$ & Distance function\tabularnewline
$f_s$ & Vortex-shedding frequency \tabularnewline
$\vect{h}$ & Force vector field combining convective and viscous forces\tabularnewline
$k$ & Turbulence kinetic energy \tabularnewline
$p$ & Pressure field \tabularnewline
$\vect{r}$ & Distance vector\tabularnewline
$r$ & Radial direction in the cylindrical coordinates frame\tabularnewline
$t$ & Time\tabularnewline
$t^*$ & Convective time ($t$ scaled with $U$ and $L$)\tabularnewline
$\vect{u}$ & Velocity vector field\tabularnewline
$u$ & Velocity component along the $x$ spatial direction\tabularnewline
$\vect{u}_b$ & Velocity boundary condition on solid walls\tabularnewline
$\vect{u}_s$ & Straining velocity vector field\tabularnewline
$\vect{u}_v$ & Columnar vortex velocity vector field\tabularnewline
$v$ & Velocity component along the $y$ spatial direction\tabularnewline
$w$ & Velocity component along the $z$ spatial direction\tabularnewline
$\vect{x}$ & Spatial coordinates vector \tabularnewline
$x$ & Spatial coordinate aligned with the principal (streamwise) flow direction\tabularnewline
$y$ & Spatial coordinate aligned with the transverse (crossflow) flow direction\tabularnewline
$z$ & Spatial coordinate aligned with the lateral (spanwise) flow direction\tabularnewline
\end{longtable}

\textbf{{\large Upper-case Greek}}

\begin{longtable}[l]{ll}
$\Gamma$ & Circulation\tabularnewline
$\Delta$ & LES filter size\tabularnewline
$\vect{\Omega}$ & Spanwise-averaged vorticity vector field \tabularnewline
$\Omega$ & A general spatial domain \tabularnewline
$\Omega_f$ & Fluid subdomain \tabularnewline
$\Omega_b$ & Solid body subdomain \tabularnewline
\end{longtable}

\textbf{{\large Lower-case Greek}}

\begin{longtable}[l]{ll}
$\gamma$ & Rate of strain\tabularnewline
$\delta_{ij}$ & Kronecker delta tensor \tabularnewline
$\delta t$ & Temporal resolution\tabularnewline
$\delta x$ & Spatial resolution\tabularnewline
$\delta_\epsilon$ & Zeroth-moment of the BDIM convolution kernel \tabularnewline
$\epsilon$ & Turbulence dissipation rate \tabularnewline
$\epsilon_T$ & Trapezoidal quadrature error \tabularnewline
$\vect{\zeta}^R$ & Spanwise-stress residual vector in the spanwise-averaged VTE \tabularnewline
$\eta$ & Invariant of the anisotropic Reynolds-stress tensor \tabularnewline
$\eta$ & Kolmogorov lengthscale \tabularnewline
$\theta$ & Angular direction in the cylindrical coordinates frame\tabularnewline
$\theta_l$ & Lower separation angle on the cylinder surface\tabularnewline
$\theta_u$ & Upper separation angle on the cylinder surface\tabularnewline
$\vect{\kappa}$ & Wavenumber vector\tabularnewline
$\kappa$ & Wavenumber\tabularnewline
$\lambda_z$ & Spanwise correlation length \tabularnewline
$\mu$ & Dynamic viscosity\tabularnewline
$\nu$ & Kinematic viscosity\tabularnewline
$\nu_{e}$ & Effective kinematic eddy viscosity in iLES\tabularnewline
$\nu_{t}$ & Kinematic eddy viscosity\tabularnewline
$\xi$ & Invariant of the anisotropic Reynolds-stress tensor \tabularnewline
$\rho$ & Density\tabularnewline
$\sigma$ & Standard deviation\tabularnewline
$\tau$ & Turbulence timescale\tabularnewline
$\vect{\tau}_{ij}^R$ & Spanwise-stress residual tensor\tabularnewline
$\vect{\tau}_{ij}^r$ & Anisotropic spanwise-stress residual tensor\tabularnewline
$\chi_{12}$ & Two-point correlation function\tabularnewline
$\vect{\omega}$ & Vorticity vector field\tabularnewline
$\vect{\omega}_v$ & Columnar vortex vorticity vector field\tabularnewline
\end{longtable}

\textbf{{\large Acronyms}}

\begin{longtable}[l]{ll}
2-D & Two-Dimensional\tabularnewline
3-D & Three-Dimensional\tabularnewline
ANN & Artificial Neural Network \tabularnewline
BDIM & Boundary Data Immersion Method \tabularnewline
CNN & Convolutional Neural Network \tabularnewline
DNS & Direct Numerical Simulation \tabularnewline
EVM & Eddy-Viscosity Model \tabularnewline
FLOP & FLoating-point OPerations\tabularnewline
FSI & Fluid-Structure Interaction\tabularnewline
HPC & High-Performance Computing \tabularnewline
IB & Immersed Boundary\tabularnewline
iLES & implicit Large-Eddy Simulation\tabularnewline
KLB & Kraichnan--Leith--Batchelor\tabularnewline
LES & Large-Eddy Simulation\tabularnewline
ML & Machine-Learning\tabularnewline
MIMO & Multiple-Input Multiple-Output \tabularnewline
PBML & Physics-Based Machine Learning\tabularnewline
PS & Power Spectrum\tabularnewline
QUICK & Quadratic Upstream Interpolation for Convective Kinematics\tabularnewline
RANS & Reynolds-Averaged Navier--Stokes\tabularnewline
ReLU & Rectified Linear Unit \tabularnewline
RNN & Recurrent Neural Network \tabularnewline
SANS & Spanwise-Averaged Navier--Stokes\tabularnewline
SGS & SubGrid Scale\tabularnewline
SSR & Spanwise-Stress Residual\tabularnewline
TKE & Turbulence Kinetic Energy\tabularnewline
VIV & Vortex-Induced Vibrations\tabularnewline
VTE & Vorticity Transport Equation\tabularnewline
\end{longtable}


\documentclass[a4paper]{article}

\def\npart{III}

\def\ntitle{3 Manifolds}
\def\nlecturer{S.\ Rasmussen}

\def\nterm{Lent}
\def\nyear{2019}

\input{header}

\renewcommand{\boundary}{\partial}
\renewcommand{\b}{\boundary}
\newcommand{\interior}{\ocirc}
\renewcommand{\P}{{\mathbb P}}
\newcommand{\immerse}{\looparrowright}
\DeclareMathOperator{\grad}{grad}

\begin{document}

\input{titlepage}

\tableofcontents

\setcounter{section}{-1}

\section{Why 3?}

\subsection{Motivation}

\paragraph{Poincare conjecture (1904)}

Question: how can we distinguish \(S^3\) fom other 3-manifolds? The strategy is to find an invariant that distinguishes \(S^3\). The frst guess is homology but

\begin{theorem}[Poincare]
  There exists a closed oriented 3-manifold \(P\) with \(H_*(P) \simeq H_*(S^3)\) but with \(P \ncong S^3\).
\end{theorem}

\begin{notation}
  We use \(\cong\) to denote homeomorphism and \(\simeq\) to denote isomorphism.
\end{notation}

This is proven in the following way: first invent the fundamental group \(\pi_1\), then construct \(P\), which is now known as (-1)-Dehn surgery on left-handed trefoil knot \(K_T \subseteq S^3\). Finally show that \(|\pi_1(P)| = 120, |\pi_1(S^3)| = 1\) and \(H_*(P) \simeq H_*(S^3)\).

\subsection{Homotopy}

\paragraph{Review of homotopy theory}

homotopy, fundamental groups and higher homotopy groups, homotopy equivalence, weak homotopy equivalence

\paragraph{Homotopy vs.\ homology}

Let \(X\) and \(Y\) be path-connected topological spaces.

\begin{theorem}[Hurewicz]\leavevmode
  \begin{enumerate}
  \item \(H_1(X, \Z) \simeq \pi_1(X)/[\pi_1(X), \pi_1(X)]\).
  \item If \(\pi_i(X) = 1\) for \(i = \{1, \dots, n\}\) then
    \begin{align*}
      H_i(X) &= 0 \text{ for } i \leq n, i \neq 0 \\
      H_{n + 1} &\simeq \pi_{n + 1}(X)
    \end{align*}
  \end{enumerate}
\end{theorem}

\begin{theorem}[Whitehead]
  If \(X, Y\) are CW complexes. Then a weak homotopy equivalence of \(X\) and \(Y\) is also a homotopy equivalence.
\end{theorem}

\begin{theorem}[Whitehead-homology variant]
  Suppose \(X, Y\) are simply-connected CW complexes. If the induced homomorphisms \(f_*: H_k(X; \Z) \to H_k(Y; \Z)\) are isomorphisms for all \(k \leq \dim X\) then \(f: X \to Y \) is a homotopy equivalence.
\end{theorem}

\begin{theorem}
  Any homotopy equivalence \(f: X \to Y\) induces isomorphisms on homology, cohomology, cohomology ring structure (for any coefficients).
\end{theorem}

\subsection{*Simplifications in higher dimension}

Let \(\mathcal C\) be the smooth category when \(n \geq 5\) and topological category \(n \geq 4\).

\begin{theorem}[Whitney trick]
  Suppose \(\dim X = n\) where \(n \geq 4\) and \(P, Q \subseteq X\) are \(\mathcal \C\)-embedded submanifolds and \(\dim P + \dim Q = \dim X\). Then \(P, Q\) can be locally \(\mathcal C\)-isotoped so that the geometric intersection number equal to the absolute value of algebraic intersection of \(P, Q\). Note that algebraic intersection number is signed while teh geometric counterpart is not.
\end{theorem}

\begin{convention}
  When we say topological embeddings we always mean locally flat embeddings, which will be defined later in the course.
\end{convention}

\begin{definition}[\(h\)-cobordism]
  Let \(W\) with \(\boundary W = X_1 \amalg X_2\) be a cobordism from \(X_1\) to \(X_2\). \(W\) is an \emph{\(h\)-cobordism} if the embeddings \(X_i \embed W\) are homotopy equivalences.
\end{definition}

\begin{convention}
  All manifolds are compact connected and oriented unless otherwise stated.
\end{convention}

\begin{theorem}[\(h\)-cobordism]
  Suppose \(\dim X_i = n, \dim W = n + 1\), \(W\) is a \(h\)-cobordism from \(X_1\) to \(X_2\). If \(\pi_1(X_i) = \pi_1(W) = 1\) and \(n \geq 4\) then \(W\) is \(\mathcal C\)-isomorphic to \(X_1 \times [0, 1]\).
\end{theorem}

\subsection{Generalised Poincare conjecture}

Poincare conjecture: if \(S\) is compact oriented \(3\)-manifold homotopy equivalent to \(S^n\), then does \(S \cong S^n\)?

Generalised Poincare conjecture: if \(S\) is compact oriented \(n\)-manifold homotopy equivalent to \(S^n\), then does \(S \cong S^n\)?

It turns out for \(n \geq 4\), the generalised Poincare conjecture is a corollary of \(h\)-cobordism theorem. Sketch of proof for \(n \geq 5\): suppose \(S\) is homotopy equivalent to \(S^n\), Then \(\pi_*(S) \simeq \pi_*(S^n), H_*(S) \simeq H_*(S^n)\). Delete two balls from \(S\) to obtain \(W \cong S \setminus \interior B_1^n \amalg \interior B_2^n\). Claim that \(W\) is a \(h\)-cobordism: apply Mayer-Vietoris with \(A = W, B = B_1^n \amalg B_2^n\). Then \(A \cap B = S^{n - 1} \amalg S^{n - 1} =_{\text{htp}} W \amalg \{0, 1\}, A \cup B = S, A \amalg B = W \).

\[
  \begin{tikzcd}
    H_n(S^{n - 1} \amalg S^{n - 1}) \ar[r] & H_n(W \amalg \{0, 1\}) \ar[r] & H_n(S) \ar[dll, out=0, in=180] \\
    H_{n - 1}(S^{n - 1} \amalg S^{n - 1}) \ar[r] & H_{n - 1}(W \amalg \{0, 1\}) \ar[r] & H_{n - 1}(S)
  \end{tikzcd}
\]

The first term vanishes because of dimension, the second term vanishes because \(W\) is not closed. By homotopy equivalence we get
\[
  \begin{tikzcd}
    0 \ar[r] & \Z \ar[r] & \Z \oplus \Z \ar[r] & H_{n - 1}(W \amalg \{0, 1\}) \ar[r] & 0
  \end{tikzcd}
\]
We can compute that \(H_{n - 1}(W \amalg \{0, 1\}) \simeq \Z\). It is an exercise to show that there is an induced isomorphism on homology \(H_k(S^n_i) \to H_k(W)\) for each \(k\). Moreover \(\pi_1(W) = 1\) so \(S^n_i \to W\) are homotopy equivalent.

Therefore \(W \cong S^{n - 1} \times [0, 1]\) So \(S \cong B_1^n \cup W \cup B_2^n\). By Alexander trick map on a \(S^{n - 1}\) can be extended \emph{topologically} to a map on \(B^n\) with \(\boundary B^n = S^n\). Extends this homeomorphism over the two balls.

Note that this only applies to topological category and smooth generalised Poincare conjecture is still open in \(n \geq 4\).

\subsection{Why not higher than 5?}

Moral: homotopy-theoretic techniques can be used to answer most/many questions about topology or smooth structures in dimension \(\geq 5\).

\section{Lecture 2: Why 3-manifolds? + Embeddings/Knots}

\subsection*{Active research areas}

\begin{enumerate}
\item An interaction with 4-dimensional manifolds (smooth/symplectic/complex structures)
\begin{enumerate}
\item Dimension reduction reduces 4-dimensional invariant to 3-dimensional ones (that are fancier ``categorified'') and maps induced by cobordisms.
\item symplectic form \(\omega\) on \(X^4\) \(\implies\) \emph{contact structure} \(\xi\) on \(Y = \b X\).
\item Stein structure (complex/symplectic structure) on \(X\) \(\implies\) Stein-fillable contact structure.
\item Normal complex structure sin \((X, 0)\) is a real cone over \(Y = \)Linkm(X, 0.
\end{enumerate}

\item Geometric group theory: fundamental groups, especially of 3-manifolds:

prime, atoroidal non lens space 3 manifolds \(\iff\) fundmental groups of such 3-manifolds.

\item 2-dimensional structure
  \begin{enumerate}
  \item contact stucture: \(\xi\) everywhere nonintegrable \(2\)-lane field. ``tight'' contact structure classification
  \item minimal genus representatives of embedded surfaces, or knot genus. This is better understood. Thurston norm. The 4-dimensional analogue is still open.
  \item Foliations. Taut folations classification. Seifert fibered
  \end{enumerate}

\item 1-dimensional structure: knots and links
  \begin{enumerate}
  \item embedddings \(\amalg_i S^1_i \embed S^3\). Every 3-manifold can be realised as \emph{Dehn surgery} on  a link \(L \embed S^3\). Thus the theory of knot theory is richer that of 3-manifold. We study 3-manifolds via knot invariants (WIlten-Reshetikhin-Turaev invariant).
  \item Relations to other areas
    \begin{enumerate}
    \item Chern-Simons knot invarints: \(K \subseteq S^3\) \(\iff\) Gromov-Witten invariants on \(O(-1) \underbrace{\oplus}_{\C\P^1} O(-1)\).
    \item Homfly homology of \(n\)str braids \(\iff\) DC sheaves on \(\operatorname{HIlb}^n(\C)\).
    \item Khovanov homology of links in \(S^3\) \(\iff\) DC sheaves on other spaces.
    \end{enumerate}
  \end{enumerate}
\end{enumerate}

\subsection{Course themes}

\begin{enumerate}
\item Decompositions/Constructions of 3-manifolds.
  \begin{enumerate}
  \item surface decompositions/constructures
    \begin{enumerate}
    \item prime decomposition --- cut along essential \(S^2\)
    \item JSJ decomposition --- cut along essential \(T\).
    \item Mapping tori \(\iff\) surface fibrations.
    \end{enumerate}
  \item quotient spaces
    \begin{enumerate}
    \item Hyperbolic quotients
    \item quotients of \(S^7\). Seifert fibration
    \item Morse theoretic
      \begin{enumerate}
      \item handle decomposition
      \item Heegaard splittings/diagrams
      \end{enumerate}
    \item Dehn surgery on links
    \end{enumerate}
  \end{enumerate}
\item Structure + Invariants for 3-manifolds
  \begin{enumerate}
  \item Knots \& links
    \begin{enumerate}
    \item complement \(S^3 \setminus K\)
    \item \(\pi_1(S^3 \setminus K)\)
    \item Alexander polynomials + Turaev torsion
    \end{enumerate}
  \item Essential/incompressible embedded surfaces, Thurston norm
  \item Foliations
  \end{enumerate}
\end{enumerate}

\section{Embeddings}

\begin{definition}[link]\index{link}
  A \emph{link} is an embedding \(L = \amalg_i S^1_i \embed S^3\) considered up to isotopy. This embedding is either smooth or topoogical and locally flat. These two notions are equivalent.
\end{definition}

Let \(X\) and \(Y\) be topological manifolds.

\begin{definition}[topological embedding]\index{topological embedding}
  A \emph{topological embedding} \(X \embed Y\) is a map \(X \embed Y\) which is a homeomorphism onto its image.
\end{definition}

\begin{definition}[immersion]\index{immersion}
  If \(X\) and \(Y\) are also smooth then a map \(f: X \to Y\) is an \emph{immersion} if \(d_xf: T_xX \to T_{f(x)}Y\) is injective for all \(x \in X\).
\end{definition}

As a consequence of inverse function theorem, any immersion is locally an embedding.

\begin{definition}[smooth embedding]\index{smooth embedding}
  A \emph{smooth embedding} is a topological embedding that is also an immersion.
\end{definition}

\begin{corollary}
  If \(X, Y\) are smooth compact then any bijective immersion is an embedding.
\end{corollary}

\begin{theorem}[Moise]\index{Moise theorem}
  There is a canonical correpondence between topological structures and smooth structures on 3-manifolds.
\end{theorem}

Thus 3-manifolds up to homeomorphism bijects to 3-manifolds up to diffeomorphism.

\begin{definition}[local flatness]\index{local flatness}
  A topologically embedded submanifold \(X \subseteq Y\) is \emph{locally flat} at \(x \in X\) if \(x\) has a neighbourhood \(x \in U \subseteq Y\) with homeomorphisms \((U \cap X, U) \cong (\R^{\dim X}, \R^{\dim Y})\).

  A \emph{locally flat embedding} is locally flat everywhere.
\end{definition}

\begin{convention}
  From now on any embedding is smooth or locally flat.
\end{convention}

\begin{definition}[regular neighbourhood]\index{regular manifolds}
  A \emph{regular neighbourhood} of an embedded submanifold \(X \subseteq Y\) is a tubular/collar neighbourhood if the embedding is smooth/topologically flat.
\end{definition}

In 3-dimensions normal bundles are trivial so a regular neighbourhood \(\nu(X)\) is just \(D^2 \times X \embed Y\) if \(\dim X = 1\) and \(D^1 \times X \embed Y\) if \(\dim Y = 2\).

In particular, neighbourhood of a not \(K \embed S^3\) is just a solid torus \(D^2 \times S^1 \embed S^3\).

\section{Lecture 3: Link diagrams \& Alexander Skein relations}

\begin{eg}
  Wild knot: not locally flat embedding
\end{eg}

\begin{definition}[isotopy]\index{isotopy}
  An \emph{isotopy} in category \(\mathcal C\) from \(f_1\) to \(f_2: X \to Y\) is a homotopy through maps of type \(\mathcal C\).
\end{definition}

The point is, all knots (including wild knot) are isotopic through non-locally flat embeddings to an unknot, and all knots are homotopic to an unknot so we want to exclude the ``bad'' homotopies where a knot can cross itself.

\subsection{Knot and link diagrams}

\begin{definition}[link]\index{link}
  A \emph{link} is an (oriented) embedding \(\iota: \coprod_i S_i^1 \embed S^3\) of (oriented circles), considered up to isotopy.
\end{definition}

\begin{definition}[link projection]
  A \emph{link projection} is an immersion \(L \immerse \Gamma \embed \R^2\), induced by
  \[
    \begin{tikzcd}
      L \ar[r, hook] \ar[d, "p|_L"] & S^3 \setminus \{x_0\} \ar[r, "\cong"] & \R^3 \ar[r, "\cong"] & \R^2 \times \R \ar[d, "p"] \\
      \Gamma \ar[rrr] & & & \R^2
    \end{tikzcd}
  \]
  such that \(x_0 \notin L\) and \(p|_L\) is an embedding except at double point singularities.
\end{definition}

This aweful looking definition is just a formalisation of a familiar concept that facilitates the study of knots:

\begin{definition}[link diagram]\index{link diagram}
  A \emph{link diagram} \(D = (\Gamma, \text{crossing} (D))\) of a link \(L \subseteq S^3\) is an embedded graph \(\Gamma \embed \R^2\) from a link projection of \(D\), together with decorations at double points to label crossings. We draw a gap in the lower strand.
\end{definition}

\begin{theorem}[Reidemeister moves]\index{Reidemeister moves}
  Let \(D_1\) and \(D_2\) be link diagrams for respective links \(L_1, L_2 \subseteq S^3\). Then \(L_1\) and \(L_2\) are isotopic if and only if \(D_1\) and \(D_2\) are related by some combination of the fuollowing moves:
\end{theorem}

It is more important to know that such moves exist than what they actually are.

\subsection{Alexander Skein relation}

To compute the alexander polynomial, you first choose an orientation for the link \(L \subseteq S^3\). However, the resulting polynomial is independent of choice of orientation for knots.

\begin{theorem}[Alexander]\index{Alexander polynomial}
  The \emph{Alexander polynomial}
  \[
    \Delta: \{\text{link diagram}\} \to \Z[t^{-1/2}, t^{1/2}]
  \]
  is specified by 2 conditions:
  \begin{enumerate}
  \item normalisation: \(\Delta(u) = 1\) where \(u\) is the unknot.
  \item Skein relation: \(\Delta(negative crossing) - \Delta(positive crossing) = \Delta(oriented resolution) (t^{-1/2} - t^{1/2})\) for all \(c \in \text{crossing}(D)\).
  \end{enumerate}
  \(\Delta(D_1) = \Delta(D_2)\) if \(D_1\) and \(D_2\) are diagrams for isotopic links.
\end{theorem}

\begin{theorem}[equivalence of Alexander polynomial]
  Later we will define an Alexander polynomial for 3-manifolds with \(b_1 > 0\). With respect to this definition,
  \[
    \Delta_{\text{link}}(L) = \Delta_{\text{3-manifold}}(S^3 \setminus L)
  \]
  for any link \(L \subseteq S^3\).
\end{theorem}

\section{Handle decompositions from Morse Singularities}

Handles: index \(k\)-handles are tubular neighbourhood of \(k\)-cell CW complex, also are neighbourhoods of Morse critical points.

\subsection{Morse functions}

Let \(X \to \R\) be a smooth function on a smooth manifold \(X\).

\begin{definition}[Hessian, critial point]\index{Hessian}\index{critcal point}
  \(\textrm{Hess}_p(x)\) is the Hessian of \(f\) at \(p\), which is local coordintes is
  \[
    \left(
      \frac{\partial^2 f}{\partial x_i \partial x_J}|_{x = p}
    \right)_{ij}.
  \]

  \(\textrm{crit} f\) is the set of critical points of \(f\), i.e.\ \(\{p \in X: \frac{\partial f}{\partial x_i} = 0 \text{ for all } i\}\), or more invariantly, \(df = 0\).
\end{definition}

\begin{definition}[Morse function]\index{Morse function}
  A smooth function \(f: X \to \R\) on an \(n\)-manifold \(X\) is \emph{Morse} if
  \begin{enumerate}
  \item every critical point of \(f\) is isolated. (If \(X\) is compact then this implies that critical points are finite)
  \item \(\textrm{Hess}_p f\) is nongenerate at each \(p \in \textrm{crit} f\), if and only if \(\det \neq 0\), if and only if has all nonzero eigenvalues.
  \end{enumerate}
\end{definition}

\subsection{Morse singularities}

A list of descriptions of Morse functions:

\begin{enumerate}
\item If \(f: X \to \R\) is Morse, then a Taylor series expansion around a critical point \(p \in \textrm{crit} f\) looks like
  \[
    f(x) = f(p) + \frac{1}{2} \sum x_i x_j \frac{\partial^2 f}{\partial x_i x_j}\Bigg|_p + \text{ higher order terms}
  \]
\item \(\textrm{Hess}_p f\) is nondegenerate means that we can rescale coordinates so that all eigenvalues are \(\pm 1\).
\item Since partial derivatives commute, \(\textrm{Hess}_p f\) is symmetric. Thus by linear algebra it is diagonalisable and we can write
  \[
    f(x) = f(p) - \sum_{i = 1}^k x_i^2 + \sum_{i = k + 1}^n x_i^2 + \text{ higher order terms}.
  \]
\end{enumerate}

\begin{lemma}[Morse lemma]
  Let \(X\) be a smooth manifold and \(f: X \to \R\) Morse. One can choose coordinates \(x\) centred at \(p \in \textrm{crit} f\) such that
  \[
    f(x) = f(p) - sum_{i = 1}^k x_i^2 + \sum_{i = k + 1}^n x_i^2.
  \]
\end{lemma}

\begin{proof}
  Use implicit function theorem.
\end{proof}

\begin{definition}[index]
  The \emph{index} \(\operatorname{ind}_p f\) of a Morse function \(f: X \to \R\) at a critical point \(p\) is
  \[
    \operatorname{ind}_p f = \# \text{ negative eigenvalues of } \textrm{Hess}_p,
  \]
  which is the \(k\) above.
\end{definition}

Thus Morse lemma says that index is the (only?) invariant of Morse functions.

Moral: there is a standard local model for each index \(k\) Morse critical point.

See printed notes

\begin{definition}[\(k\)-handle]
  An index \(k\)-handle, or just \(k\)-handle, or \(n\)-dimensional \(k\)-handle is the closure of a tubular neighbourhood of an index \(k\) critical point.
  \(H_k^m \cong \nu(x) \cong D^k \times D^{n - k} \supseteq \interior B^k\).
\end{definition}

Note that the corners in \(D^k\) and \(D^{n - k}\) are different

\section{Lecture 5: Handles from cells, Heegard diagrams}

Cell ecomplex interpretation

\begin{definition}[handle, core, cocore]\index{handle}\index{core}\index{cocore}
  An \emph{\(n\)-dimension \(k\)-handle} \(H^n_k\) or \emph{index \(k\)-handle} is a product decomposition
  \[
    H^n_k \cong D^k \times D^{n - k} \cong B^n
  \]
  of the closed \(n\)-ball into a \(k\)-dimensional \(k\)-cell \emph{core} \(D^k\) and \emph{cocore} \(D^{n - k}\).
\end{definition}

If you choose a metric, the core \(D^k\) is fat and the cocore \(D^{n - k}\) is thin.

\begin{definition}[attaching region, belt region]\index{attaching region}\index{belt region}
  The boundary \(\b H^n_k\) of an \(n\)-dimensional \(k\)-handle decomposes as
  \begin{align*}
    \b H^n_k
    &\cong \b(\text{core} \times \text{cocore}) \\
    &\cong \b(\text{core}) \times \text{cocore} \cup \text{core} \times \b(\text{cocore}) \\
    &\cong \underbrace{\b D^k \times D^{n - k}}_{\text{attaching region}} \cup \underbrace{D^k \times \p D^{n - k}}_{\text{belt region}}
  \end{align*}
\end{definition}

In a cell complex, we attach a \(k\)-cell \(D^k\) by gluing its boundary \(\b D^k \cong S^{k - 1}\) to the cell-complex we have built so far.

\[
  \text{attaching region} (H^n_k)
  \cong \overline{\nu(\p D^k)}
  \cong \overline{\nu S^{k - 1}}
  \cong \p D^k \times D^{n - k}
\]

\begin{definition}[handle attachment]\index{handle attachment}
  The attachment of a \(k\)-handle \(H^n_k\) to an \(n\)-manifold \(X\) to product an \(n\)-manifold \(X'\) is induced by a \emph{\(k\)-handle attachment} cobordism \(Z\) from \(- \b X\) to \(\b X'\).
  \[
    Z = (\b X \times I) \cup_{\text{a.r.}} H^n_r.
  \]
  We have
  \[
    \p X' \cong (\p X \setminus \text{a.r.} (H^n_k)) \cup (\text{b.r.} (H^n_k)).
  \]
\end{definition}

As \(\p X \times I\) deformation retracts to \(\p X\), we have
\[
  X' \cong X \cup Z \cong X \cup H^n_k.
\]

\begin{convention}
  We usually say that we attach a handle along the \emph{core} of the attaching region.
\end{convention}

\begin{definition}[attaching/belt sphere]
  \begin{align*}
    \text{attaching region} (H^n_k)
    &\cong \text{core}(\text{attaching region}(H^n_k)) \\
    &\cong \text{core}(\p D^k \times D^{n - k}) \\
    &\cong \p D^k
  \end{align*}
  \begin{align*}
    \text{belt region} (H^n_k)
    &\cong \text{core}(\text{belt region}(H^n_k)) \\
    &\cong \p D^{n - k}
  \end{align*}
\end{definition}

Convention reexpressed: to attach a \(k\)-handle, we specify where the \emph{attaching sphere} will be glued.

Morse interpretation, revisited

\begin{definition}[gradient]
  Choose a Riemannian metric \(g\) on a smooth \(n\)-manifold \(X\). Let \(f: X \to \R\) be a smooth function. the gradient \(\grad f \in \Gamma(TX)\) of \(f\) is the vector field satisfying
  \[
    g(\grad f, V) = df(V)
  \]
  for \(V \in \text{Vect} X = \Gamma(TX)\).
  Locally,
  \[
    g_x((\grad f)_x, V_x) = df_x(V_x).
  \]
  In local coordinates,
  \[
    \grad f = \sum g^{ik} \frac{\partial f}{\partial x^k}e_i
  \]
  where \(e_i = \frac{\partial  }{\partial x^i}\).
\end{definition}

Idea: invariant object from partials of \(f\), \(df = \sum \frac{\partial f}{\partial x^i} \w dx^i\). To get a vector field, need a bilinear form to dualise \(df\). \(\grad f\) comes from bilinear form (metric), and Hamiltonian vector field \(f\) comes from symplectic form.

Moral (Morse theorey intepretation)

Q: In what sense \(H^n_k \cong \overline{\nu(x)}\), \(x \in \text{crit} f, \text{ind}_x f = k\)?

A: Gradient flow at the boundary of \(H^n_k\): \(\grad f\) flows into attaching region \(H^n_k\), into \(x \in \text{crit} f\) in \(k\) directions. \(\grad f\) flows out of belt region \(H^n_k\), out of \(x\) in \(n - k\) directions.

For example, for
\[
  f = - \sum_{i = 1}^k x_i^2 + \sum_{j = k + 1}^n x_j^2
\]

\printindex
\end{document}

% https://www.dpmms.cam.ac.uk/~sr727/2019_3manifolds


\chapter{VRPTW via AI}\label{vrptw-ai}
In this chapter, we will describe our end-to-end deep learning method for solving \gls{vrptw}.

Machine learning and artificial intelligence have been replacing many hand-engineered algorithms and providing state-of-the-art results. In recent years, reinforcement learning \ref{rl} and advances in attention models \ref{attention} has shown great promise to disrupt the field of heuristics algorithms \cite{rl-constraint-opt, attention-route, dpdp}. Heuristics algorithms \cite{heuristics-algo} are incomplete methods that can compute solutions efficiently, but are not able to prove the optimality of a solution. Most of the business challenges do not require the most optimal exact solution \cite{excat-algo} but focus on approximation of the optimal solution in a reasonable time.

\section{Related Work}
Regarding the research of solving the \gls{vrp}, researchers have been mainly concentrating on designing hand-crafted metaheurictis via optimization. However, the great adoption of deep learning is starting to catch up with the field of operations research.

The first relatively successful deep learning model for solving general \gls{vrp} was proposed by Vinyals et al. \cite{vinyals} in the year of 2015 by introducing Pointer Networks. The model uses attention to output
a permutation of the input and the model was trained in the supervised manner by example solutions. In the next year, Bello et al. \cite{actor-critic-pointer} extended the model of Pointer Networks by adopting the Actor-Critic algorithm that introduced \gls{rl} and the model was trained on the training samples and did not require labelled data anymore. The reward function was a simple Euclidean length of the routes. The network showed improved performance on larger instances of 50 nodes over the predecessor model using supervised learning. In 2018, Nazari et al. \cite{nazari} simplified the model of RL-based Pointer Network by omitting the recurrent neural network encoder and replaced it with embedding to D-dimensional vector space. The recurrent neural network is not necessary because the inputs of delivery nodes are not dependent on order \cite{nazari}. There was no deterioration in performance and the model also supported the constraint for solving split delivery \ref{split-delivery}.

In 2018, Kool et al. \cite{attention-route} proposed a new approach and replaced the Pointer Network with Transformers \ref{transformer} using Graph Attention Network \ref{graph-attention-network} instead of positional encoding, and the Actor-Critic algorithm was changed to REINFORCE algorithm. The model showed superior performance. In this thesis, we will extend this model to support the soft time window constraint.

In 2019, Hottung et al. \cite{hottung} introduced a novel approach that was inspired by \gls{lns} \ref{lns} called Neural Large Neighborhood Search. This model learns the destroy and repair operators by using graph attention network and attention mechanism, and it is outperforming the standard metahesuristics on capacitated vehicle routing problem. However, it is still iterative algorithm based on the local search which results in much larger runtime then end-to-end deep learning methods for \gls{vrp}.

In 2021, another paper by Kool et al.\cite{dpdp} was released with a completely new approach. It combines  dynamic programming and deep learning to solve \gls{vrp} and promises much better performance than previous solutions. The method uses deep learning to restrict the dynamic programming search space using a policy derived from graph neural network. In the future, we will explore this method in depth and extend the support of constraints for time windows and pick and deliver problem \ref{pick-and-delivery}

\section{Solution}
The end-to-end deep learning method pro solving \gls{vrptw} is extension of the work done by Kool et al. \cite{attention-route}.

Let us describe the high-level concept behind the method. Consider we have a model as blackbox which takes \gls{vrptw} instance as an input and outputs probabilities for all the \gls{vrptw} nodes. The probability represents which node should be visited next and by following to the most probable node we get a partial solution which will be considered by the blackbox. We iterate this process until all nodes have been visited and we acquire a feasible plan as shown on Figure \ref{fig:attention-route-diagram}.

    \begin{figure}[ht]
        \centering
        \includegraphics[width=1.0\textwidth]{resources/vrptw-ai/attention-route-diagram.pdf}
        \caption{High-level concept behind the used method.}
        \label{fig:attention-route-diagram}
    \end{figure}

    \subsection{Model Architecture}\label{vrptw-model}
    The model architecture \cite{attention-route} leveraging recent advancements in attention mechanism is here extended by the time window constraint. The model is built upon transformers \ref{transformer}, graph attention network \ref{graph-attention-network}, and reinforcement learning \ref{rl}. The network structure is encoder-decoder that fits well for solving sequential decision problems. The structural input instance is extracted by the encoder \ref{vrptw-encoder} and then the solution is incrementally constructed by the decoder \ref{vrptw-decoder}.

    The \gls{vrptw} input instance is consisted from:
    \begin{itemize}\label{input-data}
        \item $X = \{x_1, \cdots, x_n\}$ where $x_i$ is two-dimensional coordinates in the euclidean space.
        \item $x_0$ is the location of depot.
        \item $D = \{d_1, \cdots, d_n\})$ is the demand capacity for each of the locations.
        \item $T = \{(e_1, l_1), \cdots, (e_n, l_n)\})$ is time windows for each of the location where $e_i$ is the beginning and $l_i$ is the end of the considered time window.
    \end{itemize}

    The output is the solution of VRPTW instance and is represented as a permutation $\pi$ of locations $X \cup x_0$.
    \begin{itemize}
        \item $\pi = \{\pi_1, \cdots, \pi_T\} \in \{x_0, \cdots, x_n\})$
    \end{itemize}

    \subsubsection{Encoder}\label{vrptw-encoder}
    The encoder uses graph attention network \ref{graph-attention-network} to embed the node features to graph embedding. Then the decoder architecture is the same as the decoder of transformer \ref{transformer}. Typicaly, the decoder of transformer uses positional encoding \cite{positional-encoding} to embed the input, but in this case it has been replace with \gls{gat} \ref{graph-attention-network} since we deal with graph-based structure and the input order does not matter.

    The first step is to perform the initial embedding of input data \ref{input-data} via learned linear projections as in \gls{gat}. The $h_{i}^{l}$ represents the node embedding of layer $l \in \{0, \cdots, N\}$ (N=3).
    \begin{equation}
        \widetilde{x} = \text{concat}(X, D, T)
    \end{equation}
    \begin{equation}
        h_{i}^{0} = \begin{cases} W \widetilde{x}_i + b_i &\mbox{if } i > 0 \\ W \widetilde{x}_0 + b_0 & \mbox{if } n = 0 \end{cases}
    \end{equation}

    The node embeddings are updated via $N$ attention layers, each containing multi-head attention \ref{multi-head-attention} (M=8) and a fully connected feed-forward network with normalization. The structure is identical to transformer's encoder \ref{transformer} with additional support of graph structure \ref{graph-attention-network} as shown on Figure \ref{fig:encoder-diagram}.

    \begin{figure}[ht]
        \centering
        \includegraphics[width=1.0\textwidth]{resources/vrptw-ai/encoder-diagram.png}
        \caption{Encoder layers \cite{attention-route}}
        \label{fig:encoder-diagram}
    \end{figure}

    The equation \ref{encoder-qkv} calculates the query $Q$, key $K$ and value $V$ of multi-head attention layer using the node embeddings and weights $W_m^Q$, $W_m^Q$, and $W_m^Q$, respectively. The number of heads is represented by $m \in \{1, \cdots, M\}$ (M=8).

    \begin{equation}\label{encoder-qkv}
        \textbf{q}_{im}^l = W_m^Q h_i^(l-1), \textbf{k}_{im}^l = W_m^K h_i^(l-1), \textbf{v}_{im}^l = W_m^V h_i^(l-1)
    \end{equation}

    The query and key values are used in calculating the compatibility $u_{ijm}^l$ of node $i$ with a node $j$ \ref{mha-compatibility}. If node $i$ is not adjecnt to node $j$ then they are not compatible and the value is set to a large negative number.

    \begin{equation}\label{mha-compatibility}
        u_{ijm}^l = \begin{cases} q_{im}^l k_{jm}^l &\mbox{if $i$ adjacent to $j$} \\ -\infty &\mbox{otherwise} \end{cases}
    \end{equation}

    The attention score $a_{ijm}^l \in [0,1]$ is calculated using softmax from the compatibility values of nodes \ref{encoder-attention-score}

    \begin{equation}\label{encoder-attention-score}
        a_{ijm}^l = \dfrac{e^{u_{ijm}^l}}{\sum_{j'=0}^n e^{u_{ij'm}^l}}
    \end{equation}

    The transformed $h'_{im}^l$ \ref{h-prime} aggregates all attention scores across neighbour nodes, which is based on GAT \ref{graph-attention-network}.

    \begin{equation}\label{h-prime}
        h'_{im}^l = \sum_{j=0}^n a_{ijm}^l v_{jm}^l
    \end{equation}

    Finally, we may calculate the multi-head attention \ref{transformer} for layer $l$ as a function of $\{h_1^{l-1}, \cdots, h_n^{l-1}\}$ through $h'_{im}^l$.

    \begin{equation}
        \text{MHA}_i^l(h_1^{l-1}, \cdots, h_n^{l-1}) = \sum_{m=1}^M W_{m}^O h'_{im}^l
    \end{equation}

    \begin{equation}
        \widetilde{h}_i = \text{BN}^l(h_i^{l-1} + \text{MHA}_i^l(h_1^{l-1}, \cdots, h_n^{l-1})))
    \end{equation}
    \begin{equation}
        h_i^l = \text{BN}^l(\widetilde{h}_i + \text{FF}^l(\widetilde{h}_i))
    \end{equation}

    In the final layer, the encoder computes the aggregated embedding of the input graph as the mean of the final node embeddings.
    \begin{equation}
        h^N = \dfrac{1}{n} \sum_{i=1}^m h_i^N
    \end{equation}

    The output of the encoder's final layer is passed to the decoder, which is detailed in the next sections \ref{vrptw-decoder}.

    \subsubsection{Decoder}\label{vrptw-decoder}
    Decoder works sequentially through timestamps $t \in \{0, \cdots, n\}$, at each timestamp one node is selected to be visited based on partial route $\pi_{1:t-1}$. It is predicting the probability distribution over nodes according to the node embedding and context vector of the encoder \ref{vrptw-encoder}.

    \begin{figure}[ht]
        \centering
        \includegraphics[width=1.0\textwidth]{resources/vrptw-ai/decoder-diagram.png}
        \caption{Describes the decoder iteration in the construction of a solution. This diagram very nicely visualizes the process and it was used in the paper by Kool et al. \cite{attention-route}}
        \label{fig:encoder-diagram}
    \end{figure}

    The decoder uses a new context vector $h_{c}^{'}$ which represents the state \ref{rl} and it goes as follows:
    \begin{equation}\label{decode-state-vec}
        h_{c}^{'} = \begin{cases} \text{concat}(h_N; h_0^N; D_t) & \mbox{if } t = 0 \\ \text{concat}(h_N; h_{\pi_{1:t-1}}^N; D_t) & \mbox{if } t > 0 \end{cases}
    \end{equation}
    The state of $h_{c}^{'}$ is concatenation of $h_N$, the output of the encoder, $h_{\pi_{1:t-1}}^N$, the embedding of previous partial solution, and $D_t$, the remaining demand capacity of the vehicle.

    Due to the fact that the decoder architecture is transformer \ref{transformer}, the next layers are multi-head attentions which are responsible for choosing the next node to visit. This defines the system action \ref{rl}.

    The multi-head attention in the decoder is computed in a similar manner as in the decoder \ref{vrptw-encoder} with a little alternation.
    \begin{equation}
        q_{(c)m} = W_m^Q h_{c}^{'}, k_{jm} = W_m^K h_{j}^{N}, v_{jm} = W_m^V h_{j}^{N}
    \end{equation}

    \begin{equation}\label{compatibility-decoder}
        u_{(c)j} = \begin{cases} q_c^T k_j &\mbox{if }  d_j <= D_t \text{ and } x_j \notin \pi_{1:t-1} \\ -\infty &\mbox{otherwise} \end{cases}
    \end{equation}

    The equation \ref{compatibility-decoder} computes the compatibility score and performs a masking mechanism to mask the nodes which have already been visited during the partial route (besides depot $x_0$) and eliminates nodes where the vehicle capacity would overflow. If we would consider a time window as a hard constraint, the calculation of compatibility would have extended masking mechanism to show only nodes which correspond to the time $t$.

    \begin{equation}
        h'_{(c)m} = \sum_{j=0}^n softmax(u_{(c)j}) v_jm
    \end{equation}

    \begin{equation}
        h_{c} = \text{MHA}(h_{c}^{'}) = \sum_{m=1}^M W_{m}^O h'_{(c)m}
    \end{equation}

    In order to calculate the desired probability $p_{\theta}(\pi_t|X, \pi_{1:t-1})$, a logit layer. The final layer is a single-head attention.

    \begin{equation}
        q = W^Q h_c, k_j = W^K h_j^N
    \end{equation}

    \begin{equation}
        u_j = \begin{cases} C . \text{tanh}(q^T k_{c}) &\mbox{if }  d_j <= D_t \text{ and } x_j \notin \pi_{1:t-1} \\ -\infty &\mbox{otherwise} \end{cases}
    \end{equation}

    \begin{equation}\label{encoder-attention-score}
        p_i = p_{\theta}(\pi_t|X, \pi_{1:t-1}) = \dfrac{e^{u_j}}{\sum_{j'=0}^n e^{u_{j'}}}
    \end{equation}

    \subsection{Reinforcement Learning}\label{vrptw-rl}
    The model \ref{vrptw-model} takes \gls{vrptw} instance and outputs probability distribution over nodes $p_{\theta}(\pi|X)$ which is used to sample a full feasible route as a solution $\pi$. The instance of \gls{vrptw} $S$ is defined as concatenation of locations, demand capacity and time windows for each node, $S = [X, D, T]$.

    To train the model, we have to define a reward, respectively, a cost function. The model is trained using REINFORCE algorithm \ref{reinforce} as proposed by Kool et al. \cite{attention-route}. The algorithm is based on the computation of the policy gradient, which is defined as
    \begin{equation}\label{encoder-attention-score}
        \nabla_{\theta} \mathcal{L}(\theta|X) = \mathop{\mathbb{E}}[ \mathcal{L}(\pi|X) - b(X)) \nabla \ln \pi (\pi|X))]
    \end{equation}

        \subsubsection{VRPTW Cost}\label{vrptw-rl}
        For effectively solving \gls{vrptw}, the cost function is an integral part of a successfully trained model. In this thesis, we propose a new cost function to solve the vehicle routing problem with soft constrained time windows and demand capacity for each node.

        The cost function is ranking the given solution of \gls{vrptw} instance. It penalizes the solution based on the length of the routes, early and late visits, and unequal distribution of nodes across vehicles.

        For a given \gls{vrptw} instance $S$ and its solution $\pi$, we propose the cost function as follows:
        \newcommand{\norm}[1]{\left\lVert#1\right\rVert}
        \begin{equation}\label{vrptw-cost}
            \mathcal{L}(\pi|S) = dis_p(\pi, S) + t_p(\pi, S) + bal_p(\pi, S)
        \end{equation}
        \begin{equation}\label{distance-cost}
            dis_p(\pi, S) = \sum_{i=0}^N \norm{x_{\pi(i)} - x_{\pi(i+1)}}_2
        \end{equation}
        The equation \ref{distance-cost} calculates the length of all routes in Euclidean space.

        \begin{equation}\label{time-cost}
            t_p(\pi, S) = \sum_{i=0}^N (I_{e_i > \widetilde{t}_i} (e_i - \widetilde{t}_i) p_e + I_{l_i < \widetilde{t}_i} (\widetilde{t}_i - l_i) p_l)
        \end{equation}
        The equation \ref{time-cost} calculates the penalty for early or late arrival. The time of the visit for a given node $i$ is defined by vector $\widetilde{t}_i$. We assume that the travel speed is always identical and we approximate that one unit of distance equals to one unit of time. The vector $I$ behaves as a mask $I \in (0, 1)^n$ which represents if either early or late arrival occurred. The penalty for late arrival $p_l$ should be greater than for early arrival $p_e$ and finding the proper penalties will be empirically determined as a part of experiment chapter \ref{penalty-experiment}.

        \begin{equation}\label{balance-cost}
            bal_p(\pi, S) = \sigma([|R_0|, \cdots, |R_k|])
        \end{equation}
        The last subpart of the cost function is calculating balance cost \ref{balance-cost} that aims to evenly distribute the number of nodes in a route $R_i$ by minimizing its standard deviation. In logistics, we expect to utilize couriers evenly.

        \subsubsection{Training loop}\label{vrptw-loop}

        Pseudocode of the \gls{rl} system training loop is as follows

        \SetKwInput{KwInput}{Input}
        \begin{algorithm}[H]
            \KwInput{Number of epoch $E$, steps per epoch $T$, batch size $B$} %significance $\alpha$
            \KwResult{Updated $\theta$ that maximises reward}

            Initialize $\theta$ at random\;
            \For{$epoche = 1, 2, \cdots, E$}{
                \For{$steps = 1, 2, \cdots, T$}{
                    Compute context embedding $h^N$ via decoder (\ref{vrptw-encoder});

                    \For{$t = 1, 2, \cdots, N$}{
                        Calculate $p_{\theta}(\pi_t|X, \pi_{1:t-1})$ via encoder for $t$ (\ref{vrptw-decoder});

                        Pick an action based on probability distribution;

                        Update the state by visiting a new node;
                    }

                    Compute reward $\mathcal{L}(\pi|S)$ (\ref{vrptw-cost});

                    %Compute reward baseline;

                    % $\nabla_{\theta} \mathcal{L} \gets \mathop{\mathbb{E}}[ \mathcal{L}(\pi|X) - b(X)) \nabla \ln \pi (\pi|X))]$;

                    $\nabla_{\theta} \mathcal{L} \gets \mathop{\mathbb{E}}[ \mathcal{L}(\pi|X) \nabla \ln \pi (\pi|X))]$;

                    $\theta \gets \text{Adam}(\theta, \nabla_{\theta} \mathcal{L})$;
                }
         }
         \caption{REINFORCE algorithm}
        \end{algorithm}

    \subsection{Integrating Duration Matrix}
    Real-world application of \gls{vrp} require to obtain the distance and duration matrix which represents the weighted transition between graph nodes. The duration between two locations is typically defined by the infrastructure and speed limits on a given route. Such a duration matrix is calculated using map data such as OpenStreetMap \cite{osm}.

    The neural network solving \gls{vrptw} learns to approximate the Euclidean distance between two given points. However, if we would integrate the duration matrix into the cost function of the model, the network would have to derive the duration between two points, which is an impossible task with the given model architecture. Moreover, the planning would be fixed to the location (city) on which the model was trained on.

    We propose an indirect integration of the duration matrix for the input instance. We may project the duration matrix into the node locations using multidimensional scaling \cite{mds} which would embed the duration information in a given 2D space.