\documentclass[%handout,
	sans,
	12pt,
	%slidescentered,% center text on slide
	%draft,			% compile as draft version
	%notes,			% include notes in slides
	%compress		% compress navigation bar
]{beamer}

\beamertemplatenavigationsymbolsempty

\usetheme{default}
\usecolortheme{orchid}
\setbeamertemplate{frametitle}
{
    \vspace*{1.5em}\insertframetitle\vspace*{-1.5em}
}
\setbeamertemplate{footline}[frame number]

\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}

\usepackage{mathpazo}
\usepackage[british]{babel}
\usepackage{csquotes}

\newcommand{\high}[1]{{\usebeamercolor[fg]{structure} #1}}
\newcommand{\bad}[1]{\textcolor{red}{#1}}
\newcommand{\gray}[1]{\textcolor{darkgray}{#1}}
\newcommand{\black}[1]{\textcolor{black}{#1}}

\usepackage{amsmath,amssymb}
\usepackage{upgreek}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{url}
\usepackage{setspace}
\usepackage{wrapfig}
\usepackage{tabularx}
\usepackage{xspace}
\usepackage{mathpartir}

\usepackage{tikz}
\usetikzlibrary{trees, positioning}
\usetikzlibrary{shapes.geometric}

\usepackage{isabelle,isabellesym}
\isabellestyle{it}
\def\isacartoucheopen{}%
\def\isacartoucheclose{}%

\newcommand{\NN}{\mathbb{N}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\CC}{\mathbb{C}}
\renewcommand{\epsilon}{\varepsilon}
\renewcommand{\phi}{\varphi}
\def\braces#1{[#1]}
\newcommand{\wrt}{w.\,r.\,t.\xspace}
\newcommand{\eg}{e.\,g.\xspace}
\newcommand{\ie}{i.\,e.\xspace}
\DeclareMathOperator\caret{\char`\^}

\newcommand{\hastype}{\,:\,}
\newcommand{\cons}{::}
\newcommand{\corrto}{\overset{\scriptscriptstyle\wedge}{=}}
\newcommand{\listapp}{\mathbin{@}}
\newcommand{\listnil}{[\hskip0.3mm]}
\newcommand{\listnth}{\mathbin{!}}
\newcommand{\expectation}{\text{\upshape E}}

\usepackage{manfnt}
\newenvironment{danger}{\medbreak\noindent\hangindent=2pc\hangafter=-2%
  \clubpenalty=10000%
  \hbox to0pt{\hskip-\hangindent\hskip0.25em\raisebox{-0.25em}[0pt][0pt]{\dbend}\hfill}\small\ignorespaces}%
  {\medbreak\par}
  %\raisebox{-1.05em}[0pt][0pt]{\Huge\hskip.15em \stixdanger}

\newcommand{\etAl}{\textit{et al.}\xspace}

%\definecolor{mybg}{rgb}{0.9,0.9,0.9}
\definecolor{mybg}{rgb}{1,1,1}
\setbeamercolor{background canvas}{bg=mybg}

\title{Verification of an Approximation Algorithm for the Metric Travelling Salesperson Problem}
\author{\normalsize Fabian Hellauer}
\institute[]{\footnotesize Technische Universität München}
\date{\footnotesize16 October 2019}

\begin{document}

\maketitle

\begin{frame}
\begin{center}
\includegraphics[width=5cm]{isabelle.pdf}
\end{center}
\end{frame}

\newcommand{\pivot}[1]{{\color{red}#1}}
\newcommand{\ltpiv}[1]{{\color{blue}#1}}
\newcommand{\gtpiv}[1]{{\color{olive}#1}}

\section{Verification of Algorithms}
\begin{frame}{Verification of Algorithms}%<very fast>
Reasons:
\begin{itemize}
	\item a basis for reliable software\pause
	\item find mistakes in algorithm explanations\pause
	\item prove that verification of executable programs
	is feasible\ % when using a modern tool like
	\pause when using \includegraphics[height=1em]{isabelle.pdf}Isabelle\pause
\end{itemize}
Mathematical results might be a requirement.
%In this case here, from graph theory.
\end{frame}

\section{Metric TSP}
\begin{frame}
	TSP is the problem of finding a tour of minimal cost within a graph.\\\pause
	We consider the special case where the nodes form a \textit{metric space} with their weights.\\\pause
	In particular,\pause
	\begin{itemize}
		\item \textit{weight} is total
		% All TSP cities are connected by an edge, in other words we require the graph to be complete.
		\item $\textit{weight}\ v_1\ v_3\ \leq\ \textit{weight}\ v_1\ v_2\ +\ \textit{weight}\ v_2\ v_3$
		\item $0\ \leq\ \textit{weight}\ v_1\ v_2$\pause
	\end{itemize}
	In such a graph, the cost of a \textit{minimum spanning tree} is a lower bound on the optimal tour cost.
\end{frame}

\section{Approximation Algorithms}
\begin{frame}{Approximation Algorithms}
	What are Approximation Algorithms?\pause%based on (metric) TSP
	\vspace{1em}
	\includegraphics[width=\linewidth]{OPT_line}
	%OPT is the performance of an *actual* algorithm, namely the brute-force algorithm that tries all exponentially many node sequences.
	\vspace{1em}\pause %Since we consider undirected graphs, the reverse of a TSP tour is also a TSP tour (I omitted these duplicates in the graphic)

	\high{Good solutions for NP-complete problems in polynomial time!}
\end{frame}

\section{Algorithm Explanation}
\begin{frame}
\begin{center}
	\huge\high{Algorithm Explanation}
\end{center}
\end{frame}

\subsection{Algorithm Overview}
\begin{frame}{Algorithm Overview}
Consider a complete undirected graph$G = (V, E)$ and its minimum spanning tree $T$.\pause%or rather: let one of its minimum spanning trees be $T$

We are going to
\begin{enumerate}
	\item find such a $T$\pause
	\item generate a TSP tour using $T$'s edges
\end{enumerate}% and we are going to argue that T has cost less than an optimal TSP tour
\end{frame}

\subsection{MST vs.\ TSP tour}
\begin{frame}{MST vs.\ TSP tour}
\begin{center}
	\includegraphics[height=2cm]{complete0.png}
\end{center}
\end{frame}

\subsection{MST vs.\ TSP tour}
\begin{frame}{MST vs.\ TSP tour}
\begin{center}
	\includegraphics[height=2cm]{complete1.png}
\end{center}
\end{frame}

\subsection{MST vs.\ TSP tour}
\begin{frame}{MST vs.\ TSP tour}
\begin{center}
	\includegraphics[height=2cm]{complete2.png}
\end{center}
\end{frame}

\subsection{MST vs.\ TSP tour}
\begin{frame}{MST vs.\ TSP tour}
\begin{center}
	\includegraphics[height=2cm]{complete2.png}
\end{center}
\begin{isabelle}
\isacommand{lemma}\isamarkupfalse%
\ minimum{\isacharunderscore}spanning{\isacharunderscore}tree{\isacharunderscore}le{\isacharunderscore}OPTWEIGHT{\isacharcolon}\isanewline
\ \ \isakeyword{assumes}\ {\isacartoucheopen}minimum{\isacharunderscore}spanning{\isacharunderscore}tree\ T{\isacharprime}\ {\isacharparenleft}symhull\ E{\isacharparenright}{\isacartoucheclose}\isanewline
\ \ \isakeyword{assumes}\ {\isacartoucheopen}{\isadigit{2}}\ {\isasymle}\ card\ V{\isacartoucheclose}\isanewline
\ \ \isakeyword{shows}\ {\isacartoucheopen}set{\isacharunderscore}cost\ T{\isacharprime}\ {\isasymle}\ OPTWEIGHT{\isacartoucheclose}
\end{isabelle}
\end{frame}

\subsection{Tour Search}
\begin{frame}{Tour Search}
Find an edge sequence which\pause
\begin{itemize}
	\item uses exactly the MST's edges, each of which twice\pause
	\item visits every node\pause
	\item starts and ends at the same node\pause
\end{itemize}
This sequence is then called a \textit{pretour}.\pause

Its cost is twice the cost of the MST's edges.
%And the MST's edges are, as mentioned, less than the cost of an optimal tour.
\end{frame}

\subsection{Duplicate Removal}
\begin{frame}{Duplicate Removal}
Transform the pretour into a TSP tour:
%typically we require TSP tours to visits each node exactly once. Our sequence doesn't do that yet.
\begin{itemize}
	\item remove duplicate visits, replace them by shortcuts.\pause
	%That means that when the sequence goes to an already visited node, we instead jump to the next one

	\high{This can be done at one go.}
\end{itemize}
These shortcuts always exist and do not increase the cost. %That is why we require a complete metric graph
\end{frame}

\subsection{Time Complexity}%not verified
\begin{frame}{Time Complexity}\pause
\begin{itemize}
	\item MST generation: $\mathcal{O}(|E| \log |E|) = \mathcal{O}(n^2 \log (n^2)) = \mathcal{O}(2(n^2 \log n)) = \mathcal{O}(n^2 \log n)$%We use Kruskal's, which sorts edges by comparisons
	\pause
	\item Tour: $\mathcal{O}(n)$ %This is the number of edges in the MST. We discuss later how we can arrange the edges in time linear to this, to-do: Is this actually covered?
	\pause
\end{itemize}
overall: $\mathcal{O}(n^2 \log n)$
\end{frame}

\section{Results}
%What I did in the setting of this algorithm
\begin{frame}
\begin{center}
	\huge\high{Results}
\end{center}
\end{frame}

\subsection{Algorithm Sketch}
\begin{frame}{Algorithm Sketch} %and its Specification?
%We have a fixed graph here, OPT depends on it
\begin{isabelle}
	\isacommand{definition}\isamarkupfalse%
	\ two{\isacharunderscore}approx\ \isakeyword{where}\isanewline
	\ \ {\isacartoucheopen}two{\isacharunderscore}approx\ {\isacharequal}\ SPEC\ {\isacharparenleft}{\isasymlambda}T{\isachardot}\ is{\isacharunderscore}tour\ T\ {\isasymand}\ cost\ T\ {\isasymle}\ OPT\ {\isacharplus}\ OPT{\isacharparenright}{\isacartoucheclose}%explain lack of multiplication
	\vspace{1mm}\pause\\
	\isacommand{definition}\isamarkupfalse%
	\ algorithm{\isacharunderscore}sketch\ \isakeyword{where}\ {\isacartoucheopen}algorithm{\isacharunderscore}sketch\ {\isacharequal}\isanewline
	do\ {\isacharbraceleft}\isanewline
	\ \ MST\ {\isasymleftarrow}\ SPEC\ {\isacharparenleft}{\isasymlambda}E{\isacharprime}{\isachardot}\ minimum{\isacharunderscore}spanning{\isacharunderscore}tree\ {\isacharparenleft}ind\ E{\isacharprime}{\isacharparenright}\ G{\isacharparenright}{\isacharsemicolon}\isanewline
	\ \ pretour\ {\isasymleftarrow}\ SPEC\ {\isacharparenleft}{\isasymlambda}pT{\isachardot}\ int{\isacharunderscore}vertices\ pT\ {\isacharequal}\ nodes\ G\\ \ \ \ \ {\isasymand}\ cost\ pT\ {\isasymle}\ set{\isacharunderscore}cost\ MST\ {\isacharplus}\ set{\isacharunderscore}cost\ MST{\isacharparenright}{\isacharsemicolon}\isanewline
	\ \ tour\ {\isasymleftarrow}\ SPEC\ {\isacharparenleft}{\isasymlambda}T{\isachardot}\ is{\isacharunderscore}tour\ T\ {\isasymand}\ cost\ T\ {\isasymle}\ cost\ pretour{\isacharparenright}{\isacharsemicolon}\isanewline
	\ \ RETURN\ tour\isanewline
	{\isacharbraceright}{\isacartoucheclose}
\end{isabelle}\pause
\vspace{-4mm}
\begin{theorem}
	\hspace{2.6cm}$\textit{algorithm{\isacharunderscore}sketch} \le \textit{two{\isacharunderscore}approx}$\\
\upshape if $G$ is a complete finite metric graph.
\end{theorem}
\end{frame}

\subsection{Phase I}%MST generation
%It was already in a library, but had to be adjusted
\begin{frame}{Phase I}

\begin{isabelle}
	\isacommand{locale}\isamarkupfalse%
	\ finite{\isacharunderscore}weighted{\isacharunderscore}connected{\isacharunderscore}graph\ {\isacharequal}\ finite{\isacharunderscore}weighted{\isacharunderscore}graph\ {\isacharplus}\ connected{\isacharunderscore}graph\isanewline
	\isakeyword{begin}\isanewline
	\isanewline
	\ \ \isacommand{lemma}\isamarkupfalse%
	\ kruskal{\isadigit{0}}{\isacharunderscore}MST{\isacharcolon}\ {\isacartoucheopen}s{\isachardot}kruskal{\isadigit{0}}\ {\isasymle}\ SPEC\ {\isacharparenleft}{\isasymlambda}E{\isacharprime}{\isachardot}\ minimum{\isacharunderscore}spanning{\isacharunderscore}tree\ {\isacharparenleft}ind\ E{\isacharprime}{\isacharparenright}\ G{\isacharparenright}{\isacartoucheclose}
	\isanewline
	\isanewline
	\isacommand{end}\isamarkupfalse%
\end{isabelle}\pause%This also includes that the forest is a tree (simple) and that it still is minimal in the symhull (quite a bit of work...)

\begin{isabelle}
	\isacommand{sublocale}\isamarkupfalse%
	\ complete{\isacharunderscore}finite{\isacharunderscore}weighted{\isacharunderscore}graph\ {\isasymsubseteq}\\ \ \ finite{\isacharunderscore}weighted{\isacharunderscore}connected{\isacharunderscore}graph
	\end{isabelle}\pause
This required a reorganisation in the \textit{Kruskal} AFP entry.
\end{frame}

\subsection{Library Connections}
\begin{frame}{Library Connections}\pause
\vspace{3mm}
\begin{enumerate}
	\item \textit{Kruskal}: edges with weight field, undirected/directed\pause
	%to-do: vielleicht unterringeln?
	% I improved this library: I had to reorganise this one to get what I want without unnecessary assumptions.
	\item \textit{DFS\_Framework}: edges are node relations, directed\pause
	\item \textit{Koenigsberg\_Friendship}: edges have a label, undirected\pause
	%Even worse, there are different notions of "undirected"
	%So we really have the worst case in terms of compatibility.
	%Koenigsberg-Friendship also forbids loops, for technical reasons
	%It also reinterprets..., Kruskal also has a definition "is_path_undir".
	%to-do: add Noschinski, a third notion of "undirected".
	%"There are even more graph libraries out there: The somewhat new work by Noschinski starts anew,
	% with the reasonable modeling of undirected edges as two-element-sets (It sounds reasonable, and is well argued for).
	%Sadly, the fresh start did not really establish a new standard."
\end{enumerate}
%Example Conversion:\pause
\begin{isabelle}
\isacommand{lemma}\isamarkupfalse%
\ ex{\isadigit{1}}{\isacharunderscore}the{\isacharunderscore}path{\isacharcolon}\isanewline
\ \ \isakeyword{assumes}\ {\isacartoucheopen}is{\isacharunderscore}path{\isacharunderscore}undir\ G\ v\ ps\ v{\isacharprime}{\isacartoucheclose}\isanewline
\ \ \isakeyword{shows}\ {\isacartoucheopen}{\isasymexists}{\isacharbang}ps{\isacharprime}{\isachardot}\ map\ fst\ ps{\isacharprime}\ {\isacharequal}\ map\ fst\ ps\ {\isasymand}\ is{\isacharunderscore}path{\isacharunderscore}undir\ G\ v\ ps{\isacharprime}\ v{\isacharprime}{\isacartoucheclose}
\isanewline \pause
\isanewline
	\isacommand{definition}\isamarkupfalse%
	\ the{\isacharunderscore}path\ \isakeyword{where}\isanewline
	\ \ {\isacartoucheopen}the{\isacharunderscore}path\ nodelist\ lst\ {\isacharequal}\ {\isacharparenleft}case\ nodelist\ of\isanewline
	\ \ \ \ {\isacharbrackleft}{\isacharbrackright}\ {\isasymRightarrow}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbar}\isanewline
	\ \ \ \ n\ {\isacharhash}\ ns\ {\isasymRightarrow}\ THE\ ps{\isachardot}\ map\ fst\ ps\ {\isacharequal}\ nodelist\\\ \ \ \ \ \ {\isasymand}\ is{\isacharunderscore}path{\isacharunderscore}undir\ G\ n\ ps\ lst{\isacharparenright}{\isacartoucheclose}
\end{isabelle}

\end{frame}

\subsection{Library Connections -- Example}
\begin{frame}{Library Connections -- Example}\pause
\begin{isabelle}
	\isacommand{lemma}\isamarkupfalse%
	\ spanning{\isacharunderscore}forest{\isacharunderscore}symhull{\isacharcolon}\isanewline
	\ \ {\isacartoucheopen}spanning{\isacharunderscore}forest\ F\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges\ {\isacharequal}\ E{\isasymrparr}\ \\\ \ \ \ {\isasymLongrightarrow}\ spanning{\isacharunderscore}forest\ F\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges\ {\isacharequal}\ symhull\ E{\isasymrparr}{\isacartoucheclose}
\end{isabelle}\pause
\begin{isabelle}
	\isacommand{lemma}\isamarkupfalse%
	\ {\isacharparenleft}\isakeyword{in}\ finite{\isacharunderscore}weighted{\isacharunderscore}graph{\isacharparenright}\\\ \ spanning{\isacharunderscore}forest{\isacharunderscore}symhull{\isacharunderscore}preimage{\isacharcolon}\isanewline
	\ \ \isakeyword{assumes}\ {\isacartoucheopen}spanning{\isacharunderscore}forest\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges{\isacharequal}F{\isasymrparr}\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\\\ \ \ \  edges{\isacharequal}symhull\ E{\isasymrparr}{\isacartoucheclose}\isanewline
	\ \ \isakeyword{shows}\ {\isacartoucheopen}{\isasymexists}F{\isacharprime}{\isachardot}\\\ \ \ \ spanning{\isacharunderscore}forest\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges{\isacharequal}F{\isacharprime}{\isasymrparr}\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges{\isacharequal}E{\isasymrparr}\isanewline
	\ \ \ \ {\isasymand}\ edge{\isacharunderscore}weight\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges{\isacharequal}F{\isacharprime}{\isasymrparr}\ \\\ \ \ \ \ \  {\isacharequal}\ edge{\isacharunderscore}weight\ {\isasymlparr}nodes{\isacharequal}V{\isacharcomma}\ edges{\isacharequal}F{\isasymrparr}{\isacartoucheclose}
\end{isabelle}
\end{frame}

\subsection{Phase II}
\begin{frame}{Phase II}
\begin{center}
\includegraphics[height=7cm]{Sorted_binary_tree_preorder}
\end{center}
%to-do: attribute "By Sorted_binary_tree.svg: Milesderivative work: Pluke (talk) - Sorted_binary_tree.svg, Public Domain, https://commons.wikimedia.org/w/index.php?curid=10616003"
\end{frame}

\subsection{Phase II -- Parametrisation} %to-do: replace according to e-mail
\begin{frame}{Phase II -- Parametrisation}
\vspace{8mm}
We use the \textit{DFS-Framework}. This is the parametrisation:
\vspace{-2mm}
\begin{isabelle}
	\isacommand{definition}\isamarkupfalse%
	\ fp{\isadigit{0}}{\isacharunderscore}params\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}v\ fp{\isadigit{0}}{\isacharunderscore}param{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
	{\isachardoublequoteopen}fp{\isadigit{0}}{\isacharunderscore}params\ {\isasymequiv}\ dflt{\isacharunderscore}parametrization\ state{\isachardot}more\isanewline
	\ \ {\isacharparenleft}RETURN\ {\isasymlparr}\ tour{\isacharunderscore}list\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymrparr}{\isacharparenright}\isanewline
	\ \ {\isasymlparr}on{\isacharunderscore}discover\ {\isacharcolon}{\isacharequal}\ {\isasymlambda}{\isacharunderscore}\ n\ s{\isachardot}\ RETURN\ {\isasymlparr}tour{\isacharunderscore}list\ {\isacharequal}\ tour{\isacharunderscore}list\ s\ {\isacharat}\ {\isacharbrackleft}n{\isacharbrackright}{\isasymrparr}\ {\isasymrparr}{\isachardoublequoteclose}
\end{isabelle}\pause
\vspace{-5mm}
\begin{isabelle}
	\isacommand{locale}\isamarkupfalse%
	\ node{\isacharunderscore}and{\isacharunderscore}MST{\isacharunderscore}in{\isacharunderscore}graph\ {\isacharequal}\isanewline
	\ \ complete{\isacharunderscore}finite{\isacharunderscore}metric{\isacharunderscore}graph\ G\ {\isacharplus}\isanewline
	\ \ T{\isacharcolon}\ tree\ T\isanewline
	\ \ \isakeyword{for}\ G{\isacharcolon}{\isacharcolon}{\isacartoucheopen}{\isacharparenleft}{\isacharprime}v{\isacharcolon}{\isacharcolon}metric{\isacharunderscore}space{\isacharcomma}real{\isacharparenright}\ graph{\isacartoucheclose}\isanewline
	\ \ \isakeyword{and}\ T{\isacharcolon}{\isacharcolon}{\isacartoucheopen}{\isacharparenleft}{\isacharprime}v{\isacharcomma}real{\isacharparenright}\ graph{\isacartoucheclose}\ {\isacharplus}\isanewline
	\ \ \isakeyword{fixes}\ v\isactrlsub {\isadigit{0}}{\isacharcolon}{\isacharcolon}{\isacartoucheopen}{\isacharprime}v{\isacartoucheclose}\isanewline
	\ \ \isakeyword{assumes}\ v{\isacharunderscore}in{\isacharunderscore}V{\isacharcolon}\ {\isacartoucheopen}v\isactrlsub {\isadigit{0}}\ {\isasymin}\ V{\isacartoucheclose}\isanewline
	\ \ \isakeyword{and}\ mst{\isacharcolon}\ {\isacartoucheopen}minimum{\isacharunderscore}spanning{\isacharunderscore}tree\ T\ G{\isacartoucheclose}
\end{isabelle}
\end{frame}

%to-do: simplification of Phase II? not really my work, but something which slowed me down...

\section{Plans}
\begin{frame}
\begin{center}
	\huge\high{Plans}%time ran out sadly...
\end{center}
\end{frame}

\subsection{Input Generation}% We need a script that generates the edge weights for us.
\begin{frame}{Input Generation}
Consider a Euclidean space like $\RR^2$, $\RR^3$,\dots
	\begin{itemize}
		\item A popular metric is the \textit{Euclidean} metric.\pause

		\bad{It is often irrational, and thus difficult to store and compare with infinite precision.}\pause
		\item In contrast, the \textit{maximum metric} and the \textit{Manhattan metric} return natural numbers. %When the coordinates are natural numbers.
		%to-do: definition? small drawing?
	\end{itemize}
	%application drilling robot
\end{frame}

\subsection{DFS Invariant}
\begin{frame}{DFS Invariant}\pause
	finish this proof\pause
	\vspace{-2mm}
	\begin{isabelle}
		\isacommand{lemma}\isamarkupfalse%
		\ {\isacartoucheopen}dfs{\isachardot}is{\isacharunderscore}invar\ {\isacharparenleft}{\isasymlambda}s{\isachardot}\ valid{\isacharunderscore}graph{\isachardot}tour\ {\isacharparenleft}ind{\isacharprime}\ {\isacharparenleft}dom\ {\isacharparenleft}discovered\ s{\isacharparenright}{\isacharparenright}{\isacharparenright}\ {\isacharparenleft}tour{\isacharunderscore}list\ s{\isacharparenright}{\isacharparenright}{\isacartoucheclose}
	\end{isabelle}\pause
	Advancing this proof has already led to generally useful statements for the \textit{DFS-Framework}, e.g.\ \pause
	\begin{isabelle}
		\isacommand{lemma}\isamarkupfalse%
		\ i{\isacharunderscore}snd{\isacharunderscore}pending{\isacharunderscore}sane{\isacharcolon}\ {\isacartoucheopen}dfs{\isachardot}is{\isacharunderscore}invar\ {\isacharparenleft}{\isasymlambda}s{\isachardot}\ snd\ {\isacharbackquote}\ {\isacharparenleft}pending\ s{\isacharparenright}\ {\isasymsubseteq}\ V{\isacharparenright}{\isacartoucheclose}
	\end{isabelle}\pause
	\begin{isabelle}
		\isacommand{lemma}\isamarkupfalse%
		\ i{\isacharunderscore}stack{\isacharunderscore}sane{\isacharcolon}\ {\isacartoucheopen}dfs{\isachardot}is{\isacharunderscore}invar\ {\isacharparenleft}{\isasymlambda}s{\isachardot}\ set\ {\isacharparenleft}stack\ s{\isacharparenright}\ {\isasymsubseteq}\ V{\isacharparenright}{\isacartoucheclose}
	\end{isabelle}\pause
	\begin{isabelle}
		\isacommand{lemma}\isamarkupfalse%
		\ i{\isacharunderscore}discovered{\isacharunderscore}sane{\isacharcolon}\ {\isacartoucheopen}dfs{\isachardot}is{\isacharunderscore}invar\ {\isacharparenleft}{\isasymlambda}s{\isachardot}\ dom\ {\isacharparenleft}discovered\ s{\isacharparenright}\ {\isasymsubseteq}\ V{\isacharparenright}{\isacartoucheclose}
	\end{isabelle}
\end{frame}

\section{Conclusion}
\begin{frame}{Conclusion}
Even with parts already verified, formal verification can require a lot of work:
\begin{itemize}
	\item Differing graph formalisations\pause!\pause
	%in particular connecting Digraph.graph_rec to my own finite_complete_weighted...graph
	\item For this particular algorithm, a lot of assumptions have to be collected and formulated.\pause %complete_finite_weighted is actually complete_finite_weighted_simple_loopfree_metric_graph

	%"Not really part of a conclusion, but I want to mention it here since I had to leave out much context earlier for brevity."
	\item Definitions have many dependencies. %They e.g. have to fix a graph, a subtree and an arbitrary node at the same time.
\end{itemize}
\end{frame}

\section{Questions}
\begin{frame}
\begin{center}
	\huge\high{Questions}
\end{center}
\end{frame}

%to-do: Problems?

\end{document}

%to-do: compare to the plan from the meeting:
%25+5min

%explain in the presentation:

%Bibliotheken vorstellen, Wahl begründen
%--> Graphformalisierungen: directed vs. undirected edges in both phases. Welche gibt es alle?
%edge labels, i.e. a third field besides start node and end node 5min
%MST lemma zeigen, wieso nicht Graph_Theory? 5min
%was ist der projektstatus? 5min
%maybe a slide about the commit count?
%add dfs-sublocale statement to plans. "This is already proven. However, the set membership must be implemented..."


\documentclass{fancyArticle}
\usepackage{lipsum}

\title{A Sample Document}
\author{Gary Baker}
\date{\today}

\begin{document}
\maketitle

\begin{abstract}
  \lipsum[1]
\end{abstract}
\pagebreak

\section{A first section}

This\footnote{\lipsum[1][3]} demonstrates the footnote
style. \lipsum[4] Here's another footnote\footnote{\lipsum[30][1]}
followed by a numbered equation.

\begin{equation}
  \label{eq:1}
  e^{i\pi}+1 = 0
\end{equation}

\lipsum[5]

\subsection{A subsection}

\lipsum[6]

\begin{equation*}
  V(l) = \max_{\beta\geq 0}\left\{ -c(\beta) * \Delta + e^{-r\Delta}
    \left[ \int \frac{1}{2} (\tanh(l/2)+1) V(l+\hat{s}) f_\beta(s) ds \right]\right\}
\end{equation*}

\lipsum[7]

\section{A section with some citations}

\cite{Nash1950} and \cite{Rubinstein1982} say some things about
bargaining. Those citations are also clickable links to their
respective entries in the bibliography.

\lipsum [20-21]

\pagebreak
\bibliography{sampleBib.bib}

\end{document}


\documentclass{article}

\usepackage[british]{babel}
\usepackage[useregional]{datetime2}
\DTMlangsetup[en-GB]{showdayofmonth=false}

\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{float}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=black,
    filecolor=magenta,
    urlcolor=blue,
}

\title{Machine Learning}
\author{Josh Myers-Dean \and Robin Cosbey}
\date{\today}

\begin{document}

\maketitle
\newpage
\tableofcontents
\newpage

\section{Introduction}
The term ``machine learning'' was defined in 1959 as \textit{a field of study that gives computers the ability to learn without being explicitly programmed.} This means that rather than giving a computer a list of instructions to follow, we take advantage of the computer's representational abilities. The computer \textit{learns} patterns in data. Machine learning is essentially a math problem: $y = h(x)$ where $x$ is the input, $y$ is the output and $h$ represents the function (mathematical model) applied. In simple terms we are learning a mapping from $x$ to $y$. The goal of this workshop is to dive into the topics presented in \ref{fig:flow}, show how the process of each step and provide some resources.

\begin{figure}[H]
    \centering
    \includegraphics[width=3in]{flowchart.jpeg}
    \caption{General machine learning workflow. \href{https://www.freecodecamp.org/news/every-single-machine-learning-course-on-the-internet-ranked-by-your-reviews-3c4a7b8026c0/}{Link}}
    \label{fig:flow}
\end{figure}

\subsection{Unsupervised and Supervised Learning}
We primarily see \textit{unsupervised} and \textit{supervised} learning algorithms. Both are given a set of examples to learn from, known as \textit{training data}. In the case of supervised learning, we have ground truth output associated with the input data unlike unsupervised learning in which the computer is only given the input and ``clusters'' the examples based on similarity rather than learning from the mappings provided. Most of this workshop will focus on supervised learning.
\begin{figure}[H]
    \centering
    \includegraphics[width=3.1in]{supervision.png}
    \caption{Unsupervised consists of clustering whereas supervised (in this case binary classification) consists of finding a boundary between data points. \href{https://chatbotsmagazine.com/lets-know-supervised-and-unsupervised-in-an-easy-way-9168363e06ab}{Link}}
\end{figure}

\newpage
\subsection{Tasks}

The two general types of problems that can be solved with supervised machine learning techniques are \textbf{classification} and \textbf{regression}. The main difference between the two is the output: classification has a categorical (discrete) output whereas regression has a numerical (continuous) output.

\begin{figure}[H]
    \centering
    \includegraphics[width=3.5in]{tasks.png}
    \caption{Basic distinction between the two types of tasks. \href{https://medium.com/datadriveninvestor/supervised-vs-unsupervised-machine-learning-5200ffa7301a}{Link}}
    \label{fig:tasks}
\end{figure}

\subsubsection{Classification}
Classification algorithms are used when the outputs are restricted to a limited set of values. The basic form is \textit{binary classification} as shown in \ref{fig:tasks} in which the model assigns each input to one of two outputs. For example, if we have a model that identifies if an image contains a dog, the output would be the prediction of either `dog' or `not dog' (true or false).

\begin{figure}[H]
    \centering
    \includegraphics[width=3.5in]{dogs.jpg}
    \caption{Can you tell which photos contain a dog? Can a computer? \href{https://www.npr.org/sections/thesalt/2016/03/11/470084215/canine-or-cuisine-this-photo-meme-is-fetching}{Link}}
\end{figure}

\newpage
\subsubsection{Regression}
Regression involves continuous values such as temperature, length and price. You typically see regression models used for finding relationships between variables and for forecasting. How do age, gender and diet impact height? This is an example of input variables (age, gender and diet), referred to as \textit{predictor variables}, and their relationship to a single output (height) known as the \textit{outcome variable}. Unlike classification, we determine a trend from the training data fed into the model.

\begin{figure}[H]
    \centering
    \includegraphics[width=3.5in]{regression.png}
    \caption{Regression line showing the relationship between hours studied and exam score. \href{https://stackabuse.com/linear-regression-in-python-with-scikit-learn/}{Link}}
\end{figure}

\newpage
\section{Data}
So what does data look like in machine learning?
Aside from numerical data, anything that can be encoded as a numerical value or set of numerical values, such as images, words, or audio.
With images, we can encode each pixel into their RGB numerical value.
Audio data can be represented numerically based on features or by way of images with what are called spectograms.
Words can be encoded as numbers, or word frequencies throughout an entire document might be used.
We also use categorical data, a number that represents a group i.e. dogs, cats, or birds used primarily in classification tasks.
Typically, this data is put into a matrix, let's examine some famous data sets where you can see real examples of data used in machine learning.

\subsection{Data Sets}
Let's examine some data sets that are commonly used by those exploring machine learning. Probably the most famous among these data sets, is the MNIST data set; a collection of handwritten numbers. We can use this data set to classify each picture as the number it is meant to represent. The MNIST data set is quite large and machine learning models are able to get up to 99\% accuracy classifying these images.

\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{mnist.png}
    \caption{MNIST Data set \href{http://yann.lecun.com/exdb/mnist/}{dataset linked here}.}
\end{figure}

\newpage

Another smaller data set is the Iris data set. In this case, we are not dealing with image data, we are given attributes. There are three kinds of iris represented in this data set and we are given four attributes of each flower: the sepal length and width, and the petal length and width.

\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{iris.png}
    \caption{Iris Data set \href{https://archive.ics.uci.edu/ml/datasets/iris}{dataset linked here}.}
\end{figure}

This is a great data set for beginners because there are only 150 iris samples, making it easy to test and debug. Take a look at the links included to get a feel for what data looks like in machine learning.

\subsection{Bias in Data}
As you begin a machine learning project, one of the first steps is to find the dataset you will be working with. As you are forming the initial questions that you hope to answer with your efforts make sure to also ask the data some questions. Before you start building a model to work with the data, you should have a firm understanding of the distribution and makeup of the data itself. Many news stories have surfaced over the years indicating the explicit, inherent biases in many publicly released face and object recognition systems and it is not hard to believe that similar stories can be found in other domains.

This analysis of your data is especially important when considering problems directly related to society. As the systems we build gain trust from the public, we, as computer scientists, can have great implications unknowingly on the world we live in. Throughout this analysis be on the lookout for an uneven distribution of data. Additionally, keep in mind that the biases present throughout history can be found implicitly in the datasets produced in those times and by using that data to train a model you are propagating those biases forward through time. Sometimes you may need to evaluate the types of problems you are looking to solve and ensure the value of this pursuit for the community.

\newpage
\subsection{Data Preparation}
The above datasets, MNIST and Iris, are \textit{clean}. There are no missing values, or random Unicode characters that are going to trip you up when trying to parse the data. Often, data needs to be cleaned and made consistent. This process of making sure that data is clean can take up a lot of time. If an entire chunk of data is missing should it be averaged with its neighbors or be given the value of the previous data point? These are considerations a machine learning engineer will encounter. There is also the consideration of how to store input and output data as you will often train and re-train a model many times with different parameters that can be tuned called hyperparameters or maybe parse the data in a different way to see if that leads to any performance gains. Since you will want to run your model many times, you don't want to have to re-parse your cleaned data each time you want to run it as that takes a lot of time, so you will want to store your cleaned data somehow. You may also want to save various configurations of your trained model, so you will need an efficient and organized way to store trained models. You can also create data based off of your current data set, this is called data augmentation and may be something as simple as when building an image classifier reflecting some of your images horizontally or vertically to make you model more robust to image orientation. So, data preparation is a complex beast. There are many techniques that can be explored and many components to consider when preparing data.

After our data has been cleaned we typically want to split our data into train, development (sometimes called ``validation''), and test. You'll understand more in depth as to how these data sets are used after reading the \textit{Training} section. For now, understand that in order to train a model we will need data it can see (train), new data it can see to check its progress while training (development), and more data to see if it learned a pattern that can be applied to unseen data (test). We generally want to reserve 70\% for our training set, 10\% for our development set, and 20\% for our test set. You are not limited to splitting your data in this way and can try out different configurations as well.

\subsection{Training}
Once we have an understanding of the data we are working with, have preprocessed the data appropriately and split the data into a train, development and test set, now it is time to design your model. More on the types of the basic machine learning and deep learning models in future sections. The training phase allows the the model to learn from the examples provided and understand the presents in the data. The development, or validation, phase is when we tune hyperparameters -- \textit{hyperparameters} are typically related to the model architecture. Slight changes to the hyperparameters will produce different results with the model. This process repeats for a predefined amount of time. Only once we have completed training and hyperparameter tuning do we turn to the test data. The test set is used to independently assess the accuracy of the model on held out data that has not been seen previously.

\newpage
\section{Machine Learning \& Deep Learning}
There are many differences between deep learning and machine learning algorithms. Features are pieces of information that are intended to be relevant to performing a task. For example, if we were to build an animal classifier using a machine learning algorithm a feature we may want to include is the type of coat an animal has: fur, scales, or feathers. We would want to include as many of these distinctive features as possible for each animal and then give those pieces of information to our machine learning algorithm and this would create a model that can classify animals. But with deep learning we wouldn't need to manually identify distinctive characteristics of animals, we can just give our deep learning algorithm thousands of pictures of animals. Deep learning algorithms are capable of finding which pieces of information about a picture for example, are important without human assistance. This is one benefit of deep learning algorithms.

Another difference between machine learning and deep learning algorithms is their expressiveness. Machine learning algorithms generally revolve around optimizing linear functions to fit our data. However, not all patterns found in data can be expressed by linear functions.

\begin{figure}[H]
    \centering
    \includegraphics[width=5.0in]{linearvsnonlinear.png}
    \caption{Non-linear models are able to model more complex patterns.}
\end{figure}

Deep learning algorithms can consist of one or more linear or non-linear transformations. Because of this, deep learning models are able to model both linear and non-linear patterns in data. This is very powerful, and is the \textit{secret sauce} of deep learning models. Because deep learning algorithms are able to model much more complex and nuanced patterns in data, they require a lot more data than traditional machine learning algorithms which are trying to model simpler patterns. While a machine learning model may require thousands of data points to do well, a deep learning model may require millions making deep learning much more computationally expensive.

\newpage
\subsection{Decision Trees}
Decision trees are tree-like structures that can represent probability, decisions, and much more.

\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{decisiontree.png}
    \caption{Decision Tree}
\end{figure}

\subsubsection{Random Forest}
Random Forest is a supervised machine learning algorithm that can be used for both classification and regression tasks that consists of a collection of decision trees, hence the name. Here is the general algorithm:

\begin{enumerate}
    \item Split data into $n$ random sets selecting $m$ random features from each sample.
    \item Create a decision tree using each subset of data.
    \item Given new sample, each of these independent trees makes a prediction.
    \item The prediction with the most "votes" from our trees is our overall prediction.
\end{enumerate}

For a regression task, we would average the predictions made by all of the decision trees. This idea of averaging decisions of multiple models is called bootstrap aggregating or bagging and can reduce variance and overfitting.

Essentially, every decision tree will make a prediction and the most common prediction in among all of the decision trees will be the outcome. When using the random forest algorithm for regression, we will average the output of each decision tree.

\newpage
\subsection{Support Vector Machines (SVMs)}
Support vector machines are a simple model that do not require a large amount of data and separate classes represented in data. SVMs are simple discriminative classifiers that output an optimal decision boundary between the datapoints provided. When new datapoints are fed through the SVM, they are classified based on where they fall in relation to the decision boundary. This boundary is often referred to as a ``hyperplane.''  The margin is the distance from the boundary to the nearest datapoint. We want to find a decision boundary that allows points to be in their respective classes without crossing the boundary into other classes and a good margin is one where this separation is large for all classes represented. scikit-learn offers a SVM tool that is easy to download to test with given data. More information about SVMs and the toolkit can be found \href{https://scikit-learn.org/stable/modules/svm.html}{here}.

\begin{figure}[H]
    \centering
    \includegraphics[width=3.5in]{svm.jpeg}
    \caption{Decision boundary (yellow dashed line) separating the red from blue. \href{https://medium.com/deep-math-machine-learning-ai/chapter-3-support-vector-machine-with-math-47d6193c82be}{Link}}
\end{figure}

\newpage
\subsection{KNN}
K-Nearest Neighbors is an supervised machine learning algorithm that can be used for classification and regression tasks. Let's focus on classification. In this case we won't do any training using our training data, we will using the position of our training data in space to classify unseen data points.

\begin{figure}[H]
    \centering
    \includegraphics[width=4.0in]{knn.png}
    \caption{KNN Algorithm.}
\end{figure}

\begin{enumerate}
    \item Select number of neighbors to examine $k$.
    \item Given an unseen data point, find $k$ nearest data points.
    \item The class that appears the most of those $k$ nearest data points is the class of our unseen data point.
\end{enumerate}

You can experiment with different distance metrics like Euclidean distance, Manhattan distance, or Cosine similarity. Because there is no training time involved, this can be a good option when time is limited and is relatively easy to setup. K-Nearest Neighbors may not be a good idea if you have very high dimensional or feature-rich data. This is because of something called the Curse of Dimensionality; as we go into higher and higher dimensional space distance as we know it becomes more skewed and two things that are very different may seem to be "close" to each other in high dimensional space. For more on the Curse of Dimensionality and how higher dimensionality can affect your models read \href{https://towardsdatascience.com/curse-of-dimensionality-2092410f3d27}{this article}.

\newpage
\subsection{Deep Neural Networks (DNNs)}
DNNs are commonly used within problem spaces with a lot of available data. Once the data is preprocessed, we provide the data as input to the DNN. The data undergoes a series of non-linear transformations. This is what separates deep neural networks from one-layer, shallow, linear neural networks. These transformations are followed by a linear transformation which produces the output or result.
\begin{figure}[H]
    \centering
    \includegraphics[width=3.5in]{nn.jpg}
    \caption{Simple DNN with two hidden non-linear layers. \href{https://www.digitaltrends.com/cool-tech/what-is-an-artificial-neural-network/}{Link}}
\end{figure}

\href{https://playground.tensorflow.org}{Tutorial here.}

\newpage
\subsection{Convolutional Neural Networks (CNNs)}

Convolutional Neural Networks are mostly used with image data to perform image classification and other image related tasks.

\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{cnn.jpeg}
    \caption{Unrolling an RNN. Each input is fed through to produce an output at the given timestep. We also pass context forward through time. \href{https://towardsdatascience.com/a-comprehensive-guide-to-convolutional-neural-networks-the-eli5-way-3bd2b1164a53}{Link}}
\end{figure}

\subsection{Recurrent Neural Networks (RNNs)}

Recurrent Neural Networks strength lies in finding patterns in sequential data, whether that be sentences, audio, or protein sequences. They have special cells which allow them to keep important information seen from past samples or from future samples. There are many different variations of RNNs, here is a link to some RNN tutorials written in PyTorch \href{https://github.com/yunjey/pytorch-tutorial/tree/master/tutorials/02-intermediate}{here}.

\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{rnn.png}
    \caption{Unrolling an RNN. Each input is fed through to produce an output at the given timestep. We also pass context forward through time. \href{https://medium.com/@jianqiangma/all-about-recurrent-neural-networks-9e5ae2936f6e}{Link}}
\end{figure}

\newpage
\section{Further Topics}

\subsection{Reinforcement Learning}
\href{https://deepmind.com/research/publications/playing-atari-deep-reinforcement-learning/}{Paper}
\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{rl.jpg}
    \caption{In recent years deep learning has been introduced to reinforcement learning algorithms to improve performance. The agent chooses an action and receives updated information of the environment in order to choose a new action. Deep approaches have been used to augment the agent. \href{https://www.kdnuggets.com/2018/03/5-things-reinforcement-learning.html}{Link}}
\end{figure}

\subsection{Generative Adversarial Networks}
\href{https://arxiv.org/abs/1406.2661}{Paper}
\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{gans.png}
    \caption{We have been able to achieve incredible results using this model to generate things. This is done by training a generator and discriminator model. The generator tries to generate a realistic sample from the training set and the discriminator does its best to tell if the sample given to it is from the training set or a generated "fake" sample. By doing this we are able to train a generator that can create extremely good "fakes" or generated samples. Things it may try to "fake" and generate are images, audio, or video. \href{https://skymind.ai/wiki/generative-adversarial-network-gan}{Link}}
\end{figure}

\newpage
\subsection{Few Shot Learning}
\href{https://openreview.net/forum?id=HkxLXnAcFQ}{Paper}
\begin{figure}[H]
    \centering
    \includegraphics[width=4.5in]{fewshot.png}
    \caption{Few shot learning works to train a model on very few examples of given classes. Many training episodes are used to understand the distinctions between the classes provided.  \href{https://medium.com/sap-machine-learning-research/deep-few-shot-learning-a1caa289f18}{Link}}
\end{figure}
\newpage

\end{document}


\documentclass[10pt]{article}
\usepackage[T1]{fontenc}

% Document Details
\newcommand{\CLASS}{AMATH 563}
\newcommand{\assigmentnum}{Nueral Networks}

\usepackage[margin = 1in, left=0.75in,right=0.75in]{geometry}
\input{../../import/title.tex} % Title Styling
\input{../../import/styling.tex} % General Styling
\input{../../import/code.tex} % Code Display Setup
\input{../../import/math.tex} % Math shortcuts

\usepackage{dblfloatfix}    % To enable figures at the bottom of page

% Problem
\newenvironment{problem}[1]{\vspace{2em}{\large\sffamily\textbf{#1}}\itshape\par}{}

\usepackage{nameref}
\newcommand{\vln}{\rotatebox{90}{--}}

\begin{document}

\twocolumn[{%
\begin{@twocolumnfalse}
\maketitle
\vspace{2em}
\begin{abstract}
We outline a how neural networks might be applied to the study of systems governed by possibly unknown PDEs. In particular we show that future state predictions are possible for some systems, even if they are chaotic. We address how high dimensional data can be rank reduced first in order to allow for training on a smaller neural net. While some results are encouraging, we find that it is quite difficult to correctly tune the neural networks in a limited time.
\end{abstract}

\vspace{4em}
%\tableofcontents
%\vspace{3em}
\pagebreak\end{@twocolumnfalse}
}]

\section{Introduction and Overview}
With recent increases in computation power and data storage capabilities our ability effectively process data computationally has increases substantially. Machine learning uses statistical techniques to gather information about a dataset and use it to make predictions or understand trends. One class of machine learning methods, neural networks, is particularly effective given large datasets. If neural nets can be effectively used to predict solutions of PDEs then we can step away from trying to guess at the PDEs which actually describe systems and move towards generating trajectories using these neural nets.

\section{Theoretical Background}
\subsection{Neural Network Basics}
Suppose we have sets \( \hat{X}_0 \) and \( \hat{X}_N \) with elements of size \( m \) and \( n \) respectively. Let \( \hat{f}:\hat{X}_0 \to \hat{X}_N \) be an injection. The goal of a neural network is to be able to accurately compute this injection to make predictions about elements of \( \hat{X}_0 \) for which we do not know the actual value of \( \hat{f} \).

A feed forward neural network is a function of the form,
\begin{align}
    X_N = f_N(b_{N-1}+\cdots f_2(b_1+ W_1f_1(b_0 + W_0x_0))) \label{NN}
\end{align}
where the the ``activation'' functions \( f_j:\RR\to\RR \) are applied componentwise.

Each ``layer'' is of the form,
\begin{align*}
    x_{j+1} = f_{j+1}j(W_j x_{j} + b_j), && j=0,1,\ldots, N-1
\end{align*}

Note that \( W_j \) can be of any shape compatible with \( x_j \) with the constraint that \( W_{N-1} \) must also give something of the dimension of \( x_N \).

The goal is to set the parameters \( W_j \) and \( b_j \) so that the neural network is equal to \( \hat{f} \). However, it is clear that unless we know the output of \( f \) on all of \( \hat{X}_0 \) this will not be possible even if our neural net has the same form as \( \hat{f} \). Since in general we would like to be able to make predictions about unknown data we will have to settle for the neural network being an approximation to \( \hat{f} \).

More specifically, let \( X_0\subset \hat{X}_0 \) and suppose the value of \( \hat{f}(x) \) is known for all \( x\in X_0 \). For convenience we will write \( X_0 \) as a matrix of size \( n\times t \). Define \( X_N\subset \hat{X}_N \) as the \( m\times t \) matrix found by applying \( \hat{f} \) to the columns of \( X_0 \). We will use the data from \( X_0 \) to train the neural net to (hopefully) give us a good approximation for \( \hat{f} \). Since the neural network can take any element of \( \hat{X}_0 \) as input, we hope that it can be used for predictions about the value of \( \hat{f} \) on these elements.

\subsection{Loss functions}
Given a neural network we would like to train it to be able to make predictions. In order to do this we need some way of saying what a good prediction is. In general this is done by defining a loss function which is small when the network gives good predictions, and large when it gives bad predictions.

More specifically, let \( X_0\in\RR^{n} \) and \( X_N\in\RR^{m} \) be the input data and target data respectively. Let \( f:\RR^{n}\times\RR^{Z}\to\RR^{m} \) be a neural network as defined above, where \( Z \) is the number of free parameters. The residual error of the network for a fixed set of parameters \( \beta\in\RR^{Z} \) is \( Y - f(X,\beta) \).

Ideally the residual error is zero. By picking some metric with which to measure the residual error, we have a minimization problem. In this paper we often chose to minimize the mean square error, which amounts to solving,
\begin{align}
    \min_{\beta} \sum_{x_0\in X_0} \norm{\hat{f}(x_0)-f(x_0,\beta)}_2^2 \label{mse}
\end{align}

\subsection{Optimizers}
In order to minimize expressions such as (\ref{mse}) an optimization algorithm must be applied. Since the input and output lie in such high dimensional spaces, the loss function often has many local minimum or saddle points. As such, traditional methods such as gradient decent may not work very well. Instead there are many popular gradient based algorithms which introduce some stochasticity in order to avoid ``getting stuck''. Since our neural network can be expressed as the composition of fairly straightforward functions, the gradient with respect to entries of \( \beta \) can be easily computed using the chain rule (done by something called back-propagation).

\subsection{SVD and Data reduction}
When training a neural network the size of the input and output are determine by the data given. This means the network may have to be very large the the beginning and end nodes. On approach to reduce the size of the network is to project the input and target data into lower dimensional subspaces and then train on the projections. This is equivalent to the first and last hidden layers of the neural net being of smaller size and with fixed weights. If the weights are not fixed, the net will determine the ``best'' projection. However, since the SVD already computes the optimal low rank approximation in the 2-norm or Frobenius norm, it may be beneficial to set these weights so that the net does not have to learn them.

Suppose our input data \( X \) is in \( \RR^{N} \) and we have \( T \) samples. We then have a \( N\times T \) data matrix. We would like to find a subspace of \( \RR^{N} \) of lower dimension where our data can be approximated well. Our data has a rank \( k \) reduced SVD,
\begin{align}
    X \approx U\Sigma V^* \label{SVD_eq}
\end{align}
where \( U  \) is \( N\times k \), \( \Sigma \) is \( k\times k \), and \( V^* \) is \( k\times T \). We interpret this in the following way: the columns of \( U \) are the dominant modes in our data, and the rows of \( \Sigma V^* \) tell us how these modes vary in time. We can therefore use the columns of \( \Sigma V^* \), which are of height \( k \), as our approximation to the input data.

In general the input and target data will not be of the same size or, for time series data, of the same dynamics. However, in the case that they are the rank reduction used on the input and output can be computed simultaneously saving a large computation. While it will no longer be the optimal reduction for each of these, it will be near optimal. In this paper we are generally building steppers, and so the input and target are of the same system at different times. We therefore compute the low dimensional spaces by taking the SVD of the full data set, and then split it into the input and target data sets.

\section{Algorithm Implementation and Development}

\subsection{Neural Network Framework}
We use the python libraries Keras and Tensorflow for most of our neural nets. In addition the neural network package for MATLAB is occasionally used.

In general, the setup and labeling of the data was the primary focus of this project. It is straightforward to change the net structure and tune other hyperparameters once this has been done. However, doing so is time consuming. If any of the nets work at all this should be taken as very encouraging since they were generally chosen at random without much justification.

\subsection{Data Generation}
To generate data for our systems we generally use an ODE stepper to solve a system of ODEs corresponding to the discrimination of a PDE. The target data is taken to be the training data one step forward in time (with respect to some fixed time mesh). Multiple initial conditions are generated in a variety of ways depending on

\subsection{Kuramoto-Sivashinsky Equation}
We are provided with a stepper to produce solutions to the Kuramoto-Sivashinsky equation (\ref{KS_eqn}) with periodic boundary conditions on a given mesh (with \( N \) spatial points and \( T \) time points).
\begin{align}
    \pp{u}{t} = -u \pp{u}{x} - \pp[2]{u}{x} - \pp[4]{u}{x} \label{KS_eqn}
\end{align}

In order to train our network to step forward in time we must generate a batch of trajectories stemming from some class of initial conditions. To do this we start with a zero initial condition and then randomly set a fixed (generally two or three) number Fourier modes to have weights with real and imaginary parts uniformly distributed on \( [-N/2,N/2] \). This produces periodic initial conditions which lead to fairly nice behavior. We then generate a solutions with these initial conditions and save them.

The data is then imported to Python and formatted into the training and target data sets by appropriate slicing. A neural net defined in Keras is trained to predict the value of \( u(t+\Delta t) \) given the value of \( u(t) \).

\begin{figure}[t]\centering
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/svd_mode_1.pdf}
    \caption{1st left singular vector reshaped}
    \label{1mode}
\end{subfigure}\hfill
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/svd_mode_100.pdf}
    \caption{100th singular vector reshaped}
    \label{100mode}
\end{subfigure}
\caption{SVD modes for \( u \) (left) and \( v \) (right) }
\label{SVD_modes}
\end{figure}

\begin{figure}[t]\centering
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/svd_coeff_1.pdf}
    \caption{1st right singular vector varying in time}
    \label{1coeff}
\end{subfigure}
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/svd_coeff_100.pdf}
    \caption{100th right singular vector varying in time}
    \label{100coeff}
\end{subfigure}
\caption{coefficients of SVD modes vs dataset}
\label{SVD_coeff}
\end{figure}

\subsection{ \( \boldsymbol\lambda \)-\( \boldsymbol\omega \) Reaction-Diffusion Equation}
We can apply similar methods to a PDE in two dimensions.
With,
\begin{align*}
    {\bf u} = \left[\begin{array}{c}u \\ v\end{array}\right], &&
    {\bf D} = \left[\begin{array}{cc}d_1 \\ & d_2 \end{array}\right]
\end{align*}
the Kuramoto-Sivashinsky equation is defined as,
\begin{align}
    \pp{{\bf u}}{t} =
    \left[\begin{array}{cc}
        \lambda(s) & -\omega(s) \\
        \omega(s) & \lambda(s)
    \end{array}\right]
    {\bf u}
    + {\bf D} \nabla^2 {\bf u} \label{RD_eqn}
\end{align}
where,
\begin{align*}
    s^2 = u^2 + v^2, &&
    \lambda = 1-s^2, &&
    \omega = -\beta s^2
\end{align*}

Again we are given a stepper which produces trajectories on a fixed mesh. Like with the KS equation, we generate initial conditions by picking some Fourier modes to be nonzero and use these to generate trajectories which we load into Python.

Since the data is much larger than before, training a neural net (we tried) is very slow. While the size of data used in industry is often massive, they also have massive computers and lots of time. We don't, so to deal with the large data set we reduce the rank of our data and train on the projections. Since the training and target data come from the same space we compute the SVD the entire dataset before splitting it into training and target data. This allows us to find a single subspace for both the training and target data, saving on computing and saving two subspaces (which would turn out to be almost identical since the vast majority of the data in each of these sets would be the same).

\begin{figure*}[h]\centering
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/sample_KS_trajectory.pdf}
    \caption{trajectory generated by {\tt solve\_ivp}}
    \label{sample_KS_trajectory}
\end{subfigure}\hfill
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/predicted_KS_trajectory.pdf}
    \caption{trajectory generated by neural net}
    \label{predicted_KS_trajectory}
\end{subfigure}
\caption{``actual'' and neural net predicted trajectories for Kuramoto-Sivashinsky equation (\ref{KS_eqn})}
\label{KS_trajectory}
\end{figure*}

Figure~\ref{1mode} shows the dominant left singular vector and Figure~\ref{1coeff} shows how the first right singular vector varies in time. The ``spikes'' down clearly are related to the initial conditions of the data. However, after each spike there is an oscillation in this mode. Moreover, the mode itself has quite a bit of structure, which it seems to have inherited from the way we generated initial conditions. It is not clear whether this structure would die out if we ran the simulations for longer time. Regardless, since the structure is present in our data set we can use this to train a neural net on the rank-reduced data.

We take the rank \( k \) SVD (\ref{SVD_eq}) (determined by a parameter flag) and then train the network on the weights of the basis of the subspace spanned by the first \( k \) columns of \( U \).

To test our prediction we take a trajectory not used for training, project it to the column span of \( U \), iteratively apply the network, and then embed back to the original space.

\subsection{Lorenz Equation}
The Lorenz equation (\ref{lorenz_eq}) is a system of ODEs which have chaotic solutions for some parameters. It was demonstrated in \cite{lecture_notes} that for a fixed \( \Delta t \) a simple neural network can be trained to predict the position at a time \( t+\Delta t \) given the position at time \( t \) accurately enough that the trajectory determined by iteratively applying the trained neural net matches the trajectory of a given ODE solver almost exactly. Given that the system is chaotic for these values it is somewhat surprising that the neural net manages to follow the same trajectory by only predicting one step at a time. Training data was generating using Scipy's {\tt solve\_ivp} with a tolerance of \( 10^{-10} \) and evaluating the solution along a mesh of uniformly spaced times.

\begin{align}
    \pp{}{t} \left[\begin{array}{c}x\\y\\z\end{array}\right]
    =
    \left[\begin{array}{c}
        \sigma(y-x) \\
        x (\rho-z)-y \\
        x y-\beta z
    \end{array}\right] \label{lorenz_eq}
\end{align}

We explore the Lorenz equation in two further ways, namely trying to predict trajectories for varying values of the parameter \( \rho \) and trying to predict when the solution will transition from one lobe to another.

The first task is straightforward. In particular, a neural net is trained on data where the input corresponds to the current position as well as the value of \( \rho \), and the output is the position after a time of \( \Delta t \). More specifically, we fix \( \sigma = 10 \), \( \beta = 8/3 \), and train on data with \( \rho = 10,28,40 \). We then try to use this net to predict trajectories for \( \rho = 17 \) and \( \rho = 35 \).

The second tasks requires some interpretation. We decided to train a network to determine how long until a lobe switch. To train such a network requires that we know how long it will be until the solution switches lobes. To do this we first classify what it means to be at a given lobe. This is done by separating the data with plane as shown in Figure~\ref{separating_hyperplane}. Let \( c \) be a normal vector for this hyperplane. Then the sign of \( c^Tx \) will determine which side of the plane a given point is on.

We pick \( c \) roughly in the direction of the vector connecting the two centers in the \( x \)-\( y \) plane. While there are probably better ways to do this, it seems like the projection to this plane provides a straightforward way to separate points circle different lobes.

Therefore, given a trajectory \( X \), each point in the trajectory can be classified as ``left'' or ``right''. Once this is done, we know that transitions across the plane occur when the trajectory switches from ``left'' to ``right'' or from ``right'' to ``left''. We compute these transition points by taking the difference of consecutive points in \( \operatorname{sign}(c^TX) \). If the difference is nonzero then the trajectory has switched lobes. Once we have these transition points it is relatively straightforward label each point in the trajectory with far each point is from the next crossover.

As a minor note, some of the data from the end of the each trajectory is discarded because it is not possible to tell when the next transition will occur without stepping out the solution further. We then train a neural network to try and predict the time until a crossover.
\begin{figure}[tb!]\centering
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/uv_t180.pdf}
    \caption{original data}
    \label{time_image}
\end{subfigure}\hfill
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/svd_t180.pdf}
    \caption{SVD (rank 100)}
    \label{SVD_time_image}
\end{subfigure}
\caption{snapshot of \( u \) (left) and \( v \) (right) at time \( t=180 \)}
\label{RD_SVD}
\end{figure}

\begin{figure}[b!]\centering
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/prediction_t15.pdf}
    \caption{actual trajectory}
    \label{sample_RD_trajectory}
\end{subfigure}\hfill
\begin{subfigure}{.45\textwidth}\centering
    \includegraphics[width=\textwidth]{img/svd_prediction_t15.pdf}
    \caption{predicted trajectory}
    \label{predicted_RD_trajectory}
\end{subfigure}
\caption{``actual'' and neural net predicted trajectories for Reaction Diffusion Equation (\ref{RD_eqn}) at \( t=15 \)}
\label{RD_trajectory}
\end{figure}

\begin{figure}[t!]\centering
\begin{subfigure}{.45\textwidth}\centering
\includegraphics[width=\textwidth]{img/NN_lrz17_trajectory.pdf}
\caption{\( \rho = 17 \)}
\end{subfigure}\hfill
\begin{subfigure}{.45\textwidth}\centering
\includegraphics[width=\textwidth]{img/NN_lrz35_trajectory.pdf} \hfill
\caption{\( \rho = 35 \)}
\end{subfigure}
\caption{Actual trajectory (solid) vs predicted trajectory (dotted) for variious values of \( \rho \)}
\label{xyz_trajectory}
\end{figure}

\section{Computational Results}

\subsection{Kuramoto-Sivashinsky Equation}

Figure~\ref{sample_KS_trajectory} shows a sample trajectory generated by our ODE stepper (not part of traninig data). Figure~\ref{predicted_KS_trajectory} shows the prediction of the neural net on the same trajectory. However, as time progresses the neural net predicted solution does not really change, while the reaction diffusion equation does continue to evolve.

\subsection{ \( \boldsymbol\lambda \)-\( \boldsymbol\omega \) Reaction-Diffusion Equation}
Figure~\ref{time_image} shows a snaptshot of a trajectory at time \( t=180 \). Figure~\ref{SVD_time_image} shows the same snapshot after it has been projected into a 100 dimensional subspace determined by the SVD. While a plot of the singular values shows no clear cutoff in the rank, visually it seems that the data is fairly well represented by the first 100 modes. We proceed to train a neural network on the rank reduced data.

\begin{figure}[bt!]\centering
\begin{subfigure}{.45\textwidth}\centering
\includegraphics[width=\textwidth]{img/separating_hyerplane.pdf}
\caption{Projection of sample trajectory onto the \( x \)-\( y \) plane along with image of plane \( y + 5x +0z = 0 \).}
\label{separating_hyperplane}
\end{subfigure}\hfill
\begin{subfigure}{.45\textwidth}\centering
\includegraphics[width=\textwidth]{img/jump_predictor.pdf}
\caption{Actual time to jump (solid) vs. predicted time to jump (dotted) for sample trajectory .}
\label{jump_predictor}
\end{subfigure}
\caption{}
\end{figure}

\subsection{Lorenz Equation}
Sample predictions for \( \rho = 17 \) and \( \rho = 35 \) produced by the trained net are shown in Figure~\ref{xyz_trajectory}. Note that we do not cross validate in the normal sense, since that would be testing how well our net can predict one step in the future. In fact, the cross validation would show a very high accuracy since we are able to predict the long term behavior relatively well despite only training n the current position.

Figure~\ref{jump_predictor} shows the results of applying the trained net to every point in a trajectory. This plot makes it clear that we are actually able to fairly effectively determine when a jump will occur given only the current position. Note here that the horizontal axis labeling is just the index of the point in the trajectory and has no impact on the neural net's prediction as it is applied independently to each point.

\pagebreak
\section{Summary and Conclusions}
It is clear that the trajectories of the Kuramoto-Sivashinsky and Reaction Difussion equations were not effectively predicted. On the other hand, solutions to the Lorenz equation, even for values of \( \rho \) which the neural net had never seen, were quite successful. Finally, we were able to train a neural net to predict how long it would take a trajectory to switch lobes.

Due to time constraints only simple nets were used and all hyperparameter training was done by guessing. We instead chose to focus on producing the training data in a scalable way so that in the future it would be a trivial task to generate data at large mesh sizes. With the current state of our codebase, testing new neural nets is as easy as changing a few lines in Keras. Given more time we would have liked to set up convolutional neural nets to see if the local structure of the data would be enough to determine the global behavior. In general we probably did not use enough data, and the nets we used are probably too small to be able to get very good results. However, what we did find is somewhat encouraging and given more time would be worth pursuing.

\bibliographystyle{plain}
\bibliography{hw2}

\onecolumn
\section{Appendix A}
\label{AppendixA}
All functions are included in the code in Appendix B as they are specific to the task performed in each of the files.

%\pagebreak
\section{Appendix B}
\lstinputlisting[]{PDECODES/KS_data_gen.m}
\lstinputlisting[]{python/hw2_ks.py}
\lstinputlisting[]{PDECODES/RD_data_gen.m}
\lstinputlisting[]{python/hw2_rd.py}
\lstinputlisting[]{python/hw2_lrz.py}
\lstinputlisting[]{python/lrz_classifier.py}

\end{document}


\documentclass[]{article}
\usepackage{proceed2e}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{graphicx}
\usepackage{preamble}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{color}
\definecolor{mydarkblue}{rgb}{0,0.08,0.45}
\hypersetup{ %
    pdftitle={},
    pdfauthor={},
    pdfsubject={},
    pdfkeywords={},
    pdfborder=0 0 0,
    pdfpagemode=UseNone,
    colorlinks=true,
    linkcolor=mydarkblue,
    citecolor=mydarkblue,
    filecolor=mydarkblue,
    urlcolor=mydarkblue,
    pdfview=FitH}

\title{Bayesian Quadrature minimizes Maximum Mean Discrepancy}

\author{ {\bf Ferenc Husz\'{a}r} \\
Department of Engineering\\
Cambridge University\\
\texttt{fh277@cam.ac.uk}
\And
{\bf David Duvenaud } \\ %\thanks{Both authors contributed equally.} \\
Department of Engineering\\
Cambridge University \\
\texttt{dkd23@cam.ac.uk}
}

\begin{document}

\maketitle

%\begin{abstract}
%Maximum Mean Discrepancy is equivalent to the posterior variance of an integrated Gaussian process.
%\end{abstract}

\section{INTRODUCTION}
A common problem in statistical machine learning is to compute expectations of functions over probability distributions of the form:
\begin{equation}
	Z_{f,p} = \int f(x) p(x) dx \label{eqn:integral}
\end{equation}
Examples include computing marginal distributions, making predictions marginalizing over parameters, or computing the Bayes risk in a decision problem. %In this paper we assume that the distribution $p(x)$ is known in analytic form, and $f(x)$ can be evaluated at arbitrary locations.

%Monte Carlo methods produce random samples from the distribution $p$ and then approximate the integral by taking the empirical mean $\hat{Z} = \frac{1}{N}\sum_{n=1}^{N}f_{x_n}$ of the function evaluated at those points. This non-deterministic estimate converges at a rate $\mathcal{O}(\frac{1}{\sqrt{N}})$. When exact sampling from $p$ is impossible or impractical, Markov chain Monte Carlo (MCMC) methods are often used. MCMC methods can be applied to almost any problem but convergence of the estimate depends on several factors and is hard to estimate \citep{CowlesCarlin96}. The focus of this paper is on quasi-Monte Carlo methods that -- instead of sampling randomly -- produce a set of pseudo-samples in a deterministic fashion. These methods operate by directly minimising some sort of discrepancy between the empirical distribution of pseudo-samples and the target distribution. Whenever these methods are applicable, they achieve convergence rates superior to the $\mathcal{O}(\frac{1}{\sqrt{N}})$ rate typical of random sampling.

%In this paper we highlight and explore the connections between two deterministic sampling and integration methods: Bayesian quadrature (\bq{}) \citep{BZHermiteQuadrature,BZMonteCarlo} (also known as Bayesian Monte Carlo) and kernel herding \citep{chen2010super}. Bayesian quadrature estimates integral \eqref{eqn:integral} by inferring a posterior distribution over $f$ conditioned on the observed evaluations $f_{x_n}$, and then computing the posterior expectation of $Z_{f,p}$. The points where the function should be evaluated can be found via Bayesian experimental design, providing a deterministic procedure for selecting sample locations.% We call this procedure Sequential Bayesian Quadrature (\sbq).

%Herding, proposed recently by \cite{chen2010super}, produces pseudosamples by minimising the discrepancy of moments between the sample set and the target distribution. Similarly to traditional Monte Carlo, an estimate is formed by taking the empirical mean over samples $\hat{Z} = \frac{1}{N}\sum_{n=1}^{N}f_{x_n}$. Under certain assumptions, herding has provably fast, $\mathcal{O}(\frac{1}{N})$ convergence rates in the parametric case, and has demonstrated strong empirical performance in a variety of tasks.

In this paper, we make two main contributions.  Firs, we show that the Maximum Mean Discrepancy (MMD) criterion (used to choose samples in kernel herding) is identical to the expected error in the estimate of the integral $Z_{f,p}$ under a Gaussian process prior for $f$.  This expected error is the criterion being minimized when choosing samples for Bayesian quadrature (BQ).  Because Bayesian quadrature assigns different weights to each of the observed function values $f(\vx)$, we can view Bayesian quadrature as a weighted version of kernel herding.
 We show that these weights are optimal in a minimax sense over all functions in the Hilbert space defined by our kernel.  This implies that Bayesian quadrature dominates kernel herding and other non-optimally weighted herding in rate of convergence.

We further show that the MMD, when using BQ weights, is submodular in the samples chosen, which implies that sequential BQ achieves the optimal rate of convergence for any sampling method.

\section{HERDING}

Herding was introduced by \cite{welling2009herding} as a method for generating pseudo-samples from a distribution in such a way that certain nonlinear moments of the sample set closely match those of the target distribution.  The empirical mean $\frac{1}{N}\sum_{n=1}^{N}f_{x_n}$ over these pseudosamples is then used to estimate integral \eqref{eqn:integral}.

\subsection{Maximum Mean Discrepancy}

For selecting pseudosamples, herding relies on an objective based on the maximum mean discrepancy \citep[MMD;\ ][]{Sriperumbudur2010}: %MMD measures the divergence between two distributions, $p$ and $q$ with respect to a class of integrand functions $\mathcal{F}$ as follows:
%
\begin{align}
	\mmd_{\mathcal{F}}\left(p,q\right) = \sup_{f\in\mathcal{F}}\left\vert\int f_x p(x) dx - \int f_x q(x) dx \right\vert
\end{align}
%
%Intuitively, if two distributions are close in the MMD sense, then no matter which function $f$ we choose from $\mathcal{F}$, the difference in its integral over $p$ or $q$ should be small. A particularly interesting case is
%
When the function class $\mathcal{F}$ is functions of unit norm from a reproducing kernel Hilbert space (RKHS) $\He$, the MMD between two distributions can be conveniently expressed using only expectations of the associated kernel $k(x, x')$ \citep{Sriperumbudur2010}.
%
%\begin{align}
%MMD^2_{\He}(p,q) =& \sup_{\substack{f\in\He\\\Hnorm{f}=1}}\left\vert\int f_x p(x) dx - \int f_x q(x) dx\right\vert^2\\
%	=& \Hnorm{\mu_{p} - \mu_{q}}^2\\
%\nonumber	=&\iint k(x,y) p(x) p(y) dx dy\\
%\nonumber	-2 &\iint k(x,y) p(x) q(y) dx dy\\
%	+ &\iint k(x,y) q(x) q(y) dx dy,
%\end{align}
%
%where in the above formula $\mu_{p}=\int \phi(\vx)p(\vx)d\vx\in\He$ denotes the \emph{mean element} associated with the distribution $p$.
% For characteristic kernels, such as the Gaussian kernel, the mapping between a distribution and its mean element is bijective. As a consequence $\mmd_{\He}(p,q)=0$ if and only if $p=q$, making it a powerful measure of divergence.
%
Herding uses MMD to evaluate how well the sample set $\{\vx_1,\ldots,\vx_{N}\}$ represents the target distribution $p$, adding points greedily according to:
%
%\begin{align}
%	\epsilon_{herding}&\left(\{\vx_1,\ldots,\vx_{N}\}\right) = \mmd_{\He}\left(p,\frac{1}{N}\sum_{n=1}^{N}\delta_{x_n}\right)\\
%\nonumber	=&\iint k(x,y) p(x) p(y) dx dy\\
%		-2 &\frac{1}{N}\sum_{n=1}^{N}\int k(x,x_n) p(x) dx
%		+ \frac{1}{N^2}\sum_{n,m=1}^{N} k(x_n,x_m)
%\label{eq:mmd_assumption}
%\end{align}
%
%The herding procedure greedily minimizes its objective $\epsilon_{herding}\left(\{\vx_1,\ldots,\vx_{N}\}\right)$ , adding pseudosamples $\vx_n$ one at a time. When selecting the $n+1$-st pseudosample:
%
\begin{align}
\vx_{n+1} &\leftarrow \argmin_{\vx \in \mathcal{X}} \label{eqn:herding_criterion} \epsilon_{herding}\left(\{\vx_1,\ldots,\vx_{n},\vx\}\right)\\
	&= \argmax_{\vx \in \mathcal{X}} 2 \expectargs{\vx' \sim p}{k(\vx, \vx')} - \frac{1}{n+1}\sum_{m=1}^{n} k(\vx,\vx_m)\mbox{,}\notag
\end{align}
%
assuming $k(\vx,\vx) = \mbox{const}$.
The formula \eqref{eqn:herding_criterion} admits an intuitive interpretation: the first term encourages sampling in areas with high mass under the target distribution $p(\vx)$.  The second term discourages sampling at points close to existing samples.

\section{BAYESIAN QUADRATURE}

%\begin{figure}
%\centering
%\includegraphics[width=\columnwidth]{figures/bq_intro4}
%\caption{An illustration of Bayesian Quadrature.  The function $f(x)$ is sampled at a set of input locations.  %This induces a Gaussian process posterior distribution on $f$, which is integrated in closed form against the target density, $p(\vx)$.  Since the amount of volume under $f$ is uncertain, this gives rise to a (Gaussian) posterior distribution over $Z_{f,p}$.}
%\label{fig:bq_intro}
%\end{figure}

Bayesian quadrature (\bq) puts a prior distribution on $\vf$, then estimates integral \eqref{eqn:integral} by inferring a posterior distribution over the function $\vf$, conditioned on the observations $\vf(\vx_n)$ at some query points $\vx_n$.  For simplicity, $\vf$ is assigned a Gaussian process prior with kernel function $k$ and mean $0$.  This assumption is very similar to the one made by kernel herding.  The posterior distribution over $f$ then implies a distribution over $Z_{f,p}$. %See Figure \ref{fig:bq_intro} for an illustration of Bayesian Quadrature.
%
%\subsection{ BQ Estimator}
%
%Here we derive the \bq{} estimate of \eqref{eqn:integral}, after conditioning on function evaluations $\vf(\vx_1) \dots \vf(\vx_N)$, denoted as $f(\vX)$.
 The mean of this distribution, $\expectargs{}{Z}$ is the optimal Bayesian estimator for a squared loss.
%After conditioning on $\vf(\vX)$, we obtain a closed-form posterior over $\vf$.
%
%\begin{align}
%p(\vf(\vx\st)|\vf(\vX)) = \N{\vf(\vx\st)}{\mf(\vx\st)}{\cov(\vx\st,\vx\st')}
%\end{align}
%where
%\begin{align}
%\mf(\vx\st) = & k(\vx\st, \vX) K^{-1} \vf(\vX) \\
%\cov(\vx\st, \vx\st') = & k(\vx\st,\vx\st) - k(\vx\st, \vX) K^{-1} k(\vX, \vx\st)
%\end{align}
%
%and $K = k(\vX, \vX)$.
%
Conveniently, the \gp{} posterior allows us to compute the expectation of \eqref{eqn:integral} in closed form:
%
%\begin{align}
%Z & = \int f(\vx)p(\vx)d\vx
%\end{align}
%so we integrate over functions to get:
\begin{align}
\expectargs{\gp}{Z} & = \vz^T K^{-1} \vf(\vX)
\label{eq:marg_mean_symbolic}
\end{align}
where
\begin{align}
z_n & = \int\!\! k(\vx, \vx_n) p(\vx) d\vx = \expectargs{\vx' \sim p}{k(\vx_n, \vx')}.
\end{align}
%
As in kernel herding, the desired expectation of $Z_{f,p}$ is simply a linear combination of observed function values $\vf(\vx)$:
%
\begin{align}
\expectargs{\gp}{Z} & = \vz^T K^{-1} \vf(\vX) \\
    & = \sum_n w_{\bq}^{(n)} f(x_n)  \quad \textrm{where} \quad w_{\bq}^{(n)} = \sum_m \vz_j K^{-1}_{nm}
\end{align}
%
%\begin{align}
%w_{\bq}^{(n)} & = \sum_m \vz_j K^{-1}_{nm}
%\label{eq:bq_weights}
%\end{align}
%
Thus, we can view the BQ estimate as a weighted version of the herding estimate.

\subsection{Optimal sampling for BQ}

The posterior variance $\varianceargs{}{Z_{f,p}|f_{x_1}, \dots, f_{x_N}}$ quantifies our uncertainty in the estimate of the integral. When selecting locations to evaluate the function $f$, minimising the posterior variance is a sensible strategy. Below, we give a closed form formula for the posterior variance of $Z_{f,p}$, conditioned on the observations $f_{x_1} \dots f_{x_N}$, which we will denote by $\epsilon^2_{\bq{}}$.
\begin{align}
\epsilon^{2}_{\bq{}} = \varianceargs{}{Z_{f,p}|f_{x_1}, \dots, f_{x_N}}
% \nonumber & = \expectargs{f \sim \gp, p\sim p(x)}{ \left( f(\vx) - \mf(\vx) \right)\left( f(\vx') - \mf(\vx') \right)} \\
%\nonumber & = \int \Bigg( \!\! \left( \int f(\vx) p(\vx) d\vx - \int \mf(\vx') p(\vx') d\vx' \right) \\
%\nonumber & \quad \times \left( \int f(\vx) p(\vx) d\vx - \int \mf(\vx') p(\vx') d\vx' \right) \!\! \Bigg) p(f) df \\
%\nonumber & = \int\!\!\! \int\!\! \int\!\! \left[ f(\vx) - \mf(\vx) \right] \left[ f((\vx') - \mf(\vx') \right] p(f) df \\
%\nonumber & \qquad \times   p(\vx) p(\vx') d\vx d\vx' \\
%\nonumber & = \int\!\! \!\int\!\! \Cov \left[ f((\vx), f((\vx') \right] p(\vx) p(\vx') d\vx d\vx' \\
%\nonumber & = \int\!\!\! \int\!\! \left[ k(\vx, \vx') - k(\vx, \vX) K^{-1} k(\vX, \vx') \right] \\
%\nonumber          & \qquad \times p(\vx) p(\vx') d\vx d\vx' \\
%\nonumber & = \int\!\!\! \int\!\! k(\vx, \vx') p(\vx) p(\vx') d\vx d\vx' \\
%\nonumber & \quad - \left[ \int\!\! k(\vx, \vX) p(\vx) d\vx \right] K^{-1} \left[ \int\!\! k(\vX, \vx') p(\vx') d\vx' \right] \\
  = \expectargs{\vx, \vx' \sim p}{k(\vx, \vx')} - \vz K^{-1} \vz\mbox{,}
\label{eq:marg_var_symbolic}
\end{align}
%where $\vz_n = \expectargs{\vx' \sim p}{k(\vx_n, \vx')}$ as before.
Perhaps surprisingly, the posterior variance of $Z_{f,p}$ does not depend on the observed function values, only on the location $x_n$ of samples.  This allows the optimal samples to be computed ahead of time, before observing any values of $f$ at all \citep{minka2000dqr}.
%\begin{align}
%\epsilon^{2}_{\bq{}}(\vx_1,\ldots,\vx_N) = \expectargs{\vx, \vx' \sim p}{k(\vx, \vx')} - \vz K^{-1} \vz
%\end{align}
%We can contrast the \bq{} objective $\epsilon^{2}_{\bq{}}$ to the objective being minimized in herding, $\epsilon^{2}_{herding}$ of equation \eqref{eq:mmd_assumption}.
%Just like $\epsilon^{2}_{herding}$, $\epsilon^{2}_{\bq{}}$ expresses a trade-off between accuracy and diversity of samples. On the one hand, as samples get close to high density regions under $p$, the values in $\vz$ increase, which results in decreasing variance. On the other hand, as samples get closer to each other, eigenvalues of $K$ increase, resulting in an increase in variance.

\section{RELATING $\varianceargs{}{Z_{f,p}}$ TO $\mmd$}

The similarity in the behaviour of $\epsilon^{2}_{herding}$ and $\epsilon^{2}_{\bq{}}$ is not a coincidence, the two quantities are closely related to each other, and to \mmd.

\begin{prop} The expected variance in the Bayesian quadrature $\epsilon^{2}_{\bq{}}$  is the maximum mean discrepancy between the target distribution $p$ and $q_{\bq{}}(x) = \sum_{n=1}^{N}w^{(n)}_{\bq{}}\delta_{x_n}(x)$
\end{prop}
%
%\begin{proof} Proof omitted for space reasons.
%The proof involves invoking the representer theorem, using bilinearity of scalar products and the fact that if $f$ is a standard Gaussian process then $\forall g\in\He: \left\langle f,g\right\rangle \sim \mathcal{N}(0,\Hnorm{g})$:
%\begin{align}
%&\varianceargs{}{Z_{f,p}\vert f_{x_1}, \dots, f_{x_N}}=\\
%	&= \mathbb{E}_{f\sim GP} \left( \int f(x) p(x) dx - \sum_{n=1}^{N}w^{(n)}_{\bq{}} f(x_n)\right)^2\\
%	&= \mathbb{E}_{f\sim GP} \left( \int \left\langle f, \phi (x)\right\rangle p(x) dx - \sum_{n=1}^{N}w^{(n)}_{\bq{}} \left\langle f, \phi (x_n)\right\rangle\right)^2\\
%	&= \mathbb{E}_{f\sim GP} \left\langle f ,  \int\phi(x) dx - \sum_{n=1}^{N}w^{(n)}_{\bq{}}\phi(x_n)\right\rangle^2\\
%	&= \Hnorm{\mu_p - \mu_{q_{\bq{}}}}^2\\
%	&= \mmd^2(p,q_{\bq{}})
%\end{align}
%\end{proof}

We know that the the posterior mean $\expectargs{\gp}{Z_{f,p}\vert f_1,\ldots,f_N}$ is a Bayes estimator and has therefore the minimal expected squared error amongst all estimators. This allows us to further rewrite $\epsilon^{2}_{\bq{}}$ into the following minimax forms:
%
\begin{align}
\epsilon^{2}_{\bq{}} %&= \sup_{\substack{f\in\He\\\Hnorm{f}{\He}=1}} \left| \int f_x p(x) dx - \sum_{n=1}^{N}w^{(n)}_{\bq{}} f_{x_n}\right|^2\\
%	&= \inf_{\hat{Z}:\mathcal{X}^N\mapsto\mathbb{R}} \sup_{\substack{f\in\He\\\Hnorm{f}{\He}=1}} \left| Z - \hat{Z}\left(f_{x_1},\ldots,f_{x_N}\right)\right|^2\\
	&= \inf_{\bm{w}\in\mathbb{R}^N} \sup_{\substack{f\in\He\\\Hnorm{f}{\He}=1}} \left| \int f_x p(x) dx - \sum_{n=1}^{N}w_n 	f_{x_n}\right|^2
\end{align}
%
%Looking at $\epsilon^{2}_{\bq{}}$  this way, we may discover the deep similarity to the criterion $\epsilon^2_{herding}$ that kernel herding minimises.
Optimal sampling for Bayesian quadrature minimises the same objective as kernel herding, but with the uniform $\frac{1}{N}$ weights replaced by the optimal weights. As a corollary
%
\begin{align}
\epsilon^{2}_{\bq{}}(x_1,\ldots,x_N)  \leq \epsilon^{2}_{KH} (x_1,\ldots,x_N)
\end{align}
%
It is interesting that $\epsilon^{2}_{\bq{}}$ has both a Bayesian interpretation as posterior variance under a Gaussian process prior, and a frequentist interpretation as a minimax bound on estimation error with respect to an RKHS.  Figure \ref{fig:bound_curve} demonstrates this closed-form, quickly shrinking bound on the error of the Bayesian estimator.  This equivalence also implies that the MMD is proportional to the expected error when estimating integrals of functions drawn from a GP prior.
\begin{figure}
\includegraphics[width=\columnwidth]{figures/bound_curve_rkhs}
\caption{The empirical error rate in estimating $Z_{f,p}$,  for the \sbq{} estimator, on 10 random functions drawn from the RKHS corresponding to the kernel used.  Also shown is the upper bound on the error rate implied by the $\mmd$.}
\label{fig:bound_curve}
\end{figure}
%
%Figure \ref{fig:bound_curve} demonstrates the MMD bound on the error of the \sbq{} estimator, on random functions drawn from the RKHS corresponding to the kernel used.  The empirical error always falls below the bound given by the MMD.

\subsection{Convergence Rates}

In finite dimensional Hilbert spaces, the herding algorithm has been shown to reduce $\mmd$ at a rate $\mathcal{O}(\frac{1}{N})$, which compares favourably with the $\mathcal{O}(\frac{1}{\sqrt{N}})$ rate obtained by non-deterministic Monte Carlo samplers.% However, as pointed out by \cite{bach2012equivalence}, this fast convergence is not guaranteed in infinite dimensional Hilbert spaces, such as the RKHS corresponding to the Gaussian kernel.
we have shown that the greedy Bayesian estimator obtains the optimal rate for any sampling method.  We have empirical results demonstrating a rate of convergence much faster than $\mathcal{O}(\frac{1}{N})$, but this rate is unkown to the authors, and we wish to pose this question to the kernel community.

\pagebreak

\bibliographystyle{icml2012}
\bibliography{herding}

\end{document}